use of org.hl7.fhir.r5.model.Meta in project cqf-ruler by DBCG.
the class ProcessMessageProvider method processMessageBundle.
@Operation(name = "$process-message-bundle", idempotent = false)
public Bundle processMessageBundle(HttpServletRequest theServletRequest, RequestDetails theRequestDetails, @OperationParam(name = "content", min = 1, max = 1) @Description(formalDefinition = "The message to process (or, if using asynchronous messaging, it may be a response message to accept)") Bundle theMessageToProcess) {
logger.info("Validating the Bundle");
Bundle bundle = theMessageToProcess;
Boolean errorExists = false;
OperationOutcome outcome = validateBundle(errorExists, bundle);
if (!errorExists) {
IVersionSpecificBundleFactory bundleFactory = this.getFhirContext().newBundleFactory();
bundle.setId(getUUID());
bundleFactory.initializeWithBundleResource(bundle);
Bundle dafBundle = (Bundle) bundleFactory.getResourceBundle();
dafBundle.setTimestamp(new Date());
this.getDaoRegistry().getResourceDao(Bundle.class).create(dafBundle);
MessageHeader messageHeader = null;
String patientId = null;
String commId = null;
List<MessageHeader> headers = BundleUtil.toListOfResourcesOfType(this.getFhirContext(), bundle, MessageHeader.class);
for (MessageHeader mh : headers) {
messageHeader = mh;
messageHeader.setId(getUUID());
Meta meta = messageHeader.getMeta();
meta.setLastUpdated(new Date());
messageHeader.setMeta(meta);
}
List<IBaseResource> resources = new ArrayList<>();
List<Patient> patients = BundleUtil.toListOfResourcesOfType(this.getFhirContext(), bundle, Patient.class);
for (Patient p : patients) {
patientId = p.getId();
p.setId(p.getIdElement().toVersionless());
resources.add(p);
}
List<Bundle> bundles = BundleUtil.toListOfResourcesOfType(this.getFhirContext(), bundle, Bundle.class);
for (Bundle b : bundles) {
patientId = this.processBundle(b, theRequestDetails);
b.setId(b.getIdElement().toVersionless());
resources.add(b);
}
for (BundleEntryComponent e : bundle.getEntry()) {
Resource r = e.getResource();
if (r == null) {
continue;
}
if (r.fhirType().equals("Bundle") || r.fhirType().equals("MessageHeader") || r.fhirType().equals("Patient")) {
continue;
}
r.setId(r.getIdElement().toVersionless());
resources.add(r);
}
if (patientId != null) {
commId = constructAndSaveCommunication(patientId);
}
if (messageHeader == null) {
messageHeader = constructMessageHeaderResource();
BundleEntryComponent entryComp = new BundleEntryComponent();
entryComp.setResource(messageHeader);
dafBundle.addEntry(entryComp);
}
if (commId != null) {
List<Reference> referenceList = new ArrayList<>();
Reference commRef = new Reference();
commRef.setReference("Communication/" + commId);
referenceList.add(commRef);
messageHeader.setFocus(referenceList);
}
IVersionSpecificBundleFactory newBundleFactory = this.getFhirContext().newBundleFactory();
newBundleFactory.addResourcesToBundle(resources, BundleTypeEnum.TRANSACTION, theRequestDetails.getFhirServerBase(), null, null);
Bundle transactionBundle = (Bundle) newBundleFactory.getResourceBundle();
for (BundleEntryComponent entry : transactionBundle.getEntry()) {
UriType uri = new UriType(theRequestDetails.getFhirServerBase() + "/" + entry.getResource().fhirType() + "/" + entry.getResource().getIdElement().getIdPart());
Enumeration<HTTPVerb> method = new Enumeration<>(new HTTPVerbEnumFactory());
method.setValue(HTTPVerb.PUT);
entry.setRequest(new BundleEntryRequestComponent(method, uri));
}
@SuppressWarnings("unchecked") IFhirSystemDao<Bundle, Meta> fhirSystemDao = this.getDaoRegistry().getSystemDao();
fhirSystemDao.transaction(theRequestDetails, transactionBundle);
return dafBundle;
} else {
BundleEntryComponent entryComp = new BundleEntryComponent();
entryComp.setResource(outcome);
bundle.addEntry(entryComp);
return bundle;
}
}
use of org.hl7.fhir.r5.model.Meta in project cqf-ruler by DBCG.
the class ReportProvider method patientReport.
private Parameters.ParametersParameterComponent patientReport(Patient thePatient, Period thePeriod, String serverBase) {
String patientId = thePatient.getIdElement().getIdPart();
final Map<IIdType, IAnyResource> bundleEntries = new HashMap<>();
bundleEntries.put(thePatient.getIdElement(), thePatient);
ReferenceParam subjectParam = new ReferenceParam(patientId);
search(MeasureReport.class, Searches.byParam("subject", subjectParam)).getAllResourcesTyped().forEach(measureReport -> {
if (measureReport.getPeriod().getEnd().before(thePeriod.getStart()) || measureReport.getPeriod().getStart().after(thePeriod.getEnd())) {
return;
}
bundleEntries.putIfAbsent(measureReport.getIdElement(), measureReport);
getEvaluatedResources(measureReport).values().forEach(resource -> bundleEntries.putIfAbsent(resource.getIdElement(), resource));
});
Bundle patientReportBundle = new Bundle();
patientReportBundle.setMeta(new Meta().addProfile(PATIENT_REPORT_PROFILE_URL));
patientReportBundle.setType(Bundle.BundleType.COLLECTION);
patientReportBundle.setTimestamp(new Date());
patientReportBundle.setId(patientId + "-report");
patientReportBundle.setIdentifier(new Identifier().setSystem("urn:ietf:rfc:3986").setValue("urn:uuid:" + UUID.randomUUID().toString()));
bundleEntries.entrySet().forEach(resource -> patientReportBundle.addEntry(new Bundle.BundleEntryComponent().setResource((Resource) resource.getValue()).setFullUrl(Operations.getFullUrl(serverBase, resource.getValue().fhirType(), resource.getValue().getIdElement().getIdPart()))));
Parameters.ParametersParameterComponent patientParameter = new Parameters.ParametersParameterComponent();
patientParameter.setResource(patientReportBundle);
patientParameter.setId(thePatient.getIdElement().getIdPart() + "-report");
patientParameter.setName("return");
return patientParameter;
}
use of org.hl7.fhir.r5.model.Meta in project cqf-ruler by DBCG.
the class CareGapsProvider method initializeReport.
private void initializeReport(MeasureReport report) {
if (Strings.isNullOrEmpty(report.getId())) {
IIdType id = Ids.newId(MeasureReport.class, UUID.randomUUID().toString());
report.setId(id);
}
Reference reporter = new Reference().setReference(crProperties.getMeasureReport().getReporter());
// TODO: figure out what this extension is for
// reporter.addExtension(new
// Extension().setUrl(CARE_GAPS_MEASUREREPORT_REPORTER_EXTENSION));
report.setReporter(reporter);
if (report.hasMeta()) {
report.getMeta().addProfile(CARE_GAPS_REPORT_PROFILE);
} else {
report.setMeta(new Meta().addProfile(CARE_GAPS_REPORT_PROFILE));
}
}
use of org.hl7.fhir.r5.model.Meta in project quality-measure-and-cohort-service by Alvearie.
the class CDMMeasureEvaluationTest method testSetReportMeasureToMeasureId__includesMetaVersion__hasHistoryInMeasureOnReport.
@Test
public void testSetReportMeasureToMeasureId__includesMetaVersion__hasHistoryInMeasureOnReport() {
MeasureReport report = new MeasureReport();
String measureInput = "{\"resourceType\":\"Measure\",\"id\":\"id1\",\"meta\":{\"versionId\":\"2\"}}";
Measure measure = fhirParser.parseResource(Measure.class, measureInput);
CDMMeasureEvaluation.setReportMeasureToMeasureId(report, measure);
assertEquals("Measure/id1/_history/2", report.getMeasure());
}
use of org.hl7.fhir.r5.model.Meta 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;
}
Aggregations