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;
}
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");
}
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);
}
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));
}
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);
}
Aggregations