Search in sources :

Example 16 with RequestHeaders

use of gov.cms.bfd.server.war.commons.RequestHeaders in project beneficiary-fhir-data by CMSgov.

the class PatientResourceProvider method searchByLogicalId.

/**
 * Adds support for the FHIR "search" operation for {@link Patient}s, allowing users to search by
 * {@link Patient#getId()}.
 *
 * <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 logicalId a {@link TokenParam} (with no system, per the spec) for the {@link
 *     Patient#getId()} 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 searchByLogicalId(@RequiredParam(name = Patient.SP_RES_ID) @Description(shortDefinition = "The patient identifier to search for") TokenParam logicalId, @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 (logicalId.getQueryParameterQualifier() != null)
        throw new InvalidRequestException("Unsupported query parameter qualifier: " + logicalId.getQueryParameterQualifier());
    if (logicalId.getSystem() != null && !logicalId.getSystem().isEmpty())
        throw new InvalidRequestException("Unsupported query parameter system: " + logicalId.getSystem());
    if (logicalId.getValueNotNull().isEmpty())
        throw new InvalidRequestException("Unsupported query parameter value: " + logicalId.getValue());
    List<IBaseResource> patients;
    if (loadedFilterManager.isResultSetEmpty(logicalId.getValue(), lastUpdated)) {
        patients = Collections.emptyList();
    } else {
        try {
            patients = Optional.of(read(new IdType(logicalId.getValue()), requestDetails)).filter(p -> QueryUtils.isInRange(p.getMeta().getLastUpdated().toInstant(), lastUpdated)).map(p -> Collections.singletonList((IBaseResource) p)).orElse(Collections.emptyList());
        } catch (ResourceNotFoundException e) {
            patients = Collections.emptyList();
        }
    }
    /*
     * Publish the operation name. Note: This is a bit later than we'd normally do this, as we need
     * to override the operation name that was published by the possible call to read(...), above.
     */
    RequestHeaders requestHeader = RequestHeaders.getHeaderWrapper(requestDetails);
    Operation operation = new Operation(Operation.Endpoint.V1_PATIENT);
    operation.setOption("by", "id");
    // track all api hdrs
    requestHeader.getNVPairs().forEach((n, v) -> operation.setOption(n, v.toString()));
    operation.setOption("_lastUpdated", Boolean.toString(lastUpdated != null && !lastUpdated.isEmpty()));
    operation.publishOperationName();
    OffsetLinkBuilder paging = new OffsetLinkBuilder(requestDetails, "/Patient?");
    Bundle bundle = TransformerUtils.createBundle(paging, patients, loadedFilterManager.getTransactionTime());
    return bundle;
}
Also used : IdParam(ca.uhn.fhir.rest.annotation.IdParam) Arrays(java.util.Arrays) Bundle(org.hl7.fhir.dstu3.model.Bundle) PatientLinkBuilder(gov.cms.bfd.server.war.commons.PatientLinkBuilder) Identifier(org.hl7.fhir.dstu3.model.Identifier) Description(ca.uhn.fhir.model.api.annotation.Description) IdType(org.hl7.fhir.dstu3.model.IdType) NoResultException(javax.persistence.NoResultException) StringUtils(org.apache.commons.lang3.StringUtils) BigDecimal(java.math.BigDecimal) DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) Predicate(javax.persistence.criteria.Predicate) IResourceProvider(ca.uhn.fhir.rest.server.IResourceProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) JoinType(javax.persistence.criteria.JoinType) BeneficiaryHistory(gov.cms.bfd.model.rif.BeneficiaryHistory) LoadedFilterManager(gov.cms.bfd.server.war.commons.LoadedFilterManager) SingularAttribute(javax.persistence.metamodel.SingularAttribute) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) IdDt(ca.uhn.fhir.model.primitive.IdDt) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) BeneficiaryMonthly_(gov.cms.bfd.model.rif.BeneficiaryMonthly_) QueryHints(org.hibernate.jpa.QueryHints) Collectors(java.util.stream.Collectors) BeneficiaryMonthly(gov.cms.bfd.model.rif.BeneficiaryMonthly) Objects(java.util.Objects) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) List(java.util.List) BeneficiaryHistory_(gov.cms.bfd.model.rif.BeneficiaryHistory_) TransformerConstants(gov.cms.bfd.server.war.commons.TransformerConstants) Year(java.time.Year) LocalDate(java.time.LocalDate) Timer(com.codahale.metrics.Timer) Optional(java.util.Optional) OptionalParam(ca.uhn.fhir.rest.annotation.OptionalParam) QueryUtils(gov.cms.bfd.server.war.commons.QueryUtils) Trace(com.newrelic.api.agent.Trace) HashMap(java.util.HashMap) RequestHeaders(gov.cms.bfd.server.war.commons.RequestHeaders) Beneficiary_(gov.cms.bfd.model.rif.Beneficiary_) ArrayList(java.util.ArrayList) RequiredParam(ca.uhn.fhir.rest.annotation.RequiredParam) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) RequestDetails(ca.uhn.fhir.rest.api.server.RequestDetails) Search(ca.uhn.fhir.rest.annotation.Search) CcwCodebookVariable(gov.cms.bfd.model.codebook.data.CcwCodebookVariable) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) CommonHeaders(gov.cms.bfd.server.war.commons.CommonHeaders) LinkedList(java.util.LinkedList) Root(javax.persistence.criteria.Root) Read(ca.uhn.fhir.rest.annotation.Read) OffsetLinkBuilder(gov.cms.bfd.server.war.commons.OffsetLinkBuilder) MetricRegistry(com.codahale.metrics.MetricRegistry) Operation(gov.cms.bfd.server.war.Operation) EntityManager(javax.persistence.EntityManager) PersistenceContext(javax.persistence.PersistenceContext) TokenParam(ca.uhn.fhir.rest.param.TokenParam) Component(org.springframework.stereotype.Component) Patient(org.hl7.fhir.dstu3.model.Patient) MDC(org.slf4j.MDC) YearMonth(java.time.YearMonth) Collections(java.util.Collections) OffsetLinkBuilder(gov.cms.bfd.server.war.commons.OffsetLinkBuilder) Bundle(org.hl7.fhir.dstu3.model.Bundle) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) Operation(gov.cms.bfd.server.war.Operation) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) RequestHeaders(gov.cms.bfd.server.war.commons.RequestHeaders) IdType(org.hl7.fhir.dstu3.model.IdType) Trace(com.newrelic.api.agent.Trace) Search(ca.uhn.fhir.rest.annotation.Search)

