Search in sources :

Example 1 with Search

use of ca.uhn.fhir.rest.annotation.Search in project gpconnect-demonstrator by nhsconnect.

the class MedicationAdministrationResourceProvider method getMedicationAdministrationsForPatientId.

@Search
public List<MedicationAdministration> getMedicationAdministrationsForPatientId(@RequiredParam(name = "patient") String patientId) {
    ArrayList<MedicationAdministration> medicationAdministrations = new ArrayList<>();
    List<MedicationAdministrationDetail> medicationAdministrationDetailList = medicationAdministrationSearch.findMedicationAdministrationForPatient(Long.parseLong(patientId));
    if (medicationAdministrationDetailList != null && !medicationAdministrationDetailList.isEmpty()) {
        for (MedicationAdministrationDetail medicationAdministrationDetail : medicationAdministrationDetailList) {
            MedicationAdministration medicationAdministration = new MedicationAdministration();
            String resourceId = String.valueOf(medicationAdministrationDetail.getId());
            String versionId = String.valueOf(medicationAdministrationDetail.getLastUpdated().getTime());
            String resourceType = medicationAdministration.getResourceType().toString();
            IdType id = new IdType(resourceType, resourceId, versionId);
            medicationAdministration.setId(id);
            medicationAdministration.getMeta().setVersionId(versionId);
            medicationAdministration.getMeta().setLastUpdated(medicationAdministrationDetail.getLastUpdated());
            medicationAdministration.addDefinition(new Reference("Patient/" + medicationAdministrationDetail.getPatientId()));
            medicationAdministration.addDefinition(new Reference("Practitioner/" + medicationAdministrationDetail.getPractitionerId()));
            medicationAdministration.setPrescription(new Reference("MedicationOrder/" + medicationAdministrationDetail.getPrescriptionId()));
            medicationAdministration.setEffective(new DateType(medicationAdministrationDetail.getAdministrationDate()));
            medicationAdministration.setMedication(new Reference("Medication/" + medicationAdministrationDetail.getMedicationId()));
            medicationAdministrations.add(medicationAdministration);
        }
    }
    return medicationAdministrations;
}
Also used : MedicationAdministrationDetail(uk.gov.hscic.model.medication.MedicationAdministrationDetail) Reference(org.hl7.fhir.dstu3.model.Reference) ArrayList(java.util.ArrayList) MedicationAdministration(org.hl7.fhir.dstu3.model.MedicationAdministration) DateType(org.hl7.fhir.dstu3.model.DateType) IdType(org.hl7.fhir.dstu3.model.IdType) Search(ca.uhn.fhir.rest.annotation.Search) MedicationAdministrationSearch(uk.gov.hscic.medication.administration.MedicationAdministrationSearch)

Example 2 with Search

use of ca.uhn.fhir.rest.annotation.Search in project gpconnect-demonstrator by nhsconnect.

the class OrganizationResourceProvider method getOrganizationsByODSCode.

