use of org.hl7.fhir.r4b.model.Period in project beneficiary-fhir-data by CMSgov.
the class CoverageTransformer method transformPartA.
/**
* @param metricRegistry the {@link MetricRegistry} to use
* @param beneficiary the {@link Beneficiary} to generate a {@link MedicareSegment#PART_A} {@link
* Coverage} resource for
* @return {@link MedicareSegment#PART_A} {@link Coverage} resource for the specified {@link
* Beneficiary}
*/
private static Coverage transformPartA(MetricRegistry metricRegistry, Beneficiary beneficiary) {
Timer.Context timer = metricRegistry.timer(MetricRegistry.name(CoverageTransformer.class.getSimpleName(), "transform", "part_a")).time();
Objects.requireNonNull(beneficiary);
Coverage coverage = new Coverage();
coverage.setId(TransformerUtils.buildCoverageId(MedicareSegment.PART_A, beneficiary));
if (beneficiary.getPartATerminationCode().isPresent() && beneficiary.getPartATerminationCode().get().equals('0'))
coverage.setStatus(CoverageStatus.ACTIVE);
else
coverage.setStatus(CoverageStatus.CANCELLED);
if (beneficiary.getMedicareCoverageStartDate().isPresent()) {
TransformerUtils.setPeriodStart(coverage.getPeriod(), beneficiary.getMedicareCoverageStartDate().get());
}
// deh start
coverage.addContract().setId("ptc-contract1");
Contract newContract = new Contract();
LocalDate localDate = LocalDate.now();
newContract.setIdentifier(new Identifier().setSystem("part C System").setValue("contract 5555"));
newContract.setApplies((new Period().setStart((TransformerUtils.convertToDate(localDate)), TemporalPrecisionEnum.DAY)));
coverage.addContained(newContract);
coverage.addContract(TransformerUtils.referenceCoverage("contract1 reference", MedicareSegment.PART_A));
coverage.getGrouping().setSubGroup(TransformerConstants.COVERAGE_PLAN).setSubPlan(TransformerConstants.COVERAGE_PLAN_PART_A);
coverage.setType(TransformerUtils.createCodeableConcept(TransformerConstants.COVERAGE_PLAN, TransformerConstants.COVERAGE_PLAN_PART_A));
coverage.setBeneficiary(TransformerUtils.referencePatient(beneficiary));
if (beneficiary.getMedicareEnrollmentStatusCode().isPresent()) {
coverage.addExtension(TransformerUtils.createExtensionCoding(coverage, CcwCodebookVariable.MS_CD, beneficiary.getMedicareEnrollmentStatusCode()));
}
if (beneficiary.getEntitlementCodeOriginal().isPresent()) {
coverage.addExtension(TransformerUtils.createExtensionCoding(coverage, CcwCodebookVariable.OREC, beneficiary.getEntitlementCodeOriginal()));
}
if (beneficiary.getEntitlementCodeCurrent().isPresent()) {
coverage.addExtension(TransformerUtils.createExtensionCoding(coverage, CcwCodebookVariable.CREC, beneficiary.getEntitlementCodeCurrent()));
}
if (beneficiary.getEndStageRenalDiseaseCode().isPresent()) {
coverage.addExtension(TransformerUtils.createExtensionCoding(coverage, CcwCodebookVariable.ESRD_IND, beneficiary.getEndStageRenalDiseaseCode()));
}
if (beneficiary.getPartATerminationCode().isPresent()) {
coverage.addExtension(TransformerUtils.createExtensionCoding(coverage, CcwCodebookVariable.A_TRM_CD, beneficiary.getPartATerminationCode()));
}
// The reference year of the enrollment data
if (beneficiary.getBeneEnrollmentReferenceYear().isPresent()) {
coverage.addExtension(TransformerUtils.createExtensionDate(CcwCodebookVariable.RFRNC_YR, beneficiary.getBeneEnrollmentReferenceYear()));
}
// Monthly Medicare-Medicaid dual eligibility codes
if (beneficiary.getMedicaidDualEligibilityJanCode().isPresent()) {
coverage.addExtension(TransformerUtils.createExtensionCoding(coverage, CcwCodebookVariable.DUAL_01, beneficiary.getMedicaidDualEligibilityJanCode()));
}
if (beneficiary.getMedicaidDualEligibilityFebCode().isPresent()) {
coverage.addExtension(TransformerUtils.createExtensionCoding(coverage, CcwCodebookVariable.DUAL_02, beneficiary.getMedicaidDualEligibilityFebCode()));
}
if (beneficiary.getMedicaidDualEligibilityMarCode().isPresent()) {
coverage.addExtension(TransformerUtils.createExtensionCoding(coverage, CcwCodebookVariable.DUAL_03, beneficiary.getMedicaidDualEligibilityMarCode()));
}
if (beneficiary.getMedicaidDualEligibilityAprCode().isPresent()) {
coverage.addExtension(TransformerUtils.createExtensionCoding(coverage, CcwCodebookVariable.DUAL_04, beneficiary.getMedicaidDualEligibilityAprCode()));
}
if (beneficiary.getMedicaidDualEligibilityMayCode().isPresent()) {
coverage.addExtension(TransformerUtils.createExtensionCoding(coverage, CcwCodebookVariable.DUAL_05, beneficiary.getMedicaidDualEligibilityMayCode()));
}
if (beneficiary.getMedicaidDualEligibilityJunCode().isPresent()) {
coverage.addExtension(TransformerUtils.createExtensionCoding(coverage, CcwCodebookVariable.DUAL_06, beneficiary.getMedicaidDualEligibilityJunCode()));
}
if (beneficiary.getMedicaidDualEligibilityJulCode().isPresent()) {
coverage.addExtension(TransformerUtils.createExtensionCoding(coverage, CcwCodebookVariable.DUAL_07, beneficiary.getMedicaidDualEligibilityJulCode()));
}
if (beneficiary.getMedicaidDualEligibilityAugCode().isPresent()) {
coverage.addExtension(TransformerUtils.createExtensionCoding(coverage, CcwCodebookVariable.DUAL_08, beneficiary.getMedicaidDualEligibilityAugCode()));
}
if (beneficiary.getMedicaidDualEligibilitySeptCode().isPresent()) {
coverage.addExtension(TransformerUtils.createExtensionCoding(coverage, CcwCodebookVariable.DUAL_09, beneficiary.getMedicaidDualEligibilitySeptCode()));
}
if (beneficiary.getMedicaidDualEligibilityOctCode().isPresent()) {
coverage.addExtension(TransformerUtils.createExtensionCoding(coverage, CcwCodebookVariable.DUAL_10, beneficiary.getMedicaidDualEligibilityOctCode()));
}
if (beneficiary.getMedicaidDualEligibilityNovCode().isPresent()) {
coverage.addExtension(TransformerUtils.createExtensionCoding(coverage, CcwCodebookVariable.DUAL_11, beneficiary.getMedicaidDualEligibilityNovCode()));
}
if (beneficiary.getMedicaidDualEligibilityDecCode().isPresent()) {
coverage.addExtension(TransformerUtils.createExtensionCoding(coverage, CcwCodebookVariable.DUAL_12, beneficiary.getMedicaidDualEligibilityDecCode()));
}
transformEntitlementBuyInIndicators(coverage, beneficiary);
TransformerUtils.setLastUpdated(coverage, beneficiary.getLastUpdated());
timer.stop();
return coverage;
}
use of org.hl7.fhir.r4b.model.Period in project beneficiary-fhir-data by CMSgov.
the class BeneficiaryTransformer 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);
}
patient.setId(beneficiary.getBeneficiaryId());
patient.addIdentifier(TransformerUtils.createIdentifier(CcwCodebookVariable.BENE_ID, beneficiary.getBeneficiaryId()));
// Add hicn-hash identifier ONLY if raw hicn is requested.
if (requestHeader.isHICNinIncludeIdentifiers()) {
patient.addIdentifier().setSystem(TransformerConstants.CODING_BBAPI_BENE_HICN_HASH).setValue(beneficiary.getHicn());
}
if (beneficiary.getMbiHash().isPresent()) {
Period mbiPeriod = new Period();
if (beneficiary.getMbiEffectiveDate().isPresent()) {
TransformerUtils.setPeriodStart(mbiPeriod, beneficiary.getMbiEffectiveDate().get());
}
if (beneficiary.getMbiObsoleteDate().isPresent()) {
TransformerUtils.setPeriodEnd(mbiPeriod, beneficiary.getMbiObsoleteDate().get());
}
if (mbiPeriod.hasStart() || mbiPeriod.hasEnd()) {
patient.addIdentifier().setSystem(TransformerConstants.CODING_BBAPI_BENE_MBI_HASH).setValue(beneficiary.getMbiHash().get()).setPeriod(mbiPeriod);
} else {
patient.addIdentifier().setSystem(TransformerConstants.CODING_BBAPI_BENE_MBI_HASH).setValue(beneficiary.getMbiHash().get());
}
}
Extension currentIdentifier = TransformerUtils.createIdentifierCurrencyExtension(CurrencyIdentifier.CURRENT);
Extension historicalIdentifier = TransformerUtils.createIdentifierCurrencyExtension(CurrencyIdentifier.HISTORIC);
// Add lastUpdated
TransformerUtils.setLastUpdated(patient, beneficiary.getLastUpdated());
if (requestHeader.isHICNinIncludeIdentifiers()) {
Optional<String> hicnUnhashedCurrent = beneficiary.getHicnUnhashed();
if (hicnUnhashedCurrent.isPresent())
addUnhashedIdentifier(patient, hicnUnhashedCurrent.get(), TransformerConstants.CODING_BBAPI_BENE_HICN_UNHASHED, currentIdentifier);
List<String> unhashedHicns = new ArrayList<String>();
for (BeneficiaryHistory beneHistory : beneficiary.getBeneficiaryHistories()) {
Optional<String> hicnUnhashedHistoric = beneHistory.getHicnUnhashed();
if (hicnUnhashedHistoric.isPresent())
unhashedHicns.add(hicnUnhashedHistoric.get());
TransformerUtils.updateMaxLastUpdated(patient, beneHistory.getLastUpdated());
}
List<String> unhashedHicnsNoDupes = unhashedHicns.stream().distinct().collect(Collectors.toList());
for (String hicn : unhashedHicnsNoDupes) {
addUnhashedIdentifier(patient, hicn, TransformerConstants.CODING_BBAPI_BENE_HICN_UNHASHED, historicalIdentifier);
}
}
if (requestHeader.isMBIinIncludeIdentifiers()) {
Optional<String> mbiUnhashedCurrent = beneficiary.getMedicareBeneficiaryId();
if (mbiUnhashedCurrent.isPresent())
addUnhashedIdentifier(patient, mbiUnhashedCurrent.get(), TransformerConstants.CODING_BBAPI_MEDICARE_BENEFICIARY_ID_UNHASHED, currentIdentifier);
List<String> unhashedMbis = new ArrayList<String>();
for (MedicareBeneficiaryIdHistory mbiHistory : beneficiary.getMedicareBeneficiaryIdHistories()) {
Optional<String> mbiUnhashedHistoric = mbiHistory.getMedicareBeneficiaryId();
if (mbiUnhashedHistoric.isPresent())
unhashedMbis.add(mbiUnhashedHistoric.get());
TransformerUtils.updateMaxLastUpdated(patient, mbiHistory.getLastUpdated());
}
List<String> unhashedMbisNoDupes = unhashedMbis.stream().distinct().collect(Collectors.toList());
for (String mbi : unhashedMbisNoDupes) {
addUnhashedIdentifier(patient, mbi, TransformerConstants.CODING_BBAPI_MEDICARE_BENEFICIARY_ID_UNHASHED, historicalIdentifier);
}
}
// support header includeAddressFields from downstream components e.g. BB2
// per requirement of BFD-379, BB2 always send header includeAddressFields = False
Boolean addrHdrVal = requestHeader.getValue(PatientResourceProvider.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(TransformerUtils.convertToDate(beneficiary.getBirthDate()));
}
// Death Date
if (beneficiary.getBeneficiaryDateOfDeath().isPresent()) {
patient.setDeceased(new DateTimeType(TransformerUtils.convertToDate(beneficiary.getBeneficiaryDateOfDeath().get()), TemporalPrecisionEnum.DAY));
}
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(TransformerUtils.createExtensionCoding(patient, CcwCodebookVariable.RACE, beneficiary.getRace().get()));
}
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(TransformerUtils.createExtensionDate(CcwCodebookVariable.RFRNC_YR, beneficiary.getBeneEnrollmentReferenceYear()));
}
// Monthly Medicare-Medicaid dual eligibility codes
if (beneficiary.getMedicaidDualEligibilityJanCode().isPresent()) {
patient.addExtension(TransformerUtils.createExtensionCoding(patient, CcwCodebookVariable.DUAL_01, beneficiary.getMedicaidDualEligibilityJanCode()));
}
if (beneficiary.getMedicaidDualEligibilityFebCode().isPresent()) {
patient.addExtension(TransformerUtils.createExtensionCoding(patient, CcwCodebookVariable.DUAL_02, beneficiary.getMedicaidDualEligibilityFebCode()));
}
if (beneficiary.getMedicaidDualEligibilityMarCode().isPresent()) {
patient.addExtension(TransformerUtils.createExtensionCoding(patient, CcwCodebookVariable.DUAL_03, beneficiary.getMedicaidDualEligibilityMarCode()));
}
if (beneficiary.getMedicaidDualEligibilityAprCode().isPresent()) {
patient.addExtension(TransformerUtils.createExtensionCoding(patient, CcwCodebookVariable.DUAL_04, beneficiary.getMedicaidDualEligibilityAprCode()));
}
if (beneficiary.getMedicaidDualEligibilityMayCode().isPresent()) {
patient.addExtension(TransformerUtils.createExtensionCoding(patient, CcwCodebookVariable.DUAL_05, beneficiary.getMedicaidDualEligibilityMayCode()));
}
if (beneficiary.getMedicaidDualEligibilityJunCode().isPresent()) {
patient.addExtension(TransformerUtils.createExtensionCoding(patient, CcwCodebookVariable.DUAL_06, beneficiary.getMedicaidDualEligibilityJunCode()));
}
if (beneficiary.getMedicaidDualEligibilityJulCode().isPresent()) {
patient.addExtension(TransformerUtils.createExtensionCoding(patient, CcwCodebookVariable.DUAL_07, beneficiary.getMedicaidDualEligibilityJulCode()));
}
if (beneficiary.getMedicaidDualEligibilityAugCode().isPresent()) {
patient.addExtension(TransformerUtils.createExtensionCoding(patient, CcwCodebookVariable.DUAL_08, beneficiary.getMedicaidDualEligibilityAugCode()));
}
if (beneficiary.getMedicaidDualEligibilitySeptCode().isPresent()) {
patient.addExtension(TransformerUtils.createExtensionCoding(patient, CcwCodebookVariable.DUAL_09, beneficiary.getMedicaidDualEligibilitySeptCode()));
}
if (beneficiary.getMedicaidDualEligibilityOctCode().isPresent()) {
patient.addExtension(TransformerUtils.createExtensionCoding(patient, CcwCodebookVariable.DUAL_10, beneficiary.getMedicaidDualEligibilityOctCode()));
}
if (beneficiary.getMedicaidDualEligibilityNovCode().isPresent()) {
patient.addExtension(TransformerUtils.createExtensionCoding(patient, CcwCodebookVariable.DUAL_11, beneficiary.getMedicaidDualEligibilityNovCode()));
}
if (beneficiary.getMedicaidDualEligibilityDecCode().isPresent()) {
patient.addExtension(TransformerUtils.createExtensionCoding(patient, CcwCodebookVariable.DUAL_12, beneficiary.getMedicaidDualEligibilityDecCode()));
}
return patient;
}
use of org.hl7.fhir.r4b.model.Period in project beneficiary-fhir-data by CMSgov.
the class InpatientClaimTransformerV2Test method shouldHaveAdmissionPeriodSupInfo.
@Test
public void shouldHaveAdmissionPeriodSupInfo() {
SupportingInformationComponent sic = TransformerTestUtilsV2.findSupportingInfoByCode("admissionperiod", eob.getSupportingInfo());
SupportingInformationComponent compare = TransformerTestUtilsV2.createSupportingInfo(// We don't care what the sequence number is here
sic.getSequence(), // Category
Arrays.asList(new Coding("http://hl7.org/fhir/us/carin-bb/CodeSystem/C4BBSupportingInfoType", "admissionperiod", "Admission Period"))).setTiming(// Period
new Period().setStartElement(new DateTimeType("2016-01-15")).setEndElement(new DateTimeType("2016-01-27")));
assertTrue(compare.equalsDeep(sic));
}
use of org.hl7.fhir.r4b.model.Period in project beneficiary-fhir-data by CMSgov.
the class BeneficiaryTransformerV2Test method shouldIncludeMedicareExtensionIdentifierCurrent.
@Test
public void shouldIncludeMedicareExtensionIdentifierCurrent() {
Identifier mcId = TransformerTestUtilsV2.findIdentifierBySystem("http://hl7.org/fhir/sid/us-mbi", patient.getIdentifier());
Extension extension = new Extension("https://bluebutton.cms.gov/resources/codesystem/identifier-currency", new Coding("https://bluebutton.cms.gov/resources/codesystem/identifier-currency", "current", "Current"));
Period period = new Period();
try {
Date start = (new SimpleDateFormat("yyyy-MM-dd")).parse("2020-07-30");
period.setStart(start, TemporalPrecisionEnum.DAY);
} catch (Exception e) {
}
Identifier compare = new Identifier();
compare.setValue("3456789").setSystem("http://hl7.org/fhir/sid/us-mbi").setPeriod(period).getType().addCoding().setCode("MC").setSystem("http://terminology.hl7.org/CodeSystem/v2-0203").setDisplay("Patient's Medicare number").addExtension(extension);
assertTrue(compare.equalsDeep(mcId));
}
use of org.hl7.fhir.r4b.model.Period 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;
}
Aggregations