Search in sources :

Example 6 with Patient

use of org.hl7.fhir.r4.model.Patient in project beneficiary-fhir-data by CMSgov.

the class CoverageResourceProvider method searchByBeneficiary.

/**
 * Adds support for the FHIR "search" operation for {@link Coverage}s, allowing users to search by
 * {@link Coverage#getBeneficiary()}.
 *
 * <p>The {@link Search} annotation indicates that this method supports the search operation.
 * There may be many different methods annotated with this {@link Search} annotation, to support
 * many different search criteria.
 *
 * @param beneficiary a {@link ReferenceParam} for the {@link Coverage#getBeneficiary()} to try
 *     and find matches for
 * @param startIndex an {@link OptionalParam} for the startIndex (or offset) used to determine
 *     pagination
 * @param lastUpdated an {@link OptionalParam} to filter the results based on the passed date
 *     range
 * @param requestDetails a {@link RequestDetails} containing the details of the request URL, used
 *     to parse out pagination values
 * @return Returns a {@link List} of {@link Coverage}s, which may contain multiple matching
 *     resources, or may also be empty.
 */
@Search
@Trace
public Bundle searchByBeneficiary(@RequiredParam(name = Coverage.SP_BENEFICIARY) @Description(shortDefinition = "The patient identifier to search for") ReferenceParam beneficiary, @OptionalParam(name = "startIndex") @Description(shortDefinition = "The offset used for result pagination") String startIndex, @OptionalParam(name = "_lastUpdated") @Description(shortDefinition = "Include resources last updated in the given range") DateRangeParam lastUpdated, RequestDetails requestDetails) {
    List<IBaseResource> coverages;
    try {
        Beneficiary beneficiaryEntity = findBeneficiaryById(beneficiary.getIdPart(), lastUpdated);
        if (!beneficiaryEntity.getBeneEnrollmentReferenceYear().isPresent()) {
            throw new ResourceNotFoundException("Cannot find coverage for non present enrollment year");
        }
        coverages = CoverageTransformer.transform(metricRegistry, beneficiaryEntity);
    } catch (NoResultException e) {
        coverages = new LinkedList<IBaseResource>();
    }
    OffsetLinkBuilder paging = new OffsetLinkBuilder(requestDetails, "/Coverage?");
    Operation operation = new Operation(Operation.Endpoint.V1_COVERAGE);
    operation.setOption("by", "beneficiary");
    operation.setOption("pageSize", paging.isPagingRequested() ? "" + paging.getPageSize() : "*");
    operation.setOption("_lastUpdated", Boolean.toString(lastUpdated != null && !lastUpdated.isEmpty()));
    operation.publishOperationName();
    // Add bene_id to MDC logs
    TransformerUtils.logBeneIdToMdc(Arrays.asList(beneficiary.getIdPart()));
    return TransformerUtils.createBundle(paging, coverages, loadedFilterManager.getTransactionTime());
}
Also used : OffsetLinkBuilder(gov.cms.bfd.server.war.commons.OffsetLinkBuilder) NoResultException(javax.persistence.NoResultException) Operation(gov.cms.bfd.server.war.Operation) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) LinkedList(java.util.LinkedList) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) Trace(com.newrelic.api.agent.Trace) Search(ca.uhn.fhir.rest.annotation.Search)

Example 7 with Patient

use of org.hl7.fhir.r4.model.Patient 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;
}
Also used : BeneficiaryHistory(gov.cms.bfd.model.rif.BeneficiaryHistory) ArrayList(java.util.ArrayList) Patient(org.hl7.fhir.dstu3.model.Patient) Period(org.hl7.fhir.dstu3.model.Period) MedicareBeneficiaryIdHistory(gov.cms.bfd.model.rif.MedicareBeneficiaryIdHistory) Extension(org.hl7.fhir.dstu3.model.Extension) HumanName(org.hl7.fhir.dstu3.model.HumanName) DateTimeType(org.hl7.fhir.dstu3.model.DateTimeType)

Example 8 with Patient

use of org.hl7.fhir.r4.model.Patient in project beneficiary-fhir-data by CMSgov.

the class FissClaimResponseTransformerV2 method transformClaim.

/**
 * @param claimGroup the {@link PreAdjFissClaim} to transform
 * @return a FHIR {@link ClaimResponse} resource that represents the specified {@link
 *     PreAdjFissClaim}
 */
