This function is the one with the bulk of the "smarts" - it looks at the RCS resident record, looks at the corresponding PainChek record (if any) and makes the necessary calls to update PainChek to bring it in-line with the RCS.
The function will make the following changes to PainChek:
-
create, update or edit the Patient record
-
create a Site record
-
end the current Admission record for the patient
-
start a new Admission record for the patient
-
update or delete the Patients avatar (image/headshot)
Changes are only made if the script detects differences between the two systems
Note
The code blocks shown on this page are implemented in the sample code available here: Sample Integration Code.
The process_resident is supplied with a record from the RCS system. It is assumed that record has all of the details required for the synchronisation it int (patient details, site details, admission details, etc).
One of the key assumptions with the logic below is that the PainChek UUID is recorded against the PCS record.
def process_resident (rcs_resident): # Get the PainChek site, creating it if required site = format_as_painchek_site(rcs_resident) response = post_to_paincheck_api(url="/api/integration/sites", payload=site) # Check/Update/Create Patient resident = format_as_painchek_resident(rcs_resident) if rcs_avatar_updated(rcs_resident): resident = add_avatar_details(rcs_resident, resident) response = post_to_paincheck_api(url="/api/integration/patients", payload=resident) saved_resident = response['data'] rcs_resident['uuid'] = saved_resident['uuid'] # Check/Update/Create Admission admission = format_as_painchek_admission(rcs_resident) response = post_to_paincheck_api(url="/api/integration/admissions", payload=admission)
The following table summaries the key functions referenced in the code above:
Name |
Accepts |
Returns |
Comment |
---|---|---|---|
format_as_painchek_resident |
RCS Resident Object |
PainChek Resident Object |
Extracts the resident details from the rcs_resident record (first_name, last_name, date_of_birth, gender and external_id) and returns them in a format suitable for posting to the PainChek API |
format_as_painchek_admission |
RCS Resident Object |
PainChek Resident Object |
Extracts the admission details from the rcs_resident record (bed, room, ward) and returns them in a format suitable for posting to the PainChek API |
post_to_paincheck_api |
URL and Payload |
The object created by the POST |
POSTs to the PainChek API and returns the response from that POST |
rcs_avatar_updated |
RCS Resident Object |
An indication if the Avatar has been updated or not |
Determines if the avatar has changed for an RCS resident |
add_avatar_details |
RCS Resident Object, PainChek Resident Object |
PainChek Resident Object |
Updates the PainChek RCS with the URL or the base64 encoded version of residents avatar. |
Note
For more details on these functions, refer to the Sample Integration Code.