Search in sources :

Example 1 with FINAL

use of org.hl7.fhir.dstu3.model.Observation.ObservationStatus.FINAL in project loinc2hpo by monarch-initiative.

the class CodeSystemInternal method init.

@Override
protected void init() {
    final Coding BELOWNORMAL = new Coding(INTERNALSYSTEM, "L", "below normal range");
    final Coding NORMAL = new Coding(INTERNALSYSTEM, "N", "within normal range");
    final Coding ABOVENORMAL = new Coding(INTERNALSYSTEM, "H", "above normal range");
    final Coding ABSENCE = new Coding(INTERNALSYSTEM, "NP", "not present");
    final Coding PRESENCE = new Coding(INTERNALSYSTEM, "P", "present");
    final Coding UNKNOWN = new Coding(INTERNALSYSTEM, "unknown", "unknown");
    codes.put(BELOWNORMAL.getCode(), BELOWNORMAL);
    codes.put(NORMAL.getCode(), NORMAL);
    codes.put(ABOVENORMAL.getCode(), ABOVENORMAL);
    codes.put(ABSENCE.getCode(), ABSENCE);
    codes.put(PRESENCE.getCode(), PRESENCE);
    codes.put(UNKNOWN.getCode(), UNKNOWN);
}
Also used : Coding(org.hl7.fhir.dstu3.model.Coding)

Example 2 with FINAL

use of org.hl7.fhir.dstu3.model.Observation.ObservationStatus.FINAL in project gpconnect-demonstrator by nhsconnect.

the class AppointmentResourceProvider method updateAppointment.

/**
 * amend or cancel an existing appointment
 *
 * @param appointmentId
 * @param appointment Resource
 * @param theRequest required to access the interaction id
 * @return MethodOutcome
 */
