Referenced DSLs

DSLs that create and reference intermediate results

LHS:

Assertion.Exists
[when] Assertion.Exists - There is assertion {ASSERTION:ENUM:Assertion.value} = 
(
	Assertion(value == "{ASSERTION}")
) //DslUsed==Assertion.Exists.Dsl|||ASSERTION=={ASSERTION}
Assertion.Not.Exists
[when] Assertion.Not.Exists - There is NOT an assertion {ASSERTION:ENUM:Assertion.value} = 
(
   java.util.List (size == 0) from collect ( Assertion(value == "{ASSERTION}") ) 
) //DslUsed==Assertion.Not.Exists.Dsl|||ASSERTION=={ASSERTION}
Assertion.String.Exists
[when] Assertion.String.Exists - There is an Assertion String {ASSERTIONSTRING} = 
(
	//$assertions_{ASSERTIONSTRING} : Assertion
	Assertion
	(
		value == "{ASSERTIONSTRING}"
	)
) //DslUsed==Assertion.String.Exists|||ASSERTIONSTRING=={ASSERTIONSTRING}

RHS:

Assert
[then] Assert - Assert to both Rules and Process that {ASSERTION:ENUM:Assertion.value} = 

insert(new Assertion("{ASSERTION}"));
assertions.add("{ASSERTION}"); //DslUsed==Assert.Dsl|||ASSERTION=={ASSERTION}
Assert.NamedDate
[then] Assert.NamedDate - Assert name and value for Named Date {NAMEDDATENAME} for both Rules and Process = 

assertions.add("{NAMEDDATENAME}=" + org.opencds.common.utilities.DateUtility.getInstance().getDateAsSqlLongString(((java.util.Date) namedObjects.get("{NAMEDDATENAME}"))));

insert(new Assertion("{NAMEDDATENAME}=" + org.opencds.common.utilities.DateUtility.getInstance().getDateAsSqlLongString(((java.util.Date) namedObjects.get("{NAMEDDATENAME}"))))); //DslUsed==Assert.NamedDate.StNum.Dsl|||NAMEDDATENAME=={NAMEDDATENAME}
Assert.String
[then] Assert.String - Assert String {ASSERTIONSTRING} for both Rules and Process = 
assertions.add("{ASSERTIONSTRING}");
insert(new Assertion("{ASSERTIONSTRING}")); //DslUsed==Assert.String.Dsl|||ASSERTIONSTRING=={ASSERTIONSTRING}

DSLs that control the Concept Determination Methods that you want to use in this Knowledge Module

LHS:

Concept.Det.Clin.Stmt.Identify
[when] Concept.Det.Clin.Stmt.Identify - Concept for ClinicalStatement is not determined according to {DETERMETHOD:ENUM:VMRTemplateConcept.determinationMethodCode} = 
(
$ConceptDeterminationMethodClinicalStatementConceptToRemove{DETERMETHOD} : VmrOpenCdsConcept
	(
	determinationMethodCode != "{DETERMETHOD}"
	) and 
ClinicalStatement
	(
	id == $ConceptDeterminationMethodClinicalStatementConceptToRemove{DETERMETHOD}.conceptTargetId
	) 
) //DslUsed==Concept.Det.Clin.Stmt.Identify|||DETERMETHOD=={DETERMETHOD}
Concept.Det.Entity.Identify
[when] Concept.Det.Entity.Identify - Concept for Entities is not determined according to {DETERMETHOD:ENUM:VMRTemplateConcept.determinationMethodCode} = 
(
$ConceptDeterminationMethodEntityConceptToRemove{DETERMETHOD} : VmrOpenCdsConcept
	(
	determinationMethodCode != "{DETERMETHOD}"
	) and 
EntityBase
	(
	id == $ConceptDeterminationMethodEntityConceptToRemove{DETERMETHOD}.conceptTargetId
	) 
) //DslUsed==Concept.Det.Entity.Identify.Dsl|||DETERMETHOD=={DETERMETHOD}
Concept.Det.Rship.Identify
[when] Concept.Det.Rship.Identify - Concept for Relationship is not determined according to {DETERMETHOD:ENUM:VMRTemplateConcept.determinationMethodCode} = 
(
$ConceptDeterminationMethodRelationshipConceptToRemove{DETERMETHOD} : VmrOpenCdsConcept
	(
	determinationMethodCode != "{DETERMETHOD}"
	) and 
	( 
	ClinicalStatementRelationship
		(
		id == $ConceptDeterminationMethodRelationshipConceptToRemove{DETERMETHOD}.conceptTargetId
		) or 	
	EntityRelationship
		(
		id == $ConceptDeterminationMethodRelationshipConceptToRemove{DETERMETHOD}.conceptTargetId
		) 
	) 
) //DslUsed==Concept.Det.Rship.Identify.Dsl|||DETERMETHOD=={DETERMETHOD}

RHS:

Concept.Det.Clin.Stmt.Remove
[then] Concept.Det.Clin.Stmt.Remove - Remove ClinicalStatement concept without desired concept determination method = 

retract ($ConceptDeterminationMethodClinicalStatementConceptToRemove{DETERMETHOD}); //DslUsed==Concept.Det.Clin.Stmt.Remove.Dsl|||DETERMETHOD=={DETERMETHOD}
Concept.Det.Entity.Remove
[then] Concept.Det.Entity.Remove - Remove Entities concept without desired concept determination method = 
retract ($ConceptDeterminationMethodEntityConceptToRemove{DETERMETHOD}); //DslUsed==Concept.Det.Entity.Remove.Dsl|||DETERMETHOD=={DETERMETHOD}
Concept.Det.Rship.Remove
[then] Concept.Det.Rship.Remove - Remove Relationship concept without desired concept determination method = 

retract ($ConceptDeterminationMethodRelationshipConceptToRemove{DETERMETHOD}); //DslUsed==Concept.Det.Rship.Remove.Dsl|||DETERMETHOD=={DETERMETHOD}

DSLs that select patient demographics in LHS:

Dem.Age.Time
[when] Dem.Age.Time - Evaluated Person age was {COMP:ENUM:Comparison.operator} {N1} {TIMEUNITS1:ENUM:EnumerationTarget.javaCalendarUnit} at {N2} {TIMEUNITS2:ENUM:EnumerationTarget.javaCalendarUnit} {PLUSMINUS:ENUM:Comparison.plusMinus} {N3} {TIMEUNITS3:ENUM:EnumerationTarget.javaCalendarUnit} before evalTime, where time components are ignored if age unit is year, month, or day  = 
(
/*
	E.g., Evaluated Person age was [>=] [18][yr] at [8][mo] [+] [1][d] before evalTime, where time is ignored if age unit is yr, month, or day
*/ 
	EvaluatedPerson
	(
		id == $evaluatedPersonId, 
		demographics != null,
		eval(getAgeInTimeUnitAtTime(demographics.getBirthTime(), org.opencds.common.utilities.DateUtility.getInstance().getDateAfterAddingTime(org.opencds.common.utilities.DateUtility.getInstance().getDateAfterAddingTime($evalTime, {TIMEUNITS2}, -1 * {N2}), {TIMEUNITS3}, -1 * {PLUSMINUS}1 * {N3}), {TIMEUNITS1}) {COMP} {N1})
	)
) 
//DslUsed==Dem.Age.Time.Dsl||COMP=={COMP}|||N1=={N1}|||TIMEUNITS1=={TIMEUNITS1}|||N2=={N2}|||TIMEUNITS2=={TIMEUNITS2}|||PLUSMINUS=={PLUSMINUS}|||N3=={N3}|||TIMEUNITS3=={TIMEUNITS3}
Missing.DOB
[when] Missing.DOB - EvaluatedPerson is missing date of birth = 
(
  (EvaluatedPerson(id == $evaluatedPersonId, demographics == null)) 
or
  (EvaluatedPerson(id == $evaluatedPersonId, demographics.birthTime == null))
)
//DslUsed==Missing.DOB.Dsl

