use of org.hl7.fhir.dstu2016may.model.Bundle.BundleEntryComponent in project hl7v2-fhir-converter by LinuxForHealth.
the class ResourceUtils method createFHIRBundleFromHL7MessageReturnEntryList.
public static List<BundleEntryComponent> createFHIRBundleFromHL7MessageReturnEntryList(HL7ToFHIRConverter ftv, String inputSegment, ConverterOptions options) {
String json = ftv.convert(inputSegment, options);
assertThat(json).isNotBlank();
LOGGER.debug("FHIR json result:\n" + json);
FHIRContext context = new FHIRContext();
IBaseResource bundleResource = context.getParser().parseResource(json);
assertThat(bundleResource).isNotNull();
Bundle b = (Bundle) bundleResource;
List<BundleEntryComponent> e = b.getEntry();
return e;
}
use of org.hl7.fhir.dstu2016may.model.Bundle.BundleEntryComponent in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7ObservationFHIRConversionTest method testObservationSN_valueRatio_slash_result.
@Test
void testObservationSN_valueRatio_slash_result() throws IOException {
String hl7message = baseMessage + "OBX|1|SN|111^LabWithRatio||^2^/^3|";
List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
List<Resource> obsResource = ResourceUtils.getResourceList(e, ResourceType.Observation);
assertThat(obsResource).hasSize(1);
Observation obs = (Observation) obsResource.get(0);
assertTrue(obs.hasValueRatio());
Ratio r = obs.getValueRatio();
assertEquals(2f, r.getNumerator().getValue().floatValue());
assertEquals(3f, r.getDenominator().getValue().floatValue());
}
use of org.hl7.fhir.dstu2016may.model.Bundle.BundleEntryComponent in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7ObservationFHIRConversionTest method testObservationStNullResult.
@Test
void testObservationStNullResult() throws IOException {
String hl7message = baseMessage + "OBX|1|ST|14151-5^HCO3 BldCo-sCnc^LN|TEST|||||||F|||20210311122016|||||20210311122153||||";
List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
List<Resource> obsResource = ResourceUtils.getResourceList(e, ResourceType.Observation);
assertThat(obsResource).hasSize(1);
Observation obs = (Observation) obsResource.get(0);
assertThat(obs.getValueStringType()).isNotNull();
StringType q = obs.getValueStringType();
assertThat(q.asStringValue()).isNull();
// Check the coding (OBX.3)
assertThat(obs.hasCode()).isTrue();
DatatypeUtils.checkCommonCodeableConceptAssertions(obs.getCode(), "14151-5", "HCO3 BldCo-sCnc", "http://loinc.org", "HCO3 BldCo-sCnc");
// Check the effective Date Time (OBX 14)
assertThat(obs.hasEffective()).isTrue();
assertThat(obs.hasEffectiveDateTimeType()).isTrue();
assertThat(obs.getEffectiveDateTimeType().asStringValue()).isEqualTo("2021-03-11T12:20:16+08:00");
}
use of org.hl7.fhir.dstu2016may.model.Bundle.BundleEntryComponent in project hl7v2-fhir-converter by LinuxForHealth.
the class FHIRConverterTest method test_adt_40_message.
@Test
// Test an example of a message with no message structure specifed
void test_adt_40_message() throws Exception {
Message hl7message = null;
// Test that an ADT A40 message with no MSH-9.3 is successfully parsed and converted.
String hl7messageString = "MSH|^~\\&|REGADT|MCM|RSP1P8|MCM|200301051530|SEC|ADT^A40|00000003|P|2.6\n" + "PID|||MR1^^^XYZ||MAIDENNAME^EVE\n" + "MRG|MR2^^^XYZ\n";
InputStream ins = IOUtils.toInputStream(hl7messageString, StandardCharsets.UTF_8);
Hl7InputStreamMessageStringIterator iterator = new Hl7InputStreamMessageStringIterator(ins);
if (iterator.hasNext()) {
HL7HapiParser hparser = new HL7HapiParser();
hl7message = hparser.getParser().parse(iterator.next());
}
String messageType = HL7DataExtractor.getMessageType(hl7message);
assertThat(messageType).isEqualTo("ADT_A40");
// Convert and check for a patient resource
String json = ftv.convert(hl7messageString, ConverterOptions.SIMPLE_OPTIONS);
FHIRContext context = new FHIRContext();
IBaseResource bundleResource = context.getParser().parseResource(json);
assertThat(bundleResource).isNotNull();
Bundle b = (Bundle) bundleResource;
assertThat(b.getType()).isEqualTo(BundleType.COLLECTION);
assertThat(b.getId()).isNotNull();
assertThat(b.getMeta().getLastUpdated()).isNotNull();
List<BundleEntryComponent> e = b.getEntry();
List<Resource> patientResource = e.stream().filter(v -> ResourceType.Patient == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
assertThat(patientResource).hasSize(2);
}
use of org.hl7.fhir.dstu2016may.model.Bundle.BundleEntryComponent in project hl7v2-fhir-converter by LinuxForHealth.
the class FHIRConverterTest method verifyResult.
private void verifyResult(String json, BundleType expectedBundleType, boolean messageHeaderExpected) {
FHIRContext context = new FHIRContext();
IBaseResource bundleResource = context.getParser().parseResource(json);
assertThat(bundleResource).isNotNull();
Bundle b = (Bundle) bundleResource;
assertThat(b.getType()).isEqualTo(expectedBundleType);
assertThat(b.getId()).isNotNull();
assertThat(b.getMeta().getLastUpdated()).isNotNull();
List<BundleEntryComponent> e = b.getEntry();
List<Resource> patientResource = e.stream().filter(v -> ResourceType.Patient == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
assertThat(patientResource).hasSize(1);
List<Resource> encounterResource = e.stream().filter(v -> ResourceType.Encounter == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
assertThat(encounterResource).hasSize(1);
List<Resource> obsResource = e.stream().filter(v -> ResourceType.Observation == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
// No Observation resource because OBX.2 is type TX
assertThat(obsResource).isEmpty();
List<Resource> pracResource = e.stream().filter(v -> ResourceType.Practitioner == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
assertThat(pracResource).hasSize(4);
List<Resource> allergyResources = e.stream().filter(v -> ResourceType.AllergyIntolerance == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
assertThat(allergyResources).hasSize(2);
if (messageHeaderExpected) {
List<Resource> messageHeader = e.stream().filter(v -> ResourceType.MessageHeader == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
assertThat(messageHeader).hasSize(1);
}
}
Aggregations