@Search
public List<Organization> getOrganizationsByODSCode(@RequiredParam(name = Organization.SP_IDENTIFIER) TokenParam tokenParam, @Sort SortSpec sort, @Count Integer count) {
    if (StringUtils.isBlank(tokenParam.getSystem()) || StringUtils.isBlank(tokenParam.getValue())) {
        throw OperationOutcomeFactory.buildOperationOutcomeException(new InvalidRequestException("Missing identifier token"), SystemCode.INVALID_PARAMETER, IssueType.INVALID);
    }
    if (tokenParam.getSystem().equals(SystemURL.ID_ODS_ORGANIZATION_CODE) || tokenParam.getSystem().equals(SystemURL.ID_ODS_OLD_ORGANIZATION_CODE)) {
        List<Organization> organizationDetails = convertOrganizaitonDetailsListToOrganizationList(organizationSearch.findOrganizationDetailsByOrgODSCode(tokenParam.getValue()));
        if (organizationDetails.isEmpty()) {
            return null;
        }
        if (sort != null && sort.getParamName().equalsIgnoreCase(Location.SP_STATUS)) {
            Collections.sort(organizationDetails, (Organization a, Organization b) -> {
                String aStatus = a.getName();
                String bStatus = b.getName();
                if (aStatus == null && bStatus == null) {
                    return 0;
                }
                if (aStatus == null && bStatus != null) {
                    return -1;
                }
                if (aStatus != null && bStatus == null) {
                    return 1;
                }
                return aStatus.compareToIgnoreCase(bStatus);
            });
        }
        // Update startIndex if we do paging
        return count != null ? organizationDetails.subList(0, count) : organizationDetails;
    } else {
        throw OperationOutcomeFactory.buildOperationOutcomeException(new InvalidRequestException("Invalid system code"), SystemCode.INVALID_PARAMETER, IssueType.INVALID);
    }
}
Also used : Organization(org.hl7.fhir.dstu3.model.Organization) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) Search(ca.uhn.fhir.rest.annotation.Search)

Example 3 with Search

use of ca.uhn.fhir.rest.annotation.Search in project gpconnect-demonstrator by nhsconnect.

the class SlotResourceProvider method getSlotByIds.

@Search
public Bundle getSlotByIds(@RequiredParam(name = "start") DateParam startDate, @RequiredParam(name = "end") DateParam endDate, @RequiredParam(name = "status") String status, @OptionalParam(name = "searchFilter") TokenAndListParam searchFilters, @IncludeParam(allow = { "Slot:schedule", "Schedule:actor:Practitioner", "Schedule:actor:Location", "Location:managingOrganization" }) Set<Include> theIncludes) {
    boolean foundSchedule = false;
    for (Include anInclude : theIncludes) {
        // getParamName returns any text between the first and second colons
        if (anInclude.getParamName().equals("schedule")) {
            foundSchedule = true;
            break;
        }
    }
    if (!foundSchedule) {
        // TODO check not invalid parameter?
        throwInvalidRequest400_BadRequestException("No include Slot:schedule parameter has been provided");
    }
    Bundle bundle = new Bundle();
    String bookingOdsCode = "";
    String bookingOrgType = "";
    if (!status.equals("free")) {
        throwUnprocessableEntityInvalid422_ParameterException("Status incorrect: Must be equal to free");
    }
    try {
        startDate.isEmpty();
        endDate.isEmpty();
    } catch (Exception e) {
        throwUnprocessableEntityInvalid422_ParameterException("Start Date and End Date must be populated with a correct date format");
    }
    if (startDate.getPrefix() != ParamPrefixEnum.GREATERTHAN_OR_EQUALS || endDate.getPrefix() != ParamPrefixEnum.LESSTHAN_OR_EQUALS) {
        throwUnprocessableEntityInvalid422_ParameterException("Invalid Prefix used");
    }
    validateStartDateParamAndEndDateParam(startDate, endDate);
    if (searchFilters != null) {
        List<TokenOrListParam> searchFilter = searchFilters.getValuesAsQueryTokens();
        for (TokenOrListParam filter : searchFilter) {
            TokenParam token = filter.getValuesAsQueryTokens().get(0);
            if (token.getSystem().equals(SystemURL.VS_GPC_ORG_TYPE)) {
                bookingOrgType = token.getValue();
            }
            if (token.getSystem().equals(SystemURL.ID_ODS_ORGANIZATION_CODE)) {
                bookingOdsCode = token.getValue();
            }
        }
    }
    boolean actorPractitioner = false;
    boolean actorLocation = false;
    boolean managingOrganisation = false;
    for (Include include : theIncludes) {
        switch(include.getValue()) {
            case "Schedule:actor:Practitioner":
                actorPractitioner = true;
                break;
            case "Schedule:actor:Location":
                actorLocation = true;
                break;
            case "Location:managingOrganization":
                managingOrganisation = true;
                break;
        }
    }
    startDate.getValueAsInstantDt().getValue();
    getScheduleOperation.populateBundle(bundle, new OperationOutcome(), startDate.getValueAsInstantDt().getValue(), endDate.getValueAsInstantDt().getValue(), actorPractitioner, actorLocation, managingOrganisation, bookingOdsCode, bookingOrgType);
    return bundle;
}
Also used : TokenOrListParam(ca.uhn.fhir.rest.param.TokenOrListParam) Bundle(org.hl7.fhir.dstu3.model.Bundle) TokenParam(ca.uhn.fhir.rest.param.TokenParam) OperationOutcome(org.hl7.fhir.dstu3.model.OperationOutcome) Include(ca.uhn.fhir.model.api.Include) FhirRequestGenericIntercepter.throwUnprocessableEntityInvalid422_ParameterException(uk.gov.hscic.common.filters.FhirRequestGenericIntercepter.throwUnprocessableEntityInvalid422_ParameterException) FhirRequestGenericIntercepter.throwInvalidRequest400_BadRequestException(uk.gov.hscic.common.filters.FhirRequestGenericIntercepter.throwInvalidRequest400_BadRequestException) InternalErrorException(ca.uhn.fhir.rest.server.exceptions.InternalErrorException) FhirRequestGenericIntercepter.throwUnprocessableEntity422_BadRequestException(uk.gov.hscic.common.filters.FhirRequestGenericIntercepter.throwUnprocessableEntity422_BadRequestException) Search(ca.uhn.fhir.rest.annotation.Search) SlotSearch(uk.gov.hscic.appointment.slot.SlotSearch)