Example 17 with RequestHeaders

use of gov.cms.bfd.server.war.commons.RequestHeaders in project beneficiary-fhir-data by CMSgov.

the class BeneficiaryTransformerTest method transformSampleARecordWithIdentifiersTrue.

/**
 * Verifies that {@link
 * gov.cms.bfd.server.war.stu3.providers.BeneficiaryTransformer#transform(Beneficiary)} works as
 * expected when run against the {@link StaticRifResource#SAMPLE_A_BENES} {@link Beneficiary},
 * with {@link IncludeIdentifiersValues} = ["true"].
 */
@Test
public void transformSampleARecordWithIdentifiersTrue() {
    Beneficiary beneficiary = loadSampleABeneficiary();
    RequestHeaders requestHeader = getRHwithIncldIdntityHdr("true");
    Patient patient = BeneficiaryTransformer.transform(new MetricRegistry(), beneficiary, requestHeader);
    assertMatches(beneficiary, patient, requestHeader);
    assertEquals(8, patient.getIdentifier().size(), "Number of identifiers should be 8");
    // Verify patient identifiers and values match.
    assertValuesInPatientIdentifiers(patient, CCWUtils.calculateVariableReferenceUrl(CcwCodebookVariable.BENE_ID), "567834");
    assertValuesInPatientIdentifiers(patient, TransformerConstants.CODING_BBAPI_BENE_MBI_HASH, "someMBIhash");
    assertValuesInPatientIdentifiers(patient, TransformerConstants.CODING_BBAPI_BENE_HICN_HASH, "someHICNhash");
    assertValuesInPatientIdentifiers(patient, TransformerConstants.CODING_BBAPI_BENE_HICN_UNHASHED, "543217066U");
    assertValuesInPatientIdentifiers(patient, TransformerConstants.CODING_BBAPI_MEDICARE_BENEFICIARY_ID_UNHASHED, "3456789");
    assertValuesInPatientIdentifiers(patient, TransformerConstants.CODING_BBAPI_BENE_HICN_UNHASHED, "543217066T");
    assertValuesInPatientIdentifiers(patient, TransformerConstants.CODING_BBAPI_BENE_HICN_UNHASHED, "543217066Z");
    assertValuesInPatientIdentifiers(patient, TransformerConstants.CODING_BBAPI_MEDICARE_BENEFICIARY_ID_UNHASHED, "9AB2WW3GR44");
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) Patient(org.hl7.fhir.dstu3.model.Patient) RequestHeaders(gov.cms.bfd.server.war.commons.RequestHeaders) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) Test(org.junit.jupiter.api.Test)

