DocumentRedactorImpl implements DocumentRedactor { @Override public RedactedDocument redactDocument(String document, RuleExecutionContainer ruleExecutionContainer, FactModel factModel) { Document xmlDocument = null; String tryPolicyDocument = null; final List<Node> redactNodeList = new LinkedList<Node>(); final Set<String> redactSectionCodesAndGeneratedEntryIds = new HashSet<String>(); final Set<String> redactSectionSet = new HashSet<String>(); final Set<String> redactCategorySet = new HashSet<String>(); final XacmlResult xacmlResult = factModel.getXacmlResult(); try { xmlDocument = documentXmlConverter.loadDocument(document); final Document factModelDocument = documentXmlConverter .loadDocument(marshaller.marshal(factModel)); for (final AbstractDocumentLevelRedactionHandler documentLevelRedactionHandler : documentLevelRedactionHandlers) { documentLevelRedactionHandler.execute(xmlDocument, redactSectionCodesAndGeneratedEntryIds, redactNodeList); } for (final String obligation : xacmlResult.getPdpObligations()) { for (final AbstractObligationLevelRedactionHandler obligationLevelRedactionHandler : obligationLevelRedactionHandlers) { obligationLevelRedactionHandler.execute(xmlDocument, xacmlResult, factModel, factModelDocument, ruleExecutionContainer, redactNodeList, redactSectionCodesAndGeneratedEntryIds, redactSectionSet, obligation); } } for (final ClinicalFact fact : factModel.getClinicalFactList()) { for (final AbstractClinicalFactLevelRedactionHandler clinicalFactLevelRedactionHandler : clinicalFactLevelRedactionHandlers) { clinicalFactLevelRedactionHandler.execute(xmlDocument, xacmlResult, factModel, factModelDocument, fact, ruleExecutionContainer, redactNodeList, redactSectionCodesAndGeneratedEntryIds, redactCategorySet); } } tryPolicyDocument = documentXmlConverter .convertXmlDocToString(xmlDocument); for (final Node nodeToBeReadacted : redactNodeList) { redactNodeIfNotNull(nodeToBeReadacted); } for (final AbstractPostRedactionLevelRedactionHandler postRedactionRedactionHandler : postRedactionLevelRedactionHandlers) { postRedactionRedactionHandler.execute(xmlDocument, xacmlResult, factModel, factModelDocument, ruleExecutionContainer, redactNodeList, redactSectionCodesAndGeneratedEntryIds); } document = documentXmlConverter.convertXmlDocToString(xmlDocument); } catch (final Exception e) { logger.error(e.getMessage(), e); throw new DS4PException(e.toString(), e); } return new RedactedDocument(document, tryPolicyDocument, redactSectionSet, redactCategorySet); } DocumentRedactorImpl(
			SimpleMarshaller marshaller,
			DocumentXmlConverter documentXmlConverter,
			DocumentAccessor documentAccessor,
			Set<AbstractDocumentLevelRedactionHandler> documentLevelRedactionHandlers,
			Set<AbstractObligationLevelRedactionHandler> obligationLevelRedactionHandlers,
			Set<AbstractClinicalFactLevelRedactionHandler> clinicalFactLevelRedactionHandlers,
			Set<AbstractPostRedactionLevelRedactionHandler> postRedactionLevelRedactionHandlers); @Override String cleanUpEmbeddedClinicalDocumentFromFactModel(
			String factModelXml); @Override String cleanUpGeneratedEntryIds(String document); @Override String cleanUpGeneratedServiceEventIds(String document); @Override RedactedDocument redactDocument(String document,
			RuleExecutionContainer ruleExecutionContainer, FactModel factModel);  }
