use of org.hl7.fhir.dstu2.model.Parameters 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());
}
use of org.hl7.fhir.dstu2.model.Parameters in project beneficiary-fhir-data by CMSgov.
the class AbstractR4ResourceProvider method createBundleFor.
/**
* Creates a Bundle of resources for the given data using the given {@link ResourceTypeV2}.
*
* @param resourceTypes The {@link ResourceTypeV2} data to retrieve.
* @param mbi The mbi to look up associated data for.
* @param isHashed Denotes if the given mbi is hashed.
* @param lastUpdated Date range of desired lastUpdate values to retrieve data for.
* @param serviceDate Date range of the desired service date to retrieve data for.
* @return A Bundle with data found using the provided parameters.
*/
@VisibleForTesting
Bundle createBundleFor(Set<ResourceTypeV2<T>> resourceTypes, String mbi, boolean isHashed, boolean excludeSamhsa, DateRangeParam lastUpdated, DateRangeParam serviceDate) {
List<T> resources = new ArrayList<>();
for (ResourceTypeV2<T> type : resourceTypes) {
List<?> entities;
entities = claimDao.findAllByMbiAttribute(type.getEntityClass(), type.getEntityMbiRecordAttribute(), mbi, isHashed, lastUpdated, serviceDate, type.getEntityEndDateAttribute());
resources.addAll(entities.stream().filter(e -> !excludeSamhsa || hasNoSamhsaData(metricRegistry, e)).map(e -> type.getTransformer().transform(metricRegistry, e)).collect(Collectors.toList()));
}
Bundle bundle = new Bundle();
resources.forEach(c -> {
Bundle.BundleEntryComponent entry = bundle.addEntry();
entry.setResource((Resource) c);
});
return bundle;
}
use of org.hl7.fhir.dstu2.model.Parameters in project beneficiary-fhir-data by CMSgov.
the class TransformerUtilsV2 method findOrAddBenefitBalance.
/**
* @param eob the {@link ExplanationOfBenefit} that the {@link BenefitComponent} should be part of
* @param benefitCategory the {@link BenefitCategory} to map to {@link
* BenefitBalanceComponent#getCategory()}
* @return the already-existing {@link BenefitBalanceComponent} that matches the specified
* parameters, or a new one
*/
private static BenefitBalanceComponent findOrAddBenefitBalance(ExplanationOfBenefit eob, ExBenefitcategory benefitCategory) {
Optional<BenefitBalanceComponent> matchingBenefitBalance = eob.getBenefitBalance().stream().filter(bb -> isCodeInConcept(bb.getCategory(), benefitCategory.getSystem(), benefitCategory.toCode())).findAny();
// Found an existing BenefitBalance that matches the coding system
if (matchingBenefitBalance.isPresent()) {
return matchingBenefitBalance.get();
}
CodeableConcept benefitCategoryConcept = new CodeableConcept();
benefitCategoryConcept.addCoding().setSystem(benefitCategory.getSystem()).setCode(benefitCategory.toCode()).setDisplay(benefitCategory.getDisplay());
BenefitBalanceComponent newBenefitBalance = new BenefitBalanceComponent(benefitCategoryConcept);
eob.addBenefitBalance(newBenefitBalance);
return newBenefitBalance;
}
use of org.hl7.fhir.dstu2.model.Parameters in project beneficiary-fhir-data by CMSgov.
the class ExplanationOfBenefitResourceProviderIT method searchForEobsWithPagingWithNegativePagingParameters.
/**
* Verifies that {@link ExplanationOfBenefitResourceProvider#findByPatient} works as expected for
* a {@link Patient} that does exist in the DB, with paging, using negative values for page size
* and start index parameters. This test expects to receive a BadRequestException, as negative
* values should result in an HTTP 400.
*
* @throws FHIRException (indicates test failure)
*/
@Test
public void searchForEobsWithPagingWithNegativePagingParameters() throws FHIRException {
List<Object> loadedRecords = ServerTestUtils.get().loadData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
IGenericClient fhirClient = ServerTestUtils.get().createFhirClient();
Beneficiary beneficiary = loadedRecords.stream().filter(r -> r instanceof Beneficiary).map(r -> (Beneficiary) r).findFirst().get();
/*
* FIXME: At this time we cannot check for negative page size parameters due to
* the same bug described in
* https://github.com/jamesagnew/hapi-fhir/issues/1074.
*/
Bundle searchResults = fhirClient.search().forResource(ExplanationOfBenefit.class).where(ExplanationOfBenefit.PATIENT.hasId(TransformerUtils.buildPatientId(beneficiary))).returnBundle(Bundle.class).execute();
assertNotNull(searchResults);
/*
* Access a created link of this bundle, providing the startIndex but not the
* pageSize (count).
*/
assertThrows(InvalidRequestException.class, () -> {
fhirClient.loadPage().byUrl(searchResults.getLink(Bundle.LINK_SELF).getUrl() + "&startIndex=-1").andReturnBundle(Bundle.class).execute();
});
}
use of org.hl7.fhir.dstu2.model.Parameters in project kindling by HL7.
the class Publisher method produceMap.
private void produceMap(String name, SectionTracker st, ResourceDefn res) throws Exception {
File f = new File(Utilities.path(page.getFolders().rootDir, "implementations", "r3maps", "R4toR3", name + ".map"));
if (!f.exists())
return;
String n = name.toLowerCase();
Map<String, String> values = new HashMap<String, String>();
values.put("conv-status", page.r3r4StatusForResource(name));
String fwds = TextFile.fileToString(Utilities.path(page.getFolders().rootDir, "implementations", "r3maps", "R3toR4", page.r3nameForResource(name) + ".map"));
String bcks = TextFile.fileToString(Utilities.path(page.getFolders().rootDir, "implementations", "r3maps", "R4toR3", name + ".map"));
values.put("fwds", Utilities.escapeXml(fwds));
values.put("bcks", Utilities.escapeXml(bcks));
values.put("fwds-status", "");
values.put("bcks-status", "");
values.put("r3errs", Utilities.escapeXml(page.getR3R4ValidationErrors(name)));
try {
new StructureMapUtilities(page.getWorkerContext()).parse(fwds, page.r3nameForResource(name) + ".map");
} catch (FHIRException e) {
values.put("fwds-status", "<p style=\"background-color: #ffb3b3; border:1px solid maroon; padding: 5px;\">This script does not compile: " + e.getMessage() + "</p>\r\n");
}
try {
new StructureMapUtilities(page.getWorkerContext()).parse(bcks, name + ".map");
} catch (FHIRException e) {
values.put("bcks-status", "<p style=\"background-color: #ffb3b3; border:1px solid maroon; padding: 5px;\">This script does not compile: " + e.getMessage() + "</p>\r\n");
} catch (IllegalArgumentException e) {
values.put("bcks-status", "<p style=\"background-color: #ffb3b3; border:1px solid maroon; padding: 5px;\">This script does not compile: " + e.getMessage() + "</p>\r\n");
}
if (page.getDefinitions().hasResource(name) || (page.getDefinitions().getBaseResources().containsKey(name) && !name.equals("Parameters"))) {
String src = TextFile.fileToString(page.getFolders().templateDir + "template-version-maps.html");
TextFile.stringToFile(insertSectionNumbers(page.processResourceIncludes(n, page.getDefinitions().getResourceByName(name), null, null, null, null, null, src, null, null, "res-R3/R4 Conversions", n + "-version-maps.html", null, values, res.getWg(), null), st, n + "-version-maps.html", 0, null), page.getFolders().dstDir + n + "-version-maps.html");
page.getHTMLChecker().registerFile(n + "-version-maps.html", "Version Maps for " + name, HTMLLinkChecker.XHTML_TYPE, true);
}
}
Aggregations