Search in sources :

Example 21 with Consent

use of org.hl7.fhir.r4.model.Consent in project fhir-bridge by ehrbase.

the class FindConsentTransactionIT method findConsentSearch.

@Test
void findConsentSearch() throws IOException {
    for (int i = 0; i < 3; i++) {
        create("Consent/transactions/find-consent-search.json");
    }
    Bundle bundle = search("Consent?patient.identifier=" + PATIENT_ID + "&status=rejected");
    Assertions.assertEquals(3, bundle.getTotal());
    bundle.getEntry().forEach(entry -> {
        var consent = (Consent) entry.getResource();
        Assertions.assertEquals(PATIENT_ID, consent.getPatient().getIdentifier().getValue());
        Assertions.assertEquals(Consent.ConsentState.REJECTED, consent.getStatus());
    });
}
Also used : Consent(org.hl7.fhir.r4.model.Consent) Bundle(org.hl7.fhir.r4.model.Bundle) Test(org.junit.jupiter.api.Test)

Example 22 with Consent

use of org.hl7.fhir.r4.model.Consent in project fhir-bridge by ehrbase.

the class ProvideConsentTransactionIT method provideConsentConditionalUpdate.

@Test
void provideConsentConditionalUpdate() throws IOException {
    MethodOutcome outcome;
    outcome = create("Consent/transactions/provide-consent-create.json");
    IIdType id = outcome.getId();
    outcome = update("Consent/transactions/provide-consent-update.json", "Consent?_id=" + id.getIdPart() + "&patient.identifier=" + PATIENT_ID);
    Assertions.assertEquals(id.getIdPart(), outcome.getId().getIdPart());
    Assertions.assertEquals(id.getVersionIdPartAsLong() + 1, outcome.getId().getVersionIdPartAsLong());
    Consent consent = (Consent) outcome.getResource();
    Assertions.assertEquals("https://www.aerzteblatt.de/archiv/65440/DNR-Anordnungen-Das-fehlende-Bindeglied-UPDATED", consent.getPolicyFirstRep().getUri());
    Assertions.assertEquals(PATIENT_ID, consent.getPatient().getIdentifier().getValue());
}
Also used : Consent(org.hl7.fhir.r4.model.Consent) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) IIdType(org.hl7.fhir.instance.model.api.IIdType) Test(org.junit.jupiter.api.Test)

Example 23 with Consent

use of org.hl7.fhir.r4.model.Consent in project gpconnect-demonstrator by nhsconnect.

the class PatientResourceProvider method StructuredRecordOperation.

