我正在尝试编写一个SPARQL查询,该查询将返回一组患者标识符代码(?Crid),这些代码与他们相关联的特定诊断代码(?ICD9)并且没有与他们相关联的特定药物AND在招聘日期之前的订单日期(?OrderDate)(?RecruitDate)。我已将OBIB本体合并到我的图表中。
这是我到目前为止所做的事情(稍微简化了一下,为了便于阅读/敏感而忽略了几个步骤):
SELECT DISTINCT ?Crid WHERE
{?Crid a obib:CRID .
#-- Return CRIDs with a diagnosis
?Crid obib:hasPart ?ICD9 .
?ICD9 a obib:diagnosis .
#-- Return CRIDs with a medical prescription record
?Crid obib:hasPart ?medRecord .
?medRecord a obib:medicalRecord .
#-- Return CRIDs with an order date
?medRecord obib:hasPart ?OrderDate .
?OrderDate a obib:dateOfDataEntry .
#-- Return CRIDs with a recruitment date
?Crid obib:hasPart ?FormFilling .
?FormFilling a obib:formFilling .
?RecruitDate obib:isAbout ?FormFilling .
?RecruitDate a obib:dateOfDataEntry .
#-- Filter results for specific ICD9 codes
FILTER (?ICD9 = '1')
#-- Subtract Results with Certain Medication and Order Date Prior to Recruitment
#-- This is the part that I think is giving me a problem
MINUS {
FILTER (regex (?medRecord, "medication_1", "i"))
FILTER (?RecruitDate-?OrderDate < "P0D"^^xsd:dayTimeDuration)
}
}
我的直觉是我没有正确使用MINUS。此查询返回主要是正确的结果:我期待10个结果并返回12.无关的2个结果确实需要“药物1”并且在其招募日期之前有订单日期,所以我不想要它们被包括在集合中。
如果重要,我使用Stardog端点来运行此查询并存储我的图表数据。
答案 0 :(得分:1)
而不是
#-- Subtract Results with Certain Medication and Order Date Prior to Recruitment
#-- This is the part that I think is giving me a problem
MINUS {
FILTER (regex (?medRecord, "medication_1", "i"))
FILTER (?RecruitDate-?OrderDate < "P0D"^^xsd:dayTimeDuration)
}
}
我可能只是在没有MINUS的情况下写这个:
FILTER (!regex(?medRecord, "medication_1", "i"))
FILTER (?RecruitDate-?OrderDate >= "P0D"^^xsd:dayTimeDuration)
我也可能会考虑REGEX是否是正确的工具(简单的字符串比较会起作用吗?),但这是一个不同的问题。