Search in sources :

Example 1 with Identifier

use of org.hl7.fhir.r4b.model.Identifier in project beneficiary-fhir-data by CMSgov.

the class TransformerUtils method addCareTeamPractitioner.

/**
 * Ensures that the specified {@link ExplanationOfBenefit} has the specified {@link
 * CareTeamComponent}, and links the specified {@link ItemComponent} to that {@link
 * CareTeamComponent} (via {@link ItemComponent#addCareTeamLinkId(int)}).
 *
 * @param eob the {@link ExplanationOfBenefit} that the {@link CareTeamComponent} should be part
 *     of
 * @param eobItem the {@link ItemComponent} that should be linked to the {@link CareTeamComponent}
 * @param practitionerIdSystem the {@link Identifier#getSystem()} of the practitioner to reference
 *     in {@link CareTeamComponent#getProvider()}
 * @param practitionerIdValue the {@link Identifier#getValue()} of the practitioner to reference
 *     in {@link CareTeamComponent#getProvider()}
 * @param careTeamRole the {@link ClaimCareteamrole} to use for the {@link
 *     CareTeamComponent#getRole()}
 * @return the {@link CareTeamComponent} that was created/linked
 */
static CareTeamComponent addCareTeamPractitioner(ExplanationOfBenefit eob, ItemComponent eobItem, String practitionerIdSystem, String practitionerIdValue, ClaimCareteamrole careTeamRole) {
    // Try to find a matching pre-existing entry.
    CareTeamComponent careTeamEntry = eob.getCareTeam().stream().filter(ctc -> ctc.getProvider().hasIdentifier()).filter(ctc -> practitionerIdSystem.equals(ctc.getProvider().getIdentifier().getSystem()) && practitionerIdValue.equals(ctc.getProvider().getIdentifier().getValue())).filter(ctc -> ctc.hasRole()).filter(ctc -> careTeamRole.toCode().equals(ctc.getRole().getCodingFirstRep().getCode()) && careTeamRole.getSystem().equals(ctc.getRole().getCodingFirstRep().getSystem())).findAny().orElse(null);
    // If no match was found, add one to the EOB.
    if (careTeamEntry == null) {
        careTeamEntry = eob.addCareTeam();
        careTeamEntry.setSequence(eob.getCareTeam().size() + 1);
        careTeamEntry.setProvider(createIdentifierReference(practitionerIdSystem, practitionerIdValue));
        CodeableConcept careTeamRoleConcept = createCodeableConcept(ClaimCareteamrole.OTHER.getSystem(), careTeamRole.toCode());
        careTeamRoleConcept.getCodingFirstRep().setDisplay(careTeamRole.getDisplay());
        careTeamEntry.setRole(careTeamRoleConcept);
    }
    // care team entry is at eob level so no need to create item link id
    if (eobItem == null) {
        return careTeamEntry;
    }
    // Link the EOB.item to the care team entry (if it isn't already).
    final int careTeamEntrySequence = careTeamEntry.getSequence();
    if (eobItem.getCareTeamLinkId().stream().noneMatch(id -> id.getValue() == careTeamEntrySequence)) {
        eobItem.addCareTeamLinkId(careTeamEntrySequence);
    }
    return careTeamEntry;
}
Also used : Arrays(java.util.Arrays) CarrierClaimColumn(gov.cms.bfd.model.rif.CarrierClaimColumn) CcwCodebookInterface(gov.cms.bfd.model.codebook.model.CcwCodebookInterface) Identifier(org.hl7.fhir.dstu3.model.Identifier) Constants(ca.uhn.fhir.rest.api.Constants) Coding(org.hl7.fhir.dstu3.model.Coding) InpatientClaim(gov.cms.bfd.model.rif.InpatientClaim) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept) DomainResource(org.hl7.fhir.dstu3.model.DomainResource) IBaseExtension(org.hl7.fhir.instance.model.api.IBaseExtension) StringUtils(org.apache.commons.lang3.StringUtils) SNFClaimColumn(gov.cms.bfd.model.rif.SNFClaimColumn) BigDecimal(java.math.BigDecimal) SNFClaimLine(gov.cms.bfd.model.rif.SNFClaimLine) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) CarrierClaimLine(gov.cms.bfd.model.rif.CarrierClaimLine) Map(java.util.Map) ProcedureComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.ProcedureComponent) CcwCodebookMissingVariable(gov.cms.bfd.model.codebook.data.CcwCodebookMissingVariable) TemporalPrecisionEnum(ca.uhn.fhir.model.api.TemporalPrecisionEnum) Value(gov.cms.bfd.model.codebook.model.Value) Diagnosis(gov.cms.bfd.server.war.commons.Diagnosis) OutpatientClaim(gov.cms.bfd.model.rif.OutpatientClaim) Coverage(org.hl7.fhir.dstu3.model.Coverage) IdDt(ca.uhn.fhir.model.primitive.IdDt) ExplanationOfBenefit(org.hl7.fhir.dstu3.model.ExplanationOfBenefit) MedicareSegment(gov.cms.bfd.server.war.commons.MedicareSegment) Reference(org.hl7.fhir.dstu3.model.Reference) DiagnosisComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.DiagnosisComponent) InpatientClaimColumn(gov.cms.bfd.model.rif.InpatientClaimColumn) Set(java.util.Set) StandardCharsets(java.nio.charset.StandardCharsets) ZoneId(java.time.ZoneId) UncheckedIOException(java.io.UncheckedIOException) ReferralRequestStatus(org.hl7.fhir.dstu3.model.ReferralRequest.ReferralRequestStatus) Stream(java.util.stream.Stream) ReferralRequestRequesterComponent(org.hl7.fhir.dstu3.model.ReferralRequest.ReferralRequestRequesterComponent) CarrierClaim(gov.cms.bfd.model.rif.CarrierClaim) HHAClaimLine(gov.cms.bfd.model.rif.HHAClaimLine) Money(org.hl7.fhir.dstu3.model.Money) ReferralRequest(org.hl7.fhir.dstu3.model.ReferralRequest) BenefitComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.BenefitComponent) IAnyResource(org.hl7.fhir.instance.model.api.IAnyResource) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) CCWUtils(gov.cms.bfd.server.war.commons.CCWUtils) RequestDetails(ca.uhn.fhir.rest.api.server.RequestDetails) ResourceType(org.hl7.fhir.dstu3.model.ResourceType) CcwCodebookVariable(gov.cms.bfd.model.codebook.data.CcwCodebookVariable) Period(org.hl7.fhir.dstu3.model.Period) CurrencyIdentifier(gov.cms.bfd.server.war.stu3.providers.BeneficiaryTransformer.CurrencyIdentifier) CCWProcedure(gov.cms.bfd.server.war.commons.CCWProcedure) OffsetLinkBuilder(gov.cms.bfd.server.war.commons.OffsetLinkBuilder) Practitioner(org.hl7.fhir.dstu3.model.Practitioner) MetricRegistry(com.codahale.metrics.MetricRegistry) LinkBuilder(gov.cms.bfd.server.war.commons.LinkBuilder) BadCodeMonkeyException(gov.cms.bfd.sharedutils.exceptions.BadCodeMonkeyException) SimpleQuantity(org.hl7.fhir.dstu3.model.SimpleQuantity) IOException(java.io.IOException) Observation(org.hl7.fhir.dstu3.model.Observation) InputStreamReader(java.io.InputStreamReader) FDADrugDataUtilityApp(gov.cms.bfd.server.war.FDADrugDataUtilityApp) SupportingInformationComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.SupportingInformationComponent) DMEClaimColumn(gov.cms.bfd.model.rif.DMEClaimColumn) Patient(org.hl7.fhir.dstu3.model.Patient) MDC(org.slf4j.MDC) BufferedReader(java.io.BufferedReader) IBaseHasExtensions(org.hl7.fhir.instance.model.api.IBaseHasExtensions) Bundle(org.hl7.fhir.dstu3.model.Bundle) Date(java.util.Date) BundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent) LoggerFactory(org.slf4j.LoggerFactory) Extension(org.hl7.fhir.dstu3.model.Extension) ClaimCareteamrole(org.hl7.fhir.dstu3.model.codesystems.ClaimCareteamrole) Organization(org.hl7.fhir.dstu3.model.Organization) SNFClaim(gov.cms.bfd.model.rif.SNFClaim) HHAClaimColumn(gov.cms.bfd.model.rif.HHAClaimColumn) BenefitBalanceComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.BenefitBalanceComponent) Collection(java.util.Collection) ItemComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.ItemComponent) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) DiagnosisLabel(gov.cms.bfd.server.war.commons.Diagnosis.DiagnosisLabel) Quantity(org.hl7.fhir.dstu3.model.Quantity) UnsignedIntType(org.hl7.fhir.dstu3.model.UnsignedIntType) Objects(java.util.Objects) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) List(java.util.List) CareTeamComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.CareTeamComponent) TransformerConstants(gov.cms.bfd.server.war.commons.TransformerConstants) LocalDate(java.time.LocalDate) Optional(java.util.Optional) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DateType(org.hl7.fhir.dstu3.model.DateType) OutpatientClaimColumn(gov.cms.bfd.model.rif.OutpatientClaimColumn) HospiceClaimLine(gov.cms.bfd.model.rif.HospiceClaimLine) DataFormatException(ca.uhn.fhir.parser.DataFormatException) HashMap(java.util.HashMap) InpatientClaimLine(gov.cms.bfd.model.rif.InpatientClaimLine) OutpatientClaimLine(gov.cms.bfd.model.rif.OutpatientClaimLine) HashSet(java.util.HashSet) ExplanationOfBenefitStatus(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.ExplanationOfBenefitStatus) HHAClaim(gov.cms.bfd.model.rif.HHAClaim) ObservationStatus(org.hl7.fhir.dstu3.model.Observation.ObservationStatus) InvalidRifValueException(gov.cms.bfd.model.rif.parse.InvalidRifValueException) DMEClaim(gov.cms.bfd.model.rif.DMEClaim) DMEClaimLine(gov.cms.bfd.model.rif.DMEClaimLine) LinkedList(java.util.LinkedList) NoSuchElementException(java.util.NoSuchElementException) AdjudicationComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.AdjudicationComponent) BenefitCategory(org.hl7.fhir.dstu3.model.codesystems.BenefitCategory) Logger(org.slf4j.Logger) Resource(org.hl7.fhir.dstu3.model.Resource) Variable(gov.cms.bfd.model.codebook.model.Variable) HospiceClaim(gov.cms.bfd.model.rif.HospiceClaim) Consumer(java.util.function.Consumer) URLEncoder(java.net.URLEncoder) IdentifierType(gov.cms.bfd.server.war.commons.IdentifierType) InputStream(java.io.InputStream) CareTeamComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.CareTeamComponent) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 2 with Identifier

