use of org.hl7.fhir.r5.model.Task in project Gravity-SDOH-Exchange-RI by FHIR.
the class CpService method create.
public void create(final Task ehrTask, final Endpoint endpoint) throws CpClientException {
Task cpTask = externalizeResource(ehrTask.copy(), identifierSystem);
// TODO: Remove this after Logica bug response
cpTask.setMeta(null);
cpTask.addIdentifier().setSystem(identifierSystem).setValue(ehrTask.getIdElement().getIdPart());
try {
cpClient(endpoint).create().resource(cpTask).execute();
} catch (BaseServerResponseException exc) {
throw new CpClientException(String.format("Could not create a Task with identifier '%s' in CP at '%s'. Reason: %s.", identifierSystem + "|" + ehrTask.getIdElement().getIdPart(), endpoint.getAddress(), exc.getMessage()), exc);
}
}
use of org.hl7.fhir.r5.model.Task in project Gravity-SDOH-Exchange-RI by FHIR.
the class CpService method read.
public TaskInfoHolder read(final String id, final Endpoint endpoint) throws CpClientException {
try {
Bundle taskBundle = cpClient(endpoint).search().forResource(Task.class).where(Task.IDENTIFIER.exactly().systemAndValues(identifierSystem, id)).include(Task.INCLUDE_FOCUS).returnBundle(Bundle.class).execute();
// Additional validation
int tasksSize = FhirUtil.getFromBundle(taskBundle, Task.class).size();
if (tasksSize == 0) {
throw new CpClientException(String.format("No Task is present at '%s' for identifier '%s'.", endpoint.getAddress(), identifierSystem + "|" + id));
} else if (tasksSize > 1) {
throw new CpClientException(String.format("More than one Task is present at '%s' for identifier '%s'.", endpoint.getAddress(), identifierSystem + "|" + id));
}
return new TaskInfoBundleExtractor().extract(taskBundle).stream().findFirst().get();
} catch (BaseServerResponseException exc) {
throw new CpClientException(String.format("Task retrieval failed for identifier '%s' at CP location '%s'. Reason: %s.", identifierSystem + "|" + id, endpoint.getAddress(), exc.getMessage()), exc);
}
}
use of org.hl7.fhir.r5.model.Task in project Gravity-SDOH-Exchange-RI by FHIR.
the class GoalService method addTasksAndSRsToGoalBundle.
// TODO refactor. this fragmet ins used in a ProblemService as well.
private Bundle addTasksAndSRsToGoalBundle(Bundle responseBundle) {
Bundle tasksWithServiceRequests = new TaskQueryFactory().query(ehrClient, SmartOnFhirContext.get().getPatient()).include(Task.INCLUDE_FOCUS).returnBundle(Bundle.class).execute();
if (tasksWithServiceRequests.getLink(IBaseBundle.LINK_NEXT) != null) {
throw new RuntimeException("Multi-page Task results returned for the List Problems operation. Pagination not supported yet. Make sure " + "there is a small amount of tasks in your FHIR store.");
}
Bundle merged = FhirUtil.mergeBundles(ehrClient.getFhirContext(), responseBundle, tasksWithServiceRequests);
return merged;
}
use of org.hl7.fhir.r5.model.Task in project Gravity-SDOH-Exchange-RI by FHIR.
the class PatientTaskService method addQuestionnaireResponsesToTaskBundle.
private void addQuestionnaireResponsesToTaskBundle(Bundle responseBundle) {
FhirUtil.getFromBundle(responseBundle, Task.class, Bundle.SearchEntryMode.MATCH).stream().filter(Task::hasOutput).flatMap(t -> t.getOutput().stream()).forEach(c -> {
Coding coding = FhirUtil.findCoding(Lists.newArrayList(c.getType()), SDCTemporaryCode.SYSTEM, SDCTemporaryCode.QUESTIONNAIRE_RESPONSE.getCode());
if (coding != null) {
String questionnaireResponseId = ((Reference) c.getValue()).getReferenceElement().getIdPart();
Bundle questionnaireResponse = ehrClient.search().forResource(QuestionnaireResponse.class).where(BaseResource.RES_ID.exactly().codes(questionnaireResponseId)).returnBundle(Bundle.class).execute();
FhirUtil.mergeBundles(ehrClient.getFhirContext(), responseBundle, questionnaireResponse);
}
});
}
use of org.hl7.fhir.r5.model.Task in project Gravity-SDOH-Exchange-RI by FHIR.
the class PatientTaskService method update.
public void update(String id, UpdateTaskRequestDto update, UserDto user) {
Task task = ehrClient.read().resource(Task.class).withId(id).execute();
if (task == null) {
throw new ResourceNotFoundException(new IdType(Task.class.getSimpleName(), id));
}
PatientTaskUpdateBundleFactory updateBundleFactory = new PatientTaskUpdateBundleFactory();
updateBundleFactory.setTask(task);
updateBundleFactory.setStatus(update.getFhirStatus());
updateBundleFactory.setStatusReason(update.getStatusReason());
updateBundleFactory.setComment(update.getComment());
updateBundleFactory.setUser(user);
ehrClient.transaction().withBundle(updateBundleFactory.createUpdateBundle()).execute();
}
Aggregations