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;
}
Aggregations