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;
}
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."));
}
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();
}
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);
}
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);
}
Aggregations