Example 4 with Search

use of ca.uhn.fhir.rest.annotation.Search in project gpconnect-demonstrator by nhsconnect.

the class MedicationDispenseResourceProvider method getMedicationDispensesForPatientId.

@Search
public List<MedicationDispense> getMedicationDispensesForPatientId(@RequiredParam(name = "patient") String patientId) {
    ArrayList<MedicationDispense> medicationDispenses = new ArrayList<>();
    List<MedicationDispenseDetail> medicationDispenseDetailList = medicationDispenseSearch.findMedicationDispenseForPatient(Long.parseLong(patientId));
    if (medicationDispenseDetailList != null && !medicationDispenseDetailList.isEmpty()) {
        for (MedicationDispenseDetail medicationDispenseDetail : medicationDispenseDetailList) {
            MedicationDispense medicationDispense = new MedicationDispense();
            medicationDispense.setId(String.valueOf(medicationDispenseDetail.getId()));
            medicationDispense.getMeta().setLastUpdated(medicationDispenseDetail.getLastUpdated());
            medicationDispense.getMeta().setVersionId(String.valueOf(medicationDispenseDetail.getLastUpdated().getTime()));
            switch(medicationDispenseDetail.getStatus().toLowerCase(Locale.UK)) {
                case "completed":
                    medicationDispense.setStatus(MedicationDispenseStatus.COMPLETED);
                    break;
                case "entered_in_error":
                    medicationDispense.setStatus(MedicationDispenseStatus.ENTEREDINERROR);
                    break;
                case "in_progress":
                    medicationDispense.setStatus(MedicationDispenseStatus.INPROGRESS);
                    break;
                case "on_hold":
                    medicationDispense.setStatus(MedicationDispenseStatus.ONHOLD);
                    break;
                case "stopped":
                    medicationDispense.setStatus(MedicationDispenseStatus.STOPPED);
                    break;
            }
            medicationDispense.setSubject(new Reference("Patient/" + patientId));
            medicationDispense.setAuthorizingPrescription(Collections.singletonList(new Reference("MedicationOrder/" + medicationDispenseDetail.getMedicationOrderId())));
            Medication medication = new Medication();
            Coding coding = new Coding();
            coding.setCode(String.valueOf(medicationDispenseDetail.getMedicationId()));
            coding.setDisplay(medicationDispenseDetail.getMedicationName());
            CodeableConcept codeableConcept = new CodeableConcept();
            codeableConcept.setCoding(Collections.singletonList(coding));
            medication.setCode(codeableConcept);
            medicationDispense.addDosageInstruction().setText(medicationDispenseDetail.getDosageText());
            medicationDispenses.add(medicationDispense);
        }
    }
    return medicationDispenses;
}
Also used : Coding(org.hl7.fhir.dstu3.model.Coding) MedicationDispense(org.hl7.fhir.dstu3.model.MedicationDispense) Reference(org.hl7.fhir.dstu3.model.Reference) ArrayList(java.util.ArrayList) Medication(org.hl7.fhir.dstu3.model.Medication) MedicationDispenseDetail(uk.gov.hscic.model.medication.MedicationDispenseDetail) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept) MedicationDispenseSearch(uk.gov.hscic.medication.dispense.MedicationDispenseSearch) Search(ca.uhn.fhir.rest.annotation.Search)

