@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")); }
@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 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 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); }
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); }
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);  }