Pending Approval Mapping CF
CREATE TABLE IF NOT EXISTS pending_approval_mapping (
catchment_id varchar,
last_updated timeuuid,
health_id varchar,
PRIMARY KEY (catchment_id, last_updated)
)WITH CLUSTERING ORDER BY (last_updated ASC);CREATE INDEX idx_pending_approval_mapping_health_id on pending_approval_mapping(health_id);
Search All Pending Approvals by Catchment
- health_ids and last_updated timeuuids are selected from pending_approval_mapping CF for a given catchment and gte timeuuid. The results are ordered by last_updates asc.
- For each health_id, patient CF is queried for given_name and surname.
- Sample JSON response:
{
"hid": "5958385569250672641",
"given_name": "Sony",
"sur_name": "Bazzardo",
"last_updated": "b385af50-a225-11e4-97c2-5fcb9978cb86"
}
Search by HID
- Pending approvals for a particular patient is stored in the patient CF. When pending approval for a particular patient (by HID) is queried, the result is served from patient CF.
- The field is 'pending_approvals.' The pending approvals are stored as a JSON string. Class PendingApproval is used to serialize/deserialize the JSON. Updates are grouped by fields.
- The pending approvals are ordered by field name (lexicographically), then timeuuid in desc order. For each update the timeuuid is captured. See 'field_details' in the JSON below.
- TODO: Spike user defined types in Cassandra
- Sample JSON response:
{
"field_name": "gender",
"current_value": "M",
"field_details": {
"9b450750-b28e-11e4-a7a6-5fcb9978cb86": {
"value": "O",
"facility_id": "10000059",
"created_at": "2015-02-12T08:10:28.805Z"
},
"98bc87b0-b28e-11e4-a7a6-5fcb9978cb86": {
"value": "F",
"facility_id": "10000059",
"created_at": "2015-02-12T08:10:24.555Z"
}}
Update Fields Marked for Approval
- When a particular patient field that is marked for approval is updated, patient CF and pending_approval_mapping CF are updated.
- patient CF - new field details added to the pending_approvals JSON.
- pending_approval_mapping CF -
- Search by health_id (secondary index) and delete the records.
- Create new records for each possible catchment (see explanation below). last_updated is set as the latest timeuuid of the pending_approvals in patient CF.
- Possible catchments - If catchment is 10203040, the possible catchments are 1020, 102030, 10203040. Catchments should have always division and district.
- All queries are run in a batch.
Approve Request
- The field(s) is updated in patient CF.
- When a field that is pending for approval is approved, all the updates for that field are removed from the pending_approvals in patient CF.
- If there is no other pending_approvals in the patient CF, all pending_approval_mapping CF records for that health_id is deleted.
- Else, pending_approval_mapping CF is updated as mentioned above.
- All queries are run in a batch.
Reject Request
- The field(s) is NOT updated in patient CF.
- When a field that is pending for approval is rejected, only that particular updates for that field is removed from the pending_approvals in patient CF.
- If there is no other pending_approvals in the patient CF, all pending_approval_mapping CF records for that health_id is deleted.
- Else, pending_approval_mapping CF is updated as mentioned above.
- All queries are run in a batch.
Add Comment