@Update
public MethodOutcome updateAppointment(@IdParam IdType appointmentId, @ResourceParam Appointment appointment, HttpServletRequest theRequest) {
    MethodOutcome methodOutcome = new MethodOutcome();
    OperationOutcome operationalOutcome = new OperationOutcome();
    AppointmentDetail appointmentDetail = appointmentResourceConverterToAppointmentDetail(appointment);
    Meta meta = appointment.getMeta();
    final List<UriType> profiles = meta.getProfile();
    // #203 validations
    VC.execute(new VC[] { new VC(() -> profiles.isEmpty(), () -> "Meta element must be present in Appointment"), new VC(() -> !profiles.get(0).getValue().equalsIgnoreCase(SD_GPC_APPOINTMENT), // what to do if > 1 meta profile element?
    () -> "Meta.profile " + profiles.get(0).getValue() + " is not equal to " + SD_GPC_APPOINTMENT), // #203
    new VC(() -> !appointment.getReason().isEmpty(), () -> "Appointment reason shouldn't be provided!"), new VC(() -> !appointment.getSpecialty().isEmpty(), () -> "Appointment speciality shouldn't be provided!"), // new VC(() -> !appointment.getServiceType().isEmpty(), () -> "Appointment service type shouldn't be provided!"),
    new VC(() -> !appointment.getAppointmentType().isEmpty(), () -> "Appointment type shouldn't be provided!"), new VC(() -> !appointment.getIndication().isEmpty(), () -> "Appointment indication shouldn't be provided!"), new VC(() -> !appointment.getSupportingInformation().isEmpty(), () -> "Appointment supporting information shouldn't be provided!"), new VC(() -> !appointment.getIncomingReferral().isEmpty(), () -> "Appointment incoming referral shouldn't be provided!") });
    // URL ID and Resource ID must be the same
    if (!Objects.equals(appointmentId.getIdPartAsLong(), appointmentDetail.getId())) {
        operationalOutcome.addIssue().setSeverity(IssueSeverity.ERROR).setDiagnostics("Id in URL (" + appointmentId.getIdPart() + ") should match Id in Resource (" + appointmentDetail.getId() + ")");
        methodOutcome.setOperationOutcome(operationalOutcome);
        return methodOutcome;
    }
    // Make sure there is an existing appointment to be amended
    AppointmentDetail oldAppointmentDetail = appointmentSearch.findAppointmentByID(appointmentId.getIdPartAsLong());
    if (oldAppointmentDetail == null) {
        operationalOutcome.addIssue().setSeverity(IssueSeverity.ERROR).setDiagnostics("No appointment details found for ID: " + appointmentId.getIdPart());
        methodOutcome.setOperationOutcome(operationalOutcome);
        return methodOutcome;
    }
    // 1.2.7 set the old service type and service category for comparison with incoming update/cancel content values
    SlotDetail slotDetail1 = slotSearch.findSlotByID(oldAppointmentDetail.getSlotIds().get(0));
    oldAppointmentDetail.setServiceType(slotDetail1.getTypeDisply());
    ScheduleDetail scheduleDetail = scheduleSearch.findScheduleByID(slotDetail1.getScheduleReference());
    oldAppointmentDetail.setServiceCategory(scheduleDetail.getTypeDescription());
    String oldAppointmentVersionId = String.valueOf(oldAppointmentDetail.getLastUpdated().getTime());
    String newAppointmentVersionId = appointmentId.getVersionIdPart();
    if (newAppointmentVersionId != null && !newAppointmentVersionId.equalsIgnoreCase(oldAppointmentVersionId)) {
        throw new ResourceVersionConflictException("The specified version (" + newAppointmentVersionId + ") did not match the current resource version (" + oldAppointmentVersionId + ")");
    }
    // check for absolute reference #200
    Iterator<AppointmentParticipantComponent> iter = appointment.getParticipant().iterator();
    while (iter.hasNext()) {
        AppointmentParticipantComponent participant = iter.next();
        if (participant.getActor() != null) {
            checkReferenceIsRelative(participant.getActor().getReference());
        }
    }
    String interactionId = theRequest.getHeader(SSP_INTERACTIONID);
    // Determine if it is a cancel or an amend. This was previously a check for the presence of a cancellation reason
    // but that is not sufficient. We can sefely assume that the interaction id is populated at this point.
    AppointmentOperation appointmentOperation = null;
    final AppointmentDetail fAppointmentDetail = appointmentDetail;
    switch(interactionId) {
        case REST_CANCEL_APPOINTMENT:
            appointmentOperation = AppointmentOperation.CANCEL;
            // added at 1.2.2
            VC.execute(new VC[] { new VC(() -> appointment.getStatus() != AppointmentStatus.CANCELLED, () -> "Status must be \"cancelled\""), // #203
            new VC(() -> isInThePast(fAppointmentDetail.getStartDateTime()), () -> "The cancellation start date cannot be in the past"), new VC(() -> fAppointmentDetail.getCancellationReason() == null, () -> "The cancellation reason must be provided"), // no point in this since fhir forbids empty elements
            new VC(() -> fAppointmentDetail.getCancellationReason().isEmpty(), () -> "The cancellation reason can not be blank") });
            validateAppointmentExtensions(appointment, profiles, appointmentOperation);
            // #172
            String appointmentType = appointment.getAppointmentType().getText();
            if (appointmentType != null) {
                throwUnprocessableEntity422_InvalidResourceException("The appointment type cannot be updated on a cancellation");
            }
            // This is a Cancellation - so copy across fields which can be
            // altered
            List cancelComparisonResult = compareAppointmentsForInvalidProperty(AppointmentOperation.CANCEL, oldAppointmentDetail, appointmentDetail);
            if (cancelComparisonResult.size() > 0) {
                throwUnprocessableEntity422_InvalidResourceException("Invalid Appointment property has been amended (cancellation) " + cancelComparisonResult);
            }
            oldAppointmentDetail.setCancellationReason(appointmentDetail.getCancellationReason());
            String oldStatus = oldAppointmentDetail.getStatus();
            appointmentDetail = oldAppointmentDetail;
            appointmentDetail.setStatus("cancelled");
            if (!"cancelled".equalsIgnoreCase(oldStatus)) {
                for (Long slotId : appointmentDetail.getSlotIds()) {
                    SlotDetail slotDetail = slotSearch.findSlotByID(slotId);
                    // slotDetail.setAppointmentId(null);
                    slotDetail.setFreeBusyType("FREE");
                    slotDetail.setLastUpdated(new Date());
                    slotStore.saveSlot(slotDetail);
                }
            }
            break;
        case REST_UPDATE_APPOINTMENT:
            appointmentOperation = AppointmentOperation.AMEND;
            VC.execute(new VC[] { new VC(() -> appointment.getStatus() != AppointmentStatus.BOOKED, () -> "Status must be \"booked\""), // this subsumes #161 which only inhibited amendment of the cancellation reason in an amend
            new VC(() -> fAppointmentDetail.getCancellationReason() != null, () -> "Cannot amend cancellation reason in appointment amend"), // added at 1.2.2
            new VC(() -> isInThePast(fAppointmentDetail.getStartDateTime()), () -> "The appointment amend start date cannot be in the past") });
            List amendComparisonResult = compareAppointmentsForInvalidProperty(AppointmentOperation.AMEND, oldAppointmentDetail, appointmentDetail);
            if (amendComparisonResult.size() > 0) {
                throwUnprocessableEntity422_InvalidResourceException("Invalid Appointment property has been amended " + amendComparisonResult);
            }
            validateAppointmentExtensions(appointment, profiles, appointmentOperation);
            // This is an Amend
            oldAppointmentDetail.setComment(appointmentDetail.getComment());
            oldAppointmentDetail.setDescription(appointmentDetail.getDescription());
            appointmentDetail = oldAppointmentDetail;
            break;
        default:
            System.err.println("AppointmentResourceProvider.updateAppointment Unhandled interaction id  " + interactionId);
    }
    // we'll get the delivery channel from the slot
    String deliveryChannel = null;
    String practitionerRoleCode = null;
    String practitionerRoleDisplay = null;
    ScheduleDetail schedule = null;
    // Common to both Update and cancel
    // slots valid?
    List<SlotDetail> slots = new ArrayList<>();
    for (Long slotId : appointmentDetail.getSlotIds()) {
        SlotDetail slotDetail = slotSearch.findSlotByID(slotId);
        if (slotDetail == null) {
            throwUnprocessableEntity422_InvalidResourceException("Slot resource reference is not a valid resource");
        }
        if (deliveryChannel == null) {
            deliveryChannel = slotDetail.getDeliveryChannelCode();
        }
        if (schedule == null) {
            // load the schedule so we can get the Practitioner ID
            schedule = scheduleSearch.findScheduleByID(slotDetail.getScheduleReference());
        }
        if (practitionerRoleDisplay == null) {
            practitionerRoleDisplay = schedule.getPractitionerRoleDisplay();
            practitionerRoleCode = schedule.getPractitionerRoleCode();
        }
        slots.add(slotDetail);
    }
    validateUpdateExtensions(deliveryChannel, practitionerRoleDisplay, practitionerRoleCode, appointment.getExtension());
    // dates valid?
    // #203
    Date firstSlotStart = slots.get(0).getStartDateTime();
    Date lastSlotEnd = slots.get(slots.size() - 1).getEndDateTime();
    // need to insert a colon in the timezone string
    String firstSlotStartStr = TIMESTAMP_FORMAT.format(firstSlotStart).replaceFirst("([0-9]{2})([0-9]{2})$", "$1:$2");
    String lastSlotEndStr = TIMESTAMP_FORMAT.format(lastSlotEnd).replaceFirst("([0-9]{2})([0-9]{2})$", "$1:$2");
    VC.execute(new VC[] { new VC(() -> appointment.getStart().compareTo(firstSlotStart) != 0, () -> String.format("Start date '%s' must match start date of first slot '%s'", appointment.getStart(), firstSlotStart)), new VC(() -> appointment.getEnd().compareTo(lastSlotEnd) != 0, () -> String.format("End date '%s' must match end date of last slot '%s'", appointment.getEnd(), lastSlotEnd)), // #218 strings should match exactly
    new VC(() -> !appointment.getStartElement().getValueAsString().equals(firstSlotStartStr), () -> String.format("Start date '%s' must lexically match start date of first slot '%s'", appointment.getStartElement().getValueAsString(), firstSlotStartStr)), new VC(() -> !appointment.getEndElement().getValueAsString().equals(lastSlotEndStr), () -> String.format("End date '%s' must lexically match end date of last slot '%s'", appointment.getEndElement().getValueAsString(), lastSlotEndStr)), new VC(() -> appointment.getSlot().size() != slots.size(), () -> String.format("Slot count mismatch %d provided appointment has %d", appointment.getSlot().size(), slots.size())) });
    // check the slots match
    HashSet<String> hs = new HashSet<>();
    for (SlotDetail slotDetail : slots) {
        hs.add("Slot/" + slotDetail.getId());
    }
    for (Reference reference : appointment.getSlot()) {
        if (!hs.contains(reference.getReference())) {
            throwUnprocessableEntity422_InvalidResourceException(String.format("Provided slot id %s does not exist in booked appointment", reference.getReference()));
        }
    }
    // Update version and
    appointmentDetail.setLastUpdated(new Date());
    // lastUpdated timestamp
    appointmentDetail = appointmentStore.saveAppointment(appointmentDetail, slots);
    methodOutcome.setId(new IdDt("Appointment", appointmentDetail.getId()));
    methodOutcome.setResource(appointmentDetailToAppointmentResourceConverter(appointmentDetail));
    return methodOutcome;
}
Also used : AppointmentParticipantComponent(org.hl7.fhir.dstu3.model.Appointment.AppointmentParticipantComponent) AppointmentDetail(uk.gov.hscic.model.appointment.AppointmentDetail) IdDt(ca.uhn.fhir.model.primitive.IdDt) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) VC(uk.gov.hscic.common.validators.VC) ScheduleDetail(uk.gov.hscic.model.appointment.ScheduleDetail) SlotDetail(uk.gov.hscic.model.appointment.SlotDetail)

