use of org.hl7.fhir.r4.model.HumanName in project beneficiary-fhir-data by CMSgov.
the class BeneficiaryTransformerV2 method transform.
/**
* @param beneficiary the CCW {@link Beneficiary} to transform
* @param requestHeader {@link RequestHeaders} the holder that contains all supported resource
* request headers
* @return a FHIR {@link Patient} resource that represents the specified {@link Beneficiary}
*/
private static Patient transform(Beneficiary beneficiary, RequestHeaders requestHeader) {
Objects.requireNonNull(beneficiary);
Patient patient = new Patient();
/*
* Notify end users when they receive Patient records impacted by
* https://jira.cms.gov/browse/BFD-1566. See the documentation on
* LoadAppOptions.isFilteringNonNullAndNon2022Benes() for details.
*/
if (!beneficiary.getSkippedRifRecords().isEmpty()) {
patient.getMeta().addTag(TransformerConstants.CODING_SYSTEM_BFD_TAGS, TransformerConstants.CODING_BFD_TAGS_DELAYED_BACKDATED_ENROLLMENT, TransformerConstants.CODING_BFD_TAGS_DELAYED_BACKDATED_ENROLLMENT_DISPLAY);
}
// Required values not directly mapped
patient.getMeta().addProfile(ProfileConstants.C4BB_PATIENT_URL);
patient.setId(beneficiary.getBeneficiaryId());
// BENE_ID => patient.identifier
TransformerUtilsV2.addIdentifierSlice(patient, TransformerUtilsV2.createCodeableConcept(TransformerConstants.CODING_SYSTEM_HL7_IDENTIFIER_TYPE, null, TransformerConstants.PATIENT_MB_ID_DISPLAY, "MB"), Optional.of(beneficiary.getBeneficiaryId()), Optional.of(TransformerConstants.CODING_BBAPI_BENE_ID));
// Unhashed MBI
if (beneficiary.getMedicareBeneficiaryId().isPresent()) {
Period mbiPeriod = new Period();
if (beneficiary.getMbiEffectiveDate().isPresent()) {
TransformerUtilsV2.setPeriodStart(mbiPeriod, beneficiary.getMbiEffectiveDate().get());
}
if (beneficiary.getMbiObsoleteDate().isPresent()) {
TransformerUtilsV2.setPeriodEnd(mbiPeriod, beneficiary.getMbiObsoleteDate().get());
}
addUnhashedIdentifier(patient, beneficiary.getMedicareBeneficiaryId().get(), TransformerConstants.CODING_BBAPI_MEDICARE_BENEFICIARY_ID_UNHASHED, TransformerUtilsV2.createIdentifierCurrencyExtension(CurrencyIdentifier.CURRENT), mbiPeriod);
}
// Add lastUpdated
TransformerUtilsV2.setLastUpdated(patient, beneficiary.getLastUpdated());
/**
* The following logic attempts to distill {@link MedicareBeneficiaryIdHistory} data into only
* those records which have an endDate present. This is due to the fact that it includes the
* CURRENT MBI record which was handle previously. Also, the {@link
* MedicareBeneficiaryIdHistory} table appears to contain spurious records with the only
* difference is the generated surrogate key identifier.
*/
if (requestHeader.isMBIinIncludeIdentifiers()) {
HashMap<LocalDate, MedicareBeneficiaryIdHistory> mbiHistMap = new HashMap<LocalDate, MedicareBeneficiaryIdHistory>();
for (MedicareBeneficiaryIdHistory mbiHistory : beneficiary.getMedicareBeneficiaryIdHistories()) {
// and will have been previously provided as the CURRENT rcd.
if (mbiHistory.getMbiEndDate().isPresent()) {
mbiHistMap.put(mbiHistory.getMbiEndDate().get(), mbiHistory);
}
// would come in ascending order, so any rcd would have a later
// update date than prev rcd.
TransformerUtilsV2.updateMaxLastUpdated(patient, mbiHistory.getLastUpdated());
}
if (mbiHistMap.size() > 0) {
Extension historicalIdentifier = TransformerUtilsV2.createIdentifierCurrencyExtension(CurrencyIdentifier.HISTORIC);
for (MedicareBeneficiaryIdHistory mbi : mbiHistMap.values()) {
addUnhashedIdentifier(patient, mbi.getMedicareBeneficiaryId().get(), TransformerConstants.CODING_BBAPI_MEDICARE_BENEFICIARY_ID_UNHASHED, historicalIdentifier, null);
}
}
}
// support header includeAddressFields from downstream components e.g. BB2
// per requirement of BFD-379, BB2 always send header includeAddressFields = False
Boolean addrHdrVal = requestHeader.getValue(R4PatientResourceProvider.HEADER_NAME_INCLUDE_ADDRESS_FIELDS);
if (addrHdrVal != null && addrHdrVal) {
patient.addAddress().setState(beneficiary.getStateCode()).setPostalCode(beneficiary.getPostalCode()).setCity(beneficiary.getDerivedCityName().orElse(null)).addLine(beneficiary.getDerivedMailingAddress1().orElse(null)).addLine(beneficiary.getDerivedMailingAddress2().orElse(null)).addLine(beneficiary.getDerivedMailingAddress3().orElse(null)).addLine(beneficiary.getDerivedMailingAddress4().orElse(null)).addLine(beneficiary.getDerivedMailingAddress5().orElse(null)).addLine(beneficiary.getDerivedMailingAddress6().orElse(null));
} else {
patient.addAddress().setState(beneficiary.getStateCode()).setPostalCode(beneficiary.getPostalCode());
}
if (beneficiary.getBirthDate() != null) {
patient.setBirthDate(TransformerUtilsV2.convertToDate(beneficiary.getBirthDate()));
}
// "Patient.deceased[x]": ["boolean", "dateTime"],
if (beneficiary.getBeneficiaryDateOfDeath().isPresent()) {
patient.setDeceased(new DateTimeType(TransformerUtilsV2.convertToDate(beneficiary.getBeneficiaryDateOfDeath().get()), TemporalPrecisionEnum.DAY));
} else {
patient.setDeceased(new BooleanType(false));
}
char sex = beneficiary.getSex();
if (sex == Sex.MALE.getCode())
patient.setGender((AdministrativeGender.MALE));
else if (sex == Sex.FEMALE.getCode())
patient.setGender((AdministrativeGender.FEMALE));
else
patient.setGender((AdministrativeGender.UNKNOWN));
if (beneficiary.getRace().isPresent()) {
patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.RACE, beneficiary.getRace().get()));
// for race category, v2 will just treat all race codes as Unknown (UNK);
// thus we'll simply pass in the Unknown race code .
RaceCategory raceCategory = TransformerUtilsV2.getRaceCategory('0');
Extension raceChildOMBExt1 = new Extension().setValue(new Coding().setCode(raceCategory.toCode()).setSystem(raceCategory.getSystem()).setDisplay(raceCategory.getDisplay())).setUrl("ombCategory");
Extension raceChildOMBExt2 = new Extension().setValue(new StringType().setValue(raceCategory.getDisplay())).setUrl("text");
Extension parentOMBRace = new Extension().setUrl(TransformerConstants.CODING_RACE_US);
parentOMBRace.addExtension(raceChildOMBExt1);
parentOMBRace.addExtension(raceChildOMBExt2);
patient.addExtension(parentOMBRace);
}
HumanName name = patient.addName().addGiven(beneficiary.getNameGiven()).setFamily(beneficiary.getNameSurname()).setUse(HumanName.NameUse.USUAL);
if (beneficiary.getNameMiddleInitial().isPresent()) {
name.addGiven(String.valueOf(beneficiary.getNameMiddleInitial().get()));
}
// The reference year of the enrollment data
if (beneficiary.getBeneEnrollmentReferenceYear().isPresent()) {
patient.addExtension(TransformerUtilsV2.createExtensionDate(CcwCodebookVariable.RFRNC_YR, beneficiary.getBeneEnrollmentReferenceYear()));
}
// Monthly Medicare-Medicaid dual eligibility codes
if (beneficiary.getMedicaidDualEligibilityJanCode().isPresent()) {
patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.DUAL_01, beneficiary.getMedicaidDualEligibilityJanCode()));
}
if (beneficiary.getMedicaidDualEligibilityFebCode().isPresent()) {
patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.DUAL_02, beneficiary.getMedicaidDualEligibilityFebCode()));
}
if (beneficiary.getMedicaidDualEligibilityMarCode().isPresent()) {
patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.DUAL_03, beneficiary.getMedicaidDualEligibilityMarCode()));
}
if (beneficiary.getMedicaidDualEligibilityAprCode().isPresent()) {
patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.DUAL_04, beneficiary.getMedicaidDualEligibilityAprCode()));
}
if (beneficiary.getMedicaidDualEligibilityMayCode().isPresent()) {
patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.DUAL_05, beneficiary.getMedicaidDualEligibilityMayCode()));
}
if (beneficiary.getMedicaidDualEligibilityJunCode().isPresent()) {
patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.DUAL_06, beneficiary.getMedicaidDualEligibilityJunCode()));
}
if (beneficiary.getMedicaidDualEligibilityJulCode().isPresent()) {
patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.DUAL_07, beneficiary.getMedicaidDualEligibilityJulCode()));
}
if (beneficiary.getMedicaidDualEligibilityAugCode().isPresent()) {
patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.DUAL_08, beneficiary.getMedicaidDualEligibilityAugCode()));
}
if (beneficiary.getMedicaidDualEligibilitySeptCode().isPresent()) {
patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.DUAL_09, beneficiary.getMedicaidDualEligibilitySeptCode()));
}
if (beneficiary.getMedicaidDualEligibilityOctCode().isPresent()) {
patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.DUAL_10, beneficiary.getMedicaidDualEligibilityOctCode()));
}
if (beneficiary.getMedicaidDualEligibilityNovCode().isPresent()) {
patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.DUAL_11, beneficiary.getMedicaidDualEligibilityNovCode()));
}
if (beneficiary.getMedicaidDualEligibilityDecCode().isPresent()) {
patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.DUAL_12, beneficiary.getMedicaidDualEligibilityDecCode()));
}
// Last Updated => Patient.meta.lastUpdated
TransformerUtilsV2.setLastUpdated(patient, beneficiary.getLastUpdated());
return patient;
}
use of org.hl7.fhir.r4.model.HumanName in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7FinancialInsuranceTest method testBasicInsuranceCoverageFields.
// 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
void testBasicInsuranceCoverageFields() throws IOException {
// Tests fields listed below.
String hl7message = "MSH|^~\\&|||||20151008111200||DFT^P03^DFT_P03|MSGID000001|T|2.6|||||||||\n" + "EVN||20210407191342||||||\n" + "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.3.8 to Organization Identifier.period.end
"|IdValue1^^^IdSystem4^IdType5^^20201231145045^20211231145045" + // IN1.4 to Organization Name
"|Large Blue Organization" + // IN1.5 to Organization Address (All XAD standard fields)
"|456 Ultramarine Lane^^Faketown^CA^ZIP5" + // IN1.6.13 to Organization Contact Name .period.end
"|LastFake^FirstFake^MiddleFake^III^Dr.^^L^^^^^20201231145045^20211231145045" + // IN1.7.18 to Organization Contact telecom .rank
"|^WPN^^^^333^4444444^^^^^^20201231145045^20211231145045^^^^1" + // IN1.9.1 (2) to list element Coverage.class.name and value (because IN1.9.10 (2) does not exist)
"|UA34567|NameBlue^^^^^^^^^IDBlue~NameGreen||" + // IN1.35 to Organization.identifier
"|20201231145045|20211231145045|||||||||5|||||||||||||COMPANYPLANCODE35" + // IN1.49 has value to show that it is not used for Patient.identifier because NO relationship (IN1.17/IN2.72 empty)
"|MEMBER36||||||||||Value46|||PatientId49.1||||\n" + // IN2.61 is purposely empty (primary to IN1.36) so IN1.36 will be used as the MB Coverage.identifier
"IN2|||||||||||||||||||||||||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^UNK^^^IdValue69.10||\n";
List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
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();
// From PID.3
assertThat(patient.getIdentifier()).hasSize(1);
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);
// IN1.49 not used
List<Resource> organizations = ResourceUtils.getResourceList(e, ResourceType.Organization);
// From IN1.3 creates Payor, IN2.25 to new PayorId Organization, IN2.69 creates new PolicyHolder Organization Name
assertThat(organizations).hasSize(3);
Organization org = (Organization) organizations.get(0);
// Check Payor Organization Id's
String payorOrgId = org.getId();
// IN1.17.1 (no TENANT) (Id's lowercased)
assertThat(payorOrgId).isEqualTo("Organization/idvalue1");
// IN1.4
assertThat(org.getName()).isEqualTo("Large Blue Organization");
assertThat(org.getIdentifier()).hasSize(2);
Identifier orgIdentifier = org.getIdentifier().get(0);
// IN1.3.1
assertThat(orgIdentifier.getValue()).isEqualTo("IdValue1");
// IN1.3.4
assertThat(orgIdentifier.getSystem()).isEqualTo("urn:id:IdSystem4");
// IN1.3.7
assertThat(orgIdentifier.getPeriod().getStartElement().toString()).containsPattern("2020-12-31T14:50:45");
// IN1.3.8
assertThat(orgIdentifier.getPeriod().getEndElement().toString()).containsPattern("2021-12-31T14:50:45");
// IN1.3.5
DatatypeUtils.checkCommonCodeableConceptAssertions(orgIdentifier.getType(), "IdType5", null, null, null);
Identifier orgIdentifier1 = org.getIdentifier().get(1);
// IN1.35
assertThat(orgIdentifier1.getValue()).isEqualTo("COMPANYPLANCODE35");
// Check Payor Organization address. IN1.4 is a standard XAD address, which is tested exhaustively in other tests.
assertThat(org.getAddress()).hasSize(1);
assertThat(org.getAddress().get(0).getLine().get(0).getValueAsString()).isEqualTo(// IN1.4.1
"456 Ultramarine Lane");
// IN1.4.3
assertThat(org.getAddress().get(0).getCity()).isEqualTo("Faketown");
// IN1.4.4
assertThat(org.getAddress().get(0).getState()).isEqualTo("CA");
// IN1.4.5
assertThat(org.getAddress().get(0).getPostalCode()).isEqualTo("ZIP5");
// Check Payor Organization contact name. IN1.6 name is standard XPN, tested exhaustively in other tests.
HumanName contactName = org.getContact().get(0).getName();
assertThat(org.getContact()).hasSize(1);
// IN1.6.1
assertThat(contactName.getFamily()).isEqualTo("LastFake");
// IN1.6.2
assertThat(contactName.getGiven().get(0).getValueAsString()).isEqualTo("FirstFake");
// IN1.6.3
assertThat(contactName.getGiven().get(1).getValueAsString()).isEqualTo("MiddleFake");
// IN1.6.6
assertThat(contactName.getPrefixAsSingleString()).hasToString("Dr.");
// IN1.6.5
assertThat(contactName.getSuffixAsSingleString()).hasToString("III");
// from IN1.6 aggregate
assertThat(contactName.getText()).isEqualTo("Dr. FirstFake MiddleFake LastFake III");
// IN1.6.7
assertThat(contactName.getUseElement().getCode()).hasToString("official");
// IN1.6.12
assertThat(contactName.getPeriod().getStartElement().toString()).containsPattern("2020-12-31T14:50:45");
// IN1.6.13
assertThat(contactName.getPeriod().getEndElement().toString()).containsPattern("2021-12-31T14:50:45");
// Check there is no purpose. Don't need one, here.
assertThat(org.getContact().get(0).hasPurpose()).isFalse();
// Check Payor Organization contact telecom. IN1.7 is standard XTN, tested exhaustively in other tests.
assertThat(org.getContact().get(0).getTelecom()).hasSize(1);
// telecom is type ContactPoint
ContactPoint contactPoint = org.getContact().get(0).getTelecomFirstRep();
// default type hardcoded.
assertThat(contactPoint.getSystemElement().getCode()).hasToString("phone");
// IN1.7.2 is not mapped (ignored)
assertThat(contactPoint.hasUseElement()).isFalse();
// IN1.7.6, IN1.7.7 via getFormattedTelecomNumberValue
assertThat(contactPoint.getValue()).hasToString("(333) 444 4444");
// IN1.7.13
assertThat(contactPoint.getPeriod().getStartElement().toString()).containsPattern("2020-12-31T14:50:45");
// IN1.7.14
assertThat(contactPoint.getPeriod().getEndElement().toString()).containsPattern("2021-12-31T14:50:45");
// IN1.7.18
assertThat(contactPoint.getRank()).isEqualTo(1);
// Check PayorId Organization from IN2.25
org = (Organization) organizations.get(1);
String payorOrgIdIn25 = org.getId();
// IN1.25.1 (no TENANT) (Id's lowercased)
assertThat(payorOrgIdIn25).isEqualTo("Organization/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 (no TENANT) (Id's lowercased)
assertThat(policyHolderOrgId).isEqualTo("Organization/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 unknown, the 0203 table lookup fails, and the coding has just the code, no system
// IN2.69.7
DatatypeUtils.checkCommonCodeableConceptAssertions(orgIdentifier.getType(), "UNK", null, null, 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 - Order matches order of identifier_X in Coverage.yml
// XV, XV, XV, MB, SN; but not MA (IN2.8) nor MC (IN2.6)
assertThat(coverage.getIdentifier()).hasSize(5);
// IN1.2.1
assertThat(coverage.getIdentifier().get(0).getValue()).isEqualTo("Value1");
// IN1.2.3
assertThat(coverage.getIdentifier().get(0).getSystem()).isEqualTo("urn:id:System3");
// No use, here
assertThat(coverage.getIdentifier().get(0).getUse()).isNull();
DatatypeUtils.checkCommonCodeableConceptAssertions(coverage.getIdentifier().get(0).getType(), "XV", "Health Plan Identifier", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
// IN1.2.4
assertThat(coverage.getIdentifier().get(1).getValue()).isEqualTo("Value4");
// IN1.2.6
assertThat(coverage.getIdentifier().get(1).getSystem()).isEqualTo("urn:id:System6");
// No use, here
assertThat(coverage.getIdentifier().get(1).getUse()).isNull();
DatatypeUtils.checkCommonCodeableConceptAssertions(coverage.getIdentifier().get(1).getType(), "XV", "Health Plan Identifier", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
// IN1.46
assertThat(coverage.getIdentifier().get(2).getValue()).isEqualTo("Value46");
// No system, here
assertThat(coverage.getIdentifier().get(2).getSystem()).isNull();
// Use is enumeration "old"
assertThat(coverage.getIdentifier().get(2).getUseElement().getCode()).hasToString("old");
DatatypeUtils.checkCommonCodeableConceptAssertions(coverage.getIdentifier().get(2).getType(), "XV", "Health Plan Identifier", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
// IN1.36
assertThat(coverage.getIdentifier().get(3).getValue()).isEqualTo("MEMBER36");
// No system, here
assertThat(coverage.getIdentifier().get(3).getSystem()).isNull();
// No use, here
assertThat(coverage.getIdentifier().get(3).getUse()).isNull();
DatatypeUtils.checkCommonCodeableConceptAssertions(coverage.getIdentifier().get(3).getType(), "MB", "Member Number", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
// IN1.36
assertThat(coverage.getIdentifier().get(4).getValue()).isEqualTo("MEMBER36");
// No system, here
assertThat(coverage.getIdentifier().get(4).getSystem()).isNull();
// No use, here
assertThat(coverage.getIdentifier().get(4).getUse()).isNull();
DatatypeUtils.checkCommonCodeableConceptAssertions(coverage.getIdentifier().get(4).getType(), "SN", "Subscriber Number", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
// Confirm SubscriberId
// IN1.36
assertThat(coverage.getSubscriberId()).isEqualTo("MEMBER36");
// Confirm coverage.Order
// IN1.22 takes priority over IN1.1
assertThat(coverage.getOrder()).isEqualTo(5);
// Confirm Coverage Beneficiary references to Patient, and Payor 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);
// Only one Coverage Class expected. (getClass_ is correct name for method)
assertThat(coverage.getClass_()).hasSize(3);
// IN1.8 Only has value
checkCoverageClassExistsWithCorrectValueAndName(coverage.getClass_(), "UA34567", null);
// IN1.9 (1)
checkCoverageClassExistsWithCorrectValueAndName(coverage.getClass_(), "IDBlue", "NameBlue");
// IN1.9 (2) Name is also used for value
checkCoverageClassExistsWithCorrectValueAndName(coverage.getClass_(), "NameGreen", "NameGreen");
// Confirm Coverage period
// IN1.12
assertThat(coverage.getPeriod().getStartElement().toString()).containsPattern("2020-12-31T14:50:45");
// IN1.13
assertThat(coverage.getPeriod().getEndElement().toString()).containsPattern("2021-12-31T14:50:45");
// Expect no RelatedPerson because IN1.17 was empty
List<Resource> relatedPersons = ResourceUtils.getResourceList(e, ResourceType.RelatedPerson);
// IN1.17 empty
assertThat(relatedPersons).isEmpty();
// Confirm there are no unaccounted for resources
// Expected: Coverage, Organization (3x), Patient, Encounter
assertThat(e).hasSize(6);
}
use of org.hl7.fhir.r4.model.HumanName in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7FinancialInsuranceTest method testInsuranceCoverageFromIN2.
@Test
// Tests empty IN2.63 missing telecom.
void testInsuranceCoverageFromIN2() throws IOException {
String hl7message = "MSH|^~\\&|||||20151008111200||ADT^A01^ADT_A01|MSGID000001|T|2.6|||||||||\n" + "EVN||20210407191342||||||\n" + "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 (See test testBasicInsuranceCoverageFields)
"|IdValue1^^^IdSystem4^^^^|Large Blue Organization|||||||||||" + // IN1.18 through IN1.35 NOT REFERENCED
"|DoeFake^Judy^^^Rev.|||||||||||||||||||" + // IN1.37 through IN1.53 NOT REFERENCED
"|MEMBER36|||||||||||||||||\n" + // IN2.63 purposely empty to ensure an empty telecom is not created.
"IN2||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" + // IN2.72 to Coverage.relationship and RelatedPerson.relationship. (Backup for IN1.17) Codes from table 0344
"04|\n";
// 04 = Natural child
List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
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();
List<Resource> organizations = ResourceUtils.getResourceList(e, ResourceType.Organization);
// From Payor created by IN1
assertThat(organizations).hasSize(1);
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, MB, SN
assertThat(coverage.getIdentifier()).hasSize(4);
// Coverage Identifiers deep check in testBasicInsuranceCoverageFields
// Confirm Coverage Beneficiary references to Patient, and Payor references to Organization
assertThat(coverage.getBeneficiary().getReference()).isEqualTo(patientId);
assertThat(coverage.getPayorFirstRep().getReference()).isEqualTo(organizations.get(0).getId());
// Expect one RelatedPerson
List<Resource> relatedPersons = ResourceUtils.getResourceList(e, ResourceType.RelatedPerson);
// From IN2.72
assertThat(relatedPersons).hasSize(1);
RelatedPerson related = (RelatedPerson) relatedPersons.get(0);
// Because IN2.63 is empty
assertThat(related.hasTelecom()).isFalse();
assertThat(related.getName()).hasSize(1);
HumanName relatedName = related.getName().get(0);
// Simplified name test. Deeper tests in other tests.
// from IN1.16 aggregate
assertThat(relatedName.getText()).isEqualTo("Rev. Judy DoeFake");
// Check coverage relationship
DatatypeUtils.checkCommonCodeableConceptAssertions(coverage.getRelationship(), "child", "Child", "http://terminology.hl7.org/CodeSystem/subscriber-relationship", // IN2.72 (04 = Natural child)
null);
// Check relatedPerson relationship
assertThat(related.getRelationship()).hasSize(1);
DatatypeUtils.checkCommonCodeableConceptAssertions(related.getRelationship().get(0), "PRN", "parent", "http://terminology.hl7.org/CodeSystem/v3-RoleCode", // IN2.72 (04 = Natural child)
null);
// Confirm the Coverage (subscriber) references the RelatedPerson
assertThat(coverage.getSubscriber().getReference()).isEqualTo(related.getId());
// Confirm the RelatedPerson references the Patient
assertThat(related.getPatient().getReference()).isEqualTo(patientId);
// Confirm there are no unaccounted for resources
// Expected: Coverage, Organization, Patient, Encounter, RelatedPerson
assertThat(e).hasSize(5);
}
use of org.hl7.fhir.r4.model.HumanName in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7FinancialInsuranceTest method testInsuranceCoverageByRelatedFields.
// 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")
@ParameterizedTest
// The breadth of this test is sufficent for multiple message type coverage, so other tests are not parameterized.
@ValueSource(strings = { "DFT^P03^DFT_P03", "VXU^V04^VXU_V04", "ADT^A01^ADT_A01", "ADT^A03^ADT_A03", // ADT^A04 uses structure ADT_A01
"ADT^A04^ADT_A01", // ADT^A08 uses structure ADT_A01
"ADT^A08^ADT_A01", // ADT^A28 uses structure ADT_A05
"ADT^A28^ADT_A05", // ADT^A31 uses structure ADT_A05
"ADT^A31^ADT_A05" })
// Also test IN2.2 Social Security number
void testInsuranceCoverageByRelatedFields(String messageType) throws IOException {
String hl7message = "MSH|^~\\&|||||20151008111200||" + messageType + "|MSGID000001|T|2.6|||||||||\n" + "EVN||20210407191342||||||\n" + "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 (See test testBasicInsuranceCoverageFields)
"|IdValue1^^^IdSystem4^^^^|Large Blue Organization|||||||||||" + // IN1.23 through IN1.35 NOT REFERENCED
"|DoeFake^Judy^^^Rev.|PAR|19780429|19 Rose St^^Faketown^CA^ZIP5||||||||||||||||" + // IN1.50 through IN1.53 NOT REFERENCED
"|MEMBER36|||||||F|||Value46|||J494949^^^Large HMO^XX||||\n" + // IN2.9 through IN2.60 not used
"IN2||777-88-9999||||MEDICARE06||MEDICAID08|| |||||||||| ||||||||||| |||||||||| |||||||||| ||||||||||" + // IN2.63.18 to Organization Contact telecom .rank
"MEMBER61||^^^^^555^7677777^^^^^^20201231145045^20211231145045^^^^1|";
List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
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();
// From PID.3, IN1.49, IN2.6, IN2.8
assertThat(patient.getIdentifier()).hasSize(4);
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.49.1
assertThat(patientIdentifier.getValue()).isEqualTo("J494949");
// IN1.49.4
assertThat(patientIdentifier.getSystem()).isEqualTo("urn:id:Large_HMO");
DatatypeUtils.checkCommonCodeableConceptAssertions(patientIdentifier.getType(), "XX", null, "http://terminology.hl7.org/CodeSystem/v2-0203", // IN1.49.5
null);
patientIdentifier = patient.getIdentifier().get(2);
// IN2.8
assertThat(patientIdentifier.getValue()).isEqualTo("MEDICAID08");
// No system for IN2.8
assertThat(patientIdentifier.hasSystem()).isFalse();
DatatypeUtils.checkCommonCodeableConceptAssertions(patientIdentifier.getType(), "MA", "Patient Medicaid number", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
patientIdentifier = patient.getIdentifier().get(3);
// IN2.6
assertThat(patientIdentifier.getValue()).isEqualTo("MEDICARE06");
// No system for IN2.6
assertThat(patientIdentifier.hasSystem()).isFalse();
DatatypeUtils.checkCommonCodeableConceptAssertions(patientIdentifier.getType(), "MC", "Patient's Medicare number", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
List<Resource> organizations = ResourceUtils.getResourceList(e, ResourceType.Organization);
// From Payor created by IN1
assertThat(organizations).hasSize(1);
List<Resource> coverages = ResourceUtils.getResourceList(e, ResourceType.Coverage);
// From IN1 segment
assertThat(coverages).hasSize(1);
Coverage coverage = (Coverage) coverages.get(0);
// Confirm Coverage Identifiers - Order matches order of identifier_X in Coverage.yml
// XV, XV, XV, MB, MA, MC, SN
assertThat(coverage.getIdentifier()).hasSize(7);
// IN1.2.1
assertThat(coverage.getIdentifier().get(0).getValue()).isEqualTo("Value1");
// IN1.2.3
assertThat(coverage.getIdentifier().get(0).getSystem()).isEqualTo("urn:id:System3");
// No use, here
assertThat(coverage.getIdentifier().get(0).getUse()).isNull();
DatatypeUtils.checkCommonCodeableConceptAssertions(coverage.getIdentifier().get(0).getType(), "XV", "Health Plan Identifier", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
// IN1.2.4
assertThat(coverage.getIdentifier().get(1).getValue()).isEqualTo("Value4");
// IN1.2.6
assertThat(coverage.getIdentifier().get(1).getSystem()).isEqualTo("urn:id:System6");
// No use, here
assertThat(coverage.getIdentifier().get(1).getUse()).isNull();
DatatypeUtils.checkCommonCodeableConceptAssertions(coverage.getIdentifier().get(1).getType(), "XV", "Health Plan Identifier", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
// IN1.46
assertThat(coverage.getIdentifier().get(2).getValue()).isEqualTo("Value46");
// No system, here
assertThat(coverage.getIdentifier().get(2).getSystem()).isNull();
// Use is enumeration "old"
assertThat(coverage.getIdentifier().get(2).getUseElement().getCode()).hasToString("old");
DatatypeUtils.checkCommonCodeableConceptAssertions(coverage.getIdentifier().get(2).getType(), "XV", "Health Plan Identifier", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
// IN2.61 takes priority over IN1.36
assertThat(coverage.getIdentifier().get(3).getValue()).isEqualTo("MEMBER61");
// No system, here
assertThat(coverage.getIdentifier().get(3).getSystem()).isNull();
// No use, here
assertThat(coverage.getIdentifier().get(3).getUse()).isNull();
DatatypeUtils.checkCommonCodeableConceptAssertions(coverage.getIdentifier().get(3).getType(), "MB", "Member Number", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
// IN2.8
assertThat(coverage.getIdentifier().get(4).getValue()).isEqualTo("MEDICAID08");
// No system, here
assertThat(coverage.getIdentifier().get(4).getSystem()).isNull();
// No use, here
assertThat(coverage.getIdentifier().get(4).getUse()).isNull();
DatatypeUtils.checkCommonCodeableConceptAssertions(coverage.getIdentifier().get(4).getType(), "MA", "Patient Medicaid number", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
// IN2.6
assertThat(coverage.getIdentifier().get(5).getValue()).isEqualTo("MEDICARE06");
// No system, here
assertThat(coverage.getIdentifier().get(5).getSystem()).isNull();
// No use, here
assertThat(coverage.getIdentifier().get(5).getUse()).isNull();
DatatypeUtils.checkCommonCodeableConceptAssertions(coverage.getIdentifier().get(5).getType(), "MC", "Patient's Medicare number", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
// IN1.36
assertThat(coverage.getIdentifier().get(6).getValue()).isEqualTo("MEMBER36");
// No system, here
assertThat(coverage.getIdentifier().get(6).getSystem()).isNull();
// No use, here
assertThat(coverage.getIdentifier().get(6).getUse()).isNull();
DatatypeUtils.checkCommonCodeableConceptAssertions(coverage.getIdentifier().get(6).getType(), "SN", "Subscriber Number", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
// Confirm Coverage Beneficiary references to Patient, and Payor references to Organization
assertThat(coverage.getBeneficiary().getReference()).isEqualTo(patientId);
assertThat(coverage.getPayorFirstRep().getReference()).isEqualTo(organizations.get(0).getId());
// Expect one RelatedPerson
List<Resource> relatedPersons = ResourceUtils.getResourceList(e, ResourceType.RelatedPerson);
// From IN1.16 through IN1.19; IN1.43; INI.49
assertThat(relatedPersons).hasSize(1);
RelatedPerson related = (RelatedPerson) relatedPersons.get(0);
// Check RelatedPerson identifiers
assertThat(related.getIdentifier()).hasSize(2);
// IN1.49.1
assertThat(related.getIdentifier().get(0).getValue()).isEqualTo("J494949");
// IN1.49.4
assertThat(related.getIdentifier().get(0).getSystem()).isEqualTo("urn:id:Large_HMO");
// IN1.49.5
DatatypeUtils.checkCommonCodeableConceptAssertions(// IN1.49.5
related.getIdentifier().get(0).getType(), // IN1.49.5
"XX", // Display value looked up from code 'XX'
"Organization identifier", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
// IN2.2
assertThat(related.getIdentifier().get(1).getValue()).isEqualTo("777-88-9999");
// No system to assign
assertThat(related.getIdentifier().get(1).hasSystem()).isFalse();
DatatypeUtils.checkCommonCodeableConceptAssertions(related.getIdentifier().get(1).getType(), "SS", "Social Security number", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
// Check RelatedPerson name. IN1.16 name is standard XPN, tested exhaustively in other tests.
assertThat(related.getName()).hasSize(1);
HumanName relatedName = related.getName().get(0);
// IN1.16.1
assertThat(relatedName.getFamily()).isEqualTo("DoeFake");
// IN1.16.2
assertThat(relatedName.getGiven().get(0).getValueAsString()).isEqualTo("Judy");
// IN1.16.6
assertThat(relatedName.getPrefixAsSingleString()).hasToString("Rev.");
// from IN1.16 aggregate
assertThat(relatedName.getText()).isEqualTo("Rev. Judy DoeFake");
// Check RelatedPerson birth and gender
// IN1.18
assertThat(related.getBirthDateElement().toString()).containsPattern("1978-04-29");
Enumerations.AdministrativeGender gen = related.getGender();
// IN1.43
assertThat(gen).isNotNull().isEqualTo(Enumerations.AdministrativeGender.FEMALE);
// Check the RelatedPerson address. IN1.19 is a standard XAD address, which is tested exhaustively in other tests.
assertThat(related.getAddress()).hasSize(1);
assertThat(related.getAddress().get(0).getLine().get(0).getValueAsString()).isEqualTo(// IN1.19.1
"19 Rose St");
// IN1.19.3
assertThat(related.getAddress().get(0).getCity()).isEqualTo("Faketown");
// IN1.19.4
assertThat(related.getAddress().get(0).getState()).isEqualTo("CA");
// IN1.19.5
assertThat(related.getAddress().get(0).getPostalCode()).isEqualTo("ZIP5");
// Check RelatedPerson telecom. IN2.63 is standard XTN, tested exhaustively in other tests.
// telecom is type ContactPoint
ContactPoint contactPoint = related.getTelecomFirstRep();
// default type hardcoded.
assertThat(contactPoint.getSystemElement().getCode()).hasToString("phone");
// Hard-coded to home. IN2.63.2 is not mapped (ignored).
assertThat(contactPoint.getUseElement().getCode()).isEqualTo("home");
// Hard-coded to home. IN2.63.2 is not mapped (ignored).
;
// IN2.63.6, IN2.63.7 via getFormattedTelecomNumberValue
assertThat(contactPoint.getValue()).hasToString("(555) 767 7777");
// IN2.63.13
assertThat(contactPoint.getPeriod().getStartElement().toString()).containsPattern("2020-12-31T14:50:45");
// IN2.63.14
assertThat(contactPoint.getPeriod().getEndElement().toString()).containsPattern("2021-12-31T14:50:45");
// IN2.63.18
assertThat(contactPoint.getRank()).isEqualTo(1);
// Check coverage relationship
DatatypeUtils.checkCommonCodeableConceptAssertions(coverage.getRelationship(), "child", "Child", "http://terminology.hl7.org/CodeSystem/subscriber-relationship", // IN1.17
null);
// Check relatedPerson relationship
assertThat(related.getRelationship()).hasSize(1);
DatatypeUtils.checkCommonCodeableConceptAssertions(related.getRelationship().get(0), "PRN", "parent", "http://terminology.hl7.org/CodeSystem/v3-RoleCode", // IN1.17
null);
// Confirm the Coverage (subscriber) references the RelatedPerson
assertThat(coverage.getSubscriber().getReference()).isEqualTo(related.getId());
// Confirm the RelatedPerson references the Patient
assertThat(related.getPatient().getReference()).isEqualTo(patientId);
// Confirm coverage.Order
// IN1.1 backup for missing IN1.22
assertThat(coverage.getOrder()).isEqualTo(1);
// Confirm there are no unaccounted for resources
// Expected: Coverage, Organization, Patient, Encounter, RelatedPerson
assertThat(e).hasSize(5);
}
use of org.hl7.fhir.r4.model.HumanName in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7MedicationRequestFHIRConversionTest method testMedicationRequestCategoryRequesterAndDispenseRequest.
@Test
void testMedicationRequestCategoryRequesterAndDispenseRequest() {
String hl7message = "MSH|^~\\&||||||S1|RDE^O11||T|2.6|||||||||\n" + "PID|||1234^^^^MR||DOE^JANE^|||F||||||||||||||||||||||\n" + // ORC.29 to category
"ORC|NW|||||||||||3122^PROVIDER^ORDERING^^^DR|||20190606193536||||||||||||||I\n" + // RXE.13 empty so ORC.12 takes priority
"RXE|^Q24H&0600^^20210330144208^^ROU|DUONEB3INH^3 ML PLAS CONT : IPRATROPIUM-ALBUTEROL 0.5-2.5 (3) MG/3ML IN SOLN^ADS|3||mL|47||||||||||||||||||||||||||||||||||\n";
List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
List<Resource> medicationRequestList = ResourceUtils.getResourceList(e, ResourceType.MedicationRequest);
assertThat(medicationRequestList).hasSize(1);
MedicationRequest medicationRequest = ResourceUtils.getResourceMedicationRequest(medicationRequestList.get(0), ResourceUtils.context);
// requester comes from ORC.12 which is the back up value for RXE.13
String requesterRef = medicationRequest.getRequester().getReference();
Practitioner practBundle = ResourceUtils.getSpecificPractitionerFromBundleEntriesList(e, requesterRef);
Identifier practitionerIdentifier = practBundle.getIdentifierFirstRep();
HumanName practName = practBundle.getNameFirstRep();
// ORC.12.1
assertThat(practitionerIdentifier.getValue()).isEqualTo("3122");
// ORC.12.9
assertThat(practitionerIdentifier.getSystem()).isNull();
// ORC.12.2
assertThat(practName.getFamily()).isEqualTo("PROVIDER");
// ORC.12.3
assertThat(practName.getGivenAsSingleString()).isEqualTo("ORDERING");
// ORC.12.6
assertThat(practName.getPrefixAsSingleString()).isEqualTo("DR");
// ORC.12.5
assertThat(practName.getSuffix()).isEmpty();
// ORC.12
assertThat(practName.getText()).isEqualTo("DR ORDERING PROVIDER");
// category comes from ORC.29
assertThat(medicationRequest.getCategory()).hasSize(1);
DatatypeUtils.checkCommonCodeableConceptAssertions(medicationRequest.getCategory().get(0), "inpatient", "Inpatient", "http://terminology.hl7.org/CodeSystem/medicationrequest-category", null);
// DispenseRequest.start comes from ORC.15
assertThat(medicationRequest.getDispenseRequest().hasValidityPeriod()).isTrue();
assertThat(medicationRequest.getDispenseRequest().getValidityPeriod().getStartElement().toString()).containsPattern("2019-06-06");
}
Aggregations