-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#377: Added effective data requirement generation to PlanDefinition p…
…rocessing ... added test
- Loading branch information
Showing
60 changed files
with
12,036 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/main/java/org/opencds/cqf/tooling/plandefinition/PlanDefinitionRefreshProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package org.opencds.cqf.tooling.plandefinition; | ||
|
||
import org.cqframework.cql.cql2elm.CqlTranslatorOptions; | ||
import org.cqframework.cql.cql2elm.LibraryManager; | ||
import org.cqframework.cql.cql2elm.model.TranslatedLibrary; | ||
import org.cqframework.cql.elm.requirements.fhir.DataRequirementsProcessor; | ||
import org.hl7.fhir.r5.model.*; | ||
|
||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
public class PlanDefinitionRefreshProcessor { | ||
|
||
public PlanDefinition refreshPlanDefinition(PlanDefinition planToUse, LibraryManager libraryManager, TranslatedLibrary translatedLibrary, CqlTranslatorOptions options) { | ||
Set<String> expressions = new HashSet<>(); | ||
if (planToUse.hasAction()) { | ||
getExpressions(planToUse.getAction(), expressions); | ||
} | ||
DataRequirementsProcessor dqReqTrans = new DataRequirementsProcessor(); | ||
Library moduleDefinitionLibrary = dqReqTrans.gatherDataRequirements(libraryManager, translatedLibrary, options, expressions, true); | ||
|
||
planToUse.getExtension().removeAll(planToUse.getExtensionsByUrl("http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-parameter")); | ||
planToUse.getExtension().removeAll(planToUse.getExtensionsByUrl("http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-dataRequirement")); | ||
planToUse.getExtension().removeAll(planToUse.getExtensionsByUrl("http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-directReferenceCode")); | ||
planToUse.getExtension().removeAll(planToUse.getExtensionsByUrl("http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-logicDefinition")); | ||
planToUse.getExtension().removeAll(planToUse.getExtensionsByUrl("http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-effectiveDataRequirements")); | ||
|
||
for (Extension extension : moduleDefinitionLibrary.getExtension()) { | ||
planToUse.addExtension(extension); | ||
} | ||
|
||
planToUse.getContained().removeIf(resource -> resource.getId().equalsIgnoreCase("effective-data-requirements")); | ||
// planToUse.addContained(moduleDefinitionLibrary.setId("effective-data-requirements")); | ||
// planToUse.addExtension().setUrl("http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-effectiveDataRequirements").setValue(new Reference("#effective-data-requirements")).setId("effective-data-requirements"); | ||
return planToUse; | ||
} | ||
|
||
private void getExpressions(List<PlanDefinition.PlanDefinitionActionComponent> actions, Set<String> expressions) { | ||
for (PlanDefinition.PlanDefinitionActionComponent action : actions) { | ||
if (action.hasCondition()) { | ||
for (PlanDefinition.PlanDefinitionActionConditionComponent condition : action.getCondition()) { | ||
if (condition.hasKind() && condition.getKind() == Enumerations.ActionConditionKind.APPLICABILITY | ||
&& condition.hasExpression() && isExpressionIdentifier(condition.getExpression())) { | ||
expressions.add(condition.getExpression().getExpression()); | ||
} | ||
} | ||
} | ||
if (action.hasDynamicValue()) { | ||
for (PlanDefinition.PlanDefinitionActionDynamicValueComponent dynamicValue : action.getDynamicValue()) { | ||
if (dynamicValue.hasExpression() && isExpressionIdentifier(dynamicValue.getExpression())) { | ||
expressions.add(dynamicValue.getExpression().getExpression()); | ||
} | ||
} | ||
} | ||
if (action.hasAction()) { | ||
getExpressions(action.getAction(), expressions); | ||
} | ||
} | ||
} | ||
|
||
private boolean isExpressionIdentifier(Expression expression) { | ||
return expression.hasLanguage() && expression.hasExpression() && (expression.getLanguage().equalsIgnoreCase("text/cql.identifier") || expression.getLanguage().equalsIgnoreCase("text/cql")); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...st/java/org/opencds/cqf/tooling/plandefinition/r4/PlanDefinitionRefreshProcessorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package org.opencds.cqf.tooling.plandefinition.r4; | ||
|
||
import ca.uhn.fhir.context.FhirContext; | ||
import ca.uhn.fhir.parser.JsonParser; | ||
import ca.uhn.fhir.parser.LenientErrorHandler; | ||
import ca.uhn.fhir.parser.XmlParser; | ||
import org.cqframework.cql.cql2elm.*; | ||
import org.cqframework.cql.cql2elm.model.TranslatedLibrary; | ||
import org.hl7.elm.r1.VersionedIdentifier; | ||
import org.hl7.fhir.instance.model.api.IBaseResource; | ||
import org.hl7.fhir.r5.model.PlanDefinition; | ||
import org.opencds.cqf.tooling.plandefinition.PlanDefinitionRefreshProcessor; | ||
import org.opencds.cqf.tooling.utilities.CanonicalUtils; | ||
import org.opencds.cqf.tooling.utilities.IOUtils; | ||
import org.testng.annotations.Test; | ||
|
||
import java.nio.file.Path; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class PlanDefinitionRefreshProcessorTest { | ||
|
||
public static final String separator = System.getProperty("file.separator"); | ||
|
||
@Test | ||
public void refreshPlanDefinition() { | ||
String libraryDirectoryPath = "/Users/christopherschuler/Documents/workspace/alphora/cqf-tooling/src/test/resources/org/opencds/cqf/tooling/r4/input/resources/library"; | ||
String plandefinitionDirectoryPath = "/Users/christopherschuler/Documents/workspace/alphora/cqf-tooling/src/test/resources/org/opencds/cqf/tooling/r4/input/resources/plandefinition"; | ||
|
||
List<IBaseResource> resources = IOUtils.readResources( | ||
Arrays.asList( | ||
plandefinitionDirectoryPath + separator + "plandefinition-OpioidCDSREC01.xml", | ||
plandefinitionDirectoryPath + separator + "plandefinition-OpioidCDSREC02.xml", | ||
plandefinitionDirectoryPath + separator + "plandefinition-OpioidCDSREC03.xml", | ||
plandefinitionDirectoryPath + separator + "plandefinition-OpioidCDSREC04.xml", | ||
plandefinitionDirectoryPath + separator + "plandefinition-OpioidCDSREC04PatientView.xml", | ||
plandefinitionDirectoryPath + separator + "plandefinition-OpioidCDSREC05.xml", | ||
plandefinitionDirectoryPath + separator + "plandefinition-OpioidCDSREC06.xml", | ||
plandefinitionDirectoryPath + separator + "plandefinition-OpioidCDSREC07.xml", | ||
plandefinitionDirectoryPath + separator + "plandefinition-OpioidCDSREC08.xml", | ||
plandefinitionDirectoryPath + separator + "plandefinition-OpioidCDSREC08OrderSign.xml", | ||
plandefinitionDirectoryPath + separator + "plandefinition-OpioidCDSREC09.xml", | ||
plandefinitionDirectoryPath + separator + "plandefinition-OpioidCDSREC10.xml", | ||
plandefinitionDirectoryPath + separator + "plandefinition-OpioidCDSREC10OrderSign.xml", | ||
plandefinitionDirectoryPath + separator + "plandefinition-OpioidCDSREC10PatientView.xml", | ||
plandefinitionDirectoryPath + separator + "plandefinition-OpioidCDSREC11.xml", | ||
plandefinitionDirectoryPath + separator + "plandefinition-OpioidCDSREC11PatientView.xml", | ||
plandefinitionDirectoryPath + separator + "plandefinition-OpioidCDSREC12PatientView.xml" | ||
|
||
), FhirContext.forR5() | ||
); | ||
|
||
LibrarySourceProvider sourceProvider = new DefaultLibrarySourceProvider(Path.of(libraryDirectoryPath)); | ||
LibraryManager libraryManager = new LibraryManager(new ModelManager()); | ||
libraryManager.getLibrarySourceLoader().registerProvider(sourceProvider); | ||
|
||
CqlTranslatorOptions options = CqlTranslatorOptions.defaultOptions(); | ||
VersionedIdentifier identifier; | ||
TranslatedLibrary translatedLibrary; | ||
PlanDefinitionRefreshProcessor refreshProcessor = new PlanDefinitionRefreshProcessor(); | ||
for(IBaseResource plan : resources) { | ||
PlanDefinition planDef = (PlanDefinition) plan; | ||
identifier = new VersionedIdentifier().withId(CanonicalUtils.getId(planDef.getLibrary().get(0).getValue())); | ||
translatedLibrary = libraryManager.resolveLibrary(identifier, options, new ArrayList<>()); | ||
PlanDefinition refreshedPlan = refreshProcessor.refreshPlanDefinition(planDef, libraryManager, translatedLibrary, options); | ||
IOUtils.writeResource(refreshedPlan, "/Users/christopherschuler/Documents/workspace/scratch", IOUtils.Encoding.JSON, FhirContext.forR5()); | ||
} | ||
|
||
|
||
// String resource = new XmlParser(FhirContext.forR5(), new LenientErrorHandler()).setPrettyPrint(true).encodeResourceToString(refreshedPlan); | ||
// String resource = new JsonParser(FhirContext.forR5(), new LenientErrorHandler()).setPrettyPrint(true).encodeResourceToString(refreshedPlan); | ||
|
||
String s = ""; | ||
} | ||
|
||
} |
Oops, something went wrong.