--- a/src/test/scala/RDB2RDFTest.scala Thu Jan 28 21:49:59 2010 -0500
+++ b/src/test/scala/RDB2RDFTest.scala Thu Jan 28 22:49:00 2010 -0500
@@ -829,5 +829,114 @@
"""
}
+ val hosp1:DatabaseDesc = DatabaseDesc(
+ Map(Relation("Person") ->
+ RelationDesc(Option(Attribute("ID")),
+ Map(Attribute("ID") -> Value(Datatype.INTEGER),
+ Attribute("MiddleName") -> Value(Datatype.STRING),
+ Attribute("DateOfBirth") -> Value(Datatype.DATE),
+ Attribute("SexDE") -> ForeignKey(Relation("Sex_DE"), Attribute("ID")))),
+ Relation("Sex_DE") ->
+ RelationDesc(Option(Attribute("ID")),
+ Map(Attribute("ID") -> Value(Datatype.INTEGER),
+ Attribute("EntryName") -> Value(Datatype.STRING))),
+ Relation("Item_Medication") ->
+ RelationDesc(Option(Attribute("ID")),
+ Map(Attribute("ID") -> Value(Datatype.INTEGER),
+ Attribute("PatientID") -> ForeignKey(Relation("Person"), Attribute("ID")),
+ Attribute("PerformedDTTM") -> Value(Datatype.DATE),
+ Attribute("EntryName") -> Value(Datatype.STRING))),
+ Relation("Medication") ->
+ RelationDesc(Option(Attribute("ID")),
+ Map(Attribute("ID") -> Value(Datatype.INTEGER),
+ Attribute("ItemID") -> ForeignKey(Relation("Item_Medication"), Attribute("ID")),
+ Attribute("MedDictDE") -> ForeignKey(Relation("Medication_DE"), Attribute("ID")))),
+ Relation("Medication_DE") ->
+ RelationDesc(Option(Attribute("ID")),
+ Map(Attribute("ID") -> Value(Datatype.INTEGER),
+ Attribute("NDC") -> Value(Datatype.INTEGER))),
+ Relation("NDCcodes") ->
+ RelationDesc(Option(Attribute("ID")),
+ Map(Attribute("ID") -> Value(Datatype.INTEGER),
+ Attribute("NDC") -> Value(Datatype.INTEGER),
+ Attribute("ingredient") -> Value(Datatype.INTEGER)))
+ ))
+
+ test("swobjects/tests/healthCare/lists-notBound/db.rq") {
+ val sparqlParser = Sparql()
+ val sparqlSelect = sparqlParser.parseAll(sparqlParser.select, """
+PREFIX Person: <http://hospital.example/DB/Person#>
+PREFIX Sex_DE: <http://hospital.example/DB/Sex_DE#>
+PREFIX Item_Medication: <http://hospital.example/DB/Item_Medication#>
+PREFIX Medication: <http://hospital.example/DB/Medication#>
+PREFIX Medication_DE: <http://hospital.example/DB/Medication_DE#>
+PREFIX NDCcodes: <http://hospital.example/DB/NDCcodes#>
+PREFIX xsd : <http://www.w3.org/2001/XMLSchema#>
+
+SELECT ?patient
+ WHERE {
+ ?patient Person:MiddleName ?middleName .
+ ?patient Person:DateOfBirth ?dob .
+ ?patient Person:SexDE ?sexEntry .
+ ?sexEntry Sex_DE:EntryName ?sex .
+
+ ?indicItem Item_Medication:PatientID ?patient .
+ ?indicItem Item_Medication:PerformedDTTM ?indicDate .
+ ?indicItem Item_Medication:EntryName ?takes .
+ ?indicMed Medication:ItemID ?indicItem .
+ ?indicMed Medication:MedDictDE ?indicDE .
+ ?indicDE Medication_DE:NDC ?indicNDC .
+ ?indicCode NDCcodes:NDC ?indicNDC .
+ ?indicCode NDCcodes:ingredient "6809"^^xsd:integer
+
+ OPTIONAL {
+ ?disqualItem Item_Medication:PatientID ?patient .
+ ?disqualItem Item_Medication:PerformedDTTM ?disqualDate .
+ ?disqualItem Item_Medication:EntryName ?takes .
+ ?disqualMed Medication:ItemID ?disqualItem .
+ ?disqualMed Medication:MedDictDE ?disqualDE .
+ ?disqualDE Medication_DE:NDC ?disqualNDC .
+ ?disqualCode NDCcodes:NDC ?disqualNDC .
+ ?disqualCode NDCcodes:ingredient "11289"^^xsd:integer
+ }
+ }
+""").get // FILTER (!BOUND(?disqualItem))
+ val sqlParser = Sql()
+ val parsed = sqlParser.parseAll(sqlParser.select, """
+SELECT R_patient.ID AS patient
+ FROM Person AS R_patient
+ INNER JOIN Sex_DE AS R_sexEntry ON R_sexEntry.ID=R_patient.SexDE
+ INNER JOIN Item_Medication AS R_indicItem ON R_indicItem.PatientID=R_patient.ID
+ INNER JOIN Medication AS R_indicMed ON R_indicMed.ItemID=R_indicItem.ID
+ INNER JOIN Medication_DE AS R_indicDE ON R_indicDE.ID=R_indicMed.MedDictDE
+ INNER JOIN NDCcodes AS R_indicCode ON R_indicCode.NDC=R_indicDE.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
+ ) AS G_opt6 ON G_opt6.patient=R_patient.ID
+ AND G_opt6.takes=R_indicItem.EntryName
+ WHERE R_indicCode.ingredient=6809
+ AND R_indicItem.EntryName IS NOT NULL
+ AND R_indicItem.PerformedDTTM IS NOT NULL
+ AND R_patient.DateOfBirth IS NOT NULL
+ AND R_patient.MiddleName IS NOT NULL
+ AND R_sexEntry.EntryName IS NOT NULL
+""") // AND G_opt6.patient IS NULL
+ val generated = RDB2RDF(hosp1, sparqlSelect, StemURI("http://hospital.example/DB/"), false, false)
+ assert(generated === parsed)
+ val output = """
+"""
+ }
+
}