~ MINUS tests works
authorEric Prud'hommeaux <eric@w3.org>
Sun, 14 Feb 2010 12:49:28 -0500
changeset 173 690feb66a8c3
parent 172 22c5ef94fec7
child 174 1c281daa6a8b
~ MINUS tests works
src/test/scala/SparqlToSparqlToSqlTest.scala
--- a/src/test/scala/SparqlToSparqlToSqlTest.scala	Sun Feb 14 12:49:06 2010 -0500
+++ b/src/test/scala/SparqlToSparqlToSqlTest.scala	Sun Feb 14 12:49:28 2010 -0500
@@ -164,7 +164,7 @@
     val sparqlParser = Sparql()
     val hl7Query = sparqlParser.parseAll(sparqlParser.select, """
 PREFIX hl7: <http://www.hl7.org/v3ballot/xml/infrastructure/vocabulary/vocabulary#> 
-SELECT ?patient ?dob ?sex ?inclu_name ?indicDate 
+SELECT ?patient ?dob ?sex ?inclu_name 
 WHERE
 {
   ?patient a hl7:Person .
@@ -240,7 +240,7 @@
 PREFIX NDCcodes: <http://hospital.example/DB/NDCcodes#>
 PREFIX xsd : <http://www.w3.org/2001/XMLSchema#>
 
-SELECT ?patient ?dob ?sex ?inclu_name ?indicDate 
+SELECT ?patient ?dob ?sex ?inclu_name 
  WHERE {
     ?patient Person:MiddleName ?middleName .
     ?patient Person:DateOfBirth ?dob .
@@ -248,57 +248,52 @@
     ?_0_0_sexEntry Sex_DE:EntryName ?sex .
 
     ?_0_0_indicItem Item_Medication:PatientID ?patient .
-    ?_0_0_indicItem Item_Medication:PerformedDTTM ?indicDate .
-    ?_0_0_indicItem Item_Medication:EntryName ?takes .
+    ?_0_0_indicItem Item_Medication:EntryName ?inclu_name .
     ?_0_0_indicMed Medication:ItemID ?_0_0_indicItem .
     ?_0_0_indicMed Medication:MedDictDE ?_0_0_indicDE .
-    ?_0_0_indicDE Medication_DE:NDC ?indicNDC .
-    ?_0_0_indicCode NDCcodes:NDC ?indicNDC .
+    ?_0_0_indicDE Medication_DE:NDC ?_0_0_indicNDC .
+    ?_0_0_indicCode NDCcodes:NDC ?_0_0_indicNDC .
     ?_0_0_indicCode NDCcodes:ingredient 6809
 
     MINUS {
         ?_1_0_indicItem Item_Medication:PatientID ?patient .
-        ?_1_0_indicItem Item_Medication:PerformedDTTM ?indicDate .
-        ?_1_0_indicItem Item_Medication:EntryName ?takes .
+        ?_1_0_indicItem Item_Medication:EntryName ?exclu_name .
         ?_1_0_indicMed Medication:ItemID ?_1_0_indicItem .
         ?_1_0_indicMed Medication:MedDictDE ?_1_0_indicDE .
-        ?_1_0_indicDE Medication_DE:NDC ?indicNDC .
-        ?_1_0_indicCode NDCcodes:NDC ?indicNDC .
-        ?_1_0_indicCode NDCcodes:ingredient 11289
+        ?_1_0_indicDE Medication_DE:NDC ?_1_0_indicNDC .
+        ?_1_0_indicCode NDCcodes:NDC ?_1_0_indicNDC .
+        ?_1_0_indicCode NDCcodes:ingredient 11209
     }
       }
 """).get
     val sqlParser = Sql()
     val sqlQuery = sqlParser.parseAll(sqlParser.select, """
-SELECT R_patient.ID AS patient, R_patient.DateOfBirth AS dob, R__0_sexEntry.EntryName AS sex
+SELECT R_patient.ID AS patient, R_patient.DateOfBirth AS dob, R__0_0_indicItem.EntryName AS inclu_name, R__0_0_sexEntry.EntryName AS sex
   FROM Person AS R_patient
-       INNER JOIN Sex_DE AS R__0_sexEntry ON R__0_sexEntry.ID=R_patient.SexDE
-       INNER JOIN Item_Medication AS R__0_indicItem ON R__0_indicItem.PatientID=R_patient.ID
-       INNER JOIN Medication AS R__0_indicMed ON R__0_indicMed.ItemID=R__0_indicItem.ID
-       INNER JOIN Medication_DE AS R__0_indicDE ON R__0_indicDE.ID=R__0_indicMed.MedDictDE
-       INNER JOIN NDCcodes AS R__0_indicCode ON R__0_indicCode.NDC=R__0_indicDE.NDC
+       INNER JOIN Sex_DE AS R__0_0_sexEntry ON R__0_0_sexEntry.ID=R_patient.SexDE
+       INNER JOIN Item_Medication AS R__0_0_indicItem ON R__0_0_indicItem.PatientID=R_patient.ID
+       INNER JOIN Medication AS R__0_0_indicMed ON R__0_0_indicMed.ItemID=R__0_0_indicItem.ID
+       INNER JOIN Medication_DE AS R__0_0_indicDE ON R__0_0_indicMed.MedDictDE=R__0_0_indicDE.ID
+       INNER JOIN NDCcodes AS R__0_0_indicCode ON R__0_0_indicDE.NDC=R__0_0_indicCode.NDC
        LEFT OUTER JOIN (
-   SELECT R_disqualCode.ID AS disqualCode, R_disqualMed.MedDictDE AS disqualDE,
-          R_disqualItem.PerformedDTTM AS disqualDate, R_disqualItem.ID AS disqualItem,
-          R_disqualMed.ID AS disqualMed, R_disqualDE.NDC AS disqualNDC,
-          R_disqualItem.PatientID AS patient, R_disqualItem.EntryName AS takes, 6 AS _DISJOINT_
-     FROM Item_Medication AS R_disqualItem
-          INNER JOIN Medication AS R_disqualMed ON R_disqualMed.ItemID=R_disqualItem.ID
-          INNER JOIN Medication_DE AS R_disqualDE ON R_disqualDE.ID=R_disqualMed.MedDictDE
-          INNER JOIN NDCcodes AS R_disqualCode ON R_disqualCode.NDC=R_disqualDE.NDC
-    WHERE R_disqualCode.ingredient=11289
-      AND R_disqualItem.EntryName IS NOT NULL
-      AND R_disqualItem.PatientID IS NOT NULL
-      AND R_disqualItem.PerformedDTTM IS NOT NULL
+   SELECT 6 AS _DISJOINT_, R__1_0_indicMed.ID AS _1_0_indicMed,
+          R__1_0_indicMed.MedDictDE AS _1_0_indicDE, R__1_0_indicItem.ID AS _1_0_indicItem,
+          R__1_0_indicItem.EntryName AS exclu_name, R__1_0_indicItem.PatientID AS patient,
+          R__1_0_indicCode.ID AS _1_0_indicCode, R__1_0_indicCode.NDC AS _1_0_indicNDC
+     FROM Medication AS R__1_0_indicMed
+          INNER JOIN Item_Medication AS R__1_0_indicItem ON R__1_0_indicMed.ItemID=R__1_0_indicItem.ID
+          INNER JOIN Medication_DE AS R__1_0_indicDE ON R__1_0_indicDE.ID=R__1_0_indicMed.MedDictDE
+          INNER JOIN NDCcodes AS R__1_0_indicCode ON R__1_0_indicDE.NDC=R__1_0_indicCode.NDC
+    WHERE R__1_0_indicCode.ingredient=11209
+      AND R__1_0_indicItem.EntryName IS NOT NULL
+      AND R__1_0_indicItem.PatientID IS NOT NULL
               ) AS G_opt6 ON G_opt6.patient=R_patient.ID
-                         AND G_opt6.takes=R_indicItem.EntryName
  WHERE G_opt6._DISJOINT_ IS NULL
-   AND R__0_indicCode.ingredient=6809
-   AND R__0_sexEntry.ID=R_patient.SexDE
-   AND R__0_indicItem.EntryName IS NOT NULL
+   AND R__0_0_indicCode.ingredient=6809
+   AND R__0_0_indicItem.EntryName IS NOT NULL
    AND R_patient.DateOfBirth IS NOT NULL
    AND R_patient.MiddleName IS NOT NULL
-   AND R__0_sexEntry.EntryName IS NOT NULL
+   AND R__0_0_sexEntry.EntryName IS NOT NULL
 """).get
     val asStem = SparqlToSparql(hl7Query, List(db2hl7))
     if (!(asStem == stemQuery)) {