use of uk.nhs.adaptors.scr.exceptions.FhirMappingException in project summary-care-record-api by NHSDigital.
the class BundleMapper method map.
@LogExecutionTime
public String map(Bundle bundle, String nhsdAsid) {
try {
GpSummary gpSummary = GpSummary.fromBundle(bundle, nhsdAsid);
gpSummary.setPartyIdFrom(scrConfiguration.getPartyIdFrom());
gpSummary.setPartyIdTo(scrConfiguration.getPartyIdTo());
gpSummary.setNhsdAsidTo(scrConfiguration.getNhsdAsidTo());
return TemplateUtils.fillTemplate(REPC_RM150007UK05_TEMPLATE, gpSummary);
} catch (Exception ex) {
throw new FhirMappingException(ex.getMessage());
}
}
use of uk.nhs.adaptors.scr.exceptions.FhirMappingException in project summary-care-record-api by NHSDigital.
the class CompositionMapper method setPresentation.
private static void setPresentation(GpSummary gpSummary, Composition composition) throws FhirMappingException {
if (!composition.hasSection()) {
throw new FhirMappingException("Missing mandatory Composition.section");
}
Presentation presentation = new Presentation();
var htmlDocument = createNewDocument("html", "xhtml:NPfIT:PresentationText");
var bodyNode = htmlDocument.createElement("body");
htmlDocument.getDocumentElement().appendChild(bodyNode);
for (Composition.SectionComponent section : composition.getSection()) {
var h2Node = htmlDocument.createElement("h2");
h2Node.setAttribute("id", section.getCode().getCodingFirstRep().getCode());
h2Node.appendChild(htmlDocument.createTextNode(section.getTitle()));
bodyNode.appendChild(h2Node);
var divDocument = parseDocument(section.getText().getDiv().getValueAsString());
removeEmptyNodes(divDocument);
var divChildNodes = divDocument.getDocumentElement().getChildNodes();
for (int i = 0; i < divChildNodes.getLength(); i++) {
bodyNode.appendChild(htmlDocument.importNode(divChildNodes.item(i), true));
}
}
presentation.setPresentationId(randomUUID());
presentation.setPresentationText(serialize(htmlDocument));
gpSummary.setPresentation(presentation);
}
use of uk.nhs.adaptors.scr.exceptions.FhirMappingException 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