use of org.hl7.fhir.r4.model.codesystems.TaskCode in project Gravity-SDOH-Exchange-RI by FHIR.
the class TaskValidator method validate.
public List<String> validate(Task task) {
List<String> errors = new ArrayList<>();
if (task.hasIdentifier() && task.getIdentifier().size() != 1) {
errors.add("Task.identifier is not valid.");
}
if (!task.getIntent().equals(Task.TaskIntent.ORDER)) {
errors.add(String.format("Task.intent has wrong value. Supported value is '%s'.", Task.TaskIntent.ORDER.toCode()));
}
TaskCode taskCode = TaskCode.FULFILL;
if (task.getCode().getCoding().stream().noneMatch(coding -> taskCode.getSystem().equals(coding.getSystem()) && taskCode.toCode().equals(coding.getCode()) && taskCode.getDisplay().equals(coding.getDisplay()))) {
errors.add(String.format("Task.code has no coding with system '%s' and code '%s'.", taskCode.getSystem(), taskCode.toCode()));
}
if (!task.hasFocus()) {
errors.add("Task.focus is missing.");
}
if (!task.hasFor()) {
errors.add("Task.for is missing.");
}
if (task.hasFor() && !task.getFor().getReferenceElement().getResourceType().equals(Patient.class.getSimpleName())) {
errors.add(String.format("Task.for reference is invalid. Supported reference is '%s'.", Patient.class.getSimpleName()));
}
if (task.hasRequester() && !task.getRequester().getReferenceElement().getResourceType().equals(Organization.class.getSimpleName())) {
errors.add(String.format("Task.requester reference is invalid. Supported reference is '%s'.", Organization.class.getSimpleName()));
}
if (task.hasOwner() && !task.getOwner().getReferenceElement().getResourceType().equals(Organization.class.getSimpleName())) {
errors.add(String.format("Task.owner reference is invalid. Supported reference is '%s'.", Organization.class.getSimpleName()));
}
return errors;
}
use of org.hl7.fhir.r4.model.codesystems.TaskCode in project Gravity-SDOH-Exchange-RI by FHIR.
the class TaskBundleFactory method createTask.
protected Task createTask(ServiceRequest serviceRequest) {
Task task = new Task();
task.getMeta().addProfile(SDOHProfiles.TASK);
task.setStatus(Task.TaskStatus.REQUESTED);
task.setIntent(Task.TaskIntent.ORDER);
task.setPriority(priority.getTaskPriority());
task.setAuthoredOnElement(DateTimeType.now());
task.setLastModifiedElement(DateTimeType.now());
TaskCode taskCode = TaskCode.FULFILL;
task.getCode().addCoding(new Coding(taskCode.getSystem(), taskCode.toCode(), taskCode.getDisplay()));
task.setDescription(name);
task.setFocus(new Reference(serviceRequest.getId()));
task.setFor(getPatientReference());
task.setOwner(FhirUtil.toReference(Organization.class, performer.getIdElement().getIdPart(), performer.getName()));
task.setRequester(requester);
if (!Strings.isNullOrEmpty(comment)) {
task.addNote().setText(comment).setTimeElement(DateTimeType.now()).setAuthor(new Reference(new IdType(user.getUserType(), user.getId())).setDisplay(user.getName()));
}
return task;
}
Aggregations