Search in sources :

Example 1 with ConditionEvidenceComponent

use of org.hl7.fhir.r4.model.Condition.ConditionEvidenceComponent in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7NoteFHIRConverterTest method testNoteCreationMutiplePPR.

// Test that multiple problems (PRB) each with multiple notes (NTE) are associated with the correct NTE / PRB
// and that there is no "bleed"
@Test
void testNoteCreationMutiplePPR() throws IOException {
    // TODO: Add PC2 and PC3 tests in future
    String message = "PPR^PC1";
    String hl7message = "MSH|^~\\&|SendTest1|Sendfac1|Receiveapp1|Receivefac1|200603081747|security|" + message + "|1|P^I|2.6||||||ASCII||\n" + "PID|||555444222111^^^MPI&GenHosp&L^MR||james^anderson|||M||||||||||||||\n" + "PV1||I|||||||||||||||||1400|||||||||||||||||||||||||199501102300\n" + "PRB|AD|200603150625|aortic stenosis|53692||2||200603150625\n" + "NTE|1|O|TEST PRBa NOTE AA line 1|\n" + "NTE|2|O|TEST NOTE AA line 2|\n" + "NTE|3|O|TEST NOTE AA line 3|\n" + "OBX|1|NM|17985^GLYCOHEMOGLOBIN HGB A1C^LRR^^^^^^GLYCOHEMOGLOBIN HGB A1C||5.6|%|<6.0||||F||||||||||||||\n" + "NTE|1|L|TEST OBXb NOTE BB line 1|\n" + "NTE|2|L|TEST NOTE BB line 2|\n" + "NTE|3|L|TEST NOTE BB line 3|\n" + "OBX|2|NM|17853^MEAN BLOOD GLUCOSE^LRR^^^^^^MEAN BLOOD GLUCOSE||114.02|mg/dL|||||F||||||||||||||\n" + "NTE|1|L|TEST OBXc NOTE CC line 1|\n" + "NTE|2|L|TEST NOTE CC line 2|\n" + "NTE|3|L|TEST NOTE CC line 3|\n" + "PRB|AD|200603150625|I47.2^Ventricular tachycardia^ICD-10-CM|53692||2||200603150625\n" + "NTE|1|O|TEST PRBd NOTE DD line 1|\n" + "NTE|2|O|TEST NOTE DD line 2|\n" + "NTE|3|O|TEST NOTE DD line 3|\n" + "OBX|1|NM|8595^BP Mean|1|88|MM HG|||||F|||20180520230000|||\n" + "NTE|1|L|TEST OBXe NOTE EE line 1|\n" + "NTE|2|L|TEST NOTE EE line 2|\n" + "NTE|3|L|TEST NOTE EE line 3|\n" + "OBX|2|NM|7302^Resp Rate|1|19||||||F|||20180520230000|||\n" + // Single NTE to ensure it is created correctly
    "NTE|1|L|TEST OBXf NOTE FF line 1|\n";
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
    List<Resource> patients = ResourceUtils.getResourceList(e, ResourceType.Patient);
    assertThat(patients).hasSize(1);
    // Two Conditions from two PRBs. One has "... stenosis" and notes AA, One has "... Tachycardia" and notes DD
    List<Resource> conditions = ResourceUtils.getResourceList(e, ResourceType.Condition);
    assertThat(conditions).hasSize(2);
    Condition condStenosis = ResourceUtils.getResourceCondition(conditions.get(0), ResourceUtils.context);
    Condition condTachy = ResourceUtils.getResourceCondition(conditions.get(1), ResourceUtils.context);
    // Figure out which is first and reassign if needed for testing
    if (!condStenosis.getCode().getCodingFirstRep().getCode().contains("aortic stenosis")) {
        Condition temp = condStenosis;
        condStenosis = condTachy;
        condTachy = temp;
    }
    // Test the conditions have the correct NTE's associated and have correct content.
    // NOTE: the note contains an Annotation, which contains a MarkdownType that has the string.
    // Must use getTextElement().getValueAsString() to see untrimmed contents.
    assertThat(condStenosis.hasNote()).isTrue();
    assertThat(condStenosis.getNote()).hasSize(1);
    assertThat(condStenosis.getNote().get(0).getTextElement().getValueAsString()).isEqualTo("TEST PRBa NOTE AA line 1  \nTEST NOTE AA line 2  \nTEST NOTE AA line 3");
    assertThat(condTachy.hasNote()).isTrue();
    assertThat(condTachy.getNote()).hasSize(1);
    assertThat(condTachy.getNote().get(0).getTextElement().getValueAsString()).isEqualTo("TEST PRBd NOTE DD line 1  \nTEST NOTE DD line 2  \nTEST NOTE DD line 3");
    // Four observations.  Two associated with the first problem and two with the second
    // This map tells us what Annotation text is associated with an Observation code
    Map<String, String> matchObsCodeToNotes = new HashMap<>();
    matchObsCodeToNotes.put("17985", "TEST OBXb NOTE BB line 1  \nTEST NOTE BB line 2  \nTEST NOTE BB line 3");
    matchObsCodeToNotes.put("17853", "TEST OBXc NOTE CC line 1  \nTEST NOTE CC line 2  \nTEST NOTE CC line 3");
    matchObsCodeToNotes.put("8595", "TEST OBXe NOTE EE line 1  \nTEST NOTE EE line 2  \nTEST NOTE EE line 3");
    matchObsCodeToNotes.put("7302", "TEST OBXf NOTE FF line 1");
    // This map tells us what Parent should be associated with an Observation code
    Map<String, String> matchObsCodeToParent = new HashMap<>();
    matchObsCodeToParent.put("17985", "aortic stenosis");
    matchObsCodeToParent.put("17853", "aortic stenosis");
    matchObsCodeToParent.put("8595", "I47.2");
    matchObsCodeToParent.put("7302", "I47.2");
    List<Resource> observations = ResourceUtils.getResourceList(e, ResourceType.Observation);
    assertThat(observations).hasSize(4);
    int observationsVerified = 0;
    // For the list of Conditions
    for (int condIndex = 0; condIndex < conditions.size(); condIndex++) {
        // condIndex is index for condition
        // Get the list of Observation references
        Condition cond = ResourceUtils.getResourceCondition(conditions.get(condIndex), ResourceUtils.context);
        List<ConditionEvidenceComponent> evidences = cond.getEvidence();
        for (int evidenceIndex = 0; evidenceIndex < evidences.size(); evidenceIndex++) {
            // Get the evidence Observation reference
            String obsReferenceId = evidences.get(evidenceIndex).getDetailFirstRep().getReference();
            // Find the referenced observation
            for (int obsIndex = 0; obsIndex < observations.size(); obsIndex++) {
                // If the Id's match
                if (obsReferenceId.contains(observations.get(obsIndex).getId())) {
                    // Check the contents and the parent
                    Observation obs = ResourceUtils.getResourceObservation(observations.get(obsIndex), ResourceUtils.context);
                    String code = obs.getCode().getCodingFirstRep().getCode().toString();
                    // The Annotation text should match the mapped text for this key
                    assertThat(obs.getNoteFirstRep().getText()).hasToString(matchObsCodeToNotes.get(code));
                    // The parent Condition code.coding.code should match the expected mapped code for this key
                    assertThat(cond.getCode().getCodingFirstRep().getCode()).hasToString(matchObsCodeToParent.get(code));
                    observationsVerified++;
                    break;
                }
            }
        }
    }
    // This confirms ALL of the observations were checked.
    assertThat(observationsVerified).isEqualTo(4);
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) ConditionEvidenceComponent(org.hl7.fhir.r4.model.Condition.ConditionEvidenceComponent) HashMap(java.util.HashMap) Resource(org.hl7.fhir.r4.model.Resource) Observation(org.hl7.fhir.r4.model.Observation) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with ConditionEvidenceComponent

