Search in sources :

Example 16 with UserDto

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

the class PatientTaskService method createMakeContactTaskBundleFactory.

private PatientMakeContactTaskBundleFactory createMakeContactTaskBundleFactory(UserDto user, NewMakeContactTaskRequestDto makeContactTaskRequest) {
    PatientMakeContactTaskPrepareBundleFactory taskPrepareBundleFactory = new PatientMakeContactTaskPrepareBundleFactory(SmartOnFhirContext.get().getPatient(), user.getId(), makeContactTaskRequest.getHealthcareServiceId(), makeContactTaskRequest.getReferralTaskId());
    Bundle taskRelatedResources = ehrClient.transaction().withBundle(taskPrepareBundleFactory.createPrepareBundle()).execute();
    PatientMakeContactTaskPrepareBundleExtractor.PatientMakeContactTaskPrepareInfoHolder taskPrepareInfoHolder = new PatientMakeContactTaskPrepareBundleExtractor().extract(taskRelatedResources);
    PatientMakeContactTaskBundleFactory taskBundleFactory = new PatientMakeContactTaskBundleFactory();
    taskBundleFactory.setName(makeContactTaskRequest.getName());
    taskBundleFactory.setPatient(taskPrepareInfoHolder.getPatient());
    taskBundleFactory.setPriority(makeContactTaskRequest.getPriority());
    taskBundleFactory.setOccurrence(makeContactTaskRequest.getOccurrence());
    taskBundleFactory.setRequester(taskPrepareInfoHolder.getPerformer());
    // TODO verify whether the passed Task instance is related to the Patient
    taskBundleFactory.setReferralTask(taskPrepareInfoHolder.getReferralTask());
    taskBundleFactory.setComment(makeContactTaskRequest.getComment());
    taskBundleFactory.setUser(user);
    // TODO verify whether the passed HealthcareService instance is related to the task
    taskBundleFactory.setContactInfo(taskPrepareInfoHolder.getHealthcareService());
    return taskBundleFactory;
}
Also used : PatientMakeContactTaskBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.patienttask.PatientMakeContactTaskBundleFactory) Bundle(org.hl7.fhir.r4.model.Bundle) PatientMakeContactTaskPrepareBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.patienttask.PatientMakeContactTaskPrepareBundleFactory) PatientMakeContactTaskPrepareBundleExtractor(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.patienttask.PatientMakeContactTaskPrepareBundleExtractor)

Example 17 with UserDto

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

the class ProblemService method create.

public ProblemDto create(NewProblemDto newProblemDto, UserDto user) {
    Assert.notNull(SmartOnFhirContext.get().getPatient(), "Patient id cannot be null.");
    CurrentContextPrepareBundleFactory currentContextPrepareBundleFactory = new CurrentContextPrepareBundleFactory(SmartOnFhirContext.get().getPatient(), user.getId());
    Bundle problemRelatedResources = ehrClient.transaction().withBundle(currentContextPrepareBundleFactory.createPrepareBundle()).execute();
    CurrentContextPrepareBundleExtractor.CurrentContextPrepareInfoHolder currentContextPrepareInfoHolder = new CurrentContextPrepareBundleExtractor().extract(problemRelatedResources);
    ProblemBundleFactory bundleFactory = new ProblemBundleFactory();
    bundleFactory.setName(newProblemDto.getName());
    bundleFactory.setBasedOnText(newProblemDto.getBasedOnText());
    bundleFactory.setStartDate(newProblemDto.getStartDate());
    String category = newProblemDto.getCategory();
    bundleFactory.setCategory(sdohMappings.findCategoryCoding(category));
    bundleFactory.setConditionType(UsCoreConditionCategory.PROBLEMLISTITEM);
    bundleFactory.setIcdCode(sdohMappings.findCoding(category, Condition.class, System.ICD_10, newProblemDto.getIcdCode()));
    bundleFactory.setSnomedCode(sdohMappings.findCoding(category, Condition.class, System.SNOMED, newProblemDto.getSnomedCode()));
    bundleFactory.setPatient(currentContextPrepareInfoHolder.getPatient());
    bundleFactory.setPractitioner(currentContextPrepareInfoHolder.getPractitioner());
    Bundle problemCreateBundle = ehrClient.transaction().withBundle(bundleFactory.createBundle()).execute();
    IdType problemId = FhirUtil.getFromResponseBundle(problemCreateBundle, Condition.class);
    Bundle responseBundle = searchProblemQuery(ConditionClinicalStatusCodes.ACTIVE).where(Condition.RES_ID.exactly().code(problemId.getIdPart())).returnBundle(Bundle.class).execute();
    return new ProblemBundleToDtoConverter().convert(responseBundle).stream().findFirst().orElseThrow(() -> new ProblemCreateException("Problem is not found in the response bundle."));
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) CurrentContextPrepareBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.CurrentContextPrepareBundleFactory) ProblemCreateException(org.hl7.gravity.refimpl.sdohexchange.exception.ProblemCreateException) ProblemBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.ProblemBundleFactory) CurrentContextPrepareBundleExtractor(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.CurrentContextPrepareBundleExtractor) IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) Bundle(org.hl7.fhir.r4.model.Bundle) ProblemBundleToDtoConverter(org.hl7.gravity.refimpl.sdohexchange.dto.converter.ProblemBundleToDtoConverter) IdType(org.hl7.fhir.r4.model.IdType)