@Test public void testRedactDocument() throws Throwable { initDocumentRedactorWithActualServices(); String factModelXml = factModelExtractor.extractFactModel(c32, MOCK_XACML_RESULT); c32 = embeddedClinicalDocumentExtractor .extractClinicalDocumentFromFactModel(factModelXml); factModelXml = removeEmbeddedClinicalDocument(factModelXml); final FactModel factModel = marshaller.unmarshalFromXml( FactModel.class, factModelXml); setValueSetCategories(factModel); factModel.setXacmlResult(xacmlResultMock); final String result = documentRedactor.redactDocument(c32, ruleExecutionContainer, factModel).getRedactedDocument(); logger.debug("RESULT--> " + result); assertTrue(c32 .contains("e11275e7-67ae-11db-bd13-0800200c9a66b827vs52h7")); assertTrue(c32.contains("d11275e7-67ae-11db-bd13-0800200c9a66")); assertTrue(!result .contains("e11275e7-67ae-11db-bd13-0800200c9a66b827vs52h7")); assertTrue(!result.contains("d11275e7-67ae-11db-bd13-0800200c9a66")); }
@Test public void testRedactDocument_Allergies_Medications_Results_Sections_Hiv_Eth_Redacted() throws Throwable { final String problems = NOT_SELECTED; final String allergies = ALLERGIES_SECTION; final String medications = MEDICATIONS_SECTION; final String results = RESULTS_SECTION; final String hiv = HIV_SELECTED; final String psy = NOT_SELECTED; final String eth = ETH_SELECTED; final String gdis = NOT_SELECTED; final String sdv = NOT_SELECTED; final String sex = NOT_SELECTED; final String std = NOT_SELECTED; initDocumentRedactorWithActualServices(); final RuleExecutionContainer ruleExecutionContainer = ruleExecutionContainerWithHivEth; final XacmlResult xacmlResultObj = initXacmlResult(problems, allergies, medications, results, hiv, psy, eth, gdis, sdv, sex, std); String factModelXml = factModelExtractor.extractFactModel(c32, marshaller.marshal(xacmlResultObj)); c32 = embeddedClinicalDocumentExtractor .extractClinicalDocumentFromFactModel(factModelXml); factModelXml = removeEmbeddedClinicalDocument(factModelXml); final FactModel factModel = marshaller.unmarshalFromXml( FactModel.class, factModelXml); setValueSetCategories(factModel); final String ethObservationId = "e11275e7-67ae-11db-bd13-0800200c9a66b827vs52h7"; final String hivObservationId = "d11275e7-67ae-11db-bd13-0800200c9a66"; factModel.setXacmlResult(xacmlResultObj); final String redactedC32 = documentRedactor.redactDocument(c32, ruleExecutionContainer, factModel).getRedactedDocument(); assertNotNull(getSectionElement(c32, PROBLEMS_SECTION)); assertNotNull(getSectionElement(c32, ALLERGIES_SECTION)); assertNotNull(getSectionElement(c32, MEDICATIONS_SECTION)); assertNotNull(getSectionElement(c32, RESULTS_SECTION)); assertNotNull(getSectionElement(redactedC32, PROBLEMS_SECTION)); assertNull(getSectionElement(redactedC32, ALLERGIES_SECTION)); assertNull(getSectionElement(redactedC32, MEDICATIONS_SECTION)); assertNull(getSectionElement(redactedC32, RESULTS_SECTION)); assertNull(getEntryElement(redactedC32, ethObservationId)); assertNull(getEntryElement(redactedC32, hivObservationId)); }
@Test public void testRedactDocument_Allergies_Medications_Results_Sections_Redacted() throws Throwable { final String problems = NOT_SELECTED; final String allergies = ALLERGIES_SECTION; final String medications = MEDICATIONS_SECTION; final String results = RESULTS_SECTION; final String hiv = NOT_SELECTED; final String psy = NOT_SELECTED; final String eth = NOT_SELECTED; final String gdis = NOT_SELECTED; final String sdv = NOT_SELECTED; final String sex = NOT_SELECTED; final String std = NOT_SELECTED; initDocumentRedactorWithActualServices(); final RuleExecutionContainer ruleExecutionContainer = initRuleExecutionContainer(); final XacmlResult xacmlResultObj = initXacmlResult(problems, allergies, medications, results, hiv, psy, eth, gdis, sdv, sex, std); String factModelXml = factModelExtractor.extractFactModel(robustC32, marshaller.marshal(xacmlResultObj)); robustC32 = embeddedClinicalDocumentExtractor .extractClinicalDocumentFromFactModel(factModelXml); factModelXml = removeEmbeddedClinicalDocument(factModelXml); final FactModel factModel = marshaller.unmarshalFromXml( FactModel.class, factModelXml); setValueSetCategories(factModel); factModel.setXacmlResult(xacmlResultObj); final String redactedC32 = documentRedactor.redactDocument(robustC32, ruleExecutionContainer, factModel).getRedactedDocument(); assertNotNull(getSectionElement(robustC32, PROBLEMS_SECTION)); assertNotNull(getSectionElement(robustC32, ALLERGIES_SECTION)); assertNotNull(getSectionElement(robustC32, MEDICATIONS_SECTION)); assertNotNull(getSectionElement(robustC32, RESULTS_SECTION)); assertNotNull(getSectionElement(redactedC32, PROBLEMS_SECTION)); assertNull(getSectionElement(redactedC32, ALLERGIES_SECTION)); assertNull(getSectionElement(redactedC32, MEDICATIONS_SECTION)); assertNull(getSectionElement(redactedC32, RESULTS_SECTION)); }
@Test public void testRedactDocument_Allergies_Medications_Results_Sections_Redacted_Hiv_Eth_NotRedacted() throws Throwable { final String problems = NOT_SELECTED; final String allergies = ALLERGIES_SECTION; final String medications = MEDICATIONS_SECTION; final String results = RESULTS_SECTION; final String hiv = NOT_SELECTED; final String psy = NOT_SELECTED; final String eth = NOT_SELECTED; final String gdis = NOT_SELECTED; final String sdv = NOT_SELECTED; final String sex = NOT_SELECTED; final String std = NOT_SELECTED; initDocumentRedactorWithActualServices(); final RuleExecutionContainer ruleExecutionContainer = initRuleExecutionContainer(); final XacmlResult xacmlResultObj = initXacmlResult(problems, allergies, medications, results, hiv, psy, eth, gdis, sdv, sex, std); final String ethObservationId = "e11275e7-67ae-11db-bd13-0800200c9a66b827vs52h7"; final String hivObservationId = "d11275e7-67ae-11db-bd13-0800200c9a66"; String factModelXml = factModelExtractor.extractFactModel(c32, marshaller.marshal(xacmlResultObj)); c32 = embeddedClinicalDocumentExtractor .extractClinicalDocumentFromFactModel(factModelXml); factModelXml = removeEmbeddedClinicalDocument(factModelXml); final FactModel factModel = marshaller.unmarshalFromXml( FactModel.class, factModelXml); setValueSetCategories(factModel); factModel.setXacmlResult(xacmlResultObj); final String redactedC32 = documentRedactor.redactDocument(c32, ruleExecutionContainer, factModel).getRedactedDocument(); assertNotNull(getSectionElement(c32, PROBLEMS_SECTION)); assertNotNull(getSectionElement(c32, ALLERGIES_SECTION)); assertNotNull(getSectionElement(c32, MEDICATIONS_SECTION)); assertNotNull(getSectionElement(c32, RESULTS_SECTION)); assertNotNull(getSectionElement(redactedC32, PROBLEMS_SECTION)); assertNull(getSectionElement(redactedC32, ALLERGIES_SECTION)); assertNull(getSectionElement(redactedC32, MEDICATIONS_SECTION)); assertNull(getSectionElement(redactedC32, RESULTS_SECTION)); assertNotNull(getEntryElement(redactedC32, ethObservationId)); assertNotNull(getEntryElement(redactedC32, hivObservationId)); }
@Test public void testRedactDocument_Allergies_Section_Redacted() throws Throwable { final String problems = NOT_SELECTED; final String allergies = ALLERGIES_SECTION; final String medications = NOT_SELECTED; final String results = NOT_SELECTED; final String hiv = NOT_SELECTED; final String psy = NOT_SELECTED; final String eth = NOT_SELECTED; final String gdis = NOT_SELECTED; final String sdv = NOT_SELECTED; final String sex = NOT_SELECTED; final String std = NOT_SELECTED; initDocumentRedactorWithActualServices(); final RuleExecutionContainer ruleExecutionContainer = initRuleExecutionContainer(); final XacmlResult xacmlResultObj = initXacmlResult(problems, allergies, medications, results, hiv, psy, eth, gdis, sdv, sex, std); String factModelXml = factModelExtractor.extractFactModel(robustC32, marshaller.marshal(xacmlResultObj)); robustC32 = embeddedClinicalDocumentExtractor .extractClinicalDocumentFromFactModel(factModelXml); factModelXml = removeEmbeddedClinicalDocument(factModelXml); final FactModel factModel = marshaller.unmarshalFromXml( FactModel.class, factModelXml); setValueSetCategories(factModel); factModel.setXacmlResult(xacmlResultObj); final String redactedC32 = documentRedactor.redactDocument(robustC32, ruleExecutionContainer, factModel).getRedactedDocument(); assertNotNull(getSectionElement(robustC32, PROBLEMS_SECTION)); assertNotNull(getSectionElement(robustC32, ALLERGIES_SECTION)); assertNotNull(getSectionElement(robustC32, MEDICATIONS_SECTION)); assertNotNull(getSectionElement(robustC32, RESULTS_SECTION)); assertNotNull(getSectionElement(redactedC32, PROBLEMS_SECTION)); assertNull(getSectionElement(redactedC32, ALLERGIES_SECTION)); assertNotNull(getSectionElement(redactedC32, MEDICATIONS_SECTION)); assertNotNull(getSectionElement(redactedC32, RESULTS_SECTION)); }
@Test public void testRedactDocument_Medications_Section_Redacted() throws Throwable { final String problems = NOT_SELECTED; final String allergies = NOT_SELECTED; final String medications = MEDICATIONS_SECTION; final String results = NOT_SELECTED; final String hiv = NOT_SELECTED; final String psy = NOT_SELECTED; final String eth = NOT_SELECTED; final String gdis = NOT_SELECTED; final String sdv = NOT_SELECTED; final String sex = NOT_SELECTED; final String std = NOT_SELECTED; initDocumentRedactorWithActualServices(); final RuleExecutionContainer ruleExecutionContainer = initRuleExecutionContainer(); final XacmlResult xacmlResultObj = initXacmlResult(problems, allergies, medications, results, hiv, psy, eth, gdis, sdv, sex, std); String factModelXml = factModelExtractor.extractFactModel(robustC32, marshaller.marshal(xacmlResultObj)); robustC32 = embeddedClinicalDocumentExtractor .extractClinicalDocumentFromFactModel(factModelXml); factModelXml = removeEmbeddedClinicalDocument(factModelXml); final FactModel factModel = marshaller.unmarshalFromXml( FactModel.class, factModelXml); setValueSetCategories(factModel); factModel.setXacmlResult(xacmlResultObj); final String redactedC32 = documentRedactor.redactDocument(robustC32, ruleExecutionContainer, factModel).getRedactedDocument(); assertNotNull(getSectionElement(robustC32, PROBLEMS_SECTION)); assertNotNull(getSectionElement(robustC32, ALLERGIES_SECTION)); assertNotNull(getSectionElement(robustC32, MEDICATIONS_SECTION)); assertNotNull(getSectionElement(robustC32, RESULTS_SECTION)); assertNotNull(getSectionElement(redactedC32, PROBLEMS_SECTION)); assertNotNull(getSectionElement(redactedC32, ALLERGIES_SECTION)); assertNull(getSectionElement(redactedC32, MEDICATIONS_SECTION)); assertNotNull(getSectionElement(redactedC32, RESULTS_SECTION)); }
@Test public void testRedactDocument_Problems_Allergies_Sections_Redacted() throws Throwable { final String problems = PROBLEMS_SECTION; final String allergies = ALLERGIES_SECTION; final String medications = NOT_SELECTED; final String results = NOT_SELECTED; final String hiv = NOT_SELECTED; final String psy = NOT_SELECTED; final String eth = NOT_SELECTED; final String gdis = NOT_SELECTED; final String sdv = NOT_SELECTED; final String sex = NOT_SELECTED; final String std = NOT_SELECTED; initDocumentRedactorWithActualServices(); final RuleExecutionContainer ruleExecutionContainer = initRuleExecutionContainer(); final XacmlResult xacmlResultObj = initXacmlResult(problems, allergies, medications, results, hiv, psy, eth, gdis, sdv, sex, std); String factModelXml = factModelExtractor.extractFactModel(robustC32, marshaller.marshal(xacmlResultObj)); robustC32 = embeddedClinicalDocumentExtractor .extractClinicalDocumentFromFactModel(factModelXml); factModelXml = removeEmbeddedClinicalDocument(factModelXml); final FactModel factModel = marshaller.unmarshalFromXml( FactModel.class, factModelXml); setValueSetCategories(factModel); factModel.setXacmlResult(xacmlResultObj); final String redactedC32 = documentRedactor.redactDocument(robustC32, ruleExecutionContainer, factModel).getRedactedDocument(); assertNotNull(getSectionElement(robustC32, PROBLEMS_SECTION)); assertNotNull(getSectionElement(robustC32, ALLERGIES_SECTION)); assertNotNull(getSectionElement(robustC32, MEDICATIONS_SECTION)); assertNotNull(getSectionElement(robustC32, RESULTS_SECTION)); assertNull(getSectionElement(redactedC32, PROBLEMS_SECTION)); assertNull(getSectionElement(redactedC32, ALLERGIES_SECTION)); assertNotNull(getSectionElement(redactedC32, MEDICATIONS_SECTION)); assertNotNull(getSectionElement(redactedC32, RESULTS_SECTION)); }
@Test public void testRedactDocument_Problems_Medications_Sections_Redacted() throws Throwable { final String problems = PROBLEMS_SECTION; final String allergies = NOT_SELECTED; final String medications = MEDICATIONS_SECTION; final String results = NOT_SELECTED; final String hiv = NOT_SELECTED; final String psy = NOT_SELECTED; final String eth = NOT_SELECTED; final String gdis = NOT_SELECTED; final String sdv = NOT_SELECTED; final String sex = NOT_SELECTED; final String std = NOT_SELECTED; initDocumentRedactorWithActualServices(); final RuleExecutionContainer ruleExecutionContainer = initRuleExecutionContainer(); final XacmlResult xacmlResultObj = initXacmlResult(problems, allergies, medications, results, hiv, psy, eth, gdis, sdv, sex, std); String factModelXml = factModelExtractor.extractFactModel(robustC32, marshaller.marshal(xacmlResultObj)); robustC32 = embeddedClinicalDocumentExtractor .extractClinicalDocumentFromFactModel(factModelXml); factModelXml = removeEmbeddedClinicalDocument(factModelXml); final FactModel factModel = marshaller.unmarshalFromXml( FactModel.class, factModelXml); setValueSetCategories(factModel); factModel.setXacmlResult(xacmlResultObj); final String redactedC32 = documentRedactor.redactDocument(robustC32, ruleExecutionContainer, factModel).getRedactedDocument(); assertNotNull(getSectionElement(robustC32, PROBLEMS_SECTION)); assertNotNull(getSectionElement(robustC32, ALLERGIES_SECTION)); assertNotNull(getSectionElement(robustC32, MEDICATIONS_SECTION)); assertNotNull(getSectionElement(robustC32, RESULTS_SECTION)); assertNull(getSectionElement(redactedC32, PROBLEMS_SECTION)); assertNotNull(getSectionElement(redactedC32, ALLERGIES_SECTION)); assertNull(getSectionElement(redactedC32, MEDICATIONS_SECTION)); assertNotNull(getSectionElement(redactedC32, RESULTS_SECTION)); }
@Test public void testRedactDocument_Problems_Results_Sections_Redacted() throws Throwable { final String problems = PROBLEMS_SECTION; final String allergies = NOT_SELECTED; final String medications = NOT_SELECTED; final String results = RESULTS_SECTION; final String hiv = NOT_SELECTED; final String psy = NOT_SELECTED; final String eth = NOT_SELECTED; final String gdis = NOT_SELECTED; final String sdv = NOT_SELECTED; final String sex = NOT_SELECTED; final String std = NOT_SELECTED; initDocumentRedactorWithActualServices(); final RuleExecutionContainer ruleExecutionContainer = initRuleExecutionContainer(); final XacmlResult xacmlResultObj = initXacmlResult(problems, allergies, medications, results, hiv, psy, eth, gdis, sdv, sex, std); String factModelXml = factModelExtractor.extractFactModel(robustC32, marshaller.marshal(xacmlResultObj)); robustC32 = embeddedClinicalDocumentExtractor .extractClinicalDocumentFromFactModel(factModelXml); factModelXml = removeEmbeddedClinicalDocument(factModelXml); final FactModel factModel = marshaller.unmarshalFromXml( FactModel.class, factModelXml); setValueSetCategories(factModel); factModel.setXacmlResult(xacmlResultObj); final String redactedC32 = documentRedactor.redactDocument(robustC32, ruleExecutionContainer, factModel).getRedactedDocument(); assertNotNull(getSectionElement(robustC32, PROBLEMS_SECTION)); assertNotNull(getSectionElement(robustC32, ALLERGIES_SECTION)); assertNotNull(getSectionElement(robustC32, MEDICATIONS_SECTION)); assertNotNull(getSectionElement(robustC32, RESULTS_SECTION)); assertNull(getSectionElement(redactedC32, PROBLEMS_SECTION)); assertNotNull(getSectionElement(redactedC32, ALLERGIES_SECTION)); assertNotNull(getSectionElement(redactedC32, MEDICATIONS_SECTION)); assertNull(getSectionElement(redactedC32, RESULTS_SECTION)); }
@Test public void testRedactDocument_Problems_Section_Redacted() throws Throwable { final String problems = PROBLEMS_SECTION; final String allergies = NOT_SELECTED; final String medications = NOT_SELECTED; final String results = NOT_SELECTED; final String hiv = NOT_SELECTED; final String psy = NOT_SELECTED; final String eth = NOT_SELECTED; final String gdis = NOT_SELECTED; final String sdv = NOT_SELECTED; final String sex = NOT_SELECTED; final String std = NOT_SELECTED; initDocumentRedactorWithActualServices(); final RuleExecutionContainer ruleExecutionContainer = initRuleExecutionContainer(); final XacmlResult xacmlResultObj = initXacmlResult(problems, allergies, medications, results, hiv, psy, eth, gdis, sdv, sex, std); String factModelXml = factModelExtractor.extractFactModel(robustC32, marshaller.marshal(xacmlResultObj)); robustC32 = embeddedClinicalDocumentExtractor .extractClinicalDocumentFromFactModel(factModelXml); factModelXml = removeEmbeddedClinicalDocument(factModelXml); final FactModel factModel = marshaller.unmarshalFromXml( FactModel.class, factModelXml); setValueSetCategories(factModel); factModel.setXacmlResult(xacmlResultObj); final String redactedC32 = documentRedactor.redactDocument(robustC32, ruleExecutionContainer, factModel).getRedactedDocument(); assertNotNull(getSectionElement(robustC32, PROBLEMS_SECTION)); assertNotNull(getSectionElement(robustC32, ALLERGIES_SECTION)); assertNotNull(getSectionElement(robustC32, MEDICATIONS_SECTION)); assertNotNull(getSectionElement(robustC32, RESULTS_SECTION)); assertNull(getSectionElement(redactedC32, PROBLEMS_SECTION)); assertNotNull(getSectionElement(redactedC32, ALLERGIES_SECTION)); assertNotNull(getSectionElement(redactedC32, MEDICATIONS_SECTION)); assertNotNull(getSectionElement(redactedC32, RESULTS_SECTION)); }
@Test public void testRedactDocument_RemC32() throws Throwable { initDocumentRedactorWithActualServices(); String remC32 = fileReader.readFile("testRemC32.xml"); final String remRuleExecutionContainerActual = fileReader .readFile("testRemRuleExecutionContainerActual.xml"); final RuleExecutionContainer remRuleExecutionContainerActualObj = marshaller .unmarshalFromXml(RuleExecutionContainer.class, remRuleExecutionContainerActual); final String remXacmlResult = fileReader .readFile("testRemXacmlResult.xml"); final XacmlResult remXacmlResultObj = marshaller.unmarshalFromXml( XacmlResult.class, remXacmlResult); final String factModelXml = factModelExtractor.extractFactModel(remC32, marshaller.marshal(remXacmlResultObj)); final FactModel factModel = marshaller.unmarshalFromXml( FactModel.class, factModelXml); setValueSetCategories(factModel); remC32 = embeddedClinicalDocumentExtractor .extractClinicalDocumentFromFactModel(factModelXml); final String ethObservationId = "d17e379"; final String hivObservationId = "d17e356"; factModel.setXacmlResult(xacmlResultMock); final String redactedC32 = documentRedactor.redactDocument(remC32, remRuleExecutionContainerActualObj, factModel) .getRedactedDocument(); assertNotNull(getSectionElement(remC32, PROBLEMS_SECTION)); assertNotNull(getSectionElement(remC32, MEDICATIONS_SECTION)); assertNull(getSectionElement(remC32, ALLERGIES_SECTION)); assertNull(getSectionElement(remC32, RESULTS_SECTION)); assertNotNull(getSectionElement(redactedC32, PROBLEMS_SECTION)); assertNotNull(getSectionElement(redactedC32, MEDICATIONS_SECTION)); assertNull(getSectionElement(redactedC32, ALLERGIES_SECTION)); assertNull(getSectionElement(redactedC32, RESULTS_SECTION)); assertNotNull(getEntryElement(remC32, ethObservationId)); assertNotNull(getEntryElement(remC32, hivObservationId)); assertNull(getEntryElement(redactedC32, ethObservationId)); assertNull(getEntryElement(redactedC32, hivObservationId)); assertTrue(getHumanReadableTextNodeList(remC32, "substance abuse") .getLength() > 0); assertTrue(getHumanReadableTextNodeList(remC32, "hiv").getLength() > 0); assertTrue(getHumanReadableTextNodeList(redactedC32, "substance abuse") .getLength() == 0); assertTrue(getHumanReadableTextNodeList(redactedC32, "hiv").getLength() == 0); }
@Test public void testRedactDocument_Results_Section_Redacted() throws Throwable { final String problems = NOT_SELECTED; final String allergies = NOT_SELECTED; final String medications = NOT_SELECTED; final String results = RESULTS_SECTION; final String hiv = NOT_SELECTED; final String psy = NOT_SELECTED; final String eth = NOT_SELECTED; final String gdis = NOT_SELECTED; final String sdv = NOT_SELECTED; final String sex = NOT_SELECTED; final String std = NOT_SELECTED; initDocumentRedactorWithActualServices(); final RuleExecutionContainer ruleExecutionContainer = initRuleExecutionContainer(); final XacmlResult xacmlResultObj = initXacmlResult(problems, allergies, medications, results, hiv, psy, eth, gdis, sdv, sex, std); String factModelXml = factModelExtractor.extractFactModel(robustC32, marshaller.marshal(xacmlResultObj)); robustC32 = embeddedClinicalDocumentExtractor .extractClinicalDocumentFromFactModel(factModelXml); factModelXml = removeEmbeddedClinicalDocument(factModelXml); final FactModel factModel = marshaller.unmarshalFromXml( FactModel.class, factModelXml); setValueSetCategories(factModel); factModel.setXacmlResult(xacmlResultObj); final String redactedC32 = documentRedactor.redactDocument(robustC32, ruleExecutionContainer, factModel).getRedactedDocument(); assertNotNull(getSectionElement(robustC32, PROBLEMS_SECTION)); assertNotNull(getSectionElement(robustC32, ALLERGIES_SECTION)); assertNotNull(getSectionElement(robustC32, MEDICATIONS_SECTION)); assertNotNull(getSectionElement(robustC32, RESULTS_SECTION)); assertNotNull(getSectionElement(redactedC32, PROBLEMS_SECTION)); assertNotNull(getSectionElement(redactedC32, ALLERGIES_SECTION)); assertNotNull(getSectionElement(redactedC32, MEDICATIONS_SECTION)); assertNull(getSectionElement(redactedC32, RESULTS_SECTION)); }
@Test(expected = DS4PException.class) public void testRedactDocument_Throws_DS4PException() { @SuppressWarnings("unused") final String result = documentRedactor.redactDocument("", null, new FactModel()).getRedactedDocument(); }
@Test public void testRedactDocument_WrongSensitivityInContainer() throws Exception { initDocumentRedactorWithActualServices(); final String xacmlResultWithWrongObligations = MOCK_XACML_RESULT .replace("<pdpObligation>Drug Abuse</pdpObligation>", "") .replace("<pdpObligation>HIV</pdpObligation>", ""); final XacmlResult xacmlResult = setMockXacmlResult(xacmlResultWithWrongObligations); String factModelXml = factModelExtractor.extractFactModel(c32, xacmlResultWithWrongObligations); c32 = embeddedClinicalDocumentExtractor .extractClinicalDocumentFromFactModel(factModelXml); factModelXml = removeEmbeddedClinicalDocument(factModelXml); final FactModel factModel = marshaller.unmarshalFromXml( FactModel.class, factModelXml); setValueSetCategories(factModel); factModel.setXacmlResult(xacmlResult); final String result = documentRedactor.redactDocument(c32, setRuleExecutionContainer_WrongSensitivity(), factModel) .getRedactedDocument(); logger.debug("RESULT--> " + result); assertTrue(c32 .contains("e11275e7-67ae-11db-bd13-0800200c9a66b827vs52h7")); assertTrue(c32.contains("d11275e7-67ae-11db-bd13-0800200c9a66")); assertTrue(result .contains("e11275e7-67ae-11db-bd13-0800200c9a66b827vs52h7")); assertTrue(result.contains("d11275e7-67ae-11db-bd13-0800200c9a66")); }
@Test public void testRedactDocument_WrongSensitivityInXacmlResult() throws Exception { initDocumentRedactorWithActualServices(); final String xacmlResultWithWrongObligations = MOCK_XACML_RESULT .replace("<pdpObligation>Drug Abuse</pdpObligation>", "") .replace("<pdpObligation>HIV</pdpObligation>", ""); String factModelXml = factModelExtractor.extractFactModel(c32, xacmlResultWithWrongObligations); c32 = embeddedClinicalDocumentExtractor .extractClinicalDocumentFromFactModel(factModelXml); factModelXml = removeEmbeddedClinicalDocument(factModelXml); final FactModel factModel = marshaller.unmarshalFromXml( FactModel.class, factModelXml); setValueSetCategories(factModel); factModel .setXacmlResult(setMockXacmlResult(xacmlResultWithWrongObligations)); final String result = documentRedactor.redactDocument(c32, ruleExecutionContainer, factModel).getRedactedDocument(); logger.debug("RESULT--> " + result); assertTrue(c32 .contains("e11275e7-67ae-11db-bd13-0800200c9a66b827vs52h7")); assertTrue(c32.contains("d11275e7-67ae-11db-bd13-0800200c9a66")); assertTrue(result .contains("e11275e7-67ae-11db-bd13-0800200c9a66b827vs52h7")); assertTrue(result.contains("d11275e7-67ae-11db-bd13-0800200c9a66")); }