Example 5 with Search

use of ca.uhn.fhir.rest.annotation.Search in project gpconnect-demonstrator by nhsconnect.

the class MedicationOrderResourceProvider method getMedicationOrdersForPatientId.

@Search
public List<MedicationRequest> getMedicationOrdersForPatientId(@RequiredParam(name = "patient") String patientId) {
    ArrayList<MedicationRequest> medicationOrders = new ArrayList<>();
    List<MedicationOrderDetails> medicationOrderDetailsList = medicationOrderSearch.findMedicationOrdersForPatient(Long.parseLong(patientId));
    if (medicationOrderDetailsList != null && !medicationOrderDetailsList.isEmpty()) {
        for (MedicationOrderDetails medicationOrderDetails : medicationOrderDetailsList) {
            medicationOrders.add(medicationOrderDetailsToMedicationOrderResourceConverter(medicationOrderDetails));
        }
    }
    return medicationOrders;
}
Also used : MedicationOrderDetails(uk.gov.hscic.model.medication.MedicationOrderDetails) ArrayList(java.util.ArrayList) Search(ca.uhn.fhir.rest.annotation.Search) MedicationOrderSearch(uk.gov.hscic.medication.orders.MedicationOrderSearch)

Aggregations

Search (ca.uhn.fhir.rest.annotation.Search)5 ArrayList (java.util.ArrayList)3 Reference (org.hl7.fhir.dstu3.model.Reference)2 Include (ca.uhn.fhir.model.api.Include)1 TokenOrListParam (ca.uhn.fhir.rest.param.TokenOrListParam)1 TokenParam (ca.uhn.fhir.rest.param.TokenParam)1 InternalErrorException (ca.uhn.fhir.rest.server.exceptions.InternalErrorException)1 InvalidRequestException (ca.uhn.fhir.rest.server.exceptions.InvalidRequestException)1 Bundle (org.hl7.fhir.dstu3.model.Bundle)1 CodeableConcept (org.hl7.fhir.dstu3.model.CodeableConcept)1 Coding (org.hl7.fhir.dstu3.model.Coding)1 DateType (org.hl7.fhir.dstu3.model.DateType)1 IdType (org.hl7.fhir.dstu3.model.IdType)1 Medication (org.hl7.fhir.dstu3.model.Medication)1 MedicationAdministration (org.hl7.fhir.dstu3.model.MedicationAdministration)1 MedicationDispense (org.hl7.fhir.dstu3.model.MedicationDispense)1 OperationOutcome (org.hl7.fhir.dstu3.model.OperationOutcome)1 Organization (org.hl7.fhir.dstu3.model.Organization)1 SlotSearch (uk.gov.hscic.appointment.slot.SlotSearch)1 FhirRequestGenericIntercepter.throwInvalidRequest400_BadRequestException (uk.gov.hscic.common.filters.FhirRequestGenericIntercepter.throwInvalidRequest400_BadRequestException)1