Search in sources :

Example 1 with FHIRContext

use of io.github.linuxforhealth.fhir.FHIRContext 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 2 with FHIRContext

use of io.github.linuxforhealth.fhir.FHIRContext 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 3 with FHIRContext

use of io.github.linuxforhealth.fhir.FHIRContext 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 4 with FHIRContext

use of io.github.linuxforhealth.fhir.FHIRContext in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7ORUMessageTest method test_ORU_r01_without_status.

@Test
void test_ORU_r01_without_status() throws IOException {
    String ORU_r01 = "MSH|^~\\&|NIST Test Lab APP|NIST Lab Facility||NIST EHR Facility|20150926140551||ORU^R01|NIST-LOI_5.0_1.1-NG|T|2.5.1|||AL|AL|||||\r" + "PID|1||PATID5421^^^NISTMPI^MR||Wilson^Patrice^Natasha^^^^L||19820304|F||2106-3^White^HL70005|144 East 12th Street^^Los Angeles^CA^90012^^H||^PRN^PH^^^203^2290210|||||||||N^Not Hispanic or Latino^HL70189\r" + "ORC|NW|ORD448811^NIST EHR|R-511^NIST Lab Filler||||||20120628070100|||5742200012^Radon^Nicholas^^^^^^NPI^L^^^NPI\r" + "OBR|1|ORD448811^NIST EHR|R-511^NIST Lab Filler|1000^Hepatitis A B C Panel^99USL|||20120628070100|||||||||5742200012^Radon^Nicholas^^^^^^NPI^L^^^NPI\r" + "OBX|1|CWE|22314-9^Hepatitis A virus IgM Ab [Presence] in Serum^LN^HAVM^Hepatitis A IgM antibodies (IgM anti-HAV)^L^2.52||260385009^Negative (qualifier value)^SCT^NEG^NEGATIVE^L^201509USEd^^Negative (qualifier value)||Negative|N|||F|||20150925|||||201509261400\r" + "OBX|2|CWE|20575-7^Hepatitis A virus Ab [Presence] in Serum^LN^HAVAB^Hepatitis A antibodies (anti-HAV)^L^2.52||260385009^Negative (qualifier value)^SCT^NEG^NEGATIVE^L^201509USEd^^Negative (qualifier value)||Negative|N|||F|||20150925|||||201509261400\r" + "OBX|3|NM|22316-4^Hepatitis B virus core Ab [Units/volume] in Serum^LN^HBcAbQ^Hepatitis B core antibodies (anti-HBVc) Quant^L^2.52||0.70|[IU]/mL^international unit per milliliter^UCUM^IU/ml^^L^1.9|<0.50 IU/mL|H|||F|||20150925|||||201509261400";
    String json = ftv.convert(ORU_r01, OPTIONS);
    FHIRContext context = new FHIRContext();
    IBaseResource bundleResource = context.getParser().parseResource(json);
    assertThat(bundleResource).isNotNull();
    Bundle b = (Bundle) bundleResource;
    List<BundleEntryComponent> e = b.getEntry();
    List<Resource> diagnosticReport = ResourceUtils.getResourceList(e, ResourceType.DiagnosticReport);
    assertThat(diagnosticReport).hasSize(1);
    String s = context.getParser().encodeResourceToString(diagnosticReport.get(0));
    Class<? extends IBaseResource> klass = DiagnosticReport.class;
    DiagnosticReport expectStatusUnknown = (DiagnosticReport) context.getParser().parseResource(klass, s);
    DiagnosticReport.DiagnosticReportStatus status = expectStatusUnknown.getStatus();
    assertThat(expectStatusUnknown.hasStatus()).isTrue();
    assertThat(status).isEqualTo(DiagnosticReport.DiagnosticReportStatus.UNKNOWN);
}
Also used : FHIRContext(io.github.linuxforhealth.fhir.FHIRContext) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.r4.model.Bundle) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Resource(org.hl7.fhir.r4.model.Resource) DiagnosticReport(org.hl7.fhir.r4.model.DiagnosticReport) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Test(org.junit.jupiter.api.Test)

Example 5 with FHIRContext

use of io.github.linuxforhealth.fhir.FHIRContext in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7CustomMessageTest method getBundleEntryFromHL7Message.

// Need custom convert sequence with options that turn off FHIR validation.
private static List<BundleEntryComponent> getBundleEntryFromHL7Message(String hl7message) {
    // Testing loading of config which happens once per instantiation
    HL7ToFHIRConverter ftv = new HL7ToFHIRConverter();
    // Need custom options that turn off FHIR validation.
    String json = ftv.convert(hl7message, OPTIONS);
    assertThat(json).isNotNull();
    FHIRContext context = new FHIRContext();
    IBaseResource bundleResource = context.getParser().parseResource(json);
    assertThat(bundleResource).isNotNull();
    Bundle b = (Bundle) bundleResource;
    return b.getEntry();
}
Also used : FHIRContext(io.github.linuxforhealth.fhir.FHIRContext) HL7ToFHIRConverter(io.github.linuxforhealth.hl7.HL7ToFHIRConverter) Bundle(org.hl7.fhir.r4.model.Bundle) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource)

Aggregations

FHIRContext (io.github.linuxforhealth.fhir.FHIRContext)15 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)14 Bundle (org.hl7.fhir.r4.model.Bundle)14 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)13 Resource (org.hl7.fhir.r4.model.Resource)12 Test (org.junit.jupiter.api.Test)10 Coding (org.hl7.fhir.r4.model.Coding)5 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)3 DiagnosticReport (org.hl7.fhir.r4.model.DiagnosticReport)3 Encounter (org.hl7.fhir.r4.model.Encounter)3 Observation (org.hl7.fhir.r4.model.Observation)3 Message (ca.uhn.hl7v2.model.Message)2 Hl7InputStreamMessageStringIterator (ca.uhn.hl7v2.util.Hl7InputStreamMessageStringIterator)2 HL7HapiParser (io.github.linuxforhealth.hl7.parsing.HL7HapiParser)2 File (java.io.File)2 InputStream (java.io.InputStream)2 Attachment (org.hl7.fhir.r4.model.Attachment)2 Base (org.hl7.fhir.r4.model.Base)2 Immunization (org.hl7.fhir.r4.model.Immunization)2 Reference (org.hl7.fhir.r4.model.Reference)2