Example 18 with RequestHeaders

use of gov.cms.bfd.server.war.commons.RequestHeaders in project beneficiary-fhir-data by CMSgov.

the class BeneficiaryTransformerTest method transformSampleARecordWithLastUpdated.

/**
 * Verifies that {@link
 * gov.cms.bfd.server.war.stu3.providers.BeneficiaryTransformer#transform(Beneficiary)} works as
 * expected when run against the {@link StaticRifResource#SAMPLE_A_BENES} {@link Beneficiary} with
 * a lastUpdated field set.
 */
@Test
public void transformSampleARecordWithLastUpdated() {
    Beneficiary beneficiary = loadSampleABeneficiary();
    RequestHeaders requestHeader = getRHwithIncldIdntityHdr("");
    beneficiary.setLastUpdated(Instant.now());
    Patient patientWithLastUpdated = BeneficiaryTransformer.transform(new MetricRegistry(), beneficiary, requestHeader);
    assertMatches(beneficiary, patientWithLastUpdated, requestHeader);
    beneficiary.setLastUpdated(Optional.empty());
    Patient patientWithoutLastUpdated = BeneficiaryTransformer.transform(new MetricRegistry(), beneficiary, requestHeader);
    assertMatches(beneficiary, patientWithoutLastUpdated, requestHeader);
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) Patient(org.hl7.fhir.dstu3.model.Patient) RequestHeaders(gov.cms.bfd.server.war.commons.RequestHeaders) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) Test(org.junit.jupiter.api.Test)

Example 19 with RequestHeaders

use of gov.cms.bfd.server.war.commons.RequestHeaders in project beneficiary-fhir-data by CMSgov.

the class BeneficiaryTransformerTest method transformSampleARecordWithSkippedRecord.

/**
 * Verifies that {@link
 * gov.cms.bfd.server.war.stu3.providers.BeneficiaryTransformer#transform(Beneficiary)} works as
 * expected when run against the {@link StaticRifResource#SAMPLE_A_BENES} {@link Beneficiary},
 * when there is a matching {@link SkippedRifRecord} for the {@link Beneficiary}.
 */
@Test
public void transformSampleARecordWithSkippedRecord() {
    Beneficiary beneficiary = loadSampleABeneficiary();
    beneficiary.getSkippedRifRecords().add(new SkippedRifRecord());
    RequestHeaders requestHeader = getRHwithIncldIdntityHdr("false");
    Patient patient = BeneficiaryTransformer.transform(new MetricRegistry(), beneficiary, requestHeader);
    assertEquals(1, patient.getMeta().getTag().size());
    TransformerTestUtils.assertCodingEquals(TransformerConstants.CODING_SYSTEM_BFD_TAGS, TransformerConstants.CODING_BFD_TAGS_DELAYED_BACKDATED_ENROLLMENT, patient.getMeta().getTag().get(0));
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) Patient(org.hl7.fhir.dstu3.model.Patient) SkippedRifRecord(gov.cms.bfd.model.rif.SkippedRifRecord) RequestHeaders(gov.cms.bfd.server.war.commons.RequestHeaders) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) Test(org.junit.jupiter.api.Test)

Example 20 with RequestHeaders

use of gov.cms.bfd.server.war.commons.RequestHeaders in project beneficiary-fhir-data by CMSgov.

the class BeneficiaryTransformerTest method transformBeneficiaryWithIncludeAddressFieldsAllOptEmpty.

/**
 * Notes for reviewer: for header related coverage, do not test on the combination of headers
 * values if there is no correlation between the headers, hence removed includeAddressFields
 * header tests out of includeIdentifiers header tests to speed up tests and keep the same level
 * of coverage at the same time.
 */
/**
 * Verifies that {@link gov.cms.bfd.server.war.stu3.providers.BeneficiaryTransformer} works
 * correctly when passed a {@link Beneficiary} where all {@link Optional} fields are set to {@link
 * Optional#empty()} and includeAddressFields header take all possible values.
 */
