Search in sources :

Example 1 with Loinc2HPOAnnotation

use of org.monarchinitiative.loinc2hpo.loinc.Loinc2HPOAnnotation in project loinc2hpo by monarch-initiative.

the class FhirResourceRetriever method fhir2testrest.

@Deprecated
public static LabTestResultInHPO fhir2testrest(JsonNode node, Map<LoincId, Loinc2HPOAnnotation> testmap) throws Loinc2HpoException {
    boolean interpretationDetected = false;
    String interpretationCode = null;
    LoincId lid;
    ObservationResultInInternalCode observation;
    String comment;
    System.out.println(node.toString());
    String resourcetype = node.get("resourceType").asText();
    if (!resourcetype.equals("Observation"))
        throw new WrongElementException("Unexpected resource type " + resourcetype + "(expected: LabTestResultInHPO)");
    JsonNode codeNode = node.get("code");
    lid = getLoincId(codeNode);
    JsonNode interpretationNode = node.get("interpretation");
    observation = getInterpretationCode(interpretationNode);
    if (observation != null && lid != null) {
        Loinc2HPOAnnotation test = testmap.get(lid);
        if (test == null) {
            logger.error("Could not retrieve test for " + lid.toString());
            debugPrint(testmap);
            return null;
        }
        HpoTermId4LoincTest hpoId = test.loincInterpretationToHpo(observation);
        return new BasicLabTestResultInHPO(hpoId, observation, "?");
    }
    logger.info("interpretation node: " + interpretationNode.asText());
    if (interpretationNode.isMissingNode()) {
    // 
    } else {
        JsonNode codingNode = interpretationNode.get("coding");
        logger.info("coding node: " + codingNode.asText());
        if (codingNode.isMissingNode()) {
            logger.info("coding node is not array");
        } else {
            if (!codingNode.isArray()) {
            // 
            } else {
                logger.info("coding node is array");
                for (JsonNode loinc : codingNode) {
                    if (!loinc.path("code").isMissingNode()) {
                        interpretationDetected = true;
                        interpretationCode = loinc.path("code").asText();
                        logger.info("code is detected: " + interpretationCode);
                    // if (interpretationCode.equalsIgnoreCase("H")) {
                    // return new BasicLabTestResultInHPO()
                    // }
                    }
                /**
                 *                         String system = loinc.path("system").asText();
                 *                         logger.info("system: " + system);
                 *                         if (!system.equals("http://loinc.org")) {
                 *                         System.err.println("[ERROR] Non Loinc code detected...");
                 *                         //continue;
                 *                         }
                 *
                 *                         String display = loinc.path("display").asText();
                 *                         logger.info("display: " + display);
                 */
                }
            }
        }
    }
    if (!interpretationDetected) {
        double valueObserved = 9999.0;
        JsonNode valueNode = node.get("valueQuantity");
        // System.out.println("found valueNode: " + valueNode.asText());
        try {
            logger.info("value observed: " + valueNode.get("value").asText());
            valueObserved = Double.parseDouble(valueNode.get("value").asText());
            logger.info("value retrieved: " + valueObserved);
        } catch (NumberFormatException e) {
            logger.error("measured value is not a double");
        }
        if (Math.abs(valueObserved - 9999.0) > 0.00001) {
            // we want to compare the observed value with the normal range
            if (valueObserved < 0) {
                interpretationCode = "L";
            }
            if (valueObserved > 1) {
                interpretationCode = "H";
            } else {
                interpretationCode = "N";
            }
        }
    }
    return null;
// return LabTestResultInHPO(interpretationCode);
}
Also used : ObservationResultInInternalCode(org.monarchinitiative.loinc2hpo.loinc.ObservationResultInInternalCode) Loinc2HPOAnnotation(org.monarchinitiative.loinc2hpo.loinc.Loinc2HPOAnnotation) WrongElementException(org.monarchinitiative.loinc2hpo.exception.WrongElementException) LoincId(org.monarchinitiative.loinc2hpo.loinc.LoincId) JsonNode(com.fasterxml.jackson.databind.JsonNode) HpoTermId4LoincTest(org.monarchinitiative.loinc2hpo.loinc.HpoTermId4LoincTest) BasicLabTestResultInHPO(org.monarchinitiative.loinc2hpo.testresult.BasicLabTestResultInHPO)

Example 2 with Loinc2HPOAnnotation

use of org.monarchinitiative.loinc2hpo.loinc.Loinc2HPOAnnotation in project loinc2hpo by monarch-initiative.

the class FhirObservationAnalyzerTest method getHPOFromInterpretation.

@Test
public void getHPOFromInterpretation() throws Exception {
    FhirObservationAnalyzer.setObservation(observation);
    Map<LoincId, UniversalLoinc2HPOAnnotation> testmap = new HashMap<>();
    LoincId loincId = new LoincId("15074-8");
    LoincScale loincScale = LoincScale.string2enum("Qn");
    TermId low = hpoTermMap.get("Hypoglycemia").getId();
    TermId normal = hpoTermMap.get("Abnormality of blood glucose concentration").getId();
    TermId hi = hpoTermMap.get("Hyperglycemia").getId();
    Loinc2HPOAnnotation test1 = new QnLoinc2HPOAnnotation(loincId, loincScale, low, normal, hi);
// testmap.put(loincId, test1);
// LabTestResultInHPO result = FhirObservationAnalyzer.getHPOFromInterpretation(FhirObservationAnalyzer.getObservation().getInterpretation(), testmap);
// System.out.println(result);
}
Also used : QnLoinc2HPOAnnotation(org.monarchinitiative.loinc2hpo.loinc.QnLoinc2HPOAnnotation) Loinc2HPOAnnotation(org.monarchinitiative.loinc2hpo.loinc.Loinc2HPOAnnotation) HashMap(java.util.HashMap) TermId(com.github.phenomics.ontolib.ontology.data.TermId) QnLoinc2HPOAnnotation(org.monarchinitiative.loinc2hpo.loinc.QnLoinc2HPOAnnotation) Test(org.junit.Test)

Aggregations

Loinc2HPOAnnotation (org.monarchinitiative.loinc2hpo.loinc.Loinc2HPOAnnotation)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 TermId (com.github.phenomics.ontolib.ontology.data.TermId)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 WrongElementException (org.monarchinitiative.loinc2hpo.exception.WrongElementException)1 HpoTermId4LoincTest (org.monarchinitiative.loinc2hpo.loinc.HpoTermId4LoincTest)1 LoincId (org.monarchinitiative.loinc2hpo.loinc.LoincId)1 ObservationResultInInternalCode (org.monarchinitiative.loinc2hpo.loinc.ObservationResultInInternalCode)1 QnLoinc2HPOAnnotation (org.monarchinitiative.loinc2hpo.loinc.QnLoinc2HPOAnnotation)1 BasicLabTestResultInHPO (org.monarchinitiative.loinc2hpo.testresult.BasicLabTestResultInHPO)1