Patient Records¶
Legacy file-based patient record management.
This module provides file-based storage operations for patient records mounted at /patient_data in Docker containers. Each patient has their own subdirectory identified by a sanitized patient ID.
Note
This is a legacy system. Current implementation stores patient demographics in FHIR and clinical documents in OpenEHR (EHRbase). This module may be deprecated in future releases.
Attributes:
| Name | Type | Description |
|---|---|---|
PATIENT_DATA_ROOT |
Mount point for patient data volume (/patient_data). |
Demographics ¶
Bases: BaseModel
Patient demographic information.
Note
This schema is deprecated. Use FHIR Patient resources instead.
Attributes:
| Name | Type | Description |
|---|---|---|
given_name |
str | None
|
Patient's first name. |
family_name |
str | None
|
Patient's surname. |
date_of_birth |
str | None
|
ISO 8601 date string (YYYY-MM-DD). |
sex |
str | None
|
Patient's sex (male/female/other). |
address |
dict[str, Any] | None
|
Structured address (FHIR format). |
contact |
dict[str, Any] | None
|
Contact information (phone, email). |
meta |
dict[str, Any] | None
|
Additional metadata. |
Source code in app/patient_records.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
patient_repo_name ¶
patient_repo_name(patient_id)
Generate safe directory name for patient data.
Sanitizes patient ID by removing special characters to create a filesystem-safe directory name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
patient_id
|
str
|
FHIR patient resource ID. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Safe directory name like "patient-abc123". |
Raises:
| Type | Description |
|---|---|
ValueError
|
If patient_id is empty. |
Example
patient_repo_name("Patient/123") 'patient-Patient-123'
Source code in app/patient_records.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
ensure_repo_exists ¶
ensure_repo_exists(repo, private=False)
Create patient repository directory if it doesn't exist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo
|
str
|
Repository name (from patient_repo_name). |
required |
private
|
bool
|
Unused parameter (for future ACL implementation). |
False
|
Source code in app/patient_records.py
79 80 81 82 83 84 85 86 87 | |
write_file ¶
write_file(repo, path, content, commit_message='', author_name=None, author_email=None)
Write content to a file in patient repository.
Creates parent directories as needed. Returns path information for audit trail purposes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo
|
str
|
Repository name (from patient_repo_name). |
required |
path
|
str
|
Relative file path within repository. |
required |
content
|
str
|
Text content to write. |
required |
commit_message
|
str
|
Unused (for future git integration). |
''
|
author_name
|
str | None
|
Unused (for future git integration). |
None
|
author_email
|
str | None
|
Unused (for future git integration). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, Any]
|
Dictionary with 'path' key containing absolute file path. |
Example
write_file("patient-123", "notes.txt", "Patient notes here") {'path': '/patient_data/patient-123/notes.txt'}
Source code in app/patient_records.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
read_file ¶
read_file(repo, path)
Read file content from patient repository.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo
|
str
|
Repository name (from patient_repo_name). |
required |
path
|
str
|
Relative file path within repository. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: File content or None if file doesn't exist. |
Source code in app/patient_records.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |