package Ġorg . simple . clin ic . search . results Ċ Ċ import Ġio . reactivex . Observable Ċ import Ġio . reactivex . Observable Source Ċ import Ġio . reactivex . Observable Transformer Ċ import Ġio . reactivex . rx kotlin . of Type Ċ import Ġorg . simple . clin ic . Replay Until Screen Is Destroyed Ċ import Ġorg . simple . clin ic . Report Analytics Events Ċ import Ġorg . simple . clin ic . patient . O ngo ing New Patient Entry Ċ import Ġorg . simple . clin ic . patient . Patient Repository Ċ import Ġorg . simple . clin ic . patient . Patient Search Criteria Ċ import Ġorg . simple . clin ic . patient . Patient Search Criteria . Name Ċ import Ġorg . simple . clin ic . patient . Patient Search Criteria . PhoneNumber Ċ import Ġorg . simple . clin ic . widgets . Ui Event Ċ import Ġjavax . inject . Inject Ċ Ċ type alias ĠUi Ġ= ĠPatient SearchResults Screen Ċ type alias ĠUi Change Ġ= Ġ( Ui ) Ġ-> ĠUnit Ċ Ċ class ĠPatient SearchResults Controller Ġ@ Inject Ġconstructor ( ĊĠĠĠ Ġprivate Ġval Ġpatient Repository : ĠPatient Repository Ċ ) Ġ: ĠObservable Transformer < Ui Event , ĠUi Change > Ġ{ ĊĊĠ Ġoverride Ġfun Ġapply ( events : ĠObservable < Ui Event >): ĠObservable Source < Ui Change > Ġ{ ĊĠĠĠ Ġval Ġreplay ed Events Ġ= ĠRe play Until Screen Is Destroyed ( events ) ĊĠĠĠĠĠĠĠ Ġ. compose ( Report Analytics Events ()) ĊĠĠĠĠĠĠĠ Ġ. replay () ĊĊĠĠĠ Ġreturn ĠObservable . merge Array ( ĊĠĠĠĠĠĠĠ Ġopen Patient Summary ( replay ed Events ), ĊĠĠĠĠĠĠĠ Ġregister New Patient ( replay ed Events ) ĊĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġopen Patient Summary ( events : ĠObservable < Ui Event >): ĠObservable Source < Ui Change > Ġ= ĊĠĠĠĠĠ Ġevents . of Type < Patient SearchResult Clicked >() ĊĠĠĠĠĠĠĠĠĠ Ġ. map Ġ{ Ġit . patient Uuid Ġ} ĊĠĠĠĠĠĠĠĠĠ Ġ. map Ġ{ Ġpatient Uuid Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ{ Ġui : ĠUi Ġ-> Ġui . open Patient Summary Screen ( patient Uuid ) Ġ} ĊĠĠĠĠĠĠĠĠĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġregister New Patient ( events : ĠObservable < Ui Event >): ĠObservable < Ui Change > Ġ{ ĊĠĠĠ Ġreturn Ġevents ĊĠĠĠĠĠĠĠ Ġ. of Type < Patient SearchResult Register New Patient >() ĊĠĠĠĠĠĠĠ Ġ. map Ġ{ Ġit . search Criteria Ġ} ĊĠĠĠĠĠĠĠ Ġ. map ( this :: create O ngo ing Entry From Search Criteria ) ĊĠĠĠĠĠĠĠ Ġ. flatMap ( this :: save Entry And Go To Register Patient Screen ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġcreate O ngo ing Entry From Search Criteria ( search Criteria : ĠPatient Search Criteria ): ĠO ngo ing New Patient Entry Ġ{ ĊĠĠĠ Ġreturn Ġwhen Ġ( search Criteria ) Ġ{ ĊĠĠĠĠĠ Ġis ĠName Ġ-> ĠO ngo ing New Patient Entry . from FullName ( search Criteria . patient Name ) ĊĠĠĠĠĠ Ġis ĠPhone Number Ġ-> ĠO ngo ing New Patient Entry . from PhoneNumber ( search Criteria . phoneNumber ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġsave Entry And Go To Register Patient Screen ( ongo ing New Patient Entry : ĠO ngo ing New Patient Entry ): ĠObservable < Ui Change > Ġ{ ĊĠĠĠ Ġreturn Ġpatient Repository ĊĠĠĠĠĠĠĠ Ġ. save O ngo ing Entry ( ongo ing New Patient Entry ) ĊĠĠĠĠĠĠĠ Ġ. and Then ( Observable . just ({ Ġui : ĠUi Ġ-> Ġui . open Patient Entry Screen () Ġ})) ĊĠ Ġ} Ċ } Ċ