Example 3 with FINAL

use of org.hl7.fhir.dstu3.model.Observation.ObservationStatus.FINAL in project gpconnect-demonstrator by nhsconnect.

the class GpConnectServerCapabilityStatementProvider method getServerConformance.

@Override
public CapabilityStatement getServerConformance(HttpServletRequest theRequest) {
    final boolean FROM_JSON = true;
    CapabilityStatement capabilityStatement = null;
    if (!FROM_JSON) {
        // Get the automatically generated statement
        capabilityStatement = super.getServerConformance(theRequest);
        // added at 1.2.2 force overwrite the default entries which are not correct
        for (CapabilityStatement.CapabilityStatementRestComponent st : capabilityStatement.getRest()) {
            for (CapabilityStatement.CapabilityStatementRestOperationComponent operation : st.getOperation()) {
                String opPlusDollar = "$" + operation.getName();
                switch(opPlusDollar) {
                    case REGISTER_PATIENT_OPERATION_NAME:
                        operation.getDefinition().setReference(OD_GPC_REGISTER_PATIENT);
                        break;
                    case GET_STRUCTURED_RECORD_OPERATION_NAME:
                        operation.getDefinition().setReference(OD_GPC_GET_STRUCTURED_RECORD);
                        break;
                }
            }
        }
    } else {
        try {
            // 1.2.6 #316
            String interactionId = theRequest.getHeader(SSP_INTERACTIONID);
            String capabilityFile = null;
            switch(interactionId) {
                case REST_READ_STRUCTURED_METADATA:
                    capabilityFile = "structured_capability.json";
                    break;
                default:
                    capabilityFile = "capability.json";
            }
            // read a json capability file
            String capabilityJson = new String(Files.readAllBytes(Paths.get(FhirRequestGenericIntercepter.getConfigPath() + "/" + capabilityFile)));
            FhirContext ctx = FhirContext.forDstu3();
            capabilityStatement = (CapabilityStatement) ctx.newJsonParser().parseResource(capabilityJson);
        } catch (IOException ex) {
            return null;
        }
    }
    // And add additional required information
    capabilityStatement.setVersion(SystemVariable.VERSION);
    capabilityStatement.setDescription("This server implements the GP Connect API version " + SystemVariable.VERSION);
    capabilityStatement.setName("GP Connect");
    capabilityStatement.setCopyright("Copyright NHS Digital 2018");
    capabilityStatement.getSoftware().setReleaseDate(Date.valueOf(LocalDate.parse("2017-09-27")));
    return capabilityStatement;
}
Also used : FhirContext(ca.uhn.fhir.context.FhirContext) CapabilityStatement(org.hl7.fhir.dstu3.model.CapabilityStatement) IOException(java.io.IOException)

