package Ġuk . gov . just ice . digital . h mp ps . nom is pr isoner api . helper . builders Ċ Ċ import Ġorg . springframework . beans . factory . annotation . Autowired Ċ import Ġorg . springframework . data . repository . findById OrNull Ċ import Ġorg . springframework . jdbc . core . Jdbc Template Ċ import Ġorg . springframework . stereotype . Repository Ċ import Ġorg . springframework . transaction . annotation . Transactional Ċ import Ġuk . gov . just ice . digital . h mp ps . nom is pr isoner api . jpa . Ag ency Internal Location Ċ import Ġuk . gov . just ice . digital . h mp ps . nom is pr isoner api . jpa . Ag ency Location Ċ import Ġuk . gov . just ice . digital . h mp ps . nom is pr isoner api . jpa . Contact Type Ċ import Ġuk . gov . just ice . digital . h mp ps . nom is pr isoner api . jpa . Gender Ċ import Ġuk . gov . just ice . digital . h mp ps . nom is pr isoner api . jpa . Off ender Ċ import Ġuk . gov . just ice . digital . h mp ps . nom is pr isoner api . jpa . Person Ċ import Ġuk . gov . just ice . digital . h mp ps . nom is pr isoner api . jpa . Reference Code . Pk Ċ import Ġuk . gov . just ice . digital . h mp ps . nom is pr isoner api . jpa . Relationship Type Ċ import Ġuk . gov . just ice . digital . h mp ps . nom is pr isoner api . jpa . Visit Ċ import Ġuk . gov . just ice . digital . h mp ps . nom is pr isoner api . jpa . Visit Status Ċ import Ġuk . gov . just ice . digital . h mp ps . nom is pr isoner api . jpa . Visit Type Ċ import Ġuk . gov . just ice . digital . h mp ps . nom is pr isoner api . jpa . repository . Ag ency Internal Location Repository Ċ import Ġuk . gov . just ice . digital . h mp ps . nom is pr isoner api . jpa . repository . Ag ency Location Repository Ċ import Ġuk . gov . just ice . digital . h mp ps . nom is pr isoner api . jpa . repository . Off ender Repository Ċ import Ġuk . gov . just ice . digital . h mp ps . nom is pr isoner api . jpa . repository . Person Repository Ċ import Ġuk . gov . just ice . digital . h mp ps . nom is pr isoner api . jpa . repository . Reference Code Repository Ċ import Ġuk . gov . just ice . digital . h mp ps . nom is pr isoner api . jpa . repository . Visit Repository Ċ Ċ @ Repository Ċ @ Transactional Ċ class ĠRepository ( ĊĠ Ġval Ġgender Repository : ĠReference Code Repository < Gender >, ĊĠ Ġval Ġcontact Type Repository : ĠReference Code Repository < Contact Type >, ĊĠ Ġval Ġrelationship Type Repository : ĠReference Code Repository < Relationship Type >, ĊĠ Ġval Ġoff ender Repository : ĠOff ender Repository , ĊĠ Ġval Ġagency Location Repository : ĠAg ency Location Repository , ĊĠ Ġval Ġagency Internal Location Repository : ĠAg ency Internal Location Repository , ĊĠ Ġval Ġperson Repository : ĠPerson Repository , ĊĠ Ġval Ġvisit Repository : ĠVisit Repository , ĊĠ Ġval Ġvisit Status Repository : ĠReference Code Repository < Visit Status >, ĊĠ Ġval Ġvisit Type Repository : ĠReference Code Repository < Visit Type >, Ċ ) Ġ{ ĊĠ Ġ@ Autowired ĊĠ Ġlateinit Ġvar Ġjdbc Template : ĠJdbc Template ĊĠ Ġfun Ġsave ( off ender Builder : ĠOff ender Builder ): ĠOff ender Ġ{ ĊĠĠĠ Ġval Ġgender Ġ= Ġlookup Gender ( off ender Builder . gender Code ) ĊĊĠĠĠ Ġval Ġoff ender Ġ= Ġsave ( off ender Builder . build ( gender )). apply Ġ{ ĊĠĠĠĠĠ Ġroot Off ender Id Ġ= Ġid ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoff ender . bookings . addAll ( ĊĠĠĠĠĠ Ġoff ender Builder . booking Builders . map Indexed Ġ{ Ġindex , Ġbooking Builder Ġ-> ĊĠĠĠĠĠĠĠ Ġval Ġbooking Ġ= Ġbooking Builder . build ( off ender , Ġindex , Ġlookup Ag ency ( booking Builder . agency Location Id )) ĊĠĠĠĠĠĠĠ Ġbooking Builder . visit Balance Builder ?. run Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġbooking . visit Balance Ġ= Ġthis . build ( booking ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġbooking . contacts . addAll ( ĊĠĠĠĠĠĠĠĠĠ Ġbooking Builder . contacts . map Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġit . build ( booking , Ġlookup Contact Type ( it . contact TypeCode ), Ġlookup Relationship Type ( it . relationship TypeCode )) ĊĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġbooking . vis its . addAll ( ĊĠĠĠĠĠĠĠĠĠ Ġbooking Builder . vis its . map Ġ{ Ġvisit Builder Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġvisit Ġ= Ġvisit Builder . build ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġoff ender Booking Ġ= Ġbooking , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġvisit Type Ġ= Ġlookup Visit Type ( visit Builder . visit TypeCode ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġvisit Status Ġ= Ġlookup Visit Status ( visit Builder . visit StatusCode ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġagency Location Ġ= Ġlookup Ag ency ( visit Builder . agy Loc Id ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġagency Internal Location Ġ= Ġvisit Builder . agency Internal Location Description ?. run Ġ{ Ġlookup Ag ency Internal Location By Description ( this ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġvisit . visitor s . addAll ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġvisit Builder . visitor s . map Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġit . build ( it . person , Ġlead Visitor Ġ= Ġit . lead Visitor , Ġvisit ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} Ġ+ Ġvisit Builder . visit Outcome . build ( visit ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġvisit ĊĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġbooking ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġoff ender Repository . save And Flush ( off ender ) ĊĠĠĠ Ġreturn Ġoff ender ĊĠ Ġ} ĊĊĠ Ġfun Ġsave ( person Builder : ĠPerson Builder ): ĠPerson Ġ= Ġperson Repository . save ( person Builder . build ()) ĊĠ Ġfun Ġsave ( off ender : ĠOff ender ): ĠOff ender Ġ= Ġoff ender Repository . save And Flush ( off ender ) ĊĊĠ Ġfun Ġlookup Gender ( code : ĠString ): ĠGender Ġ= Ġgender Repository . findById OrNull ( Pk ( Gender . SE X , Ġcode )) !! ĊĠ Ġfun Ġlookup Contact Type ( code : ĠString ): ĠContact Type Ġ= ĊĠĠĠ Ġcontact Type Repository . findById OrNull ( Pk ( Contact Type . CONTACT S , Ġcode )) !! ĊĊĠ Ġfun Ġlookup Visit Type ( code : ĠString ): ĠVisit Type Ġ= ĊĠĠĠ Ġvisit Type Repository . findById OrNull ( Pk ( Visit Type . VISIT _ TYPE , Ġcode )) !! ĊĊĠ Ġfun Ġlookup Visit Status ( code : ĠString ): ĠVisit Status Ġ= ĊĠĠĠ Ġvisit Status Repository . findById OrNull ( Pk ( Visit Status . VISIT _ STATUS , Ġcode )) !! ĊĊĠ Ġfun Ġlookup Relationship Type ( code : ĠString ): ĠRelationship Type Ġ= ĊĠĠĠ Ġrelationship Type Repository . findById OrNull ( Pk ( Relationship Type . REL ATION SHIP , Ġcode )) !! ĊĊĠ Ġfun Ġlookup Ag ency ( id : ĠString ): ĠAg ency Location Ġ= Ġagency Location Repository . findById OrNull ( id ) !! ĊĠ Ġfun Ġlookup Ag ency Internal Location By Description ( description : ĠString ): ĠAg ency Internal Location Ġ= Ġagency Internal Location Repository . findOne By Description ( description ). map Ġ{ Ġit Ġ}. orElse ( null ) ĊĠ Ġfun Ġdelete ( off ender : ĠOff ender ) Ġ= Ġoff ender Repository . delete ById ( off ender . id ) ĊĠ Ġfun Ġdelete ( people : ĠCollection < Person >) Ġ= Ġperson Repository . delete All ById ( people . map Ġ{ Ġit . id Ġ}) ĊĊĠ Ġfun Ġlookup Visit ( visit Id : ĠLong ?): ĠVisit Ġ{ ĊĠĠĠ Ġval Ġvisit Ġ= Ġvisit Repository . findById ( visit Id !! ). orElse Throw () ĊĠĠĠ Ġvisit . visitor s . size Ġ// Ġh yd rate ĊĠĠĠ Ġvisit . visit Order ?. visitor s ?. size ĊĠĠĠ Ġreturn Ġvisit ĊĠ Ġ} ĊĊĠ Ġfun Ġchange Visit Status ( visit Id : ĠLong ?) Ġ{ ĊĠĠĠ Ġval Ġvisit Ġ= Ġvisit Repository . findById ( visit Id !! ). orElse Throw () ĊĠĠĠ Ġvisit . visit Status Ġ= Ġvisit Status Repository . findById ( Visit Status . NORM ). orElse Throw () ĊĠ Ġ} ĊĊĠ Ġfun Ġupdate Created To Match Visit Start () Ġ{ ĊĠĠĠ Ġval Ġsql Ġ= ĊĠĠĠĠĠ Ġ" UPDATE Ġoff ender _ vis its ĠSET ĠCREATE _ DATETIME Ġ= ĠSTART _ TIME " ĊĠĠĠ Ġjdbc Template . execute ( sql ) ĊĠ Ġ} Ċ } Ċ