DSLs that select encounters

LHS:

Enc.From.NamedList.After.Med.SubDispense.Count.Id
[when] Enc.From.NamedList.After.Med.SubDispense.Count.Id - Evaluated Person had at least {INT1} {ENCLISTID:ENUM:EncounterListId.reference} from Named List "{NAMEDLIST}" where low time was at most {INT2} {TIMEUNITS2:ENUM:EnumerationTarget.javaCalendarUnitNoWeeks} after low time of {MED:ENUM:MedicationConcept.openCdsConceptCode} dispensation= 
(
	$EFNAMSDCI_MedConceptTargetIds_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED} : java.util.List (size >= 0 ) from accumulate 
	( 
		MedicationConcept
		( 
			openCdsConceptCode == "{MED}",
			ESMPBECI_MedConceptTargetId_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED} : conceptTargetId 
		),
	init (ArrayList $EFNAMSDCI_TempMedConceptTargetIds_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED} = new ArrayList(); ),
	action ($EFNAMSDCI_TempMedConceptTargetIds_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED}.add(ESMPBECI_MedConceptTargetId_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED}); ),
	reverse ($EFNAMSDCI_TempMedConceptTargetIds_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED}.remove(ESMPBECI_MedConceptTargetId_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED}); ),
	result ($EFNAMSDCI_TempMedConceptTargetIds_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED})
	) and
	
	$EFNAMSDCI_SubDispenseEvents_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED} : java.util.List  (size >= 0) from collect 
	( 
		SubstanceDispensationEvent
		(
			evaluatedPersonId == $evaluatedPersonId, 
			id memberOf $EFNAMSDCI_MedConceptTargetIds_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED},
			dispensationTime != null
		)
	) and
	
	NamedList
	(
		name == "{NAMEDLIST}", 
		list != null,
		list.size() >= 0,
		$EFNAMSDCI_Encounters_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED} : list == ( (List) (namedObjects.get("{NAMEDLIST}")))

	) and
	
	{ENCLISTID} : java.util.List (size >= {INT1} ) from accumulate 
	( 
		$EFNAMSDCI_Enc_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED} : EncounterEvent
		( 
			evaluatedPersonId == $evaluatedPersonId, 
			eval(encInEncList($EFNAMSDCI_Enc_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED}, $EFNAMSDCI_Encounters_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED},namedObjects)),
			eval(encAfterMedSubDispenseFromListWithinTime($EFNAMSDCI_Enc_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED}, $EFNAMSDCI_SubDispenseEvents_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED} ,"Low","Low",{INT2},{TIMEUNITS2},namedObjects)) 
			
		),
	init (ArrayList $EFNAMSDCI_TempFinalEncs_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED} = new ArrayList(); ),
	action ( $EFNAMSDCI_TempFinalEncs_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED}.add($EFNAMSDCI_Enc_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED}); ),
	reverse ( $EFNAMSDCI_TempFinalEncs_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED}.remove($EFNAMSDCI_Enc_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED}); ),
	result( $EFNAMSDCI_TempFinalEncs_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED})
	) 
	 
) //DslUsed==Enc.From.NamedList.After.Med.SubDispense.Count.Id|||INT1=={INT1}|||ENCLISTID=={ENCLISTID}|||NAMEDLIST=={NAMEDLIST}|||INT2=={INT2}|||TIMEUNITS2=={TIMEUNITS2}|||MED=={MED}
Enc.From.NamedList.After.Med.SubDispense.DaysSupply.Active.Count.Id
[when] Enc.From.NamedList.After.Med.SubDispense.DaysSupply.Active.Count.Id - Evaluated Person had at least {INT1} {ENCLISTID:ENUM:EncounterListId.reference} from Named List "{NAMEDLIST}" where low time was at most {INT2} {TIMEUNITS2:ENUM:EnumerationTarget.javaCalendarUnitNoWeeks} after low time of {MED:ENUM:MedicationConcept.openCdsConceptCode} dispensation plus Days Supply= 
(
	$EFNAMSDDSACI_MedConceptTargetIds_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED} : java.util.List (size >= 0 ) from accumulate 
	( 
		MedicationConcept
		( 
			openCdsConceptCode == "{MED}",
			ESMPBECI_MedConceptTargetId_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED} : conceptTargetId 
		),
	init (ArrayList $EFNAMSDDSACI_TempMedConceptTargetIds_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED} = new ArrayList(); ),
	action ($EFNAMSDDSACI_TempMedConceptTargetIds_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED}.add(ESMPBECI_MedConceptTargetId_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED}); ),
	reverse ($EFNAMSDDSACI_TempMedConceptTargetIds_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED}.remove(ESMPBECI_MedConceptTargetId_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED}); ),
	result ($EFNAMSDDSACI_TempMedConceptTargetIds_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED})
	) and
	
	$EFNAMSDDSACI_SubDispenseEvents_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED} : java.util.List  (size >= 0) from collect 
	( 
		SubstanceDispensationEvent
		(
			evaluatedPersonId == $evaluatedPersonId, 
			id memberOf $EFNAMSDDSACI_MedConceptTargetIds_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED},
			dispensationTime != null,
			daysSupply != null
		)
	) and
	
	NamedList
	(
		name == "{NAMEDLIST}", 
		list != null,
		list.size() >= 0,
		$EFNAMSDDSACI_Encounters_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED} : list == ( (List) (namedObjects.get("{NAMEDLIST}")))

	) and
	
	{ENCLISTID} : java.util.List (size >= {INT1} ) from accumulate 
	( 
		$EFNAMSDDSACI_Enc_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED} : EncounterEvent
		( 
			evaluatedPersonId == $evaluatedPersonId, 
			eval(encInEncList($EFNAMSDDSACI_Enc_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED}, $EFNAMSDDSACI_Encounters_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED},namedObjects)),
			eval(encAfterMedSubDispenseDaysSupplyActiveFromListWithinTime($EFNAMSDDSACI_Enc_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED}, $EFNAMSDDSACI_SubDispenseEvents_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED} ,"Low",{INT2},{TIMEUNITS2},namedObjects)) 
			
		),
	init (ArrayList $EFNAMSDDSACI_TempFinalEncs_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED} = new ArrayList(); ),
	action ( $EFNAMSDDSACI_TempFinalEncs_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED}.add($EFNAMSDDSACI_Enc_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED}); ),
	reverse ( $EFNAMSDDSACI_TempFinalEncs_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED}.remove($EFNAMSDDSACI_Enc_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED}); ),
	result( $EFNAMSDDSACI_TempFinalEncs_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{MED})
	) 	 
) //DslUsed==Enc.From.NamedList.After.Med.SubDispense.DaysSupply.Active.Count.Id|||INT1=={INT1}|||ENCLISTID=={ENCLISTID}|||NAMEDLIST=={NAMEDLIST}|||INT2=={INT2}|||TIMEUNITS2=={TIMEUNITS2}|||MED=={MED}
Enc.From.NamedList.Before.After.Enc.Rship.EncDx.Count.Id
[when] Enc.From.NamedList.Before.After.Enc.Rship.EncDx.Count.Id - Evaluated Person had at least {INT1} {ENCLISTID:ENUM:EncounterListId.reference} from Named List "{NAMEDLIST}" where low time was at most {INT2} {TIMEUNITS2:ENUM:EnumerationTarget.javaCalendarUnitNoWeeks} after encounter high time AND high time was at most {INT3} {TIMEUNITS3:ENUM:EnumerationTarget.javaCalendarUnitNoWeeks} before encounter low time where {PROB:ENUM:ProblemConcept.openCdsConceptCode} was {CSREL:ENUM:ClinicalStatementRelationshipConcept.openCdsConceptCode} the encounter= 
// This DSL restricts Named List of encounters to those encounters which were time timeunits before or time timeunits after encounter that was related to EncDx
(
	$EFNAERECI_ProbConceptTargetIds_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL} : java.util.List (size >= {INT1} ) from accumulate 
	( 
		ProblemConcept
		( 
		openCdsConceptCode == "{PROB}",
		$EFNAERECI_ProbConceptTargetId_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL} : conceptTargetId 
		),
	init (ArrayList $EFNAERECI_TempProbConceptTargetIds_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL} = new ArrayList(); ),
	action ($EFNAERECI_TempProbConceptTargetIds_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL}.add($EFNAERECI_ProbConceptTargetId_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL}); ),
	reverse ($EFNAERECI_TempProbConceptTargetIds_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL}.remove($EFNAERECI_ProbConceptTargetId_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL}); ),
	result($EFNAERECI_TempProbConceptTargetIds_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL})
	) and  
	
	$EFNAERECI_CSRelConceptProbTargetIds_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL} : java.util.List (size >= {INT1} ) from accumulate 
	( 
		ClinicalStatementRelationshipConcept
		( 
		openCdsConceptCode == "{CSREL}",
		$EFNAERECI_CSRelConceptProbTargetId_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL} : conceptTargetId 
		),
	init (ArrayList $EFNAERECI_TempCSRelConceptProbTargetIds_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL} = new ArrayList(); ),
	action ( $EFNAERECI_TempCSRelConceptProbTargetIds_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL}.add($EFNAERECI_CSRelConceptProbTargetId_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL}); ),
	reverse ( $EFNAERECI_TempCSRelConceptProbTargetIds_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL}.remove($EFNAERECI_CSRelConceptProbTargetId_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL}); ),
	result($EFNAERECI_TempCSRelConceptProbTargetIds_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL})
	) and  
	
	$EFNAERECI_CSRelProbSourceIds_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL} : java.util.List (size >= {INT1} ) from accumulate 
	( 
		ClinicalStatementRelationship
		( 
		id memberOf $EFNAERECI_CSRelConceptProbTargetIds_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL},
		targetId memberOf $EFNAERECI_ProbConceptTargetIds_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL},
		$EFNAERECI_CSRelProbSourceId_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL} : sourceId 
		),
	init (ArrayList $EFNAERECI_TempCSRelProbSourceIds_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL} = new ArrayList(); ),
	action ( $EFNAERECI_TempCSRelProbSourceIds_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL}.add($EFNAERECI_CSRelProbSourceId_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL}); ),
	reverse ( $EFNAERECI_TempCSRelProbSourceIds_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL}.remove($EFNAERECI_CSRelProbSourceId_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL}); ),
	result( $EFNAERECI_TempCSRelProbSourceIds_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL})
	) and  
	
	$EFNAERECI_ComorbidEncIds_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL} : java.util.List (size >= 0 ) from accumulate 
	( 
		EncounterEvent
		( 		
			$EFNAERECI_ComorbidEncId_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL} : id memberOf $EFNAERECI_CSRelProbSourceIds_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL}, 
			evaluatedPersonId == $evaluatedPersonId
		),
	init (ArrayList $EFNAERECI_TempComorbidEncIds_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL} = new ArrayList(); ),
	action ( $EFNAERECI_TempComorbidEncIds_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL}.add($EFNAERECI_ComorbidEncId_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL}); ),
	reverse ( $EFNAERECI_TempComorbidEncIds_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL}.remove($EFNAERECI_ComorbidEncId_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL}); ),
	result( $EFNAERECI_TempComorbidEncIds_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL})
	) and  
	
	$EFNAERECI_ComorbidEncs_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL} : java.util.List( size >= {INT1} ) from collect 
	( 
		EncounterEvent
		(
			id memberOf $EFNAERECI_ComorbidEncIds_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL}
		)
	) and
	
		NamedList
	(
		name == "{NAMEDLIST}", 
		list != null,
		list.size() >= 0,
		$EFNAERECI_Encounters_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL} : list == ( (List) (namedObjects.get("{NAMEDLIST}")))

	) and
	
	
	{ENCLISTID} : java.util.List (size >= {INT1} ) from accumulate 
	( 
		$EFNAERECI_Enc_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL} : EncounterEvent
		( 
			evaluatedPersonId == $evaluatedPersonId, 
			eval(encInEncList($EFNAERECI_Enc_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL}, $EFNAERECI_Encounters_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL},namedObjects)),
			(
			eval(encAfterEncFromListWithinTime($EFNAERECI_Enc_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL}, $EFNAERECI_ComorbidEncs_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL},"Low","High",{INT2},{TIMEUNITS2},namedObjects)) 
			|| 
			eval(encBeforeEncFromListWithinTime($EFNAERECI_Enc_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL}, $EFNAERECI_ComorbidEncs_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL},"High","Low",{INT3},{TIMEUNITS3},namedObjects))
			)
		),
	init (ArrayList $EFNAERECI_TempFinalEncs_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL} = new ArrayList(); ),
	action ( $EFNAERECI_TempFinalEncs_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL}.add($EFNAERECI_Enc_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL}); ),
	reverse ( $EFNAERECI_TempFinalEncs_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL}.remove($EFNAERECI_Enc_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL}); ),
	result( $EFNAERECI_TempFinalEncs_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{TIMEUNITS2}{PROB}{CSREL})
	) 
	 
) //DslUsed==Enc.From.NamedList.Before.After.Enc.Rship.EncDx.Count.Id|||INT1=={INT1}|||ENCLISTID=={ENCLISTID}|||NAMEDLIST=={NAMEDLIST}|||INT2=={INT2}|||TIMEUNITS2=={TIMEUNITS2}|||INT3=={INT3}|||TIMEUNITS3=={TIMEUNITS3}|||PROB=={PROB}|||CSREL={CSREL}
Enc.From.NamedList.Rship.EncDx.Not.Multiple.Count.Id
[when] Enc.From.NamedList.Rship.EncDx.Not.Multiple.Count.Id - Evaluated Person had at least {INT1} {ENCLISTID:ENUM:EncounterListId.reference} from Named List "{NAMEDLIST}" with more than {INT2} not a {PROB:ENUM:ProblemConcept.openCdsConceptCode} Encounter Diagnoses as {CSREL:ENUM:ClinicalStatementRelationshipConcept.openCdsConceptCode} the encounter = 
(
/*
This DSL restrict named list of encounters to those encounters which have more the INT2 Encounter Diagnosis
Variable pattern (change to XXX when editing): EFNLREDNMCI_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{PROB}{CSREL}
*/
	NamedList
	(
		name == "{NAMEDLIST}", 
		list != null,
		list.size() >= 0,
		$Encs_EFNLREDNMCI_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{PROB}{CSREL} : list == ( (List) (namedObjects.get("{NAMEDLIST}")))
	) and
	
	// Collect Clinical Statement Relationships of Problems associated with previously defined encounters, constrained by evalPersonId and encounter diagnosis template
	// - Requires: $EncIds
	// - Provides: $EncProbCSRs
	
		$EncProbCSRConceptIds_EFNLREDNMCI_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{PROB}{CSREL} : java.util.List (size >= 0) from accumulate
		(	
			ClinicalStatementRelationshipConcept
			(	 
				openCdsConceptCode == "{CSREL}",
				$TempId : conceptTargetId 
			),
			init (ArrayList $TempIds = new ArrayList(); ), action ($TempIds.add($TempId); ), reverse ($TempIds.remove($TempId); ), result($TempIds)
		) and
		
	// Problems without problem concept and with encounter diagnosis template constraint, previously identified in relation to EncounterEvents
	// - Requires: $EncProbIds
	// - Provides: $ProbIds
			$ProbConceptTargetIds_EFNLREDNMCI_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{PROB}{CSREL} : java.util.List (size >= {INT1}) from accumulate
		(	
			ProblemConcept
			(	 
				openCdsConceptCode == "{PROB}",
				$TempId : conceptTargetId
			),
			init (ArrayList $TempIds = new ArrayList(); ), action ($TempIds.add($TempId); ), reverse ($TempIds.remove($TempId); ), result($TempIds)
		) and
		
		$EncProbIds_EFNLREDNMCI_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{PROB}{CSREL} : java.util.List (size >= 0) from accumulate
		(	
			Problem
			(
				evaluatedPersonId == $evaluatedPersonId, 
				id not memberOf $ProbConceptTargetIds_EFNLREDNMCI_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{PROB}{CSREL},
				eval((templateId != null) && java.util.Arrays.asList(templateId).contains("2.16.840.1.113883.3.1829.11.7.2.18")),
				$TempId : id
			),
			init (ArrayList $TempIds = new ArrayList(); ), action ($TempIds.add($TempId); ), reverse ($TempIds.remove($TempId); ), result($TempIds)
		) and

		$EncProbCSRs_EFNLREDNMCI_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{PROB}{CSREL} : java.util.List (size >= 0 ) from accumulate 
		( 
		$TempId : ClinicalStatementRelationship
			(	 
				id memberOf $EncProbCSRConceptIds_EFNLREDNMCI_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{PROB}{CSREL} ,
				eval((getIdListFromClinicalStatementList($Encs_EFNLREDNMCI_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{PROB}{CSREL})).contains(sourceId)),
				targetId memberOf $EncProbIds_EFNLREDNMCI_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{PROB}{CSREL} 
			),
		init (ArrayList $TempIds = new ArrayList(); ), action ($TempIds.add($TempId); ), reverse ($TempIds.remove($TempId); ), result($TempIds)
		) and	
	
	{ENCLISTID} : java.util.List (size >= {INT1} ) from accumulate 
		( 
		$TempId : EncounterEvent
			( 
				evaluatedPersonId == $evaluatedPersonId, 
				eval(encInEncList($TempId, $Encs_EFNLREDNMCI_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{PROB}{CSREL}, namedObjects)),
				eval(encMeetsCsrCountReq($TempId, $EncProbCSRs_EFNLREDNMCI_{INT1}{ENCLISTID}{NAMEDLIST}{INT2}{PROB}{CSREL},{INT2}))
			),
		init (ArrayList $TempIds = new ArrayList(); ), action ($TempIds.add($TempId); ), reverse ($TempIds.remove($TempId); ), result($TempIds)
		)
) //DslUsed==Enc.From.NamedList.After.EncDx.Count.Id|||INT1=={INT1}|||ENCLISTID=={ENCLISTID}|||NAMEDLIST=={NAMEDLIST}|||INT2=={INT2}|||PROB=={PROB}|||CSREL={CSREL}
Enc.Rship.EncDx.Between.Times.Count.Id
[when] Enc.Rship.EncDx.Between.Times.Count.Id - Evaluated Person had at least {INT1} {ENCLISTID:ENUM:EncounterListId.reference} {ENCTYPE:ENUM:EncounterTypeConcept.openCdsConceptCode} with {HIGHLOW:ENUM:TimeInterval.highLowUpper} time at most {INT2} {TIMEUNITS2:ENUM:EnumerationTarget.javaCalendarUnitNoWeeks} and more than {INT3} {TIMEUNITS3:ENUM:EnumerationTarget.javaCalendarUnitNoWeeks} ago where {PROB:ENUM:ProblemConcept.openCdsConceptCode} was {CSREL:ENUM:ClinicalStatementRelationshipConcept.openCdsConceptCode} the encounter= 
(
/*
EncounterTypeConcept --> EncTypeConceptTargetIds --------------|                                
                                                                |          ProbIds, CSRelConceptTargetIds |              
ProbConcept --> ProbConceptTargetIds ---|                        |                                        --> FinalProbIds --> ProbList*
                                         --> ProbIds ---------------> CSRelSourceIds -------> FinalEncIds |--> EncList* 
                                                               |                       |
ClincialStatementRelationshipConcept --> CSRelConceptTargetIds |                       |
                                                                                      |
Encounter Date, Eval Person ID ------------------------------------------------------|

*flagged for return
       	
*/
	$EREDIBTC_EncTypeConceptTargetIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}: java.util.List (size >= {INT1} ) from accumulate 
	( 
		EncounterTypeConcept
		( 
		openCdsConceptCode == "{ENCTYPE}",
		$EREDIBTC_EncTypeConceptTargetId_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}: conceptTargetId 
		),
	init (ArrayList $EREDIBTC_TempEncTypeConceptTargetIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}= new ArrayList(); ),
	action ($EREDIBTC_TempEncTypeConceptTargetIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}.add($EREDIBTC_EncTypeConceptTargetId_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}); ),
	reverse ($EREDIBTC_TempEncTypeConceptTargetIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}.remove($EREDIBTC_EncTypeConceptTargetId_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}); ),
	result($EREDIBTC_TempEncTypeConceptTargetIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL})
	) and  
	
	$EREDIBTC_ProbIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}: java.util.List (size >= {INT1} ) from accumulate 
	( 
		ProblemConcept
		( 
		openCdsConceptCode == "{PROB}",
		$EREDIBTC_ProbConceptTargetId_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}: conceptTargetId 
		),
	init (ArrayList $EREDIBTC_TempProbConceptTargetIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}= new ArrayList(); ),
	action ($EREDIBTC_TempProbConceptTargetIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}.add($EREDIBTC_ProbConceptTargetId_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}); ),
	reverse ($EREDIBTC_TempProbConceptTargetIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}.remove($EREDIBTC_ProbConceptTargetId_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}); ),
	result($EREDIBTC_TempProbConceptTargetIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL})
	) and  
	
	$EREDIBTC_CSRelConceptTargetIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}: java.util.List (size >= {INT1} ) from accumulate 
	( 
		ClinicalStatementRelationshipConcept
		( 
		openCdsConceptCode == "{CSREL}",
		$EREDIBTC_CSRelConceptTargetId_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}: conceptTargetId 
		),
	init (ArrayList $EREDIBTC_TempCSRelConceptTargetIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}= new ArrayList(); ),
	action ( $EREDIBTC_TempCSRelConceptTargetIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}.add($EREDIBTC_CSRelConceptTargetId_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}); ),
	reverse ( $EREDIBTC_TempCSRelConceptTargetIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}.remove($EREDIBTC_CSRelConceptTargetId_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}); ),
	result($EREDIBTC_TempCSRelConceptTargetIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL})
	) and  
	
	$EREDIBTC_CSRelSourceIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}: java.util.List (size >= {INT1} ) from accumulate 
	( 
		ClinicalStatementRelationship
		( 
		id memberOf $EREDIBTC_CSRelConceptTargetIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL},
		targetId memberOf $EREDIBTC_ProbIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL},
		$EREDIBTC_CSRelSourceId_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}: sourceId memberOf $EREDIBTC_EncTypeConceptTargetIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}		
		),
	init (ArrayList $EREDIBTC_TempCSRelSourceIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}= new ArrayList(); ),
	action ( $EREDIBTC_TempCSRelSourceIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}.add($EREDIBTC_CSRelSourceId_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}); ),
	reverse ( $EREDIBTC_TempCSRelSourceIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}.remove($EREDIBTC_CSRelSourceId_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}); ),
	result( $EREDIBTC_TempCSRelSourceIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL})
	) and  
	
	$EREDIBTC_FinalEncIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}: java.util.List (size >= {INT1} ) from accumulate 
	( 
		EncounterEvent
		( 
			$EREDIBTC_FinalEncId_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}: id memberOf $EREDIBTC_CSRelSourceIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}, 
			evaluatedPersonId == $evaluatedPersonId, 
			eval(timeBeforeByAtMost(encounterEventTime.get{HIGHLOW}(), $evalTime, {INT2}, {TIMEUNITS2}, namedObjects)),
			eval(timeBeforeByMoreThan(encounterEventTime.get{HIGHLOW}(), $evalTime, {INT3}, {TIMEUNITS3}, namedObjects))
		),
	init (ArrayList $EREDIBTC_TempFinalEncIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}= new ArrayList(); ),
	action ( $EREDIBTC_TempFinalEncIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}.add($EREDIBTC_FinalEncId_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}); ),
	reverse ( $EREDIBTC_TempFinalEncIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}.remove($EREDIBTC_FinalEncId_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}); ),
	result( $EREDIBTC_TempFinalEncIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL})
	) and  
	
	{ENCLISTID} : java.util.List( size >= {INT1} ) from collect 
	( 
		EncounterEvent
		(
			id memberOf $EREDIBTC_FinalEncIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}
		)
	) and
	
	$EREDIBTC_FinalProbIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}: java.util.List (size >= {INT1} ) from accumulate 
	( 
		ClinicalStatementRelationship
		( 
			id memberOf $EREDIBTC_CSRelConceptTargetIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL},
			sourceId memberOf $EREDIBTC_FinalEncIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}, 
			$EREDIBTC_FinalProbId_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}: targetId memberOf $EREDIBTC_ProbIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}
		),
	init (ArrayList $EREDIBTC_TempFinalProbIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}= new ArrayList(); ),
	action ( $EREDIBTC_TempFinalProbIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}.add($EREDIBTC_FinalProbId_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}); ),
	reverse ( $EREDIBTC_TempFinalProbIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}.remove($EREDIBTC_FinalProbId_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}); ),
	result( $EREDIBTC_TempFinalProbIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL})
	) and 

	$EREDIBTC_ProbList_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}: java.util.List( size >= {INT1} ) from collect 
	( 
		Problem
		(
			id memberOf $EREDIBTC_FinalProbIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL}
		)
	) and
	
	EvaluatedPerson(eval(flagClinicalStatementListToReturnInOutput({ENCLISTID})), eval(flagClinicalStatementListToReturnInOutput($EREDIBTC_ProbList_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}{PROB}{CSREL})))
) //DslUsed==Enc.Rship.EncDx.Imp.Between.Times.Count.Id.Dsl|||INT1=={INT1}|||ENCLISTID=={ENCLISTID}|||ENCTYPE=={ENCTYPE}|||HIGHLOW=={HIGHLOW}|||INT2=={INT2}|||TIMEUNITS2=={TIMEUNITS2}|||INT3=={INT3}|||TIMEUNITS3=={TIMEUNITS3}|||PROB=={PROB}|||CSREL=={CSREL}|||PROBIMP=={PROBIMP}
Enc.Between.Times.Count.Id
[when] Enc.Between.Times.Count.Id - Evaluated Person had at least {INT1} {ENCLISTID:ENUM:EncounterListId.reference} {ENCTYPE:ENUM:EncounterTypeConcept.openCdsConceptCode} with {HIGHLOW:ENUM:TimeInterval.highLowUpper} time at most {INT2} {TIMEUNITS2:ENUM:EnumerationTarget.javaCalendarUnitNoWeeks} and more than {INT3} {TIMEUNITS3:ENUM:EnumerationTarget.javaCalendarUnitNoWeeks} ago = 
(
	$EBTCI_EncTypeConceptTargetIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3} : java.util.List (size >= {INT1} ) from accumulate 
	( 
		EncounterTypeConcept
		( 
		openCdsConceptCode == "{ENCTYPE}",
		$EBTCI_EncTypeConceptTargetId_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3} : conceptTargetId 
		),
	init (ArrayList $EBTCI_TempEncTypeConceptTargetIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3} = new ArrayList(); ),
	action ($EBTCI_TempEncTypeConceptTargetIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}.add($EBTCI_EncTypeConceptTargetId_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}); ),
	reverse ($EBTCI_TempEncTypeConceptTargetIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}.remove($EBTCI_EncTypeConceptTargetId_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}); ),
	result($EBTCI_TempEncTypeConceptTargetIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3})
	) and  
	
	$EBTCI_FinalEncIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3} : java.util.List (size >= {INT1} ) from accumulate 
	( 
		EncounterEvent
		( 
			$EBTCI_FinalEncId_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3} : id memberOf $EBTCI_EncTypeConceptTargetIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}, 
			evaluatedPersonId == $evaluatedPersonId, 
			eval(timeBeforeByAtMost(encounterEventTime.get{HIGHLOW}(), $evalTime, {INT2}, {TIMEUNITS2}, namedObjects)),
			eval(timeBeforeByMoreThan(encounterEventTime.get{HIGHLOW}(), $evalTime, {INT3}, {TIMEUNITS3}, namedObjects))
		),
	init (ArrayList $EBTCI_TempFinalEncIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3} = new ArrayList(); ),
	action ( $EBTCI_TempFinalEncIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}.add($EBTCI_FinalEncId_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}); ),
	reverse ( $EBTCI_TempFinalEncIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}.remove($EBTCI_FinalEncId_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}); ),
	result( $EBTCI_TempFinalEncIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3})
	) and  
	
	{ENCLISTID} : java.util.List( size >= {INT1} ) from collect 
	( 
		EncounterEvent
		(
			id memberOf $EBTCI_FinalEncIds_{INT1}{ENCLISTID}{ENCTYPE}{HIGHLOW}{INT2}{TIMEUNITS2}{INT3}{TIMEUNITS3}
		)
	) and
	EvaluatedPerson(eval(flagClinicalStatementListToReturnInOutput({ENCLISTID})))
) //DslUsed==Enc.Between.Times.Count.Id.Dsl|||INT1=={INT1}|||ENCLISTID=={ENCLISTID}|||ENCTYPE=={ENCTYPE}|||HIGHLOW=={HIGHLOW}|||INT2=={INT2}|||TIMEUNITS2=={TIMEUNITS2}|||INT3=={INT3}|||TIMEUNITS3=={TIMEUNITS3}

