use of org.hl7.fhir.r4.model.Bundle.BundleType.DOCUMENT in project summary-care-record-api by NHSDigital.
the class DiagnosisMapper method map.
@SneakyThrows
public List<Resource> map(Node document) {
var resources = new ArrayList<Resource>();
NodeList pertinentNodes = xmlUtils.getNodeListByXPath(document, PERTINENT_CRET_BASE_PATH);
for (int i = 0; i < pertinentNodes.getLength(); i++) {
Node pertinentCREType = xmlUtils.getNodeAndDetachFromParent(pertinentNodes, i);
var pertinentCRETypeCode = xmlUtils.getValueByXPath(pertinentCREType, PERTINENT_CODE_CODE_XPATH);
var pertinentCRETypeDisplay = xmlUtils.getValueByXPath(pertinentCREType, PERTINENT_CODE_DISPLAY_XPATH);
NodeList diagnosisNodes = xmlUtils.getNodeListByXPath(pertinentCREType, DIAGNOSIS_BASE_PATH);
for (int j = 0; j < diagnosisNodes.getLength(); j++) {
Node node = xmlUtils.getNodeAndDetachFromParent(diagnosisNodes, j);
CodedEntry entry = codedEntryMapper.getCommonCodedEntryValues(node);
if (COVID_19_ENTRIES.contains(entry.getCodeValue())) {
var pertinentSupportingInfo = xmlUtils.getOptionalValueByXPath(node, DIAGNOSIS_PERTINENT_SUPPORTING_INFO_XPATH);
var condition = new Condition();
condition.setId(entry.getId());
condition.addIdentifier().setValue(entry.getId());
condition.setCode(new CodeableConcept().addCoding(new Coding().setCode(entry.getCodeValue()).setSystem(SNOMED_SYSTEM).setDisplay(entry.getCodeDisplay())));
setConditionStatus(condition, entry.getStatus());
condition.addCategory(new CodeableConcept(new Coding().setSystem(SNOMED_SYSTEM).setCode(pertinentCRETypeCode).setDisplay(pertinentCRETypeDisplay)));
if (entry.getEffectiveTimeHigh().isPresent()) {
condition.setOnset(entry.getEffectiveTimeLow().get());
condition.setAbatement(entry.getEffectiveTimeHigh().get());
} else {
condition.setOnset(entry.getEffectiveTimeLow().get());
}
resources.add(condition);
pertinentSupportingInfo.map(value -> new Annotation().setText(value)).ifPresent(condition::addNote);
xmlUtils.getNodesByXPath(node, DIAGNOSIS_PERTINENT_FINDINGS_XPATH).stream().map(it -> xmlUtils.getValueByXPath(it, DIAGNOSIS_PERTINENT_FINDING_ID_XPATH)).map(it -> new Reference(new Observation().setId(it))).map(reference -> new Condition.ConditionEvidenceComponent().addDetail(reference)).forEach(condition::addEvidence);
mapEncounter(node, condition, resources);
}
}
}
return resources;
}
use of org.hl7.fhir.r4.model.Bundle.BundleType.DOCUMENT in project summary-care-record-api by NHSDigital.
the class GpSummaryMapper method addAuthorOrganisation.
private void addAuthorOrganisation(Node document, List<Resource> resources, Composition composition) {
xmlUtils.detachOptionalNodeByXPath(document, GP_SUMMARY_AUTHOR_AGENT_ORG_SDS_XPATH).ifPresent(agentOrganisationSds -> {
Organization organisation = organisationSdsMapper.mapOrganizationSds(agentOrganisationSds);
resources.add(organisation);
composition.addAuthor(new Reference(organisation));
});
xmlUtils.detachOptionalNodeByXPath(document, GP_SUMMARY_AUTHOR_AGENT_ORG_XPATH).ifPresent(agentOrganisation -> {
List<? extends Resource> organisationResources = agentOrganisationMapper.map(agentOrganisation);
resources.addAll(organisationResources);
composition.addAuthor(findPractitionerRole(organisationResources));
});
}
use of org.hl7.fhir.r4.model.Bundle.BundleType.DOCUMENT in project summary-care-record-api by NHSDigital.
the class GpSummaryMapper method map.
@SneakyThrows
public List<Resource> map(Node document) {
var gpSummaryId = xmlUtils.getValueByXPath(document, GP_SUMMARY_ID_XPATH);
var gpSummaryCodeCode = xmlUtils.getValueByXPath(document, GP_SUMMARY_CODE_CODE_XPATH);
var gpSummaryCodeDisplayName = xmlUtils.getValueByXPath(document, GP_SUMMARY_CODE_DISPLAY_NAME_XPATH);
var gpSummaryStatusCode = xmlUtils.getValueByXPath(document, GP_SUMMARY_STATUS_CODE_XPATH);
var gpSummaryEffectiveTime = parseDate(xmlUtils.getValueByXPath(document, GP_SUMMARY_EFFECTIVE_TIME_XPATH), InstantType.class);
var authorTime = parseDate(xmlUtils.getValueByXPath(document, GP_SUMMARY_AUTHOR_TIME_XPATH), DateTimeType.class);
var replacementOfPriorMessageRefIdRoot = xmlUtils.getOptionalValueByXPath(document, REPLACEMENT_OF_PRIOR_MESSAGE_REF_ID_ROOT_XPATH);
var pertinentRootCreTypeCodeCode = xmlUtils.getValueByXPath(document, PERTINENT_ROOT_CRE_TYPE_CODE_CODE_XPATH);
var pertinentRootCreTypeCodeDisplayName = xmlUtils.getValueByXPath(document, PERTINENT_ROOT_CRE_TYPE_CODE_DISPLAY_NAME_XPATH);
var presentationTextValue = xmlUtils.detachOptionalNodeByXPath(document, PRESENTATION_TEXT_VALUE);
var eventId = xmlUtils.getValueByXPath(document, EVENT_ID_XPATH);
List<Resource> resources = new ArrayList<>();
var composition = new Composition();
composition.setId(eventId);
composition.setIdentifier(new Identifier().setValue(gpSummaryId).setSystem("https://tools.ietf.org/html/rfc4122"));
composition.setType(new CodeableConcept().addCoding(new Coding().setCode(gpSummaryCodeCode).setSystem(SNOMED_SYSTEM).setDisplay(gpSummaryCodeDisplayName)));
composition.setMeta(new Meta().setLastUpdatedElement(gpSummaryEffectiveTime));
composition.setStatus(mapCompositionStatus(gpSummaryStatusCode));
composition.setDateElement(authorTime);
replacementOfPriorMessageRefIdRoot.ifPresent(val -> composition.addRelatesTo(new Composition.CompositionRelatesToComponent().setTarget(new Identifier().setValue(val)).setCode(REPLACES)));
composition.addCategory(new CodeableConcept().addCoding(new Coding().setCode(pertinentRootCreTypeCodeCode).setSystem(SNOMED_SYSTEM).setDisplay(pertinentRootCreTypeCodeDisplayName)));
Map<String, List<String>> references = sectionReferences(document);
presentationTextValue.map(htmlParser::parse).map(Collection::stream).ifPresent(it -> it.forEach(section -> {
if (section.getTitle() != null && CODED_ENTRY_RESOURCE_MAP.keySet().contains(section.getTitle()) && references.containsKey(section.getTitle())) {
for (String codedEntryId : references.get(section.getTitle())) {
section.addEntry(new Reference(CODED_ENTRY_RESOURCE_MAP.get(section.getTitle()) + "/" + codedEntryId));
}
}
composition.addSection(section);
}));
resources.add(composition);
addAuthor(document, resources, composition);
return resources;
}
use of org.hl7.fhir.r4.model.Bundle.BundleType.DOCUMENT in project summary-care-record-api by NHSDigital.
the class AcsService method setPermission.
public void setPermission(RequestData requestData) {
Parameters parameters = fhirParser.parseResource(requestData.getBody(), Parameters.class);
ParametersParameterComponent parameter = getSetPermissionParameter(parameters);
UserInfo userInfo = identityService.getUserInfo(requestData.getAuthorization());
String acsRequest = prepareAcsRequest(parameter, requestData, getUserRoleCode(userInfo, requestData.getNhsdSessionUrid()), userInfo.getId());
Response<Document> response = spineClient.sendAcsData(acsRequest, requestData.getNhsdAsid());
spineDetectedIssuesHandler.handleDetectedIssues(spineResponseParser.getDetectedIssues(response.getBody()));
}
use of org.hl7.fhir.r4.model.Bundle.BundleType.DOCUMENT in project summary-care-record-api by NHSDigital.
the class GetScrService method getScr.
@LogExecutionTime
public Bundle getScr(String nhsNumber, String compositionId, String nhsdAsid, String clientIp) {
Document scrIdXml = getScrIdRawXml(nhsNumber, nhsdAsid, clientIp);
checkDetectedIssues(scrIdXml);
EventListQueryResponse response = eventListQueryResponseParser.parseXml(scrIdXml);
if (StringUtils.equals(response.getLatestScrId(), compositionId)) {
Document document = getScrRawXml(response.getLatestScrId(), nhsNumber, nhsdAsid, clientIp);
logXml("Received SCR XML: {}", document);
checkDetectedIssues(document);
var bundle = interactionMapper.map(document);
Patient patient = recordTargetMapper.mapPatient(document);
Stream.of(gpSummaryMapper, diagnosisMapper, findingMapper).map(mapper -> mapper.map(document)).flatMap(resources -> resources.stream()).peek(it -> setPatientReferences(it, patient)).map(resource -> getBundleEntryComponent(resource)).forEach(bundle::addEntry);
bundle.addEntry(getBundleEntryComponent(patient));
bundle.setTotal(bundle.getEntry().size());
return bundle;
} else {
return interactionMapper.mapToEmpty();
}
}
Aggregations