use of org.hl7.fhir.r4b.model.Identifier in project beneficiary-fhir-data by CMSgov.

the class TransformerUtils method createIdentifierReference.

/**
 * @param identifierType the {@link gov.cms.bfd.server.war.stu3.providers.IdentifierType}
 * @param identifierValue the {@link Identifier#getValue()} to use in {@link
 *     Reference#getIdentifier()}
 * @return a {@link Reference} with the specified {@link Identifier}
 */
static Reference createIdentifierReference(IdentifierType identifierType, String identifierValue) {
    Reference reference = new Reference();
    Coding coding = new Coding().setSystem(identifierType.getSystem()).setCode(identifierType.getCode()).setDisplay(identifierType.getDisplay());
    List<Coding> codingList = new ArrayList<Coding>();
    codingList.add(coding);
    CodeableConcept codeableConcept = new CodeableConcept().setCoding(codingList);
    return reference.setIdentifier(new Identifier().setSystem(identifierType.getSystem()).setValue(identifierValue).setType(codeableConcept)).setDisplay(retrieveNpiCodeDisplay(identifierValue));
}
Also used : Identifier(org.hl7.fhir.dstu3.model.Identifier) CurrencyIdentifier(gov.cms.bfd.server.war.stu3.providers.BeneficiaryTransformer.CurrencyIdentifier) Coding(org.hl7.fhir.dstu3.model.Coding) Reference(org.hl7.fhir.dstu3.model.Reference) ArrayList(java.util.ArrayList) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 3 with Identifier

