Search in sources :

Example 1 with Parameters

use of org.hl7.fhir.r4b.model.Parameters in project gpconnect-demonstrator by nhsconnect.

the class PatientResourceProvider method registerPatient.

@Operation(name = REGISTER_PATIENT_OPERATION_NAME)
public Bundle registerPatient(@ResourceParam Parameters params) {
    Patient registeredPatient = null;
    validateParameterNames(params, registerPatientParams);
    Patient unregisteredPatient = params.getParameter().stream().filter(param -> "registerPatient".equalsIgnoreCase(param.getName())).map(ParametersParameterComponent::getResource).map(Patient.class::cast).findFirst().orElse(null);
    String nnn = nhsNumber.fromPatientResource(unregisteredPatient);
    // if its patient 14 spoof not on PDS and return the required error
    if (nnn.equals(patientNotOnSpine)) {
        throw OperationOutcomeFactory.buildOperationOutcomeException(new InvalidRequestException(String.format("Patient (NHS number - %s) not present on PDS", nnn)), SystemCode.INVALID_PATIENT_DEMOGRAPHICS, IssueType.INVALID);
    } else if (nnn.equals(patientSuperseded)) {
        throw OperationOutcomeFactory.buildOperationOutcomeException(new InvalidRequestException(String.format("Patient (NHS number - %s) is superseded", nnn)), SystemCode.INVALID_NHS_NUMBER, IssueType.INVALID);
    }
    if (unregisteredPatient != null) {
        validatePatient(unregisteredPatient);
        // check if the patient already exists
        PatientDetails patientDetails = patientSearch.findPatient(nhsNumber.fromPatientResource(unregisteredPatient));
        if (patientDetails == null || IsInactiveTemporaryPatient(patientDetails)) {
            if (patientDetails == null) {
                patientDetails = registerPatientResourceConverterToPatientDetail(unregisteredPatient);
                patientStore.create(patientDetails);
            } else {
                // reactivate inactive non temporary patient
                patientDetails.setRegistrationStatus(ACTIVE_REGISTRATION_STATUS);
                updateAddressAndTelecom(unregisteredPatient, patientDetails);
                patientStore.update(patientDetails);
            }
            try {
                registeredPatient = patientDetailsToRegisterPatientResourceConverter(patientSearch.findPatient(unregisteredPatient.getIdentifierFirstRep().getValue()));
                addPreferredBranchSurgeryExtension(registeredPatient);
            } catch (FHIRException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } else if (patientDetails.isDeceased() || patientDetails.isSensitive()) {
            throw OperationOutcomeFactory.buildOperationOutcomeException(new InvalidRequestException(String.format("Patient (NHS number - %s) has invalid demographics", nnn)), SystemCode.INVALID_PATIENT_DEMOGRAPHICS, IssueType.INVALID);
        } else {
            throw OperationOutcomeFactory.buildOperationOutcomeException(new UnclassifiedServerFailureException(409, String.format("Patient (NHS number - %s) already exists", nnn)), SystemCode.DUPLICATE_REJECTED, IssueType.INVALID);
        }
    } else {
        throw OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException("Patient record not found"), SystemCode.INVALID_PARAMETER, IssueType.INVALID);
    }
    Bundle bundle = new Bundle().setType(BundleType.SEARCHSET);
    bundle.getMeta().addProfile(SystemURL.SD_GPC_SRCHSET_BUNDLE);
    bundle.addEntry().setResource(registeredPatient);
    return bundle;
}
Also used : UnprocessableEntityException(ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException) UnclassifiedServerFailureException(ca.uhn.fhir.rest.server.exceptions.UnclassifiedServerFailureException) PatientDetails(uk.gov.hscic.model.patient.PatientDetails) PopulateMedicationBundle(uk.gov.hscic.medications.PopulateMedicationBundle) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 2 with Parameters

use of org.hl7.fhir.r4b.model.Parameters in project gpconnect-demonstrator by nhsconnect.

the class PatientResourceProvider method StructuredRecordOperation.