private static ClaimResponse transformClaim(PreAdjFissClaim claimGroup) {
    ClaimResponse claim = new ClaimResponse();
    claim.setId("f-" + claimGroup.getDcn());
    claim.setContained(List.of(getContainedPatient(claimGroup)));
    claim.setExtension(getExtension(claimGroup));
    claim.setIdentifier(getIdentifier(claimGroup));
    claim.setStatus(ClaimResponse.ClaimResponseStatus.ACTIVE);
    claim.setOutcome(STATUS_TO_OUTCOME.get(Character.toLowerCase(claimGroup.getCurrStatus())));
    claim.setType(getType());
    claim.setUse(ClaimResponse.Use.CLAIM);
    claim.setInsurer(new Reference().setIdentifier(new Identifier().setValue("CMS")));
    claim.setPatient(new Reference("#patient"));
    claim.setRequest(new Reference(String.format("Claim/f-%s", claimGroup.getDcn())));
    claim.setMeta(new Meta().setLastUpdated(Date.from(claimGroup.getLastUpdated())));
    claim.setCreated(new Date());
    return claim;
}
Also used : Meta(org.hl7.fhir.r4.model.Meta) Identifier(org.hl7.fhir.r4.model.Identifier) ClaimResponse(org.hl7.fhir.r4.model.ClaimResponse) Reference(org.hl7.fhir.r4.model.Reference) Date(java.util.Date)

Example 9 with Patient

use of org.hl7.fhir.r4.model.Patient in project beneficiary-fhir-data by CMSgov.

the class FissClaimTransformerV2 method transformClaim.

/**
 * @param claimGroup the {@link PreAdjFissClaim} to transform
 * @return a FHIR {@link Claim} resource that represents the specified {@link PreAdjFissClaim}
 */
private static Claim transformClaim(PreAdjFissClaim claimGroup) {
    Claim claim = new Claim();
    boolean isIcd9 = claimGroup.getStmtCovToDate() != null && claimGroup.getStmtCovToDate().isBefore(ICD_9_CUTOFF_DATE);
    claim.setId("f-" + claimGroup.getDcn());
    claim.setContained(List.of(getContainedPatient(claimGroup), getContainedProvider(claimGroup)));
    claim.setIdentifier(getIdentifier(claimGroup));
    claim.setExtension(getExtension(claimGroup));
    claim.setStatus(Claim.ClaimStatus.ACTIVE);
    claim.setType(getType(claimGroup));
    claim.setSupportingInfo(getSupportingInfo(claimGroup));
    claim.setBillablePeriod(getBillablePeriod(claimGroup));
    claim.setUse(Claim.Use.CLAIM);
    claim.setPriority(getPriority());
    claim.setTotal(getTotal(claimGroup));
    claim.setProvider(new Reference("#provider-org"));
    claim.setPatient(new Reference("#patient"));
    claim.setFacility(getFacility(claimGroup));
    claim.setDiagnosis(getDiagnosis(claimGroup, isIcd9));
    claim.setProcedure(getProcedure(claimGroup, isIcd9));
    claim.setInsurance(getInsurance(claimGroup));
    claim.setMeta(new Meta().setLastUpdated(Date.from(claimGroup.getLastUpdated())));
    claim.setCreated(new Date());
    return claim;
}
Also used : Meta(org.hl7.fhir.r4.model.Meta) Reference(org.hl7.fhir.r4.model.Reference) PreAdjFissClaim(gov.cms.bfd.model.rda.PreAdjFissClaim) Claim(org.hl7.fhir.r4.model.Claim) Date(java.util.Date) LocalDate(java.time.LocalDate)

Example 10 with Patient

use of org.hl7.fhir.r4.model.Patient in project beneficiary-fhir-data by CMSgov.

the class DMEClaimTransformerV2Test method shouldHaveLineItemLocationCodeableConcept.

@Test
public void shouldHaveLineItemLocationCodeableConcept() {
    CodeableConcept location = eob.getItemFirstRep().getLocationCodeableConcept();
    CodeableConcept compare = new CodeableConcept().setCoding(Arrays.asList(new Coding("https://bluebutton.cms.gov/resources/variables/line_place_of_srvc_cd", "12", "Home. Location, other than a hospital or other facility, where the patient receives care in a private residence.")));
    compare.setExtension(Arrays.asList(new Extension("https://bluebutton.cms.gov/resources/variables/prvdr_state_cd", new Coding("https://bluebutton.cms.gov/resources/variables/prvdr_state_cd", "MO", null))));
    assertTrue(compare.equalsDeep(location));
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) Coding(org.hl7.fhir.r4.model.Coding) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.Test)576 Test (org.junit.jupiter.api.Test)442 Patient (org.hl7.fhir.r4.model.Patient)437 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)255 HashMap (java.util.HashMap)251 Patient (org.hl7.fhir.dstu3.model.Patient)249 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)228 Bundle (org.hl7.fhir.r4.model.Bundle)203 Path (javax.ws.rs.Path)188 Date (java.util.Date)171 Produces (javax.ws.rs.Produces)163 ArrayList (java.util.ArrayList)156 JsonObject (javax.json.JsonObject)141 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)140 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)138 ReferenceParam (ca.uhn.fhir.rest.param.ReferenceParam)137 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)128 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)128 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)125 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)120