Search in sources :

Example 36 with ORGANIZATION

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

Example 37 with ORGANIZATION

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;
}
Also used : Coding(org.hl7.fhir.r4.model.Coding) FHIRException(org.hl7.fhir.exceptions.FHIRException) OrganizationDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.OrganizationDto)

Example 38 with ORGANIZATION

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;
}
Also used : ConsentCreateException(org.hl7.gravity.refimpl.sdohexchange.exception.ConsentCreateException) Bundle(org.hl7.fhir.r4.model.Bundle) Reference(org.hl7.fhir.r4.model.Reference) ConsentPrepareBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.ConsentPrepareBundleFactory) PractitionerRole(org.hl7.fhir.r4.model.PractitionerRole)

Example 39 with 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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) HttpStatus(org.springframework.http.HttpStatus) FhirVersion(gov.cms.ab2d.fhir.FhirVersion) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) ApiResponseEvent(gov.cms.ab2d.eventlogger.events.ApiResponseEvent) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 40 with ORGANIZATION

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) CapabilityStatement(org.hl7.fhir.r4.model.CapabilityStatement) ApiResponseEvent(gov.cms.ab2d.eventlogger.events.ApiResponseEvent) IParser(ca.uhn.fhir.parser.IParser) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Aggregations

Test (org.junit.jupiter.api.Test)101 Organization (org.hl7.fhir.dstu3.model.Organization)90 Organization (org.hl7.fhir.r4.model.Organization)69 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)41 Resource (org.hl7.fhir.r4.model.Resource)38 ArrayList (java.util.ArrayList)34 List (java.util.List)33 Reference (org.hl7.fhir.r4.model.Reference)33 Identifier (org.hl7.fhir.r4.model.Identifier)30 Bundle (org.hl7.fhir.dstu3.model.Bundle)27 UUID (java.util.UUID)26 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)25 Patient (org.hl7.fhir.r4.model.Patient)25 IdType (org.hl7.fhir.dstu3.model.IdType)24 Bundle (org.hl7.fhir.r4.model.Bundle)24 Coding (org.hl7.fhir.r4.model.Coding)24 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)19 ContactPoint (org.hl7.fhir.r4.model.ContactPoint)17 Reference (org.hl7.fhir.dstu3.model.Reference)16 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)16