RHS:

Set.EncListId.Add.EncListRefs
[then] Set.EncListId.Add.EncListRefs - Set {ENCLISTID1:ENUM:EncounterListId.reference} as {ENCLISTID2:ENUM:EncounterListId.reference} added to {ENCLISTID3:ENUM:EncounterListId.reference} = 
List {ENCLISTID1} = new ArrayList();
{ENCLISTID1}.addAll({ENCLISTID2});
{ENCLISTID1}.addAll({ENCLISTID3}); //DslUsed==Set.EncListId.Add.EncListRefs.Dsl|||ENCLISTID1=={ENCLISTID1}|||ENCLISTID2=={ENCLISTID2}|||ENCLISTID3=={ENCLISTID3}
Set.EncListId.EncListRefs.No.Time.Overlap
[then] Set.EncListId.EncListRefs.No.Time.Overlap - Set {ENCLISTID1:ENUM:EncounterListId.reference} as the encounters in {ENCLISTID2:ENUM:EncounterListId.reference} with no time overlap with {ENCLISTID3:ENUM:EncounterListId.reference} = 
List {ENCLISTID1} = getEncListWithNoTimeOverlap({ENCLISTID2}, {ENCLISTID3}); //DslUsed==Set.EncListId.EncListRefs.No.Time.Overlap.Dsl|||ENCLISTID1=={ENCLISTID1}|||ENCLISTID2=={ENCLISTID2}|||ENCLISTID3=={ENCLISTID3}