@Operation(name = GET_STRUCTURED_RECORD_OPERATION_NAME)
public Bundle StructuredRecordOperation(@ResourceParam Parameters params) throws FHIRException {
    Bundle structuredBundle = new Bundle();
    Boolean getAllergies = false;
    Boolean includeResolved = false;
    Boolean getMedications = false;
    Boolean includePrescriptionIssues = false;
    Period medicationPeriod = null;
    String NHS = getNhsNumber(params);
    PatientDetails patientDetails = patientSearch.findPatient(NHS);
    // see https://nhsconnect.github.io/gpconnect/accessrecord_structured_development_retrieve_patient_record.html#error-handling
    if (patientDetails == null || patientDetails.isSensitive() || patientDetails.isDeceased() || !patientDetails.isActive()) {
        throw OperationOutcomeFactory.buildOperationOutcomeException(new ResourceNotFoundException("No patient details found for patient ID: " + NHS), SystemCode.PATIENT_NOT_FOUND, IssueType.NOTFOUND);
    }
    if (NHS.equals(patientNoconsent)) {
        throw OperationOutcomeFactory.buildOperationOutcomeException(new ForbiddenOperationException("No patient consent to share for patient ID: " + NHS), SystemCode.NO_PATIENT_CONSENT, IssueType.FORBIDDEN);
    }
    operationOutcome = null;
    for (ParametersParameterComponent param : params.getParameter()) {
        if (validateParametersName(param.getName())) {
            if (param.getName().equals(SystemConstants.INCLUDE_ALLERGIES)) {
                getAllergies = true;
                if (param.getPart().isEmpty()) {
                    // addWarningIssue(param, IssueType.REQUIRED, "Miss parameter part : " + SystemConstants.INCLUDE_RESOLVED_ALLERGIES);
                    throw OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException("Miss parameter : " + SystemConstants.INCLUDE_RESOLVED_ALLERGIES), SystemCode.INVALID_PARAMETER, IssueType.REQUIRED);
                }
                boolean includeResolvedParameterPartPresent = false;
                for (ParametersParameterComponent paramPart : param.getPart()) {
                    if (paramPart.getName().equals(SystemConstants.INCLUDE_RESOLVED_ALLERGIES)) {
                        if (paramPart.getValue() instanceof BooleanType) {
                            includeResolved = Boolean.valueOf(paramPart.getValue().primitiveValue());
                            includeResolvedParameterPartPresent = true;
                        } else {
                            throw OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException("Miss parameter : " + SystemConstants.INCLUDE_RESOLVED_ALLERGIES), SystemCode.INVALID_PARAMETER, IssueType.REQUIRED);
                        }
                    } else {
                        addWarningIssue(param, paramPart, IssueType.NOTSUPPORTED);
                    // throw OperationOutcomeFactory.buildOperationOutcomeException(
                    // new UnprocessableEntityException("Incorrect parameter passed : " + paramPart.getName()),
                    // SystemCode.INVALID_PARAMETER, IssueType.INVALID);
                    }
                }
                if (!includeResolvedParameterPartPresent) {
                    throw OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException("Miss parameter : " + SystemConstants.INCLUDE_RESOLVED_ALLERGIES), SystemCode.INVALID_PARAMETER, IssueType.REQUIRED);
                }
            }
            if (param.getName().equals(SystemConstants.INCLUDE_MEDICATION)) {
                getMedications = true;
                boolean isIncludedPrescriptionIssuesExist = false;
                for (ParametersParameterComponent paramPart : param.getPart()) {
                    if (paramPart.getName().equals(SystemConstants.INCLUDE_PRESCRIPTION_ISSUES)) {
                        if (paramPart.getValue() instanceof BooleanType) {
                            includePrescriptionIssues = Boolean.valueOf(paramPart.getValue().primitiveValue());
                            isIncludedPrescriptionIssuesExist = true;
                        }
                    } else if (paramPart.getName().equals(SystemConstants.MEDICATION_SEARCH_FROM_DATE) && paramPart.getValue() instanceof DateType) {
                        DateType startDateDt = (DateType) paramPart.getValue();
                        medicationPeriod = new Period();
                        medicationPeriod.setStart(startDateDt.getValue());
                        medicationPeriod.setEnd(null);
                        String startDate = startDateDt.asStringValue();
                        if (!validateStartDateParamAndEndDateParam(startDate, null)) {
                        // addWarningIssue(param, paramPart, IssueType.INVALID, "Invalid date used");
                        }
                    } else {
                        addWarningIssue(param, paramPart, IssueType.NOTSUPPORTED);
                    // throw OperationOutcomeFactory.buildOperationOutcomeException(
                    // new UnprocessableEntityException("Incorrect parameter passed : " + paramPart.getName()),
                    // SystemCode.INVALID_PARAMETER, IssueType.INVALID);
                    }
                }
                if (!isIncludedPrescriptionIssuesExist) {
                    // # 1.2.6 now defaults to true if not provided
                    includePrescriptionIssues = true;
                }
            }
        } else {
            // invalid parameter
            addWarningIssue(param, IssueType.NOTSUPPORTED);
        }
    }
    // for parameter
    // Add Patient
    Patient patient = patientDetailsToPatientResourceConverter(patientDetails);
    if (patient.getIdentifierFirstRep().getValue().equals(NHS)) {
        structuredBundle.addEntry().setResource(patient);
    }
    // Organization from patient
    Set<String> orgIds = new HashSet<>();
    orgIds.add(patientDetails.getManagingOrganization());
    // Practitioner from patient
    Set<String> practitionerIds = new HashSet<>();
    List<Reference> practitionerReferenceList = patient.getGeneralPractitioner();
    practitionerReferenceList.forEach(practitionerReference -> {
        String[] pracRef = practitionerReference.getReference().split("/");
        if (pracRef.length > 1) {
            practitionerIds.add(pracRef[1]);
        }
    });
    if (getAllergies) {
        structuredBundle = structuredAllergyIntoleranceBuilder.buildStructuredAllergyIntolerence(NHS, practitionerIds, structuredBundle, includeResolved);
    }
    if (getMedications) {
        structuredBundle = populateMedicationBundle.addMedicationBundleEntries(structuredBundle, patientDetails, includePrescriptionIssues, medicationPeriod, practitionerIds, orgIds);
    }
    // Add all practitioners and practitioner roles
    for (String practitionerId : practitionerIds) {
        Practitioner pracResource = practitionerResourceProvider.getPractitionerById(new IdType(practitionerId));
        structuredBundle.addEntry().setResource(pracResource);
        List<PractitionerRole> practitionerRoleList = practitionerRoleResourceProvider.getPractitionerRoleByPracticionerId(new IdType(practitionerId));
        for (PractitionerRole role : practitionerRoleList) {
            String[] split = role.getOrganization().getReference().split("/");
            orgIds.add(split[1]);
            structuredBundle.addEntry().setResource(role);
        }
    }
    // Add all organizations
    for (String orgId : orgIds) {
        OrganizationDetails organizationDetails = organizationSearch.findOrganizationDetails(new Long(orgId));
        Organization organization = organizationResourceProvider.convertOrganizationDetailsToOrganization(organizationDetails);
        structuredBundle.addEntry().setResource(organization);
    }
    structuredBundle.setType(BundleType.COLLECTION);
    structuredBundle.getMeta().addProfile(SystemURL.SD_GPC_STRUCTURED_BUNDLE);
    if (operationOutcome != null) {
        structuredBundle.addEntry().setResource(operationOutcome);
    } else {
        removeDuplicateResources(structuredBundle);
    }
    return structuredBundle;
}
Also used : OrganizationDetails(uk.gov.hscic.model.organization.OrganizationDetails) ForbiddenOperationException(ca.uhn.fhir.rest.server.exceptions.ForbiddenOperationException) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) UnprocessableEntityException(ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException) PopulateMedicationBundle(uk.gov.hscic.medications.PopulateMedicationBundle) PatientDetails(uk.gov.hscic.model.patient.PatientDetails) ParametersParameterComponent(org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent)

