use of org.monarchinitiative.loinc2hpo.codesystems.Code in project loinc2hpo by monarch-initiative.
the class CurrentAnnotationController method populateTables.
private void populateTables() {
if (model == null) {
logger.error("model is null.");
return;
}
this.currentAnnotation = model.getCurrentAnnotation();
LoincEntry currentLoincEntry = model.getLoincEntryMap().get(currentAnnotation.getLoincId());
annotationTitle.setText(String.format("Annotations for Loinc: %s[%s]", currentLoincEntry.getLOINC_Number(), currentLoincEntry.getLongName()));
internalCodeAnnotations.clear();
currentAnnotation.getCandidateHpoTerms().entrySet().stream().filter(p -> p.getKey().getSystem().equals(Loinc2HPOCodedValue.CODESYSTEM)).map(p -> new Annotation(p.getKey(), p.getValue())).forEach(internalCodeAnnotations::add);
externalCodeAnnotations.clear();
currentAnnotation.getCandidateHpoTerms().entrySet().stream().filter(p -> !p.getKey().getSystem().equals(Loinc2HPOCodedValue.CODESYSTEM)).map(p -> new Annotation(p.getKey(), p.getValue())).forEach(externalCodeAnnotations::add);
interpretationCodeAnnotations.clear();
for (Map.Entry<Code, Code> entry : CodeSystemConvertor.getCodeConversionMap().entrySet()) {
logger.debug("key: " + entry.getKey() + "\nvalue: " + entry.getValue());
HpoTermId4LoincTest result = currentAnnotation.loincInterpretationToHPO(entry.getValue());
logger.debug("result is null? " + (result == null));
if (result != null) {
Annotation annotation = new Annotation(entry.getKey(), result);
interpretationCodeAnnotations.add(annotation);
logger.debug("interpretationCodeAnnotations size: " + interpretationCodeAnnotations.size());
}
}
logger.debug("internalTableview is null: " + (internalTableview == null));
logger.debug("internalCodeAnnotations is null: " + (internalTableview == null));
logger.debug("internal annotation size: " + internalCodeAnnotations.size());
internalCodeAnnotations.forEach(logger::info);
logger.trace("exit initInternalTableview()");
}
use of org.monarchinitiative.loinc2hpo.codesystems.Code in project loinc2hpo by monarch-initiative.
the class FhirObservationAnalyzer method getHPOFromInterpretation.
/**
* Convert a FHIR observation to HPO through the interpretation field
* @param interpretation
* @param testmap
* @return
* @throws MalformedLoincCodeException
* @throws LoincCodeNotFoundException
* @throws UnsupportedCodingSystemException
*/
public static LabTestResultInHPO getHPOFromInterpretation(CodeableConcept interpretation, Map<LoincId, UniversalLoinc2HPOAnnotation> testmap) throws MalformedLoincCodeException, LoincCodeNotFoundException, UnsupportedCodingSystemException, AnnotationNotFoundException {
// here we only look at interpretation code system defined by HL7
Code interpretationCode = null;
for (Coding coding : interpretation.getCoding()) {
if (coding.getSystem().equals("http://hl7.org/fhir/v2/0078")) {
interpretationCode = Code.getNewCode().setSystem(coding.getSystem()).setCode(coding.getCode());
break;
}
}
if (interpretationCode != null) {
// find result
try {
Code internalCode = CodeSystemConvertor.convertToInternalCode(interpretationCode);
// get the loinc code from the observation
LoincId loincId = getLoincIdOfObservation();
// get the annotation class for this loinc code
UniversalLoinc2HPOAnnotation annotationForLoinc = testmap.get(loincId);
if (annotationForLoinc == null)
throw new AnnotationNotFoundException();
HpoTermId4LoincTest hpoId = annotationForLoinc.loincInterpretationToHPO(internalCode);
return new BasicLabTestResultInHPO(hpoId, null, "?");
} catch (InternalCodeNotFoundException e) {
e.printStackTrace();
}
} else {
logger.error("Could not recognize the coding system for interpretation");
for (Coding coding : interpretation.getCoding()) {
logger.error("coding system: " + coding.getSystem() + " Value: " + coding.getCode());
}
throw new UnsupportedCodingSystemException("Coding system is not supported");
}
return null;
}
use of org.monarchinitiative.loinc2hpo.codesystems.Code in project loinc2hpo by monarch-initiative.
the class ObservationAnalysisFromInterpretation method getInterpretationCodes.
public Set<Code> getInterpretationCodes() {
Set<Code> interpretationCodes = new HashSet<>();
interpretationField.getCoding().forEach(x -> {
Code interpretationcode = Code.getNewCode().setSystem(x.getSystem()).setCode(x.getCode());
interpretationCodes.add(interpretationcode);
});
return interpretationCodes;
}
use of org.monarchinitiative.loinc2hpo.codesystems.Code in project loinc2hpo by monarch-initiative.
the class ObservationAnalysisFromCodedValuesTest method setup.
@BeforeClass
public static void setup() throws MalformedLoincCodeException {
String path = FhirObservationAnalyzerTest.class.getClassLoader().getResource("json/staphylococcus.fhir").getPath();
Observation observation1 = FhirResourceRetriever.parseJsonFile2Observation(path);
path = FhirObservationAnalyzerTest.class.getClassLoader().getResource("json/staphylococcusNoInterpretation.fhir").getPath();
Observation observation2 = FhirResourceRetriever.parseJsonFile2Observation(path);
path = FhirObservationAnalyzerTest.class.getClassLoader().getResource("json/ecoliNoInterpretation.fhir").getPath();
Observation observation3 = FhirResourceRetriever.parseJsonFile2Observation(path);
path = FhirObservationAnalyzerTest.class.getClassLoader().getResource("json/neisseriaNoInterpretation.fhir").getPath();
Observation observation4 = FhirResourceRetriever.parseJsonFile2Observation(path);
observations[0] = observation1;
observations[1] = observation2;
observations[2] = observation3;
observations[3] = observation4;
String hpo_obo = FhirObservationAnalyzerTest.class.getClassLoader().getResource("obo/hp.obo").getPath();
HpoOboParser hpoOboParser = new HpoOboParser(new File(hpo_obo));
HpoOntology hpo = null;
try {
hpo = hpoOboParser.parse();
} catch (IOException e) {
e.printStackTrace();
}
ImmutableMap.Builder<String, HpoTerm> termmap = new ImmutableMap.Builder<>();
ImmutableMap.Builder<TermId, HpoTerm> termmap2 = new ImmutableMap.Builder<>();
if (hpo != null) {
List<HpoTerm> res = hpo.getTermMap().values().stream().distinct().collect(Collectors.toList());
res.forEach(term -> {
termmap.put(term.getName(), term);
termmap2.put(term.getId(), term);
});
}
hpoTermMap = termmap.build();
hpoTermMap2 = termmap2.build();
UniversalLoinc2HPOAnnotation.Builder loinc2HpoAnnotationBuilder = new UniversalLoinc2HPOAnnotation.Builder();
LoincId loincId = new LoincId("15074-8");
LoincScale loincScale = LoincScale.string2enum("Qn");
HpoTerm low = hpoTermMap.get("Hypoglycemia");
HpoTerm normal = hpoTermMap.get("Abnormality of blood glucose concentration");
HpoTerm hi = hpoTermMap.get("Hyperglycemia");
loinc2HpoAnnotationBuilder.setLoincId(loincId).setLoincScale(loincScale).setLowValueHpoTerm(low).setIntermediateValueHpoTerm(normal).setIntermediateNegated(true).setHighValueHpoTerm(hi);
UniversalLoinc2HPOAnnotation annotation15074 = loinc2HpoAnnotationBuilder.build();
testmap.put(loincId, annotation15074);
loinc2HpoAnnotationBuilder = new UniversalLoinc2HPOAnnotation.Builder();
loincId = new LoincId("600-7");
loincScale = LoincScale.string2enum("Nom");
HpoTerm forCode1 = hpoTermMap.get("Recurrent E. coli infections");
HpoTerm forCode2 = hpoTermMap.get("Recurrent Staphylococcus aureus infections");
HpoTerm positive = hpoTermMap.get("Recurrent bacterial infections");
Code code1 = Code.getNewCode().setSystem("http://snomed.info/sct").setCode("112283007");
Code code2 = Code.getNewCode().setSystem("http://snomed.info/sct").setCode("3092008");
loinc2HpoAnnotationBuilder.setLoincId(loincId).setLoincScale(loincScale).setHighValueHpoTerm(positive).addAdvancedAnnotation(code1, new HpoTermId4LoincTest(forCode1, false)).addAdvancedAnnotation(code2, new HpoTermId4LoincTest(forCode2, false));
UniversalLoinc2HPOAnnotation annotation600 = loinc2HpoAnnotationBuilder.build();
testmap.put(loincId, annotation600);
}
use of org.monarchinitiative.loinc2hpo.codesystems.Code in project loinc2hpo by monarch-initiative.
the class ObservationAnalysisFromInterpretationTest method setup.
@BeforeClass
public static void setup() throws MalformedLoincCodeException {
String path = FhirObservationAnalyzerTest.class.getClassLoader().getResource("json/glucoseHigh.fhir").getPath();
Observation observation1 = FhirResourceRetriever.parseJsonFile2Observation(path);
path = FhirObservationAnalyzerTest.class.getClassLoader().getResource("json/glucoseConflictingInterpretation.fhir").getPath();
Observation observation2 = FhirResourceRetriever.parseJsonFile2Observation(path);
observations[0] = observation1;
observations[1] = observation2;
String hpo_obo = FhirObservationAnalyzerTest.class.getClassLoader().getResource("obo/hp.obo").getPath();
HpoOboParser hpoOboParser = new HpoOboParser(new File(hpo_obo));
HpoOntology hpo = null;
try {
hpo = hpoOboParser.parse();
} catch (IOException e) {
e.printStackTrace();
}
ImmutableMap.Builder<String, HpoTerm> termmap = new ImmutableMap.Builder<>();
ImmutableMap.Builder<TermId, HpoTerm> termmap2 = new ImmutableMap.Builder<>();
if (hpo != null) {
List<HpoTerm> res = hpo.getTermMap().values().stream().distinct().collect(Collectors.toList());
res.forEach(term -> {
termmap.put(term.getName(), term);
termmap2.put(term.getId(), term);
});
}
hpoTermMap = termmap.build();
hpoTermMap2 = termmap2.build();
UniversalLoinc2HPOAnnotation.Builder loinc2HpoAnnotationBuilder = new UniversalLoinc2HPOAnnotation.Builder();
LoincId loincId = new LoincId("15074-8");
LoincScale loincScale = LoincScale.string2enum("Qn");
HpoTerm low = hpoTermMap.get("Hypoglycemia");
HpoTerm normal = hpoTermMap.get("Abnormality of blood glucose concentration");
HpoTerm hi = hpoTermMap.get("Hyperglycemia");
loinc2HpoAnnotationBuilder.setLoincId(loincId).setLoincScale(loincScale).setLowValueHpoTerm(low).setIntermediateValueHpoTerm(normal).setIntermediateNegated(true).setHighValueHpoTerm(hi);
UniversalLoinc2HPOAnnotation annotation15074 = loinc2HpoAnnotationBuilder.build();
testmap.put(loincId, annotation15074);
loinc2HpoAnnotationBuilder = new UniversalLoinc2HPOAnnotation.Builder();
loincId = new LoincId("600-7");
loincScale = LoincScale.string2enum("Nom");
HpoTerm forCode1 = hpoTermMap.get("Recurrent E. coli infections");
HpoTerm forCode2 = hpoTermMap.get("Recurrent Staphylococcus aureus infections");
HpoTerm positive = hpoTermMap.get("Recurrent bacterial infections");
Code code1 = Code.getNewCode().setSystem("http://snomed.info/sct").setCode("112283007");
Code code2 = Code.getNewCode().setSystem("http://snomed.info/sct").setCode("3092008");
loinc2HpoAnnotationBuilder.setLoincId(loincId).setLoincScale(loincScale).setHighValueHpoTerm(positive).addAdvancedAnnotation(code1, new HpoTermId4LoincTest(forCode1, false)).addAdvancedAnnotation(code2, new HpoTermId4LoincTest(forCode2, false));
UniversalLoinc2HPOAnnotation annotation600 = loinc2HpoAnnotationBuilder.build();
testmap.put(loincId, annotation600);
}
Aggregations