DSLs that select Medications in LHS:

SubDispense.Med.Between.NamedDates.NoTimes
[when] SubDispense.Med.Between.NamedDates.NoTimes.Count.Id - Evaluated Person had at least {INT1} {CSLISTID:ENUM:CSListId.reference} {MED:ENUM:MedicationConcept.openCdsConceptCode}  with {HIGHLOW:ENUM:TimeInterval.highLowUpper} dispensation time {COMP1:ENUM:Comparison.operatorGTE} {NAMEDDATE1NAME} and {COMP2:ENUM:Comparison.operatorLTE} {NAMEDDATE2NAME} ignoring time components of all dates = 
(
/*
This DSL collects a list of substance dispensation events that happened between named dates
Variable pattern (change to XXX when editing): SDMBNDNTCI_{INT1}{MED}{HIGHLOW}
*/
	NamedDate
	(
		name == "{NAMEDDATE1NAME}", 
		date != null,
		$NamedDate1_SDMBNDNTCI_{INT1}{MED}{HIGHLOW} : date == ((java.util.Date) namedObjects.get("{NAMEDDATE1NAME}"))
	) and

	NamedDate
	(
		name == "{NAMEDDATE2NAME}", 
		date != null,
		$NamedDate2_SDMBNDNTCI_{INT1}{MED}{HIGHLOW} : date == ((java.util.Date) namedObjects.get("{NAMEDDATE2NAME}"))
	) and

// Collect SubstanceDispensationEvents with medication concept, evalPersonId, and Named Dates
	// - Requires: None
	// - Provides: $SubDispenseEvents
	
	$MedConceptTargetIds_SDMBNDNTCI_{INT1}{MED}{HIGHLOW} : java.util.List (size >= 0 ) from accumulate 
	( 
		MedicationConcept
		( 
			openCdsConceptCode == "{MED}",
			$TempId : conceptTargetId 
		),
			init (ArrayList $TempIds = new ArrayList(); ), action ($TempIds.add($TempId); ), reverse ($TempIds.remove($TempId); ), result($TempIds)
	) and
	
	{CSLISTID}: java.util.List( size >= {INT1} ) from accumulate
	( 
		$TempId : SubstanceDispensationEvent
		(
			evaluatedPersonId == $evaluatedPersonId, 
			id memberOf $MedConceptTargetIds_SDMBNDNTCI_{INT1}{MED}{HIGHLOW},
			dispensationTime != null,
			(stripTimeComponent(dispensationTime.get{HIGHLOW}())) {COMP1} (stripTimeComponent($NamedDate1_SDMBNDNTCI_{INT1}{MED}{HIGHLOW})),
			(stripTimeComponent(dispensationTime.get{HIGHLOW}())) {COMP2} (stripTimeComponent($NamedDate2_SDMBNDNTCI_{INT1}{MED}{HIGHLOW})) 
		),
			init (ArrayList $TempIds = new ArrayList(); ), action ($TempIds.add($TempId); ), reverse ($TempIds.remove($TempId); ), result($TempIds)
	)


) //SubDispense.Med.Between.NamedDates.NoTimes.Count.Id|||INT1=={INT1}|||CSLISTID=={CSLISTID}|||MED=={MED}|||HIGHLOW=={HIGHLOW}|||COMP1=={COMP1}|||COMP2=={COMP2}|||NAMEDDATE1NAME=={NAMEDDATE1NAME}|||NAMEDDATE2NAME=={NAMEDDATE2NAME}