Example 3 with Parameters

use of org.hl7.fhir.r4b.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());
}
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 Parameters

use of org.hl7.fhir.r4b.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;
}
Also used : IdParam(ca.uhn.fhir.rest.annotation.IdParam) ClaimDao(gov.cms.bfd.server.war.r4.providers.preadj.common.ClaimDao) Trace(com.newrelic.api.agent.Trace) SpringConfiguration(gov.cms.bfd.server.war.SpringConfiguration) Description(ca.uhn.fhir.model.api.annotation.Description) NoResultException(javax.persistence.NoResultException) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) RequiredParam(ca.uhn.fhir.rest.annotation.RequiredParam) PreAdjMcsClaim(gov.cms.bfd.model.rda.PreAdjMcsClaim) Inject(javax.inject.Inject) TransformerUtilsV2(gov.cms.bfd.server.war.r4.providers.TransformerUtilsV2) Matcher(java.util.regex.Matcher) RequestDetails(ca.uhn.fhir.rest.api.server.RequestDetails) DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) Search(ca.uhn.fhir.rest.annotation.Search) IResourceProvider(ca.uhn.fhir.rest.server.IResourceProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) Map(java.util.Map) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) Nonnull(javax.annotation.Nonnull) Read(ca.uhn.fhir.rest.annotation.Read) PreAdjFissClaim(gov.cms.bfd.model.rda.PreAdjFissClaim) IdDt(ca.uhn.fhir.model.primitive.IdDt) MetricRegistry(com.codahale.metrics.MetricRegistry) Set(java.util.Set) Resource(org.hl7.fhir.r4.model.Resource) EntityManager(javax.persistence.EntityManager) PersistenceContext(javax.persistence.PersistenceContext) Collectors(java.util.stream.Collectors) ClaimResponse(org.hl7.fhir.r4.model.ClaimResponse) IdType(org.hl7.fhir.r4.model.IdType) TokenParam(ca.uhn.fhir.rest.param.TokenParam) Objects(java.util.Objects) List(java.util.List) ResourceTypeV2(gov.cms.bfd.server.war.r4.providers.preadj.common.ResourceTypeV2) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) Bundle(org.hl7.fhir.r4.model.Bundle) OptionalParam(ca.uhn.fhir.rest.annotation.OptionalParam) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Pattern(java.util.regex.Pattern) Claim(org.hl7.fhir.r4.model.Claim) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) Bundle(org.hl7.fhir.r4.model.Bundle) ArrayList(java.util.ArrayList) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 5 with Parameters

