@Test public void afterProcessOnlyConsentedSectionsRemain() throws ComponentLookupException { final UIExtension sectionExtensionA = mock(UIExtension.class); final UIExtension sectionExtensionB = mock(UIExtension.class); final UIExtension sectionExtensionC = mock(UIExtension.class); final UIExtensionManager uixManager = mock(UIExtensionManager.class); final UIExtensionFilter orderFilter = mock(UIExtensionFilter.class, new ReturnsArgumentAt(0)); when(sectionExtensionA.getId()).thenReturn(SECTION_A_LABEL); when(sectionExtensionB.getId()).thenReturn(SECTION_B_LABEL); when(sectionExtensionC.getId()).thenReturn(SECTION_C_LABEL); final UIExtension fieldExtensionA = mock(UIExtension.class); final List<UIExtension> fieldsA = Collections.singletonList(fieldExtensionA); when(fieldExtensionA.getId()).thenReturn(FIELD_A_LABEL); when(uixManager.get(SECTION_A_LABEL)).thenReturn(fieldsA); final UIExtension fieldExtensionB1 = mock(UIExtension.class); final UIExtension fieldExtensionB2 = mock(UIExtension.class); final List<UIExtension> fieldsB = Arrays.asList(fieldExtensionB1, fieldExtensionB2); when(fieldExtensionB1.getId()).thenReturn(FIELD_B1_LABEL); when(fieldExtensionB2.getId()).thenReturn(FIELD_B2_LABEL); when(uixManager.get(SECTION_B_LABEL)).thenReturn(fieldsB); final UIExtension fieldExtensionC = mock(UIExtension.class); final List<UIExtension> fieldsC = Collections.singletonList(fieldExtensionC); when(fieldExtensionC.getId()).thenReturn(FIELD_C_LABEL); when(uixManager.get(SECTION_C_LABEL)).thenReturn(fieldsC); final RecordSection sectionA = new UIXRecordSection(sectionExtensionA, uixManager, orderFilter); final RecordSection sectionB = new UIXRecordSection(sectionExtensionB, uixManager, orderFilter); final RecordSection sectionC = new UIXRecordSection(sectionExtensionC, uixManager, orderFilter); when(this.config.getAllSections()).thenReturn(Arrays.asList(sectionA, sectionB, sectionC)); when(this.config.getEnabledSections()).thenCallRealMethod(); Assert.assertEquals(3, this.config.getEnabledSections().size()); Assert.assertEquals(1, this.config.getEnabledSections().get(0).getEnabledElements().size()); Assert.assertEquals(2, this.config.getEnabledSections().get(1).getEnabledElements().size()); Assert.assertEquals(1, this.config.getEnabledSections().get(2).getEnabledElements().size()); Assert.assertTrue(sectionA.isEnabled()); Assert.assertTrue(sectionA.getAllElements().get(0).isEnabled()); Assert.assertTrue(sectionB.isEnabled()); Assert.assertTrue(sectionB.getAllElements().get(0).isEnabled()); Assert.assertTrue(sectionB.getAllElements().get(1).isEnabled()); Assert.assertTrue(sectionC.isEnabled()); Assert.assertTrue(sectionC.getAllElements().get(0).isEnabled()); when(this.consentAuthorizer.filterForm(sectionA.getEnabledElements(), this.patient)) .thenReturn(Collections.emptyList()); when(this.consentAuthorizer.filterForm(sectionB.getEnabledElements(), this.patient)) .thenReturn(sectionB.getEnabledElements().subList(1, 2)); when(this.consentAuthorizer.filterForm(sectionC.getEnabledElements(), this.patient)) .thenReturn(Collections.emptyList()); Assert.assertSame(this.config, this.mocker.getComponentUnderTest().process(this.config)); Assert.assertEquals(1, this.config.getEnabledSections().size()); Assert.assertEquals(1, this.config.getEnabledSections().get(0).getEnabledElements().size()); Assert.assertEquals(0, sectionA.getEnabledElements().size()); Assert.assertEquals(1, sectionA.getAllElements().size()); Assert.assertFalse(sectionA.getAllElements().get(0).isEnabled()); Assert.assertEquals(1, sectionB.getEnabledElements().size()); Assert.assertEquals(2, sectionB.getAllElements().size()); Assert.assertFalse(sectionB.getAllElements().get(0).isEnabled()); Assert.assertTrue(sectionB.getAllElements().get(1).isEnabled()); Assert.assertEquals(0, sectionC.getEnabledElements().size()); Assert.assertEquals(1, sectionC.getAllElements().size()); Assert.assertFalse(sectionC.getAllElements().get(0).isEnabled()); Assert.assertFalse(sectionA.isEnabled()); Assert.assertTrue(sectionB.isEnabled()); Assert.assertFalse(sectionC.isEnabled()); }
@Override public RecordConfiguration process(RecordConfiguration config) { if (config == null || this.dab.getCurrentDocumentReference() == null) { return config; } final Patient patient = this.patients.get(this.dab.getCurrentDocumentReference()); if (patient == null) { return config; } for (final RecordSection section : config.getEnabledSections()) { final List<RecordElement> enabledElements = Collections.unmodifiableList(section.getEnabledElements()); final List<RecordElement> consentedElements = this.consentAuthorizer.filterForm(enabledElements, patient); disableNonConsentedElements(enabledElements, consentedElements); disableSectionIfNoEnabledElements(section); } return config; }
ConsentsRecordConfigurationModule implements RecordConfigurationModule { @Override public RecordConfiguration process(RecordConfiguration config) { if (config == null || this.dab.getCurrentDocumentReference() == null) { return config; } final Patient patient = this.patients.get(this.dab.getCurrentDocumentReference()); if (patient == null) { return config; } for (final RecordSection section : config.getEnabledSections()) { final List<RecordElement> enabledElements = Collections.unmodifiableList(section.getEnabledElements()); final List<RecordElement> consentedElements = this.consentAuthorizer.filterForm(enabledElements, patient); disableNonConsentedElements(enabledElements, consentedElements); disableSectionIfNoEnabledElements(section); } return config; } }
ConsentsRecordConfigurationModule implements RecordConfigurationModule { @Override public RecordConfiguration process(RecordConfiguration config) { if (config == null || this.dab.getCurrentDocumentReference() == null) { return config; } final Patient patient = this.patients.get(this.dab.getCurrentDocumentReference()); if (patient == null) { return config; } for (final RecordSection section : config.getEnabledSections()) { final List<RecordElement> enabledElements = Collections.unmodifiableList(section.getEnabledElements()); final List<RecordElement> consentedElements = this.consentAuthorizer.filterForm(enabledElements, patient); disableNonConsentedElements(enabledElements, consentedElements); disableSectionIfNoEnabledElements(section); } return config; }  }
ConsentsRecordConfigurationModule implements RecordConfigurationModule { @Override public RecordConfiguration process(RecordConfiguration config) { if (config == null || this.dab.getCurrentDocumentReference() == null) { return config; } final Patient patient = this.patients.get(this.dab.getCurrentDocumentReference()); if (patient == null) { return config; } for (final RecordSection section : config.getEnabledSections()) { final List<RecordElement> enabledElements = Collections.unmodifiableList(section.getEnabledElements()); final List<RecordElement> consentedElements = this.consentAuthorizer.filterForm(enabledElements, patient); disableNonConsentedElements(enabledElements, consentedElements); disableSectionIfNoEnabledElements(section); } return config; }  @Override RecordConfiguration process(RecordConfiguration config); @Override int getPriority(); @Override boolean supportsRecordType(String recordType); }
ConsentsRecordConfigurationModule implements RecordConfigurationModule { @Override public RecordConfiguration process(RecordConfiguration config) { if (config == null || this.dab.getCurrentDocumentReference() == null) { return config; } final Patient patient = this.patients.get(this.dab.getCurrentDocumentReference()); if (patient == null) { return config; } for (final RecordSection section : config.getEnabledSections()) { final List<RecordElement> enabledElements = Collections.unmodifiableList(section.getEnabledElements()); final List<RecordElement> consentedElements = this.consentAuthorizer.filterForm(enabledElements, patient); disableNonConsentedElements(enabledElements, consentedElements); disableSectionIfNoEnabledElements(section); } return config; }  @Override RecordConfiguration process(RecordConfiguration config); @Override int getPriority(); @Override boolean supportsRecordType(String recordType);  }