DSLs that create output structures

LHS:

Out.Concepts.All.Read
[when] Out.Concepts.All.Read - All OpenCDS Concepts have been mapped to the vMR data = 
(
$concepts : java.util.Set (size >= 0) from collect ( VmrOpenCdsConcept() ) 
) //DslUsed==Out.Concepts.All.Read.Dsl

RHS:

Out.Concepts.All.Write
[then] Out.Concepts.All.Write - Create output observation with ID {CONCEPTS} containing all OpenCDS Concepts in working memory selected above = 

IVLDate obsTime{CONCEPTS} = new IVLDate(); 
obsTime{CONCEPTS}.setLow($evalTime); 
obsTime{CONCEPTS}.setHigh($evalTime); 

ObservationResult parentObs{CONCEPTS} = new ObservationResult(); 
String parentObs{CONCEPTS}Id = "2.16.840.1.113883.3.795.5.1.1^{CONCEPTS}"; 
parentObs{CONCEPTS}.setId(parentObs{CONCEPTS}Id); 
parentObs{CONCEPTS}.setEvaluatedPersonId($evaluatedPersonId); 
parentObs{CONCEPTS}.setObservationEventTime(obsTime{CONCEPTS}); 
parentObs{CONCEPTS}.setSubjectIsFocalPerson($evaluatedPersonId == $focalPersonId); 

