Skip to content

Commit a073c80

Browse files
committed
ezhuthachan to clarify things before proceeding
1 parent f09f368 commit a073c80

6 files changed

Lines changed: 491 additions & 13 deletions

File tree

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
# CARE Codebase Navigation Guide
2+
3+
Pre-verified map of both repositories. Use these paths and grep patterns directly —
4+
do NOT re-analyze how RBAC, i18n, shortcuts, or routing work.
5+
6+
Repository roots, cloned as siblings of the docs repository:
7+
8+
- Backend: `../care` (Django 6 + DRF, Python 3.13)
9+
- Frontend: `../care_fe` (React 19 + TypeScript + Vite, raviger, TanStack Query)
10+
11+
---
12+
13+
## Backend (`care/`)
14+
15+
### Permissions (RBAC)
16+
17+
- **Definitions:** `care/security/permissions/{domain}.py` — one file per domain
18+
(`patient.py`, `encounter.py`, `facility.py`, `questionnaire.py`, ...). Each file has an
19+
enum class like `PatientPermissions` whose members follow `can_<action>_<resource>`
20+
(e.g., `can_create_patient`, `can_list_patients`).
21+
- Each member is a `Permission` dataclass: display name, description, `PermissionContext`
22+
(GENERIC | FACILITY | PATIENT | QUESTIONNAIRE | ORGANIZATION | FACILITY_ORGANIZATION |
23+
ENCOUNTER), and the list of roles that hold it. **The first argument is the
24+
human-readable permission name to use in docs** (e.g., `"Can Create Patient"`).
25+
- `Permission` / `PermissionContext` classes: `care/security/permissions/constants.py`
26+
- Aggregator: `care/security/permissions/base.py`
27+
28+
### Roles
29+
30+
- Predefined roles: `care/security/roles/role.py``DOCTOR_ROLE`, `NURSE_ROLE`,
31+
`STAFF_ROLE`, `VOLUNTEER_ROLE`, `PHARMACIST_ROLE`, `ADMINISTRATOR`,
32+
`FACILITY_ADMIN_ROLE`, `ADMIN_ROLE`, plus `ROLE_ORGANIZATION_*` variants.
33+
- Role→permission mapping: each `Permission` definition lists its roles inline.
34+
35+
### Authorization flow (how to find which permission gates an action)
36+
37+
1. Open the domain viewset: `care/emr/api/viewsets/{domain}.py`
38+
(e.g., `patient.py``PatientViewSet`).
39+
2. Find the `authorize_create` / `authorize_update` / `authorize_destroy` /
40+
`authorize_retrieve` overrides. Base mixins (`EMRCreateMixin` etc.) that call these
41+
hooks live in `care/emr/api/viewsets/base.py`.
42+
3. Each hook calls `AuthorizationController.call("can_<action>_<resource>", user, obj)`.
43+
4. The handler method lives in `care/security/authorization/{domain}.py`
44+
(e.g., `PatientAccess.can_create_patient`). Controller base:
45+
`care/security/authorization/base.py`.
46+
5. Map the permission slug back to its display name in
47+
`care/security/permissions/{domain}.py`.
48+
49+
```bash
50+
grep -rn "authorize_" care/emr/api/viewsets/<domain>.py
51+
grep -rn "def can_" care/security/authorization/<domain>.py
52+
grep -rn "can_<slug>" care/security/permissions/
53+
```
54+
55+
### Models, resource specs, enums
56+
57+
- Django models: `care/emr/models/{domain}.py`
58+
- Pydantic resource specs (field definitions, validation):
59+
`care/emr/resources/{domain}/spec.py` — classes extend `EMRResource`
60+
(`care/emr/resources/base.py`), `__model__` points to the Django model.
61+
- Status/choice enums: `care/emr/resources/{domain}/constants.py` or inside `spec.py`.
62+
Example: `StatusChoices` in `care/emr/resources/encounter/constants.py`
63+
(`planned`, `in_progress`, `on_hold`, `discharged`, `completed`, `cancelled`, ...).
64+
- Backend display names for some enums: `care/emr/resources/{domain}/enum_display_names.py`
65+
(e.g., `get_admit_source_display`). Prefer frontend i18n labels (see below) for
66+
user-facing terms; fall back to these.
67+
- FHIR alignment: valuesets in `care/emr/resources/{domain}/valueset.py` and
68+
`care/emr/registries/` (SNOMED CT `http://snomed.info/sct`, FHIR valuesets).
69+
70+
```bash
71+
grep -rn "class .*Choices" care/emr/resources/<domain>/
72+
grep -rn "__model__" care/emr/resources/<domain>/
73+
```
74+
75+
### Configuration that changes behavior
76+
77+
- Business config: `config/settings/config.py`. Known flags:
78+
- `PATIENT_GLOBAL_EDIT_ACCESS_ENABLED` — patient edit scope
79+
- `MAINTAIN_PATIENT_NAME_IDENTIFIER`, `MAINTAIN_PATIENT_PHONE_NUMBER_IDENTIFIER`,
80+
`MAINTAIN_FACILITY_PATIENT_NAME_IDENTIFIER`, `PATIENT_NAME_MAX_LENGTH`
81+
- Limits: `MAX_APPOINTMENTS_PER_PATIENT`,
82+
`MAX_ACTIVE_ENCOUNTERS_PER_PATIENT_IN_FACILITY`, `ENCOUNTER_RESTART_TIME_LIMIT_HOURS`
83+
- Billing: `TAX_CODES`, `DISCOUNT_CODES`, `INVOICE_FREE_CANCEL_PERIOD_MINUTES`
84+
- Patient identifier config model: `PatientIdentifierConfig` in `care/emr/models/patient.py`,
85+
spec in `care/emr/resources/patient/spec.py`, authz in
86+
`care/security/authorization/patient_identifier_config.py`.
87+
- Plugin system: `plug_config.py` (root).
88+
89+
Always check whether a flow's behavior depends on these before writing "Note:" lines.
90+
91+
### API routing and fixtures
92+
93+
- Endpoint registration: `config/api_router.py`
94+
- Fixtures (example data, behavior reference): `care/fixtures/`
95+
`base.py` (`create_*` helpers), `scripts/default_fixtures.py`, `fixtures.md`.
96+
97+
---
98+
99+
## Frontend (`care_fe/`)
100+
101+
### i18n and enum display labels (CRITICAL for user-facing terms)
102+
103+
- All English strings: `public/locale/en.json`
104+
- Enum display keys follow `{PREFIX}__{value}`:
105+
- `encounter_status__in_progress` → "In Progress"
106+
- `GENDER__male` → "Male"
107+
- `BLOOD_GROUP_LONG__AB_positive` → "AB Positive"
108+
- To find the label for a coded value:
109+
110+
```bash
111+
grep -n "__<enum_value>" public/locale/en.json
112+
grep -n "\"<field_label_key>\"" public/locale/en.json
113+
```
114+
115+
Docs MUST use these labels, never codebase literals.
116+
117+
### Keyboard shortcuts
118+
119+
- Registry: `src/config/keyboardShortcuts.json` — entries per context
120+
(e.g., `facility:patient:home`) with `key`, `action`, `description`, `when`.
121+
- Runtime: `src/context/ShortcutContext.tsx`, `src/hooks/useKeyboardShortcuts.ts`,
122+
helpers in `src/Utils/keyboardShortcutUtils.ts`.
123+
- Form submit shortcut is the `submit-action` entry (currently `Shift+Enter`).
124+
**Always check the JSON — do not assume Ctrl+Enter.**
125+
126+
```bash
127+
grep -n "<action-or-key>" src/config/keyboardShortcuts.json
128+
```
129+
130+
### Routes and navigation
131+
132+
- Route files: `src/Routers/routes/*Routes.tsx`
133+
(`FacilityRoutes.tsx`, `PatientRoutes.tsx`, `ConsultationRoutes.tsx`, ...),
134+
combined in `src/Routers/AppRouter.tsx`.
135+
- Sidebar/left-nav items (names, order, permission gating):
136+
`src/components/ui/sidebar/facility/facility-nav.tsx` (facility),
137+
dispatcher `src/components/ui/sidebar/app-sidebar.tsx`,
138+
renderer `src/components/ui/sidebar/nav-main.tsx`.
139+
- Use these to write accurate "Steps": nav label → route → page component.
140+
141+
### Forms (fields, required/optional, sections)
142+
143+
- Pattern: react-hook-form + zod. Example: patient registration in
144+
`src/components/Patient/PatientRegistration.tsx``getFormSchema()` defines
145+
required (`.nonempty(...)`) vs optional (`.optional()`) vs conditional fields.
146+
- Deployment config affecting forms: `care.config.ts` (root) — e.g.,
147+
`patientRegistration.minimalPatientRegistration`,
148+
`openScheduleAfterPatientRegistration`, `encounterClasses`
149+
(from `REACT_ALLOWED_ENCOUNTER_CLASSES`). Check this file for every flow.
150+
151+
### API layer
152+
153+
- Route definitions: `src/types/{domain}/{domain}Api.ts`
154+
(e.g., `src/types/emr/patient/patientApi.ts`) — typed path/method/TBody/TRes objects.
155+
- Wrappers: `src/Utils/request/query.ts` and `src/Utils/request/mutate.ts`.
156+
- Use these to confirm which backend endpoint a UI action calls.
157+
158+
### Frontend enums and styling
159+
160+
- Enum constants + badge colors/icons: `src/types/emr/{domain}/{domain}.ts`
161+
(e.g., `EncounterStatus`, `ENCOUNTER_STATUS_COLORS` in
162+
`src/types/emr/encounter/encounter.ts`).
163+
164+
### Frontend permission checks
165+
166+
- `src/context/PermissionContext.tsx``usePermissions()` / `useHasPermission("<slug>")`.
167+
- Used in sidebar `visibility` props and page actions. Cross-check with backend
168+
permission slugs to confirm what the UI hides vs what the API enforces.
169+
170+
---
171+
172+
## FHIR R5 references
173+
174+
- Base URL: `https://build.fhir.org/`
175+
- Resource pages: `https://build.fhir.org/<resource>.html`
176+
(patient, encounter, observation, questionnaire, medicationrequest,
177+
servicerequest, location, appointment, careplan, ...)
178+
- Link the FHIR resource on first mention of the concept in every concept doc.

0 commit comments

Comments
 (0)