Skip to content

Commit 80ff388

Browse files
authored
Merge pull request #2827 from Permify/omer/fix-healthcare-example
docs: update healthcare example
2 parents 3eca4b6 + 91b7210 commit 80ff388

1 file changed

Lines changed: 15 additions & 23 deletions

File tree

docs/getting-started/examples/healthcare.mdx

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,26 @@ entity group {
3232
permission view = edit or partner.view
3333
}
3434
35-
entity state {
36-
attribute age_limit integer
37-
38-
rule check_age(age integer) {
39-
this.age_limit > age
40-
}
41-
}
42-
4335
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.
4537
relation primary_doctor @doctor
4638
relation consultant @doctor
4739
relation group @group
48-
relation state @state
4940
relation owner @user
5041
relation guardian @user
5142
5243
attribute age integer
5344
5445
// Permissions for accessing patient data.
55-
permission parent_access = state.check_age(age)
46+
permission parent_access = check_age(age)
5647
permission edit = owner or group.edit or primary_doctor or consultant
5748
permission view = edit or group.view or guardian
5849
}
5950
51+
rule check_age(age integer) {
52+
age < 18
53+
}
54+
6055
entity medical_record {
6156
// Each medical record pertains to a patient and a doctor.
6257
relation patient @patient
@@ -137,30 +132,27 @@ Here’s a breakdown of the combined schema, explaining each part and how it fun
137132
- `permission view = edit or partner.view`: The view permission is granted if a user has edit access or if the partner can view.
138133
- **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.
139134

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 { ... }`
149136

150137
- **Relations**:
151138
- `relation primary_doctor @doctor`: A patient has a primary doctor.
152139
- `relation consultant @doctor`: A patient can have consultant doctors.
153140
- `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.
155141
- `relation owner @user`: An owner (usually a guardian or caregiver) is associated with the patient.
156142
- `relation guardian @user`: A guardian can also be linked to a patient.
157143
- **Attributes**:
158144
- `attribute age integer`: Represents the patient's age.
159145
- **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.
161147
- `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.
162148
- `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.
164156

165157
### 7. `entity medical_record { ... }`
166158

0 commit comments

Comments
 (0)