use of io.github.linuxforhealth.hl7.ConverterOptions in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7FinancialInsuranceTest method testInsuranceCoverageOfSelfAndTenant.
// Suppress warnings about too many assertions in a test. Justification: creating a FHIR message is very costly; we need to check many asserts per creation for efficiency.
@java.lang.SuppressWarnings("squid:S5961")
@Test
// Tests multiple Organization Id's created with a TENANT prepend.
void testInsuranceCoverageOfSelfAndTenant() throws IOException {
String hl7message = "MSH|^~\\&|||||20151008111200||DFT^P03^DFT_P03|MSGID000001|T|2.6|||||||||\n" + "EVN||20210407191342||||||\n" + // PID.19 purposely empty so IN2.2 used as SSN PatientIdentifier
"PID|||MR1^^^XYZ^MR||DOE^JANE^|||F||||||||||||||||||||||\n" + "PV1||I||||||||||||||||||||||||||||||||||||||||||\n" + // FT1.7 is required transaction code (currently not used)
"FT1||||20201231145045||CG|FAKE|||||||||||||||||||||||||||||||||||||\n" + // IN1.2.4, IN1.2.6 to second XV Coverage.identifier
"IN1|1|Value1^^System3^Value4^^System6" + // IN1.5 to 15 NOT REFERENCED (Tested in testBasicInsuranceCoverageFields)
"|IdValue1^^^IdSystem4^^^^|Large Blue Organization|||||||||||" + // IN1.18 through IN1.35 NOT REFERENCED
"||SEL||||||||||||||||||" + // IN1.47 through IN1.53 NOT REFERENCED
"|MEMBER36||||||||||Value46|||||||\n" + // Only used for MB Patient.Identifier because subscriber is SELF
"IN2||SSN123456|||||||||||||||||||||||IdValue25.1^^^IdSystem25.4^IdType25.5^^20201231145045^20211231145045|||||||||||||||||||||||||||||||||||||||||||" + // IN2.72 is purposely empty (backup to IN1.17) so no RelatedPerson is created.
"|Name69.1^^^^^IdSystem69.6^XX^^^IdValue69.10||\n";
// TENANT prepend is passed through the options.
ConverterOptions customOptionsWithTenant = new Builder().withValidateResource().withPrettyPrint().withProperty("TENANT", "TenantId").build();
List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message, customOptionsWithTenant);
List<Resource> encounters = ResourceUtils.getResourceList(e, ResourceType.Encounter);
// From PV1
assertThat(encounters).hasSize(1);
List<Resource> patients = ResourceUtils.getResourceList(e, ResourceType.Patient);
// From PID
assertThat(patients).hasSize(1);
Patient patient = (Patient) patients.get(0);
String patientId = patient.getId();
// Check Patient.identifiers
// From PID.3, IN2.2 and IN1.36
assertThat(patient.getIdentifier()).hasSize(3);
Identifier patientIdentifier = patient.getIdentifier().get(0);
// PID.3.1
assertThat(patientIdentifier.getValue()).isEqualTo("MR1");
// PID.3.4
assertThat(patientIdentifier.getSystem()).isEqualTo("urn:id:XYZ");
DatatypeUtils.checkCommonCodeableConceptAssertions(patientIdentifier.getType(), "MR", "Medical record number", "http://terminology.hl7.org/CodeSystem/v2-0203", // PID.3.5
null);
patientIdentifier = patient.getIdentifier().get(1);
// IN1.36 backup to IN2.61, active because subscriber is SELF
assertThat(patientIdentifier.getValue()).isEqualTo("MEMBER36");
// No system for MB
assertThat(patientIdentifier.hasSystem()).isFalse();
DatatypeUtils.checkCommonCodeableConceptAssertions(patientIdentifier.getType(), "MB", "Member Number", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
patientIdentifier = patient.getIdentifier().get(2);
// IN2.2
assertThat(patientIdentifier.getValue()).isEqualTo("SSN123456");
// No system for SSN
assertThat(patientIdentifier.hasSystem()).isFalse();
DatatypeUtils.checkCommonCodeableConceptAssertions(patientIdentifier.getType(), "SS", "Social Security number", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
List<Resource> organizations = ResourceUtils.getResourceList(e, ResourceType.Organization);
// From Payor created by IN1, PayorId Organization (IN2.25), and PolcyHolder Organization Name (IN2.69)
assertThat(organizations).hasSize(3);
Organization org = (Organization) organizations.get(0);
String payorOrgId = org.getId();
// IN1.17.1 w/TENANT prepend (Id's lowercased)
assertThat(payorOrgId).isEqualTo("Organization/tenantid.idvalue1");
// Check organization Identifier's
// IN1.4
assertThat(org.getName()).isEqualTo("Large Blue Organization");
assertThat(org.getIdentifier()).hasSize(1);
Identifier orgIdentifier = org.getIdentifierFirstRep();
// IN1.3.1
assertThat(orgIdentifier.getValue()).isEqualTo("IdValue1");
// IN1.3.4
assertThat(orgIdentifier.getSystem()).isEqualTo("urn:id:IdSystem4");
// IN1.3.7 & IN1.3.7 empty
assertThat(orgIdentifier.hasPeriod()).isFalse();
// IN1.3.5 empty
assertThat(orgIdentifier.hasType()).isFalse();
// Check PayorId Organization from IN2.25
org = (Organization) organizations.get(1);
String payorOrgIdIn25 = org.getId();
// IN1.25.1 w/TENANT prepend (Id's lowercased)
assertThat(payorOrgIdIn25).isEqualTo("Organization/tenantid.idvalue25.1");
// IN2.25.1
assertThat(org.getName()).isEqualTo("IdValue25.1");
assertThat(org.getIdentifier()).hasSize(1);
orgIdentifier = org.getIdentifier().get(0);
// IN2.25.1
assertThat(orgIdentifier.getValue()).isEqualTo("IdValue25.1");
// IN2.25.4
assertThat(orgIdentifier.getSystem()).isEqualTo("urn:id:IdSystem25.4");
// IN2.25.7
assertThat(orgIdentifier.getPeriod().getStartElement().toString()).containsPattern("2020-12-31T14:50:45");
// IN2.25.8
assertThat(orgIdentifier.getPeriod().getEndElement().toString()).containsPattern("2021-12-31T14:50:45");
// IN2.25.5
DatatypeUtils.checkCommonCodeableConceptAssertions(orgIdentifier.getType(), "IdType25.5", null, null, null);
// Check PolicyHolder Organization Name and ID Organization from IN2.69
org = (Organization) organizations.get(2);
String policyHolderOrgId = org.getId();
// IN2.69.1 w/TENANT prepend (Id's lowercased)
assertThat(policyHolderOrgId).isEqualTo("Organization/tenantid.idvalue69.10");
// IN2.69.1
assertThat(org.getName()).isEqualTo("Name69.1");
assertThat(org.getIdentifier()).hasSize(1);
orgIdentifier = org.getIdentifier().get(0);
// IN2.69.10
assertThat(orgIdentifier.getValue()).isEqualTo("IdValue69.10");
// IN2.69.6
assertThat(orgIdentifier.getSystem()).isEqualTo("urn:id:IdSystem69.6");
// Becuase the code is known, the 0203 table lookup is successful and returns code, display, and system
DatatypeUtils.checkCommonCodeableConceptAssertions(orgIdentifier.getType(), "XX", "Organization identifier", "http://terminology.hl7.org/CodeSystem/v2-0203", // IN2.69.7 with lookup
null);
List<Resource> coverages = ResourceUtils.getResourceList(e, ResourceType.Coverage);
// From IN1 segment
assertThat(coverages).hasSize(1);
Coverage coverage = (Coverage) coverages.get(0);
// Confirm Coverage Identifiers
// XV, XV, XV, MB, SN
assertThat(coverage.getIdentifier()).hasSize(5);
// Coverage Identifiers deep check in testBasicInsuranceCoverageFields
// Confirm Coverage Subscriber references to Patient
assertThat(coverage.getSubscriber().getReference()).isEqualTo(patientId);
// Confirm Coverage Beneficiary references to Patient, and Payors references correct Organizations
assertThat(coverage.getBeneficiary().getReference()).isEqualTo(patientId);
// One for each payorOrganization
assertThat(coverage.getPayor()).hasSize(2);
assertThat(coverage.getPayor().get(0).getReference()).isEqualTo(payorOrgId);
assertThat(coverage.getPayor().get(1).getReference()).isEqualTo(payorOrgIdIn25);
// Confirm policyHolder references correct organization
assertThat(coverage.getPolicyHolder().getReference()).isEqualTo(policyHolderOrgId);
// Expect no RelatedPerson because IN1.17 was self
List<Resource> relatedPersons = ResourceUtils.getResourceList(e, ResourceType.RelatedPerson);
// No related person should be created because IN1.17 was SEL
assertThat(relatedPersons).isEmpty();
// Check coverage.relationship (from SubscriberRelationship mapping)
DatatypeUtils.checkCommonCodeableConceptAssertions(coverage.getRelationship(), "self", "Self", "http://terminology.hl7.org/CodeSystem/subscriber-relationship", // IN1.17
null);
// Confirm there are no unaccounted for resources
// Expected: Coverage, Organization (3x), Patient, Encounter
assertThat(e).hasSize(6);
}
use of io.github.linuxforhealth.hl7.ConverterOptions in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7ImmunizationFHIRConversionTest method testImmunizationAdministrationPlaceOrg3.
@Test
// Third test of priority of Immunization Performer sourcing.
void testImmunizationAdministrationPlaceOrg3() throws IOException {
String hl7VUXmessageRep = "MSH|^~\\&|||||20140701041038||VXU^V04^VXU_V04|MSG.Valid_01|P|2.6|||\n" + "PID|||1234^^^^MR||DOE^JANE^|||F||||||||||||||||||||||\r" + // PV1 purposely missing
"ORC|||197027|||||||^Clerk^Myron|||||||RI2050\r" + // RXA.11.4 present and takes priority because there is no RXA.27 nor PV1.3.4
"RXA|0|1|20130531||48^HIB PRP-T^CVX||||||^^^PlaceRXA11|||||||||||||||" + "OBX|1|CE|59784-9^Disease with presumed immunity^LN||\r";
// TENANT prepend is passed through the options.
ConverterOptions customOptionsWithTenant = new Builder().withValidateResource().withPrettyPrint().withProperty("TENANT", "TenantId").build();
List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7VUXmessageRep, customOptionsWithTenant);
// We expect two different organizations, one for Encounter.serviceProvider, one for Immunization.performer
List<Resource> organizations = ResourceUtils.getResourceList(e, ResourceType.Organization);
assertThat(organizations).hasSize(1);
Organization org = (Organization) organizations.get(0);
String orgId = org.getId();
// RXA.11.4 + tenantid
assertThat(orgId).isEqualTo("Organization/tenantid.placerxa11");
List<Resource> immunizations = ResourceUtils.getResourceList(e, ResourceType.Immunization);
assertThat(immunizations).hasSize(1);
Immunization imm = (Immunization) immunizations.get(0);
// RXA.11.4
assertThat(imm.getPerformer()).hasSize(1);
// RXA.11.4 + tenantid
assertThat(imm.getPerformerFirstRep().getActor().getReference()).isEqualTo(orgId);
List<Resource> encounters = ResourceUtils.getResourceList(e, ResourceType.Encounter);
assertThat(encounters).isEmpty();
// Check for expected resources: Organization, Immunization, Patient
assertThat(e).hasSize(3);
}
use of io.github.linuxforhealth.hl7.ConverterOptions 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 io.github.linuxforhealth.hl7.ConverterOptions 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 io.github.linuxforhealth.hl7.ConverterOptions in project hl7v2-fhir-converter by LinuxForHealth.
the class HL7ToFHIRConverter method convertToBundle.
/**
* Converts the input HL7 message (String data) into FHIR bundle resource.
*
* @param hl7MessageData Message to convert
* @param options Options for conversion
* @param engine Hl7Message engine
* @return Bundle {@link Bundle} resource.
* @throws UnsupportedOperationException - if message type is not supported
*/
public Bundle convertToBundle(String hl7MessageData, ConverterOptions options, HL7MessageEngine engine) {
Preconditions.checkArgument(StringUtils.isNotBlank(hl7MessageData), "Input HL7 message cannot be blank");
if (engine == null) {
engine = getMessageEngine(options);
}
Message hl7message = getHl7Message(hl7MessageData);
if (hl7message != null) {
String messageType = HL7DataExtractor.getMessageType(hl7message);
HL7MessageModel hl7MessageTemplateModel = messagetemplates.get(messageType);
if (hl7MessageTemplateModel != null) {
return hl7MessageTemplateModel.convert(hl7message, engine);
} else {
throw new UnsupportedOperationException("Message type not yet supported " + messageType);
}
} else {
throw new IllegalArgumentException("Parsed HL7 message was null.");
}
}
Aggregations