use of org.hl7.fhir.r4b.model.Identifier in project beneficiary-fhir-data by CMSgov.

the class ExplanationOfBenefitResourceProvider method findByPatient.

/**
 * Adds support for the FHIR "search" operation for {@link ExplanationOfBenefit}s, allowing users
 * to search by {@link ExplanationOfBenefit#getPatient()}.
 *
 * <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 patient a {@link ReferenceParam} for the {@link ExplanationOfBenefit#getPatient()} to
 *     try and find matches for {@link ExplanationOfBenefit}s
 * @param type a list of {@link ClaimType} to include in the result. Defaults to all types.
 * @param startIndex an {@link OptionalParam} for the startIndex (or offset) used to determine
 *     pagination
 * @param excludeSamhsa an {@link OptionalParam} that, if <code>"true"</code>, will use {@link
 *     Stu3EobSamhsaMatcher} to filter out all SAMHSA-related claims from the results
 * @param lastUpdated an {@link OptionalParam} that specifies a date range for the lastUpdated
 *     field.
 * @param serviceDate an {@link OptionalParam} that specifies a date range for {@link
 *     ExplanationOfBenefit}s that completed
 * @param requestDetails a {@link RequestDetails} containing the details of the request URL, used
 *     to parse out pagination values
 * @return Returns a {@link Bundle} of {@link ExplanationOfBenefit}s, which may contain multiple
 *     matching resources, or may also be empty.
 */
