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());
}
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]");
}
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();
}
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);
}
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();
}
Aggregations