package Ġorg . simple . clin ic . add id top at ient . search for patient Ċ Ċ import Ġandroid . content . Context Ċ import Ġandroid . util . Attribute Set Ċ import Ġandroid . view . View Ċ import Ġandroid . view . input method . Editor Info Ċ import Ġandroid . widget . Relative Layout Ċ import Ġandroidx . appcompat . app . AppCompatActivity Ċ import Ġcom . jak ew h art on . r xb ind ing 2 . view . Rx View Ċ import Ġcom . jak ew h art on . r xb ind ing 2 . widget . Rx TextView Ċ import Ġio . reactivex . Observable Ċ import Ġio . reactivex . rx kotlin . of Type Ċ import Ġkotlinx . android . synt hetic . main . screen _ add id top at ient search . view .* Ċ import Ġorg . simple . clin ic . R Ċ import Ġorg . simple . clin ic . main . The Activity Ċ import Ġorg . simple . clin ic . add id top at ient . search results . Add Id To Patient SearchResults Screen Key Ċ import Ġorg . simple . clin ic . all pat ients inf ac ility . All Pat ients In Facility List Sc rolled Ċ import Ġorg . simple . clin ic . all pat ients inf ac ility . All Pat ients In Facility SearchResult Clicked Ċ import Ġorg . simple . clin ic . all pat ients inf ac ility . All Pat ients In Facility View Ċ import Ġorg . simple . clin ic . bind Ui To Controller Ċ import Ġorg . simple . clin ic . patient . Patient Search Criteria Ċ import Ġorg . simple . clin ic . router . screen . Screen Router Ċ import Ġorg . simple . clin ic . summary . Open Int ention Ċ import Ġorg . simple . clin ic . summary . Patient Summary Screen Key Ċ import Ġorg . simple . clin ic . text . style . TextAppearance With Letter Spacing Span Ċ import Ġorg . simple . clin ic . util . Tr uss Ċ import Ġorg . simple . clin ic . util . Utc Clock Ċ import Ġorg . simple . clin ic . util . identifier display . Identifier Display Adapter Ċ import Ġorg . simple . clin ic . util . unsafe Lazy Ċ import Ġorg . simple . clin ic . widgets . Screen Destroyed Ċ import Ġorg . simple . clin ic . widgets . Ui Event Ċ import Ġorg . simple . clin ic . widgets . hide Keyboard Ċ import Ġorg . simple . clin ic . widgets . show Keyboard Ċ import Ġorg . th reet en . bp . Instant Ċ import Ġjava . util . UUID Ċ import Ġjavax . inject . Inject Ċ Ċ class ĠAdd Id To Patient Search Screen ( context : ĠContext , Ġattrs : ĠAttributeSet ) Ġ: ĠRelative Layout ( context , Ġattrs ) Ġ{ ĊĊĠ Ġ@ Inject ĊĠ Ġlateinit Ġvar Ġscreen Router : ĠScreen Router ĊĊĠ Ġ@ Inject ĊĠ Ġlateinit Ġvar Ġactivity : ĠAppCompatActivity ĊĊĠ Ġ@ Inject ĊĠ Ġlateinit Ġvar Ġcontroller : ĠAdd Id To Patient Search Screen Controller ĊĊĠ Ġ@ Inject ĊĠ Ġlateinit Ġvar Ġidentifier Display Adapter : ĠIdentifier Display Adapter ĊĊĠ Ġ@ Inject ĊĠ Ġlateinit Ġvar Ġut c Clock : ĠU tc Clock ĊĊĠ Ġprivate Ġval Ġscreen Key Ġby Ġunsafe Lazy Ġ{ ĊĠĠĠ Ġscreen Router . key < Add Id To Patient Search Screen Key >( this ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġval Ġall Pat ients In Facility Ġby Ġunsafe Lazy Ġ{ ĊĠĠĠ Ġall Pat ients In Facility View Ġas ĠAll Pat ients In Facility View ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġon Finish Inf late () Ġ{ ĊĠĠĠ Ġsuper . on Finish Inf late () ĊĠĠĠ Ġif Ġ( isIn Edit Mode ) Ġ{ ĊĠĠĠĠĠ Ġreturn ĊĠĠĠ Ġ} ĊĠĠĠ ĠThe Activity . component . inject ( this ) ĊĊĠĠĠ Ġtool Bar . set Navigation OnClickListener Ġ{ ĊĠĠĠĠĠ Ġscreen Router . pop () ĊĠĠĠ Ġ} ĊĠĠĠ Ġdisplay Screen Title () ĊĠĠĠ Ġsearch Query EditText . show Keyboard () ĊĊĠĠĠ Ġval Ġscreen Dest ro ys Ġ= ĠRx View . det aches ( this ). map Ġ{ ĠScreen Destroyed () Ġ} ĊĠĠĠ Ġhide Keyboard When All Pat ients List Is Sc rolled ( screen Dest ro ys ) ĊĊĠĠĠ Ġbind Ui To Controller ( ĊĠĠĠĠĠĠĠ Ġui Ġ= Ġthis , ĊĠĠĠĠĠĠĠ Ġevents Ġ= ĠObservable . merge ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsearch Query Changes (), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsearch Click s (), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġpatient Click Events () ĊĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠ Ġcontroller Ġ= Ġcontroller , ĊĠĠĠĠĠĠĠ Ġscreen Dest ro ys Ġ= Ġscreen Dest ro ys ĊĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġdisplay Screen Title () Ġ{ ĊĠĠĠ Ġval Ġidentifier Type Ġ= Ġidentifier Display Adapter . type As Text ( screen Key . identifier ) ĊĠĠĠ Ġval Ġidentifier Value Ġ= Ġidentifier Display Adapter . value As Text ( screen Key . identifier ) ĊĊĠĠĠ Ġval Ġidentifier TextAppearance Span Ġ= ĠText Appearance With Letter Spacing Span ( ĊĠĠĠĠĠĠĠ Ġcontext , ĊĠĠĠĠĠĠĠ ĠR . style . Clin ic _ V 2 _ TextAppearance _ Body 0 Left _ Numeric Bold _ White 1 0 0 ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġtitle TextView . text Ġ= ĠTr uss () ĊĠĠĠĠĠĠĠ Ġ. append ( resources . getString ( R . string . add id top at ient search _ add , Ġidentifier Type )) ĊĠĠĠĠĠĠĠ Ġ. push Span ( identifier TextAppearance Span ) ĊĠĠĠĠĠĠĠ Ġ. append ( identifier Value ) ĊĠĠĠĠĠĠĠ Ġ. pop Span () ĊĠĠĠĠĠĠĠ Ġ. append ( resources . getString ( R . string . add id top at ient search _ to _ patient )) ĊĠĠĠĠĠĠĠ Ġ. build () ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġsearch Query Changes (): ĠObservable < Ui Event > Ġ{ ĊĠĠĠ Ġreturn ĠRx TextView ĊĠĠĠĠĠĠĠ Ġ. text Changes ( search Query EditText ) ĊĠĠĠĠĠĠĠ Ġ. map ( CharSequence :: toString ) ĊĠĠĠĠĠĠĠ Ġ. map (:: Search Query TextChanged ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġsearch Click s (): ĠObservable < Search Clicked > Ġ{ ĊĠĠĠ Ġval Ġ ime Search Click s Ġ= ĠRx TextView ĊĠĠĠĠĠĠĠ Ġ. editor Action Events ( search Query EditText ) ĊĠĠĠĠĠĠĠ Ġ. filter Ġ{ Ġit . action Id () Ġ== ĠEditor Info . IME _ ACTION _ SEARCH Ġ} ĊĊĠĠĠ Ġreturn ĠRx View ĊĠĠĠĠĠĠĠ Ġ. click s ( search Button Frame . button ) ĊĠĠĠĠĠĠĠ Ġ. merge With ( ime Search Click s ) ĊĠĠĠĠĠĠĠ Ġ. map Ġ{ ĠSearch Clicked Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġpatient Click Events (): ĠObservable < Ui Event > Ġ{ ĊĠĠĠ Ġreturn Ġall Pat ients In Facility ĊĠĠĠĠĠĠĠ Ġ. ui Events ĊĠĠĠĠĠĠĠ Ġ. of Type < All Pat ients In Facility SearchResult Clicked >() ĊĠĠĠĠĠĠĠ Ġ. map Ġ{ Ġit . patient Uuid Ġ} ĊĠĠĠĠĠĠĠ Ġ. map (:: Patient Item Clicked ) ĊĠ Ġ} ĊĊĠ Ġ@ Suppress (" Check Result ") ĊĠ Ġprivate Ġfun Ġhide Keyboard When All Pat ients List Is Sc rolled ( screen Dest ro ys : ĠObservable < Screen Destroyed >) Ġ{ ĊĠĠĠ Ġall Pat ients In Facility ĊĠĠĠĠĠĠĠ Ġ. ui Events ĊĠĠĠĠĠĠĠ Ġ. of Type < All Pat ients In Facility List Sc rolled >() ĊĠĠĠĠĠĠĠ Ġ. take Until ( screen Dest ro ys ) ĊĠĠĠĠĠĠĠ Ġ. subscribe Ġ{ Ġenter Patient Name Input Container . hide Keyboard () Ġ} ĊĠ Ġ} ĊĊĠ Ġfun Ġopen Add Id To Patient SearchResults Screen ( criteria : ĠPatient Search Criteria ) Ġ{ ĊĠĠĠ Ġscreen Router . push ( Add Id To Patient SearchResults Screen Key ( ĊĠĠĠĠĠĠĠ Ġsearch Criteria Ġ= Ġcriteria , ĊĠĠĠĠĠĠĠ Ġidentifier Ġ= Ġscreen Key . identifier ĊĠĠĠ Ġ)) ĊĠ Ġ} ĊĊĠ Ġfun Ġset Empty Search Query Error Visible ( visible : ĠBoolean ) Ġ{ ĊĠĠĠ Ġsearch Query EditText . error Ġ= Ġif Ġ( visible ) Ġ{ ĊĠĠĠĠĠ Ġresources . getString ( R . string . add id top at ient search _ error _ empty _ fullname ) ĊĠĠĠ Ġ} Ġelse Ġnull ĊĠ Ġ} ĊĊĠ Ġfun Ġopen Patient Summary ( patient Uuid : ĠUUID ) Ġ{ ĊĠĠĠ Ġscreen Router . push ( Patient Summary Screen Key ( ĊĠĠĠĠĠĠĠ Ġpatient Uuid Ġ= Ġpatient Uuid , ĊĠĠĠĠĠĠĠ Ġintention Ġ= ĠOpen Int ention . Link Id With Patient ( screen Key . identifier ), ĊĠĠĠĠĠĠĠ Ġscreen Created Timestamp Ġ= ĠInstant . now ( utc Clock ) ĊĠĠĠ Ġ)) ĊĠ Ġ} ĊĊĠ Ġfun Ġshow All Pat ients In Facility () Ġ{ ĊĠĠĠ Ġall Pat ients In Facility View . visibility Ġ= ĠView . VISIBLE ĊĠ Ġ} ĊĊĠ Ġfun Ġhide All Pat ients In Facility () Ġ{ ĊĠĠĠ Ġall Pat ients In Facility View . visibility Ġ= ĠView . GONE ĊĠ Ġ} ĊĊĠ Ġfun Ġshow Search Button () Ġ{ ĊĠĠĠ Ġsearch Button Frame . visibility Ġ= ĠView . VISIBLE ĊĠ Ġ} ĊĊĠ Ġfun Ġhide Search Button () Ġ{ ĊĠĠĠ Ġsearch Button Frame . visibility Ġ= ĠView . GONE ĊĠ Ġ} Ċ } Ċ