@Search
@Trace
public Bundle findByPatient(@RequiredParam(name = ExplanationOfBenefit.SP_PATIENT) @Description(shortDefinition = "The patient identifier to search for") ReferenceParam patient, @OptionalParam(name = "type") @Description(shortDefinition = "A list of claim types to include") TokenAndListParam type, @OptionalParam(name = "startIndex") @Description(shortDefinition = "The offset used for result pagination") String startIndex, @OptionalParam(name = "excludeSAMHSA") @Description(shortDefinition = "If true, exclude all SAMHSA-related resources") String excludeSamhsa, @OptionalParam(name = "_lastUpdated") @Description(shortDefinition = "Include resources last updated in the given range") DateRangeParam lastUpdated, @OptionalParam(name = "service-date") @Description(shortDefinition = "Include resources that completed in the given range") DateRangeParam serviceDate, RequestDetails requestDetails) {
    /*
     * startIndex is an optional parameter here because it must be declared in the
     * event it is passed in. However, it is not being used here because it is also
     * contained within requestDetails and parsed out along with other parameters
     * later.
     */
    String beneficiaryId = patient.getIdPart();
    Set<ClaimType> claimTypes = parseTypeParam(type);
    Boolean includeTaxNumbers = returnIncludeTaxNumbers(requestDetails);
    OffsetLinkBuilder paging = new OffsetLinkBuilder(requestDetails, "/ExplanationOfBenefit?");
    Operation operation = new Operation(Operation.Endpoint.V1_EOB);
    operation.setOption("by", "patient");
    operation.setOption("types", (claimTypes.size() == ClaimType.values().length) ? "*" : claimTypes.stream().sorted(Comparator.comparing(ClaimType::name)).collect(Collectors.toList()).toString());
    operation.setOption("IncludeTaxNumbers", "" + includeTaxNumbers);
    operation.setOption("pageSize", paging.isPagingRequested() ? "" + paging.getPageSize() : "*");
    operation.setOption("_lastUpdated", Boolean.toString(lastUpdated != null && !lastUpdated.isEmpty()));
    operation.setOption("service-date", Boolean.toString(serviceDate != null && !serviceDate.isEmpty()));
    operation.publishOperationName();
    List<IBaseResource> eobs = new ArrayList<IBaseResource>();
    // Optimize when the lastUpdated parameter is specified and result set is empty
    if (loadedFilterManager.isResultSetEmpty(beneficiaryId, lastUpdated)) {
        return TransformerUtils.createBundle(paging, eobs, loadedFilterManager.getTransactionTime());
    }
    /*
     * The way our JPA/SQL schema is setup, we have to run a separate search for
     * each claim type, then combine the results. It's not super efficient, but it's
     * also not so inefficient that it's worth fixing.
     */
    if (claimTypes.contains(ClaimType.CARRIER))
        eobs.addAll(transformToEobs(ClaimType.CARRIER, findClaimTypeByPatient(ClaimType.CARRIER, beneficiaryId, lastUpdated, serviceDate), Optional.of(includeTaxNumbers)));
    if (claimTypes.contains(ClaimType.DME))
        eobs.addAll(transformToEobs(ClaimType.DME, findClaimTypeByPatient(ClaimType.DME, beneficiaryId, lastUpdated, serviceDate), Optional.of(includeTaxNumbers)));
    if (claimTypes.contains(ClaimType.HHA))
        eobs.addAll(transformToEobs(ClaimType.HHA, findClaimTypeByPatient(ClaimType.HHA, beneficiaryId, lastUpdated, serviceDate), Optional.of(includeTaxNumbers)));
    if (claimTypes.contains(ClaimType.HOSPICE))
        eobs.addAll(transformToEobs(ClaimType.HOSPICE, findClaimTypeByPatient(ClaimType.HOSPICE, beneficiaryId, lastUpdated, serviceDate), Optional.of(includeTaxNumbers)));
    if (claimTypes.contains(ClaimType.INPATIENT))
        eobs.addAll(transformToEobs(ClaimType.INPATIENT, findClaimTypeByPatient(ClaimType.INPATIENT, beneficiaryId, lastUpdated, serviceDate), Optional.of(includeTaxNumbers)));
    if (claimTypes.contains(ClaimType.OUTPATIENT))
        eobs.addAll(transformToEobs(ClaimType.OUTPATIENT, findClaimTypeByPatient(ClaimType.OUTPATIENT, beneficiaryId, lastUpdated, serviceDate), Optional.of(includeTaxNumbers)));
    if (claimTypes.contains(ClaimType.PDE))
        eobs.addAll(transformToEobs(ClaimType.PDE, findClaimTypeByPatient(ClaimType.PDE, beneficiaryId, lastUpdated, serviceDate), Optional.of(includeTaxNumbers)));
    if (claimTypes.contains(ClaimType.SNF))
        eobs.addAll(transformToEobs(ClaimType.SNF, findClaimTypeByPatient(ClaimType.SNF, beneficiaryId, lastUpdated, serviceDate), Optional.of(includeTaxNumbers)));
    if (Boolean.parseBoolean(excludeSamhsa))
        filterSamhsa(eobs);
    eobs.sort(ExplanationOfBenefitResourceProvider::compareByClaimIdThenClaimType);
    // Add bene_id to MDC logs
    TransformerUtils.logBeneIdToMdc(Arrays.asList(beneficiaryId));
    return TransformerUtils.createBundle(paging, eobs, loadedFilterManager.getTransactionTime());
}
Also used : OffsetLinkBuilder(gov.cms.bfd.server.war.commons.OffsetLinkBuilder) ArrayList(java.util.ArrayList) Operation(gov.cms.bfd.server.war.Operation) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Trace(com.newrelic.api.agent.Trace) Search(ca.uhn.fhir.rest.annotation.Search)

