Creating the Sync Archive

Preparing Records for Synchronization

The sync process (SyncUtils.exportSite method) loops through a SyncEvent collection of SyncLogs and serializes the records to the file system and creates a zip archive.

Each time the sync process runs, a new SyncEvent object is created. A SyncEvent is a record of the sync operations - it stores information about the records that have been archived and other details about the sync operation. A SyncEvent object has the following fields:

  • uuid - unique identifier for this syncEvent
  • syncDate - Timestamp of this syncEvent
  • siteId - which site is being synced
  • siteInstanceId - Helps to differentiate instances of Zcore contributing to the same site. Configured in setup: site.jsp; 1:TCC,2:Case Manager laptop,3:Other 1,4:Other 2
  • url: Network Protocol for this zcore instance (http or https) + url of this publisher instance.
  • Lists of records (stored as SyncLog objects) that are being archived of the types listed in the Record Sync Process section of the Offline Mode page.

Each SyncEvent has collections of SyncLog objects. If the record is an object that has a parent, the parent uuid is also stored in the SyncLog parentUuid field. An example of this parent/child relationship is the relationship between an encounter and a patient. When an encounter record is archived, the uuid of the patient is stored in syncLog.parentUuid. Note: the parentUuid is stored only in the data sync file - not in the database. The parentUuid is used in constructing the directory hierarchy when data files are saved to the file system.

Fields in the SyncLog object:

  • uuid - uuid for this syncLog instance
  • objectUuid - uuid of the object being synced
  • siteId
  • siteInstanceId
  • exportTimestamp - Timestamp for this SyncLog (when the record was archived)
  • Some fields are used for certain objects:
    • encounter:
      • parentUuid - encounter.getClientUuid() - only if the record is not an Admin record, which are not associated with patients.
      • formId - encounter.getFormId()
    • edits:
      • parentUuid - encounter.getClientUuid()
    • relationships, organizations, contacts, users, courts, police stations,
      • formId
    • events:
      • parentUuid
    • deletions:
      • formId

Fetching a List of Unsynced Records

When a record is put into an archive for synchronization, the record uuid is stored in the synclog table in the object_uuid field. Each synclog record also has its own uuid.

Synclog table diagram

The following query in SyncUtils.getUnSyncedObjects method returns a list of unsynced records:

            sql="(SELECT o.uuid FROM " + objectName + " o " +
            "WHERE o.site_id=?) " +
            "EXCEPT (SELECT object_uuid AS uuid FROM synclog " +
            "WHERE synclog.site_id=?)";

Saving unarchived Records and Creating the Archive

The SyncUtils.exportSite method loops through the SyncEvent collection of SyncLogs. Each SyncEvent record type (encounters, admin records, etc) has its own location on the file system where it is saved. A log is created in the updatelog table as well as in the mostRecentUpdate file, which also provides a list of recent SyncEvent UUID's. The archive is saved to a directory based on the current year, month, and week number (1-5).