Search in sources :

Example 51 with Use

use of org.hl7.fhir.r4.model.ExplanationOfBenefit.Use in project hl7v2-fhir-converter by LinuxForHealth.

the class HL7ConditionFHIRConversionTest method validateEncounterMultipleDiagnosesTestingMultipleDiagnosisAndReasonReferences.

// Tests that the Encounter has the full array of condition references in both
// diagnosis and reasonReference.
@Test
void validateEncounterMultipleDiagnosesTestingMultipleDiagnosisAndReasonReferences() {
    String hl7message = "MSH|^~\\&||||||S1|ADT^A01^ADT_A01||T|2.6|||||||||\r" + "EVN|A04||||||\r" + "PID|||1234^^^^MR||DOE^JANE^|||F||||||||||||||||||||||\r" + "PV1||I|||||||||||||||||1492|||||||||||||||||||||||||\r" + "DG1|1|D1|V72.83^Other specified pre-operative examination^ICD-9^^^|Other specified pre-operative examination|20151008111200|F|||||||||8|\r" + "DG1|2|D2|R00.0^Tachycardia, unspecified^ICD-10^^^|Tachycardia, unspecified|20150725201300|F|||||||||8|\r" + "DG1|3|D3|R06.02^Shortness of breath^ICD-10^^^|Shortness of breath||F|||||||||8|\r" + "DG1|4|D4|Q99.9^Chromosomal abnormality, unspecified^ICD-10^^^|Chromosomal abnormality, unspecified||F|||||||||8|\r" + "DG1|5|D5|I34.8^Arteriosclerosis^ICD-10^^^|Arteriosclerosis||F|||||||||8|\r" + "DG1|6|D6|I34.0^Mitral valve regurgitation^ICD-10^^^|Mitral valve regurgitation||F|||||||||8|\r" + "DG1|6|D7|I05.9^Mitral valve disorder in childbirth^ICD-10^^^|Mitral valve disorder in childbirth||F|||||||||8|\r" + "DG1|7|D8|J45.909^Unspecified asthma, uncomplicated^ICD-10^^^|Unspecified asthma, uncomplicated||F|||||||||8|\r";
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
    // Find the conditions from the FHIR bundle.
    List<Resource> conditionResource = ResourceUtils.getResourceList(e, ResourceType.Condition);
    // We should have 1 condition for each diagnosis therefore 8 for this message.
    assertThat(conditionResource).hasSize(8);
    // Find the encounter from the FHIR bundle.
    List<Resource> encounterResource = ResourceUtils.getResourceList(e, ResourceType.Encounter);
    // Verify we only have 1 encounter
    assertThat(encounterResource).hasSize(1);
    Encounter encounter = (Encounter) encounterResource.get(0);
    // Verify reasonReference has a reference for each condition. Therefore there should be 8.
    assertThat(encounter.getReasonReference()).hasSize(8);
    // Check the references are referencing conditions
    for (int i = 0; i < 8; i++) {
        assertThat(encounter.getReasonReference().get(i).getReference().substring(0, 10)).isEqualTo("Condition/");
    }
    // Verify there is encounter.diagnosis for every diagnosis. Therefore there should be 8.
    assertThat(encounter.getDiagnosis()).hasSize(8);
    List<String> referencedConditions = encounter.getDiagnosis().stream().map(i -> i.getCondition().getReference()).collect(Collectors.toList());
    List<String> condIdentifiers = conditionResource.stream().map(r -> (Condition) r).map(c -> c.getId()).collect(Collectors.toList());
    assertThat(referencedConditions).containsExactlyInAnyOrderElementsOf(condIdentifiers);
    // Verify each diagnosis is set correctly.
    for (int i = 0; i < 8; i++) {
        // Diagnosis requires a reference to condition.
        assertThat(encounter.getDiagnosis().get(i).getCondition().getReference().substring(0, 10)).isEqualTo("Condition/");
        // Verify Use coding of each diagnosis
        DatatypeUtils.checkCommonCodeableConceptAssertions(encounter.getDiagnosis().get(i).getUse(), "F", "Final", "http://terminology.hl7.org/CodeSystem/v2-0052", null);
        // Verify encounter diagnosis rank is set correctly.
        // DG1.15
        assertThat(encounter.getDiagnosis().get(i).getRank()).isEqualTo(8);
    }
}
Also used : ValueSource(org.junit.jupiter.params.provider.ValueSource) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Resource(org.hl7.fhir.r4.model.Resource) Condition(org.hl7.fhir.r4.model.Condition) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) Encounter(org.hl7.fhir.r4.model.Encounter) ResourceType(org.hl7.fhir.r4.model.ResourceType) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DatatypeUtils(io.github.linuxforhealth.hl7.segments.util.DatatypeUtils) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) ResourceUtils(io.github.linuxforhealth.hl7.segments.util.ResourceUtils) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) HL7ToFHIRConverter(io.github.linuxforhealth.hl7.HL7ToFHIRConverter) Practitioner(org.hl7.fhir.r4.model.Practitioner) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Resource(org.hl7.fhir.r4.model.Resource) Encounter(org.hl7.fhir.r4.model.Encounter) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 52 with Use

