Search in sources :

Example 1 with IParameter

use of ca.uhn.fhir.rest.server.method.IParameter in project gpconnect-demonstrator by nhsconnect.

the class PatientJwtValidator method getNhsNumber.

private String getNhsNumber(RequestDetails requestDetails) {
    ResourceBinding patientResourceBinding = getPatientResourceBinding(requestDetails.getServer());
    if (patientResourceBinding != null) {
        BaseMethodBinding<?> methodBinding = patientResourceBinding.getMethod(requestDetails);
        // the request may not be for the patient resource in which case
        // we would not expect a method binding
        Object parameterValue = null;
        if (methodBinding != null) {
            for (IParameter parameter : methodBinding.getParameters()) {
                parameterValue = parameter.translateQueryParametersIntoServerArgument(requestDetails, methodBinding);
                // the identifier may have been passed in the URL
                if (parameterValue == null) {
                    parameterValue = ParameterUtil.convertIdToType(requestDetails.getId(), IdDt.class);
                }
                if (parameterValue != null) {
                    String nhsNumber = patientResourceProvider.getNhsNumber(parameterValue);
                    if (null != nhsNumber) {
                        return nhsNumber;
                    }
                }
            }
        }
        if (parameterValue != null) {
            if (RequestTypeEnum.GET == requestDetails.getRequestType()) {
                throw OperationOutcomeFactory.buildOperationOutcomeException(new ResourceNotFoundException("No patient details found for patient ID: " + parameterValue), SystemCode.PATIENT_NOT_FOUND, IssueType.INVALID);
            }
            // Otherwise, there should have been an identifier header
            throw OperationOutcomeFactory.buildOperationOutcomeException(new InvalidRequestException("No NHS number submitted: " + parameterValue), SystemCode.INVALID_NHS_NUMBER, IssueType.INVALID);
        }
    }
    return null;
}
Also used : IParameter(ca.uhn.fhir.rest.server.method.IParameter) IdDt(ca.uhn.fhir.model.primitive.IdDt) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) ResourceBinding(ca.uhn.fhir.rest.server.ResourceBinding)

Aggregations

IdDt (ca.uhn.fhir.model.primitive.IdDt)1 ResourceBinding (ca.uhn.fhir.rest.server.ResourceBinding)1 InvalidRequestException (ca.uhn.fhir.rest.server.exceptions.InvalidRequestException)1 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)1 IParameter (ca.uhn.fhir.rest.server.method.IParameter)1