CD parentObs{CONCEPTS}Focus = new CD(); 
parentObs{CONCEPTS}Focus.setCodeSystem("2.16.840.1.113883.3.795.12.1.1"); 
parentObs{CONCEPTS}Focus.setCodeSystemName("OpenCDS concepts"); 
parentObs{CONCEPTS}Focus.setCode("concepts"); 
parentObs{CONCEPTS}Focus.setDisplayName("Concepts found in working memory"); 

parentObs{CONCEPTS}.setObservationFocus(parentObs{CONCEPTS}Focus); 
parentObs{CONCEPTS}.setClinicalStatementToBeRoot(true); 
parentObs{CONCEPTS}.setToBeReturned(true); 

ObservationValue obsValue{CONCEPTS} = new ObservationValue();

String conceptsAsString = getConceptsAsString($concepts);

obsValue{CONCEPTS}.setText(conceptsAsString);

parentObs{CONCEPTS}.setObservationValue(obsValue{CONCEPTS}); 
insert(parentObs{CONCEPTS}); 
namedObjects.put("parentObs{CONCEPTS}", (Object)parentObs{CONCEPTS}); //DslUsed==Out.Concepts.All.Write.Dsl|||CONCEPTS=={CONCEPTS}
Out.Assertions
[then] Out.Assertions - Create output observation with ID {ASSERTIONS} containing a list of all assertions in working memory = 

IVLDate obsTime{ASSERTIONS} = new IVLDate(); 
obsTime{ASSERTIONS}.setLow($evalTime); 
obsTime{ASSERTIONS}.setHigh($evalTime); 

ObservationResult parentObs{ASSERTIONS} = new ObservationResult(); 
String parentObs{ASSERTIONS}Id = "2.16.840.1.113883.3.795.5.1.1^{ASSERTIONS}"; 
parentObs{ASSERTIONS}.setId(parentObs{ASSERTIONS}Id); 
parentObs{ASSERTIONS}.setEvaluatedPersonId($evaluatedPersonId); 
parentObs{ASSERTIONS}.setObservationEventTime(obsTime{ASSERTIONS}); 
parentObs{ASSERTIONS}.setSubjectIsFocalPerson($evaluatedPersonId == $focalPersonId); 

CD parentObs{ASSERTIONS}Focus = new CD(); 
parentObs{ASSERTIONS}Focus.setCodeSystem("2.16.840.1.113883.3.795.12.1.1"); 
parentObs{ASSERTIONS}Focus.setCodeSystemName("OpenCDS concepts"); 
parentObs{ASSERTIONS}Focus.setCode("assertions"); 
parentObs{ASSERTIONS}Focus.setDisplayName("Assertions found in working memory"); 

parentObs{ASSERTIONS}.setObservationFocus(parentObs{ASSERTIONS}Focus); 
parentObs{ASSERTIONS}.setClinicalStatementToBeRoot(true); 
parentObs{ASSERTIONS}.setToBeReturned(true); 

ObservationValue obsValue{ASSERTIONS} = new ObservationValue();

// obsValue{ASSERTIONS}.setText(assertions.toString());
// updated section
obsValue{ASSERTIONS}.setText(getAssertionsAsString(assertions));

