use of uk.nhs.adaptors.scr.models.xml.Diagnosis in project summary-care-record-api by NHSDigital.
the class ConditionMapper method mapDiagnosis.
private static Diagnosis mapDiagnosis(Condition condition, Bundle bundle) throws FhirMappingException {
var diagnosis = new Diagnosis();
diagnosis.setIdRoot(condition.getIdentifierFirstRep().getValue());
diagnosis.setCodeCode(condition.getCode().getCodingFirstRep().getCode());
diagnosis.setCodeDisplayName(condition.getCode().getCodingFirstRep().getDisplay());
diagnosis.setStatusCodeCode(mapStatus(condition));
if (condition.hasOnsetDateTimeType()) {
diagnosis.setEffectiveTimeLow(formatDateToHl7(condition.getOnsetDateTimeType()));
}
if (condition.hasOnsetPeriod()) {
Period period = condition.getOnsetPeriod();
diagnosis.setEffectiveTimeLow(formatDateToHl7(period.getStartElement()));
diagnosis.setEffectiveTimeHigh(formatDateToHl7(period.getEndElement()));
}
Optional.ofNullable(condition.getEvidenceFirstRep().getDetailFirstRep().getReference()).map(reference -> reference.split("/")[1]).ifPresent(diagnosis::setFindingId);
diagnosis.setSupportingInformation(condition.getNoteFirstRep().getText());
LOGGER.debug("Looking up Encounter for Condition.id={}", condition.getIdElement().getIdPart());
var encounterReference = condition.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", condition.getEncounter().getReference(), condition.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 = mapAuthor(bundle, encounterParticipant);
diagnosis.setAuthor(author);
} else if ("INF".equals(code)) {
var informant = mapInformant(bundle, encounterParticipant);
diagnosis.setInformant(informant);
} else {
throw new FhirValidationException(String.format("Invalid encounter %s participant code %s", encounter.getId(), code));
}
}
}
return diagnosis;
}
Aggregations