Debian Codegraph @

reasoning/four-types-of-specification/health-hypertension-copay-aid.n3

raw
1 ### 1) VOCAB_TTL ###
2 @prefix ex: <https://example.org/health#> .
3 @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
4 @prefix skos: <http://www.w3.org/2004/02/skos/core#> .
5 @prefix foaf: <http://xmlns.com/foaf/0.1/> .
6 @prefix dct: <http://purl.org/dc/terms/> .
7 @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
8
9 ex:Patient a rdfs:Class ; rdfs:label "Patient" ; rdfs:subClassOf foaf:Person .
10 ex:CoPayApplication a rdfs:Class ; rdfs:label "Hypertension Co-pay Application" .
11 ex:HealthcarePayment a rdfs:Class ; rdfs:label "Healthcare Payment" .
12
13 ex:HypertensionCoPayAid a skos:Concept ; skos:prefLabel "Hypertension Co-pay Aid" .
14
15 ex:hasApplicant a rdf:Property ; rdfs:domain ex:CoPayApplication ; rdfs:range ex:Patient ; rdfs:label "has applicant" .
16 ex:appliesFor a rdf:Property ; rdfs:domain ex:CoPayApplication ; rdfs:range skos:Concept ; rdfs:label "applies for" .
17 ex:status a rdf:Property ; rdfs:domain ex:CoPayApplication ; rdfs:label "status" .
18 ex:eligible a rdf:Property ; rdfs:domain ex:CoPayApplication ; rdfs:label "eligible" .
19 ex:issuedPayment a rdf:Property ; rdfs:domain ex:CoPayApplication ; rdfs:range ex:HealthcarePayment ; rdfs:label "issued payment" .
20
21 ex:hasAge a rdf:Property ; rdfs:domain ex:Patient ; rdfs:label "age" .
22 ex:bpS1 a rdf:Property ; rdfs:domain ex:Patient ; rdfs:label "systolic BP reading 1" .
23 ex:bpS2 a rdf:Property ; rdfs:domain ex:Patient ; rdfs:label "systolic BP reading 2" .
24 ex:bpS3 a rdf:Property ; rdfs:domain ex:Patient ; rdfs:label "systolic BP reading 3" .
25
26 ex:hasEvidence a rdf:Property ; rdfs:domain ex:CoPayApplication ; rdfs:label "has evidence" .
27 ex:AgeEvidence a rdfs:Class ; rdfs:label "Age Evidence" .
28 ex:BPReadingEvidence a rdfs:Class ; rdfs:label "BP Reading Evidence" .
29
30 # Minimal statuses as SKOS concepts
31 ex:Submitted a skos:Concept ; skos:prefLabel "Submitted" .
32 ex:Approved a skos:Concept ; skos:prefLabel "Approved" .
33 ex:Rejected a skos:Concept ; skos:prefLabel "Rejected" .
34
35 ### 2) PROFILE_SHACL_TTL ###
36 @prefix sh: <http://www.w3.org/ns/shacl#> .
37 @prefix ex: <https://example.org/health#> .
38 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
39
40 ex:CoPayApplicationShape a sh:NodeShape ;
41 sh:targetClass ex:CoPayApplication ;
42 sh:property [
43 sh:path ex:hasApplicant ;
44 sh:minCount 1 ;
45 sh:nodeKind sh:IRI ;
46 ] ;
47 sh:property [
48 sh:path ex:appliesFor ;
49 sh:hasValue ex:HypertensionCoPayAid ;
50 sh:minCount 1 ;
51 ] ;
52 sh:property [
53 sh:path ex:status ;
54 sh:minCount 1 ;
55 ] ;
56 sh:property [
57 sh:path ex:hasEvidence ;
58 sh:minCount 3 ; # require at least three evidences (e.g., age + 2 BP proofs)
59 ] .
60
61 ex:PatientShape a sh:NodeShape ;
62 sh:targetClass ex:Patient ;
63 sh:property [
64 sh:path ex:hasAge ;
65 sh:minCount 1 ;
66 sh:datatype xsd:integer ;
67 ] ;
68 sh:property [
69 sh:path ex:bpS1 ;
70 sh:minCount 1 ;
71 sh:datatype xsd:integer ;
72 ] ;
73 sh:property [
74 sh:path ex:bpS2 ;
75 sh:minCount 1 ;
76 sh:datatype xsd:integer ;
77 ] ;
78 sh:property [
79 sh:path ex:bpS3 ;
80 sh:minCount 1 ;
81 sh:datatype xsd:integer ;
82 ] .
83
84 ### 3) RULES_N3 ###
85 # Interaction pattern: Hypertension Co-pay Aid
86 # States: Submitted -> (Eligible?) -> Approved/Rejected
87 # Preconditions: Application conforms to CoPayApplicationShape; Patient conforms to PatientShape
88 # Abstract messages: submitApplication, validate, decide, notify
89
90 @prefix ex: <https://example.org/health#> .
91 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
92 @prefix math: <http://www.w3.org/2000/10/swap/math#> .
93
94 # R1: Eligibility — age≥40 AND avg(systolic BP over 3 readings) ≥ 140
95 # avg = (r1 + r2 + r3) / 3
96 {
97 ?app ex:appliesFor ex:HypertensionCoPayAid .
98 ?app ex:hasApplicant ?p .
99 ?p ex:hasAge ?age .
100 ?p ex:bpS1 ?r1 .
101 ?p ex:bpS2 ?r2 .
102 ?p ex:bpS3 ?r3 .
103 "40"^^xsd:integer math:notGreaterThan ?age .
104 (?r1 ?r2) math:sum ?s12 .
105 (?s12 ?r3) math:sum ?sum3 .
106 (?sum3 "3"^^xsd:integer) math:quotient ?avg .
107 ?avg math:notLessThan "140"^^xsd:integer .
108 }
109 =>
110 {
111 ?app ex:eligible true .
112 } .
113
114 # R2: Approve — eligible true AND status Submitted → status Approved + payment issuance
115 {
116 ?app ex:eligible true .
117 ?app ex:status ex:Submitted .
118 }
119 =>
120 {
121 ?app ex:status ex:Approved .
122 _:pay a ex:HealthcarePayment .
123 ?app ex:issuedPayment _:pay .
124 } .
125
126 # R3: Reject — eligible false AND status Submitted → status Rejected
127 {
128 ?app ex:eligible false .
129 ?app ex:status ex:Submitted .
130 }
131 =>
132 {
133 ?app ex:status ex:Rejected .
134 } .
135
136 ### DATA (Turtle from FACTS) ###
137 @prefix ex: <https://example.org/health#> .
138 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
139 @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
140 @prefix skos: <http://www.w3.org/2004/02/skos/core#> .
141
142 ex:APP-HYP-01
143 ex:appliesFor ex:HypertensionCoPayAid ;
144 ex:hasApplicant ex:Dana ;
145 ex:hasEvidence "AgeEvidence" ;
146 ex:hasEvidence "BPReadingEvidence" ;
147 ex:hasEvidence "BPReadingEvidence" ;
148 ex:status ex:Submitted .
149
150 ex:Dana
151 ex:bpS1 150 ;
152 ex:bpS2 142 ;
153 ex:bpS3 138 ;
154 ex:hasAge 52 .
155