parentObs{ASSERTIONS}.setObservationValue(obsValue{ASSERTIONS}); 
insert(parentObs{ASSERTIONS}); 
namedObjects.put("parentObs{ASSERTIONS}", (Object)parentObs{ASSERTIONS}); 
//DslUsed==Out.Assertions.Dsl|||ASSERTIONS=={ASSERTIONS}
Out.Nested.Obs.Num.Denom
[then] Out.Nested.Obs.Num.Denom - Create numerator value {NUMVALUE} as ID {NUMID} and denominator value {DENOMVALUE} as ID {DENOMID} for output observations focused on {OBSFOCUS:ENUM:ObservationFocusConcept.openCdsConceptCode} within enclosing observation ID {ROOT} =
IVLDate obsTime{NUMID} = new IVLDate();
obsTime{NUMID}.setLow($evalTime);
obsTime{NUMID}.setHigh($evalTime);
 
ObservationResult childObs{NUMID} = new ObservationResult();
String childObs{NUMID}Id = "2.16.840.1.113883.3.795.5.1.1^{NUMID}";
 
childObs{NUMID}.setId(childObs{NUMID}Id);
childObs{NUMID}.setEvaluatedPersonId($evaluatedPersonId);
childObs{NUMID}.setObservationEventTime(obsTime{NUMID});
childObs{NUMID}.setSubjectIsFocalPerson($evaluatedPersonId == $focalPersonId);
childObs{NUMID}.setClinicalStatementToBeRoot(false);
childObs{NUMID}.setToBeReturned(true);
 
CD childObs{NUMID}Focus = new CD();
childObs{NUMID}Focus.setCodeSystem("2.16.840.1.113883.3.795.12.1.1");
childObs{NUMID}Focus.setCodeSystemName("OpenCDS concepts");
childObs{NUMID}Focus.setCode("{OBSFOCUS}");
childObs{NUMID}Focus.setDisplayName(getOpenCDSConceptName("{OBSFOCUS}"));
childObs{NUMID}.setObservationFocus(childObs{NUMID}Focus);
 
int iChildObs{NUMID} = {NUMVALUE};
INT childObs{NUMID}IntegerValue = new INT();
childObs{NUMID}IntegerValue.setValue(iChildObs{NUMID});
 
ObservationValue childObs{NUMID}Value = new ObservationValue();
childObs{NUMID}Value.setInteger(childObs{NUMID}IntegerValue);
childObs{NUMID}.setObservationValue(childObs{NUMID}Value);
 
ClinicalStatementRelationship rel{NUMID} = new ClinicalStatementRelationship();
rel{NUMID}.setSourceId("2.16.840.1.113883.3.795.5.1.1^{ROOT}");
rel{NUMID}.setTargetId("2.16.840.1.113883.3.795.5.1.1^{NUMID}");
 
CD rel{NUMID}Code = new CD();
rel{NUMID}Code.setCodeSystem("2.16.840.1.113883.3.795.12.1.1");
rel{NUMID}Code.setCodeSystemName("OpenCDS concepts");
rel{NUMID}Code.setCode("C405");
rel{NUMID}Code.setDisplayName("Part of");
rel{NUMID}.setTargetRelationshipToSource(rel{NUMID}Code);
 
java.util.List<RelationshipToSource> childObs{NUMID}RelationshipToSources = new java.util.ArrayList<RelationshipToSource>();
RelationshipToSource childObs{NUMID}RelationshipToSource = new RelationshipToSource();
 
childObs{NUMID}RelationshipToSource.setSourceId("2.16.840.1.113883.3.795.5.1.1^{ROOT}");
childObs{NUMID}RelationshipToSource.setRelationshipToSource(rel{NUMID}Code);
childObs{NUMID}RelationshipToSources.add(childObs{NUMID}RelationshipToSource);
childObs{NUMID}.setRelationshipToSources(childObs{NUMID}RelationshipToSources);
 
namedObjects.put("childObs{NUMID}", childObs{NUMID});
 
namedObjects.put("rel{NUMID}", rel{NUMID});
 
IVLDate obsTime{DENOMID} = new IVLDate();
obsTime{DENOMID}.setLow($evalTime);
obsTime{DENOMID}.setHigh($evalTime);
 
ObservationResult childObs{DENOMID} = new ObservationResult();
String childObs{DENOMID}Id = "2.16.840.1.113883.3.795.5.1.1^{DENOMID}";
 
childObs{DENOMID}.setId(childObs{DENOMID}Id);
childObs{DENOMID}.setEvaluatedPersonId($evaluatedPersonId);
childObs{DENOMID}.setObservationEventTime(obsTime{DENOMID});
childObs{DENOMID}.setSubjectIsFocalPerson($evaluatedPersonId == $focalPersonId);
childObs{DENOMID}.setClinicalStatementToBeRoot(false);
childObs{DENOMID}.setToBeReturned(true);
 
CD childObs{DENOMID}Focus = new CD();
childObs{DENOMID}Focus.setCodeSystem("2.16.840.1.113883.3.795.12.1.1");
childObs{DENOMID}Focus.setCodeSystemName("OpenCDS concepts");
childObs{DENOMID}Focus.setCode("{OBSFOCUS}");
childObs{DENOMID}Focus.setDisplayName(getOpenCDSConceptName("{OBSFOCUS}"));
childObs{DENOMID}.setObservationFocus(childObs{DENOMID}Focus);
 
int iChildObs{DENOMID} = {DENOMVALUE};
INT childObs{DENOMID}IntegerValue = new INT();
 
childObs{DENOMID}IntegerValue.setValue(iChildObs{DENOMID});
ObservationValue childObs{DENOMID}Value = new ObservationValue();
childObs{DENOMID}Value.setInteger(childObs{DENOMID}IntegerValue);
childObs{DENOMID}.setObservationValue(childObs{DENOMID}Value);
 
ClinicalStatementRelationship rel{DENOMID} = new ClinicalStatementRelationship();
rel{DENOMID}.setSourceId("2.16.840.1.113883.3.795.5.1.1^{ROOT}");
rel{DENOMID}.setTargetId("2.16.840.1.113883.3.795.5.1.1^{DENOMID}");
 
CD rel{DENOMID}Code = new CD();
rel{DENOMID}Code.setCodeSystem("2.16.840.1.113883.3.795.12.1.1");
rel{DENOMID}Code.setCodeSystemName("OpenCDS concepts");
rel{DENOMID}Code.setCode("C405");
rel{DENOMID}Code.setDisplayName("Part of");
rel{DENOMID}.setTargetRelationshipToSource(rel{DENOMID}Code);
 
java.util.List<RelationshipToSource> childObs{DENOMID}RelationshipToSources = new java.util.ArrayList<RelationshipToSource>();
RelationshipToSource childObs{DENOMID}RelationshipToSource = new RelationshipToSource();
 
childObs{DENOMID}RelationshipToSource.setSourceId("2.16.840.1.113883.3.795.5.1.1^{ROOT}");
childObs{DENOMID}RelationshipToSource.setRelationshipToSource(rel{DENOMID}Code);
childObs{DENOMID}RelationshipToSources.add(childObs{DENOMID}RelationshipToSource);
childObs{DENOMID}.setRelationshipToSources(childObs{DENOMID}RelationshipToSources);
 
namedObjects.put("childObs{DENOMID}", childObs{DENOMID});
 
namedObjects.put("rel{DENOMID}", rel{DENOMID}); //DslUsed==Out.Nested.Obs.Num.Denom.Dsl|||DENOMVALUE=={DENOMVALUE}|||DENOMID=={DENOMID}|||NUMVALUE=={NUMVALUE}|||NUMID=={NUMID}|||ROOT=={ROOT}|||OBSFOCUS=={OBSFOCUS}
Out.Root.Obs.Focus.EvalpId
[then] Out.Root.Obs.Focus.EvalpId - Create root output observation with ID {ROOT} focused on {OUTROOTFOCUS:ENUM:ObservationFocusConcept.openCdsConceptCode} with value identifying the evaluatedPerson =
 
ObservationResult parentObs{ROOT} = new ObservationResult();
String parentObs{ROOT}Id = "2.16.840.1.113883.3.795.5.1.1^{ROOT}";
 
