package Ġorg . simple . clin ic . sync Ċ Ċ import Ġandroidx . annotation . Worker Thread Ċ import Ġcom . f 2 pr ate ek . rx . preferences 2 . Preference Ċ import Ġorg . simple . clin ic . App Database Ċ import Ġorg . simple . clin ic . facility . Facility Ċ import Ġorg . simple . clin ic . main . Typed Preference Ċ import Ġorg . simple . clin ic . main . Typed Preference . Type . Facility Sync Group Sw itched At Ċ import Ġorg . simple . clin ic . remote config . Config Reader Ċ import Ġjava . util . Optional Ċ import Ġorg . simple . clin ic . util . Utc Clock Ċ import Ġjava . time . Duration Ċ import Ġjava . time . Instant Ċ import Ġjavax . inject . Inject Ċ import Ġjavax . inject . Provider Ċ Ċ class ĠPur ge On Sync ( ĊĠĠĠ Ġprivate Ġval Ġcurrent Facility : ĠProvider < Facility >, ĊĠĠĠ Ġprivate Ġval Ġapp Database : ĠApp Database , ĊĠĠĠ Ġprivate Ġval Ġfacility Sync Group Sw itched At : ĠPreference < Optional < Instant >>, ĊĠĠĠ Ġprivate Ġval Ġdelay Purge After Switch For : ĠDuration , ĊĠĠĠ Ġprivate Ġval Ġclock : ĠU tc Clock Ċ ) Ġ{ ĊĊĠ Ġ@ Inject ĊĠ Ġconstructor ( ĊĠĠĠĠĠ Ġcurrent Facility : ĠProvider < Facility >, ĊĠĠĠĠĠ Ġapp Database : ĠApp Database , ĊĠĠĠĠĠ Ġ@ Typed Preference ( Facility Sync Group Sw itched At ) Ġfacility Sync Group Sw itched At : ĠPreference < Optional < Instant >>, ĊĠĠĠĠĠ Ġclock : ĠU tc Clock , ĊĠĠĠĠĠ Ġremote Config : ĠConfig Reader ĊĠ Ġ) Ġ: Ġthis ( ĊĠĠĠĠĠ Ġcurrent Facility Ġ= Ġcurrent Facility , ĊĠĠĠĠĠ Ġapp Database Ġ= Ġapp Database , ĊĠĠĠĠĠ Ġfacility Sync Group Sw itched At Ġ= Ġfacility Sync Group Sw itched At , ĊĠĠĠĠĠ Ġdelay Purge After Switch For Ġ= ĠDuration . parse ( remote Config . string (" delay _ purge _ after _ facility _ sync _ group _ switch _ duration ", Ġ" P 1 D ")), ĊĠĠĠĠĠ Ġclock Ġ= Ġclock ĊĠ Ġ) ĊĊĠ Ġ@ Worker Thread ĊĠ Ġfun Ġpurge Unused Data () Ġ{ ĊĠĠĠ Ġval Ġfacility Sync Sw itched At Instant Ġ= Ġfacility Sync Group Sw itched At . get () ĊĊĠĠĠ Ġval Ġshould Purge Data Ġ= Ġ! facility Sync Sw itched At Instant . isPresent () Ġ|| Ġis Safe To Purge Data ( facility Sync Sw itched At Instant . get ()) ĊĊĠĠĠ Ġif Ġ( should Purge Data ) Ġapp Database . delete Pat ients NotIn Facility Sync Group ( current Facility . get ()) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġis Safe To Purge Data ( ĊĠĠĠĠĠ Ġswitched At : ĠInstant ĊĠ Ġ): ĠBoolean Ġ{ ĊĠĠĠ Ġval Ġnow Ġ= ĠInstant . now ( clock ) ĊĊĠĠĠ Ġreturn ĠDuration . between ( sw itched At , Ġnow ) Ġ> Ġdelay Purge After Switch For ĊĠ Ġ} Ċ } Ċ