use of gov.cms.bfd.server.war.commons.MedicareSegment in project beneficiary-fhir-data by CMSgov.
the class CoverageTransformerTest method transformSampleARecord.
/**
* Verifies that {@link
* gov.cms.bfd.server.war.stu3.providers.CoverageTransformer#transform(MedicareSegment,
* Beneficiary)} works as expected when run against the {@link StaticRifResource#SAMPLE_A_CARRIER}
* {@link Beneficiary}.
*
* @throws FHIRException (indicates test failure)
*/
@Test
public void transformSampleARecord() throws FHIRException {
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();
beneficiary.setLastUpdated(Instant.now());
Coverage partACoverage = CoverageTransformer.transform(new MetricRegistry(), MedicareSegment.PART_A, beneficiary);
assertPartAMatches(beneficiary, partACoverage);
Coverage partBCoverage = CoverageTransformer.transform(new MetricRegistry(), MedicareSegment.PART_B, beneficiary);
assertPartBMatches(beneficiary, partBCoverage);
Coverage partCCoverage = CoverageTransformer.transform(new MetricRegistry(), MedicareSegment.PART_C, beneficiary);
assertPartCMatches(beneficiary, partCCoverage);
Coverage partDCoverage = CoverageTransformer.transform(new MetricRegistry(), MedicareSegment.PART_D, beneficiary);
assertPartDMatches(beneficiary, partDCoverage);
// Test with null lastUpdated
beneficiary.setLastUpdated(Optional.empty());
Coverage partACoverageNullLastUpdated = CoverageTransformer.transform(new MetricRegistry(), MedicareSegment.PART_A, beneficiary);
assertPartAMatches(beneficiary, partACoverageNullLastUpdated);
}
use of gov.cms.bfd.server.war.commons.MedicareSegment in project beneficiary-fhir-data by CMSgov.
the class CoverageResourceProvider method read.
/**
* Adds support for the FHIR "read" operation, for {@link Coverage}s. The {@link Read} annotation
* indicates that this method supports the read operation.
*
* <p>Read operations take a single parameter annotated with {@link IdParam}, and should return a
* single resource instance.
*
* @param coverageId The read operation takes one parameter, which must be of type {@link IdType}
* and must be annotated with the {@link IdParam} annotation.
* @return Returns a resource matching the specified {@link IdDt}, or <code>null</code> if none
* exists.
*/
@Read(version = false)
@Trace
public Coverage read(@IdParam IdType coverageId) {
if (coverageId == null)
throw new IllegalArgumentException();
if (coverageId.getVersionIdPartAsLong() != null)
throw new IllegalArgumentException();
String coverageIdText = coverageId.getIdPart();
if (coverageIdText == null || coverageIdText.trim().isEmpty())
throw new IllegalArgumentException();
Operation operation = new Operation(Operation.Endpoint.V1_COVERAGE);
operation.setOption("by", "id");
operation.publishOperationName();
Matcher coverageIdMatcher = COVERAGE_ID_PATTERN.matcher(coverageIdText);
if (!coverageIdMatcher.matches())
throw new IllegalArgumentException("Unsupported ID pattern: " + coverageIdText);
String coverageIdSegmentText = coverageIdMatcher.group(1);
Optional<MedicareSegment> coverageIdSegment = MedicareSegment.selectByUrlPrefix(coverageIdSegmentText);
if (!coverageIdSegment.isPresent())
throw new ResourceNotFoundException(coverageId);
String coverageIdBeneficiaryIdText = coverageIdMatcher.group(2);
Beneficiary beneficiaryEntity;
try {
beneficiaryEntity = findBeneficiaryById(coverageIdBeneficiaryIdText, null);
if (!beneficiaryEntity.getBeneEnrollmentReferenceYear().isPresent()) {
throw new ResourceNotFoundException("Cannot find coverage for non present enrollment year");
}
} catch (NoResultException e) {
throw new ResourceNotFoundException(new IdDt(Beneficiary.class.getSimpleName(), coverageIdBeneficiaryIdText));
}
Coverage coverage = CoverageTransformer.transform(metricRegistry, coverageIdSegment.get(), beneficiaryEntity);
return coverage;
}
Aggregations