Search in sources :

Example 6 with Outcome

use of org.monarchinitiative.loinc2hpocore.codesystems.Outcome in project loinc2hpo by monarch-initiative.

the class Loinc2HpoAnnotation method fromAnnotationLine.

public static Loinc2HpoAnnotation fromAnnotationLine(String line) {
    String[] fields = line.split("\t");
    if (fields.length != EXPECTED_NUMBER_OF_FIELDS) {
        System.err.printf("Malformed line with %d fields: %s%n", fields.length, line);
    }
    LoincId loincId = new LoincId(fields[0]);
    LoincScale scale = LoincScale.fromString(fields[1]);
    TermId hpoId = TermId.of(fields[3]);
    String curation = fields[5];
    String comment = fields[6];
    String outcomeString = fields[2];
    Outcome outcome;
    if (scale.equals(LoincScale.NOMINAL)) {
        outcome = Outcome.nominal(outcomeString);
    } else {
        outcome = new Outcome(ShortCode.fromShortCode(outcomeString));
    }
    if (fields[4].equals(".")) {
        return new Loinc2HpoAnnotation(loincId, scale, outcome, hpoId, curation, comment);
    }
    TermId supplementalId = TermId.of(fields[4]);
    return new Loinc2HpoAnnotation(loincId, scale, outcome, hpoId, supplementalId, curation, comment);
}
Also used : Outcome(org.monarchinitiative.loinc2hpocore.codesystems.Outcome) LoincId(org.monarchinitiative.loinc2hpocore.loinc.LoincId) TermId(org.monarchinitiative.phenol.ontology.data.TermId)

Example 7 with Outcome

use of org.monarchinitiative.loinc2hpocore.codesystems.Outcome 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 8 with Outcome

use of org.monarchinitiative.loinc2hpocore.codesystems.Outcome in project loinc2hpo by monarch-initiative.

the class ObservationDtu3 method getOutcomeFromCodedValue.

Optional<Outcome> getOutcomeFromCodedValue() {
    CodeableConcept codeableConcept = this.observation.getValueCodeableConcept();
    if (codeableConcept == null) {
        // should never happen
        LOGGER.error("Codable concept null in getOutcomeFromCodedValue");
    }
    List<Coding> codings = codeableConcept != null ? codeableConcept.getCoding() : List.of();
    for (Coding coding : codings) {
        String code = coding.getCode();
        String system = coding.getSystem();
        String display = coding.getDisplay();
        String outcomeString = code + ":" + system + ":" + display;
        Outcome outcome = Outcome.nominal(outcomeString);
        return Optional.of(outcome);
    }
    return Optional.empty();
}
Also used : Coding(org.hl7.fhir.dstu3.model.Coding) Outcome(org.monarchinitiative.loinc2hpocore.codesystems.Outcome) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 9 with Outcome

use of org.monarchinitiative.loinc2hpocore.codesystems.Outcome in project loinc2hpo by monarch-initiative.

the class ObservationR5 method getOutcome.

@Override
public Optional<Outcome> getOutcome() {
    if (observation.hasInterpretation()) {
        List<String> codes = this.observation.getInterpretation().stream().distinct().map(CodeableConcept::getCoding).flatMap(Collection::stream).map(org.hl7.fhir.r5.model.Coding::getCode).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) Outcome(org.monarchinitiative.loinc2hpocore.codesystems.Outcome) Collection(java.util.Collection)

Example 10 with Outcome

use of org.monarchinitiative.loinc2hpocore.codesystems.Outcome in project loinc2hpo by monarch-initiative.

the class ObservationR5 method getOutcomeFromCodedValue.

Optional<Outcome> getOutcomeFromCodedValue() {
    CodeableConcept codeableConcept = this.observation.getValueCodeableConcept();
    if (codeableConcept == null) {
        // should never happen
        LOGGER.error("Codable concept null in getOutcomeFromCodedValue");
    }
    List<Coding> codings = codeableConcept != null ? codeableConcept.getCoding() : List.of();
    for (Coding coding : codings) {
        String code = coding.getCode();
        String system = coding.getSystem();
        String display = coding.getDisplay();
        String outcomeString = code + ":" + system + ":" + display;
        Outcome outcome = Outcome.nominal(outcomeString);
        return Optional.of(outcome);
    }
    return Optional.empty();
}
Also used : Coding(org.hl7.fhir.r5.model.Coding) Outcome(org.monarchinitiative.loinc2hpocore.codesystems.Outcome) CodeableConcept(org.hl7.fhir.r5.model.CodeableConcept)

Aggregations

Outcome (org.monarchinitiative.loinc2hpocore.codesystems.Outcome)13 LoincId (org.monarchinitiative.loinc2hpocore.loinc.LoincId)7 Observation (org.hl7.fhir.dstu3.model.Observation)6 Test (org.junit.jupiter.api.Test)6 ObservationDtu3 (org.monarchinitiative.loinc2hpofhir.fhir2hpo.ObservationDtu3)6 Uberobservation (org.monarchinitiative.loinc2hpofhir.fhir2hpo.Uberobservation)6 TestBase.importDstu3Observation (fhir.TestBase.importDstu3Observation)3 ShortCode (org.monarchinitiative.loinc2hpocore.codesystems.ShortCode)3 Collection (java.util.Collection)2 Coding (org.hl7.fhir.dstu3.model.Coding)2 CodeableConcept (org.hl7.fhir.dstu3.model.CodeableConcept)1 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)1 Coding (org.hl7.fhir.r4.model.Coding)1 CodeableConcept (org.hl7.fhir.r5.model.CodeableConcept)1 Coding (org.hl7.fhir.r5.model.Coding)1 TermId (org.monarchinitiative.phenol.ontology.data.TermId)1