Search in sources :

Example 11 with Code

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()");
}
Also used : javafx.scene.control(javafx.scene.control) Inject(com.google.inject.Inject) Node(javafx.scene.Node) Loinc2HPOCodedValue(org.monarchinitiative.loinc2hpo.codesystems.Loinc2HPOCodedValue) Model(org.monarchinitiative.loinc2hpo.model.Model) FXCollections(javafx.collections.FXCollections) LoincEntry(org.monarchinitiative.loinc2hpo.loinc.LoincEntry) ReadOnlyStringWrapper(javafx.beans.property.ReadOnlyStringWrapper) FXML(javafx.fxml.FXML) ActionEvent(javafx.event.ActionEvent) Logger(org.apache.logging.log4j.Logger) HpoTermId4LoincTest(org.monarchinitiative.loinc2hpo.loinc.HpoTermId4LoincTest) UniversalLoinc2HPOAnnotation(org.monarchinitiative.loinc2hpo.loinc.UniversalLoinc2HPOAnnotation) ReadOnlyBooleanWrapper(javafx.beans.property.ReadOnlyBooleanWrapper) Stage(javafx.stage.Stage) CodeSystemConvertor(org.monarchinitiative.loinc2hpo.codesystems.CodeSystemConvertor) Annotation(org.monarchinitiative.loinc2hpo.model.Annotation) Map(java.util.Map) Code(org.monarchinitiative.loinc2hpo.codesystems.Code) ObservableList(javafx.collections.ObservableList) BorderPane(javafx.scene.layout.BorderPane) LogManager(org.apache.logging.log4j.LogManager) Singleton(com.google.inject.Singleton) LoincEntry(org.monarchinitiative.loinc2hpo.loinc.LoincEntry) HpoTermId4LoincTest(org.monarchinitiative.loinc2hpo.loinc.HpoTermId4LoincTest) Map(java.util.Map) Code(org.monarchinitiative.loinc2hpo.codesystems.Code) UniversalLoinc2HPOAnnotation(org.monarchinitiative.loinc2hpo.loinc.UniversalLoinc2HPOAnnotation) Annotation(org.monarchinitiative.loinc2hpo.model.Annotation)

Example 12 with Code

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;
}
Also used : Code(org.monarchinitiative.loinc2hpo.codesystems.Code) BasicLabTestResultInHPO(org.monarchinitiative.loinc2hpo.testresult.BasicLabTestResultInHPO)

Example 13 with Code

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;
}
Also used : Code(org.monarchinitiative.loinc2hpo.codesystems.Code)

Example 14 with Code

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);
}
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 15 with Code

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);
}
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)

Aggregations

Code (org.monarchinitiative.loinc2hpo.codesystems.Code)20 HpoTerm (com.github.phenomics.ontolib.formats.hpo.HpoTerm)11 ImmutableMap (com.google.common.collect.ImmutableMap)10 HpoOntology (com.github.phenomics.ontolib.formats.hpo.HpoOntology)8 HpoOboParser (com.github.phenomics.ontolib.io.obo.hpo.HpoOboParser)8 File (java.io.File)8 IOException (java.io.IOException)8 TermId (com.github.phenomics.ontolib.ontology.data.TermId)6 Test (org.junit.Test)6 WriteToFile (org.monarchinitiative.loinc2hpo.io.WriteToFile)6 HpoTermId4LoincTest (org.monarchinitiative.loinc2hpo.loinc.HpoTermId4LoincTest)6 UniversalLoinc2HPOAnnotation (org.monarchinitiative.loinc2hpo.loinc.UniversalLoinc2HPOAnnotation)6 FhirObservationAnalyzerTest (org.monarchinitiative.loinc2hpo.fhir.FhirObservationAnalyzerTest)5 LoincId (org.monarchinitiative.loinc2hpo.loinc.LoincId)5 HashMap (java.util.HashMap)4 Annotation (org.monarchinitiative.loinc2hpo.model.Annotation)4 Map (java.util.Map)3 FXML (javafx.fxml.FXML)3 LogManager (org.apache.logging.log4j.LogManager)3 Logger (org.apache.logging.log4j.Logger)3