Example 4 with FINAL

use of org.hl7.fhir.dstu3.model.Observation.ObservationStatus.FINAL in project beneficiary-fhir-data by CMSgov.

the class TransformerUtils method addCareTeamPractitioner.

/**
 * Ensures that the specified {@link ExplanationOfBenefit} has the specified {@link
 * CareTeamComponent}, and links the specified {@link ItemComponent} to that {@link
 * CareTeamComponent} (via {@link ItemComponent#addCareTeamLinkId(int)}).
 *
 * @param eob the {@link ExplanationOfBenefit} that the {@link CareTeamComponent} should be part
 *     of
 * @param eobItem the {@link ItemComponent} that should be linked to the {@link CareTeamComponent}
 * @param practitionerIdSystem the {@link Identifier#getSystem()} of the practitioner to reference
 *     in {@link CareTeamComponent#getProvider()}
 * @param practitionerIdValue the {@link Identifier#getValue()} of the practitioner to reference
 *     in {@link CareTeamComponent#getProvider()}
 * @param careTeamRole the {@link ClaimCareteamrole} to use for the {@link
 *     CareTeamComponent#getRole()}
 * @return the {@link CareTeamComponent} that was created/linked
 */
static CareTeamComponent addCareTeamPractitioner(ExplanationOfBenefit eob, ItemComponent eobItem, String practitionerIdSystem, String practitionerIdValue, ClaimCareteamrole careTeamRole) {
    // Try to find a matching pre-existing entry.
    CareTeamComponent careTeamEntry = eob.getCareTeam().stream().filter(ctc -> ctc.getProvider().hasIdentifier()).filter(ctc -> practitionerIdSystem.equals(ctc.getProvider().getIdentifier().getSystem()) && practitionerIdValue.equals(ctc.getProvider().getIdentifier().getValue())).filter(ctc -> ctc.hasRole()).filter(ctc -> careTeamRole.toCode().equals(ctc.getRole().getCodingFirstRep().getCode()) && careTeamRole.getSystem().equals(ctc.getRole().getCodingFirstRep().getSystem())).findAny().orElse(null);
    // If no match was found, add one to the EOB.
    if (careTeamEntry == null) {
        careTeamEntry = eob.addCareTeam();
        careTeamEntry.setSequence(eob.getCareTeam().size() + 1);
        careTeamEntry.setProvider(createIdentifierReference(practitionerIdSystem, practitionerIdValue));
        CodeableConcept careTeamRoleConcept = createCodeableConcept(ClaimCareteamrole.OTHER.getSystem(), careTeamRole.toCode());
        careTeamRoleConcept.getCodingFirstRep().setDisplay(careTeamRole.getDisplay());
        careTeamEntry.setRole(careTeamRoleConcept);
    }
    // care team entry is at eob level so no need to create item link id
    if (eobItem == null) {
        return careTeamEntry;
    }
    // Link the EOB.item to the care team entry (if it isn't already).
    final int careTeamEntrySequence = careTeamEntry.getSequence();
    if (eobItem.getCareTeamLinkId().stream().noneMatch(id -> id.getValue() == careTeamEntrySequence)) {
        eobItem.addCareTeamLinkId(careTeamEntrySequence);
    }
    return careTeamEntry;
}
Also used : Arrays(java.util.Arrays) CarrierClaimColumn(gov.cms.bfd.model.rif.CarrierClaimColumn) CcwCodebookInterface(gov.cms.bfd.model.codebook.model.CcwCodebookInterface) Identifier(org.hl7.fhir.dstu3.model.Identifier) Constants(ca.uhn.fhir.rest.api.Constants) Coding(org.hl7.fhir.dstu3.model.Coding) InpatientClaim(gov.cms.bfd.model.rif.InpatientClaim) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept) DomainResource(org.hl7.fhir.dstu3.model.DomainResource) IBaseExtension(org.hl7.fhir.instance.model.api.IBaseExtension) StringUtils(org.apache.commons.lang3.StringUtils) SNFClaimColumn(gov.cms.bfd.model.rif.SNFClaimColumn) BigDecimal(java.math.BigDecimal) SNFClaimLine(gov.cms.bfd.model.rif.SNFClaimLine) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) CarrierClaimLine(gov.cms.bfd.model.rif.CarrierClaimLine) Map(java.util.Map) ProcedureComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.ProcedureComponent) CcwCodebookMissingVariable(gov.cms.bfd.model.codebook.data.CcwCodebookMissingVariable) TemporalPrecisionEnum(ca.uhn.fhir.model.api.TemporalPrecisionEnum) Value(gov.cms.bfd.model.codebook.model.Value) Diagnosis(gov.cms.bfd.server.war.commons.Diagnosis) OutpatientClaim(gov.cms.bfd.model.rif.OutpatientClaim) Coverage(org.hl7.fhir.dstu3.model.Coverage) IdDt(ca.uhn.fhir.model.primitive.IdDt) ExplanationOfBenefit(org.hl7.fhir.dstu3.model.ExplanationOfBenefit) MedicareSegment(gov.cms.bfd.server.war.commons.MedicareSegment) Reference(org.hl7.fhir.dstu3.model.Reference) DiagnosisComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.DiagnosisComponent) InpatientClaimColumn(gov.cms.bfd.model.rif.InpatientClaimColumn) Set(java.util.Set) StandardCharsets(java.nio.charset.StandardCharsets) ZoneId(java.time.ZoneId) UncheckedIOException(java.io.UncheckedIOException) ReferralRequestStatus(org.hl7.fhir.dstu3.model.ReferralRequest.ReferralRequestStatus) Stream(java.util.stream.Stream) ReferralRequestRequesterComponent(org.hl7.fhir.dstu3.model.ReferralRequest.ReferralRequestRequesterComponent) CarrierClaim(gov.cms.bfd.model.rif.CarrierClaim) HHAClaimLine(gov.cms.bfd.model.rif.HHAClaimLine) Money(org.hl7.fhir.dstu3.model.Money) ReferralRequest(org.hl7.fhir.dstu3.model.ReferralRequest) BenefitComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.BenefitComponent) IAnyResource(org.hl7.fhir.instance.model.api.IAnyResource) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) CCWUtils(gov.cms.bfd.server.war.commons.CCWUtils) RequestDetails(ca.uhn.fhir.rest.api.server.RequestDetails) ResourceType(org.hl7.fhir.dstu3.model.ResourceType) CcwCodebookVariable(gov.cms.bfd.model.codebook.data.CcwCodebookVariable) Period(org.hl7.fhir.dstu3.model.Period) CurrencyIdentifier(gov.cms.bfd.server.war.stu3.providers.BeneficiaryTransformer.CurrencyIdentifier) CCWProcedure(gov.cms.bfd.server.war.commons.CCWProcedure) OffsetLinkBuilder(gov.cms.bfd.server.war.commons.OffsetLinkBuilder) Practitioner(org.hl7.fhir.dstu3.model.Practitioner) MetricRegistry(com.codahale.metrics.MetricRegistry) LinkBuilder(gov.cms.bfd.server.war.commons.LinkBuilder) BadCodeMonkeyException(gov.cms.bfd.sharedutils.exceptions.BadCodeMonkeyException) SimpleQuantity(org.hl7.fhir.dstu3.model.SimpleQuantity) IOException(java.io.IOException) Observation(org.hl7.fhir.dstu3.model.Observation) InputStreamReader(java.io.InputStreamReader) FDADrugDataUtilityApp(gov.cms.bfd.server.war.FDADrugDataUtilityApp) SupportingInformationComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.SupportingInformationComponent) DMEClaimColumn(gov.cms.bfd.model.rif.DMEClaimColumn) Patient(org.hl7.fhir.dstu3.model.Patient) MDC(org.slf4j.MDC) BufferedReader(java.io.BufferedReader) IBaseHasExtensions(org.hl7.fhir.instance.model.api.IBaseHasExtensions) Bundle(org.hl7.fhir.dstu3.model.Bundle) Date(java.util.Date) BundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent) LoggerFactory(org.slf4j.LoggerFactory) Extension(org.hl7.fhir.dstu3.model.Extension) ClaimCareteamrole(org.hl7.fhir.dstu3.model.codesystems.ClaimCareteamrole) Organization(org.hl7.fhir.dstu3.model.Organization) SNFClaim(gov.cms.bfd.model.rif.SNFClaim) HHAClaimColumn(gov.cms.bfd.model.rif.HHAClaimColumn) BenefitBalanceComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.BenefitBalanceComponent) Collection(java.util.Collection) ItemComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.ItemComponent) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) DiagnosisLabel(gov.cms.bfd.server.war.commons.Diagnosis.DiagnosisLabel) Quantity(org.hl7.fhir.dstu3.model.Quantity) UnsignedIntType(org.hl7.fhir.dstu3.model.UnsignedIntType) Objects(java.util.Objects) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) List(java.util.List) CareTeamComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.CareTeamComponent) TransformerConstants(gov.cms.bfd.server.war.commons.TransformerConstants) LocalDate(java.time.LocalDate) Optional(java.util.Optional) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DateType(org.hl7.fhir.dstu3.model.DateType) OutpatientClaimColumn(gov.cms.bfd.model.rif.OutpatientClaimColumn) HospiceClaimLine(gov.cms.bfd.model.rif.HospiceClaimLine) DataFormatException(ca.uhn.fhir.parser.DataFormatException) HashMap(java.util.HashMap) InpatientClaimLine(gov.cms.bfd.model.rif.InpatientClaimLine) OutpatientClaimLine(gov.cms.bfd.model.rif.OutpatientClaimLine) HashSet(java.util.HashSet) ExplanationOfBenefitStatus(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.ExplanationOfBenefitStatus) HHAClaim(gov.cms.bfd.model.rif.HHAClaim) ObservationStatus(org.hl7.fhir.dstu3.model.Observation.ObservationStatus) InvalidRifValueException(gov.cms.bfd.model.rif.parse.InvalidRifValueException) DMEClaim(gov.cms.bfd.model.rif.DMEClaim) DMEClaimLine(gov.cms.bfd.model.rif.DMEClaimLine) LinkedList(java.util.LinkedList) NoSuchElementException(java.util.NoSuchElementException) AdjudicationComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.AdjudicationComponent) BenefitCategory(org.hl7.fhir.dstu3.model.codesystems.BenefitCategory) Logger(org.slf4j.Logger) Resource(org.hl7.fhir.dstu3.model.Resource) Variable(gov.cms.bfd.model.codebook.model.Variable) HospiceClaim(gov.cms.bfd.model.rif.HospiceClaim) Consumer(java.util.function.Consumer) URLEncoder(java.net.URLEncoder) IdentifierType(gov.cms.bfd.server.war.commons.IdentifierType) InputStream(java.io.InputStream) CareTeamComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.CareTeamComponent) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 5 with FINAL

