You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/getting-started/examples/healthcare.mdx
+15-23Lines changed: 15 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,31 +32,26 @@ entity group {
32
32
permission view = edit or partner.view
33
33
}
34
34
35
-
entity state {
36
-
attribute age_limit integer
37
-
38
-
rule check_age(age integer) {
39
-
this.age_limit > age
40
-
}
41
-
}
42
-
43
35
entity patient {
44
-
// Patients can have multiple doctors and be linked to groups and states.
36
+
// Patients can have multiple doctors and be linked to groups.
45
37
relation primary_doctor @doctor
46
38
relation consultant @doctor
47
39
relation group @group
48
-
relation state @state
49
40
relation owner @user
50
41
relation guardian @user
51
42
52
43
attribute age integer
53
44
54
45
// Permissions for accessing patient data.
55
-
permission parent_access = state.check_age(age)
46
+
permission parent_access = check_age(age)
56
47
permission edit = owner or group.edit or primary_doctor or consultant
57
48
permission view = edit or group.view or guardian
58
49
}
59
50
51
+
rule check_age(age integer) {
52
+
age < 18
53
+
}
54
+
60
55
entity medical_record {
61
56
// Each medical record pertains to a patient and a doctor.
62
57
relation patient @patient
@@ -137,30 +132,27 @@ Here’s a breakdown of the combined schema, explaining each part and how it fun
137
132
-`permission view = edit or partner.view`: The view permission is granted if a user has edit access or if the partner can view.
138
133
-**Explanation**: Groups are collections that can include doctors and be tied to partners. This entity manages permissions for actions within the group, such as editing or viewing.
139
134
140
-
### 5. `entity state { ... }`
141
-
142
-
-**Attributes**:
143
-
-`attribute age_limit integer`: The state entity has an `age_limit` attribute of type integer.
144
-
-**Rules**:
145
-
-`rule check_age(age integer) { this.age_limit > age }`: This rule checks if the state's age limit is greater than a specified age.
146
-
-**Explanation**: This entity allows defining conditions or rules based on age, which can be used in permissions for entities like patients.
147
-
148
-
### 6. `entity patient { ... }`
135
+
### 5. `entity patient { ... }`
149
136
150
137
-**Relations**:
151
138
-`relation primary_doctor @doctor`: A patient has a primary doctor.
152
139
-`relation consultant @doctor`: A patient can have consultant doctors.
153
140
-`relation group @group`: Patients can be linked to groups (e.g., departments).
154
-
-`relation state @state`: Patients have a state, potentially linked to age-based permissions.
155
141
-`relation owner @user`: An owner (usually a guardian or caregiver) is associated with the patient.
156
142
-`relation guardian @user`: A guardian can also be linked to a patient.
157
143
-**Attributes**:
158
144
-`attribute age integer`: Represents the patient's age.
159
145
-**Permissions**:
160
-
-`permission parent_access = state.check_age(age)`: The permission for parent access is granted if the state’s`check_age` rule is met.
146
+
-`permission parent_access = check_age(age)`: The permission for parent access is granted when the schema-level`check_age` rule evaluates true for underage patients.
161
147
-`permission edit = owner or group.edit or primary_doctor or consultant`: Editing permissions are granted to the owner, group members with edit rights, or the doctors.
162
148
-`permission view = edit or group.view or guardian`: View permissions extend to anyone who can edit, group members who can view, or the guardian.
163
-
-**Explanation**: This entity models patients and defines relationships with doctors, groups, and guardians. Permissions are fine-grained, involving rules based on age and relationships with other entities.
149
+
-**Explanation**: This entity models patients and defines relationships with doctors, groups, and guardians. Permissions are fine-grained, including a simple age-based rule for underage access.
150
+
151
+
### 6. `rule check_age(age integer)`
152
+
153
+
-**Rule**:
154
+
-`rule check_age(age integer) { age < 18 }`: This rule evaluates an age-based condition and returns a boolean result.
155
+
-**Explanation**: In Permify, rules are schema-level definitions that evaluate conditions and return a boolean result. This rule is used to determine whether a patient qualifies for age-based access.
0 commit comments