@Operation(name = GET_STRUCTURED_RECORD_OPERATION_NAME)
public Bundle StructuredRecordOperation(@ResourceParam Parameters params) throws FHIRException {
    Bundle structuredBundle = new Bundle();
    Boolean getAllergies = false;
    Boolean includeResolved = false;
    Boolean getMedications = false;
    Boolean includePrescriptionIssues = false;
    Period medicationPeriod = null;
    String NHS = getNhsNumber(params);
    PatientDetails patientDetails = patientSearch.findPatient(NHS);
    // see https://nhsconnect.github.io/gpconnect/accessrecord_structured_development_retrieve_patient_record.html#error-handling
    if (patientDetails == null || patientDetails.isSensitive() || patientDetails.isDeceased() || !patientDetails.isActive()) {
        throw OperationOutcomeFactory.buildOperationOutcomeException(new ResourceNotFoundException("No patient details found for patient ID: " + NHS), SystemCode.PATIENT_NOT_FOUND, IssueType.NOTFOUND);
    }
    if (NHS.equals(patientNoconsent)) {
        throw OperationOutcomeFactory.buildOperationOutcomeException(new ForbiddenOperationException("No patient consent to share for patient ID: " + NHS), SystemCode.NO_PATIENT_CONSENT, IssueType.FORBIDDEN);
    }
    operationOutcome = null;
    for (ParametersParameterComponent param : params.getParameter()) {
        if (validateParametersName(param.getName())) {
            if (param.getName().equals(SystemConstants.INCLUDE_ALLERGIES)) {
                getAllergies = true;
                if (param.getPart().isEmpty()) {
                    // addWarningIssue(param, IssueType.REQUIRED, "Miss parameter part : " + SystemConstants.INCLUDE_RESOLVED_ALLERGIES);
                    throw OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException("Miss parameter : " + SystemConstants.INCLUDE_RESOLVED_ALLERGIES), SystemCode.INVALID_PARAMETER, IssueType.REQUIRED);
                }
                boolean includeResolvedParameterPartPresent = false;
                for (ParametersParameterComponent paramPart : param.getPart()) {
                    if (paramPart.getName().equals(SystemConstants.INCLUDE_RESOLVED_ALLERGIES)) {
                        if (paramPart.getValue() instanceof BooleanType) {
                            includeResolved = Boolean.valueOf(paramPart.getValue().primitiveValue());
                            includeResolvedParameterPartPresent = true;
                        } else {
                            throw OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException("Miss parameter : " + SystemConstants.INCLUDE_RESOLVED_ALLERGIES), SystemCode.INVALID_PARAMETER, IssueType.REQUIRED);
                        }
                    } else {
                        addWarningIssue(param, paramPart, IssueType.NOTSUPPORTED);
                    // throw OperationOutcomeFactory.buildOperationOutcomeException(
                    // new UnprocessableEntityException("Incorrect parameter passed : " + paramPart.getName()),
                    // SystemCode.INVALID_PARAMETER, IssueType.INVALID);
                    }
                }
                if (!includeResolvedParameterPartPresent) {
                    throw OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException("Miss parameter : " + SystemConstants.INCLUDE_RESOLVED_ALLERGIES), SystemCode.INVALID_PARAMETER, IssueType.REQUIRED);
                }
            }
            if (param.getName().equals(SystemConstants.INCLUDE_MEDICATION)) {
                getMedications = true;
                boolean isIncludedPrescriptionIssuesExist = false;
                for (ParametersParameterComponent paramPart : param.getPart()) {
                    if (paramPart.getName().equals(SystemConstants.INCLUDE_PRESCRIPTION_ISSUES)) {
                        if (paramPart.getValue() instanceof BooleanType) {
                            includePrescriptionIssues = Boolean.valueOf(paramPart.getValue().primitiveValue());
                            isIncludedPrescriptionIssuesExist = true;
                        }
                    } else if (paramPart.getName().equals(SystemConstants.MEDICATION_SEARCH_FROM_DATE) && paramPart.getValue() instanceof DateType) {
                        DateType startDateDt = (DateType) paramPart.getValue();
                        medicationPeriod = new Period();
                        medicationPeriod.setStart(startDateDt.getValue());
                        medicationPeriod.setEnd(null);
                        String startDate = startDateDt.asStringValue();
                        if (!validateStartDateParamAndEndDateParam(startDate, null)) {
                        // addWarningIssue(param, paramPart, IssueType.INVALID, "Invalid date used");
                        }
                    } else {
                        addWarningIssue(param, paramPart, IssueType.NOTSUPPORTED);
                    // throw OperationOutcomeFactory.buildOperationOutcomeException(
                    // new UnprocessableEntityException("Incorrect parameter passed : " + paramPart.getName()),
                    // SystemCode.INVALID_PARAMETER, IssueType.INVALID);
                    }
                }
                if (!isIncludedPrescriptionIssuesExist) {
                    // # 1.2.6 now defaults to true if not provided
                    includePrescriptionIssues = true;
                }
            }
        } else {
            // invalid parameter
            addWarningIssue(param, IssueType.NOTSUPPORTED);
        }
    }
    // for parameter
    // Add Patient
    Patient patient = patientDetailsToPatientResourceConverter(patientDetails);
    if (patient.getIdentifierFirstRep().getValue().equals(NHS)) {
        structuredBundle.addEntry().setResource(patient);
    }
    // Organization from patient
    Set<String> orgIds = new HashSet<>();
    orgIds.add(patientDetails.getManagingOrganization());
    // Practitioner from patient
    Set<String> practitionerIds = new HashSet<>();
    List<Reference> practitionerReferenceList = patient.getGeneralPractitioner();
    practitionerReferenceList.forEach(practitionerReference -> {
        String[] pracRef = practitionerReference.getReference().split("/");
        if (pracRef.length > 1) {
            practitionerIds.add(pracRef[1]);
        }
    });
    if (getAllergies) {
        structuredBundle = structuredAllergyIntoleranceBuilder.buildStructuredAllergyIntolerence(NHS, practitionerIds, structuredBundle, includeResolved);
    }
    if (getMedications) {
        structuredBundle = populateMedicationBundle.addMedicationBundleEntries(structuredBundle, patientDetails, includePrescriptionIssues, medicationPeriod, practitionerIds, orgIds);
    }
    // Add all practitioners and practitioner roles
    for (String practitionerId : practitionerIds) {
        Practitioner pracResource = practitionerResourceProvider.getPractitionerById(new IdType(practitionerId));
        structuredBundle.addEntry().setResource(pracResource);
        List<PractitionerRole> practitionerRoleList = practitionerRoleResourceProvider.getPractitionerRoleByPracticionerId(new IdType(practitionerId));
        for (PractitionerRole role : practitionerRoleList) {
            String[] split = role.getOrganization().getReference().split("/");
            orgIds.add(split[1]);
            structuredBundle.addEntry().setResource(role);
        }
    }
    // Add all organizations
    for (String orgId : orgIds) {
        OrganizationDetails organizationDetails = organizationSearch.findOrganizationDetails(new Long(orgId));
        Organization organization = organizationResourceProvider.convertOrganizationDetailsToOrganization(organizationDetails);
        structuredBundle.addEntry().setResource(organization);
    }
    structuredBundle.setType(BundleType.COLLECTION);
    structuredBundle.getMeta().addProfile(SystemURL.SD_GPC_STRUCTURED_BUNDLE);
    if (operationOutcome != null) {
        structuredBundle.addEntry().setResource(operationOutcome);
    } else {
        removeDuplicateResources(structuredBundle);
    }
    return structuredBundle;
}
Also used : OrganizationDetails(uk.gov.hscic.model.organization.OrganizationDetails) ForbiddenOperationException(ca.uhn.fhir.rest.server.exceptions.ForbiddenOperationException) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) UnprocessableEntityException(ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException) PopulateMedicationBundle(uk.gov.hscic.medications.PopulateMedicationBundle) PatientDetails(uk.gov.hscic.model.patient.PatientDetails) ParametersParameterComponent(org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent)

