Search in sources :

Example 1 with FhirValidationException

use of uk.nhs.adaptors.scr.exceptions.FhirValidationException in project summary-care-record-api by NHSDigital.

the class ParticipantAgentMapper method mapInformant.

public static Participant.Informant mapInformant(Bundle bundle, EncounterParticipantComponent encounterParticipant) {
    var informant = new Participant.Informant();
    informant.setTime(formatDateToHl7(encounterParticipant.getPeriod().getStartElement()));
    var participantType = encounterParticipant.getIndividual().getReference().split("/")[0];
    if (PractitionerRole.class.getSimpleName().equals(participantType)) {
        setParticipantAgents(bundle, encounterParticipant.getIndividual(), informant);
    } else if (RelatedPerson.class.getSimpleName().equals(participantType)) {
        var relatedPerson = getResourceByReference(bundle, encounterParticipant.getIndividual().getReference(), RelatedPerson.class).orElseThrow(() -> new FhirValidationException(String.format("Bundle is missing RelatedPerson %s that is linked to Encounter", encounterParticipant.getIndividual().getReference())));
        var participantNonAgentRole = new NonAgentRole("participantNonAgentRole");
        setRelationship(relatedPerson, participantNonAgentRole);
        setRelatedPersonName(relatedPerson, participantNonAgentRole);
        informant.setParticipantNonAgentRole(participantNonAgentRole);
    } else {
        throw new FhirValidationException(String.format("Invalid Encounter participant type %s", participantType));
    }
    return informant;
}
Also used : PractitionerRole(org.hl7.fhir.r4.model.PractitionerRole) NonAgentRole(uk.nhs.adaptors.scr.models.xml.NonAgentRole) FhirValidationException(uk.nhs.adaptors.scr.exceptions.FhirValidationException)

Example 2 with FhirValidationException

use of uk.nhs.adaptors.scr.exceptions.FhirValidationException in project summary-care-record-api by NHSDigital.

the class ObservationMapper method mapFinding.

private static Finding mapFinding(Observation observation, Bundle bundle) {
    var finding = new Finding();
    finding.setIdRoot(observation.getIdentifierFirstRep().getValue());
    finding.setCodeCode(observation.getCode().getCodingFirstRep().getCode());
    finding.setCodeDisplayName(observation.getCode().getCodingFirstRep().getDisplay());
    finding.setStatusCodeCode(mapStatus(observation.getStatus()));
    if (observation.getEffective() instanceof DateTimeType) {
        finding.setEffectiveTimeCenter(formatDateToHl7(observation.getEffectiveDateTimeType()));
    } else if (observation.getEffective() instanceof Period) {
        var period = observation.getEffectivePeriod();
        if (period.hasStart()) {
            finding.setEffectiveTimeLow(formatDateToHl7(period.getStartElement()));
        }
        if (period.hasEnd()) {
            finding.setEffectiveTimeHigh(formatDateToHl7(period.getEndElement()));
        }
    } else {
        throw new FhirValidationException("Observation.effective must be of type DateTimeType or Period");
    }
    var encounterReference = observation.getEncounter().getReference();
    if (StringUtils.isNotBlank(encounterReference)) {
        var encounter = getResourceByReference(bundle, encounterReference, Encounter.class).orElseThrow(() -> new FhirValidationException(String.format("Bundle is Missing Encounter %s that is linked to Condition %s", observation.getEncounter().getReference(), observation.getId())));
        for (var encounterParticipant : encounter.getParticipant()) {
            Coding coding = encounterParticipant.getTypeFirstRep().getCodingFirstRep();
            if (!PARTICIPATION_TYPE_SYSTEM.equals(coding.getSystem())) {
                throw new FhirValidationException("Unsupported encounter participant system: " + coding.getSystem());
            }
            var code = coding.getCode();
            if ("AUT".equals(code)) {
                var author = mapAuthor1(bundle, encounterParticipant);
                finding.setAuthor(author);
            } else if ("INF".equals(code)) {
                var informant = mapInformant(bundle, encounterParticipant);
                finding.setInformant(informant);
            } else if ("PRF".equals(code)) {
                var performer = mapPerformer(bundle, encounterParticipant);
                finding.setPerformer(performer);
            } else {
                throw new FhirValidationException(String.format("Invalid encounter %s participant code %s", encounter.getId(), code));
            }
        }
    }
    return finding;
}
Also used : DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Coding(org.hl7.fhir.r4.model.Coding) Finding(uk.nhs.adaptors.scr.models.xml.Finding) Period(org.hl7.fhir.r4.model.Period) Encounter(org.hl7.fhir.r4.model.Encounter) FhirValidationException(uk.nhs.adaptors.scr.exceptions.FhirValidationException)

Example 3 with FhirValidationException

use of uk.nhs.adaptors.scr.exceptions.FhirValidationException in project summary-care-record-api by NHSDigital.

the class AcsRequestValidator method checkPermission.

