@doctorus/common 0.0.14 β 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +327 -97
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
# @doctorus/common
|
|
2
2
|
|
|
3
|
-
Common TypeScript utilities for Doctorus - A shared library
|
|
3
|
+
Common TypeScript utilities for Doctorus - A comprehensive shared library providing operations management, status handling, SSM parameters, audit logging, and internationalization across the platform.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@doctorus/common)
|
|
6
6
|
[](https://github.com/DoctorusRepoOwner/common/blob/main/LICENSE)
|
|
7
|
+
[](https://github.com/DoctorusRepoOwner/common)
|
|
7
8
|
|
|
8
9
|
## Installation
|
|
9
10
|
|
|
@@ -17,11 +18,238 @@ yarn add @doctorus/common
|
|
|
17
18
|
|
|
18
19
|
## Features
|
|
19
20
|
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
-
|
|
23
|
-
-
|
|
24
|
-
-
|
|
21
|
+
- π― **Operations Module** - Type-safe resource-action patterns with i18n support (English/French)
|
|
22
|
+
- π **Status Module** - Rich status management with icons, colors, and translations
|
|
23
|
+
- π **Audit Module** - Comprehensive audit logging and compliance tracking
|
|
24
|
+
- ποΈ **SSM Module** - AWS SSM Parameter Store utilities with hierarchical keys
|
|
25
|
+
- π **Internationalization** - Full bilingual support (us-EN, fr-FR) for all user-facing text
|
|
26
|
+
- π₯ **Medical Compliance** - Separate categorization for HIPAA-compliant resources
|
|
27
|
+
- β
**100% Test Coverage** - Production-ready with comprehensive testing
|
|
28
|
+
|
|
29
|
+
## Quick Start
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import {
|
|
33
|
+
// Operations
|
|
34
|
+
Operation,
|
|
35
|
+
Action,
|
|
36
|
+
Resource,
|
|
37
|
+
getOperationLabel,
|
|
38
|
+
|
|
39
|
+
// Status
|
|
40
|
+
MedicalServiceStatus,
|
|
41
|
+
getStatusLabel,
|
|
42
|
+
getStatusIcon,
|
|
43
|
+
|
|
44
|
+
// SSM
|
|
45
|
+
buildSSMKey,
|
|
46
|
+
SSM_CATEGORIES,
|
|
47
|
+
|
|
48
|
+
// Audit
|
|
49
|
+
AuditEvent,
|
|
50
|
+
} from '@doctorus/common';
|
|
51
|
+
|
|
52
|
+
// Create and label an operation
|
|
53
|
+
const op = new Operation(Action.CREATE, Resource.PRESCRIPTION);
|
|
54
|
+
console.log(getOperationLabel(op, 'us-EN')); // "Create Prescription"
|
|
55
|
+
console.log(getOperationLabel(op, 'fr-FR')); // "CrΓ©er Ordonnance"
|
|
56
|
+
|
|
57
|
+
// Get status information
|
|
58
|
+
const status = MedicalServiceStatus.IN_PROGRESS;
|
|
59
|
+
console.log(getStatusLabel(status, 'us-EN')); // "In Progress"
|
|
60
|
+
console.log(getStatusIcon(status)); // "medical_services"
|
|
61
|
+
|
|
62
|
+
// Build SSM key
|
|
63
|
+
const key = buildSSMKey({
|
|
64
|
+
environment: 'production',
|
|
65
|
+
application: 'doctorus',
|
|
66
|
+
category: SSM_CATEGORIES.DATABASE,
|
|
67
|
+
subcategory: 'postgres',
|
|
68
|
+
name: 'connection-string',
|
|
69
|
+
});
|
|
70
|
+
// "/production/doctorus/database/postgres/connection-string"
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Modules Overview
|
|
74
|
+
|
|
75
|
+
### π― [Operations Module](src/operations/README.md)
|
|
76
|
+
|
|
77
|
+
Resource-action based system for permissions, operations, and audit logging with full internationalization.
|
|
78
|
+
|
|
79
|
+
**Key Features:**
|
|
80
|
+
|
|
81
|
+
- 67 predefined actions (CRUD, medical-specific, system operations)
|
|
82
|
+
- 49 categorized resources (medical + public)
|
|
83
|
+
- Bilingual labels (English/French)
|
|
84
|
+
- Predefined operation combinations
|
|
85
|
+
- Resource categorization helpers
|
|
86
|
+
|
|
87
|
+
**Quick Example:**
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
import { Action, Resource, getActionLabel, isMedicalResource } from '@doctorus/common';
|
|
91
|
+
|
|
92
|
+
const action = Action.PRESCRIBE;
|
|
93
|
+
console.log(getActionLabel(action, 'us-EN')); // "Prescribe"
|
|
94
|
+
console.log(getActionLabel(action, 'fr-FR')); // "Prescrire"
|
|
95
|
+
|
|
96
|
+
console.log(isMedicalResource(Resource.PATIENT)); // true
|
|
97
|
+
console.log(isMedicalResource(Resource.ACCOUNT)); // false
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
[π Full Operations Documentation](src/operations/README.md)
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
### π [Status Module](src/status/README.md)
|
|
105
|
+
|
|
106
|
+
Comprehensive status management with rich metadata, visual elements, and validation.
|
|
107
|
+
|
|
108
|
+
**Key Features:**
|
|
109
|
+
|
|
110
|
+
- Type-safe status enums
|
|
111
|
+
- Material Design icons and color schemes
|
|
112
|
+
- Short and long labels in English/French
|
|
113
|
+
- Detailed descriptions
|
|
114
|
+
- Status transition validation
|
|
115
|
+
- Reusable pattern for multiple entity types
|
|
116
|
+
|
|
117
|
+
**Quick Example:**
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
import {
|
|
121
|
+
MedicalServiceStatus,
|
|
122
|
+
getStatusLabel,
|
|
123
|
+
getStatusColor,
|
|
124
|
+
getStatusIcon,
|
|
125
|
+
isValidTransition,
|
|
126
|
+
} from '@doctorus/common';
|
|
127
|
+
|
|
128
|
+
const status = MedicalServiceStatus.IN_PROGRESS;
|
|
129
|
+
console.log(getStatusLabel(status, 'us-EN', 'long')); // "Service In Progress"
|
|
130
|
+
console.log(getStatusColor(status)); // "#2196F3"
|
|
131
|
+
console.log(getStatusIcon(status)); // "medical_services"
|
|
132
|
+
|
|
133
|
+
// Validate transitions
|
|
134
|
+
isValidTransition(MedicalServiceStatus.PENDING, MedicalServiceStatus.IN_PROGRESS); // true
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
[π Full Status Documentation](src/status/README.md)
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
### π [Audit Module](src/audit/README.md)
|
|
142
|
+
|
|
143
|
+
Enterprise-grade audit logging for compliance, security, and debugging.
|
|
144
|
+
|
|
145
|
+
**Key Features:**
|
|
146
|
+
|
|
147
|
+
- Comprehensive event tracking
|
|
148
|
+
- User and system action logging
|
|
149
|
+
- Data change tracking (before/after states)
|
|
150
|
+
- Correlation and tracing support
|
|
151
|
+
- HIPAA/GDPR compliance ready
|
|
152
|
+
- Integration with Operations module
|
|
153
|
+
|
|
154
|
+
**Quick Example:**
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
import { AuditEvent, Action, Resource } from '@doctorus/common';
|
|
158
|
+
|
|
159
|
+
const event: AuditEvent = {
|
|
160
|
+
id: uuidv4(),
|
|
161
|
+
timestamp: new Date(),
|
|
162
|
+
userId: 'user-123',
|
|
163
|
+
action: Action.CREATE,
|
|
164
|
+
resource: Resource.PRESCRIPTION,
|
|
165
|
+
resourceId: 'prescription-789',
|
|
166
|
+
result: 'success',
|
|
167
|
+
metadata: { medication: 'Amoxicillin' },
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
await auditLogger.log(event);
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
[π Full Audit Documentation](src/audit/README.md)
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
### ποΈ [SSM Module](src/ssm/README.md)
|
|
178
|
+
|
|
179
|
+
Type-safe AWS Systems Manager Parameter Store key management.
|
|
180
|
+
|
|
181
|
+
**Key Features:**
|
|
182
|
+
|
|
183
|
+
- Hierarchical key structure
|
|
184
|
+
- Environment-aware configuration
|
|
185
|
+
- Key parsing and validation
|
|
186
|
+
- Predefined key categories
|
|
187
|
+
- Prefix building for batch operations
|
|
188
|
+
|
|
189
|
+
**Quick Example:**
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
import { buildSSMKey, parseSSMKey, SSM_CATEGORIES } from '@doctorus/common';
|
|
193
|
+
|
|
194
|
+
// Build a key
|
|
195
|
+
const key = buildSSMKey({
|
|
196
|
+
environment: 'production',
|
|
197
|
+
application: 'doctorus',
|
|
198
|
+
category: SSM_CATEGORIES.API,
|
|
199
|
+
subcategory: 'stripe',
|
|
200
|
+
name: 'secret-key',
|
|
201
|
+
});
|
|
202
|
+
// "/production/doctorus/api/stripe/secret-key"
|
|
203
|
+
|
|
204
|
+
// Parse a key
|
|
205
|
+
const parsed = parseSSMKey(key);
|
|
206
|
+
console.log(parsed.category); // "api"
|
|
207
|
+
console.log(parsed.subcategory); // "stripe"
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
[π Full SSM Documentation](src/ssm/README.md)
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
## Internationalization (i18n)
|
|
215
|
+
|
|
216
|
+
All user-facing text supports English (us-EN) and French (fr-FR):
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
import { getActionLabel, getResourceLabel, getStatusLabel } from '@doctorus/common';
|
|
220
|
+
|
|
221
|
+
// Action labels
|
|
222
|
+
getActionLabel(Action.CREATE, 'us-EN'); // "Create"
|
|
223
|
+
getActionLabel(Action.CREATE, 'fr-FR'); // "CrΓ©er"
|
|
224
|
+
|
|
225
|
+
// Resource labels
|
|
226
|
+
getResourceLabel(Resource.PATIENT, 'us-EN'); // "Patient"
|
|
227
|
+
getResourceLabel(Resource.PATIENT, 'fr-FR'); // "Patient"
|
|
228
|
+
|
|
229
|
+
// Status labels
|
|
230
|
+
getStatusLabel(MedicalServiceStatus.COMPLETED, 'us-EN'); // "Completed"
|
|
231
|
+
getStatusLabel(MedicalServiceStatus.COMPLETED, 'fr-FR'); // "TerminΓ©"
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## Medical Service Status Actions
|
|
235
|
+
|
|
236
|
+
Special actions for medical service workflow management:
|
|
237
|
+
|
|
238
|
+
```typescript
|
|
239
|
+
import { Action } from '@doctorus/common';
|
|
240
|
+
|
|
241
|
+
// Status transition actions
|
|
242
|
+
Action.CHECK_IN; // Move patient to waiting room
|
|
243
|
+
Action.UNDO_CHECK_IN; // Revert check-in
|
|
244
|
+
Action.START_SERVICE; // Begin consultation
|
|
245
|
+
Action.UNSTART_SERVICE; // Undo service start
|
|
246
|
+
Action.COMPLETE_SERVICE; // Mark as completed
|
|
247
|
+
Action.REOPEN_COMPLETED_SERVICE; // Reopen completed service
|
|
248
|
+
Action.CANCEL_SERVICE; // Cancel the service
|
|
249
|
+
Action.UNDO_CANCEL_SERVICE; // Uncancel
|
|
250
|
+
Action.FORCE_RESET_STATUS; // Admin: reset all (dangerous)
|
|
251
|
+
Action.CORRECT_TIMESTAMPS; // Admin: modify timestamps
|
|
252
|
+
```
|
|
25
253
|
|
|
26
254
|
## Modules
|
|
27
255
|
|
|
@@ -43,7 +271,7 @@ const customOp = new Operation(Resource.PRESCRIPTION, Action.PRESCRIBE);
|
|
|
43
271
|
console.log(customOp.toString()); // "PRESCRIPTION:PRESCRIBE"
|
|
44
272
|
|
|
45
273
|
// Parse from string
|
|
46
|
-
const parsed = Operation.fromString(
|
|
274
|
+
const parsed = Operation.fromString('MEDICAL_SERVICE:SCHEDULE');
|
|
47
275
|
if (parsed) {
|
|
48
276
|
console.log(parsed.resource); // Resource.MEDICAL_SERVICE
|
|
49
277
|
console.log(parsed.action); // Action.SCHEDULE
|
|
@@ -64,6 +292,7 @@ const json = operation.toJSON();
|
|
|
64
292
|
Resources are categorized as **Medical** (require special access control) or **Public** (standard access control):
|
|
65
293
|
|
|
66
294
|
**Medical Resources:**
|
|
295
|
+
|
|
67
296
|
- Patient: `PATIENT`, `PATIENT_MEDICAL_NOTES`, `PATIENT_MEDICAL_PROPERTIES`, `PATIENT_PAYMENT`
|
|
68
297
|
- Medical Services: `MEDICAL_SERVICE`, `MEDICAL_SERVICE_NOTE`, `MEDICAL_SERVICE_SCHEDULE`, `MEDICAL_SERVICE_FEES`, `MEDICAL_SERVICE_STATUS`
|
|
69
298
|
- Clinical: `MEDICAL_RECORD`, `MEDICAL_HISTORY`, `PRESCRIPTION`, `DIAGNOSIS`, `OBSERVATION`, `MEDICATION`, `ALLERGY`, `IMMUNIZATION`, `PROCEDURE`
|
|
@@ -71,6 +300,7 @@ Resources are categorized as **Medical** (require special access control) or **P
|
|
|
71
300
|
- Diagnostics: `LAB_RESULT`, `IMAGING`
|
|
72
301
|
|
|
73
302
|
**Public Resources:**
|
|
303
|
+
|
|
74
304
|
- Account: `ACCOUNT`, `ACCOUNT_OWNERSHIP`, `ACCOUNT_PREFERENCES`
|
|
75
305
|
- User: `USER`, `CONTACT`
|
|
76
306
|
- Documents: `UPLOADED_DOCUMENT`, `DOCUMENT_LAYOUT`, `GENERATED_DOCUMENT`, `DOCUMENT_MODEL`, `SNIPPET`
|
|
@@ -80,39 +310,43 @@ Resources are categorized as **Medical** (require special access control) or **P
|
|
|
80
310
|
|
|
81
311
|
```typescript
|
|
82
312
|
// CRUD operations
|
|
83
|
-
Action.CREATE, Action.READ, Action.UPDATE, Action.DELETE, Action.PUT, Action.LIST
|
|
313
|
+
(Action.CREATE, Action.READ, Action.UPDATE, Action.DELETE, Action.PUT, Action.LIST);
|
|
84
314
|
|
|
85
315
|
// General actions
|
|
86
|
-
Action.MANAGE, Action.VIEW, Action.SEARCH
|
|
316
|
+
(Action.MANAGE, Action.VIEW, Action.SEARCH);
|
|
87
317
|
|
|
88
318
|
// Medical-specific actions
|
|
89
|
-
Action.PRESCRIBE,
|
|
90
|
-
Action.
|
|
319
|
+
(Action.PRESCRIBE,
|
|
320
|
+
Action.DIAGNOSE,
|
|
321
|
+
Action.SIGN,
|
|
322
|
+
Action.VERIFY,
|
|
323
|
+
Action.SCHEDULE,
|
|
324
|
+
Action.CANCEL,
|
|
325
|
+
Action.APPROVE,
|
|
326
|
+
Action.REJECT);
|
|
91
327
|
|
|
92
328
|
// Medical service actions
|
|
93
|
-
Action.SET_MEDICAL_SERVICE_STATUS, Action.SET_MEDICAL_SERVICE_FEES
|
|
329
|
+
(Action.SET_MEDICAL_SERVICE_STATUS, Action.SET_MEDICAL_SERVICE_FEES);
|
|
94
330
|
|
|
95
331
|
// Patient-specific actions
|
|
96
|
-
Action.UPDATE_STATUS, Action.VIEW_PATIENTS,
|
|
97
|
-
Action.PUT_PATIENT_PAYMENT, Action.DELETE_PATIENT_PAYMENT
|
|
332
|
+
(Action.UPDATE_STATUS, Action.VIEW_PATIENTS, Action.PUT_PATIENT_PAYMENT, Action.DELETE_PATIENT_PAYMENT);
|
|
98
333
|
|
|
99
334
|
// Data operations
|
|
100
|
-
Action.EXPORT, Action.IMPORT, Action.ARCHIVE, Action.RESTORE,
|
|
101
|
-
Action.SHARE, Action.DOWNLOAD, Action.UPLOAD
|
|
335
|
+
(Action.EXPORT, Action.IMPORT, Action.ARCHIVE, Action.RESTORE, Action.SHARE, Action.DOWNLOAD, Action.UPLOAD);
|
|
102
336
|
|
|
103
337
|
// System operations
|
|
104
|
-
Action.LOGIN, Action.LOGOUT, Action.CONFIGURE, Action.AUDIT
|
|
338
|
+
(Action.LOGIN, Action.LOGOUT, Action.CONFIGURE, Action.AUDIT);
|
|
105
339
|
```
|
|
106
340
|
|
|
107
341
|
#### Helper Functions
|
|
108
342
|
|
|
109
343
|
```typescript
|
|
110
|
-
import {
|
|
111
|
-
isMedicalResource,
|
|
344
|
+
import {
|
|
345
|
+
isMedicalResource,
|
|
112
346
|
isPublicResource,
|
|
113
347
|
getAllOperations,
|
|
114
348
|
getOperationsByResource,
|
|
115
|
-
getOperationsByAction
|
|
349
|
+
getOperationsByAction,
|
|
116
350
|
} from '@doctorus/common';
|
|
117
351
|
|
|
118
352
|
// Check resource type
|
|
@@ -142,29 +376,46 @@ Commonly used operations are predefined for convenience:
|
|
|
142
376
|
|
|
143
377
|
```typescript
|
|
144
378
|
// Account operations
|
|
145
|
-
Operations.ACCOUNT_CREATE,
|
|
146
|
-
Operations.
|
|
379
|
+
(Operations.ACCOUNT_CREATE,
|
|
380
|
+
Operations.ACCOUNT_READ,
|
|
381
|
+
Operations.ACCOUNT_UPDATE,
|
|
382
|
+
Operations.ACCOUNT_DELETE,
|
|
383
|
+
Operations.ACCOUNT_MANAGE);
|
|
147
384
|
|
|
148
385
|
// Patient operations
|
|
149
|
-
Operations.PATIENT_CREATE,
|
|
150
|
-
Operations.
|
|
151
|
-
Operations.
|
|
386
|
+
(Operations.PATIENT_CREATE,
|
|
387
|
+
Operations.PATIENT_READ,
|
|
388
|
+
Operations.PATIENT_UPDATE,
|
|
389
|
+
Operations.PATIENT_DELETE,
|
|
390
|
+
Operations.PATIENT_LIST,
|
|
391
|
+
Operations.PATIENT_VIEW,
|
|
392
|
+
Operations.PATIENT_UPDATE_STATUS);
|
|
152
393
|
|
|
153
394
|
// Medical service operations
|
|
154
|
-
Operations.MEDICAL_SERVICE_CREATE,
|
|
155
|
-
Operations.
|
|
156
|
-
Operations.
|
|
157
|
-
Operations.
|
|
158
|
-
Operations.
|
|
395
|
+
(Operations.MEDICAL_SERVICE_CREATE,
|
|
396
|
+
Operations.MEDICAL_SERVICE_READ,
|
|
397
|
+
Operations.MEDICAL_SERVICE_UPDATE,
|
|
398
|
+
Operations.MEDICAL_SERVICE_DELETE,
|
|
399
|
+
Operations.MEDICAL_SERVICE_MANAGE,
|
|
400
|
+
Operations.MEDICAL_SERVICE_SCHEDULE,
|
|
401
|
+
Operations.MEDICAL_SERVICE_CANCEL,
|
|
402
|
+
Operations.MEDICAL_SERVICE_SET_STATUS,
|
|
403
|
+
Operations.MEDICAL_SERVICE_SET_FEES);
|
|
159
404
|
|
|
160
405
|
// Prescription operations
|
|
161
|
-
Operations.PRESCRIPTION_CREATE,
|
|
162
|
-
Operations.
|
|
163
|
-
Operations.
|
|
406
|
+
(Operations.PRESCRIPTION_CREATE,
|
|
407
|
+
Operations.PRESCRIPTION_READ,
|
|
408
|
+
Operations.PRESCRIPTION_UPDATE,
|
|
409
|
+
Operations.PRESCRIPTION_SIGN,
|
|
410
|
+
Operations.PRESCRIPTION_PRESCRIBE);
|
|
164
411
|
|
|
165
412
|
// User operations
|
|
166
|
-
Operations.USER_CREATE,
|
|
167
|
-
Operations.
|
|
413
|
+
(Operations.USER_CREATE,
|
|
414
|
+
Operations.USER_READ,
|
|
415
|
+
Operations.USER_UPDATE,
|
|
416
|
+
Operations.USER_DELETE,
|
|
417
|
+
Operations.USER_LOGIN,
|
|
418
|
+
Operations.USER_LOGOUT);
|
|
168
419
|
|
|
169
420
|
// ... and many more
|
|
170
421
|
```
|
|
@@ -176,13 +427,13 @@ Utilities for managing AWS SSM Parameter Store keys with environment support.
|
|
|
176
427
|
#### Basic Usage
|
|
177
428
|
|
|
178
429
|
```typescript
|
|
179
|
-
import {
|
|
180
|
-
SSM_PARAM_KEY,
|
|
181
|
-
buildSSMPath,
|
|
430
|
+
import {
|
|
431
|
+
SSM_PARAM_KEY,
|
|
432
|
+
buildSSMPath,
|
|
182
433
|
buildSSMPathWithPrefix,
|
|
183
434
|
extractEnvFromPath,
|
|
184
435
|
extractKeyFromPath,
|
|
185
|
-
isEnvAgnostic
|
|
436
|
+
isEnvAgnostic,
|
|
186
437
|
} from '@doctorus/common';
|
|
187
438
|
|
|
188
439
|
// Build environment-specific path
|
|
@@ -194,10 +445,7 @@ const sharedPath = buildSSMPath(null, SSM_PARAM_KEY.DB_USER);
|
|
|
194
445
|
console.log(sharedPath); // "/db-user"
|
|
195
446
|
|
|
196
447
|
// Build path with custom prefix
|
|
197
|
-
const customPath = buildSSMPathWithPrefix(
|
|
198
|
-
'/myapp/prod',
|
|
199
|
-
SSM_PARAM_KEY.GRAPHQL_API_ID
|
|
200
|
-
);
|
|
448
|
+
const customPath = buildSSMPathWithPrefix('/myapp/prod', SSM_PARAM_KEY.GRAPHQL_API_ID);
|
|
201
449
|
console.log(customPath); // "/myapp/prod/graphql-api-id"
|
|
202
450
|
|
|
203
451
|
// Extract environment from path
|
|
@@ -216,28 +464,28 @@ console.log(isEnvAgnostic('/prod/user-pool-id')); // false
|
|
|
216
464
|
#### Available SSM Parameter Keys
|
|
217
465
|
|
|
218
466
|
```typescript
|
|
219
|
-
SSM_PARAM_KEY.COGNITO_USER_POOL_ID
|
|
220
|
-
SSM_PARAM_KEY.COGNITO_USER_POOL_WEB_CLIENT_ID
|
|
221
|
-
SSM_PARAM_KEY.COGNITO_OAUTH_DOMAIN
|
|
222
|
-
SSM_PARAM_KEY.RUM_GUEST_ROLE_ARN
|
|
223
|
-
SSM_PARAM_KEY.RUM_IDENTITY_POOL_ID
|
|
224
|
-
SSM_PARAM_KEY.RUM_APP_ID
|
|
225
|
-
SSM_PARAM_KEY.GRAPHQL_HTTP_URL
|
|
226
|
-
SSM_PARAM_KEY.GRAPHQL_WS_URL
|
|
227
|
-
SSM_PARAM_KEY.GRAPHQL_HOST
|
|
228
|
-
SSM_PARAM_KEY.GRAPHQL_API_ID
|
|
229
|
-
SSM_PARAM_KEY.MEDICAL_ASSETS_AWS_CLOUDFRONT_PRIVATE_KEY
|
|
230
|
-
SSM_PARAM_KEY.MEDICAL_ASSETS_AWS_CLOUDFRONT_KEY_ID
|
|
231
|
-
SSM_PARAM_KEY.MEDICAL_ASSETS_BUCKET_NAME
|
|
232
|
-
SSM_PARAM_KEY.PUBLIC_ASSETS_BUCKET_NAME
|
|
233
|
-
SSM_PARAM_KEY.DB_USER
|
|
234
|
-
SSM_PARAM_KEY.DB_PASSWORD
|
|
235
|
-
SSM_PARAM_KEY.MEDICAL_ASSETS_DISTRIBUTION_DOMAIN_NAME
|
|
236
|
-
SSM_PARAM_KEY.BASE_HOST
|
|
237
|
-
SSM_PARAM_KEY.EMAIL_FROM_ADDRESS
|
|
238
|
-
SSM_PARAM_KEY.EVENT_API_REAL_TIME_DNS
|
|
239
|
-
SSM_PARAM_KEY.EVENT_API_HTTP_DNS
|
|
240
|
-
SSM_PARAM_KEY.NOTIFIED_EVENT_ACTIONS
|
|
467
|
+
SSM_PARAM_KEY.COGNITO_USER_POOL_ID;
|
|
468
|
+
SSM_PARAM_KEY.COGNITO_USER_POOL_WEB_CLIENT_ID;
|
|
469
|
+
SSM_PARAM_KEY.COGNITO_OAUTH_DOMAIN;
|
|
470
|
+
SSM_PARAM_KEY.RUM_GUEST_ROLE_ARN;
|
|
471
|
+
SSM_PARAM_KEY.RUM_IDENTITY_POOL_ID;
|
|
472
|
+
SSM_PARAM_KEY.RUM_APP_ID;
|
|
473
|
+
SSM_PARAM_KEY.GRAPHQL_HTTP_URL;
|
|
474
|
+
SSM_PARAM_KEY.GRAPHQL_WS_URL;
|
|
475
|
+
SSM_PARAM_KEY.GRAPHQL_HOST;
|
|
476
|
+
SSM_PARAM_KEY.GRAPHQL_API_ID;
|
|
477
|
+
SSM_PARAM_KEY.MEDICAL_ASSETS_AWS_CLOUDFRONT_PRIVATE_KEY;
|
|
478
|
+
SSM_PARAM_KEY.MEDICAL_ASSETS_AWS_CLOUDFRONT_KEY_ID;
|
|
479
|
+
SSM_PARAM_KEY.MEDICAL_ASSETS_BUCKET_NAME;
|
|
480
|
+
SSM_PARAM_KEY.PUBLIC_ASSETS_BUCKET_NAME;
|
|
481
|
+
SSM_PARAM_KEY.DB_USER;
|
|
482
|
+
SSM_PARAM_KEY.DB_PASSWORD;
|
|
483
|
+
SSM_PARAM_KEY.MEDICAL_ASSETS_DISTRIBUTION_DOMAIN_NAME;
|
|
484
|
+
SSM_PARAM_KEY.BASE_HOST;
|
|
485
|
+
SSM_PARAM_KEY.EMAIL_FROM_ADDRESS;
|
|
486
|
+
SSM_PARAM_KEY.EVENT_API_REAL_TIME_DNS;
|
|
487
|
+
SSM_PARAM_KEY.EVENT_API_HTTP_DNS;
|
|
488
|
+
SSM_PARAM_KEY.NOTIFIED_EVENT_ACTIONS;
|
|
241
489
|
```
|
|
242
490
|
|
|
243
491
|
## Use Cases
|
|
@@ -250,21 +498,18 @@ import { Operation, isMedicalResource } from '@doctorus/common';
|
|
|
250
498
|
function checkPermission(userPermissions: string[], operation: Operation): boolean {
|
|
251
499
|
// Check if user has permission for this operation
|
|
252
500
|
const hasPermission = userPermissions.includes(operation.toString());
|
|
253
|
-
|
|
501
|
+
|
|
254
502
|
// Apply additional checks for medical resources
|
|
255
503
|
if (isMedicalResource(operation.resource)) {
|
|
256
504
|
// Enforce HIPAA compliance, additional logging, etc.
|
|
257
505
|
return hasPermission && user.hasHIPAAAccess;
|
|
258
506
|
}
|
|
259
|
-
|
|
507
|
+
|
|
260
508
|
return hasPermission;
|
|
261
509
|
}
|
|
262
510
|
|
|
263
511
|
// Usage
|
|
264
|
-
const canRead = checkPermission(
|
|
265
|
-
userPermissions,
|
|
266
|
-
Operations.PATIENT_READ
|
|
267
|
-
);
|
|
512
|
+
const canRead = checkPermission(userPermissions, Operations.PATIENT_READ);
|
|
268
513
|
```
|
|
269
514
|
|
|
270
515
|
### 2. Audit Logging
|
|
@@ -280,20 +525,15 @@ interface AuditLog {
|
|
|
280
525
|
success: boolean;
|
|
281
526
|
}
|
|
282
527
|
|
|
283
|
-
function logAudit(
|
|
284
|
-
userId: string,
|
|
285
|
-
operation: Operation,
|
|
286
|
-
resourceId: string,
|
|
287
|
-
success: boolean
|
|
288
|
-
) {
|
|
528
|
+
function logAudit(userId: string, operation: Operation, resourceId: string, success: boolean) {
|
|
289
529
|
const log: AuditLog = {
|
|
290
530
|
timestamp: new Date(),
|
|
291
531
|
userId,
|
|
292
532
|
operation: operation.toString(),
|
|
293
533
|
resourceId,
|
|
294
|
-
success
|
|
534
|
+
success,
|
|
295
535
|
};
|
|
296
|
-
|
|
536
|
+
|
|
297
537
|
// Store in audit log database
|
|
298
538
|
auditLogService.create(log);
|
|
299
539
|
}
|
|
@@ -311,15 +551,9 @@ import { StringParameter } from 'aws-cdk-lib/aws-ssm';
|
|
|
311
551
|
// In your CDK stack
|
|
312
552
|
const env = 'prod';
|
|
313
553
|
|
|
314
|
-
const userPoolId = StringParameter.valueFromLookup(
|
|
315
|
-
this,
|
|
316
|
-
buildSSMPath(env, SSM_PARAM_KEY.COGNITO_USER_POOL_ID)
|
|
317
|
-
);
|
|
554
|
+
const userPoolId = StringParameter.valueFromLookup(this, buildSSMPath(env, SSM_PARAM_KEY.COGNITO_USER_POOL_ID));
|
|
318
555
|
|
|
319
|
-
const graphqlUrl = StringParameter.valueFromLookup(
|
|
320
|
-
this,
|
|
321
|
-
buildSSMPath(env, SSM_PARAM_KEY.GRAPHQL_HTTP_URL)
|
|
322
|
-
);
|
|
556
|
+
const graphqlUrl = StringParameter.valueFromLookup(this, buildSSMPath(env, SSM_PARAM_KEY.GRAPHQL_HTTP_URL));
|
|
323
557
|
```
|
|
324
558
|
|
|
325
559
|
### 4. Frontend Configuration
|
|
@@ -330,21 +564,17 @@ import { SSM } from '@aws-sdk/client-ssm';
|
|
|
330
564
|
|
|
331
565
|
async function loadConfig(environment: string) {
|
|
332
566
|
const ssm = new SSM();
|
|
333
|
-
|
|
334
|
-
const params = [
|
|
335
|
-
|
|
336
|
-
SSM_PARAM_KEY.GRAPHQL_HTTP_URL,
|
|
337
|
-
SSM_PARAM_KEY.RUM_APP_ID
|
|
338
|
-
];
|
|
339
|
-
|
|
567
|
+
|
|
568
|
+
const params = [SSM_PARAM_KEY.COGNITO_USER_POOL_ID, SSM_PARAM_KEY.GRAPHQL_HTTP_URL, SSM_PARAM_KEY.RUM_APP_ID];
|
|
569
|
+
|
|
340
570
|
const config: Record<string, string> = {};
|
|
341
|
-
|
|
571
|
+
|
|
342
572
|
for (const param of params) {
|
|
343
573
|
const path = buildSSMPath(environment, param);
|
|
344
574
|
const response = await ssm.getParameter({ Name: path });
|
|
345
575
|
config[param] = response.Parameter?.Value || '';
|
|
346
576
|
}
|
|
347
|
-
|
|
577
|
+
|
|
348
578
|
return config;
|
|
349
579
|
}
|
|
350
580
|
```
|
|
@@ -388,4 +618,4 @@ Apache-2.0
|
|
|
388
618
|
|
|
389
619
|
---
|
|
390
620
|
|
|
391
|
-
Built with β€οΈ for Doctorus
|
|
621
|
+
Built with β€οΈ for Doctorus
|