Example 4 with Identifier

use of org.hl7.fhir.r4b.model.Identifier in project beneficiary-fhir-data by CMSgov.

the class PatientResourceProvider method searchByIdentifier.

/**
 * Adds support for the FHIR "search" operation for {@link Patient}s, allowing users to search by
 * {@link Patient#getIdentifier()}. Specifically, the following criteria are supported:
 *
 * <ul>
 *   <li>Matching a {@link Beneficiary#getHicn()} hash value: when {@link TokenParam#getSystem()}
 *       matches one of the {@link #SUPPORTED_HASH_IDENTIFIER_SYSTEMS} entries.
 * </ul>
 *
 * <p>Searches that don't match one of the above forms are not supported.
 *
 * <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 identifier an {@link Identifier} {@link TokenParam} for the {@link
 *     Patient#getIdentifier()} to try and find a matching {@link Patient} 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 Patient}s, which may contain multiple matching
 *     resources, or may also be empty.
 */
@Search
@Trace
public Bundle searchByIdentifier(@RequiredParam(name = Patient.SP_IDENTIFIER) @Description(shortDefinition = "The patient identifier to search for") TokenParam identifier, @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) {
    if (identifier.getQueryParameterQualifier() != null)
        throw new InvalidRequestException("Unsupported query parameter qualifier: " + identifier.getQueryParameterQualifier());
    if (!SUPPORTED_HASH_IDENTIFIER_SYSTEMS.contains(identifier.getSystem()))
        throw new InvalidRequestException("Unsupported identifier system: " + identifier.getSystem());
    RequestHeaders requestHeader = RequestHeaders.getHeaderWrapper(requestDetails);
    Operation operation = new Operation(Operation.Endpoint.V1_PATIENT);
    operation.setOption("by", "identifier");
    requestHeader.getNVPairs().forEach((n, v) -> operation.setOption(n, v.toString()));
    operation.setOption("_lastUpdated", Boolean.toString(lastUpdated != null && !lastUpdated.isEmpty()));
    operation.publishOperationName();
    List<IBaseResource> patients;
    try {
        Patient patient;
        switch(identifier.getSystem()) {
            case TransformerConstants.CODING_BBAPI_BENE_HICN_HASH:
            case TransformerConstants.CODING_BBAPI_BENE_HICN_HASH_OLD:
                patient = queryDatabaseByHicnHash(identifier.getValue(), requestHeader);
                break;
            case TransformerConstants.CODING_BBAPI_BENE_MBI_HASH:
                patient = queryDatabaseByMbiHash(identifier.getValue(), requestHeader);
                break;
            default:
                throw new InvalidRequestException("Unsupported identifier system: " + identifier.getSystem());
        }
        patients = QueryUtils.isInRange(patient.getMeta().getLastUpdated().toInstant(), lastUpdated) ? Collections.singletonList(patient) : Collections.emptyList();
    } catch (NoResultException e) {
        patients = new LinkedList<>();
    }
    OffsetLinkBuilder paging = new OffsetLinkBuilder(requestDetails, "/Patient?");
    Bundle bundle = TransformerUtils.createBundle(paging, patients, loadedFilterManager.getTransactionTime());
    return bundle;
}
Also used : OffsetLinkBuilder(gov.cms.bfd.server.war.commons.OffsetLinkBuilder) Bundle(org.hl7.fhir.dstu3.model.Bundle) Patient(org.hl7.fhir.dstu3.model.Patient) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) Operation(gov.cms.bfd.server.war.Operation) NoResultException(javax.persistence.NoResultException) RequestHeaders(gov.cms.bfd.server.war.commons.RequestHeaders) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) LinkedList(java.util.LinkedList) Trace(com.newrelic.api.agent.Trace) Search(ca.uhn.fhir.rest.annotation.Search)

Example 5 with Identifier

use of org.hl7.fhir.r4b.model.Identifier 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)

Aggregations

Identifier (org.hl7.fhir.r4.model.Identifier)212 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)143 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)125 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)116 Test (org.junit.Test)90 Test (org.junit.jupiter.api.Test)84 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)66 ArrayList (java.util.ArrayList)62 Reference (org.hl7.fhir.r4.model.Reference)57 Identifier (org.hl7.fhir.dstu3.model.Identifier)55 Patient (org.hl7.fhir.r4.model.Patient)55 Coding (org.hl7.fhir.r4.model.Coding)49 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)41 Practitioner (org.hl7.fhir.r4.model.Practitioner)41 Date (java.util.Date)40 List (java.util.List)40 Resource (org.hl7.fhir.r4.model.Resource)37 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)36 InvalidRequestException (ca.uhn.fhir.rest.server.exceptions.InvalidRequestException)34 Collectors (java.util.stream.Collectors)31