private static void checkPermission(Parameters.ParametersParameterComponent parameter) {
    Coding coding = (Coding) parameter.getPart().stream().filter(p -> PERMISSION_CODE_PART_NAME.equals(p.getName())).filter(p -> PERMISSION_CODE_SYSTEM.equals(((Coding) p.getValue()).getSystem())).reduce((x, y) -> {
        throw new FhirValidationException(String.format("Exactly 1 Parameter.Part named '%s' with valueCoding.system %s expected", PERMISSION_CODE_PART_NAME, PERMISSION_CODE_SYSTEM));
    }).orElseThrow(() -> new FhirValidationException(String.format("Parameter.Part named '%s' with valueCoding.system %s not found", PERMISSION_CODE_PART_NAME, PERMISSION_CODE_SYSTEM))).getValue();
    String permissionValue = coding.getCode();
    try {
        AcsPermission.fromValue(permissionValue);
    } catch (Exception e) {
        LOGGER.error("Invalid permission value: " + permissionValue, e);
        throw new FhirValidationException(String.format("Invalid value - %s in field 'valueCoding.code'", permissionValue));
    }
}
Also used : ParametersParameterComponent(org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent) ConstraintValidator(javax.validation.ConstraintValidator) ConstraintValidatorContext(javax.validation.ConstraintValidatorContext) RequiredArgsConstructor(lombok.RequiredArgsConstructor) FhirValidationException(uk.nhs.adaptors.scr.exceptions.FhirValidationException) Autowired(org.springframework.beans.factory.annotation.Autowired) FhirParser(uk.nhs.adaptors.scr.components.FhirParser) AcsPermission(uk.nhs.adaptors.scr.models.AcsPermission) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) Coding(org.hl7.fhir.r4.model.Coding) StringUtils.isEmpty(org.springframework.util.StringUtils.isEmpty) Parameters(org.hl7.fhir.r4.model.Parameters) Coding(org.hl7.fhir.r4.model.Coding) FhirValidationException(uk.nhs.adaptors.scr.exceptions.FhirValidationException) FhirValidationException(uk.nhs.adaptors.scr.exceptions.FhirValidationException)

Example 4 with FhirValidationException

use of uk.nhs.adaptors.scr.exceptions.FhirValidationException in project summary-care-record-api by NHSDigital.

the class AcsRequestValidator method isValid.

@Override
public boolean isValid(String requestBody, ConstraintValidatorContext context) {
    try {
        Parameters parameters = fhirParser.parseResource(requestBody, Parameters.class);
        ParametersParameterComponent parameter = getSetPermissionParameter(parameters);
        checkNhsNumber(parameter);
        checkPermission(parameter);
    } catch (FhirValidationException exc) {
        setErrorMessage(context, exc.getMessage());
        return false;
    }
    return true;
}
Also used : Parameters(org.hl7.fhir.r4.model.Parameters) FhirValidationException(uk.nhs.adaptors.scr.exceptions.FhirValidationException) ParametersParameterComponent(org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent)

Example 5 with FhirValidationException

use of uk.nhs.adaptors.scr.exceptions.FhirValidationException in project summary-care-record-api by NHSDigital.

the class AlertRequestValidator method isValid.

@Override
public boolean isValid(String alert, ConstraintValidatorContext context) {
    try {
        AuditEvent auditEvent = fhirParser.parseResource(alert, AuditEvent.class);
        checkId(auditEvent);
        checkExtension(auditEvent);
        checkType(auditEvent.getType());
        checkSubtype(auditEvent.getSubtype());
        checkRecorded(auditEvent.getRecorded());
        checkSource(auditEvent.getSource());
        checkEntity(auditEvent.getEntity());
        checkPatient(auditEvent.getAgent());
        checkOrganization(auditEvent.getAgent());
        checkPerson(auditEvent.getAgent());
    } catch (FhirValidationException exc) {
        setErrorMessage(context, exc.getMessage());
        return false;
    }
    return true;
}
Also used : AuditEvent(org.hl7.fhir.r4.model.AuditEvent) FhirValidationException(uk.nhs.adaptors.scr.exceptions.FhirValidationException)

Aggregations

FhirValidationException (uk.nhs.adaptors.scr.exceptions.FhirValidationException)13 Coding (org.hl7.fhir.r4.model.Coding)8 Slf4j (lombok.extern.slf4j.Slf4j)4 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)4 PractitionerRole (org.hl7.fhir.r4.model.PractitionerRole)4 Optional (java.util.Optional)3 Bundle (org.hl7.fhir.r4.model.Bundle)3 NonAgentRole (uk.nhs.adaptors.scr.models.xml.NonAgentRole)3 DateUtil.formatDateToHl7 (uk.nhs.adaptors.scr.utils.DateUtil.formatDateToHl7)3 FhirHelper.getDomainResourceList (uk.nhs.adaptors.scr.utils.FhirHelper.getDomainResourceList)3 FhirHelper.getResourceByReference (uk.nhs.adaptors.scr.utils.FhirHelper.getResourceByReference)3 Collectors (java.util.stream.Collectors)2 StringUtils (org.apache.commons.lang3.StringUtils)2 StringUtils.isNotEmpty (org.apache.commons.lang3.StringUtils.isNotEmpty)2 ContactPoint (org.hl7.fhir.r4.model.ContactPoint)2 MANUFACTURERNAME (org.hl7.fhir.r4.model.Device.DeviceNameType.MANUFACTURERNAME)2 OTHER (org.hl7.fhir.r4.model.Device.DeviceNameType.OTHER)2 EncounterParticipantComponent (org.hl7.fhir.r4.model.Encounter.EncounterParticipantComponent)2 HumanName (org.hl7.fhir.r4.model.HumanName)2 Identifier (org.hl7.fhir.r4.model.Identifier)2