Search in sources :

Example 31 with BundleEntryComponent

use of org.hl7.fhir.r4.model.Bundle.BundleEntryComponent in project hl7v2-fhir-converter by LinuxForHealth.

the class HL7EventTypeFHIRConversionTest method validateEVNsegmentWithOBXreference.

@Test
void validateEVNsegmentWithOBXreference() {
    // When there is an OBX record, it should create a reason reference in the encounter segment
    String hl7message = "MSH|^~\\&|||||||ADT^A01^ADT_A01|64322|P|2.6|123|456|ER|AL|USA|ASCII|en|2.6||||||\r" + "EVN||||7525|||\r" + "PV1|1|I||R|||||||||R|1||||||||||||||||||||||||||||||200603150624|200603150625|||||||\r" + "OBX|1|CWE|DQW^Some text 1^SNM3|||||||||||||||||||||\r";
    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 Observation in the bundle
    List<Resource> obsResource = e.stream().filter(v -> ResourceType.Observation == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
    assertThat(obsResource).hasSize(1);
    Observation obs = (Observation) obsResource.get(0);
    // 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);
    assertThat(encounter.hasReasonReference()).isTrue();
    assertThat(encounter.getReasonReference()).hasSize(1);
    // Check that the cross reference is equal to the Observation id
    assertThat(encounter.getReasonReferenceFirstRep().getReference()).hasToString(obs.getId());
}
Also used : FHIRContext(io.github.linuxforhealth.fhir.FHIRContext) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.r4.model.Bundle) Resource(org.hl7.fhir.r4.model.Resource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Observation(org.hl7.fhir.r4.model.Observation) Encounter(org.hl7.fhir.r4.model.Encounter) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Test(org.junit.jupiter.api.Test)

Example 32 with BundleEntryComponent

use of org.hl7.fhir.r4.model.Bundle.BundleEntryComponent 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 33 with BundleEntryComponent

use of org.hl7.fhir.r4.model.Bundle.BundleEntryComponent 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 34 with BundleEntryComponent

use of org.hl7.fhir.r4.model.Bundle.BundleEntryComponent 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 35 with BundleEntryComponent

use of org.hl7.fhir.r4.model.Bundle.BundleEntryComponent 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

BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)250 Resource (org.hl7.fhir.r4.model.Resource)163 Test (org.junit.jupiter.api.Test)126 Bundle (org.hl7.fhir.r4.model.Bundle)107 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)92 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)88 ArrayList (java.util.ArrayList)62 Date (java.util.Date)52 Reference (org.hl7.fhir.r4.model.Reference)51 BundleEntryComponent (org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent)47 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)42 Observation (org.hl7.fhir.r4.model.Observation)36 IOException (java.io.IOException)35 Patient (org.hl7.fhir.r4.model.Patient)35 Test (org.junit.Test)35 BundleEntryComponent (org.hl7.fhir.r5.model.Bundle.BundleEntryComponent)34 MedicationRequest (org.hl7.fhir.r4.model.MedicationRequest)33 Condition (org.hl7.fhir.r4.model.Condition)32 Encounter (org.hl7.fhir.r4.model.Encounter)31 Coding (org.hl7.fhir.r4.model.Coding)29