use of org.hl7.fhir.dstu3.model.Procedure in project elexis-server by elexis.
the class ServiceRequestTest method createServiceRequest.
@Test
public void createServiceRequest() {
Condition problem = new Condition();
problem.setCode(new CodeableConcept().addCoding(new Coding("http://hl7.org/fhir/sid/icpc-2", "A04", "Müdigkeit")));
problem.setSubject(new Reference("Patient/" + AllTests.getTestDatabaseInitializer().getPatient().getId()));
problem.addCategory().addCoding(new Coding(ConditionCategory.PROBLEMLISTITEM.getSystem(), ConditionCategory.PROBLEMLISTITEM.toCode(), ConditionCategory.PROBLEMLISTITEM.getDisplay()));
MethodOutcome problemOutcome = client.create().resource(problem).execute();
Encounter encounter = new Encounter();
EncounterParticipantComponent participant = new EncounterParticipantComponent();
participant.setIndividual(new Reference("Practitioner/" + TestDatabaseInitializer.getMandant().getId()));
encounter.addParticipant(participant);
encounter.setPeriod(new Period().setStart(AllTests.getDate(LocalDate.of(2016, Month.DECEMBER, 1).atStartOfDay())).setEnd(AllTests.getDate(LocalDate.of(2016, Month.DECEMBER, 1).atTime(23, 59, 59))));
encounter.setSubject(new Reference("Patient/" + AllTests.getTestDatabaseInitializer().getPatient().getId()));
encounter.addDiagnosis().setCondition(new Reference(new IdType(problem.getResourceType().name(), problemOutcome.getId().getIdPart())));
encounter.addType(new CodeableConcept().addCoding(new Coding("www.elexis.info/encounter/type", "struct", "structured enconter")));
MethodOutcome encounterOutcome = client.create().resource(encounter).execute();
assertNotNull(encounterOutcome);
assertTrue(encounterOutcome.getCreated());
assertNotNull(encounterOutcome.getId());
// add subjective to the encounter
Observation subjective = new Observation();
Narrative narrative = new Narrative();
String divEncodedText = "Subjective\nTest".replaceAll("(\r\n|\r|\n)", "<br />");
narrative.setDivAsString(divEncodedText);
subjective.setText(narrative);
subjective.setSubject(new Reference("Patient/" + AllTests.getTestDatabaseInitializer().getPatient().getId()));
subjective.addCategory().addCoding(new Coding(IdentifierSystem.ELEXIS_SOAP.getSystem(), ObservationCategory.SOAP_SUBJECTIVE.getCode(), ObservationCategory.SOAP_SUBJECTIVE.getLocalized()));
subjective.setEncounter(new Reference(new IdType(encounter.getResourceType().name(), encounterOutcome.getId().getIdPart())));
MethodOutcome subjectiveOutcome = client.create().resource(subjective).execute();
assertTrue(subjectiveOutcome.getCreated());
// add procedure request to encounter
ServiceRequest serviceRequest = new ServiceRequest();
narrative = new Narrative();
divEncodedText = "Procedure\nTest".replaceAll("(\r\n|\r|\n)", "<br />");
narrative.setDivAsString(divEncodedText);
serviceRequest.setText(narrative);
serviceRequest.setSubject(new Reference("Patient/" + AllTests.getTestDatabaseInitializer().getPatient().getId()));
serviceRequest.setEncounter(new Reference(new IdType(encounter.getResourceType().name(), encounterOutcome.getId().getIdPart())));
MethodOutcome outcome = client.create().resource(serviceRequest).execute();
assertNotNull(outcome);
assertTrue(outcome.getCreated());
assertNotNull(outcome.getId());
ServiceRequest readServiceRequest = client.read().resource(ServiceRequest.class).withId(outcome.getId()).execute();
assertNotNull(readServiceRequest);
assertEquals(outcome.getId().getIdPart(), readServiceRequest.getIdElement().getIdPart());
assertEquals(serviceRequest.getSubject().getReferenceElement().getIdPart(), readServiceRequest.getSubject().getReferenceElement().getIdPart());
assertEquals(serviceRequest.getEncounter().getReferenceElement().getIdPart(), readServiceRequest.getEncounter().getReferenceElement().getIdPart());
assertTrue(readServiceRequest.getText().getDivAsString().contains("Test"));
// check if the consultation text has been updated
// search by patient and date
Bundle results = client.search().forResource(Encounter.class).where(Encounter.PATIENT.hasId(AllTests.getTestDatabaseInitializer().getPatient().getId())).and(Encounter.DATE.exactly().day(AllTests.getDate(LocalDate.of(2016, Month.DECEMBER, 1).atStartOfDay()))).returnBundle(Bundle.class).execute();
assertNotNull(results);
List<BundleEntryComponent> entries = results.getEntry();
assertFalse(entries.isEmpty());
Encounter readEncounter = (Encounter) entries.get(0).getResource();
assertNotNull(readEncounter);
assertEquals(readEncounter.getIdElement().getIdPart(), encounterOutcome.getId().getIdPart());
List<Identifier> identifier = readEncounter.getIdentifier();
String consultationId = null;
for (Identifier id : identifier) {
if (id.getSystem().equals(IdentifierSystem.ELEXIS_CONSID.getSystem())) {
consultationId = id.getValue();
}
}
assertNotNull(consultationId);
Optional<IEncounter> behandlung = AllTests.getModelService().load(consultationId, IEncounter.class);
assertTrue(behandlung.isPresent());
assertTrue(behandlung.get().getVersionedEntry().getHead().contains("Procedure"));
}
use of org.hl7.fhir.dstu3.model.Procedure in project Gravity-SDOH-Exchange-RI by FHIR.
the class TaskPollingService method handleFinishedTask.
protected void handleFinishedTask(Bundle resultBundle, Task ehrTask, ServiceRequest ehrServiceRequest, Task cpTask, Endpoint endpoint) {
if (Task.TaskStatus.COMPLETED.equals(cpTask.getStatus())) {
ehrServiceRequest.setStatus(ServiceRequest.ServiceRequestStatus.COMPLETED);
resultBundle.addEntry(FhirUtil.createPutEntry(ehrServiceRequest));
}
// property.
if (Task.TaskStatus.COMPLETED.equals(cpTask.getStatus()) || Task.TaskStatus.CANCELLED.equals(cpTask.getStatus())) {
// Modify Task.output. If task output is of type resulting-activity and contains a Reference to a proper
// Procedure - copy output changing a Procedure reference to a local one.
List<TaskOutputComponent> cpOutputs = cpTask.getOutput().stream().filter(t -> t.getValue() instanceof CodeableConcept || (t.getValue() instanceof Reference && ((Reference) t.getValue()).getReferenceElement().getResourceType().equals(Procedure.class.getSimpleName()))).collect(Collectors.toList());
if (cpOutputs.size() == 0) {
log.warn("Not output of type 'http://hl7.org/fhir/us/sdoh-clinicalcare/CodeSystem/sdohcc-temporary-codes|resulting" + "-activity' with a reference to a proper Procedure is present in task with id '{}' at '{}'. " + "Expecting a reference to a Procedure resource.", cpTask.getIdElement().getIdPart(), endpoint.getAddress());
}
Map<String, Procedure> cpProcedureMap = getCpProcedures(cpOutputs, endpoint);
for (Task.TaskOutputComponent cpOutput : cpOutputs) {
Task.TaskOutputComponent ehrTaskOutput = cpOutput.copy();
if (cpOutput.getValue() instanceof Reference) {
Reference cpProcedureReference = (Reference) cpOutput.getValue();
String cpProcedureId = cpProcedureReference.getReferenceElement().getIdPart();
Procedure cpProcedure = cpProcedureMap.get(cpProcedureId);
// All Procedures have the same reason reference as ServiceRequest
Procedure resultProcedure = copyProcedure(cpProcedure, ehrTask.getFor(), ehrTask.getFocus(), ehrServiceRequest.getReasonReference());
resultProcedure.setId(IdType.newRandomUuid());
resultProcedure.addIdentifier().setSystem(endpoint.getAddress()).setValue(cpProcedureId);
// Add Procedure to result bundle
resultBundle.addEntry(FhirUtil.createPostEntry(resultProcedure));
ehrTaskOutput.setValue(FhirUtil.toReference(Procedure.class, resultProcedure.getIdElement().getIdPart(), cpProcedureReference.getDisplay()));
}
ehrTask.addOutput(ehrTaskOutput);
}
}
}
use of org.hl7.fhir.dstu3.model.Procedure in project Gravity-SDOH-Exchange-RI by FHIR.
the class OurTaskPollingService method handleFinishedTask.
protected void handleFinishedTask(Bundle resultBundle, Task task, ServiceRequest serviceRequest, Task ourTask) {
boolean isFinished = false;
if (TaskStatus.COMPLETED.equals(ourTask.getStatus())) {
serviceRequest.setStatus(ServiceRequest.ServiceRequestStatus.COMPLETED);
resultBundle.addEntry(FhirUtil.createPutEntry(serviceRequest));
isFinished = true;
} else if (TaskStatus.CANCELLED.equals(ourTask.getStatus()) || TaskStatus.REJECTED.equals(ourTask.getStatus()) || TaskStatus.FAILED.equals(ourTask.getStatus())) {
serviceRequest.setStatus(ServiceRequest.ServiceRequestStatus.REVOKED);
resultBundle.addEntry(FhirUtil.createPutEntry(serviceRequest));
isFinished = true;
}
// property.
if (isFinished) {
// Modify Task.output. If task output is of type resulting-activity and contains a Reference to a proper
// Procedure - copy output changing a Procedure reference to a local one.
List<TaskOutputComponent> ourTaskOutputs = ourTask.getOutput().stream().filter(t -> t.getValue() instanceof CodeableConcept || (t.getValue() instanceof Reference && ((Reference) t.getValue()).getReferenceElement().getResourceType().equals(Procedure.class.getSimpleName()))).collect(Collectors.toList());
if (ourTaskOutputs.size() == 0) {
log.warn("No output of type 'http://hl7.org/fhir/us/sdoh-clinicalcare/CodeSystem/sdohcc-temporary-codes|resulting" + "-activity' with a reference to a proper Procedure is present in task with id '{}'. " + "Expecting a reference to a Procedure resource.", ourTask.getIdElement().getIdPart());
}
Map<String, Procedure> ourProcedureMap = getOurTaskProcedures(ourTaskOutputs);
for (TaskOutputComponent ourTaskOutput : ourTaskOutputs) {
TaskOutputComponent taskOutput = ourTaskOutput.copy();
if (ourTaskOutput.getValue() instanceof Reference) {
Reference ourProcedureReference = (Reference) ourTaskOutput.getValue();
String ourProcedureId = ourProcedureReference.getReferenceElement().getIdPart();
Procedure ourProcedure = ourProcedureMap.get(ourProcedureId);
// All Procedures have the same reason reference as ServiceRequest
Procedure resultProcedure = copyProcedure(ourProcedure, task.getFor(), task.getFocus(), serviceRequest.getReasonReference());
resultProcedure.setId(IdType.newRandomUuid());
// TODO add identifier
// resultProcedure.addIdentifier()
// .setSystem(SERVER_BASE)
// .setValue(ourProcedureId);
// Add Procedure to result bundle
resultBundle.addEntry(FhirUtil.createPostEntry(resultProcedure));
taskOutput.setValue(FhirUtil.toReference(Procedure.class, resultProcedure.getIdElement().getIdPart(), ourProcedureReference.getDisplay()));
}
task.addOutput(taskOutput);
}
}
}
use of org.hl7.fhir.dstu3.model.Procedure in project Gravity-SDOH-Exchange-RI by FHIR.
the class TaskUpdateBundleFactory method createProceduresOutput.
private void createProceduresOutput(Bundle updateBundle) {
for (Coding code : procedureCodes) {
Procedure procedure = createProcedure(code);
updateBundle.addEntry(FhirUtil.createPostEntry(procedure));
Task.TaskOutputComponent taskOutput = createTaskOutput(FhirUtil.toReference(Procedure.class, procedure.getIdElement().getIdPart(), String.format("%s (%s)", code.getDisplay(), code.getCode())));
task.getOutput().add(taskOutput);
}
}
use of org.hl7.fhir.dstu3.model.Procedure in project org.hl7.fhir.core by hapifhir.
the class CCDAConverter method processProcedure.
protected void processProcedure(ListResource list, Element procedure, ProcedureType type) throws Exception {
switch(type) {
case Procedure:
cda.checkTemplateId(procedure, "2.16.840.1.113883.10.20.22.4.14");
break;
case Observation:
cda.checkTemplateId(procedure, "2.16.840.1.113883.10.20.22.4.13");
break;
case Act:
cda.checkTemplateId(procedure, "2.16.840.1.113883.10.20.22.4.12");
}
checkNoNegationOrNullFlavor(procedure, "Procedure (" + type + ")");
checkNoSubject(procedure, "Procedure (" + type + ")");
Procedure p = new Procedure();
addItemToList(list, p);
// moodCode is either INT or EVN. INT is not handled yet. INT is deprecated anyway
if (procedure.getAttribute("moodCode").equals("INT"))
p.getModifierExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-planned", Factory.newBoolean(true), false));
// SHALL contain at least one [1..*] id (CONF:7655).
for (Element e : cda.getChildren(procedure, "id")) p.getIdentifier().add(convert.makeIdentifierFromII(e));
// SHALL contain exactly one [1..1] code (CONF:7656).
// This code @code in a procedure activity SHOULD be selected from LOINC or SNOMED CT and MAY be selected from CPT-4, ICD9 Procedures, ICD10 Procedures
p.setCode(convert.makeCodeableConceptFromCD(cda.getChild(procedure, "code")));
// SHALL contain exactly one [1..1] statusCode/@code, which SHALL be selected from ValueSet 2.16.840.1.113883.11.20.9.22 ProcedureAct
// completed | active | aborted | cancelled - not in FHIR
p.getModifierExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-status", Factory.newCode(cda.getStatus(procedure)), false));
// SHOULD contain zero or one [0..1] effectiveTime (CONF:7662).
p.setPerformed(convert.makePeriodFromIVL(cda.getChild(procedure, "effectiveTime")));
// MAY contain zero or one [0..1] priorityCode/@code, which SHALL be selected from ValueSet 2.16.840.1.113883.1.11.16866 ActPriority DYNAMIC (CONF:7668)
p.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-priority", convert.makeCodeableConceptFromCD(cda.getChild(procedure, "priorityCode")), false));
// MAY contain zero or one [0..1] methodCode (CONF:7670).
p.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-method", convert.makeCodeableConceptFromCD(cda.getChild(procedure, "methodCode")), false));
if (type == ProcedureType.Observation) {
// for Procedure-Observation:
// 9. SHALL contain exactly one [1..1] value (CONF:16846).
// don't know what this is. It's not the actual result of the procedure (that goes in results "This section records ... procedure observations"), and there seems to be no value. The example as <value xsi:type="CD"/> which is not valid
// so we ignore this for now
}
// SHOULD contain zero or more [0..*] targetSiteCode/@code, which SHALL be selected from ValueSet 2.16.840.1.113883.3.88.12.3221.8.9 Body site DYNAMIC (CONF:7683).
for (Element e : cda.getChildren(procedure, "targetSiteCode")) p.addBodySite(convert.makeCodeableConceptFromCD(e));
// SHOULD contain zero or more [0..*] performer (CONF:7718) such that it
for (Element e : cda.getChildren(procedure, "performer")) {
ProcedurePerformerComponent pp = new ProcedurePerformerComponent();
p.getPerformer().add(pp);
pp.setActor(makeReferenceToPractitionerForAssignedEntity(e, p));
}
for (Element participant : cda.getChildren(procedure, "participant")) {
Element participantRole = cda.getlastChild(participant);
if (type == ProcedureType.Procedure && cda.hasTemplateId(participantRole, "2.16.840.1.113883.10.20.22.4.37")) {
// MAY contain zero or more [0..*] participant (CONF:7751) such that it SHALL contain exactly one [1..1] @typeCode="DEV" Device
// implanted devices
p.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/implanted-devices", Factory.makeReference(processDevice(participantRole, p)), false));
} else if (cda.hasTemplateId(participantRole, "2.16.840.1.113883.10.20.22.4.32")) {
// MAY contain zero or more [0..*] participant (CONF:7765) such that it SHALL contain exactly one [1..1] Service Delivery Location (templateId:2.16.840.1.113883.10.20.22.4.32) (CONF:7767)
p.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/location", Factory.makeReference(processSDLocation(participantRole, p)), false));
}
}
for (Element e : cda.getChildren(procedure, "entryRelationship")) {
Element a = /* act*/
cda.getlastChild(e);
if (a.getLocalName().equals("encounter")) {
// MAY contain zero or more [0..*] entryRelationship (CONF:7768) such that it SHALL contain exactly one encounter which SHALL contain exactly one [1..1] id (CONF:7773).
// todo - and process as a full encounter while we're at it
} else if (cda.hasTemplateId(a, "2.16.840.1.113883.10.20.22.4.20")) {
// MAY contain zero or one [0..1] entryRelationship (CONF:7775) such that it SHALL contain exactly one [1..1] Instructions (templateId:2.16.840.1.113883.10.20.22.4.20) (CONF:7778).
// had code for type, plus text for instructions
Extension n = Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-instructions", null, true);
n.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-instructions-type", convert.makeCodeableConceptFromCD(cda.getChild(a, "code")), false));
n.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-instructions-text", convert.makeStringFromED(cda.getChild(a, "text")), false));
p.getExtension().add(n);
} else if (cda.hasTemplateId(a, "2.16.840.1.113883.10.20.22.4.19")) {
// MAY contain zero or more [0..*] entryRelationship (CONF:7779) such that it SHALL contain exactly one [1..1] Indication (templateId:2.16.840.1.113883.10.20.22.4.19) (CONF:7781).
p.addReasonCode(processIndication(a));
} else if (cda.hasTemplateId(cda.getlastChild(e), "2.16.840.1.113883.10.20.22.4.16")) {
// MAY contain zero or one [0..1] entryRelationship (CONF:7886) such that it SHALL contain exactly one [1..1] Medication Activity (templateId:2.16.840.1.113883.10.20.22.4.16) (CONF:7888).
// todo
}
}
}
Aggregations