use of org.hl7.fhir.r4.model.ExplanationOfBenefit.Use in project hl7v2-fhir-converter by LinuxForHealth.

the class HL7EventTypeFHIRConversionTest method validate_evn_segment_no_period_override.

@Test
void validate_evn_segment_no_period_override() {
    String hl7message = "MSH|^~\\&|||||||ADT^A01^ADT_A01|64322|P|2.6|123|456|ER|AL|USA|ASCII|en|2.6||||||\r" + // + "EVN||||7525||20210319134735|\r"  // TODO, not working with this value
    "EVN||||O||20210319134735|\r" + "PV1|1|I||R|||||||||R|1||||||||||||||||||||||||||||||200603150624|200603150625|||||||";
    String json = ftv.convert(hl7message, OPTIONS);
    assertThat(json).isNotBlank();
    FHIRContext context = new FHIRContext();
    IBaseResource bundleResource = context.getParser().parseResource(json);
    assertThat(bundleResource).isNotNull();
    Bundle b = (Bundle) bundleResource;
    List<BundleEntryComponent> e = b.getEntry();
    // Find the encounter from the FHIR bundle.
    List<Resource> encounterResource = e.stream().filter(v -> ResourceType.Encounter == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
    assertThat(encounterResource).hasSize(1);
    Encounter encounter = (Encounter) encounterResource.get(0);
    // ENV.4 is used for reasonCode
    List<CodeableConcept> reasonCodes = encounter.getReasonCode();
    assertEquals(1, reasonCodes.size());
    CodeableConcept encounterReason = encounter.getReasonCodeFirstRep();
    Coding encounterReasonCoding = encounterReason.getCodingFirstRep();
    // assertThat(encounterReasonCoding.getCode()).isEqualTo("7525");  // TODO, should be able to use user-defined values
    assertThat(encounterReasonCoding.getCode()).isEqualTo("O");
    // EVN.6 is used for start period if there is no PV1.44 but since we have a
    // PV1.44 it should use that not EVN.6
    Base period = encounter.getNamedProperty("period").getValues().get(0);
    String startPeriod = period.getNamedProperty("start").getValues().get(0).toString();
    // And use PV1.45 for end period.
    String endPeriod = period.getNamedProperty("end").getValues().get(0).toString();
    assertThat(startPeriod).isEqualTo("DateTimeType[2006-03-15T06:24:00+08:00]");
    assertThat(endPeriod).isEqualTo("DateTimeType[2006-03-15T06:25:00+08:00]");
}
Also used : FHIRContext(io.github.linuxforhealth.fhir.FHIRContext) Bundle(org.hl7.fhir.r4.model.Bundle) Resource(org.hl7.fhir.r4.model.Resource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Base(org.hl7.fhir.r4.model.Base) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Coding(org.hl7.fhir.r4.model.Coding) Encounter(org.hl7.fhir.r4.model.Encounter) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.jupiter.api.Test)

Example 53 with Use

use of org.hl7.fhir.r4.model.ExplanationOfBenefit.Use in project hl7v2-fhir-converter by LinuxForHealth.

the class HL7EventTypeFHIRConversionTest method validate_evn_segment.

@Test
void validate_evn_segment() {
    String hl7message = "MSH|^~\\&|||||||ADT^A01^ADT_A01|64322|P|2.6|123|456|ER|AL|USA|ASCII|en|2.6||||||\r" + // + "EVN||||851||20210319134735|\r"  // TODO, not working with this value
    "EVN||||O||20210319134735|\r" + "PV1|1|I||R|||||||||R|1||||||||||||||||||||||||||||||||||||||";
    String json = ftv.convert(hl7message, OPTIONS);
    assertThat(json).isNotBlank();
    FHIRContext context = new FHIRContext(true, false);
    IBaseResource bundleResource = context.getParser().parseResource(json);
    assertThat(bundleResource).isNotNull();
    Bundle b = (Bundle) bundleResource;
    List<BundleEntryComponent> e = b.getEntry();
    // Find the encounter from the FHIR bundle.
    List<Resource> encounterResource = e.stream().filter(v -> ResourceType.Encounter == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
    assertThat(encounterResource).hasSize(1);
    Encounter encounter = (Encounter) encounterResource.get(0);
    // ENV.4 is used for reasonCode
    List<CodeableConcept> reasonCodes = encounter.getReasonCode();
    assertEquals(1, reasonCodes.size());
    CodeableConcept encounterReason = encounter.getReasonCodeFirstRep();
    Coding encounterReasonCoding = encounterReason.getCodingFirstRep();
    // assertThat(encounterReasonCoding.getCode()).isEqualTo("851");  // TODO, should be able to use user-defined values
    assertThat(encounterReasonCoding.getCode()).isEqualTo("O");
    // EVN.6 is used for start period (with no end) if there is no PV1.44
    Base period = encounter.getNamedProperty("period").getValues().get(0);
    String startPeriod = period.getNamedProperty("start").getValues().get(0).toString();
    int endPeriodSize = period.getNamedProperty("end").getValues().size();
    assertThat(startPeriod).isEqualTo("DateTimeType[2021-03-19T13:47:35+08:00]");
    assertThat(endPeriodSize).isZero();
}
Also used : FHIRContext(io.github.linuxforhealth.fhir.FHIRContext) Bundle(org.hl7.fhir.r4.model.Bundle) Resource(org.hl7.fhir.r4.model.Resource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Base(org.hl7.fhir.r4.model.Base) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Coding(org.hl7.fhir.r4.model.Coding) Encounter(org.hl7.fhir.r4.model.Encounter) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.jupiter.api.Test)

Example 54 with Use

use of org.hl7.fhir.r4.model.ExplanationOfBenefit.Use in project hl7v2-fhir-converter by LinuxForHealth.

the class HL7MergeFHIRConversionTest method validateHappyPathADT_A34WithMRG.

// Test ADT_A34 with one MRG segment (the most it supports).
@Test
void validateHappyPathADT_A34WithMRG() {
    String hl7message = "MSH|^~\\&|SENDING_APPLICATION|SENDING_FACILITY|RECEIVING_APPLICATION|RECEIVING_FACILITY|||ADT^A34||P|2.3||||\r" + "EVN|A40|20110613122406637||01\r" + // Identifier value 234 with no system and no identifier type
    "PID|1||123^^^^MR||||||||||||||||||||||||||||||||||||\r" + // Identifier value 456 with no system and no identifier type
    "MRG|456||||||\r";
    // Convert hl7 message
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
    // Find the patient resources in the FHIR bundle.
    List<Resource> patientResources = ResourceUtils.getResourceList(e, ResourceType.Patient);
    // There should be 2 - One for the PID segment and one for the MRG segment
    assertThat(patientResources).hasSize(2);
    // Get first patient and associated identifiers and id.
    Patient patientOne = PatientUtils.getPatientFromResource(patientResources.get(0));
    String patientOneId = patientOne.getId();
    List<Identifier> patientOneIdentifierList = patientOne.getIdentifier();
    // Get second patient and associated identifiers and id.
    Patient patientTwo = PatientUtils.getPatientFromResource(patientResources.get(1));
    String patientTwoId = patientTwo.getId();
    List<Identifier> patientTwoIdentifierList = patientTwo.getIdentifier();
    /*-----------Verify Patient One-----------*/
    // Verify patient one's identifier is set correctly (this is the patient build
    // from the PID segment)
    // 
    // "identifier":[
    // {
    // "type":{
    // "coding":[
    // {
    // "system":"http://terminology.hl7.org/CodeSystem/v2-0203",
    // "code":"MR",
    // "display":"Medical record number"
    // }
    // ]
    // },
    // "value":"123"
    // },
    // {
    // "use":"old",
    // "value":"456"
    // }
    // ]
    // Verify the patient has two identifiers
    assertThat(patientOneIdentifierList).hasSize(2);
    // Verify the identifier values are correct.
    assertThat(patientOneIdentifierList.get(0).getValue()).isEqualTo("123");
    assertThat(patientOneIdentifierList.get(1).getValue()).isEqualTo("456");
    // Verify the system values are not present
    assertThat(patientOneIdentifierList.get(0).getSystem()).isNull();
    assertThat(patientOneIdentifierList.get(1).getSystem()).isNull();
    // Verify the first identifier has no use field.
    assertThat(patientOneIdentifierList.get(0).getUse()).isNull();
    // Verify the second identifier is marked as old
    assertThat(patientOneIdentifierList.get(1).getUse()).isEqualTo(Identifier.IdentifierUse.OLD);
    // Verify identifier type is set correctly for the first identifier
    CodeableConcept patientOneIdentifierType = patientOneIdentifierList.get(0).getType();
    assertThat(patientOneIdentifierType.getCoding().get(0).getSystem()).isEqualTo("http://terminology.hl7.org/CodeSystem/v2-0203");
    assertThat(patientOneIdentifierType.getCoding().get(0).getDisplay()).isEqualTo("Medical record number");
    assertThat(patientOneIdentifierType.getCoding().get(0).getCode()).isEqualTo("MR");
    // Verify the identifier type for the second identifier is not present.
    assertThat(patientOneIdentifierList.get(1).getType().getCoding()).isEmpty();
    // Verify first patient has these fields
    // 
    // "active":true,
    // "link":[
    // {
    // "other":{
    // "reference":"Patient/expiringID-MRG"
    // },
    // "type":"replaces"
    // }
    // ]
    // The first patient should be active.
    assertThat(patientOne.getActive()).isTrue();
    // Verify link.other.reference references the MRG (2nd) patient with of a type of 'replaces'
    PatientLinkComponent linkOne = patientOne.getLink().get(0);
    assertThat(linkOne.getType()).isEqualTo(Patient.LinkType.REPLACES);
    assertThat(linkOne.getOther().getReference()).isEqualTo(patientTwoId);
    /*-----------Verify Patient Two-----------*/
    // Verify patient two's identifier is set correctly (this is the patient build
    // from the MRG segment)
    // 
    // "identifier":[
    // {
    // "use":"old",
    // "value":"456"
    // }
    // ]
    // Verify has only 1 identifier
    assertThat(patientTwoIdentifierList).hasSize(1);
    // Verify the identifier value is correct.
    assertThat(patientTwoIdentifierList.get(0).getValue()).isEqualTo("456");
    // Verify the system is not present
    assertThat(patientTwoIdentifierList.get(0).getSystem()).isNull();
    // Verify the identifier is marked as old
    assertThat(patientTwoIdentifierList.get(0).getUse()).isEqualTo(Identifier.IdentifierUse.OLD);
    // Verify identifier type is not present
    assertThat(patientTwoIdentifierList.get(0).getType().getCoding()).isEmpty();
    // Verify second patient has these fields.
    // "active":false,
    // "link":[
    // {
    // "other":{
    // "reference":"Patient/survivingID"
    // },
    // "type":"replaced-by"
    // }
    // ]
    // The second patient should NOT be active.
    assertThat(patientTwo.getActive()).isFalse();
    // We should have link.other.reference to the PID (1st) patient with a type of 'replaced-by'
    PatientLinkComponent linkTwo = patientTwo.getLink().get(0);
    assertThat(linkTwo.getType()).isEqualTo(Patient.LinkType.REPLACEDBY);
    assertThat(linkTwo.getOther().getReference()).isEqualTo(patientOneId);
    ;
}
Also used : BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Identifier(org.hl7.fhir.r4.model.Identifier) Resource(org.hl7.fhir.r4.model.Resource) Patient(org.hl7.fhir.r4.model.Patient) PatientLinkComponent(org.hl7.fhir.r4.model.Patient.PatientLinkComponent) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.jupiter.api.Test)

Example 55 with Use

use of org.hl7.fhir.r4.model.ExplanationOfBenefit.Use in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7MDMMessageTest method test_mdm_ORDER_with_OBXnotTX.

@ParameterizedTest
@ValueSource(strings = { "MDM^T02", "MDM^T06" })
void test_mdm_ORDER_with_OBXnotTX(String message) throws IOException {
    // Also check NTE working for MDM messages.
    String hl7message = "MSH|^~\\&|HNAM|W|RAD_IMAGING_REPORT|W|20180118111520||" + message + "|<MESSAGEID>|P|2.6\r" + "EVN||20150502090000|\r" + "PID|||1234^^^^MR||DOE^JANE^|||F||||||||||||||||||||||\r" + "PV1||O||||||||||||||||||||||||||||||||||||||||||199501102300\r" + "ORC|NW|622470H432|||||^^^^^R||||||||||||||\r" + "OBR|1|622470H432|102397CE432|||20170725143849|20180102|||||||||||||||||RAD|O||^^^^^R||||REASON_ID_1^REASON_TEXT_1||||\r" + // ServiceRequest NTE has a practitioner reference in NTE.5
    "NTE|1|O|TEST ORC/OBR NOTE AA line 1||Pract1ID^Pract1Last^Pract1First|\n" + "NTE|2|O|TEST NOTE AA line 2|\n" + "TXA|1|HP^History and physical examination|TX||||201801171442||||||||||||AV|||||\r" + "OBX|1|NM|Most Current Weight^Most current measured weight (actual)||90|kg\r" + // Observation NTE has a practitioner reference in second NTE.5. Annotation uses the first valid NTE.5
    "NTE|1|L|TEST OBX NOTE BB line 1|\n" + "NTE|2|L|TEST NOTE BB line 2||Pract2ID^Pract2Last^Pract2First|\n";
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
    // Check for the expected resources
    List<Resource> encounterResource = ResourceUtils.getResourceList(e, ResourceType.Encounter);
    // from EVN, PV1
    assertThat(encounterResource).hasSize(1);
    List<Resource> patientResource = ResourceUtils.getResourceList(e, ResourceType.Patient);
    // from PID
    assertThat(patientResource).hasSize(1);
    List<Resource> serviceRequestResource = ResourceUtils.getResourceList(e, ResourceType.ServiceRequest);
    // from ORC, OBR
    assertThat(serviceRequestResource).hasSize(1);
    // Light check that ServiceRequest contains NTE for ORC/OBR;  Deep check of NTE in Hl7NoteFHIRConverterTest.
    ServiceRequest serviceRequest = ResourceUtils.getResourceServiceRequest(serviceRequestResource.get(0), ResourceUtils.context);
    assertThat(serviceRequest.hasNote()).isTrue();
    assertThat(serviceRequest.getNote()).hasSize(1);
    // NOTE: the note contains an Annotation, which contains a MarkdownType that has the string.
    // Must use getTextElement().getValueAsString() to see untrimmed contents.
    assertThat(serviceRequest.getNote().get(0).getTextElement().getValueAsString()).isEqualTo("TEST ORC/OBR NOTE AA line 1  \nTEST NOTE AA line 2");
    assertThat(serviceRequest.getNote().get(0).hasAuthorReference()).isTrue();
    List<Resource> documentReferenceResource = ResourceUtils.getResourceList(e, ResourceType.DocumentReference);
    // from TXA
    assertThat(documentReferenceResource).hasSize(1);
    List<Resource> observationResources = ResourceUtils.getResourceList(e, ResourceType.Observation);
    // from OBX(not type TX)
    assertThat(observationResources).hasSize(1);
    // Light check that Observation contains NTE for OBX;  Deep check of NTE in Hl7NoteFHIRConverterTest.
    Observation observation = ResourceUtils.getResourceObservation(observationResources.get(0), ResourceUtils.context);
    // Validate the note contents and reference existance.
    assertThat(observation.hasNote()).isTrue();
    assertThat(observation.getNote()).hasSize(1);
    // NOTE: the note contains an Annotation, which contains a MarkdownType that has the string.
    // Must use getTextElement().getValueAsString() to see untrimmed contents.
    assertThat(observation.getNote().get(0).getTextElement().getValueAsString()).isEqualTo("TEST OBX NOTE BB line 1  \nTEST NOTE BB line 2");
    assertThat(observation.getNote().get(0).hasAuthorReference()).isTrue();
    // Two Practitioners, one for the serviceRequest, one for the Observation
    List<Resource> practitioners = ResourceUtils.getResourceList(e, ResourceType.Practitioner);
    // from NTE.4 references
    assertThat(practitioners).hasSize(2);
    // Confirm that no extra resources are created
    assertThat(e.size()).isEqualTo(7);
}
Also used : BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Resource(org.hl7.fhir.r4.model.Resource) Observation(org.hl7.fhir.r4.model.Observation) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ArrayList (java.util.ArrayList)82 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)43 List (java.util.List)41 FHIRException (org.hl7.fhir.exceptions.FHIRException)40 Date (java.util.Date)39 IOException (java.io.IOException)38 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)35 Test (org.junit.jupiter.api.Test)35 Resource (org.hl7.fhir.r4.model.Resource)34 Collectors (java.util.stream.Collectors)29 Coding (org.hl7.fhir.r4.model.Coding)27 Reference (org.hl7.fhir.r4.model.Reference)27 Timer (com.codahale.metrics.Timer)26 HashMap (java.util.HashMap)25 Bundle (org.hl7.fhir.r4.model.Bundle)25 Reference (org.hl7.fhir.dstu3.model.Reference)24 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)23 CodeableConcept (org.hl7.fhir.dstu3.model.CodeableConcept)21 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)21 JsonObject (com.google.gson.JsonObject)20