目的:根据分配给用户的角色对工作列表执行 alpha 拆分。如果用户只有一个 alpha 拆分(例如 A-CZZZ),则以下逻辑有效,但我需要一些用户具有多个拆分的灵活性(例如 A-CZZZ 和 T-ZZZZ)。
高等级:
SELECT Name
FROM PatientDatabase
WHERE Name Between
(SELECT UserRole.AlphaFrom
FROM UserRole
WHERE UserRole.HasRole = 1)
AND
(SELECT UserRole.AlphaThru
FROM UserRole
WHERE UserRole.HasRole = 1)
PatientDatabase 中的潜在名称:
ABC,PERSON
LMN,PERSON
XYZ,PERSON
当前用户有两个 UserRoles(alpha 拆分):
A-CZZZ
T-ZZZZ
我想返回:
ABC,PERSON
XYZ,PERSON
我相信考虑到下面与安全相关的逻辑,子查询可能是必要的。
信息:
-'Roledef->ReportingCategory1->Name' is the AlphaFrom
-'Roledef->ReportingCategory2->Name' is the AlphaThru
当前只有一个时有效的 alpha 拆分逻辑(如果超过一个,则在第一个拆分时):
AND T.PatId->PatNm BETWEEN
(SELECT E2.Roledef->ReportingCategory1->Name
FROM SECURITYPLUS.USR S2, SecurityPlus.UsrETMRole E2,
SecurityPlus.UsrETMApplication A2
WHERE A2.USR = S2.USERNAME AND
E2.USRETMAPPLICATION = A2.ID AND S2.Username = ?
AND E2.Roledef->Name ['Alpha')
AND
(SELECT E3.Roledef->ReportingCategory2->Name
FROM SECURITYPLUS.USR S3, SecurityPlus.UsrETMRole E3,
SecurityPlus.UsrETMApplication A3
WHERE A3.USR = S3.USERNAME AND
E3.USRETMAPPLICATION = A3.ID AND S3.Username = ?
AND E3.Roledef->Name ['Alpha')
上下文的整个 SQL 逻辑:
SELECT
T.Id,
T.PatId->Mrn,
T.PatId->PatNm,
T.Invoice,
T.Invoice->Fsc,
T.Stage->Name As Stage,
T.Status->Name As Status,
T.Invoice->InvBal,
T.ReviewDate,
T.HasNoteFlag
FROM
TaskManager.Task T
WHERE
T.TaskNm->Name = 'Insurance Followup'
AND T.Status IN (SELECT ID FROM Dict.ETMTaskStatus TS
WHERE StatusType NOT IN ('DELETED','DONE'))
AND T.Invoice->Fsc->EtmRole IN
(SELECT E1.Roledef
FROM SECURITYPLUS.USR S1, SecurityPlus.UsrETMRole E1,
SecurityPlus.UsrETMApplication A1
WHERE A1.USR = S1.USERNAME AND
E1.USRETMAPPLICATION = A1.ID AND S1.Username = ?)
AND T.PatId->PatNm BETWEEN
(SELECT E2.Roledef->ReportingCategory1->Name
FROM SECURITYPLUS.USR S2, SecurityPlus.UsrETMRole E2,
SecurityPlus.UsrETMApplication A2
WHERE A2.USR = S2.USERNAME AND
E2.USRETMAPPLICATION = A2.ID AND S2.Username = ?
AND E2.Roledef->Name ['Alpha')
AND
(SELECT E3.Roledef->ReportingCategory2->Name
FROM SECURITYPLUS.USR S3, SecurityPlus.UsrETMRole E3,
SecurityPlus.UsrETMApplication A3
WHERE A3.USR = S3.USERNAME AND
E3.USRETMAPPLICATION = A3.ID AND S3.Username = ?
AND E3.Roledef->Name ['Alpha')
下一个逻辑返回我需要的表,但我不知道如何获得一个 between 语句来处理这个:
SELECT E2.Roledef->ReportingCategory1->Name As AlphaFrom,
E2.Roledef->ReportingCategory2->Name As AlphaThru
FROM SECURITYPLUS.USR S2, SecurityPlus.UsrETMRole E2,
SecurityPlus.UsrETMApplication A2
WHERE A2.USR = S2.USERNAME AND
E2.USRETMAPPLICATION = A2.ID AND S2.Username = ?
AND E2.Roledef->Name ['Alpha'
返回:
AlphaFrom AlphaThru
A CZZZ
T ZZZZ
我怀疑我将不得不放弃子查询才能完成此操作,因为加入它们的尝试失败了,但我不确定如何继续。