use of org.hl7.fhir.dstu3.model.Observation.ObservationStatus.FINAL in project beneficiary-fhir-data by CMSgov.

the class ExplanationOfBenefitResourceProvider method findClaimTypeByPatient.

/**
 * @param claimType the {@link ClaimType} to find
 * @param patientId the {@link Beneficiary#getBeneficiaryId()} to filter by
 * @param lastUpdated the update time to filter by
 * @return the matching claim/event entities
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
@Trace
private <T> List<T> findClaimTypeByPatient(ClaimType claimType, String patientId, DateRangeParam lastUpdated, DateRangeParam serviceDate) {
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery criteria = builder.createQuery((Class) claimType.getEntityClass());
    Root root = criteria.from(claimType.getEntityClass());
    claimType.getEntityLazyAttributes().stream().forEach(a -> root.fetch(a));
    criteria.select(root).distinct(true);
    // Search for a beneficiary's records. Use lastUpdated if present
    Predicate wherePredicate = builder.equal(root.get(claimType.getEntityBeneficiaryIdAttribute()), patientId);
    if (lastUpdated != null && !lastUpdated.isEmpty()) {
        Predicate predicate = QueryUtils.createLastUpdatedPredicate(builder, root, lastUpdated);
        wherePredicate = builder.and(wherePredicate, predicate);
    }
    criteria.where(wherePredicate);
    List<T> claimEntities = null;
    Long eobsByBeneIdQueryNanoSeconds = null;
    Timer.Context timerEobQuery = metricRegistry.timer(MetricRegistry.name(metricRegistry.getClass().getSimpleName(), "query", "eobs_by_bene_id", claimType.name().toLowerCase())).time();
    try {
        claimEntities = entityManager.createQuery(criteria).getResultList();
    } finally {
        eobsByBeneIdQueryNanoSeconds = timerEobQuery.stop();
        TransformerUtils.recordQueryInMdc(String.format("eobs_by_bene_id.%s", claimType.name().toLowerCase()), eobsByBeneIdQueryNanoSeconds, claimEntities == null ? 0 : claimEntities.size());
    }
    if (claimEntities != null && serviceDate != null && !serviceDate.isEmpty()) {
        final Instant lowerBound = serviceDate.getLowerBoundAsInstant() != null ? serviceDate.getLowerBoundAsInstant().toInstant() : null;
        final Instant upperBound = serviceDate.getUpperBoundAsInstant() != null ? serviceDate.getUpperBoundAsInstant().toInstant() : null;
        final java.util.function.Predicate<LocalDate> lowerBoundCheck = lowerBound == null ? (date) -> true : (date) -> compareLocalDate(date, lowerBound.atZone(ZoneId.systemDefault()).toLocalDate(), serviceDate.getLowerBound().getPrefix());
        final java.util.function.Predicate<LocalDate> upperBoundCheck = upperBound == null ? (date) -> true : (date) -> compareLocalDate(date, upperBound.atZone(ZoneId.systemDefault()).toLocalDate(), serviceDate.getUpperBound().getPrefix());
        return claimEntities.stream().filter(entity -> lowerBoundCheck.test(claimType.getServiceEndAttributeFunction().apply(entity)) && upperBoundCheck.test(claimType.getServiceEndAttributeFunction().apply(entity))).collect(Collectors.toList());
    }
    return claimEntities;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) IdParam(ca.uhn.fhir.rest.annotation.IdParam) Arrays(java.util.Arrays) Bundle(org.hl7.fhir.dstu3.model.Bundle) ListIterator(java.util.ListIterator) Description(ca.uhn.fhir.model.api.annotation.Description) IdType(org.hl7.fhir.dstu3.model.IdType) LoggerFactory(org.slf4j.LoggerFactory) NoResultException(javax.persistence.NoResultException) Matcher(java.util.regex.Matcher) 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) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) LoadedFilterManager(gov.cms.bfd.server.war.commons.LoadedFilterManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) IdDt(ca.uhn.fhir.model.primitive.IdDt) ExplanationOfBenefit(org.hl7.fhir.dstu3.model.ExplanationOfBenefit) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) ParamPrefixEnum(ca.uhn.fhir.rest.param.ParamPrefixEnum) Set(java.util.Set) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) List(java.util.List) TransformerConstants(gov.cms.bfd.server.war.commons.TransformerConstants) LocalDate(java.time.LocalDate) TokenOrListParam(ca.uhn.fhir.rest.param.TokenOrListParam) Timer(com.codahale.metrics.Timer) Optional(java.util.Optional) OptionalParam(ca.uhn.fhir.rest.annotation.OptionalParam) Pattern(java.util.regex.Pattern) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) QueryUtils(gov.cms.bfd.server.war.commons.QueryUtils) Trace(com.newrelic.api.agent.Trace) ArrayList(java.util.ArrayList) RequiredParam(ca.uhn.fhir.rest.annotation.RequiredParam) HashSet(java.util.HashSet) Inject(javax.inject.Inject) RequestDetails(ca.uhn.fhir.rest.api.server.RequestDetails) Search(ca.uhn.fhir.rest.annotation.Search) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) Nullable(javax.annotation.Nullable) 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) Logger(org.slf4j.Logger) 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) Comparator(java.util.Comparator) Root(javax.persistence.criteria.Root) Instant(java.time.Instant) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) LocalDate(java.time.LocalDate) Predicate(javax.persistence.criteria.Predicate) Timer(com.codahale.metrics.Timer) Trace(com.newrelic.api.agent.Trace)

Aggregations

Test (org.junit.jupiter.api.Test)229 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)85 HashMap (java.util.HashMap)83 CamelSpringBootTest (org.apache.camel.test.spring.junit5.CamelSpringBootTest)59 List (java.util.List)53 Bundle (org.hl7.fhir.dstu3.model.Bundle)50 Nonnull (javax.annotation.Nonnull)48 Patient (org.hl7.fhir.dstu3.model.Patient)46 Organization (org.hl7.fhir.dstu3.model.Organization)45 ArrayList (java.util.ArrayList)44 Bundle (org.hl7.fhir.r4.model.Bundle)41 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)39 UUID (java.util.UUID)38 Collectors (java.util.stream.Collectors)38 Coding (org.hl7.fhir.r4.model.Coding)34 FhirContext (ca.uhn.fhir.context.FhirContext)33 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)32 IParser (ca.uhn.fhir.parser.IParser)31 IOException (java.io.IOException)29 IdType (org.hl7.fhir.dstu3.model.IdType)28