package Ġnet . cord acl ub . mar ge Ċ Ċ import Ġco . parallel universe . fib ers . Suspend able Ċ import Ġio . cord ite . d gl . cord a . account . Get Account Flow Ċ import Ġnet . cord a . core . contracts . Amount Ċ import Ġnet . cord a . core . contracts . Command Ċ import Ġnet . cord a . core . contracts . State And Ref Ċ import Ġnet . cord a . core . flows . Final ity Flow Ċ import Ġnet . cord a . core . flows . Flow Logic Ċ import Ġnet . cord a . core . flows . Start able By RPC Ċ import Ġnet . cord a . core . flows . Start able By Service Ċ import Ġnet . cord a . core . transactions . Signed Transaction Ċ import Ġnet . cord a . core . transactions . Transaction Builder Ċ import Ġnet . cord a . core . utilities . seconds Ċ import Ġnet . cord acl ub . mar ge . hospital . Ho spital API Ċ import Ġjava . util .* Ċ Ċ /** Ċ Ġ* ĠSecond ĠFlow ! Ċ Ġ* ĠThis Ġis Ġrun Ġby Ġthe ĠHo spital Ġwhen Ġthe Ġtreatment Ġis Ġover . Ċ Ġ* Ċ Ġ* Ġ 1 ) ĠIt Ġwill Ġtransition Ġthe ĠT reatment State Ġto Ġthe ĠFinal ized Ġstatus . Ċ Ġ* Ġ 2 ) ĠIt Ġwill Ġrequests Ġpayments Ġfrom Ġthe Ġins urer Ġand Ġpatient . Ċ Ġ*/ Ċ @ Start able By RPC Ċ @ Start able By Service Ċ class ĠTrigger T reatment Payments Flow ( private Ġval Ġtreatment State : ĠState And Ref < T reatment State >, Ġprivate Ġval Ġreal T reatment Cost : ĠAmount < Currency >) Ġ: ĠFlow Logic < Unit >() Ġ{ ĊĊĠĠĠ Ġ@ Suspend able ĊĠĠĠ Ġoverride Ġfun Ġcall () Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġfinal ised T reatment Ġ= Ġfinal ise T reatment () ĊĠĠĠĠĠĠĠ Ġsleep ( 1 0 . seconds ) ĊĊĠĠĠĠĠĠĠ Ġval Ġhospital Account Ġ= Ġsub Flow ( Get Account Flow ( Ho spital API . HO SP ITAL _ ACCOUNT )). state . data . address ĊĊĠĠĠĠĠĠĠ Ġval Ġpayment From Ins urer Tx Ġ= Ġsub Flow ( Ins urer Flows . Ins urer T reatment Payment Flow ( final ised T reatment . core Transaction . out Ref ( 0 ), Ġhospital Account )) ĊĊĠĠĠĠĠĠĠ Ġsleep ( 1 0 . seconds ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġthe Ġpatient Ġneeds Ġto Ġcover Ġthe Ġdifference ĊĠĠĠĠĠĠĠ Ġsub Flow ( Patient Flows . Patient T reatment Payment Flow ( payment From Ins urer Tx , Ġhospital Account )) ĊĊĠĠĠĠĠĠĠ Ġprintln (" Finished ĠTrigger T reatment Payments Flow ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Suspend able ĊĠĠĠ Ġprivate Ġfun Ġfinal ise T reatment (): ĠSigned Transaction Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġnot ary Ġ= Ġservice Hub . network Map Cache . not ary Id entities . first () ĊĠĠĠĠĠĠĠ Ġval Ġt xb Ġ= ĠTransaction Builder ( not ary ). apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd Command ( Command ( T reatment Command . Final ise T reatment (), ĠlistOf ( our Identity . own ing Key ))) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd Input State ( t reatment State ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd Output State ( t reatment State . state . copy ( data Ġ= Ġtreatment State . state . data . let Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠT reatment State ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġtreatment Ġ= Ġit . t reatment , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġestimated T reatment Cost Ġ= Ġit . estimated T reatment Cost , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġtreatment Cost Ġ= Ġreal T reatment Cost , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġamount Pay ed Ġ= Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġins urer Quote Ġ= Ġit . ins urer Quote , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġtreatment Status Ġ= ĠT reatment Status . FIN ALI SED , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġlinear Id Ġ= Ġit . linear Id ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ})) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġst x Ġ= Ġservice Hub . sign Initial Transaction ( tx b ) ĊĠĠĠĠĠĠĠ Ġreturn Ġsub Flow ( Final ity Flow ( st x )) ĊĠĠĠ Ġ} Ċ } Ċ