use of org.hl7.fhir.r4.model.Condition.ConditionEvidenceComponent in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7MessageTest method test_observation_condition.

@Test
void test_observation_condition() throws IOException {
    ResourceModel obsModel = ResourceReader.getInstance().generateResourceModel("resource/Observation");
    HL7FHIRResourceTemplateAttributes attributesObs = new HL7FHIRResourceTemplateAttributes.Builder().withResourceName("Observation").withResourceModel(obsModel).withSegment(".PROBLEM_OBSERVATION.OBX").withIsReferenced(true).withRepeats(true).withGroup("PROBLEM").build();
    HL7FHIRResourceTemplate obsTemplate = new HL7FHIRResourceTemplate(attributesObs);
    ResourceModel condModel = ResourceReader.getInstance().generateResourceModel("resource/Condition");
    HL7FHIRResourceTemplateAttributes attributesCond = new HL7FHIRResourceTemplateAttributes.Builder().withResourceName("Condition").withResourceModel(condModel).withSegment(".PRB").withIsReferenced(false).withRepeats(true).withGroup("PROBLEM").build();
    HL7FHIRResourceTemplate conditionTemplate = new HL7FHIRResourceTemplate(attributesCond);
    HL7MessageModel message = new HL7MessageModel("ADT", Lists.newArrayList(obsTemplate, conditionTemplate));
    String hl7message = "MSH|^~\\&|SendTest1|Sendfac1|Receiveapp1|Receivefac1|200603081747|security|PPR^PC1^PPR_PC1|1|P^I|2.6||||||ASCII||\r" + "PID|||555444222111^^^MPI&GenHosp&L^MR||james^anderson||19600614|M||C|99 Oakland #106^^qwerty^OH^44889||^^^^^626^5641111|^^^^^626^5647654|||||343132266|||N\r" + "PV1||I|6N^1234^A^GENHOS||||0100^ANDERSON^CARL|0148^ADDISON^JAMES||SUR|||||||0148^ANDERSON^CARL|S|1400|A|||||||||||||||||||SF|K||||199501102300\r" + "PRB|AD|200603150625|aortic stenosis|53692||2||200603150625\r" + "NTE|1|P|Problem Comments\r" + "VAR|varid1|200603150610\r" + // Two observation records
    "OBX|1|ST|0135-4^TotalProtein||6.4|gm/dl|5.9-8.4||||F|||||2740^Tsadok^Janetary~2913^Merrit^Darren^F|\r" + "OBX|2|ST|0135-4^TotalProtein||7.8|gm/dl|5.9-8.4||||F|||||2740^Tsadok^Janetary~2913^Merrit^Darren^F|\r";
    String json = message.convert(hl7message, engine);
    assertThat(json).isNotBlank();
    IBaseResource bundleResource = context.getParser().parseResource(json);
    assertThat(bundleResource).isNotNull();
    Bundle b = (Bundle) bundleResource;
    List<BundleEntryComponent> e = b.getEntry();
    List<Resource> observationResource = e.stream().filter(v -> ResourceType.Observation == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
    assertThat(observationResource).hasSize(2);
    List<String> ids = observationResource.stream().map(m -> m.getId()).collect(Collectors.toList());
    List<Resource> conditionResource = e.stream().filter(v -> ResourceType.Condition == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
    assertThat(conditionResource).hasSize(1);
    Condition cond = ResourceUtils.getResourceCondition(conditionResource.get(0), context);
    List<ConditionEvidenceComponent> evidences = cond.getEvidence();
    assertThat(evidences).hasSize(2);
    assertThat(evidences.get(0).hasDetail()).isTrue();
    assertThat(evidences.get(0).getDetail().get(0).getReference()).isIn(ids);
    assertThat(evidences.get(1).getDetail().get(0).getReference()).isIn(ids);
    assertThat(evidences.get(0).getDetail().get(0).getReference()).isNotEqualTo(evidences.get(1).getDetail().get(0).getReference());
}
Also used : Specimen(org.hl7.fhir.r4.model.Specimen) Logger(org.slf4j.Logger) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LoggerFactory(org.slf4j.LoggerFactory) Resource(org.hl7.fhir.r4.model.Resource) IOException(java.io.IOException) Condition(org.hl7.fhir.r4.model.Condition) Reference(org.hl7.fhir.r4.model.Reference) Collectors(java.util.stream.Collectors) ResourceReader(io.github.linuxforhealth.hl7.resource.ResourceReader) Test(org.junit.jupiter.api.Test) Encounter(org.hl7.fhir.r4.model.Encounter) ResourceType(org.hl7.fhir.r4.model.ResourceType) List(java.util.List) Lists(com.google.common.collect.Lists) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) ResourceUtils(io.github.linuxforhealth.hl7.segments.util.ResourceUtils) Bundle(org.hl7.fhir.r4.model.Bundle) ConditionEvidenceComponent(org.hl7.fhir.r4.model.Condition.ConditionEvidenceComponent) ResourceModel(io.github.linuxforhealth.api.ResourceModel) FHIRContext(io.github.linuxforhealth.fhir.FHIRContext) MessageHeader(org.hl7.fhir.r4.model.MessageHeader) Observation(org.hl7.fhir.r4.model.Observation) Condition(org.hl7.fhir.r4.model.Condition) ConditionEvidenceComponent(org.hl7.fhir.r4.model.Condition.ConditionEvidenceComponent) Bundle(org.hl7.fhir.r4.model.Bundle) Resource(org.hl7.fhir.r4.model.Resource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) ResourceModel(io.github.linuxforhealth.api.ResourceModel) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Test(org.junit.jupiter.api.Test)

Example 3 with ConditionEvidenceComponent

use of org.hl7.fhir.r4.model.Condition.ConditionEvidenceComponent in project Gravity-SDOH-Exchange-RI by FHIR.

the class ConditionInfoBundleExtractor method extract.

@Override
public List<? extends ConditionInfoHolder> extract(Bundle bundle) {
    Map<String, Observation> allObservations = FhirUtil.getFromBundle(bundle, Observation.class).stream().collect(Collectors.toMap(observation -> observation.getIdElement().getIdPart(), Function.identity()));
    Map<String, QuestionnaireResponse> allQuestionnaireResponses = FhirUtil.getFromBundle(bundle, QuestionnaireResponse.class).stream().collect(Collectors.toMap(qr -> qr.getIdElement().getIdPart(), Function.identity()));
    Map<String, Questionnaire> allQuestionnaires = FhirUtil.getFromBundle(bundle, Questionnaire.class).stream().collect(Collectors.toMap(q -> q.getUrl(), Function.identity()));
    return FhirUtil.getFromBundle(bundle, Condition.class).stream().map(condition -> {
        Reference evidenceReference = condition.getEvidence().stream().map(ConditionEvidenceComponent::getDetail).flatMap(Collection::stream).findFirst().orElse(null);
        QuestionnaireResponse questionnaireResponse = null;
        Questionnaire questionnaire = null;
        List<Observation> observations = new ArrayList<>();
        if (evidenceReference != null) {
            Observation evidenceObservation = allObservations.remove(evidenceReference.getReferenceElement().getIdPart());
            observations.add(evidenceObservation);
            questionnaireResponse = allQuestionnaireResponses.get(findQuestionnaireResponseId(evidenceObservation));
            String questionnaireResponseId = questionnaireResponse.getIdElement().getIdPart();
            Iterator<Entry<String, Observation>> iterator = allObservations.entrySet().iterator();
            while (iterator.hasNext()) {
                Entry<String, Observation> observationEntry = iterator.next();
                Observation value = observationEntry.getValue();
                if (containsQuestionnaireReference(value, questionnaireResponseId)) {
                    observations.add(value);
                    iterator.remove();
                }
            }
            questionnaire = allQuestionnaires.get(questionnaireResponse.getQuestionnaire());
        }
        return new ConditionInfoHolder(condition, questionnaire, questionnaireResponse, observations);
    }).collect(Collectors.toList());
}
Also used : Getter(lombok.Getter) Iterator(java.util.Iterator) Collection(java.util.Collection) Condition(org.hl7.fhir.r4.model.Condition) ConditionInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.ConditionInfoBundleExtractor.ConditionInfoHolder) Reference(org.hl7.fhir.r4.model.Reference) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse) List(java.util.List) Map(java.util.Map) Entry(java.util.Map.Entry) Bundle(org.hl7.fhir.r4.model.Bundle) ConditionEvidenceComponent(org.hl7.fhir.r4.model.Condition.ConditionEvidenceComponent) AllArgsConstructor(lombok.AllArgsConstructor) Observation(org.hl7.fhir.r4.model.Observation) Questionnaire(org.hl7.fhir.r4.model.Questionnaire) FhirUtil(org.hl7.gravity.refimpl.sdohexchange.util.FhirUtil) Condition(org.hl7.fhir.r4.model.Condition) Questionnaire(org.hl7.fhir.r4.model.Questionnaire) ConditionEvidenceComponent(org.hl7.fhir.r4.model.Condition.ConditionEvidenceComponent) Reference(org.hl7.fhir.r4.model.Reference) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse) Entry(java.util.Map.Entry) Observation(org.hl7.fhir.r4.model.Observation) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) ConditionInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.ConditionInfoBundleExtractor.ConditionInfoHolder)

Aggregations

Condition (org.hl7.fhir.r4.model.Condition)3 ConditionEvidenceComponent (org.hl7.fhir.r4.model.Condition.ConditionEvidenceComponent)3 Observation (org.hl7.fhir.r4.model.Observation)3 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Bundle (org.hl7.fhir.r4.model.Bundle)2 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)2 Reference (org.hl7.fhir.r4.model.Reference)2 Resource (org.hl7.fhir.r4.model.Resource)2 Test (org.junit.jupiter.api.Test)2 Lists (com.google.common.collect.Lists)1 ResourceModel (io.github.linuxforhealth.api.ResourceModel)1 FHIRContext (io.github.linuxforhealth.fhir.FHIRContext)1 ResourceReader (io.github.linuxforhealth.hl7.resource.ResourceReader)1 ResourceUtils (io.github.linuxforhealth.hl7.segments.util.ResourceUtils)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1