Example 18 with UserDto

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

the class TaskService method newTask.

public String newTask(NewTaskRequestDto taskRequest, UserDto user) {
    Assert.notNull(SmartOnFhirContext.get().getPatient(), "Patient id cannot be null.");
    TaskPrepareBundleFactory taskPrepareBundleFactory = new TaskPrepareBundleFactory(SmartOnFhirContext.get().getPatient(), user.getId(), taskRequest.getPerformerId(), taskRequest.getConsent(), taskRequest.getConditionIds(), taskRequest.getGoalIds());
    Bundle taskRelatedResources = ehrClient.transaction().withBundle(taskPrepareBundleFactory.createPrepareBundle()).execute();
    TaskPrepareInfoHolder taskPrepareInfoHolder = new TaskPrepareBundleExtractor().extract(taskRelatedResources);
    TaskBundleFactory taskBundleFactory = new TaskBundleFactory();
    taskBundleFactory.setName(taskRequest.getName());
    taskBundleFactory.setPatient(taskPrepareInfoHolder.getPatient());
    taskBundleFactory.setCategory(sdohMappings.findCategoryCoding(taskRequest.getCategory()));
    taskBundleFactory.setRequestCode(sdohMappings.findResourceCoding(ServiceRequest.class, taskRequest.getCode()));
    taskBundleFactory.setPriority(taskRequest.getPriority());
    taskBundleFactory.setOccurrence(taskRequest.getOccurrence());
    taskBundleFactory.setPerformer(taskPrepareInfoHolder.getPerformerOrganization());
    taskBundleFactory.setRequester(taskPrepareInfoHolder.getPerformer());
    taskBundleFactory.setComment(taskRequest.getComment());
    taskBundleFactory.setUser(user);
    taskBundleFactory.setConsent(taskPrepareInfoHolder.getConsent());
    taskBundleFactory.setConditions(taskPrepareInfoHolder.getConditions(taskRequest.getConditionIds()));
    taskBundleFactory.setGoals(taskPrepareInfoHolder.getGoals(taskRequest.getGoalIds()));
    Bundle taskCreateBundle = ehrClient.transaction().withBundle(taskBundleFactory.createBundle()).execute();
    IdType taskId = FhirUtil.getFromResponseBundle(taskCreateBundle, Task.class);
    TaskInfoHolder createInfo = new TaskInfoBundleExtractor().extract(getTask(taskId.getIdPart(), Task.INCLUDE_FOCUS)).stream().findFirst().orElseThrow(() -> new TaskCreateException("Task/ServiceRequest are not found in the response bundle."));
    Task task = createInfo.getTask();
    try {
        cpService.create(task, taskPrepareInfoHolder.getEndpoint());
    } catch (CpClientException exc) {
        log.warn("Task '{}' creation failed at CP. Failing a local Task and related ServiceRequest.", task.getIdElement().getIdPart(), exc);
        ehrClient.transaction().withBundle(new TaskFailBundleFactory(task, createInfo.getServiceRequest(), exc.getMessage()).createFailBundle()).execute();
    }
    return task.getIdElement().getIdPart();
}
Also used : TaskInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskInfoBundleExtractor.TaskInfoHolder) Task(org.hl7.fhir.r4.model.Task) TaskPrepareBundleExtractor(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskPrepareBundleExtractor) TaskPrepareBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.TaskPrepareBundleFactory) IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) Bundle(org.hl7.fhir.r4.model.Bundle) TaskPrepareInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskPrepareBundleExtractor.TaskPrepareInfoHolder) TaskCreateException(org.hl7.gravity.refimpl.sdohexchange.exception.TaskCreateException) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) TaskBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.TaskBundleFactory) IdType(org.hl7.fhir.r4.model.IdType) TaskFailBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.TaskFailBundleFactory) CpClientException(org.hl7.gravity.refimpl.sdohexchange.service.CpService.CpClientException) TaskInfoBundleExtractor(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskInfoBundleExtractor)

