use of org.hl7.fhir.r4.model.Bundle.BundleEntryComponent in project hl7v2-fhir-converter by LinuxForHealth.
the class FHIRConverterTest method testCodingSystems.
@Test
/*
* This tests some of coding systems of interest or potential problems
*/
void testCodingSystems() throws FHIRException {
String hl7VUXmessageRep = "MSH|^~\\&|MYEHR2.5|RI88140101|KIDSNET_IFL|RIHEALTH|201305330||VXU^V04^VXU_V04|20130531RI881401010105|P|2.6|||AL|NE|764|ASCII||||||^4086::132:2A57:3C28^IPv6\r" + "EVN|A01|20130617154644||01\r" + "PID|1||12345678^^^MYEMR^MR||TestPatient^John|||M|\r" + "ORC|RE||197027|||||||^Clerk^Myron||MD67895^Pediatric^MARY^^^^MD^^RIA|||||RI2050\r" + // Test MVX
"RXA|0|1|20130528|20130529|48^HIB PRP-T^CVX|0.5|ML^^ISO+||00^new immunization record^NIP001|^Sticker^Nurse|^^^RI2050||||33k2a|20131210|PMC^sanofi^MVX|||CP|A\r" + // Test HL70162 & HL70163
"RXR|C28161^IM^NCIT^IM^INTRAMUSCULAR^HL70162|RT^right thigh^HL70163\r";
String json = ftv.convert(hl7VUXmessageRep, 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();
List<BundleEntryComponent> e = b.getEntry();
List<Resource> obsResource = e.stream().filter(v -> ResourceType.Immunization == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
assertThat(obsResource).hasSize(1);
Immunization immunization = (Immunization) obsResource.get(0);
// Check that organization identifier (MVX) has a system
Organization org = (Organization) immunization.getManufacturer().getResource();
List<Identifier> li = org.getIdentifier();
Identifier ident = li.get(0);
assertThat(ident.hasSystem()).isTrue();
assertThat(ident.getSystem()).isEqualTo("http://terminology.hl7.org/CodeSystem/MVX");
assertThat(ident.hasValue()).isTrue();
assertThat(ident.getValue()).isEqualTo("PMC");
// Check that route (HL70162) has a system
CodeableConcept route = immunization.getRoute();
assertThat(route.hasCoding()).isTrue();
List<Coding> codings = route.getCoding();
assertThat(codings.size()).isEqualTo(2);
Coding coding = codings.get(0);
// If the first one is not the one we want look at the second one.
if (coding.getCode().contains("C28161")) {
coding = codings.get(1);
}
assertThat(coding.hasSystem()).isTrue();
assertThat(coding.getSystem()).isEqualTo("http://terminology.hl7.org/CodeSystem/v2-0162");
// Check that site (HL70163) has a system
CodeableConcept site = immunization.getSite();
coding = site.getCodingFirstRep();
assertThat(coding.hasSystem()).isTrue();
assertThat(coding.getSystem()).isEqualTo("http://terminology.hl7.org/CodeSystem/v2-0163");
}
use of org.hl7.fhir.r4.model.Bundle.BundleEntryComponent in project hl7v2-fhir-converter by LinuxForHealth.
the class FHIRConverterTest method test_patient_encounter_bundle_return.
@Test
void test_patient_encounter_bundle_return() throws IOException {
String hl7message = "MSH|^~\\&|REGADT|MCM|RSP1P8|MCM|200301051530|SEC|ADT^A40^ADT_A39|00000003|P|2.6\n" + "PID|||MR1^^^XYZ||MAIDENNAME^EVE\n" + "MRG|MR2^^^XYZ\n";
Bundle b = ftv.convertToBundle(hl7message, OPTIONS, null);
assertThat(b.getType()).isEqualTo(BundleType.COLLECTION);
List<Resource> patientResource = b.getEntry().stream().filter(v -> ResourceType.Patient == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
assertThat(patientResource).hasSize(2);
}
use of org.hl7.fhir.r4.model.Bundle.BundleEntryComponent in project hl7v2-fhir-converter by LinuxForHealth.
the class InputTimeZoneIdTest method validateTimeZoneIdSettingViaOption.
@Test
void validateTimeZoneIdSettingViaOption() {
// NOTE: This simple Condition (PRB) segment is used for testing time because it has both
// standard DateTime conversions (abatementDateTime, recordedDate) and value conversions (extension).
String hl7message = "MSH|^~\\&|||||20040629164652|1|PPR^PC1|331|P|2.3.1||\r" + "PID||||||||||||||||||||||||||||||\r" + "PV1||I||||||||||||||||||||||||||||||||||||||||||\r" + // PRB.16 to onsetDateTime (check time ZoneId)
"PRB|AD|20020202020000|K80.00^Cholelithiasis^I10|53956|||20070707070000||20090909090000|||||||20160616160000\r";
// FIRST test with city based ZoneId passed through options
ConverterOptions customOptionsWithTenant = new Builder().withValidateResource().withPrettyPrint().withZoneIdText("America/Chicago").build();
// "America/Chicago" will become -06:00 in winter (CST) -05:00 in spring/summer/fall (CDT). This is expected.
List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message, customOptionsWithTenant);
// Find the condition from the FHIR bundle.
List<Resource> conditionResource = ResourceUtils.getResourceList(e, ResourceType.Condition);
assertThat(conditionResource).hasSize(1);
Condition condition = (Condition) conditionResource.get(0);
// PRB.2 Chicago Central STANDARD Time
assert (condition.getRecordedDateElement().getValueAsString()).contains("2002-02-02T02:00:00-06:00");
// PRB.9 Chicago Central DAYLIGHT Time
assert (condition.getAbatementDateTimeType().getValueAsString()).contains("2009-09-09T09:00:00-05:00");
// PRB.16 Chicago CDT
assert (condition.getOnsetDateTimeType().getValueAsString()).contains("2016-06-16T16:00:00-05:00");
assert (condition.getExtensionByUrl("http://hl7.org/fhir/StructureDefinition/condition-assertedDate").getValueAsPrimitive().getValueAsString()).contains(// PRB.7 Chicago CDT
"2007-07-07T07:00:00-05:00");
// SECOND test with fixed ZoneId passed through options
customOptionsWithTenant = new Builder().withValidateResource().withPrettyPrint().withZoneIdText("+03:00").build();
e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message, customOptionsWithTenant);
// Find the condition from the FHIR bundle.
conditionResource = ResourceUtils.getResourceList(e, ResourceType.Condition);
assertThat(conditionResource).hasSize(1);
condition = (Condition) conditionResource.get(0);
// PRB.2 fixed ZoneId
assert (condition.getRecordedDateElement().getValueAsString()).contains("2002-02-02T02:00:00+03:00");
// PRB.9
assert (condition.getAbatementDateTimeType().getValueAsString()).contains("2009-09-09T09:00:00+03:00");
// PRB.16
assert (condition.getOnsetDateTimeType().getValueAsString()).contains("2016-06-16T16:00:00+03:00");
assert (condition.getExtensionByUrl("http://hl7.org/fhir/StructureDefinition/condition-assertedDate").getValueAsPrimitive().getValueAsString()).contains(// PRB.7
"2007-07-07T07:00:00+03:00");
// THIRD test with no ZoneId passed through options, so it uses the config.properties ZoneId
customOptionsWithTenant = new Builder().withValidateResource().withPrettyPrint().build();
e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message, customOptionsWithTenant);
// Find the condition from the FHIR bundle.
conditionResource = ResourceUtils.getResourceList(e, ResourceType.Condition);
assertThat(conditionResource).hasSize(1);
condition = (Condition) conditionResource.get(0);
// PRB.2 config.properties ZoneId
assert (condition.getRecordedDateElement().getValueAsString()).contains("2002-02-02T02:00:00+08:00");
// PRB.9
assert (condition.getAbatementDateTimeType().getValueAsString()).contains("2009-09-09T09:00:00+08:00");
// PRB.16
assert (condition.getOnsetDateTimeType().getValueAsString()).contains("2016-06-16T16:00:00+08:00");
assert (condition.getExtensionByUrl("http://hl7.org/fhir/StructureDefinition/condition-assertedDate").getValueAsPrimitive().getValueAsString()).contains(// PRB.7
"2007-07-07T07:00:00+08:00");
}
use of org.hl7.fhir.r4.model.Bundle.BundleEntryComponent in project hl7v2-fhir-converter by LinuxForHealth.
the class JvmTimeZoneIdTest method testEmptyDefaultTimeZoneYieldsJVMZoneId.
@Test
void testEmptyDefaultTimeZoneYieldsJVMZoneId() throws IOException {
// Create our own properties file
File configFile = new File(folder, "config.properties");
writeSimpleProperties(configFile);
System.setProperty(CONF_PROP_HOME, configFile.getParent());
ConverterConfiguration.reset();
// Prove that we're using our custom properties file with no ZoneId
ConverterConfiguration theConvConfig = ConverterConfiguration.getInstance();
// Four messages supported. (Proves we're using our created file, not the default.)
assertThat(theConvConfig.getSupportedMessageTemplates()).hasSize(13);
// Purposely empty
assertThat(theConvConfig.getZoneId()).isNull();
// IMPORTANT: TimeZoneId's are different than an offset. TimeZoneId's are a location.
// The offset of the location changes depending on whether Daylight savings time is in effect.
// Because we compare after processing, we can't compare locations, only offsets.
// It is critical that when we compare offsets, we start with the same date, so the same daylight savings rules apply!
// Otherwise a test might work only half of the year.
// Calculate the local server zone offset
// 20020202020000
LocalDateTime localDateTime = LocalDateTime.of(2002, Month.FEBRUARY, 2, 2, 0, 0);
String defaultLocalZone = TimeZone.getDefault().getID();
ZoneId localZoneId = ZoneId.of(defaultLocalZone);
ZonedDateTime localZonedDateTime = localDateTime.atZone(localZoneId);
ZoneOffset localOffset = localZonedDateTime.getOffset();
// PART 1
// Test the format utility (which will fallback to local server time and zone offset)
String testDateTime = DateUtil.formatToDateTimeWithDefaultZone("20020202020000");
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
ZonedDateTime testZonedDateTime = ZonedDateTime.parse(testDateTime, dateTimeFormatter);
ZoneOffset testOffset = testZonedDateTime.getOffset();
// Offset from our function call test should equal offset of the local time
assertThat(testOffset).isEqualTo(localOffset);
// PART 2
// Do the same for a date going through the entire conversion
String hl7message = "MSH|^~\\&|||||20020202020000|1|PPR^PC1|331|P|2.3.1||\r" + "PID||||||||||||||||||||||||||||||\r" + "PV1||I||||||||||||||||||||||||||||||||||||||||||\r" + // PRB.2 to recordedDateTime (check time ZoneId)
"PRB|AD|20020202020000|K80.00^Cholelithiasis^I10|53956||||||||||||\r";
ConverterOptions customOptionsWithTenant = new Builder().withValidateResource().withPrettyPrint().build();
List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message, customOptionsWithTenant);
// Find the condition from the FHIR bundle.
List<Resource> conditionResource = ResourceUtils.getResourceList(e, ResourceType.Condition);
assertThat(conditionResource).hasSize(1);
Condition condition = (Condition) conditionResource.get(0);
// Get the recordedDate value; convert it back to a zoned time; get the offset for comparison
// PRB.2
testDateTime = condition.getRecordedDateElement().getValueAsString();
testZonedDateTime = ZonedDateTime.parse(testDateTime, dateTimeFormatter);
testOffset = testZonedDateTime.getOffset();
// Offset from our test should equal offset of the local time
assertThat(testOffset).isEqualTo(localOffset);
// After the test, the properties file resets.
}
use of org.hl7.fhir.r4.model.Bundle.BundleEntryComponent in project hl7v2-fhir-converter by LinuxForHealth.
the class HL7MessageModel method duplicateFound.
// Determine if an entry has duplicates by counting all the entries which have the same Url.
// If count > 1 then it has duplicates. (It will be counted, too, as 1.)
private boolean duplicateFound(BundleEntryComponent entry, List<BundleEntryComponent> entries) {
String targetUrl = entry.getFullUrl();
Integer foundCount = 0;
for (BundleEntryComponent component : entries) {
if (component.getFullUrl().equals(targetUrl)) {
foundCount++;
}
}
return foundCount > 1;
}
Aggregations