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