Search in sources :

Example 6 with FhirValidationException

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

the class AlertRequestValidator method checkSubtype.

private void checkSubtype(List<Coding> subtypes) {
    if (subtypes.size() != 1) {
        throw new FhirValidationException("Expecting exactly one 'subtype' element");
    }
    Coding subtype = subtypes.get(0);
    if (!SUBTYPE_SYSTEM.equals(subtype.getSystem())) {
        throw new FhirValidationException("Invalid or missing value in field 'subtype.system'. Supported value is: " + SUBTYPE_SYSTEM);
    }
    if (!SUBTYPE_CODES.contains(subtype.getCode())) {
        throw new FhirValidationException("Invalid or missing value in field 'subtype.code'. Supported values are: " + SUBTYPE_CODES.stream().collect(joining(", ")));
    }
    checkNotEmpty(subtype.getDisplay(), "Missing value 'subtype.display'");
}
Also used : Coding(org.hl7.fhir.r4.model.Coding) FhirValidationException(uk.nhs.adaptors.scr.exceptions.FhirValidationException)

Example 7 with FhirValidationException

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

the class ParticipantAgentMapper method mapAuthor1.

public static Participant.Author1 mapAuthor1(Bundle bundle, EncounterParticipantComponent encounterParticipant) {
    var author = new Participant.Author1();
    author.setTime(formatDateToHl7(encounterParticipant.getPeriod().getStartElement()));
    var practitionerRoleReference = encounterParticipant.getIndividual().getReference();
    var practitionerRole = getResourceByReference(bundle, practitionerRoleReference, PractitionerRole.class).orElseThrow(() -> new FhirValidationException(String.format("Bundle is missing PractitionerRole %s that is linked to Encounter", practitionerRoleReference)));
    if (StringUtils.isNotBlank(practitionerRole.getOrganization().getReference())) {
        setAgentDevice(bundle, practitionerRole.getOrganization(), author);
    } else if (StringUtils.isNotBlank(practitionerRole.getPractitioner().getReference())) {
        setParticipantAgents(bundle, practitionerRole.getPractitioner(), author);
    }
    return author;
}
Also used : PractitionerRole(org.hl7.fhir.r4.model.PractitionerRole) FhirValidationException(uk.nhs.adaptors.scr.exceptions.FhirValidationException)

Example 8 with FhirValidationException

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

the class ParticipantAgentMapper method setDeviceCoding.

private static void setDeviceCoding(org.hl7.fhir.r4.model.Device fhirDevice, Device agentDevice1) {
    CodeableConcept type = fhirDevice.getType();
    Coding coding = type.getCodingFirstRep();
    if (!type.isEmpty() && isNotEmpty(coding.getCode()) && isNotEmpty(coding.getDisplay())) {
        agentDevice1.setCodeCode(coding.getCode());
        agentDevice1.setCodeDisplayName(coding.getDisplay());
    } else {
        throw new FhirValidationException("Missing mandatory elements: Device.type");
    }
}
Also used : Coding(org.hl7.fhir.r4.model.Coding) FhirValidationException(uk.nhs.adaptors.scr.exceptions.FhirValidationException) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 9 with FhirValidationException

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

the class ParticipantAgentMapper method setRelationship.

private static void setRelationship(RelatedPerson relatedPerson, NonAgentRole participantNonAgentRole) {
    Coding relationshipCoding = relatedPerson.getRelationshipFirstRep().getCodingFirstRep();
    if (!RELATIONSHIP_TYPE_SYSTEM.equals(relationshipCoding.getSystem())) {
        throw new FhirValidationException("Unsupported RelatedPerson.relationship.coding.system: " + relationshipCoding.getSystem());
    }
    if (!relationshipCoding.hasCode()) {
        throw new FhirValidationException("Missing RelatedPerson.relationship.coding.code element");
    }
    if (!relationshipCoding.hasDisplay()) {
        throw new FhirValidationException("Missing RelatedPerson.relationship.coding.display element");
    }
    participantNonAgentRole.setCodeCode(relationshipCoding.getCode());
    participantNonAgentRole.setCodeDisplayName(relationshipCoding.getDisplay());
}
Also used : Coding(org.hl7.fhir.r4.model.Coding) FhirValidationException(uk.nhs.adaptors.scr.exceptions.FhirValidationException)

Example 10 with FhirValidationException

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

the class PatientMapper method mapPatient.

public static void mapPatient(GpSummary gpSummary, Bundle bundle) throws FhirMappingException {
    Patient patient = getDomainResource(bundle, Patient.class);
    setPatientIds(gpSummary, patient);
    var composition = getDomainResource(bundle, Composition.class);
    if (!composition.hasSubject() || !patient.getId().contains(composition.getSubject().getReference())) {
        throw new FhirValidationException("Composition.subject reference is missing or invalid");
    }
}
Also used : Patient(org.hl7.fhir.r4.model.Patient) 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