Example 24 with Consent

use of org.hl7.fhir.r4.model.Consent in project dpc-app by CMSgov.

the class ConsentResource method search.

@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
@GET
@FHIR
@Timed
@ExceptionMetered
@UnitOfWork
@ApiOperation(value = "Search for Consent Entries", notes = "Search for Consent records. " + "<p>Must provide ONE OF Consent ID as an _id or identifier, or a patient MBI or HICN to search for.", response = Bundle.class)
@ApiResponses(@ApiResponse(code = 400, message = "Must provide Consent or Patient id"))
public List<Consent> search(@ApiParam(value = "Consent resource _id") @QueryParam(Consent.SP_RES_ID) Optional<UUID> id, @ApiParam(value = "Consent resource identifier") @QueryParam(Consent.SP_IDENTIFIER) Optional<UUID> identifier, @ApiParam(value = "Patient Identifier") @QueryParam(Consent.SP_PATIENT) Optional<String> patientId) {
    final List<ConsentEntity> entities;
    // Priority order for processing params. If multiple params are passed, we only pay attention to one
    if (id.isPresent()) {
        final Optional<ConsentEntity> consentEntity = this.dao.getConsent(id.get());
        entities = consentEntity.map(List::of).orElseGet(() -> List.of(ConsentEntity.defaultConsentEntity(id, Optional.empty(), Optional.empty())));
    } else if (identifier.isPresent()) {
        // not sure we should support this
        final Optional<ConsentEntity> consentEntity = this.dao.getConsent(identifier.get());
        entities = consentEntity.map(List::of).orElseGet(() -> List.of(ConsentEntity.defaultConsentEntity(id, Optional.empty(), Optional.empty())));
    } else if (patientId.isPresent()) {
        final Identifier patientIdentifier = FHIRExtractors.parseIDFromQueryParam(patientId.get());
        entities = getEntitiesByPatient(patientIdentifier);
    } else {
        throw new WebApplicationException("Must have some form of Consent Resource ID or Patient ID", Response.Status.BAD_REQUEST);
    }
    if (entities.isEmpty()) {
        throw new WebApplicationException("Cannot find patient with given ID", Response.Status.NOT_FOUND);
    }
    return entities.stream().map(e -> ConsentEntityConverter.toFhir(e, fhirReferenceURL)).collect(Collectors.toList());
}
Also used : Bundle(org.hl7.fhir.dstu3.model.Bundle) Identifier(org.hl7.fhir.dstu3.model.Identifier) ApiParam(io.swagger.annotations.ApiParam) ApiResponses(io.swagger.annotations.ApiResponses) ConsentEntity(gov.cms.dpc.common.consent.entities.ConsentEntity) Inject(javax.inject.Inject) ApiOperation(io.swagger.annotations.ApiOperation) ConsentDAO(gov.cms.dpc.consent.jdbi.ConsentDAO) ExceptionMetered(com.codahale.metrics.annotation.ExceptionMetered) HttpStatus(org.eclipse.jetty.http.HttpStatus) ConsentEntityConverter(gov.cms.dpc.fhir.converters.entities.ConsentEntityConverter) FHIR(gov.cms.dpc.fhir.annotations.FHIR) Consent(org.hl7.fhir.dstu3.model.Consent) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Timed(com.codahale.metrics.annotation.Timed) List(java.util.List) javax.ws.rs(javax.ws.rs) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) UnitOfWork(io.dropwizard.hibernate.UnitOfWork) Optional(java.util.Optional) Named(com.google.inject.name.Named) FHIRExtractors(gov.cms.dpc.fhir.FHIRExtractors) DPCIdentifierSystem(gov.cms.dpc.fhir.DPCIdentifierSystem) Identifier(org.hl7.fhir.dstu3.model.Identifier) Optional(java.util.Optional) ConsentEntity(gov.cms.dpc.common.consent.entities.ConsentEntity) List(java.util.List) UnitOfWork(io.dropwizard.hibernate.UnitOfWork) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) FHIR(gov.cms.dpc.fhir.annotations.FHIR) ExceptionMetered(com.codahale.metrics.annotation.ExceptionMetered) ApiResponses(io.swagger.annotations.ApiResponses)

