@Test public void filterFormHasRequiredConsents() { final RecordElement recordElementA = mock(UIXRecordElement.class); final RecordElement recordElementB = mock(UIXRecordElement.class); final RecordElement recordElementC = mock(UIXRecordElement.class); final Set<Consent> consents = new HashSet<>(); consents.add(this.consentA); consents.add(this.consentB); when(this.consentB.isRequired()).thenReturn(true); when(this.consentManager.getMissingConsentsForPatient(this.patient)).thenReturn(consents); when(this.consentManager.getSystemConsents()).thenReturn(consents); final List<RecordElement> elements = Arrays.asList(recordElementA, recordElementB, recordElementC); final List<RecordElement> enabledElements = this.component.filterForm(elements, this.patient); Assert.assertTrue(enabledElements.isEmpty()); }
@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 (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; }
DefaultConsentAuthorizer implements ConsentAuthorizer { @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 (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; } }
DefaultConsentAuthorizer implements ConsentAuthorizer { @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 (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; }  }
DefaultConsentAuthorizer implements ConsentAuthorizer { @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 (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 boolean consentsGloballyEnabled(); @Override List<RecordElement> filterForm(List<RecordElement> elements, Patient patient); @Override boolean authorizeInteraction(Patient patient); @Override boolean authorizeInteraction(Set<String> grantedConsents); @Override boolean isElementConsented(RecordElement element, Patient patient); }
DefaultConsentAuthorizer implements ConsentAuthorizer { @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 (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 boolean consentsGloballyEnabled(); @Override List<RecordElement> filterForm(List<RecordElement> elements, Patient patient); @Override boolean authorizeInteraction(Patient patient); @Override boolean authorizeInteraction(Set<String> grantedConsents); @Override boolean isElementConsented(RecordElement element, Patient patient);  }