use of ca.uhn.fhir.rest.server.exceptions.InvalidRequestException in project gpconnect-demonstrator by nhsconnect.
the class FhirRequestAuthInterceptor method validateOrganizationIdentifier.
private void validateOrganizationIdentifier(RequestDetails requestDetails) {
Map<String, String[]> parameters = requestDetails.getParameters();
if (parameters != null && parameters.containsKey(SystemParameter.IDENTIFIER)) {
String[] identifierParts = parameters.get(SystemParameter.IDENTIFIER)[0].split("\\|");
String identifierSystem = identifierParts[0];
if (!PERMITTED_ORGANIZATION_IDENTIFIER_SYSTEMS.contains(identifierSystem)) {
throw OperationOutcomeFactory.buildOperationOutcomeException(new InvalidRequestException("Invalid organization identifier system: " + identifierSystem), SystemCode.BAD_REQUEST, IssueType.INVALID);
}
}
}
use of ca.uhn.fhir.rest.server.exceptions.InvalidRequestException in project gpconnect-demonstrator by nhsconnect.
the class WebTokenValidator method verifyRequestedResourceValues.
private static void verifyRequestedResourceValues(WebToken webToken) {
// Checking the reason for request is directcare
if (!"directcare".equals(webToken.getReasonForRequest())) {
throw OperationOutcomeFactory.buildOperationOutcomeException(new InvalidRequestException("Reason for request is not directcare"), SystemCode.BAD_REQUEST, IssueType.INVALID);
}
RequestingDevice requestingDevice = webToken.getRequestingDevice();
if (null == requestingDevice) {
throw OperationOutcomeFactory.buildOperationOutcomeException(new InvalidRequestException("No requesting_device"), SystemCode.BAD_REQUEST, IssueType.INVALID);
}
String deviceType = requestingDevice.getResourceType();
String organizationType = webToken.getRequestingOrganization().getResourceType();
String practitionerType = webToken.getRequestingPractitioner().getResourceType();
if (!deviceType.equals("Device") || !organizationType.equals("Organization") || !practitionerType.equals("Practitioner")) {
throw OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException("Invalid resource type"), SystemCode.BAD_REQUEST, IssueType.INVALID);
}
}
use of ca.uhn.fhir.rest.server.exceptions.InvalidRequestException 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);
}
}
use of ca.uhn.fhir.rest.server.exceptions.InvalidRequestException in project gpconnect-demonstrator by nhsconnect.
the class PatientResourceProvider method validateNames.
private void validateNames(Patient patient) {
List<HumanName> names = patient.getName();
if (names.size() < 1) {
throw OperationOutcomeFactory.buildOperationOutcomeException(new InvalidRequestException("The patient must have at least one Name."), SystemCode.BAD_REQUEST, IssueType.INVALID);
}
List<HumanName> activeOfficialNames = names.stream().filter(nm -> IsActiveName(nm)).filter(nm -> NameUse.OFFICIAL.equals(nm.getUse())).collect(Collectors.toList());
if (activeOfficialNames.size() != 1) {
InvalidRequestException exception = new InvalidRequestException("The patient must have one Active Name with a Use of OFFICIAL");
throw OperationOutcomeFactory.buildOperationOutcomeException(exception, SystemCode.BAD_REQUEST, IssueType.INVALID);
}
List<String> officialFamilyNames = new ArrayList<>();
for (HumanName humanName : activeOfficialNames) {
if (humanName.getFamily() != null) {
officialFamilyNames.add(humanName.getFamily());
}
}
validateNameCount(officialFamilyNames, "family");
}
use of ca.uhn.fhir.rest.server.exceptions.InvalidRequestException in project gpconnect-demonstrator by nhsconnect.
the class PatientResourceProvider method valiateGender.
private void valiateGender(Patient patient) {
AdministrativeGender gender = patient.getGender();
if (gender != null) {
EnumSet<AdministrativeGender> genderList = EnumSet.allOf(AdministrativeGender.class);
Boolean valid = false;
for (AdministrativeGender genderItem : genderList) {
if (genderItem.toCode().equalsIgnoreCase(gender.toString())) {
valid = true;
break;
}
}
if (!valid) {
throw OperationOutcomeFactory.buildOperationOutcomeException(new InvalidRequestException(String.format("The supplied Patient gender %s is an unrecognised type.", gender)), SystemCode.BAD_REQUEST, IssueType.INVALID);
}
}
}
Aggregations