Example 25 with Consent

use of org.hl7.fhir.r4.model.Consent in project dpc-app by CMSgov.

the class ConsentEntityConverterTest method convert_correctlyConverts_fromDefaultEntity.

@Test
final void convert_correctlyConverts_fromDefaultEntity() {
    ConsentEntity ce = ConsentEntity.defaultConsentEntity(Optional.empty(), Optional.of(TEST_HICN), Optional.of(TEST_MBI));
    final Consent result = ConsentEntityConverter.toFhir(ce, TEST_FHIR_URL);
    assertNotNull(result);
    assertEquals(Consent.ConsentState.ACTIVE, result.getStatus());
    assertEquals(ConsentEntity.CATEGORY_LOINC_CODE, result.getCategoryFirstRep().getCodingFirstRep().getCode());
    assertEquals(ConsentEntity.CATEGORY_DISPLAY, result.getCategoryFirstRep().getCodingFirstRep().getDisplay());
    assertEquals(TEST_FHIR_URL + "/Patient?identity=|" + TEST_MBI, result.getPatient().getReference());
    assertEquals(ConsentEntityConverter.OPT_IN_MAGIC, result.getPolicyRule());
    assertTrue(result.getPolicy().isEmpty());
    assertDoesNotThrow(() -> FhirContext.forDstu3().newJsonParser().encodeResourceToString(result));
}
Also used : Consent(org.hl7.fhir.dstu3.model.Consent) ConsentEntity(gov.cms.dpc.common.consent.entities.ConsentEntity) Test(org.junit.jupiter.api.Test)

Aggregations

Consent (org.hl7.fhir.r4.model.Consent)15 Consent (org.hl7.fhir.dstu3.model.Consent)8 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)8 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)7 Test (org.junit.jupiter.api.Test)7 MethodOutcome (ca.uhn.fhir.rest.api.MethodOutcome)6 List (java.util.List)5 Bundle (org.hl7.fhir.r4.model.Bundle)5 Reference (org.hl7.fhir.r4.model.Reference)5 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)4 ConsentEntity (gov.cms.dpc.common.consent.entities.ConsentEntity)4 Optional (java.util.Optional)4 Collectors (java.util.stream.Collectors)4 IIdType (org.hl7.fhir.instance.model.api.IIdType)4 ConsentCreateException (org.hl7.gravity.refimpl.sdohexchange.exception.ConsentCreateException)4 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)3 SmartOnFhirContext (com.healthlx.smartonfhir.core.SmartOnFhirContext)2 DPCIdentifierSystem (gov.cms.dpc.fhir.DPCIdentifierSystem)2 FHIR (gov.cms.dpc.fhir.annotations.FHIR)2 UnitOfWork (io.dropwizard.hibernate.UnitOfWork)2