@Test
public void transformBeneficiaryWithIncludeAddressFieldsAllOptEmpty() {
    List<Object> parsedRecords = ServerTestUtils.parseData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
    Beneficiary beneficiary = parsedRecords.stream().filter(r -> r instanceof Beneficiary).map(r -> (Beneficiary) r).findFirst().get();
    TransformerTestUtils.setAllOptionalsToEmpty(beneficiary);
    RequestHeaders requestHeader = getRHwithIncldAddrFldHdr("true");
    Patient patient = BeneficiaryTransformer.transform(new MetricRegistry(), beneficiary, requestHeader);
    assertMatches(beneficiary, patient, requestHeader);
    requestHeader = getRHwithIncldAddrFldHdr("false");
    patient = BeneficiaryTransformer.transform(new MetricRegistry(), beneficiary, requestHeader);
    assertMatches(beneficiary, patient, requestHeader);
    requestHeader = getRHwithIncldAddrFldHdr("");
    patient = BeneficiaryTransformer.transform(new MetricRegistry(), beneficiary, requestHeader);
    assertMatches(beneficiary, patient, requestHeader);
    requestHeader = RequestHeaders.getHeaderWrapper();
    patient = BeneficiaryTransformer.transform(new MetricRegistry(), beneficiary, requestHeader);
    assertMatches(beneficiary, patient, requestHeader);
}
Also used : SkippedRifRecord(gov.cms.bfd.model.rif.SkippedRifRecord) Arrays(java.util.Arrays) StaticRifResource(gov.cms.bfd.model.rif.samples.StaticRifResource) Identifier(org.hl7.fhir.dstu3.model.Identifier) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) RequestHeaders(gov.cms.bfd.server.war.commons.RequestHeaders) CCWUtils(gov.cms.bfd.server.war.commons.CCWUtils) Sex(gov.cms.bfd.server.war.commons.Sex) CcwCodebookVariable(gov.cms.bfd.model.codebook.data.CcwCodebookVariable) BeneficiaryHistory(gov.cms.bfd.model.rif.BeneficiaryHistory) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) StaticRifResourceGroup(gov.cms.bfd.model.rif.samples.StaticRifResourceGroup) ServerTestUtils(gov.cms.bfd.server.war.ServerTestUtils) MetricRegistry(com.codahale.metrics.MetricRegistry) Set(java.util.Set) MedicareBeneficiaryIdHistory(gov.cms.bfd.model.rif.MedicareBeneficiaryIdHistory) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) AdministrativeGender(org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) List(java.util.List) TransformerConstants(gov.cms.bfd.server.war.commons.TransformerConstants) Patient(org.hl7.fhir.dstu3.model.Patient) Optional(java.util.Optional) MetricRegistry(com.codahale.metrics.MetricRegistry) Patient(org.hl7.fhir.dstu3.model.Patient) RequestHeaders(gov.cms.bfd.server.war.commons.RequestHeaders) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) Test(org.junit.jupiter.api.Test)

Aggregations

RequestHeaders (gov.cms.bfd.server.war.commons.RequestHeaders)31 Beneficiary (gov.cms.bfd.model.rif.Beneficiary)28 Patient (org.hl7.fhir.dstu3.model.Patient)20 Test (org.junit.jupiter.api.Test)18 TransformerConstants (gov.cms.bfd.server.war.commons.TransformerConstants)17 Arrays (java.util.Arrays)17 List (java.util.List)17 Collectors (java.util.stream.Collectors)17 InvalidRequestException (ca.uhn.fhir.rest.server.exceptions.InvalidRequestException)13 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)13 MetricRegistry (com.codahale.metrics.MetricRegistry)13 BeneficiaryHistory (gov.cms.bfd.model.rif.BeneficiaryHistory)13 CommonHeaders (gov.cms.bfd.server.war.commons.CommonHeaders)13 Optional (java.util.Optional)13 ArrayList (java.util.ArrayList)12 StaticRifResourceGroup (gov.cms.bfd.model.rif.samples.StaticRifResourceGroup)8 ServerTestUtils (gov.cms.bfd.server.war.ServerTestUtils)8 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)8 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)7 CcwCodebookVariable (gov.cms.bfd.model.codebook.data.CcwCodebookVariable)7