package Ġorg . simple . clin ic . search results view Ċ Ċ import Ġio . reactivex . Observable Ċ import Ġio . reactivex . Observable Source Ċ import Ġio . reactivex . Observable Transformer Ċ import Ġio . reactivex . rx kotlin . Observable s Ċ import Ġorg . simple . clin ic . bp . Blood Pressure Measurement Ċ import Ġorg . simple . clin ic . bp . Patient To Facility Id Ċ import Ġorg . simple . clin ic . facility . Facility Ċ import Ġorg . simple . clin ic . patient . Facility Uuid Ċ import Ġorg . simple . clin ic . patient . Patient SearchResult Ċ import Ġorg . simple . clin ic . patient . Patient Uuid Ċ Ċ class ĠPartition SearchResults By Vis ited Facility ( ĊĠĠĠ Ġprivate Ġval Ġblood Pressure Dao : ĠB lood Pressure Measurement . Room Dao , ĊĠĠĠ Ġprivate Ġval Ġfacility Stream : ĠObservable < Facility > Ċ ) Ġ: ĠObservable Transformer < List < Patient SearchResult >, ĠPatient SearchResults > Ġ{ ĊĊĠ Ġoverride Ġfun Ġapply ( upstream : ĠObservable < List < Patient SearchResult >> ): ĠObservable Source < Patient SearchResults > Ġ{ ĊĠĠĠ Ġval Ġsearch Results Ġ= Ġupstream . replay (). ref Count () ĊĊĠĠĠ Ġval Ġpatient To Facility Uuid Stream Ġ= Ġsearch Results ĊĠĠĠĠĠĠĠ Ġ. map Ġ{ Ġpatients Ġ-> Ġpatients . map Ġ{ Ġit . uuid Ġ} Ġ} ĊĠĠĠĠĠĠĠ Ġ. switch Map Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġblood Pressure Dao ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. patient To Facility Ids ( it ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. to Observable () ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠ Ġreturn ĠObservable s . combine Latest ( search Results , Ġpatient To Facility Uuid Stream , Ġfacility Stream ) ĊĠĠĠĠĠĠĠ Ġ. map Ġ{ Ġ( pat ients , Ġpatient To Fac ilities , Ġfacility ) Ġ-> ĊĠĠĠĠĠĠĠĠĠ Ġval Ġpatients To Vis ited Fac ilities Ġ= Ġmap Pat ients To Vis ited Fac ilities ( patient To Fac ilities ) ĊĊĠĠĠĠĠĠĠĠĠ Ġval Ġ( pat ients In Current Facility , Ġpatients In Other Facility ) Ġ= Ġpatients . partition Ġ{ Ġpatient SearchResult Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġhas Patient Vis ited Facility ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġpatients To Vis ited Fac ilities Ġ= Ġpatients To Vis ited Fac ilities , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġfacility Uuid Ġ= Ġfacility . uuid , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġpatient Uuid Ġ= Ġpatient SearchResult . uuid ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠĠĠ ĠPatient SearchResults ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġvisited Current Facility Ġ= Ġpatients In Current Facility , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġnot Vis ited Current Facility Ġ= Ġpatients In Other Facility , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcurrent Facility Ġ= Ġfacility ĊĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġhas Patient Vis ited Facility ( ĊĠĠĠĠĠ Ġpatients To Vis ited Fac ilities : ĠMap < Patient Uuid , ĠSet < Facility Uuid >>, ĊĠĠĠĠĠ Ġfacility Uuid : ĠFac ility Uuid , ĊĠĠĠĠĠ Ġpatient Uuid : ĠPatient Uuid ĊĠ Ġ): ĠBoolean Ġ{ ĊĠĠĠ Ġreturn Ġpatients To Vis ited Fac ilities [ patient Uuid ]?. contains ( facility Uuid ) Ġ?: Ġfalse ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġmap Pat ients To Vis ited Fac ilities ( patient To Fac ilities : ĠList < Patient To Facility Id >): ĠMap < Patient Uuid , ĠSet < Facility Uuid >> Ġ{ ĊĠĠĠ Ġreturn Ġpatient To Fac ilities ĊĠĠĠĠĠĠĠ Ġ. fold ( mutable Map Of < Patient Uuid , ĠMutable Set < Facility Uuid >> ()) Ġ{ Ġfacility Uuid s , Ġ( patient Uuid , Ġfacility Uuid ) Ġ-> ĊĠĠĠĠĠĠĠĠĠ Ġif Ġ( patient Uuid Ġ! in Ġfacility Uuid s ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfacility Uuid s [ patient Uuid ] Ġ= Ġmutable Set Of () ĊĠĠĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠĠĠ Ġfacility Uuid s [ patient Uuid ]?. add ( facility Uuid ) ĊĠĠĠĠĠĠĠĠĠ Ġfacility Uuid s ĊĠĠĠĠĠĠĠ Ġ} ĊĠ Ġ} Ċ } Ċ