0

我正在尝试编写一个 SPARQL 查询,该查询将返回一组患者标识符代码 (?Crid),这些代码与特定的诊断代码 (?ICD9) 相关联,并且没有与特定的药物相关联并且具有订单日期(?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 个结果确实采用了“medication_1”,并且订单日期早于其招聘日期,因此我不希望它们包含在集合中。

万一这很重要,我将使用 Stardog 端点来运行此查询并存储我的图形数据。

4

1 回答 1

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 是否是正确的工具(简单的字符串比较会起作用吗?),但这是一个不同的问题。

于 2017-02-10T17:55:28.227 回答