Search in sources :

Example 1 with TaskJsonResourcesDto

use of org.hl7.gravity.refimpl.sdohexchange.dto.response.TaskJsonResourcesDto in project Gravity-SDOH-Exchange-RI by FHIR.

the class ResourceService method getTaskResources.

public TaskJsonResourcesDto getTaskResources(String id) {
    // Getting task by id with Patient, requester Organization and ServiceRequest
    Bundle taskBundle = cpClient.search().forResource(Task.class).where(Task.RES_ID.exactly().code(id)).include(Task.INCLUDE_FOCUS).include(Task.INCLUDE_PATIENT).include(Task.INCLUDE_REQUESTER).returnBundle(Bundle.class).execute();
    Task task = FhirUtil.getFromBundle(taskBundle, Task.class).stream().findFirst().orElseThrow(() -> new ResourceNotFoundException(new IdType(Task.class.getSimpleName(), id)));
    // We expect that task was validated and contains all resources
    ServiceRequest serviceRequest = FhirUtil.getFirstFromBundle(taskBundle, ServiceRequest.class);
    Patient patient = FhirUtil.getFirstFromBundle(taskBundle, Patient.class);
    Organization requester = FhirUtil.getFirstFromBundle(taskBundle, Organization.class);
    // Load all Task Procedures and ServiceRequest required resources as one transaction
    Map<Class<? extends Resource>, List<Resource>> loadedResources = resourceLoader.getResources(cpClient, collectAllReferences(task, serviceRequest));
    TaskJsonResourcesDto resourcesDto = new TaskJsonResourcesDto();
    resourcesDto.setTask(resourceParser.parse(task));
    resourcesDto.setServiceRequest(resourceParser.parse(serviceRequest));
    resourcesDto.setPatient(resourceParser.parse(patient));
    resourcesDto.setRequester(resourceParser.parse(requester));
    resourcesDto.setConsent(resourceParser.parse(loadedResources.get(Consent.class)).stream().findFirst().orElse(null));
    resourcesDto.setConditions(resourceParser.parse(loadedResources.get(Condition.class)));
    resourcesDto.setGoals(resourceParser.parse(loadedResources.get(Goal.class)));
    resourcesDto.setProcedures(resourceParser.parse(loadedResources.get(Procedure.class)));
    return resourcesDto;
}
Also used : Task(org.hl7.fhir.r4.model.Task) Organization(org.hl7.fhir.r4.model.Organization) Bundle(org.hl7.fhir.r4.model.Bundle) Resource(org.hl7.fhir.r4.model.Resource) Patient(org.hl7.fhir.r4.model.Patient) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) IdType(org.hl7.fhir.r4.model.IdType) TaskJsonResourcesDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.TaskJsonResourcesDto) Consent(org.hl7.fhir.r4.model.Consent) ArrayList(java.util.ArrayList) List(java.util.List) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)

Example 2 with TaskJsonResourcesDto

use of org.hl7.gravity.refimpl.sdohexchange.dto.response.TaskJsonResourcesDto in project Gravity-SDOH-Exchange-RI by FHIR.

the class ResourceService method getTaskResources.

public TaskJsonResourcesDto getTaskResources(Integer serverId, String taskId) {
    Server server = serverRepository.findById(serverId).orElseThrow(() -> new ServerNotFoundException(String.format("No server was found by id '%s'", serverId)));
    IGenericClient fhirClient = fhirContext.newRestfulGenericClient(server.getFhirServerUrl());
    // Doesn't support now
    // fhirClient.registerInterceptor(new BearerTokenAuthInterceptor(
    // authorizationClient.getTokenResponse(URI.create(server.getAuthServerUrl()), server.getClientId(),
    // server.getClientSecret(), SCOPE)
    // .getAccessToken()));
    // Getting task by id with Patient, requester Organization and ServiceRequest
    Bundle taskBundle = fhirClient.search().forResource(Task.class).where(Task.RES_ID.exactly().code(taskId)).include(Task.INCLUDE_FOCUS).include(Task.INCLUDE_PATIENT).include(Task.INCLUDE_REQUESTER).returnBundle(Bundle.class).execute();
    Task task = FhirUtil.getFromBundle(taskBundle, Task.class).stream().findFirst().orElseThrow(() -> new ResourceNotFoundException(new IdType(Task.class.getSimpleName(), taskId)));
    // We expect that task was validated and contains all resources
    ServiceRequest serviceRequest = FhirUtil.getFirstFromBundle(taskBundle, ServiceRequest.class);
    Patient patient = FhirUtil.getFirstFromBundle(taskBundle, Patient.class);
    Organization requester = FhirUtil.getFirstFromBundle(taskBundle, Organization.class);
    // Load all Task Procedures and ServiceRequest required resources as one transaction
    Map<Class<? extends Resource>, List<Resource>> loadedResources = resourceLoader.getResources(fhirClient, collectAllReferences(task, serviceRequest));
    TaskJsonResourcesDto resourcesDto = new TaskJsonResourcesDto();
    resourcesDto.setTask(resourceParser.parse(task));
    resourcesDto.setServiceRequest(resourceParser.parse(serviceRequest));
    resourcesDto.setPatient(resourceParser.parse(patient));
    resourcesDto.setRequester(resourceParser.parse(requester));
    resourcesDto.setConsent(resourceParser.parse(loadedResources.get(Consent.class)).stream().findFirst().orElse(null));
    resourcesDto.setConditions(resourceParser.parse(loadedResources.get(Condition.class)));
    resourcesDto.setGoals(resourceParser.parse(loadedResources.get(Goal.class)));
    resourcesDto.setProcedures(resourceParser.parse(loadedResources.get(Procedure.class)));
    return resourcesDto;
}
Also used : Task(org.hl7.fhir.r4.model.Task) Organization(org.hl7.fhir.r4.model.Organization) Server(org.hl7.gravity.refimpl.sdohexchange.model.Server) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Bundle(org.hl7.fhir.r4.model.Bundle) Resource(org.hl7.fhir.r4.model.Resource) Patient(org.hl7.fhir.r4.model.Patient) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) IdType(org.hl7.fhir.r4.model.IdType) TaskJsonResourcesDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.TaskJsonResourcesDto) Consent(org.hl7.fhir.r4.model.Consent) ArrayList(java.util.ArrayList) List(java.util.List) ServerNotFoundException(org.hl7.gravity.refimpl.sdohexchange.exception.ServerNotFoundException) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)

Aggregations

ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Bundle (org.hl7.fhir.r4.model.Bundle)2 Consent (org.hl7.fhir.r4.model.Consent)2 IdType (org.hl7.fhir.r4.model.IdType)2 Organization (org.hl7.fhir.r4.model.Organization)2 Patient (org.hl7.fhir.r4.model.Patient)2 Resource (org.hl7.fhir.r4.model.Resource)2 ServiceRequest (org.hl7.fhir.r4.model.ServiceRequest)2 Task (org.hl7.fhir.r4.model.Task)2 TaskJsonResourcesDto (org.hl7.gravity.refimpl.sdohexchange.dto.response.TaskJsonResourcesDto)2 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)1 ServerNotFoundException (org.hl7.gravity.refimpl.sdohexchange.exception.ServerNotFoundException)1 Server (org.hl7.gravity.refimpl.sdohexchange.model.Server)1