CD parentObs{ROOT}Focus = new CD();
parentObs{ROOT}Focus.setCodeSystem("2.16.840.1.113883.3.795.12.1.1");
parentObs{ROOT}Focus.setCodeSystemName("OpenCDS concepts");
parentObs{ROOT}Focus.setCode("{OUTROOTFOCUS}");
parentObs{ROOT}Focus.setDisplayName(getOpenCDSConceptName("{OUTROOTFOCUS}"));
 
ObservationValue parentObs{ROOT}Value = new ObservationValue();
String parentObs{ROOT}Identifier = $evaluatedPersonId;
parentObs{ROOT}Value.setIdentifier(parentObs{ROOT}Identifier);
 
IVLDate obsTime{ROOT} = new IVLDate();
obsTime{ROOT}.setLow($evalTime);
obsTime{ROOT}.setHigh($evalTime);
 
parentObs{ROOT}.setId(parentObs{ROOT}Id);
parentObs{ROOT}.setObservationFocus(parentObs{ROOT}Focus);
parentObs{ROOT}.setObservationValue(parentObs{ROOT}Value);
parentObs{ROOT}.setObservationEventTime(obsTime{ROOT});
parentObs{ROOT}.setEvaluatedPersonId($evaluatedPersonId);
parentObs{ROOT}.setSubjectIsFocalPerson($evaluatedPersonId == $focalPersonId);
parentObs{ROOT}.setClinicalStatementToBeRoot(true);
parentObs{ROOT}.setToBeReturned(true);
 
namedObjects.put("parentObs{ROOT}", parentObs{ROOT}); //DslUsed==Out.Root.Obs.Focus.EvalpId.Dsl|||ROOT=={ROOT}|||OUTROOTFOCUS=={OUTROOTFOCUS}

DSLs that initialize variables in LHS:

Init.EvalTime.FpId.EvalpId
[when] Init.EvalTime.FpId.EvalpId - Note that all criteria below must be met for the rule to fire. = 
( EvalTime($evalTime : evalTimeValue) and FocalPersonId($focalPersonId : id) and FocalPersonId($evaluatedPersonId : id) ) 
//DslUsed==Init.EvalTime.FpId.EvalpId.Dsl

DSLs that create and inference on new generic facts

LHS:

NamedDate.Exists.Not.Null
[when] NamedDate.Exists.Not.Null - The Named Date {NAME} exists and is not null = 
(
	NamedDate
	(
		name == "{NAME}", 
		date != null,
		date == ((java.util.Date) namedObjects.get("{NAME}"))
	)
) //DslUsed==NamedDate.Exists.Not.Null.Dsl|||NAME=={NAME}
NamedEnc.Exists.Not.Null
[when] NamedEnc.Exists.Not.Null - The Named Encounter {NAME} exists and is not null = 
(
	NamedEncounter
	(
		name == "{NAME}", 
		encounter != null,
		namedObjects.get("{NAME}") != null, 
		encounter.id == ((EncounterEvent) namedObjects.get("{NAME}")).getId()	
	)
) //DslUsed==NamedEncounter.Exists.Not.Null.Dsl|||NAME=={NAME}
NamedList.Exists.EncListId
[when] NamedList.Exists.EncListId - The Named List {ENCLISTID:ENUM:EncounterListId.reference} {NAME} exists; may be empty = 
(
	NamedList
	(
		name == "{NAME}", 
		list != null,
		{ENCLISTID} : list == ( (List) (namedObjects.get("{NAME}")))
	)
) //DslUsed==NamedList.Exists.EncListId.Dsl|||ENCLISTID=={ENCLISTID}|||NAME=={NAME}
NamedList.Exists.Not.Empty
[when] NamedList.Exists.Not.Empty - The Named List {NAME} exists and is not empty = 
(
	NamedList
	(
		name == "{NAME}", 
		list != null,
		list.size() > 0,
		list == ( (List) (namedObjects.get("{NAME}")))
	)
) //DslUsed==NamedList.Exists.Not.Empty.Dsl|||NAME=={NAME}

RHS:

Insert.EncListRef.As.NamedList
[then] Insert.EncListRef.As.NamedList - Insert {ENCLISTID:ENUM:EncounterListId.reference} as Named List "{NAME}" for both Rules and Process = 
namedObjects.put('{NAME}', {ENCLISTID});

NamedList  $namedList{ENCLISTID} = new NamedList();
$namedList{ENCLISTID}.setName('{NAME}');
$namedList{ENCLISTID}.setList({ENCLISTID}); 
insert ($namedList{ENCLISTID}); //DslUsed==Insert.EncListRef.As.NamedList.Dsl|||ENCLISTID=={ENCLISTID}|||NAME=={NAME}
Insert.NamedDate.After.NamedDate
[then] Insert.NamedDate.After.NamedDate - Insert Named Date "{NAME}" for both Rules and Process which is {INT} {TIMEUNITS:ENUM:EnumerationTarget.javaCalendarUnit} after {NAMEDDATENAME}; requires NamedDate.Exists.Not.Null = 
/*
This DSL inserts a nameDate after another namedDate.
Variable pattern (change to XXX when editing): INDAND_{INT}{TIMEUNITS}    	
*/

java.util.Date sourcenamedDateValue_INDAND_{INT}{TIMEUNITS} = (java.util.Date) namedObjects.get("{NAMEDDATENAME}");
java.util.Date namedDateValue_INDAND_{INT}{TIMEUNITS} = org.opencds.common.utilities.DateUtility.getInstance().getDateAfterAddingTime(sourcenamedDateValue_INDAND_{INT}{TIMEUNITS}, {TIMEUNITS}, {INT});
namedObjects.put("{NAME}", namedDateValue_INDAND_{INT}{TIMEUNITS});

// System.out.println(">> Adding: <{NAME}> with value " + namedDateValue_INDAND_{INT}{TIMEUNITS}.toString()); 

NamedDate $namedDateAfterNamedDate_INDAND_{INT}{TIMEUNITS} = new NamedDate();
$namedDateAfterNamedDate_INDAND_{INT}{TIMEUNITS}.setName("{NAME}");
$namedDateAfterNamedDate_INDAND_{INT}{TIMEUNITS}.setDate(namedDateValue_INDAND_{INT}{TIMEUNITS}); 
insert ($namedDateAfterNamedDate_INDAND_{INT}{TIMEUNITS}); //DslUsed==Insert.NamedDate.After.NamedDate.Dsl|||NAME=={NAME}|||INT=={INT}|||TIMEUNITS=={TIMEUNITS}|||NAMEDDATENAME=={NAMEDDATENAME}
Insert.NamedDate.From.Earliest.Enc.In.NamedList
[then] Insert.NamedDate.From.Earliest.Enc.In.NamedList - Insert Named Date "{NAME}" for both Rules and Process which is the earliest encounter {HIGHLOW:ENUM:TimeInterval.highLowUpper} time in {NAMEDLISTNAME}; requires NamedList.Exists.Not.Empty = 
List<EncounterEvent> namedListEncs = (List<EncounterEvent>) namedObjects.get("{NAMEDLISTNAME}");
java.util.Date namedDateValue = getEarliestDateFromEncounterList(namedListEncs, "{HIGHLOW}");
namedObjects.put("{NAME}", namedDateValue);

// System.out.println(">> Adding: <{NAME}> with value " + namedDateValue.toString()); 

NamedDate $INDFEEINL_NamedDate = new NamedDate();
$INDFEEINL_NamedDate.setName("{NAME}");
$INDFEEINL_NamedDate.setDate(namedDateValue); 
insert ($INDFEEINL_NamedDate); //DslUsed==Insert.NamedDate.From.Earliest.Enc.In.NamedList.Dsl|||NAME=={NAME}|||HIGHLOW=={HIGHLOW}|||NAMEDLISTNAME=={NAMEDLISTNAME}