Search in sources :

Example 16 with Observation

use of org.hl7.fhir.dstu3.model.Observation 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);
}
Also used : HpoOboParser(com.github.phenomics.ontolib.io.obo.hpo.HpoOboParser) IOException(java.io.IOException) Code(org.monarchinitiative.loinc2hpo.codesystems.Code) ImmutableMap(com.google.common.collect.ImmutableMap) HpoTerm(com.github.phenomics.ontolib.formats.hpo.HpoTerm) Observation(org.hl7.fhir.dstu3.model.Observation) TermId(com.github.phenomics.ontolib.ontology.data.TermId) File(java.io.File) HpoOntology(com.github.phenomics.ontolib.formats.hpo.HpoOntology) BeforeClass(org.junit.BeforeClass)

Example 17 with Observation

use of org.hl7.fhir.dstu3.model.Observation 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);
}
Also used : HpoOboParser(com.github.phenomics.ontolib.io.obo.hpo.HpoOboParser) IOException(java.io.IOException) Code(org.monarchinitiative.loinc2hpo.codesystems.Code) ImmutableMap(com.google.common.collect.ImmutableMap) HpoTerm(com.github.phenomics.ontolib.formats.hpo.HpoTerm) Observation(org.hl7.fhir.dstu3.model.Observation) TermId(com.github.phenomics.ontolib.ontology.data.TermId) File(java.io.File) HpoOntology(com.github.phenomics.ontolib.formats.hpo.HpoOntology) BeforeClass(org.junit.BeforeClass)

Example 18 with Observation

use of org.hl7.fhir.dstu3.model.Observation in project loinc2hpo by monarch-initiative.

the class ObservationAnalysisFromQnValueTest method setup.

@BeforeClass
public static void setup() throws MalformedLoincCodeException {
    String path = FhirObservationAnalyzerTest.class.getClassLoader().getResource("json/glucoseHighNoInterpretation.fhir").getPath();
    Observation observation1 = FhirResourceRetriever.parseJsonFile2Observation(path);
    path = FhirObservationAnalyzerTest.class.getClassLoader().getResource("json/glucoseNoInterpretationNoReference.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);
}
Also used : HpoOboParser(com.github.phenomics.ontolib.io.obo.hpo.HpoOboParser) IOException(java.io.IOException) Code(org.monarchinitiative.loinc2hpo.codesystems.Code) ImmutableMap(com.google.common.collect.ImmutableMap) HpoTerm(com.github.phenomics.ontolib.formats.hpo.HpoTerm) Observation(org.hl7.fhir.dstu3.model.Observation) TermId(com.github.phenomics.ontolib.ontology.data.TermId) File(java.io.File) HpoOntology(com.github.phenomics.ontolib.formats.hpo.HpoOntology) BeforeClass(org.junit.BeforeClass)

Example 19 with Observation

use of org.hl7.fhir.dstu3.model.Observation in project loinc2hpo by monarch-initiative.

the class ObservationDtu3 method getOutcome.

@Override
public Optional<Outcome> getOutcome() {
    if (observation.hasInterpretation()) {
        List<String> codes = this.observation.getInterpretation().getCoding().stream().map(Coding::getCode).distinct().collect(Collectors.toList());
        if (codes.size() > 1) {
            LOGGER.error("Multiple interpretation codes returned");
            return Optional.empty();
        }
        ShortCode code = ShortCode.fromShortCode(codes.get(0));
        Outcome outcome = getOutcome(code, observation);
        return Optional.of(outcome);
    } else if (observation.hasValueCodeableConcept()) {
        return getOutcomeFromCodedValue();
    } else if (observation.hasValueQuantity()) {
        return getOutcomeFromValueQuantity();
    } else {
        LOGGER.error("Unable to handle observation {}", observation);
        return Optional.empty();
    }
}
Also used : ShortCode(org.monarchinitiative.loinc2hpocore.codesystems.ShortCode) Coding(org.hl7.fhir.dstu3.model.Coding) Outcome(org.monarchinitiative.loinc2hpocore.codesystems.Outcome)

Example 20 with Observation

use of org.hl7.fhir.dstu3.model.Observation in project loinc2hpo by monarch-initiative.

the class Dstu3ObservationTest method testGlucoseLow.

@Test
void testGlucoseLow() throws IOException {
    String jsonPath = "json/glucoseLow.fhir";
    Observation glucoseAbnormal = importDstu3Observation(jsonPath);
    Uberobservation uberobservation = new ObservationDtu3(glucoseAbnormal);
    LoincId expectedLoincId = new LoincId("15074-8");
    Optional<LoincId> opt = uberobservation.getLoincId();
    assertTrue(opt.isPresent());
    assertEquals(expectedLoincId, opt.get());
    Optional<Outcome> opt2 = uberobservation.getOutcome();
    assertTrue(opt2.isPresent());
    assertEquals(Outcome.LOW(), opt2.get());
    assertNotEquals(Outcome.NORMAL(), opt2.get());
    assertNotEquals(Outcome.HIGH(), opt2.get());
}
Also used : ObservationDtu3(org.monarchinitiative.loinc2hpofhir.fhir2hpo.ObservationDtu3) Outcome(org.monarchinitiative.loinc2hpocore.codesystems.Outcome) Observation(org.hl7.fhir.dstu3.model.Observation) TestBase.importDstu3Observation(fhir.TestBase.importDstu3Observation) LoincId(org.monarchinitiative.loinc2hpocore.loinc.LoincId) Uberobservation(org.monarchinitiative.loinc2hpofhir.fhir2hpo.Uberobservation) Test(org.junit.jupiter.api.Test)

Aggregations

Observation (org.hl7.fhir.dstu3.model.Observation)15 Outcome (org.monarchinitiative.loinc2hpocore.codesystems.Outcome)7 Test (org.junit.jupiter.api.Test)6 LoincId (org.monarchinitiative.loinc2hpocore.loinc.LoincId)6 ObservationDtu3 (org.monarchinitiative.loinc2hpofhir.fhir2hpo.ObservationDtu3)6 Uberobservation (org.monarchinitiative.loinc2hpofhir.fhir2hpo.Uberobservation)6 TermId (com.github.phenomics.ontolib.ontology.data.TermId)4 IBaseBundle (org.hl7.fhir.instance.model.api.IBaseBundle)4 BeforeClass (org.junit.BeforeClass)4 HpoOntology (com.github.phenomics.ontolib.formats.hpo.HpoOntology)3 HpoTerm (com.github.phenomics.ontolib.formats.hpo.HpoTerm)3 HpoOboParser (com.github.phenomics.ontolib.io.obo.hpo.HpoOboParser)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 TestBase.importDstu3Observation (fhir.TestBase.importDstu3Observation)3 File (java.io.File)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Code (org.monarchinitiative.loinc2hpo.codesystems.Code)3 Test (org.junit.Test)2 ReferenceClientParam (ca.uhn.fhir.rest.gclient.ReferenceClientParam)1