Operation Details
Description: Search by outcome plan, related type, record status and not already added to plan. Also limits the result set.
Sterotype: nsmulti
SQL
SELECT opr.*	
		INTO :outcomePlanRecommendationID,
			:caseParticipantRoleID,
			:relatedType,
   			:relatedID,
			:activityType,
			:nameTextID,
			:recordStatus,
			:outcomePlanID,
			:lapseDate,
			:versionNo
FROM outcomePlanRecommendation opr
	WHERE opr.outcomeplanid = :outcomePlanID
		AND opr.recordstatus = :recordStatus
		AND opr.relatedType = :relatedType
		AND NOT EXISTS(
						SELECT opeo.outcomePlanExpectedOutcomeID
							FROM outcomePlanExpectedOutcome opeo,
                     					expectedOutcomeClient eoc
									WHERE opeo.outcomePlanID = :outcomePlanID
										AND opr.relatedID = opeo.expectedOutcomeID
										AND opeo.recordStatus = 'RST1'
										AND opeo.outcome = 'EOA10101'
                        				AND eoc.outcomePlanExpectedOutcomeID = opeo.outcomePlanExpectedOutcomeID
                        				AND opr.caseParticipantRoleID = eoc.caseParticipantRoleID
										AND opr.relatedType = 'RECT31001'
		)
		AND NOT EXISTS(
						SELECT opa.outcomePlanActionID
							FROM OutcomePlanAction opa,
                   						OutcomePlanActionRole opar
									WHERE opa.outcomePlanID = :outcomePlanID
										AND opr.relatedID = opa.outcomePlanActionAdminID
										AND opa.status != 'OPAS10004'
                        				AND opar.outcomePlanActionID= opa.outcomePlanActionID
                        				AND opr.caseParticipantRoleID = opar.caseParticipantRoleID
										AND opr.relatedType = 'RECT31000'
		)