Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added provision to update encounter location on the FHIR Task resource #42

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public Task createOrder(Order order) throws OrderCreationException {
mappedTestsExist = true;
}
}

if (!mappedTestsExist && config.filterOrderByTestUuuids()) {
return null;
}
Expand Down Expand Up @@ -85,26 +85,31 @@ public Task createOrder(Order order) throws OrderCreationException {
// Create References
List<Reference> basedOnRefs = Collections.singletonList(
newReference(order.getUuid(), FhirConstants.SERVICE_REQUEST));

Reference forReference = newReference(order.getPatient().getUuid(), FhirConstants.PATIENT);

Reference ownerRef = newReference(config.getLisUserUuid(), FhirConstants.PRACTITIONER);

Reference encounterRef = newReference(order.getEncounter().getUuid(), FhirConstants.ENCOUNTER);

Optional<EncounterProvider> requesterProvider = order.getEncounter().getActiveEncounterProviders().stream()
.findFirst();

Reference requesterRef = requesterProvider.map(
encounterProvider -> newReference(encounterProvider.getUuid(), FhirConstants.PRACTITIONER)).orElse(null);


Reference locationRef = null;
if (order.getEncounter().getLocation() != null) {
locationRef = newReference(order.getEncounter().getLocation().getUuid(), FhirConstants.LOCATION);
}

// Create Task Resource for given Order
Task newTask = createTask(basedOnRefs, forReference, ownerRef, encounterRef ,taskInputs);
Task newTask = createTask(basedOnRefs, forReference, ownerRef, encounterRef, locationRef ,taskInputs);

if (order.getEncounter().getActiveEncounterProviders().isEmpty()) {
newTask.setRequester(requesterRef);
}

// Save the new Task Resource
try {
newTask = taskService.create(newTask);
Expand All @@ -116,14 +121,15 @@ public Task createOrder(Order order) throws OrderCreationException {
}

private Task createTask(List<Reference> basedOnRefs, Reference forReference, Reference ownerRef,
Reference encounterRef ,List<Task.ParameterComponent> taskInputs) {
Reference encounterRef, Reference locationRef ,List<Task.ParameterComponent> taskInputs) {
Task newTask = new Task();
newTask.setStatus(Task.TaskStatus.REQUESTED);
newTask.setIntent(Task.TaskIntent.ORDER);
newTask.setBasedOn(basedOnRefs);
newTask.setFor(forReference);
newTask.setOwner(ownerRef);
newTask.setEncounter(encounterRef);
newTask.setLocation(locationRef);
if (taskInputs != null) {
newTask.setInput(taskInputs);
}
Expand Down Expand Up @@ -171,9 +177,9 @@ public Task createOrder(Encounter encounter) throws OrderCreationException {
taskInputs.add(input);
}
}

// Create Task Resource for given Order
Task newTask = createTask(basedOnRefs, forReference, ownerRef, encounterRef ,taskInputs);
Task newTask = createTask(basedOnRefs, forReference, ownerRef, encounterRef, locationRef ,taskInputs);
newTask.setLocation(locationRef);

if (!encounter.getActiveEncounterProviders().isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,14 @@ public Bundle createLabBundle(Task task) {
includes.add(new Include("Task:owner"));
includes.add(new Include("Task:encounter"));
includes.add(new Include("Task:based-on"));
includes.add(new Include("Task:location"));

IBundleProvider labBundle = fhirTaskService.searchForTasks(new TaskSearchParams(null, null, null, uuid, null, null, includes));

Bundle transactionBundle = new Bundle();
transactionBundle.setType(Bundle.BundleType.TRANSACTION);
List<IBaseResource> labResources = labBundle.getAllResources();
if (!task.getLocation().isEmpty() && config.getLabUpdateTriggerObject().equals("Encounter")) {
if (!task.getLocation().isEmpty()) {
labResources.add(fhirLocationService.get(FhirUtils.referenceToId(task.getLocation().getReference()).get()));
}
for (IBaseResource r : labResources) {
Expand Down
Loading