One of the methods that can be employed to keep PainChek in sync with a PCS is to use update stamp based synchronisation. That is, the synchronisation process records a value that indicates which records have been processed to date and then, on subsequent runs, it processes the records updated since that time.
The update stamp might be a date-time, or it may be a number, but in either case, the process is much the same.
The RCS is expected to update the update stamp for a resident whenever a material change occurs to the resident, including:
-
A resident is added
-
A resident is updated (this only applies to the basic details that PainChek cares about - first name, last name, gender, date-of-birth and nickname)
-
A residents avatar (photo) is updated or removed
-
The residents' admission details change - i.e. they are moved to another room or site
-
The resident is permanently discharged
This type of synchronisation process would run periodically (say every 1 to 5 minutes) and hence push the updates to PainChek in near-real-time.
Note
There is an alternative to Update Stamp based synchronisation which is discussed here: Best Practice Guide - Event-Based Resident Synchronisation
The following block shows the pseudo-code for performing update stamp based synchronisations:
def process_rcs_residents_using_timestamp(): # Get the last recorded update stamp value last_update_stamp = read_update_stamp() # Iterate through each resident updated since last_update_stamp for rcs_resident in (select residents from the RCS where update_stamp > last_update_stamp): if rcs_resident.current_site not in whitelisted_sites: # skip this resident continue # Process any changes to the resident process_resident(rcs_resident) # Update the last recorded update stamp value if rcs_resident.update_stamp >= last_update_stamp: last_update_stamp = rcs_resident.update_stamp # Save the updated update_stamp assuming there was no errors if no errors: save_update_stamp(last_update_stamp)
Note
-
"read_update_stamp" is a function that fetches the last recorded update stamp from some form of permanent storage
-
"save_update_stamp" is a function that saves the last recorded update stamp to some form of permanent storage
-
The "process_resident" function returns an indication of success and also an indication if a retry-able error was detected (e.g. if the PainCHek API was down). For more details on the process_resident, see Best Practice Guide - The "process_resident" function