use of org.hl7.fhir.r4.model.Identifier in project beneficiary-fhir-data by CMSgov.
the class TransformerUtilsV2 method addProviderSlice.
/**
* Looks up or adds a contained {@link Organization} object to the current {@link
* ExplanationOfBenefit}. This is used to store Identifier slices related to the Provider
* organization.
*
* @param eob The {@link ExplanationOfBenefit} to provider org details to
* @param type The {@link C4BBIdentifierType} of the identifier slice
* @param value The value of the identifier. If empty, this call is a no-op
*/
static void addProviderSlice(ExplanationOfBenefit eob, C4BBOrganizationIdentifierType type, Optional<String> value, Optional<Instant> lastUpdated) {
if (value.isPresent()) {
Resource providerResource = findOrCreateContainedOrg(eob, PROVIDER_ORG_ID);
// We are assuming that the contained resource with an id of "provider-org" is an Organization
if (!Organization.class.isInstance(providerResource)) {
throw new BadCodeMonkeyException();
}
Organization provider = (Organization) providerResource;
// Add the new Identifier to the Organization
Identifier id = new Identifier().setType(createCodeableConcept(type.getSystem(), type.toCode())).setValue(value.get());
// Certain types have specific systems
if (type == C4BBOrganizationIdentifierType.NPI) {
id.setSystem(TransformerConstants.CODING_NPI_US);
}
provider.addIdentifier(id);
// Set active to value of true
provider.setActive(true);
setLastUpdated(provider, lastUpdated);
// This gets updated for every call, but always set to the same value
eob.getProvider().setReference(PROVIDER_ORG_REFERENCE);
}
}
use of org.hl7.fhir.r4.model.Identifier 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.Identifier in project beneficiary-fhir-data by CMSgov.
the class TransformerTestUtils method assertExtensionIdentifierEqualsString.
/**
* Tests that the specified extension list contains a single Identifier with the expected string
* value
*
* @param extension a {@link List}<{@link Extension}> containing an Identifier
* @param expected a {@link String} containing the expected value of the Identifier
*/
static void assertExtensionIdentifierEqualsString(List<Extension> extension, String expected) {
assertEquals(1, extension.size());
assertTrue(extension.get(0).getValue() instanceof Identifier);
Identifier identifier = (Identifier) extension.get(0).getValue();
assertEquals(expected, identifier.getValue());
}
use of org.hl7.fhir.r4.model.Identifier in project beneficiary-fhir-data by CMSgov.
the class PatientResourceProviderIT method readExistingPatientWithNoHistoryIncludeIdentifiersTrue.
/**
* Verifies that {@link
* gov.cms.bfd.server.war.stu3.providers.PatientResourceProvider#read(org.hl7.fhir.dstu3.model.IdType)}
* works as expected for a {@link Patient} that does exist in the DB but has no {@link
* BeneficiaryHistory} or {@link MedicareBeneficiaryIdHistory} records when include identifiers
* value = ["true"].
*/
@Test
public void readExistingPatientWithNoHistoryIncludeIdentifiersTrue() {
List<Object> loadedRecords = ServerTestUtils.get().loadData(Arrays.asList(StaticRifResource.SAMPLE_A_BENES));
RequestHeaders requestHeader = RequestHeaders.getHeaderWrapper(PatientResourceProvider.HEADER_NAME_INCLUDE_IDENTIFIERS, "true", PatientResourceProvider.HEADER_NAME_INCLUDE_ADDRESS_FIELDS, "true");
IGenericClient fhirClient = createFhirClient(requestHeader);
Beneficiary beneficiary = loadedRecords.stream().filter(r -> r instanceof Beneficiary).map(r -> (Beneficiary) r).findFirst().get();
Patient patient = fhirClient.read().resource(Patient.class).withId(beneficiary.getBeneficiaryId()).execute();
assertNotNull(patient);
BeneficiaryTransformerTest.assertMatches(beneficiary, patient, requestHeader);
/*
* Ensure the unhashed values for HICN and MBI are present.
*/
Boolean hicnUnhashedPresent = false;
Boolean mbiUnhashedPresent = false;
Iterator<Identifier> identifiers = patient.getIdentifier().iterator();
while (identifiers.hasNext()) {
Identifier identifier = identifiers.next();
if (identifier.getSystem().equals(TransformerConstants.CODING_BBAPI_BENE_HICN_UNHASHED))
hicnUnhashedPresent = true;
if (identifier.getSystem().equals(TransformerConstants.CODING_BBAPI_MEDICARE_BENEFICIARY_ID_UNHASHED))
mbiUnhashedPresent = true;
}
assertTrue(hicnUnhashedPresent);
assertTrue(mbiUnhashedPresent);
}
use of org.hl7.fhir.r4.model.Identifier in project beneficiary-fhir-data by CMSgov.
the class PatientResourceProviderIT method searchForExistingPatientByMbiHashIncludeIdentifiersFalse.
/**
* Verifies that {@link
* gov.cms.bfd.server.war.stu3.providers.PatientResourceProvider#searchByIdentifier(ca.uhn.fhir.rest.param.TokenParam)}
* works as expected for a {@link Patient} that does exist in the DB, including identifiers to
* return the unhashed HICN and MBI.
*/
@Test
public void searchForExistingPatientByMbiHashIncludeIdentifiersFalse() {
List<Object> loadedRecords = ServerTestUtils.get().loadData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
IGenericClient fhirClient = createFhirClient("false", "true");
Beneficiary beneficiary = loadedRecords.stream().filter(r -> r instanceof Beneficiary).map(r -> (Beneficiary) r).findFirst().get();
Bundle searchResults = fhirClient.search().forResource(Patient.class).where(Patient.IDENTIFIER.exactly().systemAndIdentifier(TransformerConstants.CODING_BBAPI_BENE_MBI_HASH, beneficiary.getMbiHash().get())).returnBundle(Bundle.class).execute();
assertNotNull(searchResults);
Patient patientFromSearchResult = (Patient) searchResults.getEntry().get(0).getResource();
/*
* Ensure the unhashed values for HICN and MBI are *not* present.
*/
Boolean hicnUnhashedPresent = false;
Boolean mbiUnhashedPresent = false;
Iterator<Identifier> identifiers = patientFromSearchResult.getIdentifier().iterator();
while (identifiers.hasNext()) {
Identifier identifier = identifiers.next();
if (identifier.getSystem().equals(TransformerConstants.CODING_BBAPI_BENE_HICN_UNHASHED))
hicnUnhashedPresent = true;
if (identifier.getSystem().equals(TransformerConstants.CODING_BBAPI_MEDICARE_BENEFICIARY_ID_UNHASHED))
mbiUnhashedPresent = true;
}
assertFalse(hicnUnhashedPresent);
assertFalse(mbiUnhashedPresent);
}
Aggregations