Skip to content

Commit 2716524

Browse files
authored
Merge pull request #61 from projkov/update-readme
Add detailed tutorials for managing user data and resources in README…
2 parents ea95247 + 0870cb0 commit 2716524

3 files changed

Lines changed: 176 additions & 0 deletions

File tree

README.md

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,148 @@ cp .env.tpl .env
88
Run aidbox and otehr components with docker
99
```
1010
docker compose up
11+
```
12+
13+
## Tutorials
14+
15+
### Delete data of any user
16+
17+
The patient user in the system owns the following resources: User, Role, Patient, and QuestionnaireResponse.
18+
To delete these resources, we first need to obtain the patient's ID. Then, we execute SQL commands to remove the associated data.
19+
20+
This is a step-by-step guide on how to delete all related resources for a specific user using Aidbox's DB console.
21+
22+
**Short description:** Retrieve the patient's ID and email, then run SQL commands to filter and delete the corresponding resources from the database.
23+
24+
#### 1. Get user IDS, phones and email
25+
26+
```sql
27+
SELECT
28+
id AS ID,
29+
(
30+
SELECT t->>'value'
31+
FROM jsonb_array_elements(resource->'telecom') AS t
32+
WHERE t->>'system' = 'email'
33+
LIMIT 1
34+
) AS email,
35+
(
36+
SELECT t->>'value'
37+
FROM jsonb_array_elements(resource->'telecom') AS t
38+
WHERE t->>'system' = 'phone'
39+
LIMIT 1
40+
) AS phone
41+
FROM patient
42+
WHERE "patient".resource::text ILIKE '%YOUR_SEARCH_STRING%';
43+
```
44+
45+
Replace **YOUR_SEARCH_STRING** to find a patient with any information, ex: email, name, etc...
46+
47+
#### 2. Delete user
48+
49+
```sql
50+
DELETE FROM "user"
51+
WHERE resource#>>'{email}' = 'USER_EMAIL';
52+
```
53+
54+
#### 3. Delete user role
55+
56+
```sql
57+
DELETE FROM role
58+
WHERE resource#>>'{links,patient,id}' = 'PATIENT_ID';
59+
```
60+
61+
#### 4. Delete user patient
62+
63+
```sql
64+
DELETE FROM patient
65+
WHERE id = 'PATIENT_ID';
66+
```
67+
68+
#### 5. Delete user questionnaire responses
69+
70+
```sql
71+
DELETE FROM QuestionnaireResponse
72+
WHERE resource#>>'{subject,id}' = 'PATIENT_ID';
73+
```
74+
75+
#### Example of all commands with known patient's ID and email
76+
77+
```sql
78+
DELETE FROM "user" WHERE resource#>>'{email}' = 'USER_EMAIL';
79+
DELETE FROM role WHERE resource#>>'{links,patient,id}' = 'PATIENT_ID';
80+
DELETE FROM patient WHERE id = 'PATIENT_ID';
81+
DELETE FROM QuestionnaireResponse WHERE resource#>>'{subject,id}' = 'PATIENT_ID';
82+
```
83+
84+
### Create new coordinators
85+
86+
To create a coordinator, you need to add two entities to the system: User and Role.
87+
88+
Below, you will find links to create them in the Aidbox console, along with information about the required fields and which values you need to modify to ensure each coordinator is unique and valid.
89+
90+
Please note that the order of creation is important, as there are dependencies between the resources.
91+
92+
In this document aidbox backend reference is http://localhost:8080. You need to use correct address.
93+
94+
#### 1. Create User resource
95+
96+
Use this link:
97+
98+
```bash
99+
http://localhost:8080/ui/console#/resource-types/User/new?tab=raw&create=true&raw-format=json
100+
```
101+
102+
```json
103+
{
104+
"password": "password",
105+
"id": "my-custom-coordinator",
106+
"resourceType": "User",
107+
"email": "admin@pro.com"
108+
}
109+
```
110+
111+
**Important notes:**
112+
113+
1. Don't forget to use a strong password;
114+
2. You can use any id or just skip it.
115+
116+
#### 2. Create Role resource
117+
118+
Use this link:
119+
120+
```bash
121+
http://localhost:8080/ui/console#/resource-types/Role/new?tab=raw&create=true&raw-format=json
122+
```
123+
124+
```json
125+
{
126+
"name": "admin",
127+
"user": {
128+
"reference": "User/my-custom-coordinator"
129+
},
130+
"links": {
131+
"organization": {
132+
"reference": "Organization/mammochat"
133+
}
134+
},
135+
"id": "my-custom-coordinator",
136+
"resourceType": "Role"
137+
}
138+
```
139+
140+
**Important notes:**
141+
142+
1. Use need to use a reference to your previously created User ID;
143+
2. You can use any id or just skip it.
144+
145+
### Request patient's data through FHIR API
146+
147+
You can retrieve data for a specific user by searching for the Patient resource by ID, along with related QuestionnaireResponse resources using the _revinclude search parameter. This approach will return a Bundle of type searchset, which should contain a single Patient resource and three QuestionnaireResponse resources.
148+
149+
Below is an example of such a request. You can use Aidbox's REST console to execute it.
150+
151+
```bash
152+
GET /fhir/Patient?_id=patient_id&_revinclude=QuestionnaireResponse:subject
153+
content-type: application/json
154+
accept: application/json
11155
```
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
type: sql
2+
command: >-
3+
DELETE FROM "user" WHERE resource#>>'{email}' = 'USER_EMAIL';
4+
5+
DELETE FROM role WHERE resource#>>'{links,patient,id}' = 'PATIENT_ID';
6+
7+
DELETE FROM patient WHERE id = 'PATIENT_ID';
8+
9+
DELETE FROM QuestionnaireResponse WHERE resource#>>'{subject,id}' =
10+
'PATIENT_ID';
11+
id: delete-patients-and-related-data
12+
resourceType: ui_snippet
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
type: sql
2+
command: |-
3+
SELECT
4+
id AS ID,
5+
(
6+
SELECT t->>'value'
7+
FROM jsonb_array_elements(resource->'telecom') AS t
8+
WHERE t->>'system' = 'email'
9+
LIMIT 1
10+
) AS email,
11+
(
12+
SELECT t->>'value'
13+
FROM jsonb_array_elements(resource->'telecom') AS t
14+
WHERE t->>'system' = 'phone'
15+
LIMIT 1
16+
) AS phone
17+
FROM patient
18+
WHERE "patient".resource::text ILIKE '%patient%'
19+
id: search-patients
20+
resourceType: ui_snippet

0 commit comments

Comments
 (0)