package Ġorg . simple . clin ic . blood s ugar . entry Ċ Ċ import Ġcom . f 2 pr ate ek . rx . preferences 2 . Preference Ċ import Ġcom . spotify . mob ius . rx 2 . Rx Mob ius Ċ import Ġdagger . Lazy Ċ import Ġdagger . ass isted . Ass isted Ċ import Ġdagger . ass isted . Ass isted Factory Ċ import Ġdagger . ass isted . Ass isted Inject Ċ import Ġio . reactivex . Observable Transformer Ċ import Ġio . reactivex . Scheduler Ċ import Ġio . reactivex . Single Ċ import Ġio . reactivex . rx kotlin . cast Ċ import Ġorg . simple . clin ic . Report Analytics Events Ċ import Ġorg . simple . clin ic . blood s ugar . Blood S ugar Measurement Ċ import Ġorg . simple . clin ic . blood s ugar . Blood S ugar Repository Ċ import Ġorg . simple . clin ic . blood s ugar . Blood S ugar Unit Preference Ċ import Ġorg . simple . clin ic . blood s ugar . entry . Pref ill Date . Pref ill Specific Date Ċ import Ġorg . simple . clin ic . blood s ugar . entry . Validation Result . Error Blood S ugar Empty Ċ import Ġorg . simple . clin ic . blood s ugar . entry . Validation Result . Error Blood S ugar Too High Ċ import Ġorg . simple . clin ic . blood s ugar . entry . Validation Result . Error Blood S ugar Too Low Ċ import Ġorg . simple . clin ic . facility . Facility Ċ import Ġorg . simple . clin ic . over due . Appointment Repository Ċ import Ġorg . simple . clin ic . patient . Patient Repository Ċ import Ġorg . simple . clin ic . user . User Ċ import Ġorg . simple . clin ic . util . User Clock Ċ import Ġorg . simple . clin ic . util . exhaustive Ċ import Ġorg . simple . clin ic . util . scheduler . Schedulers Provider Ċ import Ġorg . simple . clin ic . util . to LocalDate At Zone Ċ import Ġorg . simple . clin ic . util . to Utc Instant Ċ import Ġorg . simple . clin ic . uuid . Uuid Generator Ċ import Ġorg . simple . clin ic . widgets . age and date of birth . User Input Date Validator Ċ import Ġorg . simple . clin ic . widgets . age and date of birth . User Input Date Validator . Result . Invalid . Date IsIn Future Ċ import Ġorg . simple . clin ic . widgets . age and date of birth . User Input Date Validator . Result . Invalid . Invalid Pattern Ċ import Ġorg . simple . clin ic . widgets . age and date of birth . User Input Date Validator . Result . Valid Ċ import Ġjava . time . Instant Ċ import Ġjava . time . LocalDate Ċ import Ġjava . util . UUID Ċ Ċ class ĠB lood S ugar Entry Effect Handler Ġ@ Ass isted Inject Ġconstructor ( ĊĠĠĠ Ġ@ Ass isted Ġprivate Ġval Ġui : ĠB lood S ugar Entry Ui , ĊĠĠĠ Ġprivate Ġval Ġblood S ugar Repository : ĠB lood S ugar Repository , ĊĠĠĠ Ġprivate Ġval Ġpatient Repository : ĠPatient Repository , ĊĠĠĠ Ġprivate Ġval Ġapp ointments Repository : ĠAppointment Repository , ĊĠĠĠ Ġprivate Ġval Ġuser Clock : ĠUser Clock , ĊĠĠĠ Ġprivate Ġval Ġs chedulers Provider : ĠS chedulers Provider , ĊĠĠĠ Ġprivate Ġval ĠcurrentUser : ĠLazy < User >, ĊĠĠĠ Ġprivate Ġval Ġcurrent Facility : ĠLazy < Facility >, ĊĠĠĠ Ġprivate Ġval Ġuuid Generator : ĠU uid Generator , ĊĠĠĠ Ġprivate Ġval Ġblood S ugar Unit Preference : ĠPreference < Blood S ugar Unit Preference > Ċ ) Ġ{ ĊĠ Ġ@ Ass isted Factory ĊĠ Ġinterface ĠFactory Ġ{ ĊĠĠĠ Ġfun Ġcreate ( ui : ĠB lood S ugar Entry Ui ): ĠB lood S ugar Entry Effect Handler ĊĠ Ġ} ĊĊĠ Ġprivate Ġval Ġreport Analytics Events Ġ= ĠReport Analytics Events () ĊĊĠ Ġfun Ġbuild (): ĠObservable Transformer < Blood S ugar Entry Effect , ĠB lood S ugar Entry Event > Ġ{ ĊĠĠĠ Ġreturn ĠRx Mob ius ĊĠĠĠĠĠĠĠ Ġ. subtype Effect Handler < Blood S ugar Entry Effect , ĠB lood S ugar Entry Event >() ĊĠĠĠĠĠĠĠ Ġ. addAction ( Hide Blood S ugar ErrorMessage :: class . java , Ġui :: hide Blood S ugar ErrorMessage , Ġs chedulers Provider . ui ()) ĊĠĠĠĠĠĠĠ Ġ. addAction ( Hide Date ErrorMessage :: class . java , Ġui :: hide Date ErrorMessage , Ġs chedulers Provider . ui ()) ĊĠĠĠĠĠĠĠ Ġ. addAction ( Dismiss :: class . java , Ġui :: dismiss , Ġs chedulers Provider . ui ()) ĊĠĠĠĠĠĠĠ Ġ. addAction ( Show Date Entry Screen :: class . java , Ġui :: show Date Entry Screen , Ġs chedulers Provider . ui ()) ĊĠĠĠĠĠĠĠ Ġ. add Consumer ( Show Blood S ugar ValidationError :: class . java , Ġ{ Ġshow Blood S ugar ValidationError ( it . result , Ġit . unit Preference ) Ġ}, Ġs chedulers Provider . ui ()) ĊĠĠĠĠĠĠĠ Ġ. add Consumer ( Show Blood S ugar Entry Screen :: class . java , Ġ{ Ġshow Blood S ugar Entry Screen ( it . date ) Ġ}, Ġs chedulers Provider . ui ()) ĊĠĠĠĠĠĠĠ Ġ. add Transformer ( Pref ill Date :: class . java , Ġpref ill Date ( schedul ers Provider . ui ())) ĊĠĠĠĠĠĠĠ Ġ. add Consumer ( Show Date ValidationError :: class . java , Ġ{ Ġshow Date ValidationError ( it . result ) Ġ}, Ġs chedulers Provider . ui ()) ĊĠĠĠĠĠĠĠ Ġ. addAction ( Set Blood S ugar Saved Result And Finish :: class . java , Ġui :: set Blood S ugar Saved Result And Finish , Ġs chedulers Provider . ui ()) ĊĠĠĠĠĠĠĠ Ġ. add Transformer ( Create New Blood S ugar Entry :: class . java , Ġcreate New Blood S ugar Entry Transformer ()) ĊĠĠĠĠĠĠĠ Ġ. add Transformer ( Fetch Blood S ugar Measurement :: class . java , Ġfetch Blood S ugar Measurement ( schedul ers Provider . io ())) ĊĠĠĠĠĠĠĠ Ġ. add Consumer ( Set Blood S ugar Reading :: class . java , Ġ{ Ġui . set Blood S ugar Reading ( it . blood S ugar Reading ) Ġ}, Ġs chedulers Provider . ui ()) ĊĠĠĠĠĠĠĠ Ġ. add Transformer ( Update Blood S ugar Entry :: class . java , Ġupdate Blood S ugar Entry Transformer ( schedul ers Provider . io ())) ĊĠĠĠĠĠĠĠ Ġ. add Consumer ( Show Confirm Remove Blood S ugar Dialog :: class . java , Ġ{ Ġui . show Confirm Remove Blood S ugar Dialog ( it . blood S ugar Measurement Uuid ) Ġ}, Ġs chedulers Provider . ui ()) ĊĠĠĠĠĠĠĠ Ġ. add Transformer ( Load Blood S ugar Unit Preference :: class . java , Ġload Blood S ugar Unit Preference ()) ĊĠĠĠĠĠĠĠ Ġ. add Consumer ( Show Blood S ugar Unit Selection Dialog :: class . java , Ġ{ Ġui . show Blood S ugar Unit Selection Dialog ( it . blood S ugar Unit Preference ) Ġ}, Ġs chedulers Provider . ui ()) ĊĠĠĠĠĠĠĠ Ġ. build () ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġload Blood S ugar Unit Preference (): ĠObservable Transformer < Load Blood S ugar Unit Preference , ĠB lood S ugar Entry Event > Ġ{ ĊĠĠĠ Ġreturn ĠObservable Transformer Ġ{ Ġeffect Ġ-> ĊĠĠĠĠĠ Ġeffect ĊĠĠĠĠĠĠĠĠĠ Ġ. observe On ( schedul ers Provider . io ()) ĊĠĠĠĠĠĠĠĠĠ Ġ. switch Map Ġ{ Ġblood S ugar Unit Preference . as Observable () Ġ} ĊĠĠĠĠĠĠĠĠĠ Ġ. map (:: Blood S ugar Unit Preference Loaded ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġfetch Blood S ugar Measurement ( ĊĠĠĠĠĠ Ġscheduler : ĠScheduler ĊĠ Ġ): ĠObservable Transformer < Fetch Blood S ugar Measurement , ĠB lood S ugar Entry Event > Ġ{ ĊĠĠĠ Ġreturn ĠObservable Transformer Ġ{ Ġfetch Blood S ugar Measurement Effect Stream Ġ-> ĊĠĠĠĠĠ Ġfetch Blood S ugar Measurement Effect Stream ĊĠĠĠĠĠĠĠĠĠ Ġ. observe On ( scheduler ) ĊĠĠĠĠĠĠĠĠĠ Ġ. map Ġ{ Ġget Existing Blood S ugar Measurement ( it . blood S ugar Measurement Uuid ) Ġ} ĊĠĠĠĠĠĠĠĠĠ Ġ. map Ġ{ ĠB lood S ugar Measurement F etched ( it ) Ġ} ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġget Existing Blood S ugar Measurement ( blood S ugar Measurement Uuid : ĠUUID ): ĠB lood S ugar Measurement ? Ġ= ĊĠĠĠĠĠ Ġblood S ugar Repository . measurement ( blood S ugar Measurement Uuid ) ĊĊĠ Ġprivate Ġfun Ġshow Blood S ugar ValidationError ( ĊĠĠĠĠĠ Ġresult : ĠValidation Result , ĊĠĠĠĠĠ Ġunit Preference : ĠB lood S ugar Unit Preference ĊĠ Ġ) Ġ{ ĊĠĠĠ Ġwhen Ġ( result ) Ġ{ ĊĠĠĠĠĠ ĠError Blood S ugar Empty Ġ-> Ġui . show Blood S ugar Empty Error () ĊĠĠĠĠĠ Ġis ĠError Blood S ugar Too High Ġ-> Ġui . show Blood S ugar High Error ( result . measurement Type , Ġunit Preference ) ĊĠĠĠĠĠ Ġis ĠError Blood S ugar Too Low Ġ-> Ġui . show Blood S ugar Low Error ( result . measurement Type , Ġunit Preference ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġshow Blood S ugar Entry Screen ( date : ĠLocalDate ) Ġ{ ĊĠĠĠ Ġwith ( ui ) Ġ{ ĊĠĠĠĠĠ Ġshow Blood S ugar Entry Screen () ĊĠĠĠĠĠ Ġshow Blood S ugar Date ( date ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġpref ill Date ( scheduler : ĠScheduler ): ĠObservable Transformer < Pref ill Date , ĠB lood S ugar Entry Event > Ġ{ ĊĠĠĠ Ġreturn ĠObservable Transformer Ġ{ Ġpref ill Dates Ġ-> ĊĠĠĠĠĠ Ġpref ill Dates ĊĠĠĠĠĠĠĠĠĠ Ġ. map (:: convertTo LocalDate ) ĊĠĠĠĠĠĠĠĠĠ Ġ. observe On ( scheduler ) ĊĠĠĠĠĠĠĠĠĠ Ġ. do On Next ( ui :: setDate On Input Fields ) ĊĠĠĠĠĠĠĠĠĠ Ġ. do On Next ( ui :: show Blood S ugar Date ) ĊĠĠĠĠĠĠĠĠĠ Ġ. map Ġ{ ĠDate Pref illed ( it ) Ġ} ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun ĠconvertTo LocalDate ( pref ill Date : ĠPref ill Date ): ĠLocalDate Ġ{ ĊĠĠĠ Ġval Ġinstant Ġ= Ġif Ġ( pref ill Date Ġis ĠPref ill Specific Date ) Ġpref ill Date . date Ġelse ĠInstant . now ( user Clock ) ĊĠĠĠ Ġreturn Ġinstant . to LocalDate At Zone ( user Clock . zone ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġshow Date ValidationError ( result : ĠUser Input Date Validator . Result ) Ġ{ ĊĠĠĠ Ġwhen Ġ( result ) Ġ{ ĊĠĠĠĠĠ ĠInvalid Pattern Ġ-> Ġui . show Invalid Date Error () ĊĠĠĠĠĠ ĠDate IsIn Future Ġ-> Ġui . show Date IsIn Future Error () ĊĠĠĠĠĠ Ġis ĠValid Ġ-> Ġthrow ĠIllegalStateException (" Date Ġvalidation Ġerror Ġcannot Ġbe Ġ$ result ") ĊĠĠĠ Ġ}. exhaustive () ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġcreate New Blood S ugar Entry Transformer (): ĠObservable Transformer < Create New Blood S ugar Entry , ĠB lood S ugar Entry Event > Ġ{ ĊĠĠĠ Ġreturn ĠObservable Transformer Ġ{ Ġcreate New Blood S ugar Entries Ġ-> ĊĠĠĠĠĠ Ġcreate New Blood S ugar Entries ĊĠĠĠĠĠĠĠĠĠ Ġ. observe On ( schedul ers Provider . io ()) ĊĠĠĠĠĠĠĠĠĠ Ġ. flatMap Single Ġ{ Ġcreate New Blood S ugar Entry Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġuser Ġ= ĠcurrentUser . get () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġfacility Ġ= Ġcurrent Facility . get () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġstore New Blood S ugar Measurement ( user , Ġfacility , Ġcreate New Blood S ugar Entry ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. flatMap Ġ{ Ġupdate App ointments As Vis ited ( createNew Blood S ugar Entry , Ġit ) Ġ} ĊĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠ Ġ. compose ( report Analytics Events ) ĊĠĠĠĠĠĠĠĠĠ Ġ. cast () ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġstore New Blood S ugar Measurement ( ĊĠĠĠĠĠ Ġuser : ĠUser , ĊĠĠĠĠĠ Ġcurrent Facility : ĠFac ility , ĊĠĠĠĠĠ Ġentry : ĠCreate New Blood S ugar Entry ĊĠ Ġ): ĠSingle < Blood S ugar Measurement > Ġ{ ĊĠĠĠ Ġval Ġ( patient Uuid , Ġdate , Ġ_, Ġreading ) Ġ= Ġentry ĊĠĠĠ Ġreturn Ġblood S ugar Repository . save Measurement ( ĊĠĠĠĠĠĠĠ Ġuuid Ġ= Ġuuid Generator . v 4 (), ĊĠĠĠĠĠĠĠ Ġreading Ġ= Ġreading , ĊĠĠĠĠĠĠĠ Ġpatient Uuid Ġ= Ġpatient Uuid , ĊĠĠĠĠĠĠĠ Ġlogged In User Ġ= Ġuser , ĊĠĠĠĠĠĠĠ Ġfacility Ġ= Ġcurrent Facility , ĊĠĠĠĠĠĠĠ Ġrecorded At Ġ= Ġdate . to Utc Instant ( user Clock ) ĊĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġupdate App ointments As Vis ited ( ĊĠĠĠĠĠ Ġcreate New Blood S ugar Entry : ĠCreate New Blood S ugar Entry , ĊĠĠĠĠĠ Ġblood S ugar Measurement : ĠB lood S ugar Measurement ĊĠ Ġ): ĠSingle < Blood S ugar Saved > Ġ{ ĊĠĠĠ Ġval Ġentry Date Ġ= Ġcreate New Blood S ugar Entry . user Entered Date . to Utc Instant ( user Clock ) ĊĊĠĠĠ Ġapp ointments Repository . mark App ointments Created Before Today As Vis ited ( blood S ugar Measurement . patient Uuid ) ĊĠĠĠ Ġpatient Repository . compare AndUpdate Re corded At ( blood S ugar Measurement . patient Uuid , Ġentry Date ) ĊĊĠĠĠ Ġreturn ĠSingle . just ( Blood S ugar Saved ( createNew Blood S ugar Entry . was Date Changed )) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġupdate Blood S ugar Entry Transformer ( scheduler : ĠScheduler ): ĠObservable Transformer < Update Blood S ugar Entry , ĠB lood S ugar Entry Event > Ġ{ ĊĠĠĠ Ġreturn ĠObservable Transformer Ġ{ Ġupdate Blood S ugar Entries Ġ-> ĊĠĠĠĠĠ Ġupdate Blood S ugar Entries ĊĠĠĠĠĠĠĠĠĠ Ġ. observe On ( scheduler ) ĊĠĠĠĠĠĠĠĠĠ Ġ. map Ġ{ Ġupdate Blood S ugar Entry Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġupdated Blood S ugar Measurement Ġ= Ġupdate Blood S ugar Measurement ( update Blood S ugar Entry ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġstore Update Blood S ugar Measurement ( updated Blood S ugar Measurement ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠB lood S ugar Saved ( update Blood S ugar Entry . was Date Changed ) ĊĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠ Ġ. compose ( report Analytics Events ) ĊĠĠĠĠĠĠĠĠĠ Ġ. cast < Blood S ugar Entry Event >() ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġupdate Blood S ugar Measurement ( update Blood S ugar Entry : ĠUpdate Blood S ugar Entry ): ĠB lood S ugar Measurement Ġ{ ĊĠĠĠ Ġval Ġ(_, Ġuser Entered Date , Ġ_, Ġblood S ugar Reading ) Ġ= Ġupdate Blood S ugar Entry ĊĠĠĠ Ġval Ġblood S ugar Measurement Ġ= Ġget Existing Blood S ugar Measurement ( update Blood S ugar Entry . blood S ugar Measurement Uuid ) !! ĊĠĠĠ Ġval Ġuser Ġ= ĠcurrentUser . get () ĊĠĠĠ Ġval Ġfacility Ġ= Ġcurrent Facility . get () ĊĊĠĠĠ Ġreturn Ġblood S ugar Measurement . copy ( ĊĠĠĠĠĠĠĠ Ġuser Uuid Ġ= Ġuser . uuid , ĊĠĠĠĠĠĠĠ Ġfacility Uuid Ġ= Ġfacility !!. uuid , ĊĠĠĠĠĠĠĠ Ġreading Ġ= Ġblood S ugar Measurement . reading . copy ( value Ġ= Ġblood S ugar Reading . value ), ĊĠĠĠĠĠĠĠ Ġrecorded At Ġ= Ġuser Entered Date . to Utc Instant ( user Clock ) ĊĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġstore Update Blood S ugar Measurement ( blood S ugar Measurement : ĠB lood S ugar Measurement ) Ġ{ ĊĠĠĠ Ġblood S ugar Repository . update Measurement ( blood S ugar Measurement ) ĊĠĠĠ Ġpatient Repository . compare AndUpdate Re corded At ( blood S ugar Measurement . patient Uuid , Ġblood S ugar Measurement . re corded At ) ĊĠ Ġ} Ċ } Ċ