Search in sources :

Example 1 with InvalidRequestException

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);
        }
    }
}
Also used : InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException)

Example 2 with InvalidRequestException

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);
    }
}
Also used : UnprocessableEntityException(ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException)

Example 3 with InvalidRequestException

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);
    }
}
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 4 with InvalidRequestException

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");
}
Also used : IdParam(ca.uhn.fhir.rest.annotation.IdParam) ParametersParameterComponent(org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent) Type(org.hl7.fhir.dstu3.model.Type) Bundle(org.hl7.fhir.dstu3.model.Bundle) ContactDetail(org.hl7.fhir.dstu3.model.ContactDetail) AppointmentResourceProvider(uk.gov.hscic.appointments.AppointmentResourceProvider) MedicationAdministration(org.hl7.fhir.dstu3.model.MedicationAdministration) Date(java.util.Date) Identifier(org.hl7.fhir.dstu3.model.Identifier) Coding(org.hl7.fhir.dstu3.model.Coding) IdType(org.hl7.fhir.dstu3.model.IdType) Autowired(org.springframework.beans.factory.annotation.Autowired) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept) Operation(ca.uhn.fhir.rest.annotation.Operation) Extension(org.hl7.fhir.dstu3.model.Extension) IdentifierUse(org.hl7.fhir.dstu3.model.Identifier.IdentifierUse) NhsCodeValidator(uk.gov.hscic.util.NhsCodeValidator) DateTimeDt(ca.uhn.fhir.model.primitive.DateTimeDt) DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) Locale(java.util.Locale) IResourceProvider(ca.uhn.fhir.rest.server.IResourceProvider) Map(java.util.Map) EnumSet(java.util.EnumSet) IdDt(ca.uhn.fhir.model.primitive.IdDt) Reference(org.hl7.fhir.dstu3.model.Reference) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) Set(java.util.Set) Count(ca.uhn.fhir.rest.annotation.Count) Collectors(java.util.stream.Collectors) Appointment(org.hl7.fhir.dstu3.model.Appointment) IssueType(org.hl7.fhir.dstu3.model.OperationOutcome.IssueType) AdministrativeGender(org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender) List(java.util.List) SortSpec(ca.uhn.fhir.rest.api.SortSpec) IdentifierValidator(uk.gov.hscic.common.validators.IdentifierValidator) PostConstruct(javax.annotation.PostConstruct) ContactPointSystem(org.hl7.fhir.dstu3.model.ContactPoint.ContactPointSystem) SystemCode(uk.gov.hscic.SystemCode) OptionalParam(ca.uhn.fhir.rest.annotation.OptionalParam) BooleanType(org.hl7.fhir.dstu3.model.BooleanType) ContactPoint(org.hl7.fhir.dstu3.model.ContactPoint) NameUse(org.hl7.fhir.dstu3.model.HumanName.NameUse) PatientSearch(uk.gov.hscic.patient.details.PatientSearch) AddressType(org.hl7.fhir.dstu3.model.Address.AddressType) MedicationRequest(org.hl7.fhir.dstu3.model.MedicationRequest) PatientStore(uk.gov.hscic.patient.details.PatientStore) HashMap(java.util.HashMap) PractitionerResourceProvider(uk.gov.hscic.practitioner.PractitionerResourceProvider) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) RequiredParam(ca.uhn.fhir.rest.annotation.RequiredParam) Calendar(java.util.Calendar) UnprocessableEntityException(ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException) MedicationOrderResourceProvider(uk.gov.hscic.medications.MedicationOrderResourceProvider) AddressUse(org.hl7.fhir.dstu3.model.Address.AddressUse) Search(ca.uhn.fhir.rest.annotation.Search) Period(org.hl7.fhir.dstu3.model.Period) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) Read(ca.uhn.fhir.rest.annotation.Read) Practitioner(org.hl7.fhir.dstu3.model.Practitioner) DateTimeType(org.hl7.fhir.dstu3.model.DateTimeType) Sort(ca.uhn.fhir.rest.annotation.Sort) PatientDetails(uk.gov.hscic.model.patient.PatientDetails) BundleType(org.hl7.fhir.dstu3.model.Bundle.BundleType) SystemURL(uk.gov.hscic.SystemURL) TokenParam(ca.uhn.fhir.rest.param.TokenParam) MedicationAdministrationResourceProvider(uk.gov.hscic.medications.MedicationAdministrationResourceProvider) OperationOutcomeFactory(uk.gov.hscic.OperationOutcomeFactory) Component(org.springframework.stereotype.Component) ResourceParam(ca.uhn.fhir.rest.annotation.ResourceParam) StaticElementsHelper(uk.gov.hscic.common.helpers.StaticElementsHelper) MedicationDispenseResourceProvider(uk.gov.hscic.medications.MedicationDispenseResourceProvider) Patient(org.hl7.fhir.dstu3.model.Patient) DateAndListParam(ca.uhn.fhir.rest.param.DateAndListParam) ContactPointUse(org.hl7.fhir.dstu3.model.ContactPoint.ContactPointUse) Parameters(org.hl7.fhir.dstu3.model.Parameters) OrganizationResourceProvider(uk.gov.hscic.organization.OrganizationResourceProvider) MedicationDispense(org.hl7.fhir.dstu3.model.MedicationDispense) FHIRException(org.hl7.fhir.exceptions.FHIRException) Collections(java.util.Collections) HumanName(org.hl7.fhir.dstu3.model.HumanName) HumanName(org.hl7.fhir.dstu3.model.HumanName) ArrayList(java.util.ArrayList) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException)

Example 5 with InvalidRequestException

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);
        }
    }
}
Also used : InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) AdministrativeGender(org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender)

Aggregations

InvalidRequestException (ca.uhn.fhir.rest.server.exceptions.InvalidRequestException)10 UnprocessableEntityException (ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException)4 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)3 IdDt (ca.uhn.fhir.model.primitive.IdDt)2 Search (ca.uhn.fhir.rest.annotation.Search)2 AdministrativeGender (org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender)2 FHIRException (org.hl7.fhir.exceptions.FHIRException)2 PatientDetails (uk.gov.hscic.model.patient.PatientDetails)2 DateTimeDt (ca.uhn.fhir.model.primitive.DateTimeDt)1 DataFormatException (ca.uhn.fhir.parser.DataFormatException)1 Count (ca.uhn.fhir.rest.annotation.Count)1 IdParam (ca.uhn.fhir.rest.annotation.IdParam)1 Operation (ca.uhn.fhir.rest.annotation.Operation)1 OptionalParam (ca.uhn.fhir.rest.annotation.OptionalParam)1 Read (ca.uhn.fhir.rest.annotation.Read)1 RequiredParam (ca.uhn.fhir.rest.annotation.RequiredParam)1 ResourceParam (ca.uhn.fhir.rest.annotation.ResourceParam)1 Sort (ca.uhn.fhir.rest.annotation.Sort)1 SortSpec (ca.uhn.fhir.rest.api.SortSpec)1 DateAndListParam (ca.uhn.fhir.rest.param.DateAndListParam)1