Search in sources :

Example 1 with TaskCode

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;
}
Also used : TaskCode(org.hl7.fhir.r4.model.codesystems.TaskCode) Organization(org.hl7.fhir.r4.model.Organization) ArrayList(java.util.ArrayList) Patient(org.hl7.fhir.r4.model.Patient)

Example 2 with TaskCode

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;
}
Also used : Task(org.hl7.fhir.r4.model.Task) TaskCode(org.hl7.fhir.r4.model.codesystems.TaskCode) Organization(org.hl7.fhir.r4.model.Organization) Coding(org.hl7.fhir.r4.model.Coding) Reference(org.hl7.fhir.r4.model.Reference) IdType(org.hl7.fhir.r4.model.IdType)

Aggregations

Organization (org.hl7.fhir.r4.model.Organization)2 TaskCode (org.hl7.fhir.r4.model.codesystems.TaskCode)2 ArrayList (java.util.ArrayList)1 Coding (org.hl7.fhir.r4.model.Coding)1 IdType (org.hl7.fhir.r4.model.IdType)1 Patient (org.hl7.fhir.r4.model.Patient)1 Reference (org.hl7.fhir.r4.model.Reference)1 Task (org.hl7.fhir.r4.model.Task)1