Search in sources :

Example 1 with TokenOrListParam

use of ca.uhn.fhir.rest.param.TokenOrListParam 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)

Aggregations

Include (ca.uhn.fhir.model.api.Include)1 Search (ca.uhn.fhir.rest.annotation.Search)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 Bundle (org.hl7.fhir.dstu3.model.Bundle)1 OperationOutcome (org.hl7.fhir.dstu3.model.OperationOutcome)1 SlotSearch (uk.gov.hscic.appointment.slot.SlotSearch)1 FhirRequestGenericIntercepter.throwInvalidRequest400_BadRequestException (uk.gov.hscic.common.filters.FhirRequestGenericIntercepter.throwInvalidRequest400_BadRequestException)1 FhirRequestGenericIntercepter.throwUnprocessableEntity422_BadRequestException (uk.gov.hscic.common.filters.FhirRequestGenericIntercepter.throwUnprocessableEntity422_BadRequestException)1 FhirRequestGenericIntercepter.throwUnprocessableEntityInvalid422_ParameterException (uk.gov.hscic.common.filters.FhirRequestGenericIntercepter.throwUnprocessableEntityInvalid422_ParameterException)1