Example 19 with UserDto

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

the class ConsentService method createConsent.

public ConsentDto createConsent(String name, MultipartFile attachment, UserDto userDto) {
    Reference patient = FhirUtil.toReference(Patient.class, SmartOnFhirContext.get().getPatient());
    Reference organization = retrieveOrganization(userDto);
    Consent consent = new CreateConsentFactory(name, patient, attachment, organization).createConsent();
    MethodOutcome methodOutcome = ehrClient.create().resource(consent).execute();
    Consent savedConsent = (Consent) methodOutcome.getResource();
    return new ConsentToDtoConverter().convert(savedConsent);
}
Also used : Consent(org.hl7.fhir.r4.model.Consent) CreateConsentFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.resource.CreateConsentFactory) Reference(org.hl7.fhir.r4.model.Reference) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) ConsentToDtoConverter(org.hl7.gravity.refimpl.sdohexchange.dto.converter.ConsentToDtoConverter)

Example 20 with UserDto

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

the class ContextService method getUser.

protected UserDto getUser() {
    IdType fhirUser = new IdType(SmartOnFhirContext.get().getFhirUser());
    Assert.isTrue(fhirUser.hasIdPart(), "Current User cannot be null.");
    // TODO support other user Resource types. For example another Patient can create Tasks.
    Assert.isTrue(Practitioner.class.getSimpleName().equals(fhirUser.getResourceType()), "Current user is not a Practitioner. Only Practitioner resource type is supported for now.");
    Practitioner practitioner = ehrClient.read().resource(Practitioner.class).withId(fhirUser.getIdPart()).execute();
    return new PractitionerToDtoConverter().convert(practitioner);
}
Also used : Practitioner(org.hl7.fhir.r4.model.Practitioner) PractitionerToDtoConverter(org.hl7.gravity.refimpl.sdohexchange.dto.converter.PractitionerToDtoConverter) IdType(org.hl7.fhir.r4.model.IdType)

Aggregations

Bundle (org.hl7.fhir.r4.model.Bundle)12 IdType (org.hl7.fhir.r4.model.IdType)7 IBaseBundle (org.hl7.fhir.instance.model.api.IBaseBundle)5 Task (org.hl7.fhir.r4.model.Task)5 UserDto (org.hl7.gravity.refimpl.sdohexchange.dto.response.UserDto)5 ApiOperation (io.swagger.annotations.ApiOperation)3 UserInfoToDtoConverter (org.hl7.gravity.refimpl.sdohexchange.dto.converter.UserInfoToDtoConverter)3 PutMapping (org.springframework.web.bind.annotation.PutMapping)3 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)2 Condition (org.hl7.fhir.r4.model.Condition)2 Practitioner (org.hl7.fhir.r4.model.Practitioner)2 PractitionerRole (org.hl7.fhir.r4.model.PractitionerRole)2 Reference (org.hl7.fhir.r4.model.Reference)2 ServiceRequest (org.hl7.fhir.r4.model.ServiceRequest)2 HealthConcernCreateException (org.hl7.gravity.refimpl.sdohexchange.exception.HealthConcernCreateException)2 CurrentContextPrepareBundleExtractor (org.hl7.gravity.refimpl.sdohexchange.fhir.extract.CurrentContextPrepareBundleExtractor)2 TaskInfoBundleExtractor (org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskInfoBundleExtractor)2 TaskInfoHolder (org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskInfoBundleExtractor.TaskInfoHolder)2 CurrentContextPrepareBundleFactory (org.hl7.gravity.refimpl.sdohexchange.fhir.factory.CurrentContextPrepareBundleFactory)2 TaskFailBundleFactory (org.hl7.gravity.refimpl.sdohexchange.fhir.factory.TaskFailBundleFactory)2