/** * Returns the list of all consents configured in the system, with "granted"/"not granted" status for the given * patient for each consent. * * @param patientId record on which consents are granted (or not granted) * @return All the consents configured in the system with granted (for the patient) status set for each. Returns * null if patientId is not a valid id. */ public JSONArray getAllConsentsForPatient(String patientId) { try { return this.consentManager.toJSON(this.consentManager.getAllConsentsForPatient(patientId)); } catch (Exception ex) { return null; } } }
@Override public boolean consentsGloballyEnabled() { return !this.consentManager.getSystemConsents().isEmpty(); }
@Override public boolean authorizeInteraction(Patient patient) { return (patient != null) && this.containsRequiredConsents(this.consentManager.getMissingConsentsForPatient(patient)); }
response.put(ShareProtocol.SERVER_JSON_GETINFO_KEY_NAME_UPDATESENABLED, true); response.put(ShareProtocol.SERVER_JSON_GETINFO_KEY_NAME_CONSENTS, this.consentManager.toJSON(this.consentManager.getSystemConsents()));
String consentId = consentsJSON.optString(i); if (consentId != null) { if (!this.consentManager.isValidConsentId(consentId)) { return Response.status(INVALID_CONSENT_ID_CODE).build(); boolean status = this.consentManager.setPatientConsents(security.getPatient(), consentIds); if (status) { return Response.ok().build();
@Override public Response grantConsent(String patientId, String id) { Security security = this.securityCheck(patientId, Right.EDIT); if (security.isAllowed()) { if (!this.consentManager.isValidConsentId(id)) { return Response.status(INVALID_CONSENT_ID_CODE).build(); } boolean status = this.consentManager.grantConsent(security.getPatient(), id); if (status) { return Response.ok().build(); } else { return Response.serverError().build(); } } else { return security.getFailResponse(); } }
@Override public Response revokeConsent(String patientId, String id) { Security security = this.securityCheck(patientId, Right.EDIT); if (security.isAllowed()) { if (!this.consentManager.isValidConsentId(id)) { return Response.status(INVALID_CONSENT_ID_CODE).build(); } boolean status = this.consentManager.revokeConsent(security.getPatient(), id); if (status) { return Response.ok().build(); } else { return Response.serverError().build(); } } else { return security.getFailResponse(); } }
this.consentManager.setPatientConsents(affectedPatient, consentIds);
/** * Checks if a specific consent is given for the patient record. If consentId is not configured in the system * returns {@code false} regardless of patient consent status. * * @param patientId record in which to test consent * @param consentId of consent which is to be checked * @return {@code true} if the consent was granted for the patient, otherwise {@code false} */ public boolean hasConsent(String patientId, String consentId) { return this.consentManager.hasConsent(patientId, consentId); }
/** * Checks if a specific consent is given for the patient record. If consentId is not configured in the system * returns {@code false} regardless of patient consent status. * * @param patientId record in which to test consent * @param consentId of consent which is to be checked * @return {@code true} if the consent was granted for the patient, otherwise {@code false} */ public boolean hasConsent(String patientId, String consentId) { return this.consentManager.hasConsent(patientId, consentId); }
/** * Returns the list of all consents configured in the system, with "granted"/"not granted" status for the given * patient for each consent. * * @param patientId record on which consents are granted (or not granted) * @return All the consents configured in the system with granted (for the patient) status set for each. Returns * null if patientId is not a valid id. */ public JSONArray getAllConsentsForPatient(String patientId) { try { return this.consentManager.toJSON(this.consentManager.getAllConsentsForPatient(patientId)); } catch (Exception ex) { return null; } } }
@Override public boolean consentsGloballyEnabled() { return !this.consentManager.getSystemConsents().isEmpty(); }
@Override public boolean authorizeInteraction(Patient patient) { return (patient != null) && this.containsRequiredConsents(this.consentManager.getMissingConsentsForPatient(patient)); }
@Override public Response getConsents(String patientId) { this.logger.debug("Retrieving consents from patient record [{}] via REST", patientId); Security security = this.securityCheck(patientId, Right.VIEW); if (security.isAllowed()) { Set<Consent> consents = this.consentManager.getAllConsentsForPatient(security.getPatient()); JSONArray json = this.consentManager.toJSON(consents); return Response.ok(json, MediaType.APPLICATION_JSON_TYPE).build(); } else { return security.getFailResponse(); } }
@Override public boolean authorizeInteraction(Set<String> grantedConsents) { Set<Consent> systemConsents = this.consentManager.getSystemConsents(); if (CollectionUtils.isEmpty(systemConsents)) { return true; } if (CollectionUtils.isEmpty(grantedConsents)) { return containsRequiredConsents(systemConsents); } Set<Consent> missingConsents = new HashSet<>(); for (Consent consent : systemConsents) { if (!grantedConsents.contains(consent.getId())) { missingConsents.add(consent); } } return containsRequiredConsents(missingConsents); }
@Override public boolean isElementConsented(RecordElement element, Patient patient) { Set<Consent> missingConsents = this.consentManager.getMissingConsentsForPatient(patient); return this.isElementEnabled(element, this.getNonConsentedFieldSet(missingConsents)); }
@Override public boolean authorizeInteraction(Set<String> grantedConsents) { Set<Consent> systemConsents = this.consentManager.getSystemConsents(); if (CollectionUtils.isEmpty(systemConsents)) { return true; } if (CollectionUtils.isEmpty(grantedConsents)) { return containsRequiredConsents(systemConsents); } Set<Consent> missingConsents = new HashSet<>(); for (Consent consent : systemConsents) { if (!grantedConsents.contains(consent.getId())) { missingConsents.add(consent); } } return containsRequiredConsents(missingConsents); }
@Override public boolean isElementConsented(RecordElement element, Patient patient) { Set<Consent> missingConsents = this.consentManager.getMissingConsentsForPatient(patient); return this.isElementEnabled(element, this.getNonConsentedFieldSet(missingConsents)); }
@Override public List<RecordElement> filterForm(List<RecordElement> elements, Patient patient) { if (CollectionUtils.isEmpty(elements)) { return Collections.emptyList(); } if (!this.consentsGloballyEnabled() || patient == null) { return elements; } Set<Consent> missingConsents = this.consentManager.getMissingConsentsForPatient(patient); // If !containsRequiredConsents(missingConsents) is true, then one of the consents is mandatory, which means // that no sections should be displayed; missingConsents will only be null if patient is null. if (missingConsents == null || !containsRequiredConsents(missingConsents)) { return Collections.emptyList(); } Set<String> nonConsentedFields = this.getNonConsentedFieldSet(missingConsents); List<RecordElement> updatedElements = new LinkedList<>(); for (RecordElement element : elements) { if (this.isElementEnabled(element, nonConsentedFields)) { updatedElements.add(element); } } return updatedElements; }
@Override public List<RecordElement> filterForm(List<RecordElement> elements, Patient patient) { if (CollectionUtils.isEmpty(elements)) { return Collections.emptyList(); } if (!this.consentsGloballyEnabled() || patient == null) { return elements; } Set<Consent> missingConsents = this.consentManager.getMissingConsentsForPatient(patient); // If !containsRequiredConsents(missingConsents) is true, then one of the consents is mandatory, which means // that no sections should be displayed; missingConsents will only be null if patient is null. if (missingConsents == null || !containsRequiredConsents(missingConsents)) { return Collections.emptyList(); } Set<String> nonConsentedFields = this.getNonConsentedFieldSet(missingConsents); List<RecordElement> updatedElements = new LinkedList<>(); for (RecordElement element : elements) { if (this.isElementEnabled(element, nonConsentedFields)) { updatedElements.add(element); } } return updatedElements; }