use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.ORGANIZATION in project Gravity-SDOH-Exchange-RI by FHIR.
the class TaskReferenceResourcesLoader method loadTaskReferences.
private TaskReferencesHolder loadTaskReferences(IGenericClient ehrClient, Task task, String identifierSystem, Bundle bundle) {
TaskReferenceResolver referenceResolver = new TaskReferenceResolver(task, identifierSystem);
// Load local references in one transaction
referenceResolver.setLocalResources(resourceLoader.getResourcesBySystem(openCpClient, identifierSystem, referenceResolver.getLocalReferences()));
// Load EHR references in one transaction
referenceResolver.setExternalResources(resourceLoader.getResources(ehrClient, referenceResolver.getExternalReferences()));
Patient patient = referenceResolver.getPatient();
if (referenceResolver.createPatient()) {
updateResourceRefs(patient, ehrClient.getServerBase(), new HashMap());
// Create CP Patient resource
bundle.addEntry(FhirUtil.createPostEntry(patient));
}
Organization requester = referenceResolver.getRequester();
if (referenceResolver.createRequester()) {
// Create CP Organization resource
bundle.addEntry(FhirUtil.createPostEntry(requester));
}
ServiceRequest serviceRequest = referenceResolver.getServiceRequest();
// Link CP ServiceRequest with Patient
serviceRequest.setSubject(FhirUtil.toReference(Patient.class, patient.getIdElement().getIdPart()));
// Create CP ServiceRequest resource
bundle.addEntry(FhirUtil.createPostEntry(serviceRequest));
// Link CP Task with Patient, Organization and ServiceRequest
task.setFor(FhirUtil.toReference(Patient.class, patient.getIdElement().getIdPart(), patient.getNameFirstRep().getNameAsSingleString()));
task.setRequester(FhirUtil.toReference(Organization.class, requester.getIdElement().getIdPart(), requester.getName()));
task.setFocus(FhirUtil.toReference(ServiceRequest.class, serviceRequest.getIdElement().getIdPart()));
return new TaskReferencesHolder(patient, requester, serviceRequest);
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.ORGANIZATION in project Gravity-SDOH-Exchange-RI by FHIR.
the class OrganizationToDtoConverter method convert.
@Override
public OrganizationDto convert(Organization org) {
String orgId = org.getIdElement().getIdPart();
OrganizationDto orgDto = new OrganizationDto(orgId);
orgDto.setName(org.getName());
// We are interested only in CBO/CP types. Other are ignored.
Coding coding = FhirUtil.findCoding(org.getType(), OrganizationTypeCode.SYSTEM);
if (coding == null) {
orgDto.getErrors().add(String.format("Organization with id '%s' has no coding with system '%s' within a 'type' property. Such organizations " + "are " + "not expected in this context.", orgId, OrganizationTypeCode.SYSTEM));
} else {
try {
orgDto.setType(OrganizationTypeCode.fromCode(coding.getCode()));
} catch (FHIRException exc) {
orgDto.getErrors().add(String.format("OrganizationTypeCode code '%s' cannot be resolved for Organization with id '%s'.", coding.getCode(), orgId));
}
}
return orgDto;
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.ORGANIZATION in project Gravity-SDOH-Exchange-RI by FHIR.
the class ConsentService method retrieveOrganization.
private Reference retrieveOrganization(UserDto userDto) {
Bundle bundle = new ConsentPrepareBundleFactory(userDto.getId()).createPrepareBundle();
Bundle consentResponseBundle = ehrClient.transaction().withBundle(bundle).execute();
Bundle consentBundle = FhirUtil.getFirstFromBundle(consentResponseBundle, Bundle.class);
PractitionerRole practitionerRole = FhirUtil.getFirstFromBundle(consentBundle, PractitionerRole.class);
Reference organization = practitionerRole.getOrganization();
if (organization == null) {
throw new ConsentCreateException("No Organization found for Consent creation.");
}
return organization;
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.ORGANIZATION in project ab2d by CMSgov.
the class ErrorHandler method generateFHIRError.
private ResponseEntity<JsonNode> generateFHIRError(Exception e, HttpHeaders httpHeaders, HttpServletRequest request) throws IOException {
String msg = getRootCause(e);
HttpStatus httpStatus = getErrorResponse(e.getClass());
FhirVersion version = FhirVersion.fromAB2DUrl(request.getRequestURI());
IBaseResource operationOutcome = version.getErrorOutcome(msg);
String encoded = version.outcomePrettyToJSON(operationOutcome);
// Log so that Splunk can pick this up and alert
log.warn("{} {}", ExceptionUtils.getRootCause(e).getClass(), msg);
eventLogger.log(new ApiResponseEvent(MDC.get(ORGANIZATION), null, ErrorHandler.getErrorResponse(e.getClass()), "FHIR Error", msg, (String) request.getAttribute(REQUEST_ID)));
return new ResponseEntity<>(new ObjectMapper().readTree(encoded), httpHeaders, httpStatus);
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.ORGANIZATION in project ab2d by CMSgov.
the class CapabilityAPIV2 method capabilityStatement.
@Operation(summary = CAP_REQ)
@ApiResponses(value = { @ApiResponse(responseCode = "200", description = CAP_DESC + " http://hl7.org/fhir/capabilitystatement.html") })
@ResponseStatus(value = HttpStatus.OK)
@GetMapping(value = "/metadata")
public ResponseEntity<String> capabilityStatement(HttpServletRequest request) {
IParser parser = R4.getJsonParser();
eventLogger.log(new ApiResponseEvent(MDC.get(ORGANIZATION), null, HttpStatus.OK, CAP_STMT, CAP_RET, (String) request.getAttribute(REQUEST_ID)));
String server = common.getCurrentUrl(request).replace("/metadata", "");
CapabilityStatement capabilityStatement = CapabilityStatementR4.populateCS(server);
return new ResponseEntity<>(parser.encodeResourceToString(capabilityStatement), null, HttpStatus.OK);
}
Aggregations