cdisc-org / conformance-rules-editor

MIT License
6 stars 3 forks source link

Update select statements for get_rules #173

Closed gerrycampion closed 8 months ago

gerrycampion commented 1 year ago

Currently the get_rules queries are written as:

SELECT Rules1.json
FROM Rules1
JOIN Rules2 IN Rules1["json"]["Authorities"]
JOIN Rules3 IN Rules2["Standards"]
JOIN Rules4 IN Rules3["References"]
WHERE CONTAINS(Rules4["Rule_Identifier"]["Id"], "CG0", true)

The external joins should be converted to arrays and subqueries, for example:

SELECT DISTINCT
Rule["Core"]["Id"] ?? null as "CORE-ID",
ARRAY(SELECT DISTINCT VALUE Reference["Rule_Identifier"]["Id"] FROM Authority IN Rule["Authorities"] JOIN Standard IN Authority["Standards"] JOIN Reference IN Standard["References"]) as "CDISC Rule ID",
Rule["Outcome"]["Message"] ?? null as "Error Message",
Rule["Description"] ?? null as "Description",
ARRAY(SELECT DISTINCT VALUE Authority["Organization"] FROM Authority IN Rule["Authorities"]) as "Organization",
ARRAY(SELECT DISTINCT VALUE Standard["Name"] FROM Authority IN Rule["Authorities"] JOIN Standard IN Authority["Standards"]) as "Standard Name",
ARRAY(SELECT DISTINCT VALUE Standard["Version"] FROM Authority IN Rule["Authorities"] JOIN Standard IN Authority["Standards"]) as "Standard Version",
Rule["Executability"] ?? null as "Executability",
Rule["Core"]["Status"] ?? null as "Status"
FROM Rules["json"] as Rule
ORDER BY Rule["Core"]["Id"] ASC

This will reduce the size of the rules listing request and improve performance. Refer to: https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/query/subquery

AC: Get_rules selections have been converted to individual subqueries. Corresponding logic on the frontend handles the arrays that are returned instead of full json objects.