use of org.hl7.fhir.r4b.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;
}
Also used : Arrays(java.util.Arrays) CcwCodebookInterface(gov.cms.bfd.model.codebook.model.CcwCodebookInterface) SimpleQuantity(org.hl7.fhir.r4.model.SimpleQuantity) Constants(ca.uhn.fhir.rest.api.Constants) Identifier(org.hl7.fhir.r4.model.Identifier) Reference(org.hl7.fhir.r4.model.Reference) StringUtils(org.apache.commons.lang3.StringUtils) BigDecimal(java.math.BigDecimal) ItemComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.ItemComponent) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) SupportingInformationComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.SupportingInformationComponent) Map(java.util.Map) CcwCodebookMissingVariable(gov.cms.bfd.model.codebook.data.CcwCodebookMissingVariable) TemporalPrecisionEnum(ca.uhn.fhir.model.api.TemporalPrecisionEnum) Value(gov.cms.bfd.model.codebook.model.Value) Coverage(org.hl7.fhir.r4.model.Coverage) IdDt(ca.uhn.fhir.model.primitive.IdDt) ReflectionUtils(gov.cms.bfd.server.war.commons.ReflectionUtils) MedicareSegment(gov.cms.bfd.server.war.commons.MedicareSegment) BenefitBalanceComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.BenefitBalanceComponent) Period(org.hl7.fhir.r4.model.Period) Set(java.util.Set) StandardCharsets(java.nio.charset.StandardCharsets) ZoneId(java.time.ZoneId) UncheckedIOException(java.io.UncheckedIOException) Coding(org.hl7.fhir.r4.model.Coding) CarrierClaim(gov.cms.bfd.model.rif.CarrierClaim) RaceCategory(gov.cms.bfd.server.war.commons.RaceCategory) ExplanationOfBenefitStatus(org.hl7.fhir.r4.model.ExplanationOfBenefit.ExplanationOfBenefitStatus) Use(org.hl7.fhir.r4.model.ExplanationOfBenefit.Use) C4BBClaimIdentifierType(gov.cms.bfd.server.war.commons.carin.C4BBClaimIdentifierType) IAnyResource(org.hl7.fhir.instance.model.api.IAnyResource) Money(org.hl7.fhir.r4.model.Money) Strings(com.google.common.base.Strings) CCWUtils(gov.cms.bfd.server.war.commons.CCWUtils) RequestDetails(ca.uhn.fhir.rest.api.server.RequestDetails) CcwCodebookVariable(gov.cms.bfd.model.codebook.data.CcwCodebookVariable) UnsignedIntType(org.hl7.fhir.r4.model.UnsignedIntType) CCWProcedure(gov.cms.bfd.server.war.commons.CCWProcedure) Quantity(org.hl7.fhir.r4.model.Quantity) CareTeamComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.CareTeamComponent) OffsetLinkBuilder(gov.cms.bfd.server.war.commons.OffsetLinkBuilder) LinkBuilder(gov.cms.bfd.server.war.commons.LinkBuilder) BadCodeMonkeyException(gov.cms.bfd.sharedutils.exceptions.BadCodeMonkeyException) IOException(java.io.IOException) C4BBClaimProfessionalAndNonClinicianCareTeamRole(gov.cms.bfd.server.war.commons.carin.C4BBClaimProfessionalAndNonClinicianCareTeamRole) InputStreamReader(java.io.InputStreamReader) FDADrugDataUtilityApp(gov.cms.bfd.server.war.FDADrugDataUtilityApp) AdjudicationComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.AdjudicationComponent) ExplanationOfBenefit(org.hl7.fhir.r4.model.ExplanationOfBenefit) MDC(org.slf4j.MDC) Bundle(org.hl7.fhir.r4.model.Bundle) BufferedReader(java.io.BufferedReader) TotalComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.TotalComponent) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) BenefitComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.BenefitComponent) ProcedureComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.ProcedureComponent) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) C4BBAdjudicationDiscriminator(gov.cms.bfd.server.war.commons.carin.C4BBAdjudicationDiscriminator) Patient(org.hl7.fhir.r4.model.Patient) DateType(org.hl7.fhir.r4.model.DateType) Collection(java.util.Collection) Resource(org.hl7.fhir.r4.model.Resource) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) List(java.util.List) TransformerConstants(gov.cms.bfd.server.war.commons.TransformerConstants) C4BBOrganizationIdentifierType(gov.cms.bfd.server.war.commons.carin.C4BBOrganizationIdentifierType) LocalDate(java.time.LocalDate) Optional(java.util.Optional) Extension(org.hl7.fhir.r4.model.Extension) PositiveIntType(org.hl7.fhir.r4.model.PositiveIntType) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ClaimCareteamrole(org.hl7.fhir.r4.model.codesystems.ClaimCareteamrole) DataFormatException(ca.uhn.fhir.parser.DataFormatException) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) ProfileConstants(gov.cms.bfd.server.war.commons.ProfileConstants) HashMap(java.util.HashMap) ExBenefitcategory(org.hl7.fhir.r4.model.codesystems.ExBenefitcategory) HashSet(java.util.HashSet) C4BBClaimPharmacyTeamRole(gov.cms.bfd.server.war.commons.carin.C4BBClaimPharmacyTeamRole) C4BBIdentifierType(gov.cms.bfd.server.war.commons.carin.C4BBIdentifierType) Address(org.hl7.fhir.r4.model.Address) InvalidRifValueException(gov.cms.bfd.model.rif.parse.InvalidRifValueException) NoSuchElementException(java.util.NoSuchElementException) Nonnull(javax.annotation.Nonnull) C4BBAdjudication(gov.cms.bfd.server.war.commons.carin.C4BBAdjudication) Observation(org.hl7.fhir.r4.model.Observation) ObservationStatus(org.hl7.fhir.r4.model.Observation.ObservationStatus) C4BBPractitionerIdentifierType(gov.cms.bfd.server.war.commons.carin.C4BBPractitionerIdentifierType) C4BBSupportingInfoType(gov.cms.bfd.server.war.commons.carin.C4BBSupportingInfoType) Logger(org.slf4j.Logger) C4BBClaimInstitutionalCareTeamRole(gov.cms.bfd.server.war.commons.carin.C4BBClaimInstitutionalCareTeamRole) Organization(org.hl7.fhir.r4.model.Organization) ResourceType(org.hl7.fhir.r4.model.ResourceType) CurrencyIdentifier(gov.cms.bfd.server.war.r4.providers.BeneficiaryTransformerV2.CurrencyIdentifier) URLEncoder(java.net.URLEncoder) RemittanceOutcome(org.hl7.fhir.r4.model.ExplanationOfBenefit.RemittanceOutcome) InputStream(java.io.InputStream) Assert(org.springframework.util.Assert) BenefitBalanceComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.BenefitBalanceComponent) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Aggregations

Parameters (org.hl7.fhir.r4.model.Parameters)98 Test (org.junit.jupiter.api.Test)84 StringType (org.hl7.fhir.r4.model.StringType)68 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)68 RestIntegrationTest (org.opencds.cqf.ruler.test.RestIntegrationTest)61 ArrayList (java.util.ArrayList)53 FHIRException (org.hl7.fhir.exceptions.FHIRException)48 IOException (java.io.IOException)40 HashMap (java.util.HashMap)31 Measure (org.hl7.fhir.r4.model.Measure)31 Bundle (org.hl7.fhir.r4.model.Bundle)29 FileNotFoundException (java.io.FileNotFoundException)24 Parameters (org.hl7.fhir.dstu3.model.Parameters)24 List (java.util.List)23 Patient (org.hl7.fhir.r4.model.Patient)23 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)21 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)19 ParametersParameterComponent (org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent)19 Parameters (org.hl7.fhir.r5.model.Parameters)18 HashSet (java.util.HashSet)17