-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restrict orders sent to only the two tests LNSP supports (#54)
- Loading branch information
Showing
6 changed files
with
73 additions
and
33 deletions.
There are no files selected for viewing
67 changes: 47 additions & 20 deletions
67
api/src/main/java/org/openmrs/module/labintegration/api/hl7/ObsSelector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,71 @@ | ||
package org.openmrs.module.labintegration.api.hl7; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.openmrs.Concept; | ||
import org.openmrs.Obs; | ||
import org.openmrs.api.ConceptService; | ||
import org.openmrs.api.context.Context; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.io.InputStream; | ||
import java.util.HashSet; | ||
import java.util.Scanner; | ||
import java.util.Set; | ||
|
||
@Component | ||
public class ObsSelector { | ||
|
||
private static final int TESTS_ORDERED_CONCEPT_ID = 1271; | ||
private static volatile int viralLoadConceptId = -1; | ||
private static volatile int earlyInfantDiagnosisConceptId = -1; | ||
|
||
private Set<Integer> conceptIds = new HashSet<>(); | ||
|
||
public ObsSelector() { | ||
InputStream in = null; | ||
try { | ||
in = getClass().getClassLoader().getResourceAsStream("test-concepts.txt"); | ||
Scanner scanner = new Scanner(in, "UTF-8"); | ||
|
||
while (scanner.hasNextLine()) { | ||
String line = scanner.nextLine(); | ||
if (StringUtils.isNotBlank(line)) { | ||
conceptIds.add(Integer.valueOf(line)); | ||
|
||
} | ||
|
||
public boolean isValidTestType(Obs obs) { | ||
return TESTS_ORDERED_CONCEPT_ID == obs.getConcept().getConceptId() && obs.getValueCoded() != null && ( | ||
(getViralLoadConceptId() != -1 && obs.getValueCoded().getConceptId() == getViralLoadConceptId()) | ||
|| (getEarlyInfantDiagnosisConceptId() != -1 && obs.getValueCoded().getConceptId() == getEarlyInfantDiagnosisConceptId()) | ||
); | ||
} | ||
|
||
private int getViralLoadConceptId() { | ||
if (viralLoadConceptId == -1) { | ||
synchronized (ObsSelector.class) { | ||
if (viralLoadConceptId == -1) { | ||
ConceptService conceptService = Context.getService(ConceptService.class); | ||
Concept concept = conceptService.getConceptByMapping("CIEL", "856"); | ||
if (concept == null) { | ||
concept = conceptService.getConceptByMapping("LOINC", "25836-8"); | ||
} | ||
|
||
if (concept != null) { | ||
viralLoadConceptId = concept.getConceptId(); | ||
} | ||
} | ||
} | ||
} finally { | ||
IOUtils.closeQuietly(in); | ||
} | ||
} | ||
|
||
public Set<Integer> getConceptIds() { | ||
return conceptIds; | ||
return viralLoadConceptId; | ||
} | ||
|
||
public boolean isTestType(Obs obs) { | ||
return TESTS_ORDERED_CONCEPT_ID == obs.getConcept().getConceptId(); | ||
private int getEarlyInfantDiagnosisConceptId() { | ||
if (earlyInfantDiagnosisConceptId == -1) { | ||
synchronized (ObsSelector.class) { | ||
if (earlyInfantDiagnosisConceptId == -1) { | ||
ConceptService conceptService = Context.getService(ConceptService.class); | ||
Concept concept = conceptService.getConceptByMapping("CIEL", "844"); | ||
if (concept == null) { | ||
concept = conceptService.getConceptByMapping("LOINC", "44871-2"); | ||
} | ||
|
||
if (concept != null) { | ||
earlyInfantDiagnosisConceptId = concept.getConceptId(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
return earlyInfantDiagnosisConceptId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters