Skip to content

Commit 3e93a78

Browse files
committed
refactored lambda and added tests
1 parent d667632 commit 3e93a78

4 files changed

Lines changed: 688 additions & 129 deletions

File tree

lambdas/delta_backend/README.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,85 @@ Note: Paths are relative to this directory, `delta_backend`.
4040
4141
4. Run `make test` to run unit tests or `make coverage-run`. To see the unit test coverage, run `make coverage-run` first and then `make coverage-report`.
4242
43+
## Delta Stream Input Contract
44+
45+
This lambda consumes DynamoDB Stream records from `imms-<env>-imms-events` (`NEW_IMAGE`).
46+
47+
## Delta table indexing contract
48+
49+
For ordering-safe reads and backward compatibility, the delta table uses:
50+
51+
- Legacy GSI: `SearchIndex`
52+
- PK: `Operation`
53+
- SK: `DateTimeStamp`
54+
- New GSI: `OperationSequenceIndex`
55+
- PK: `Operation`
56+
- SK: `DateTimeStampWithSequence`
57+
58+
`DateTimeStamp` is retained for DPS backward compatibility.
59+
`DateTimeStampWithSequence` is for deterministic ordering of same-second events.
60+
61+
### Expected shape
62+
63+
```json
64+
{
65+
"eventID": "stream-id",
66+
"eventName": "INSERT | MODIFY | REMOVE",
67+
"dynamodb": {
68+
"ApproximateCreationDateTime": 1690896000,
69+
"SequenceNumber": "4959...",
70+
"NewImage": {
71+
"PK": { "S": "covid#<imms-id>" },
72+
"SK": { "S": "covid#<patient-id>" },
73+
"Operation": { "S": "CREATE | UPDATE | DELETE | DELETE_LOGICAL" },
74+
"SupplierSystem": { "S": "EMIS | RAVS | ..." },
75+
"Resource": { "S": "{\"resourceType\":\"Immunization\", ... }" }
76+
},
77+
"Keys": {
78+
"PK": { "S": "covid#<imms-id>" }
79+
}
80+
}
81+
}
82+
```
83+
84+
### Compatibility rules
85+
86+
The processor accepts the following legacy/fallback inputs:
87+
88+
1. **Patient key fallback**
89+
- Preferred: `NewImage.SK`
90+
- Fallback: `NewImage.PatientSK`
91+
92+
2. **Operation fallback**
93+
- Preferred: `NewImage.Operation`
94+
- Fallback: mapped from `eventName`:
95+
- `INSERT -> CREATE`
96+
- `MODIFY -> UPDATE`
97+
- `REMOVE -> DELETE`
98+
99+
3. **Payload fallback**
100+
- Preferred: `NewImage.Resource` (FHIR JSON string, converted via `Converter`)
101+
- Fallback: `NewImage.Imms` (already-flat or JSON string), with `ACTION_FLAG` added when missing
102+
103+
4. **Sequence fallback**
104+
- Preferred: `dynamodb.SequenceNumber`
105+
- Fallback: `NewImage.SequenceNumber`
106+
- Final fallback: `"0"`
107+
108+
5. **Skip rules**
109+
- If `SupplierSystem` is `DPSFULL` or `DPSREDUCED`, record is skipped (logged, no DDB write)
110+
111+
### Output/behavior contract
112+
113+
- `process_record(...)` returns:
114+
- `tuple[bool, dict]``(success, operation_outcome)`
115+
- `operation_outcome` always includes:
116+
- `record`
117+
- `operation_type`
118+
- `statusCode`
119+
- `statusDesc`
120+
- Failed records are sent to DLQ.
121+
43122
## 🛠️ Key Features
44123

45124
- Schema-driven field extraction and formatting

0 commit comments

Comments
 (0)