Get recent encounters (visits) from the iClinic Integration API. Use status=all so that cancelled encounters are included.
Match encounters to the appointment by phone number, with a visitDate within ±5 days of the appointment date. Skip encounters where phone = null.
At least one matching encounter is not CANCELLED → Arrived. All matching encounters are CANCELLED → Cancelled. No matching encounters → leave the appointment unchanged.
Follow-up call list after a visit (day 0 / 3 / 6 / 30)
Get encounters with status=FINISHED and from = today − 30 days (a range of exactly 31 days, enough for the day-30 call).
Calculate the call date as visitDate + 0, 3, 6 and 30 days. Keep the encounters whose call date is today.
Show patientName, phone and diagnosis. patientType = NEW means a new patient; OLD and RE_EXAMINATION mean returning patients.