private static List<String> convertToIds(List<Consent> consents) { List<String> ids = new LinkedList<>(); for (Consent consent : consents) { ids.add(consent.getId()); } return ids; }
private static List<String> convertToIds(List<Consent> consents) { List<String> ids = new LinkedList<>(); for (Consent consent : consents) { ids.add(consent.getId()); } return ids; }
@Override public boolean isValidConsentId(String consentId) { Set<Consent> systemConsents = getSystemConsents(); for (Consent consent : systemConsents) { if (StringUtils.equals(consentId, consent.getId())) { return true; } } return false; }
@Override public boolean isValidConsentId(String consentId) { Set<Consent> systemConsents = getSystemConsents(); for (Consent consent : systemConsents) { if (StringUtils.equals(consentId, consent.getId())) { return true; } } return false; }
/** @return consents that exist in the system and correspond to the given ids */ private List<Consent> selectFromSystem(Iterable<String> ids) { List<Consent> existingConsents = new LinkedList<>(); for (String id : ids) { for (Consent consent : this.getSystemConsents()) { if (StringUtils.equals(consent.getId(), id)) { existingConsents.add(consent); break; } } } return existingConsents; }
/** * @return consents that exist in the system and correspond to the given ids */ private List<Consent> selectFromSystem(Iterable<String> ids) { List<Consent> existingConsents = new LinkedList<>(); for (String id : ids) { for (Consent consent : this.getSystemConsents()) { if (StringUtils.equals(consent.getId(), id)) { existingConsents.add(consent); break; } } } return existingConsents; }
@Override public boolean hasConsent(Patient patient, String consentId) { if (patient == null || !isValidConsentId(consentId)) { return false; } Set<Consent> missingPatientConsents = getMissingConsentsForPatient(patient); if (missingPatientConsents == null) { return false; } for (Consent consent : missingPatientConsents) { if (consent.getId().equals(consentId)) { return false; } } return true; }
@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 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 hasConsent(Patient patient, String consentId) { if (patient == null || !isValidConsentId(consentId)) { return false; } Set<Consent> missingPatientConsents = getMissingConsentsForPatient(patient); if (missingPatientConsents == null) { return false; } for (Consent consent : missingPatientConsents) { if (consent.getId().equals(consentId)) { return false; } } return true; }
private Set<Consent> getConsentsForPatient(Patient patient, boolean includeGranted) { if (patient == null) { return null; } // List of consent ids a patient has agreed to, read from the database Set<String> xwikiPatientConsents = readConsentIdsFromPatientDoc(patient); Set<Consent> returnedConsents = new LinkedHashSet<>(); // Using system consents to ignore consents set for the patient but no longer configured in the system // (it is faster to check contains() in a set, so iterating through the list and checking the set) Set<Consent> systemConsents = getSystemConsents(); for (Consent systemConsent : systemConsents) { if (xwikiPatientConsents.contains(systemConsent.getId())) { if (includeGranted) { Consent copy = systemConsent.copy(ConsentStatus.YES); returnedConsents.add(copy); } } else { Consent copy = systemConsent.copy(ConsentStatus.NO); returnedConsents.add(copy); } } return returnedConsents; }
private Set<Consent> getConsentsForPatient(Patient patient, boolean includeGranted) { if (patient == null) { return null; } // List of consent ids a patient has agreed to, read from the database Set<String> xwikiPatientConsents = readConsentIdsFromPatientDoc(patient); Set<Consent> returnedConsents = new LinkedHashSet<>(); // Using system consents to ignore consents set for the patient but no longer configured in the system // (it is faster to check contains() in a set, so iterating through the list and checking the set) Set<Consent> systemConsents = getSystemConsents(); for (Consent systemConsent : systemConsents) { if (xwikiPatientConsents.contains(systemConsent.getId())) { if (includeGranted) { Consent copy = systemConsent.copy(ConsentStatus.YES); returnedConsents.add(copy); } } else { Consent copy = systemConsent.copy(ConsentStatus.NO); returnedConsents.add(copy); } } return returnedConsents; }