dialysis_api_controller.go 137KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648
  1. package controllers
  2. import (
  3. "XT_New/models"
  4. "XT_New/service"
  5. "XT_New/utils"
  6. "encoding/json"
  7. "fmt"
  8. "github.com/jinzhu/gorm"
  9. "math"
  10. "reflect"
  11. "strconv"
  12. "strings"
  13. //"strings"
  14. "time"
  15. "XT_New/enums"
  16. "github.com/astaxie/beego"
  17. )
  18. type DialysisApiController struct {
  19. BaseAuthAPIController
  20. }
  21. func DialysisApiRegistRouters() {
  22. beego.Router("/api/dialysis/device", &DialysisApiController{}, "get:GetDeviceList")
  23. beego.Router("/api/dialysis/patients", &DialysisApiController{}, "get:GetDialysisWatch")
  24. beego.Router("/api/dialysis/zone", &DialysisApiController{}, "get:GetAllDeviceZone")
  25. beego.Router("/api/dialysis/info", &DialysisApiController{}, "get:GetSchedualPatientsInfo")
  26. beego.Router("/api/dialysis/advice/create", &DialysisApiController{}, "Post:CreateDoctorAdvice")
  27. beego.Router("/api/dialysis/advice/get", &DialysisApiController{}, "Get:GetDoctorAdvice")
  28. beego.Router("/api/dialysis/advice/edit", &DialysisApiController{}, "put:EditDoctorAdvice")
  29. beego.Router("/api/dialysis/monitor/create", &DialysisApiController{}, "Post:CreateMonitor")
  30. beego.Router("/api/dialysis/monitor/del", &DialysisApiController{}, "Post:DelMonitor")
  31. beego.Router("/api/dialysis/dialysisorder", &DialysisApiController{}, "Get:GetDialysisOrder")
  32. beego.Router("/api/dialysis/prescription", &DialysisApiController{}, "Post:PostPrescription")
  33. beego.Router("/api/dialysis/soulution", &DialysisApiController{}, "Post:PostSoulution")
  34. beego.Router("/api/dialysis/dobule", &DialysisApiController{}, "Post:PostDouleCheck")
  35. beego.Router("/api/dialysis/accepts", &DialysisApiController{}, "Post:PostReceiveTreatmentAsses")
  36. beego.Router("/api/dialysis/assessmentbeforedislysis", &DialysisApiController{}, "Post:PostAssessmentBeforeDislysis")
  37. beego.Router("/api/dialysis/assessmentafterdislysis", &DialysisApiController{}, "Post:PostAssessmentAfterDislysis")
  38. beego.Router("/api/dialysis/treatmentsummary", &DialysisApiController{}, "Post:PostTreatmentSummary")
  39. beego.Router("/api/dialysis/advice_remind", &DialysisApiController{}, "Get:GetLongAdvice")
  40. beego.Router("/api/advice_remind/create", &DialysisApiController{}, "Post:CreateRemindDoctorAdvice")
  41. beego.Router("/api/solution/get", &DialysisApiController{}, "Get:GetSolution")
  42. beego.Router("/api/schedule/get", &DialysisApiController{}, "Get:GetSchedule")
  43. beego.Router("/api/today_monitor/get", &DialysisApiController{}, "Get:GetTodayMonitor")
  44. beego.Router("/api/dryweight/commit", &DialysisApiController{}, "Post:UploadDryWeight")
  45. beego.Router("/api/func_per/get", &DialysisApiController{}, "Get:GetFuncPurview")
  46. beego.Router("/api/doctoradvice/get", &DialysisApiController{}, "Get:GetLastOrNextDoctorAdvice")
  47. beego.Router("/api/dialysisgoods/get", &DialysisApiController{}, "Get:GetDialysisGoods")
  48. beego.Router("/api/goodstatistics/get", &DialysisApiController{}, "Get:GetDialysisGoodsStatistics")
  49. beego.Router("/api/queue/get", &DialysisApiController{}, "Get:GetQueueCall")
  50. beego.Router("/api/queue/update", &DialysisApiController{}, "Get:UpdateQueueCall")
  51. }
  52. func (c *DialysisApiController) GetQueueCall() {
  53. adminUserInfo := c.GetAdminUserInfo()
  54. queueConfig, _ := service.FindQueueCallInfo(adminUserInfo.CurrentOrgId)
  55. if queueConfig.ID <= 0 {
  56. queueConfig.OrgId = adminUserInfo.CurrentOrgId
  57. queueConfig.Qhsj = 10
  58. queueConfig.Jzdcbbcs = 3
  59. queueConfig.Jzbbsy = 1
  60. queueConfig.Jzjhyc = 0
  61. queueConfig.Sjdcbbcs = 3
  62. queueConfig.Sjbbsy = 0
  63. queueConfig.Sjjhyc = 0
  64. queueConfig.Txxqyxs = 0
  65. queueConfig.Txglsyxs = 0
  66. }
  67. c.ServeSuccessJSON(map[string]interface{}{
  68. "queue_config": queueConfig,
  69. })
  70. }
  71. func (c *DialysisApiController) UpdateQueueCall() {
  72. adminUserInfo := c.GetAdminUserInfo()
  73. queueConfig, _ := service.FindQueueCallInfo(adminUserInfo.CurrentOrgId)
  74. if queueConfig.ID <= 0 {
  75. queueConfig.OrgId = adminUserInfo.CurrentOrgId
  76. queueConfig.Qhsj = 10
  77. queueConfig.Jzdcbbcs = 3
  78. queueConfig.Jzbbsy = 1
  79. queueConfig.Jzjhyc = 0
  80. queueConfig.Sjdcbbcs = 3
  81. queueConfig.Sjbbsy = 0
  82. queueConfig.Sjjhyc = 0
  83. queueConfig.Txxqyxs = 0
  84. queueConfig.Txglsyxs = 0
  85. queueConfig.CreateTime = time.Now().Unix()
  86. queueConfig.UpdateTime = time.Now().Unix()
  87. }
  88. qhsj, _ := c.GetInt64("qhsj", 0)
  89. if qhsj > 0 {
  90. queueConfig.Qhsj = qhsj
  91. }
  92. jzdcbbcs, _ := c.GetInt64("jzdcbbcs", 0)
  93. if jzdcbbcs > 0 {
  94. queueConfig.Jzdcbbcs = jzdcbbcs
  95. }
  96. jzbbsy, _ := c.GetInt64("jzbbsy", 0)
  97. if jzbbsy > 0 {
  98. queueConfig.Jzbbsy = jzbbsy
  99. }
  100. jzjhyc, _ := c.GetInt64("jzjhyc", 0)
  101. queueConfig.Jzjhyc = jzjhyc
  102. sjdcbbcs, _ := c.GetInt64("sjdcbbcs", 0)
  103. if sjdcbbcs > 0 {
  104. queueConfig.Sjdcbbcs = sjdcbbcs
  105. }
  106. sjbbsy, _ := c.GetInt64("sjbbsy", 0)
  107. if sjbbsy > 0 {
  108. queueConfig.Sjbbsy = sjbbsy
  109. }
  110. sjjhyc, _ := c.GetInt64("sjjhyc", 0)
  111. queueConfig.Sjjhyc = sjjhyc
  112. txxqyxs, _ := c.GetInt64("txxqyxs", 0)
  113. queueConfig.Txxqyxs = txxqyxs
  114. txglsyxs, _ := c.GetInt64("txglsyxs", 0)
  115. queueConfig.Txglsyxs = txglsyxs
  116. queueConfig.UpdateTime = time.Now().Unix()
  117. service.UpDateQueueCallInfo(queueConfig)
  118. c.ServeSuccessJSON(map[string]interface{}{
  119. "queue_config": queueConfig,
  120. })
  121. }
  122. func (c *DialysisApiController) PostPrescription() {
  123. patient, _ := c.GetInt64("patient", 0)
  124. recordDateStr := c.GetString("record_date")
  125. if patient <= 0 {
  126. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  127. return
  128. }
  129. adminUserInfo := c.GetAdminUserInfo()
  130. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  131. if patientInfo.ID == 0 {
  132. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  133. return
  134. }
  135. if len(recordDateStr) == 0 {
  136. recordDateStr = time.Now().Format("2006-01-02")
  137. }
  138. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  139. if parseDateErr != nil {
  140. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  142. return
  143. }
  144. mode_id, _ := c.GetInt64("mode_id", 0)
  145. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  146. dialyzer, _ := c.GetInt64("dialyzer", 0)
  147. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  148. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  149. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  150. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  151. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  152. replacement_way, _ := c.GetInt64("replacement_way", 0)
  153. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  154. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  155. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  156. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  157. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  158. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  159. kalium, _ := c.GetFloat("kalium", 0)
  160. sodium, _ := c.GetFloat("sodium", 0)
  161. replacement_total, _ := c.GetFloat("replacement_total", 0)
  162. calcium, _ := c.GetFloat("calcium", 0)
  163. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  164. glucose, _ := c.GetFloat("glucose", 0)
  165. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  166. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  167. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  168. conductivity, _ := c.GetFloat("conductivity", 0)
  169. remark := c.GetString("remark")
  170. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  171. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  172. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  173. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  174. body_fluid, _ := c.GetInt64("body_fluid", 0)
  175. special_medicine, _ := c.GetInt64("special_medicine", 0)
  176. special_medicine_other := c.GetString("special_medicine_other")
  177. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  178. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  179. blood_access, _ := c.GetInt64("blood_access", 0)
  180. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  181. body_fluid_other := c.GetString("body_fluid_other")
  182. target_ktv, _ := c.GetFloat("target_ktv", 0)
  183. niprocart, _ := c.GetInt64("niprocart", 0)
  184. jms, _ := c.GetInt64("jms", 0)
  185. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  186. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  187. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  188. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  189. filtryzer, _ := c.GetInt64("filtryzer", 0)
  190. dialyzers, _ := c.GetInt64("dialyzers", 0)
  191. injector, _ := c.GetInt64("injector", 0)
  192. bloodlines, _ := c.GetInt64("bloodlines", 0)
  193. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  194. safe_package, _ := c.GetInt64("package", 0)
  195. a_liquid, _ := c.GetInt64("a_liquid", 0)
  196. preImpules, _ := c.GetFloat("pre_impulse", 0)
  197. fmt.Println("", preImpules)
  198. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  199. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  200. //heparin_sodium := c.GetString("heparin_sodium")
  201. //fmt.Println("肝素钠",heparin_sodium)
  202. //nucleoprotamine := c.GetString("nucleoprotamine")
  203. //fmt.Println("鱼精蛋白",nucleoprotamine)
  204. //push_the_protamine := c.GetString("push_the_protamine")
  205. //fmt.Println("下机前推注鱼精蛋白",push_the_protamine)
  206. // var prescription_doctor int64
  207. blood := c.GetString("blood")
  208. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  209. dialysis_irrigation := c.GetString("dialysis_irrigation")
  210. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  211. displace_speed := c.GetString("displace_speed")
  212. illness, _ := c.GetInt64("illness")
  213. amylaceum := c.GetString("amylaceum")
  214. single_time := c.GetString("single_time")
  215. single_water := c.GetString("single_water")
  216. replacement_flow := c.GetString("replacement_flow")
  217. plasma_separator := c.GetString("plasma_separator")
  218. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  219. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  220. oxygen_flow := c.GetString("oxygen_flow")
  221. oxygen_time := c.GetString("oxygen_time")
  222. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  223. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  224. puncture_needle := c.GetString("puncture_needle")
  225. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  226. epo := c.GetString("epo")
  227. epo_count, _ := c.GetFloat("epo_count", 0)
  228. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  229. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  230. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  231. //if template.TemplateId == 2 || template.TemplateId == 6 {
  232. // if appRole.UserType == 3 {
  233. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  234. // if getPermissionErr != nil {
  235. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  236. // return
  237. // } else if headNursePermission == nil {
  238. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  239. // return
  240. // }
  241. // }
  242. //}
  243. prescription := models.DialysisPrescription{
  244. UserOrgId: adminUserInfo.CurrentOrgId,
  245. PatientId: patient,
  246. RecordDate: recordDate.Unix(),
  247. ModeId: mode_id,
  248. DialysisDuration: dialysis_duration,
  249. Dialyzer: dialyzer,
  250. ReplacementTotal: replacement_total,
  251. PerfusionApparatus: perfusion_apparatus,
  252. BloodFlowVolume: blood_flow_volume,
  253. DewaterAmount: dewater_amount,
  254. DisplaceLiqui: displace_liqui,
  255. ReplacementWay: replacement_way,
  256. Anticoagulant: anticoagulant,
  257. AnticoagulantShouji: anticoagulant_shouji,
  258. AnticoagulantWeichi: anticoagulant_weichi,
  259. AnticoagulantZongliang: anticoagulant_zongliang,
  260. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  261. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  262. Kalium: kalium,
  263. Sodium: sodium,
  264. Calcium: calcium,
  265. Bicarbonate: bicarbonate,
  266. Glucose: glucose,
  267. // DryWeight: dry_weight,
  268. DialysateFlow: dialysate_flow,
  269. DialysateTemperature: dialysate_temperature,
  270. Conductivity: conductivity,
  271. Remark: remark,
  272. Status: 1,
  273. CreatedTime: time.Now().Unix(),
  274. UpdatedTime: time.Now().Unix(),
  275. DialysisDurationMinute: dialysisDurationMinute,
  276. DialysisDurationHour: dialysisDurationHour,
  277. TargetUltrafiltration: targetUltrafiltration,
  278. DialysateFormulation: dialysateFormulation,
  279. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  280. BodyFluid: body_fluid,
  281. SpecialMedicine: special_medicine,
  282. SpecialMedicineOther: special_medicine_other,
  283. DisplaceLiquiPart: displace_liqui_part,
  284. DisplaceLiquiValue: displace_liqui_value,
  285. BloodAccess: blood_access,
  286. Ultrafiltration: ultrafiltration,
  287. BodyFluidOther: body_fluid_other,
  288. TargetKtv: target_ktv,
  289. Niprocart: niprocart,
  290. Jms: jms,
  291. FistulaNeedleSet: fistula_needle_set,
  292. FistulaNeedleSet16: fistula_needle_set_16,
  293. Hemoperfusion: hemoperfusion,
  294. DialyserSterilised: dialyser_sterilised,
  295. Filtryzer: filtryzer,
  296. Dialyzers: dialyzers,
  297. Injector: injector,
  298. Bloodlines: bloodlines,
  299. TubingHemodialysis: tubing_hemodialysis,
  300. Package: safe_package,
  301. ALiquid: a_liquid,
  302. PreImpulse: preImpules,
  303. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  304. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  305. Blood: blood,
  306. DialysisDialyszers: dialysis_dialyszers,
  307. DialysisIrrigation: dialysis_irrigation,
  308. AntioxidantCommodityName: antioxidant_commodity_name,
  309. DisplaceSpeed: displace_speed,
  310. Illness: illness,
  311. Amylaceum: amylaceum,
  312. SingleTime: single_time,
  313. SingleWater: single_water,
  314. ReplacementFlow: replacement_flow,
  315. PlasmaSeparator: plasma_separator,
  316. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  317. OxygenFlow: oxygen_flow,
  318. OxygenUptake: oxygen_uptake,
  319. OxygenTime: oxygen_time,
  320. HemodialysisPipelines: hemodialysis_pipelines,
  321. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  322. PunctureNeedle: puncture_needle,
  323. PunctureNeedleCount: puncture_needle_count,
  324. Epo: epo,
  325. EpoCount: epo_count,
  326. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  327. }
  328. if appRole.UserType == 2 || appRole.UserType == 1 {
  329. prescription.PrescriptionDoctor = appRole.AdminUserId
  330. }
  331. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  332. if dialysisPrescription.ID == 0 { //新增
  333. if mode_id > 0 {
  334. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  335. }
  336. prescription.Creater = adminUserInfo.AdminUser.Id
  337. err := service.AddSigleRecord(&prescription)
  338. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  339. redis := service.RedisClient()
  340. defer redis.Close()
  341. //清空key 值
  342. redis.Set(key, "", time.Second)
  343. if err == nil {
  344. updateErr := service.UpdateScheduleModeId(patient, adminUserInfo.CurrentOrgId, recordDate.Unix(), mode_id)
  345. if updateErr != nil {
  346. utils.ErrorLog("%v", updateErr)
  347. }
  348. c.ServeSuccessJSON(map[string]interface{}{
  349. "prescription": &prescription,
  350. })
  351. } else {
  352. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  353. }
  354. } else { //修改
  355. if mode_id > 0 {
  356. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  357. }
  358. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  359. //if template.TemplateId == 1 {
  360. // if dialysisPrescription.Creater > 0 && dialysisPrescription.Creater != adminUserInfo.AdminUser.Id {
  361. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  362. // if getPermissionErr != nil {
  363. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  364. // return
  365. // } else if headNursePermission == nil {
  366. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  367. // return
  368. // }
  369. // }
  370. //}
  371. if appRole.UserType == 2 || appRole.UserType == 1 {
  372. prescription_doctor := adminUserInfo.AdminUser.Id
  373. prescription.PrescriptionDoctor = prescription_doctor
  374. }
  375. if dialysisPrescription.Creater == 0 { //体重称
  376. prescription.Creater = adminUserInfo.AdminUser.Id
  377. } else {
  378. prescription.Creater = dialysisPrescription.Creater
  379. }
  380. prescription.CreatedTime = dialysisPrescription.CreatedTime
  381. prescription.UpdatedTime = time.Now().Unix()
  382. prescription.Modifier = adminUserInfo.AdminUser.Id
  383. prescription.ID = dialysisPrescription.ID
  384. updateErr := service.UpDateDialysisPrescription(&prescription)
  385. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  386. redis := service.RedisClient()
  387. defer redis.Close()
  388. //清空key 值
  389. redis.Set(key, "", time.Second)
  390. if updateErr == nil {
  391. updateErr := service.UpdateScheduleModeId(patient, adminUserInfo.CurrentOrgId, recordDate.Unix(), mode_id)
  392. if updateErr != nil {
  393. utils.ErrorLog("%v", updateErr)
  394. }
  395. c.ServeSuccessJSON(map[string]interface{}{
  396. "prescription": &prescription,
  397. })
  398. } else {
  399. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  400. }
  401. }
  402. }
  403. func (c *DialysisApiController) PostSoulution() {
  404. patient, _ := c.GetInt64("patient", 0)
  405. recordDateStr := c.GetString("record_date")
  406. if patient <= 0 {
  407. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  408. return
  409. }
  410. adminUserInfo := c.GetAdminUserInfo()
  411. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  412. if patientInfo.ID == 0 {
  413. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  414. return
  415. }
  416. if len(recordDateStr) == 0 {
  417. recordDateStr = time.Now().Format("2006-01-02")
  418. }
  419. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  420. if parseDateErr != nil {
  421. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  422. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  423. return
  424. }
  425. mode_id, _ := c.GetInt64("mode_id", 0)
  426. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  427. dialyzer, _ := c.GetInt64("dialyzer", 0)
  428. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  429. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  430. replacement_total, _ := c.GetFloat("replacement_total", 0)
  431. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  432. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  433. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  434. replacement_way, _ := c.GetInt64("replacement_way", 0)
  435. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  436. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  437. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  438. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  439. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  440. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  441. kalium, _ := c.GetFloat("kalium", 0)
  442. sodium, _ := c.GetFloat("sodium", 0)
  443. calcium, _ := c.GetFloat("calcium", 0)
  444. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  445. glucose, _ := c.GetFloat("glucose", 0)
  446. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  447. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  448. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  449. conductivity, _ := c.GetFloat("conductivity", 0)
  450. remark := c.GetString("remark")
  451. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  452. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  453. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  454. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  455. body_fluid, _ := c.GetInt64("body_fluid", 0)
  456. special_medicine, _ := c.GetInt64("special_medicine", 0)
  457. special_medicine_other := c.GetString("special_medicine_other")
  458. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  459. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  460. blood_access, _ := c.GetInt64("blood_access", 0)
  461. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  462. body_fluid_other := c.GetString("body_fluid_other")
  463. target_ktv, _ := c.GetFloat("target_ktv", 0)
  464. niprocart, _ := c.GetInt64("niprocart", 0)
  465. jms, _ := c.GetInt64("jms", 0)
  466. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  467. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  468. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  469. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  470. filtryzer, _ := c.GetInt64("filtryzer", 0)
  471. dialyzers, _ := c.GetInt64("dialyzers", 0)
  472. injector, _ := c.GetInt64("injector", 0)
  473. bloodlines, _ := c.GetInt64("bloodlines", 0)
  474. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  475. safe_package, _ := c.GetInt64("package", 0)
  476. a_liquid, _ := c.GetInt64("a_liquid", 0)
  477. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  478. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  479. blood := c.GetString("blood")
  480. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  481. dialysis_irrigation := c.GetString("dialysis_irrigation")
  482. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  483. displace_speed := c.GetString("displace_speed")
  484. illness, _ := c.GetInt64("illness")
  485. amylaceum := c.GetString("amylaceum")
  486. single_time := c.GetString("single_time")
  487. single_water := c.GetString("single_water")
  488. replacement_flow := c.GetString("replacement_flow")
  489. plasma_separator := c.GetString("plasma_separator")
  490. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  491. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  492. oxygen_flow := c.GetString("oxygen_flow")
  493. oxygen_time := c.GetString("oxygen_time")
  494. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  495. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  496. puncture_needle := c.GetString("puncture_needle")
  497. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  498. epo := c.GetString("epo")
  499. epo_count, _ := c.GetFloat("epo_count", 0)
  500. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  501. var prescription_doctor int64
  502. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  503. if appRole.UserType == 2 || appRole.UserType == 1 {
  504. prescription_doctor = appRole.AdminUserId
  505. }
  506. if mode_id > 0 {
  507. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  508. }
  509. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  510. //
  511. //if template.TemplateId == 2 || template.TemplateId == 6 {
  512. // if appRole.UserType == 3 {
  513. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  514. // if getPermissionErr != nil {
  515. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  516. // return
  517. // } else if headNursePermission == nil {
  518. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  519. // return
  520. // }
  521. // }
  522. //}
  523. prescription := models.DialysisPrescription{
  524. UserOrgId: adminUserInfo.CurrentOrgId,
  525. PatientId: patient,
  526. RecordDate: recordDate.Unix(),
  527. ModeId: mode_id,
  528. DialysisDuration: dialysis_duration,
  529. Dialyzer: dialyzer,
  530. PerfusionApparatus: perfusion_apparatus,
  531. BloodFlowVolume: blood_flow_volume,
  532. DewaterAmount: dewater_amount,
  533. DisplaceLiqui: displace_liqui,
  534. ReplacementWay: replacement_way,
  535. Anticoagulant: anticoagulant,
  536. AnticoagulantShouji: anticoagulant_shouji,
  537. AnticoagulantWeichi: anticoagulant_weichi,
  538. AnticoagulantZongliang: anticoagulant_zongliang,
  539. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  540. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  541. Kalium: kalium,
  542. Sodium: sodium,
  543. Calcium: calcium,
  544. Bicarbonate: bicarbonate,
  545. Glucose: glucose,
  546. // DryWeight: dry_weight,
  547. DialysateFlow: dialysate_flow,
  548. DialysateTemperature: dialysate_temperature,
  549. Conductivity: conductivity,
  550. Remark: remark,
  551. PrescriptionDoctor: prescription_doctor,
  552. Status: 1,
  553. CreatedTime: time.Now().Unix(),
  554. UpdatedTime: time.Now().Unix(),
  555. DialysisDurationMinute: dialysisDurationMinute,
  556. DialysisDurationHour: dialysisDurationHour,
  557. TargetUltrafiltration: targetUltrafiltration,
  558. DialysateFormulation: dialysateFormulation,
  559. ReplacementTotal: replacement_total,
  560. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  561. BodyFluid: body_fluid,
  562. SpecialMedicine: special_medicine,
  563. SpecialMedicineOther: special_medicine_other,
  564. DisplaceLiquiPart: displace_liqui_part,
  565. DisplaceLiquiValue: displace_liqui_value,
  566. BloodAccess: blood_access,
  567. Ultrafiltration: ultrafiltration,
  568. BodyFluidOther: body_fluid_other,
  569. TargetKtv: target_ktv,
  570. Niprocart: niprocart,
  571. Jms: jms,
  572. FistulaNeedleSet: fistula_needle_set,
  573. FistulaNeedleSet16: fistula_needle_set_16,
  574. Hemoperfusion: hemoperfusion,
  575. DialyserSterilised: dialyser_sterilised,
  576. Filtryzer: filtryzer,
  577. Dialyzers: dialyzers,
  578. Injector: injector,
  579. Bloodlines: bloodlines,
  580. TubingHemodialysis: tubing_hemodialysis,
  581. Package: safe_package,
  582. ALiquid: a_liquid,
  583. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  584. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  585. Blood: blood,
  586. DialysisIrrigation: dialysis_irrigation,
  587. DialysisDialyszers: dialysis_dialyszers,
  588. AntioxidantCommodityName: antioxidant_commodity_name,
  589. DisplaceSpeed: displace_speed,
  590. Illness: illness,
  591. Amylaceum: amylaceum,
  592. SingleTime: single_time,
  593. SingleWater: single_water,
  594. ReplacementFlow: replacement_flow,
  595. PlasmaSeparator: plasma_separator,
  596. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  597. OxygenTime: oxygen_time,
  598. OxygenUptake: oxygen_uptake,
  599. OxygenFlow: oxygen_flow,
  600. HemodialysisPipelines: hemodialysis_pipelines,
  601. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  602. PunctureNeedle: puncture_needle,
  603. PunctureNeedleCount: puncture_needle_count,
  604. Epo: epo,
  605. EpoCount: epo_count,
  606. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  607. }
  608. //查询最近透析准备表里是否存在 透析器 灌流器
  609. //splitStr := strings.Split(dialysis_dialyszers, ",")
  610. //
  611. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  612. //
  613. //mation, _ := service.GetGoodInfoMation(adminUserInfo.CurrentOrgId)
  614. //if len(mation)>0{
  615. // for _, item := range splitStr {
  616. // for _,it := range mation{
  617. // if(item == it.SpecificationName){
  618. //
  619. // //查询最近一次的透析器
  620. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.CurrentOrgId,patient)
  621. //
  622. // if errcode == gorm.ErrRecordNotFound{
  623. // //插入数据
  624. // prepare := models.DialysisBeforePrepare{
  625. // UserOrgId: adminUserInfo.CurrentOrgId,
  626. // PatientId: patient,
  627. // RecordDate: recordDate.Unix(),
  628. // GoodTypeId: it.GoodTypeId,
  629. // GoodId: it.ID,
  630. // Count: 1,
  631. // Ctime: time.Now().Unix(),
  632. // Creater: adminUserInfo.AdminUser.Id,
  633. // Status:1,
  634. //
  635. // }
  636. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  637. // fmt.Println("",errcode)
  638. // }
  639. // }
  640. // }
  641. //
  642. // }
  643. //
  644. // for _, item := range splitIrrigation {
  645. // for _,it := range mation{
  646. // if(item == it.SpecificationName){
  647. // //查询最近一次的透析器
  648. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.CurrentOrgId,patient)
  649. // if errcode == gorm.ErrRecordNotFound{
  650. // //插入数据
  651. // prepare := models.DialysisBeforePrepare{
  652. // UserOrgId: adminUserInfo.CurrentOrgId,
  653. // PatientId: patient,
  654. // RecordDate: recordDate.Unix(),
  655. // GoodTypeId: it.GoodTypeId,
  656. // GoodId: it.ID,
  657. // Count: 1,
  658. // Ctime: time.Now().Unix(),
  659. // Creater: adminUserInfo.AdminUser.Id,
  660. // Status:1,
  661. //
  662. // }
  663. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  664. // fmt.Println(errcode)
  665. // }
  666. // }
  667. // }
  668. // }
  669. //}
  670. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  671. if dialysisPrescription.ID == 0 { //新增
  672. if appRole.UserType == 2 || appRole.UserType == 1 {
  673. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  674. }
  675. prescription.Creater = adminUserInfo.AdminUser.Id
  676. } else { //修改
  677. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  678. //if template.TemplateId == 1 {
  679. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  680. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  681. // if getPermissionErr != nil {
  682. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  683. // return
  684. // } else if headNursePermission == nil {
  685. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  686. // return
  687. // }
  688. // }
  689. //}
  690. if appRole.UserType == 2 || appRole.UserType == 1 {
  691. prescription_doctor := adminUserInfo.AdminUser.Id
  692. prescription.PrescriptionDoctor = prescription_doctor
  693. } else {
  694. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  695. }
  696. if dialysisPrescription.Creater == 0 {
  697. prescription.Creater = adminUserInfo.AdminUser.Id
  698. } else {
  699. prescription.Creater = dialysisPrescription.Creater
  700. }
  701. prescription.CreatedTime = dialysisPrescription.CreatedTime
  702. prescription.UpdatedTime = time.Now().Unix()
  703. prescription.Modifier = adminUserInfo.AdminUser.Id
  704. prescription.ID = dialysisPrescription.ID
  705. }
  706. solution := models.DialysisSolution{
  707. RegistrarsId: adminUserInfo.AdminUser.Id,
  708. UserOrgId: adminUserInfo.CurrentOrgId,
  709. Doctor: prescription_doctor,
  710. PatientId: patient,
  711. ModeId: mode_id,
  712. DialysisDuration: dialysis_duration,
  713. PerfusionApparatus: perfusion_apparatus,
  714. BloodFlowVolume: blood_flow_volume,
  715. Dewater: dewater_amount,
  716. DisplaceLiqui: displace_liqui,
  717. ReplacementWay: replacement_way,
  718. Anticoagulant: anticoagulant,
  719. AnticoagulantShouji: anticoagulant_shouji,
  720. AnticoagulantWeichi: anticoagulant_weichi,
  721. AnticoagulantZongliang: anticoagulant_zongliang,
  722. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  723. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  724. Kalium: kalium,
  725. Sodium: sodium,
  726. Calcium: calcium,
  727. Bicarbonate: bicarbonate,
  728. Glucose: glucose,
  729. // DryWeight: dry_weight,
  730. DialysateFlow: dialysate_flow,
  731. DialysateTemperature: dialysate_temperature,
  732. Conductivity: conductivity,
  733. Remark: remark,
  734. Status: 1,
  735. CreatedTime: time.Now().Unix(),
  736. UpdatedTime: time.Now().Unix(),
  737. DialysisDurationMinute: dialysisDurationMinute,
  738. DialysisDurationHour: dialysisDurationHour,
  739. TargetUltrafiltration: targetUltrafiltration,
  740. DialysateFormulation: dialysateFormulation,
  741. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  742. BodyFluid: body_fluid,
  743. SpecialMedicine: special_medicine,
  744. SpecialMedicineOther: special_medicine_other,
  745. DisplaceLiquiPart: displace_liqui_part,
  746. DisplaceLiquiValue: displace_liqui_value,
  747. BloodAccess: blood_access,
  748. Ultrafiltration: ultrafiltration,
  749. BodyFluidOther: body_fluid_other,
  750. ReplacementTotal: replacement_total,
  751. TargetKtv: target_ktv,
  752. DialysisIrrigation: dialysis_irrigation,
  753. DialysisDialyszers: dialysis_dialyszers,
  754. HemodialysisPipelines: hemodialysis_pipelines,
  755. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  756. PunctureNeedle: puncture_needle,
  757. PunctureNeedleCount: puncture_needle_count,
  758. Epo: epo,
  759. EpoCount: epo_count,
  760. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  761. }
  762. err := service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  763. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  764. redis := service.RedisClient()
  765. //清空key 值
  766. redis.Set(key, "", time.Second)
  767. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  768. //清空key 值
  769. redis.Set(keyOne, "", time.Second)
  770. defer redis.Close()
  771. if err == nil {
  772. c.ServeSuccessJSON(map[string]interface{}{
  773. "solution": &solution,
  774. "prescription": &prescription,
  775. })
  776. } else {
  777. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  778. }
  779. }
  780. func (c *DialysisApiController) PostDouleCheck() {
  781. id, _ := c.GetInt64("patient", 0)
  782. recordDateStr := c.GetString("record_date")
  783. checkTimeStr := c.GetString("check_time")
  784. firstCheckTimeStr := c.GetString("first_check_time")
  785. creater, _ := c.GetInt64("creater", 0)
  786. modifier, _ := c.GetInt64("modifier", 0)
  787. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  788. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  789. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  790. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  791. dialysis_item_desc := c.GetString("dialysis_item_desc")
  792. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  793. vascular_access_desc := c.GetString("vascular_access_desc")
  794. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  795. collator, _ := c.GetInt64("collator", 0)
  796. if id <= 0 {
  797. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  798. return
  799. }
  800. adminUserInfo := c.GetAdminUserInfo()
  801. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  802. if patient.ID == 0 {
  803. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  804. return
  805. }
  806. if len(recordDateStr) == 0 {
  807. recordDateStr = time.Now().Format("2006-01-02")
  808. }
  809. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  810. if parseDateErr != nil {
  811. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  812. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  813. return
  814. }
  815. var checkDate int64
  816. if len(checkTimeStr) == 0 {
  817. //checkTimeStr = time.Now().Format("2006-01-02 15:04")
  818. checkDate = 0
  819. } else {
  820. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", checkTimeStr)
  821. checkDate = checkDateUnix.Unix()
  822. }
  823. var firstCheckTimeDate int64
  824. if len(firstCheckTimeStr) == 0 {
  825. //firstCheckTimeStr = time.Now().Format("2006-01-02 15:04")
  826. firstCheckTimeDate = 0
  827. } else {
  828. firstCheckTimeDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", firstCheckTimeStr)
  829. firstCheckTimeDate = firstCheckTimeDateUnix.Unix()
  830. }
  831. doubleCheck := models.DoubleCheck{
  832. UserOrgId: adminUserInfo.CurrentOrgId,
  833. PatientId: id,
  834. DialysisItemCheck: dialysis_item_check,
  835. DialysisParameterCheck: dialysis_parameter_check,
  836. VascularAccessVerification: vascular_access_verification,
  837. PipelineConnectionCheck: pipeline_connection_check,
  838. DialysisItemDesc: dialysis_item_desc,
  839. DialysisParameterDesc: dialysis_parameter_desc,
  840. VascularAccessDesc: vascular_access_desc,
  841. PipelineConnectionDesc: pipeline_connection_desc,
  842. Collator: collator,
  843. Status: 1,
  844. CreatedTime: time.Now().Unix(),
  845. UpdatedTime: time.Now().Unix(),
  846. CheckDate: recordDate.Unix(),
  847. }
  848. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  849. if check.ID == 0 { //新增
  850. doubleCheck.FirstCheckTime = firstCheckTimeDate
  851. doubleCheck.CheckTime = checkDate
  852. doubleCheck.Creater = creater
  853. doubleCheck.Modifier = modifier
  854. err := service.AddSigleDoubleCheck(&doubleCheck)
  855. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  856. redis := service.RedisClient()
  857. defer redis.Close()
  858. //清空key 值
  859. redis.Set(key, "", time.Second)
  860. if err == nil {
  861. c.ServeSuccessJSON(map[string]interface{}{
  862. "doubleCheck": doubleCheck,
  863. })
  864. } else {
  865. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  866. }
  867. } else { //修改
  868. doubleCheck.FirstCheckTime = firstCheckTimeDate
  869. doubleCheck.CheckTime = checkDate
  870. doubleCheck.Creater = creater
  871. doubleCheck.Modifier = modifier
  872. doubleCheck.CreatedTime = check.CreatedTime
  873. doubleCheck.UpdatedTime = time.Now().Unix()
  874. doubleCheck.ID = check.ID
  875. err := service.UpdateDoubleCheck(&doubleCheck)
  876. if err == nil {
  877. c.ServeSuccessJSON(map[string]interface{}{
  878. "doubleCheck": doubleCheck,
  879. })
  880. } else {
  881. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  882. }
  883. }
  884. }
  885. func (c *DialysisApiController) PostReceiveTreatmentAsses() {
  886. id, _ := c.GetInt64("patient", 0)
  887. recordDateStr := c.GetString("record_date")
  888. way, _ := c.GetInt64("way", 0)
  889. consciousness, _ := c.GetInt64("consciousness", 0)
  890. appetite, _ := c.GetInt64("appetite", 0)
  891. condition, _ := c.GetInt64("condition", 0)
  892. posture, _ := c.GetInt64("posture")
  893. score := c.GetString("score")
  894. sick_condition, _ := c.GetInt64("sick_condition", 0)
  895. danger_level, _ := c.GetInt64("danger_level", 0)
  896. intake, _ := c.GetInt64("intake", 0)
  897. nutrition, _ := c.GetInt64("nutrition", 0)
  898. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  899. psychological_assessment_other := c.GetString("psychological_assessment_other")
  900. sick_condition_other := c.GetString("sick_condition_other")
  901. //precaution, _ := c.GetInt64("precaution", 0)
  902. precaution := c.GetString("precaution")
  903. precaution_other := c.GetString("precaution_other")
  904. psychological_other := c.GetString("psychological_other")
  905. admission_number := c.GetString("admission_number")
  906. tumble, _ := c.GetInt64("tumble")
  907. if id <= 0 {
  908. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  909. return
  910. }
  911. adminUserInfo := c.GetAdminUserInfo()
  912. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  913. if patient.ID == 0 {
  914. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  915. return
  916. }
  917. if len(recordDateStr) == 0 {
  918. recordDateStr = time.Now().Format("2006-01-02")
  919. }
  920. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  921. if parseDateErr != nil {
  922. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  923. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  924. return
  925. }
  926. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  927. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  928. UserOrgId: adminUserInfo.CurrentOrgId,
  929. PatientId: id,
  930. RecordDate: recordDate.Unix(),
  931. Way: way,
  932. Consciousness: consciousness,
  933. Appetite: appetite,
  934. Condition: condition,
  935. SickCondition: sick_condition,
  936. DangerLevel: danger_level,
  937. Intake: intake,
  938. Nutrition: nutrition,
  939. PsychologicalAssessment: psychological_assessment,
  940. PsychologicalAssessmentOther: psychological_assessment_other,
  941. SickConditionOther: sick_condition_other,
  942. Posture: posture,
  943. CreatedTime: time.Now().Unix(),
  944. UpdateTime: time.Now().Unix(),
  945. Status: 1,
  946. Score: score,
  947. Precaution: precaution,
  948. PrecautionOther: precaution_other,
  949. PsychologicalOther: psychological_other,
  950. AdmissionNumber: admission_number,
  951. Tumble: tumble,
  952. }
  953. if receiveTreatment.ID == 0 { //新增
  954. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  955. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  956. if err == nil {
  957. c.ServeSuccessJSON(map[string]interface{}{
  958. "receiveTreatmentAsses": receiveTreatmentAsses,
  959. })
  960. } else {
  961. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  962. }
  963. } else { //修改
  964. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  965. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  966. // if getPermissionErr != nil {
  967. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  968. // return
  969. // } else if headNursePermission == nil {
  970. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  971. // return
  972. // }
  973. //}
  974. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  975. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  976. receiveTreatmentAsses.UpdateTime = time.Now().Unix()
  977. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  978. receiveTreatmentAsses.ID = receiveTreatment.ID
  979. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  980. if err == nil {
  981. c.ServeSuccessJSON(map[string]interface{}{
  982. "receiveTreatmentAsses": receiveTreatmentAsses,
  983. })
  984. } else {
  985. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  986. }
  987. }
  988. }
  989. func (c *DialysisApiController) PostAssessmentAfterDislysis() {
  990. patient, _ := c.GetInt64("patient", 0)
  991. recordDateStr := c.GetString("record_date")
  992. fmt.Println(recordDateStr)
  993. if patient <= 0 {
  994. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  995. return
  996. }
  997. adminUserInfo := c.GetAdminUserInfo()
  998. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  999. if patientInfo.ID == 0 {
  1000. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1001. return
  1002. }
  1003. if len(recordDateStr) == 0 {
  1004. recordDateStr = time.Now().Format("2006-01-02")
  1005. }
  1006. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1007. if parseDateErr != nil {
  1008. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1009. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1010. return
  1011. }
  1012. // data := make(map[string]interface{}, 0)
  1013. var data models.AssessmentAfterDislysis
  1014. var err error
  1015. err = json.Unmarshal(c.Ctx.Input.RequestBody, &data)
  1016. fmt.Println(err)
  1017. if err != nil {
  1018. c.ErrorLog("数据解析错误:%v", err)
  1019. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1020. return
  1021. }
  1022. assessment, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1023. assessment.DialysisOrderId = data.DialysisOrderId
  1024. assessment.Evaluator = adminUserInfo.AdminUser.Id
  1025. assessment.Status = 1
  1026. assessment.WeightAfter = data.WeightAfter
  1027. assessment.WeightLoss = data.WeightLoss
  1028. assessment.Temperature = data.Temperature
  1029. assessment.SystolicBloodPressure = data.SystolicBloodPressure
  1030. assessment.DiastolicBloodPressure = data.DiastolicBloodPressure
  1031. assessment.PulseFrequency = data.PulseFrequency
  1032. assessment.ActualUltrafiltration = data.ActualUltrafiltration
  1033. assessment.ActualDisplacement = data.ActualDisplacement
  1034. assessment.ActualTreatmentHour = data.ActualTreatmentHour
  1035. assessment.ActualTreatmentMinute = data.ActualTreatmentMinute
  1036. assessment.Cruor = data.Cruor
  1037. assessment.SymptomAfterDialysis = data.SymptomAfterDialysis
  1038. assessment.DialysisIntakes = data.DialysisIntakes
  1039. assessment.InternalFistula = data.InternalFistula
  1040. assessment.BloodAccessPartId = data.BloodAccessPartId
  1041. assessment.BloodAccessPartOperaId = data.BloodAccessPartOperaId
  1042. assessment.Catheter = data.Catheter
  1043. assessment.Complication = data.Complication
  1044. assessment.PuncturePointOozingBlood = data.PuncturePointOozingBlood
  1045. assessment.PuncturePointHaematoma = data.PuncturePointHaematoma
  1046. assessment.InternalFistulaTremorAc = data.InternalFistulaTremorAc
  1047. assessment.PatientGose = data.PatientGose
  1048. assessment.InpatientDepartment = data.InpatientDepartment
  1049. assessment.ObservationContent = data.ObservationContent
  1050. assessment.ObservationContentOther = data.ObservationContentOther
  1051. assessment.Remark = data.Remark
  1052. assessment.BreathingRate = data.BreathingRate
  1053. assessment.DialysisProcess = data.DialysisProcess
  1054. assessment.InAdvanceMinute = data.InAdvanceMinute
  1055. assessment.InAdvanceReasonOther = data.InAdvanceReasonOther
  1056. assessment.InAdvanceReason = data.InAdvanceReason
  1057. assessment.HemostasisOpera = data.HemostasisOpera
  1058. assessment.HemostasisMinute = data.HemostasisMinute
  1059. assessment.TremorNoise = data.TremorNoise
  1060. assessment.DisequilibriumSyndrome = data.DisequilibriumSyndrome
  1061. assessment.DisequilibriumSyndromeOption = data.DisequilibriumSyndromeOption
  1062. assessment.ArterialTube = data.ArterialTube
  1063. assessment.IntravenousTube = data.IntravenousTube
  1064. assessment.DialysisIntakesUnit = data.DialysisIntakesUnit
  1065. assessment.Dialyzer = data.Dialyzer
  1066. assessment.IsEat = data.IsEat
  1067. assessment.CvcA = data.CvcA
  1068. assessment.CvcV = data.CvcV
  1069. assessment.Channel = data.Channel
  1070. assessment.ReturnBlood = data.ReturnBlood
  1071. assessment.RehydrationVolume = data.RehydrationVolume
  1072. assessment.DialysisDuring = data.DialysisDuring
  1073. assessment.StrokeVolume = data.StrokeVolume
  1074. assessment.BloodFlow = data.BloodFlow
  1075. assessment.SealingFluidDispose = data.SealingFluidDispose
  1076. assessment.SealingFluidSpecial = data.SealingFluidSpecial
  1077. assessment.DosageOfAnticoagulants = data.DosageOfAnticoagulants
  1078. assessment.SupineSystolicBloodPressure = data.SupineSystolicBloodPressure
  1079. assessment.SettingPressure = data.SettingPressure
  1080. assessment.SupineDiastolicBloodPressure = data.SupineDiastolicBloodPressure
  1081. assessment.DiastolicPressure = data.DiastolicPressure
  1082. assessment.AdditionalWeight = data.AdditionalWeight
  1083. assessment.OtherComplication = data.OtherComplication
  1084. assessment.Ktv = data.Ktv
  1085. assessment.Urr = data.Urr
  1086. assessment.Hypertenison = data.Hypertenison
  1087. assessment.Hypopiesia = data.Hypopiesia
  1088. assessment.LeaveOfficeMethod = data.LeaveOfficeMethod
  1089. assessment.Lapse = data.Lapse
  1090. assessment.Consciousness = data.Consciousness
  1091. assessment.Fallrisk = data.Fallrisk
  1092. assessment.MachineRun = data.MachineRun
  1093. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1094. if assessment.ID > 0 {
  1095. if appRole.UserType == 2 || appRole.UserType == 1 {
  1096. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1097. assessment.AssessmentTime = time.Now().Unix()
  1098. } else {
  1099. if assessment.Creater == 0 {
  1100. assessment.Modifier = adminUserInfo.AdminUser.Id
  1101. assessment.Creater = adminUserInfo.AdminUser.Id
  1102. } else {
  1103. assessment.Modifier = adminUserInfo.AdminUser.Id
  1104. }
  1105. }
  1106. assessment.UpdatedTime = time.Now().Unix()
  1107. err = service.UpdateAssessmentAfterDislysisRecord(&assessment)
  1108. } else {
  1109. if appRole.UserType == 2 || appRole.UserType == 1 {
  1110. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1111. assessment.AssessmentTime = time.Now().Unix()
  1112. } else {
  1113. assessment.Creater = adminUserInfo.AdminUser.Id
  1114. }
  1115. assessment.CreatedTime = time.Now().Unix()
  1116. assessment.UpdatedTime = time.Now().Unix()
  1117. assessment.UserOrgId = adminUserInfo.CurrentOrgId
  1118. assessment.PatientId = patient
  1119. assessment.AssessmentDate = recordDate.Unix()
  1120. err = service.AddSigleAssessmentAfterDislysisRecord(&assessment)
  1121. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1122. redis := service.RedisClient()
  1123. defer redis.Close()
  1124. //清空key 值
  1125. redis.Set(key, "", time.Second)
  1126. }
  1127. if err != nil {
  1128. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1129. return
  1130. }
  1131. c.ServeSuccessJSON(map[string]interface{}{
  1132. "AssessmentAfterDislysis": &assessment,
  1133. })
  1134. }
  1135. func (c *DialysisApiController) PostAssessmentBeforeDislysis() {
  1136. patient, _ := c.GetInt64("patient", 0)
  1137. recordDateStr := c.GetString("record_date")
  1138. if patient <= 0 {
  1139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1140. return
  1141. }
  1142. adminUserInfo := c.GetAdminUserInfo()
  1143. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1144. if patientInfo.ID == 0 {
  1145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1146. return
  1147. }
  1148. if len(recordDateStr) == 0 {
  1149. recordDateStr = time.Now().Format("2006-01-02")
  1150. }
  1151. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1152. if parseDateErr != nil {
  1153. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1155. return
  1156. }
  1157. weight_before, _ := c.GetFloat("weight_before", 0)
  1158. dry_weight, _ := c.GetFloat("dry_weight", 0)
  1159. additional_weight, _ := c.GetFloat("additional_weight", 0)
  1160. temperature, _ := c.GetFloat("temperature", 0)
  1161. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1162. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1163. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1164. last_post_dialysis := c.GetString("last_post_dialysis")
  1165. dialysis_interphase := c.GetString("dialysis_interphase")
  1166. symptom_before_dialysis := c.GetString("symptom_before_dialysis")
  1167. bloodAccessPartOperaId, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1168. //bloodAccessPartId, _ := c.GetInt64("blood_access_part_id", 0)
  1169. bloodAccessPartId := c.GetString("blood_access_part_id")
  1170. internalFistula := c.GetString("internal_fistula")
  1171. internal_fistula_skin := c.GetString("internal_fistula_skin")
  1172. catheter := c.GetString("catheter")
  1173. catheter_bend, _ := c.GetInt("catheter_bend")
  1174. complication := c.GetString("complication")
  1175. is_hemorrhage, _ := c.GetInt64("is_hemorrhage", 0)
  1176. hemorrhage := c.GetString("hemorrhage")
  1177. hemorrhage_other := c.GetString("hemorrhage_other")
  1178. remark := c.GetString("remark")
  1179. puncture_method := c.GetString("puncture_method")
  1180. dialysis_count := c.GetString("dialysis_count")
  1181. emergency_treatment, _ := c.GetInt64("emergency_treatment", 0)
  1182. emergency_treatment_other := c.GetString("emergency_treatment_other")
  1183. ductus_arantii := c.GetString("ductus_arantii")
  1184. venous_catheterization_part_other := c.GetString("venous_catheterization_part_other")
  1185. venous_catheterization_part, _ := c.GetInt64("venous_catheterization_part", 0)
  1186. venous_catheterization, _ := c.GetInt64("venous_catheterization", 0)
  1187. //puncture_way, _ := c.GetInt64("puncture_way", 0)
  1188. puncture_way := c.GetString("puncture_way")
  1189. blood_access_noise, _ := c.GetInt64("blood_access_noise", 0)
  1190. internal_fistula_other := c.GetString("internal_fistula_other")
  1191. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  1192. breathing_rate, _ := c.GetFloat("breathing_rate", 0)
  1193. is_infect, _ := c.GetInt64("is_infect", 0)
  1194. exposed, _ := c.GetFloat("exposed", 0)
  1195. //skin, _ := c.GetInt64("skin", 0)
  1196. skin := c.GetString("skin")
  1197. skin_other := c.GetString("skin_other")
  1198. infect_other := c.GetString("infect_other")
  1199. ductus_arantii_other := c.GetString("ductus_arantii_other")
  1200. machine_type := c.GetString("machine_type")
  1201. puncture_needle := c.GetString("puncture_needle")
  1202. humor_excessive_symptom := c.GetString("humor_excessive_symptom")
  1203. phinholing := c.GetString("pinholing")
  1204. catheter_suture := c.GetString("catheter_suture")
  1205. catheter_suture_other := c.GetString("catheter_suture_other")
  1206. edema := c.GetString("edema")
  1207. urine_volume, _ := c.GetFloat("urine_volume", 0)
  1208. special_treatment := c.GetString("special_treatment")
  1209. catheter_maintenance := c.GetString("catheter_maintenance")
  1210. thrombusType := c.GetString("thromubus_type")
  1211. thrombusInt, _ := strconv.ParseInt(thrombusType, 10, 64)
  1212. thrombus_a := c.GetString("thromubus_a")
  1213. thrombus_av := c.GetString("thrombus_av")
  1214. thrombus_v := c.GetString("thromubus_v")
  1215. dehydration := c.GetString("dehydration")
  1216. pre_dialysis_drugs := c.GetString("pre_dialysis_drugs")
  1217. period, _ := c.GetInt64("period")
  1218. estimated_food_intake := c.GetString("estimated_food_intake")
  1219. blood_pressure_during_dialysis := c.GetString("blood_pressure_during_dialysis")
  1220. assessmentBeforeDislysis := models.PredialysisEvaluation{
  1221. DialysisCount: dialysis_count,
  1222. EmergencyTreatment: emergency_treatment,
  1223. EmergencyTreatmentOther: emergency_treatment_other,
  1224. DuctusArantii: ductus_arantii,
  1225. VenousCatheterization: venous_catheterization,
  1226. VenousCatheterizationPart: venous_catheterization_part,
  1227. VenousCatheterizationPartOther: venous_catheterization_part_other,
  1228. PunctureWay: puncture_way,
  1229. BloodAccessInternalFistula: blood_access_internal_fistula,
  1230. BloodAccessNoise: blood_access_noise,
  1231. InternalFistulaOther: internal_fistula_other,
  1232. Evaluator: adminUserInfo.AdminUser.Id,
  1233. UserOrgId: adminUserInfo.CurrentOrgId,
  1234. PatientId: patient,
  1235. AssessmentDate: recordDate.Unix(),
  1236. Temperature: temperature,
  1237. PulseFrequency: pulse_frequency,
  1238. SystolicBloodPressure: systolic_blood_pressure,
  1239. DiastolicBloodPressure: diastolic_blood_pressure,
  1240. WeightBefore: weight_before,
  1241. DryWeight: dry_weight,
  1242. AdditionalWeight: additional_weight,
  1243. DialysisInterphase: dialysis_interphase,
  1244. LastPostDialysis: last_post_dialysis,
  1245. SymptomBeforeDialysis: symptom_before_dialysis,
  1246. InternalFistula: internalFistula,
  1247. InternalFistulaSkin: internal_fistula_skin,
  1248. Catheter: catheter,
  1249. CatheterBend: catheter_bend,
  1250. Complication: complication,
  1251. CreatedTime: time.Now().Unix(),
  1252. Status: 1,
  1253. Remark: remark,
  1254. IsHemorrhage: is_hemorrhage,
  1255. Hemorrhage: hemorrhage,
  1256. HemorrhageOther: hemorrhage_other,
  1257. BloodAccessPartId: bloodAccessPartId,
  1258. BloodAccessPartOperaId: bloodAccessPartOperaId,
  1259. PunctureMethod: puncture_method,
  1260. BreathingRate: breathing_rate,
  1261. IsInfect: is_infect,
  1262. Exposed: exposed,
  1263. Skin: skin,
  1264. SkinOther: skin_other,
  1265. InfectOther: infect_other,
  1266. DuctusArantiiOther: ductus_arantii_other,
  1267. MachineType: machine_type,
  1268. PunctureNeedle: puncture_needle,
  1269. HumorExcessiveSymptom: humor_excessive_symptom,
  1270. Phinholing: phinholing,
  1271. CatheterSuture: catheter_suture,
  1272. CatheterSutureOther: catheter_suture_other,
  1273. Edema: edema,
  1274. UrineVolume: urine_volume,
  1275. SpecialTreatment: special_treatment,
  1276. CatheterMaintenance: catheter_maintenance,
  1277. ThromubusType: thrombusInt,
  1278. ThrombusAv: thrombus_av,
  1279. ThromubusA: thrombus_a,
  1280. ThromubusV: thrombus_v,
  1281. Dehydration: dehydration,
  1282. PreDialysisDrugs: pre_dialysis_drugs,
  1283. Period: period,
  1284. EstimatedFoodIntake: estimated_food_intake,
  1285. BloodPressureDuringDialysis: blood_pressure_during_dialysis,
  1286. }
  1287. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1288. _, evaluation := service.FindPredialysisEvaluationByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1289. if evaluation.ID == 0 { //新增
  1290. if appRole.UserType == 2 || appRole.UserType == 1 {
  1291. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1292. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  1293. } else {
  1294. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  1295. }
  1296. err := service.AddSigleAssessmentBeforeDislysisRecord(&assessmentBeforeDislysis)
  1297. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1298. redis := service.RedisClient()
  1299. defer redis.Close()
  1300. //清空key 值
  1301. redis.Set(key, "", time.Second)
  1302. if err == nil {
  1303. c.ServeSuccessJSON(map[string]interface{}{
  1304. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  1305. })
  1306. } else {
  1307. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1308. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1309. }
  1310. } else { //修改
  1311. //if appRole.UserType == 3 {
  1312. // if evaluation.Creater != adminUserInfo.AdminUser.Id && evaluation.Creater != 0 {
  1313. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1314. // if getPermissionErr != nil {
  1315. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1316. // return
  1317. // } else if headNursePermission == nil {
  1318. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1319. // return
  1320. // }
  1321. // }
  1322. //}
  1323. if appRole.UserType == 2 || appRole.UserType == 1 {
  1324. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1325. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  1326. } else {
  1327. if evaluation.Creater == 0 {
  1328. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  1329. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  1330. } else {
  1331. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  1332. }
  1333. }
  1334. assessmentBeforeDislysis.UpdatedTime = time.Now().Unix()
  1335. assessmentBeforeDislysis.ID = evaluation.ID
  1336. assessmentBeforeDislysis.CreatedTime = evaluation.CreatedTime
  1337. //
  1338. //新增逻辑
  1339. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  1340. var dewater_amount float64
  1341. dewater_amount = 0
  1342. if evaluation.DryWeight > 0 {
  1343. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  1344. if templateInfo.TemplateId == 17 || templateInfo.TemplateId == 22 || templateInfo.TemplateId == 21 || templateInfo.TemplateId == 34 {
  1345. dewater_amount = dewater_amount * 1000
  1346. }
  1347. if dewater_amount <= 0 {
  1348. dewater_amount = 0
  1349. }
  1350. } else {
  1351. dewater_amount = 0
  1352. }
  1353. // 计算透析处方的相关超滤量
  1354. schedual, _ := service.MobileGetSchedualDetail(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1355. var lastDialysisPrescribe *models.DialysisPrescription
  1356. var dialysisSolution *models.DialysisSolution
  1357. var dialysisPrescribe *models.DialysisPrescription
  1358. var mode_id int64
  1359. if schedual != nil {
  1360. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeId(adminUserInfo.CurrentOrgId, patient, recordDate.Unix(), schedual.ModeId)
  1361. if dialysisPrescribe == nil {
  1362. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1363. }
  1364. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeId(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  1365. // 获取透析模版
  1366. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  1367. mode_id = schedual.ModeId
  1368. } else {
  1369. //lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribe(adminUserInfo.Org.Id, id,schedual.ModeId)
  1370. // 获取透析模版
  1371. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1372. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.CurrentOrgId, patient)
  1373. if dialysisPrescribe == nil && dialysisSolution != nil {
  1374. mode_id = dialysisSolution.ModeId
  1375. }
  1376. if dialysisPrescribe == nil && dialysisSolution == nil {
  1377. mode_id = 0
  1378. }
  1379. }
  1380. // 插入透析处方
  1381. if dialysisPrescribe == nil && dialysisSolution != nil {
  1382. var newprescribe models.DialysisPrescription
  1383. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  1384. newprescribe.PatientId = dialysisSolution.PatientId
  1385. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  1386. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  1387. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  1388. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  1389. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  1390. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  1391. newprescribe.ModeId = dialysisSolution.ModeId
  1392. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  1393. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  1394. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  1395. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  1396. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  1397. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  1398. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  1399. newprescribe.Glucose = dialysisSolution.Glucose
  1400. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  1401. newprescribe.Kalium = dialysisSolution.Kalium
  1402. newprescribe.Sodium = dialysisSolution.Sodium
  1403. newprescribe.Calcium = dialysisSolution.Calcium
  1404. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  1405. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  1406. newprescribe.Conductivity = dialysisSolution.Conductivity
  1407. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  1408. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  1409. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  1410. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  1411. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  1412. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  1413. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  1414. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  1415. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  1416. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  1417. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  1418. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  1419. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  1420. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  1421. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  1422. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  1423. newprescribe.CreatedTime = time.Now().Unix()
  1424. newprescribe.UpdatedTime = time.Now().Unix()
  1425. newprescribe.RecordDate = recordDate.Unix()
  1426. newprescribe.DewaterAmount = dewater_amount
  1427. newprescribe.TargetUltrafiltration = dewater_amount
  1428. newprescribe.Status = 1
  1429. err := service.AddSigleRecord(&newprescribe)
  1430. if err != nil {
  1431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1432. }
  1433. }
  1434. if dialysisPrescribe == nil && dialysisSolution == nil {
  1435. if lastDialysisPrescribe != nil {
  1436. var newprescribe models.DialysisPrescription
  1437. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  1438. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  1439. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  1440. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  1441. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  1442. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  1443. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  1444. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  1445. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  1446. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  1447. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  1448. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  1449. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  1450. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  1451. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  1452. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  1453. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  1454. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  1455. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  1456. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  1457. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  1458. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  1459. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  1460. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  1461. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  1462. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  1463. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  1464. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  1465. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  1466. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  1467. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  1468. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  1469. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  1470. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  1471. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  1472. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  1473. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  1474. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  1475. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  1476. newprescribe.CreatedTime = time.Now().Unix()
  1477. newprescribe.UpdatedTime = time.Now().Unix()
  1478. newprescribe.RecordDate = recordDate.Unix()
  1479. newprescribe.DewaterAmount = dewater_amount
  1480. newprescribe.TargetUltrafiltration = dewater_amount
  1481. newprescribe.Status = 1
  1482. err := service.AddSigleRecord(&newprescribe)
  1483. if err != nil {
  1484. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1485. }
  1486. } else {
  1487. var newprescribe models.DialysisPrescription
  1488. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  1489. newprescribe.PatientId = patient
  1490. newprescribe.ModeId = mode_id
  1491. newprescribe.CreatedTime = time.Now().Unix()
  1492. newprescribe.UpdatedTime = time.Now().Unix()
  1493. newprescribe.RecordDate = recordDate.Unix()
  1494. newprescribe.DewaterAmount = dewater_amount
  1495. newprescribe.TargetUltrafiltration = dewater_amount
  1496. newprescribe.Status = 1
  1497. err := service.AddSigleRecord(&newprescribe)
  1498. if err != nil {
  1499. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1500. }
  1501. }
  1502. }
  1503. err := service.UpadatePredialysisEvaluation(&assessmentBeforeDislysis)
  1504. if err == nil {
  1505. c.ServeSuccessJSON(map[string]interface{}{
  1506. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  1507. })
  1508. } else {
  1509. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1510. }
  1511. }
  1512. }
  1513. func (c *DialysisApiController) PostTreatmentSummary() {
  1514. patient, _ := c.GetInt64("patient", 0)
  1515. recordDateStr := c.GetString("record_date")
  1516. if patient <= 0 {
  1517. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1518. return
  1519. }
  1520. adminUserInfo := c.GetAdminUserInfo()
  1521. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1522. if patientInfo.ID == 0 {
  1523. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1524. return
  1525. }
  1526. if len(recordDateStr) == 0 {
  1527. recordDateStr = time.Now().Format("2006-01-02")
  1528. }
  1529. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1530. if parseDateErr != nil {
  1531. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1532. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1533. return
  1534. }
  1535. mission := c.GetString("mission")
  1536. dialysis_summary := c.GetString("dialysis_summary")
  1537. nursingRecord := c.GetString("nursing_record")
  1538. specialRecord := c.GetString("special_record")
  1539. sj_nurse := adminUserInfo.AdminUser.Id
  1540. zl_nurse := adminUserInfo.AdminUser.Id
  1541. hd_nurse := adminUserInfo.AdminUser.Id
  1542. xj_nurse := adminUserInfo.AdminUser.Id
  1543. zl_doctor := adminUserInfo.AdminUser.Id
  1544. treatmentSummary := models.TreatmentSummary{
  1545. UserOrgId: adminUserInfo.CurrentOrgId,
  1546. PatientId: patient,
  1547. AssessmentDate: recordDate.Unix(),
  1548. Mission: mission,
  1549. DialysisSummary: dialysis_summary,
  1550. SjNurse: sj_nurse,
  1551. ZlNurse: zl_nurse,
  1552. HdNurse: hd_nurse,
  1553. XjNurse: xj_nurse,
  1554. ZlDoctor: zl_doctor,
  1555. Status: 1,
  1556. CreatedTime: time.Now().Unix(),
  1557. NursingRecord: nursingRecord,
  1558. SpecialRecord: specialRecord,
  1559. }
  1560. _, tempTreatmentSummary := service.FindTreatmentSummaryByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1561. if tempTreatmentSummary.ID == 0 { //新增
  1562. treatmentSummary.Creater = adminUserInfo.AdminUser.Id
  1563. err := service.AddSigleSummaryRecord(&treatmentSummary)
  1564. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  1565. redis := service.RedisClient()
  1566. defer redis.Close()
  1567. //清空key 值
  1568. redis.Set(key, "", time.Second)
  1569. if err == nil {
  1570. c.ServeSuccessJSON(map[string]interface{}{
  1571. "summary": treatmentSummary,
  1572. })
  1573. } else {
  1574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1575. }
  1576. } else { //修改
  1577. //if tempTreatmentSummary.Creater != adminUserInfo.AdminUser.Id {
  1578. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1579. // if getPermissionErr != nil {
  1580. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1581. // return
  1582. // } else if headNursePermission == nil {
  1583. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1584. // return
  1585. // }
  1586. //}
  1587. treatmentSummary.Creater = tempTreatmentSummary.Creater
  1588. treatmentSummary.CreatedTime = tempTreatmentSummary.CreatedTime
  1589. treatmentSummary.UpdatedTime = time.Now().Unix()
  1590. treatmentSummary.Modifier = adminUserInfo.AdminUser.Id
  1591. treatmentSummary.ID = tempTreatmentSummary.ID
  1592. err := service.UpdateSummeRecord(&treatmentSummary)
  1593. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  1594. //清空key 值
  1595. redis := service.RedisClient()
  1596. redis.Set(key, "", time.Second)
  1597. defer redis.Close()
  1598. if err == nil {
  1599. c.ServeSuccessJSON(map[string]interface{}{
  1600. "summary": treatmentSummary,
  1601. })
  1602. } else {
  1603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1604. }
  1605. }
  1606. }
  1607. func (c *DialysisApiController) GetDeviceList() {
  1608. adminUserInfo := c.GetAdminUserInfo()
  1609. device, _ := service.FindAllDeviceInfo(adminUserInfo.CurrentOrgId)
  1610. c.ServeSuccessJSON(map[string]interface{}{
  1611. "device": device,
  1612. })
  1613. }
  1614. func (c *DialysisApiController) GetAllDeviceZone() {
  1615. adminUserInfo := c.GetAdminUserInfo()
  1616. err, zone := service.GetAllDeviceZone(adminUserInfo.CurrentOrgId)
  1617. dics, _, err := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
  1618. if err == nil {
  1619. c.ServeSuccessJSON(map[string]interface{}{
  1620. "zone": zone,
  1621. "dics": dics,
  1622. })
  1623. }
  1624. }
  1625. func (c *DialysisApiController) GetDialysisWatch() {
  1626. page, _ := c.GetInt64("page", 1)
  1627. limit, _ := c.GetInt64("limit", 10)
  1628. schedulType, _ := c.GetInt64("schedul_type", 0)
  1629. startTime, _ := c.GetInt64("schedul_time", 0)
  1630. partitionType, _ := c.GetInt64("partition_type", 0)
  1631. keywords := c.GetString("keywords")
  1632. adminUserInfo := c.GetAdminUserInfo()
  1633. if len(keywords) > 0 {
  1634. dialysisSchedule, err, total := service.GetDialysisWatchByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit)
  1635. //获取所有床位号
  1636. numberList, _ := service.GetAllDeviceNumberByList(adminUserInfo.CurrentOrgId)
  1637. //获取所有分区
  1638. //zoneList, _ := service.GetAllZoneByList(adminUserInfo.CurrentOrgId)
  1639. //获取透析处方
  1640. prescriptions, _ := service.GetAllPrescriptionByListTwo(adminUserInfo.CurrentOrgId, startTime)
  1641. //获取透前评估
  1642. assessmentBefores, _ := service.GetAllAssessmentBeforesByListThree(adminUserInfo.CurrentOrgId, startTime)
  1643. //获取上机
  1644. dialysisOrders, _ := service.GetAllDialysisOrdersByListThree(adminUserInfo.CurrentOrgId, startTime)
  1645. //获取透后
  1646. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListThree(adminUserInfo.CurrentOrgId, startTime)
  1647. //获取透后监测
  1648. monitorlist, _ := service.GetAllMonitorListThree(adminUserInfo.CurrentOrgId, startTime)
  1649. //获取所有的患者
  1650. patients, _ := service.GetAllPatientListByListThree(adminUserInfo.CurrentOrgId)
  1651. //获取所有透析模式
  1652. treatments, _ := service.GetAllTreatModeByList(adminUserInfo.CurrentOrgId)
  1653. for key, scheduals := range dialysisSchedule {
  1654. // 获取患者信息
  1655. for _, patient := range patients {
  1656. if scheduals.PatientId == patient.ID {
  1657. dialysisSchedule[key].MonitorPatients = patient
  1658. break
  1659. }
  1660. }
  1661. // 床位信息
  1662. for _, device := range numberList {
  1663. if scheduals.BedId == device.ID {
  1664. dialysisSchedule[key].DeviceNumber = device
  1665. break
  1666. }
  1667. }
  1668. // 医嘱信息
  1669. for _, prescription := range prescriptions {
  1670. if scheduals.PatientId == prescription.PatientId {
  1671. dialysisSchedule[key].Prescription = prescription
  1672. break
  1673. }
  1674. }
  1675. // 透前评估
  1676. for _, assessmentBefore := range assessmentBefores {
  1677. if scheduals.PatientId == assessmentBefore.PatientId {
  1678. dialysisSchedule[key].AssessmentBeforeDislysis = assessmentBefore
  1679. break
  1680. }
  1681. }
  1682. // 透析上下机
  1683. for _, dialysisOrder := range dialysisOrders {
  1684. if scheduals.PatientId == dialysisOrder.PatientId {
  1685. dialysisSchedule[key].DialysisOrder = dialysisOrder
  1686. break
  1687. }
  1688. }
  1689. records := make([]*models.MonitoringRecord, 0)
  1690. // 透析监测
  1691. for _, it := range monitorlist {
  1692. records := append(records, it)
  1693. if scheduals.PatientId == it.PatientId {
  1694. dialysisSchedule[key].MonitoringRecord = records
  1695. }
  1696. }
  1697. // 透后评估
  1698. for _, afterDislysis := range AssessmentAfterDislysis {
  1699. if scheduals.PatientId == afterDislysis.PatientId {
  1700. dialysisSchedule[key].AssessmentAfterDislysis = afterDislysis
  1701. break
  1702. }
  1703. }
  1704. //透析模式
  1705. for _, treatment := range treatments {
  1706. if scheduals.ModeId == treatment.ID {
  1707. dialysisSchedule[key].TreatmentMode = treatment
  1708. break
  1709. }
  1710. }
  1711. }
  1712. //获取所有床位号
  1713. if err == nil {
  1714. c.ServeSuccessJSON(map[string]interface{}{
  1715. "schedule": dialysisSchedule,
  1716. "total": total,
  1717. })
  1718. } else {
  1719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1720. }
  1721. } else {
  1722. dialysisSchedule, err, total := service.GetDialysisWatch(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit)
  1723. if err == nil {
  1724. c.ServeSuccessJSON(map[string]interface{}{
  1725. "schedule": dialysisSchedule,
  1726. "total": total,
  1727. })
  1728. } else {
  1729. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1730. }
  1731. }
  1732. }
  1733. func (c *DialysisApiController) GetSchedualPatientsInfo() {
  1734. patientId, _ := c.GetInt64("id", 0)
  1735. record_date, _ := c.GetInt64("record_date", 0)
  1736. adminUserInfo := c.GetAdminUserInfo()
  1737. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1738. var dialysisStatus int64
  1739. if dialysisOrder == nil { //没有透析记录
  1740. dialysisStatus = 0 //未透析
  1741. } else {
  1742. dialysisStatus = dialysisOrder.Stage
  1743. }
  1744. //用户基本信息
  1745. schedualPatientInfo, _ := service.FindPatientInfoById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1746. //接诊评估
  1747. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1748. //透前评估
  1749. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1750. //临时医嘱
  1751. DoctorAdvice, _ := service.FindDoctorAdviceById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1752. //双人核对
  1753. DoubleCheck, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1754. //透析监测
  1755. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientId, record_date)
  1756. //透后评估
  1757. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1758. //透析小结
  1759. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1760. //透析处方
  1761. dialysisPrescription, _ := service.FindPatientPrescribeById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1762. if dialysisPrescription.ID == 0 {
  1763. solution, _ := service.FindDialysisSolution(adminUserInfo.CurrentOrgId, patientId)
  1764. c.ServeSuccessJSON(map[string]interface{}{
  1765. "patientInfo": schedualPatientInfo,
  1766. "dialysisPrescription": solution,
  1767. "receiverTreatmentAccess": receiverTreatmentAccess,
  1768. "predialysisEvaluation": PredialysisEvaluation,
  1769. "doctorAdvice": DoctorAdvice,
  1770. "doubleCheck": DoubleCheck,
  1771. "assessmentAfterDislysis": AssessmentAfterDislysis,
  1772. "treatmentSummary": TreatmentSummary,
  1773. "monitorRecord": Record,
  1774. "dialysisStatus": dialysisStatus,
  1775. "dialysisOrder": dialysisOrder,
  1776. "isSolution": 1,
  1777. })
  1778. } else {
  1779. c.ServeSuccessJSON(map[string]interface{}{
  1780. "patientInfo": schedualPatientInfo,
  1781. "dialysisPrescription": dialysisPrescription,
  1782. "receiverTreatmentAccess": receiverTreatmentAccess,
  1783. "predialysisEvaluation": PredialysisEvaluation,
  1784. "doctorAdvice": DoctorAdvice,
  1785. "doubleCheck": DoubleCheck,
  1786. "assessmentAfterDislysis": AssessmentAfterDislysis,
  1787. "treatmentSummary": TreatmentSummary,
  1788. "monitorRecord": Record,
  1789. "dialysisStatus": dialysisStatus,
  1790. "dialysisOrder": dialysisOrder,
  1791. "isSolution": 2,
  1792. })
  1793. }
  1794. }
  1795. func (c *DialysisApiController) CreateDoctorAdvice() {
  1796. patient, _ := c.GetInt64("id", 0)
  1797. dialysis_id, _ := c.GetInt64("dialysis_id", 0)
  1798. record_date, _ := c.GetInt64("record_date", 0)
  1799. if patient <= 0 {
  1800. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1801. return
  1802. }
  1803. adminUserInfo := c.GetAdminUserInfo()
  1804. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1805. if patientInfo.ID == 0 {
  1806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1807. return
  1808. }
  1809. var advice models.DoctorAdvice
  1810. code, subAdivice := adviceFormDatas(&advice, c.Ctx.Input.RequestBody, "create")
  1811. if code > 0 {
  1812. c.ServeFailJSONWithSGJErrorCode(code)
  1813. return
  1814. }
  1815. if advice.ParentId > 0 {
  1816. old, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, advice.ParentId)
  1817. if old.ID == 0 || old.PatientId != patient {
  1818. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  1819. return
  1820. }
  1821. if old.StopState == 1 || old.ExecutionState == 1 {
  1822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  1823. return
  1824. }
  1825. if old.ParentId > 0 {
  1826. advice.ParentId = old.ParentId
  1827. }
  1828. advice.StartTime = old.StartTime
  1829. advice.AdviceDoctor = old.AdviceDoctor
  1830. advice.DeliveryWay = old.DeliveryWay
  1831. advice.ExecutionFrequency = old.ExecutionFrequency
  1832. }
  1833. advice.RecordDate = record_date
  1834. advice.DialysisOrderId = dialysis_id
  1835. advice.Status = 1
  1836. advice.CreatedTime = time.Now().Unix()
  1837. advice.UpdatedTime = time.Now().Unix()
  1838. advice.StopState = 2
  1839. advice.ExecutionState = 2
  1840. advice.AdviceType = 2
  1841. advice.UserOrgId = adminUserInfo.CurrentOrgId
  1842. advice.PatientId = patient
  1843. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  1844. err := service.CreateDoctorAdvice(&advice)
  1845. if err != nil {
  1846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  1847. return
  1848. }
  1849. for _, subAdvice := range subAdivice {
  1850. subAdvice.ParentId = advice.ID
  1851. subAdvice.PatientId = patient
  1852. subAdvice.RecordDate = record_date
  1853. subAdvice.CreatedTime = time.Now().Unix()
  1854. subAdvice.UpdatedTime = time.Now().Unix()
  1855. subAdvice.UserOrgId = adminUserInfo.CurrentOrgId
  1856. }
  1857. service.CreateSubDoctorAdvice(subAdivice)
  1858. _, subAdivices := service.FindAllSubDoctorAdvice(patient, advice.ID)
  1859. c.ServeSuccessJSON(map[string]interface{}{
  1860. "msg": "ok",
  1861. "advice": advice,
  1862. "subAdvice": subAdivices,
  1863. })
  1864. return
  1865. }
  1866. func (c *DialysisApiController) EditDoctorAdvice() {
  1867. patient, _ := c.GetInt64("patient", 0)
  1868. id, _ := c.GetInt64("id", 0)
  1869. parent_id, _ := c.GetInt64("parent_id", 0)
  1870. execution_time := c.GetString("execution_time")
  1871. // execution_staff, _ := c.GetInt64("execution_staff", 0)
  1872. // checker, _ := c.GetInt64("checker", 0)
  1873. if id <= 0 || patient <= 0 {
  1874. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1875. return
  1876. }
  1877. adminUserInfo := c.GetAdminUserInfo()
  1878. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1879. if advice.ID == 0 || advice.PatientId != patient {
  1880. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1881. return
  1882. }
  1883. if len(execution_time) <= 0 {
  1884. utils.ErrorLog("execution_time")
  1885. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1886. return
  1887. }
  1888. execution_staff := adminUserInfo.AdminUser.Id
  1889. checker := adminUserInfo.AdminUser.Id
  1890. timeLayout2 := "2006-01-02 15:04"
  1891. loc, _ := time.LoadLocation("Local")
  1892. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  1893. if errs != nil {
  1894. utils.ErrorLog(errs.Error())
  1895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1896. return
  1897. }
  1898. advices := models.DoctorAdvice{
  1899. ExecutionStaff: execution_staff,
  1900. ExecutionTime: theTime.Unix(),
  1901. Checker: checker,
  1902. UpdatedTime: time.Now().Unix(),
  1903. }
  1904. var err error
  1905. if parent_id > 0 {
  1906. err = service.ExceDoctorAdviceById(&advices, parent_id, patient)
  1907. } else {
  1908. err = service.ExceDoctorAdviceById(&advices, id, patient)
  1909. }
  1910. if err != nil {
  1911. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1912. return
  1913. }
  1914. c.ServeSuccessJSON(map[string]interface{}{
  1915. "msg": "ok",
  1916. "advice": advice,
  1917. })
  1918. return
  1919. }
  1920. func (c *DialysisApiController) GetDoctorAdvice() {
  1921. patient, _ := c.GetInt64("patient_id", 0)
  1922. parent_id, _ := c.GetInt64("parent_id", 0)
  1923. adviceId, _ := c.GetInt64("id", 0)
  1924. if patient <= 0 {
  1925. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1926. return
  1927. }
  1928. dminUserInfo := c.GetAdminUserInfo()
  1929. patientInfo, _ := service.FindPatientById(dminUserInfo.CurrentOrgId, patient)
  1930. if patientInfo.ID == 0 {
  1931. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1932. return
  1933. }
  1934. var subAdvice []*models.DoctorAdvice
  1935. var advice models.DoctorAdvice
  1936. if parent_id > 0 {
  1937. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, parent_id)
  1938. if advice.ID == 0 || advice.PatientId != patient {
  1939. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  1940. return
  1941. }
  1942. subAdvice = service.FindSubAdivceById(patient, parent_id)
  1943. } else {
  1944. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, adviceId)
  1945. if advice.ID == 0 || advice.PatientId != patient {
  1946. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  1947. return
  1948. }
  1949. subAdvice = service.FindSubAdivceById(patient, adviceId)
  1950. }
  1951. c.ServeSuccessJSON(map[string]interface{}{
  1952. "msg": "ok",
  1953. "advice": advice,
  1954. "subAdvice": subAdvice,
  1955. })
  1956. }
  1957. func (this *DialysisApiController) DelMonitor() {
  1958. recordID, _ := this.GetInt64("record_id")
  1959. patientID, _ := this.GetInt64("patient_id")
  1960. if recordID <= 0 || patientID <= 0 {
  1961. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1962. return
  1963. }
  1964. adminInfo := this.GetAdminUserInfo()
  1965. patient, getPatientErr := service.MobileGetPatientById(adminInfo.CurrentOrgId, patientID)
  1966. if getPatientErr != nil {
  1967. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  1968. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1969. return
  1970. } else if patient == nil {
  1971. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1972. return
  1973. }
  1974. monitor, getMonitorErr := service.GetMonitor(adminInfo.CurrentOrgId, patientID, recordID)
  1975. if getMonitorErr != nil {
  1976. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1977. return
  1978. }
  1979. //if monitor != nil {
  1980. // if monitor.MonitoringNurse != adminInfo.AdminUser.Id {
  1981. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminInfo.CurrentOrgId, adminInfo.CurrentAppId, adminInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1982. // if getPermissionErr != nil {
  1983. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1984. // return
  1985. // } else if headNursePermission == nil {
  1986. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1987. // return
  1988. // }
  1989. // }
  1990. //}
  1991. err := service.DisableMonitor(adminInfo.CurrentOrgId, patientID, recordID, adminInfo.AdminUser.Id)
  1992. if err != nil {
  1993. this.ErrorLog("删除透析监测记录失败:%v", err)
  1994. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1995. return
  1996. }
  1997. this.ServeSuccessJSON(map[string]interface{}{
  1998. "record_id": monitor.ID,
  1999. })
  2000. }
  2001. func (c *DialysisApiController) CreateMonitor() {
  2002. patient, _ := c.GetInt64("id", 0)
  2003. dialysis_order_id, _ := c.GetInt64("dialysis_order_id", 0)
  2004. monitoring_date, _ := c.GetInt64("monitoring_date", 0)
  2005. operate_time, _ := c.GetInt64("operate_time", 0)
  2006. // monitoring_time := c.GetString("monitoring_time")
  2007. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  2008. breathing_rated, _ := c.GetFloat("breathing_rated", 0)
  2009. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  2010. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  2011. blood_pressure_type, _ := c.GetInt64("blood_pressure_type", 0)
  2012. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  2013. venous_pressure, _ := c.GetFloat("venous_pressure", 0)
  2014. venous_pressure_type, _ := c.GetInt64("venous_pressure_type", 1)
  2015. transmembrane_pressure, _ := c.GetFloat("transmembrane_pressure", 0)
  2016. transmembrane_pressure_type, _ := c.GetInt64("transmembrane_pressure_type", 1)
  2017. ultrafiltration_rate, _ := c.GetFloat("ultrafiltration_rate", 0)
  2018. ultrafiltration_volume, _ := c.GetFloat("ultrafiltration_volume", 0)
  2019. sodium_concentration, _ := c.GetFloat("sodium_concentration", 0)
  2020. arterial_pressure, _ := c.GetFloat("arterial_pressure", 0)
  2021. arterial_pressure_type, _ := c.GetInt64("arterial_pressure_type", 1)
  2022. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  2023. temperature, _ := c.GetFloat("temperature", 0)
  2024. replacement_rate, _ := c.GetFloat("replacement_rate", 0)
  2025. displacement_quantity, _ := c.GetFloat("displacement_quantity", 0)
  2026. conductivity, _ := c.GetFloat("conductivity", 0)
  2027. displacement_flow_quantity, _ := c.GetFloat("displacement_flow_quantity", 0)
  2028. heparin, _ := c.GetFloat("heparin", 0)
  2029. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  2030. ktv, _ := c.GetFloat("ktv", 0)
  2031. symptom := c.GetString("symptom")
  2032. dispose := c.GetString("dispose")
  2033. result := c.GetString("results")
  2034. monitoring_nurse, _ := c.GetInt64("monitoring_nurse", 0)
  2035. monitor_anticoagulant, _ := c.GetInt64("monitor_anticoagulant")
  2036. monitor_anticoagulant_value := c.GetString("monitor_anticoagulant_value")
  2037. monitoring_date = monitoring_date / 1000
  2038. // operate_time = operate_time / 1000
  2039. if patient <= 0 {
  2040. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2041. return
  2042. }
  2043. adminUserInfo := c.GetAdminUserInfo()
  2044. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2045. if patientInfo.ID == 0 {
  2046. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2047. return
  2048. }
  2049. monitorRecord := models.MonitoringRecord{
  2050. PatientId: patient,
  2051. MonitoringDate: monitoring_date,
  2052. DialysisOrderId: dialysis_order_id,
  2053. OperateTime: operate_time,
  2054. // MonitoringTime: monitoring_time,
  2055. PulseFrequency: pulse_frequency,
  2056. BreathingRate: breathing_rated,
  2057. SystolicBloodPressure: systolic_blood_pressure,
  2058. DiastolicBloodPressure: diastolic_blood_pressure,
  2059. BloodPressureType: blood_pressure_type,
  2060. BloodFlowVolume: blood_flow_volume,
  2061. VenousPressure: venous_pressure,
  2062. VenousPressureType: venous_pressure_type,
  2063. TransmembranePressure: transmembrane_pressure,
  2064. TransmembranePressureType: transmembrane_pressure_type,
  2065. UltrafiltrationRate: ultrafiltration_rate,
  2066. UltrafiltrationVolume: ultrafiltration_volume,
  2067. SodiumConcentration: sodium_concentration,
  2068. ArterialPressure: arterial_pressure,
  2069. ArterialPressureType: arterial_pressure_type,
  2070. DialysateTemperature: dialysate_temperature,
  2071. Temperature: temperature,
  2072. ReplacementRate: replacement_rate,
  2073. DisplacementQuantity: displacement_quantity,
  2074. Ktv: ktv,
  2075. Symptom: symptom,
  2076. Dispose: dispose,
  2077. Result: result,
  2078. MonitoringNurse: monitoring_nurse,
  2079. Status: 1,
  2080. CreatedTime: time.Now().Unix(),
  2081. UpdatedTime: time.Now().Unix(),
  2082. UserOrgId: adminUserInfo.CurrentOrgId,
  2083. Conductivity: conductivity,
  2084. DisplacementFlowQuantity: displacement_flow_quantity,
  2085. Heparin: heparin,
  2086. DialysateFlow: dialysate_flow,
  2087. MonitorAnticoagulant: monitor_anticoagulant,
  2088. MonitorAnticoagulantValue: monitor_anticoagulant_value,
  2089. }
  2090. err := service.CreateMonitor(&monitorRecord)
  2091. if err != nil {
  2092. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  2093. return
  2094. }
  2095. c.ServeSuccessJSON(map[string]interface{}{
  2096. "msg": "ok",
  2097. "monitor": monitorRecord,
  2098. })
  2099. return
  2100. }
  2101. // 已弃用
  2102. // func (c *DialysisApiController) CreateRecordData() {
  2103. // patient, _ := c.GetInt64("id", 0)
  2104. // status, _ := c.GetInt64("status", 0)
  2105. // now := time.Now()
  2106. // year, month, day := now.Date()
  2107. // today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2108. // todayTimeStamp := today_time.Unix()
  2109. // if patient <= 0 {
  2110. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2111. // return
  2112. // }
  2113. // adminUserInfo := c.GetAdminUserInfo()
  2114. // patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2115. // if patientInfo.ID == 0 {
  2116. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2117. // return
  2118. // }
  2119. // record := &models.DialysisOrder{
  2120. // DialysisDate: todayTimeStamp,
  2121. // UserOrgId: adminUserInfo.CurrentOrgId,
  2122. // PatientId: patient,
  2123. // Stage: status,
  2124. // Status: 1,
  2125. // CreatedTime: time.Now().Unix(),
  2126. // UpdatedTime: time.Now().Unix(),
  2127. // }
  2128. // if status == 1 {
  2129. // //创建透析记录
  2130. // err := service.CreateDialysisRecord(patient, adminUserInfo.CurrentOrgId, record)
  2131. // if err == nil {
  2132. // c.ServeSuccessJSON(map[string]interface{}{
  2133. // "dialysisOrder": record,
  2134. // })
  2135. // } else {
  2136. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2137. // }
  2138. // } else {
  2139. // record_id, _ := c.GetInt64("record_id", 0)
  2140. // //修改透析记录状态
  2141. // errs := service.ModifyDialysisRecord(record_id)
  2142. // //结束时候透析次数加1
  2143. // service.UpdateSolutionByPatientId(patient)
  2144. // if errs == nil {
  2145. // c.ServeSuccessJSON(map[string]interface{}{
  2146. // "dialysisOrder": record,
  2147. // })
  2148. // } else {
  2149. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2150. // }
  2151. // }
  2152. // }
  2153. func adviceFormDatas(advice *models.DoctorAdvice, data []byte, action string) (code int, subAdvice []*models.DoctorAdvice) {
  2154. dataBody := make(map[string]interface{}, 0)
  2155. err := json.Unmarshal(data, &dataBody)
  2156. if err != nil {
  2157. utils.ErrorLog(err.Error())
  2158. code = enums.ErrorCodeParamWrong
  2159. return
  2160. }
  2161. timeLayout := "2006-01-02 "
  2162. timeLayout2 := "2006-01-02 15:04"
  2163. loc, _ := time.LoadLocation("Local")
  2164. if action == "create" {
  2165. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2166. utils.ErrorLog("advice_type")
  2167. code = enums.ErrorCodeParamWrong
  2168. return
  2169. }
  2170. adviceType := int64(dataBody["advice_type"].(float64))
  2171. if adviceType != 1 && adviceType != 2 {
  2172. utils.ErrorLog("advice_type != 1&&2")
  2173. code = enums.ErrorCodeParamWrong
  2174. return
  2175. }
  2176. advice.AdviceType = adviceType
  2177. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2178. utils.ErrorLog("advice_date")
  2179. code = enums.ErrorCodeParamWrong
  2180. return
  2181. }
  2182. adviceDate, _ := dataBody["advice_date"].(string)
  2183. if len(adviceDate) == 0 {
  2184. utils.ErrorLog("len(adviceDate) == 0")
  2185. code = enums.ErrorCodeParamWrong
  2186. return
  2187. }
  2188. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  2189. if err != nil {
  2190. utils.ErrorLog(err.Error())
  2191. code = enums.ErrorCodeParamWrong
  2192. return
  2193. }
  2194. advice.AdviceDate = theTime.Unix()
  2195. }
  2196. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2197. utils.ErrorLog("start_time")
  2198. code = enums.ErrorCodeParamWrong
  2199. return
  2200. }
  2201. startDate, _ := dataBody["start_time"].(string)
  2202. if len(startDate) == 0 {
  2203. utils.ErrorLog("len(startDate) == 0")
  2204. code = enums.ErrorCodeParamWrong
  2205. return
  2206. }
  2207. theTime, err := time.ParseInLocation(timeLayout2, startDate, loc)
  2208. if err != nil {
  2209. utils.ErrorLog(err.Error())
  2210. code = enums.ErrorCodeParamWrong
  2211. return
  2212. }
  2213. advice.StartTime = theTime.Unix()
  2214. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  2215. utils.ErrorLog("advice_name")
  2216. code = enums.ErrorCodeParamWrong
  2217. return
  2218. }
  2219. adviceName, _ := dataBody["advice_name"].(string)
  2220. if len(adviceName) == 0 {
  2221. utils.ErrorLog("len(advice_name) == 0")
  2222. code = enums.ErrorCodeParamWrong
  2223. return
  2224. }
  2225. advice.AdviceName = adviceName
  2226. if dataBody["delivery_way"] == nil || reflect.TypeOf(dataBody["delivery_way"]).String() != "string" {
  2227. utils.ErrorLog("delivery_way")
  2228. code = enums.ErrorCodeParamWrong
  2229. return
  2230. }
  2231. deliveryWay, _ := dataBody["delivery_way"].(string)
  2232. if len(deliveryWay) == 0 {
  2233. utils.ErrorLog("len(deliveryWay) == 0")
  2234. code = enums.ErrorCodeParamWrong
  2235. return
  2236. }
  2237. advice.DeliveryWay = deliveryWay
  2238. if dataBody["execution_frequency"] == nil || reflect.TypeOf(dataBody["execution_frequency"]).String() != "string" {
  2239. utils.ErrorLog("execution_frequency")
  2240. code = enums.ErrorCodeParamWrong
  2241. return
  2242. }
  2243. execution_frequency, _ := dataBody["execution_frequency"].(string)
  2244. if len(execution_frequency) == 0 {
  2245. utils.ErrorLog("len(execution_frequency) == 0")
  2246. code = enums.ErrorCodeParamWrong
  2247. return
  2248. }
  2249. advice.ExecutionFrequency = execution_frequency
  2250. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  2251. adviceDsc, _ := dataBody["advice_desc"].(string)
  2252. advice.AdviceDesc = adviceDsc
  2253. }
  2254. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  2255. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  2256. advice.DrugSpecUnit = drugSpecUnit
  2257. }
  2258. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  2259. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  2260. advice.SingleDose = singleDose
  2261. }
  2262. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  2263. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  2264. advice.SingleDoseUnit = singleDoseUnit
  2265. }
  2266. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  2267. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  2268. advice.PrescribingNumber = prescribingNumber
  2269. }
  2270. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  2271. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  2272. advice.PrescribingNumberUnit = prescribingNumberUnit
  2273. }
  2274. if dataBody["subAdviceForm"] != nil && reflect.TypeOf(dataBody["subAdviceForm"]).String() == "[]interface {}" {
  2275. thisContagions, _ := dataBody["subAdviceForm"].([]interface{})
  2276. if len(thisContagions) > 0 {
  2277. for _, item := range thisContagions {
  2278. items := item.(map[string]interface{})
  2279. advice_name, _ := items["advice_name"].(string)
  2280. advice_desc, _ := items["advice_desc"].(string)
  2281. drug_spec_unit, _ := items["drug_spec_unit"].(string)
  2282. prescribing_number_unit, _ := items["prescribing_number_unit"].(string)
  2283. single_dose_unit, _ := items["single_dose_unit"].(string)
  2284. prescribing_number, _ := strconv.ParseFloat(items["prescribing_number"].(string), 64)
  2285. single_dose, _ := strconv.ParseFloat(items["single_dose"].(string), 64)
  2286. advice := &models.DoctorAdvice{
  2287. AdviceName: advice_name,
  2288. AdviceDesc: advice_desc,
  2289. SingleDose: single_dose,
  2290. SingleDoseUnit: single_dose_unit,
  2291. DrugSpecUnit: drug_spec_unit,
  2292. PrescribingNumber: prescribing_number,
  2293. PrescribingNumberUnit: prescribing_number_unit,
  2294. }
  2295. subAdvice = append(subAdvice, advice)
  2296. }
  2297. }
  2298. }
  2299. return
  2300. }
  2301. func (c *DialysisApiController) GetDialysisOrder() {
  2302. xtno := c.GetString("xtno")
  2303. xtdate := c.GetString("xtdate")
  2304. timeLayout := "2006-01-02"
  2305. loc, _ := time.LoadLocation("Local")
  2306. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  2307. if err != nil {
  2308. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2309. return
  2310. }
  2311. xttime := theTime.Unix()
  2312. operatorIDs := make([]int64, 0)
  2313. adminUserInfo := c.GetAdminUserInfo()
  2314. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  2315. patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.CurrentOrgId, xtno, xttime)
  2316. //透析单
  2317. dialysisOrder, _ := service.MobileGetSchedualDialysisRecord(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2318. if dialysisOrder != nil {
  2319. if dialysisOrder.FinishNurse > 0 {
  2320. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  2321. }
  2322. if dialysisOrder.StartNurse > 0 {
  2323. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  2324. }
  2325. }
  2326. //透前评估
  2327. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2328. predialysName, err := service.FindPredialysisName(PredialysisEvaluation.BloodAccessPartOperaId, adminUserInfo.CurrentOrgId)
  2329. //透后评估
  2330. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2331. if AssessmentAfterDislysis.Modifier > 0 {
  2332. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  2333. }
  2334. //上次透前评估
  2335. lastPredialysisEvaluation, _ := service.GetLastTimePredialysisEvaluation(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2336. lastOrder, _ := service.GetLastTimeOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2337. //透析处方
  2338. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2339. if dialysisPrescription.PrescriptionDoctor > 0 {
  2340. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  2341. }
  2342. //获取病人的透析模式
  2343. schedule, err := service.FindDialysisMode(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2344. order, err := service.FindDialysisMacher(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2345. nurse, err := service.FindPunctureNurse(order.PunctureNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  2346. startNuse, err := service.FindeStartNuse(order.StartNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  2347. FinishNuse, err := service.FindeStartNuse(order.FinishNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  2348. //获取透析处方
  2349. dialysisway, err := service.FindDialysisWay(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2350. //获取临时医嘱
  2351. doctorAdvice, _ := service.FindDoctorOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2352. //config, err := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  2353. //获取医嘱内容
  2354. doctor, err := service.FindDoctor(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  2355. DoctorName, err := service.FindDoctorName(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  2356. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2357. doctorAdevieInfo, err := service.FindDoctorAdviceByInfo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2358. //获取上次的透后体重
  2359. // assessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2360. assessmentAfterDislysis, _ := service.MobileGetLast(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2361. //获取透析次数
  2362. _, total, err := service.GetTotalDialysisCout(adminUserInfo.CurrentOrgId, patientInfo.ID)
  2363. if len(DoctorAdvice) > 0 {
  2364. for _, item := range DoctorAdvice {
  2365. if item.AdviceDoctor > 0 {
  2366. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  2367. }
  2368. if item.ExecutionStaff > 0 {
  2369. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  2370. }
  2371. if item.Checker > 0 {
  2372. operatorIDs = append(operatorIDs, item.Checker)
  2373. }
  2374. }
  2375. }
  2376. //透析监测
  2377. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2378. //透析检测
  2379. //monitor, err := service.FindAllMonitor(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2380. //透析小结
  2381. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2382. //接诊评估
  2383. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2384. check, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2385. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2386. patientInfo.TotalDialysis = dialysis_count
  2387. //相关操作对应的操作人
  2388. //operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  2389. operators, err := service.GetAdminUserEsOne(adminUserInfo.CurrentOrgId)
  2390. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  2391. //获取当前日期月份的第一天
  2392. firstmonth := service.GetFirstDateOfMonth(theTime)
  2393. firstMonthDate := firstmonth.Unix()
  2394. //获取当前月份的病人透析次数
  2395. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.CurrentOrgId)
  2396. //获取his数据
  2397. hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2398. //hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2399. config, _ := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  2400. project_config, _ := service.GetHisProjectConfig(adminUserInfo.CurrentOrgId)
  2401. projects, _ := service.FindAllHisProjectById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2402. //if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
  2403. // for _, item := range projects {
  2404. // var advice *models.HisDoctorAdviceInfo
  2405. // advice.ID = item.ID
  2406. // advice.Checker = item.Checker
  2407. // advice.CheckTime = item.CheckTime
  2408. // advice.CheckState = item.CheckState
  2409. // advice.ExecutionState = item.ExecutionState
  2410. // advice.ExecutionStaff = item.ExecutionStaff
  2411. // advice.PrescribingNumber = float64(item.Count)
  2412. // advice.PrescribingNumberUnit = item.Unit
  2413. // advice.AdviceDoctor = item.Doctor
  2414. // if item.Type == 3 {
  2415. // advice.AdviceName = item.GoodInfo.GoodName
  2416. // } else if item.Type == 2 {
  2417. // advice.AdviceName = item.HisProject.ProjectName
  2418. // }
  2419. // advice.StartTime = item.StartTime
  2420. // hisAdvice = append(hisAdvice, advice)
  2421. // }
  2422. //}
  2423. if config.IsOpen == 1 {
  2424. c.ServeSuccessJSON(map[string]interface{}{
  2425. "xtdate": xtdate,
  2426. "users": adminUser,
  2427. "patientInfo": patientInfo,
  2428. "PredialysisEvaluation": PredialysisEvaluation,
  2429. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  2430. "dialysisPrescription": dialysisPrescription,
  2431. "advices": hisAdvice,
  2432. "monitors": Record,
  2433. "summary": TreatmentSummary,
  2434. "receiverTreatmentAccess": receiverTreatmentAccess,
  2435. "dialysisOrder": dialysisOrder,
  2436. "operators": operators,
  2437. "org_template_info": templateInfo,
  2438. "check": check,
  2439. "schedule": schedule,
  2440. "dialysisway": dialysisway,
  2441. "order": order,
  2442. "doctorAdvice": doctorAdvice,
  2443. "doctor": doctor,
  2444. "nurse": nurse,
  2445. "doctorAdevieInfo": doctorAdevieInfo,
  2446. "total": total,
  2447. "startNuse": startNuse,
  2448. "DoctorName": DoctorName,
  2449. "assessmentAfterDislysis": assessmentAfterDislysis,
  2450. "predialysName": predialysName,
  2451. "FinishNuse": FinishNuse,
  2452. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  2453. "dialysiscount": dialysiscount,
  2454. "last_order": lastOrder,
  2455. "project_config": project_config,
  2456. "projects": projects,
  2457. })
  2458. }
  2459. if config.IsOpen == 0 || config.IsOpen == 2 {
  2460. c.ServeSuccessJSON(map[string]interface{}{
  2461. "xtdate": xtdate,
  2462. "users": adminUser,
  2463. "patientInfo": patientInfo,
  2464. "PredialysisEvaluation": PredialysisEvaluation,
  2465. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  2466. "dialysisPrescription": dialysisPrescription,
  2467. "advices": DoctorAdvice,
  2468. "monitors": Record,
  2469. "summary": TreatmentSummary,
  2470. "receiverTreatmentAccess": receiverTreatmentAccess,
  2471. "dialysisOrder": dialysisOrder,
  2472. "operators": operators,
  2473. "org_template_info": templateInfo,
  2474. "check": check,
  2475. "schedule": schedule,
  2476. "dialysisway": dialysisway,
  2477. "order": order,
  2478. "doctorAdvice": doctorAdvice,
  2479. "doctor": doctor,
  2480. "nurse": nurse,
  2481. "doctorAdevieInfo": doctorAdevieInfo,
  2482. "total": total,
  2483. "startNuse": startNuse,
  2484. "DoctorName": DoctorName,
  2485. "assessmentAfterDislysis": assessmentAfterDislysis,
  2486. "predialysName": predialysName,
  2487. "FinishNuse": FinishNuse,
  2488. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  2489. "dialysiscount": dialysiscount,
  2490. "last_order": lastOrder,
  2491. "project_config": project_config,
  2492. "projects": projects,
  2493. })
  2494. }
  2495. }
  2496. //
  2497. func (c *DialysisApiController) GetLongAdvice() {
  2498. patient_id, _ := c.GetInt64("patient_id")
  2499. adminUserInfo := c.GetAdminUserInfo()
  2500. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  2501. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  2502. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  2503. c.ServeSuccessJSON(map[string]interface{}{
  2504. "status": "1",
  2505. })
  2506. return
  2507. } else { //开启推送提醒
  2508. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  2509. var advice_three []*models.DoctorAdvice
  2510. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  2511. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id)
  2512. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id)
  2513. for _, advice := range advices {
  2514. if advice.FrequencyType == 3 {
  2515. t := time.Now()
  2516. week := int(t.Weekday())
  2517. switch week {
  2518. case 1:
  2519. if strings.Index(advice.WeekDay, "周一") == -1 {
  2520. advice_three = append(advice_three, advice)
  2521. }
  2522. break
  2523. case 2:
  2524. if strings.Index(advice.WeekDay, "周二") == -1 {
  2525. advice_three = append(advice_three, advice)
  2526. }
  2527. break
  2528. case 3:
  2529. if strings.Index(advice.WeekDay, "周三") == -1 {
  2530. advice_three = append(advice_three, advice)
  2531. }
  2532. break
  2533. case 4:
  2534. if strings.Index(advice.WeekDay, "周四") == -1 {
  2535. advice_three = append(advice_three, advice)
  2536. }
  2537. break
  2538. case 5:
  2539. if strings.Index(advice.WeekDay, "周五") == -1 {
  2540. advice_three = append(advice_three, advice)
  2541. }
  2542. break
  2543. case 6:
  2544. if strings.Index(advice.WeekDay, "周六") == -1 {
  2545. advice_three = append(advice_three, advice)
  2546. }
  2547. break
  2548. case 0:
  2549. if strings.Index(advice.WeekDay, "周日") == -1 {
  2550. advice_three = append(advice_three, advice)
  2551. }
  2552. break
  2553. }
  2554. }
  2555. }
  2556. for _, advice := range advices_two {
  2557. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  2558. now := p.Unix()
  2559. dayStr := strconv.FormatInt(advice.DayCount, 10)
  2560. dayStr2 := "-" + dayStr
  2561. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  2562. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  2563. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  2564. for _, ad := range advices {
  2565. advice_three = append(advice_three, ad)
  2566. }
  2567. }
  2568. if err == nil {
  2569. c.ServeSuccessJSON(map[string]interface{}{
  2570. "status": "2",
  2571. "advices": advices,
  2572. "advices_two": RemoveRepeatedElement(advice_three),
  2573. "is_open_remind": config.IsOpenRemind,
  2574. })
  2575. }
  2576. }
  2577. }
  2578. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  2579. newArr = make([]*models.DoctorAdvice, 0)
  2580. for i := 0; i < len(arr); i++ {
  2581. repeat := false
  2582. for j := i + 1; j < len(arr); j++ {
  2583. if arr[i].ID == arr[j].ID {
  2584. repeat = true
  2585. break
  2586. }
  2587. }
  2588. if !repeat {
  2589. newArr = append(newArr, arr[i])
  2590. }
  2591. }
  2592. return
  2593. }
  2594. func (c *DialysisApiController) CreateRemindDoctorAdvice() {
  2595. patient, _ := c.GetInt64("id", 0)
  2596. groupNo, _ := c.GetInt64("groupno", 0)
  2597. if patient <= 0 {
  2598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2599. return
  2600. }
  2601. adminUserInfo := c.GetAdminUserInfo()
  2602. dataBody := make(map[string]interface{}, 0)
  2603. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2604. if err != nil {
  2605. utils.ErrorLog(err.Error())
  2606. return
  2607. }
  2608. utils.ErrorLog("%v", dataBody)
  2609. timeLayout := "2006-01-02 15:04"
  2610. loc, _ := time.LoadLocation("Local")
  2611. timeLayout2 := "2006-01-02"
  2612. loc2, _ := time.LoadLocation("Local")
  2613. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2614. utils.ErrorLog("advice_type")
  2615. return
  2616. }
  2617. adviceType := int64(2)
  2618. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2619. utils.ErrorLog("advice_date")
  2620. return
  2621. }
  2622. adviceDate, _ := dataBody["advice_date"].(string)
  2623. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  2624. fmt.Println("the-----------------", theTime)
  2625. AdviceDate := theTime.Unix()
  2626. RecordDate := theTime.Unix()
  2627. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2628. utils.ErrorLog("start_time")
  2629. return
  2630. }
  2631. startTime, _ := dataBody["start_time"].(string)
  2632. if len(startTime) == 0 {
  2633. utils.ErrorLog("len(start_time) == 0")
  2634. return
  2635. }
  2636. theTimeUnix, err := time.ParseInLocation(timeLayout, startTime, loc)
  2637. if err != nil {
  2638. utils.ErrorLog(err.Error())
  2639. return
  2640. }
  2641. StartTime := theTimeUnix.Unix()
  2642. fmt.Println("startTIME", StartTime)
  2643. Remark := ""
  2644. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2645. remark, _ := dataBody["remark"].(string)
  2646. Remark = remark
  2647. }
  2648. var advices []*models.GroupAdvice
  2649. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  2650. utils.ErrorLog("advices")
  2651. return
  2652. }
  2653. adviceNames := dataBody["advices"].([]interface{})
  2654. for _, adviceNameMap := range adviceNames {
  2655. adviceNameM := adviceNameMap.(map[string]interface{})
  2656. var advice models.GroupAdvice
  2657. advice.Remark = Remark
  2658. advice.AdviceType = adviceType
  2659. advice.StartTime = StartTime
  2660. advice.AdviceDate = AdviceDate
  2661. advice.RecordDate = RecordDate
  2662. advice.Status = 1
  2663. advice.CreatedTime = time.Now().Unix()
  2664. advice.UpdatedTime = time.Now().Unix()
  2665. advice.StopState = 2
  2666. advice.ExecutionState = 2
  2667. advice.UserOrgId = adminUserInfo.CurrentOrgId
  2668. advice.PatientId = patient
  2669. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  2670. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  2671. utils.ErrorLog("advice_name")
  2672. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2673. return
  2674. }
  2675. adviceName, _ := adviceNameM["advice_name"].(string)
  2676. if len(adviceName) == 0 {
  2677. utils.ErrorLog("len(advice_name) == 0")
  2678. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2679. return
  2680. }
  2681. advice.AdviceName = adviceName
  2682. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  2683. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  2684. advice.DrugSpec = drugSpec
  2685. }
  2686. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  2687. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  2688. advice.AdviceDesc = adviceDesc
  2689. }
  2690. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  2691. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  2692. advice.DrugSpecUnit = drugSpecUnit
  2693. }
  2694. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  2695. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  2696. // advice.SingleDose = singleDose
  2697. //}
  2698. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  2699. //single_dose := int64(adviceNameM["single_dose"].(float64))
  2700. advice.SingleDose = adviceNameM["single_dose"].(float64)
  2701. }
  2702. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  2703. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  2704. advice.SingleDoseUnit = singleDoseUnit
  2705. }
  2706. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  2707. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  2708. // advice.PrescribingNumber = prescribingNumber
  2709. //}
  2710. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  2711. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  2712. }
  2713. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  2714. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  2715. advice.PrescribingNumberUnit = prescribingNumberUnit
  2716. }
  2717. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  2718. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  2719. advice.DeliveryWay = deliveryWay
  2720. }
  2721. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  2722. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  2723. advice.ExecutionFrequency = executionFrequency
  2724. }
  2725. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  2726. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  2727. advice.FrequencyType = frequency_type
  2728. }
  2729. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  2730. day_count := int64(adviceNameM["day_count"].(float64))
  2731. advice.DayCount = day_count
  2732. }
  2733. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  2734. way := int64(adviceNameM["way"].(float64))
  2735. advice.Way = way
  2736. }
  2737. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  2738. drug_id := int64(adviceNameM["drug_id"].(float64))
  2739. advice.DrugId = drug_id
  2740. }
  2741. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  2742. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  2743. advice.DrugNameId = drug_name_id
  2744. }
  2745. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  2746. week_day, _ := adviceNameM["week_day"].(string)
  2747. advice.WeekDay = week_day
  2748. }
  2749. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  2750. template_id, _ := adviceNameM["template_id"].(string)
  2751. advice.TemplateId = template_id
  2752. }
  2753. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  2754. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  2755. advice.ExecutionFrequency = executionFrequency
  2756. }
  2757. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  2758. children := adviceNameM["child"].([]interface{})
  2759. if len(children) > 0 {
  2760. for _, childrenMap := range children {
  2761. childMap := childrenMap.(map[string]interface{})
  2762. var child models.GroupAdvice
  2763. child.Remark = Remark
  2764. child.AdviceType = adviceType
  2765. child.StartTime = StartTime
  2766. child.AdviceDate = AdviceDate
  2767. child.RecordDate = RecordDate
  2768. child.Status = 1
  2769. child.CreatedTime = time.Now().Unix()
  2770. child.UpdatedTime = time.Now().Unix()
  2771. child.StopState = 2
  2772. child.ExecutionState = 2
  2773. child.UserOrgId = adminUserInfo.CurrentOrgId
  2774. child.PatientId = patient
  2775. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  2776. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  2777. utils.ErrorLog("child advice_name")
  2778. return
  2779. }
  2780. childAdviceName, _ := childMap["advice_name"].(string)
  2781. if len(childAdviceName) == 0 {
  2782. utils.ErrorLog("len(child advice_name) == 0")
  2783. return
  2784. }
  2785. child.AdviceName = childAdviceName
  2786. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  2787. childAdviceDesc, _ := childMap["advice_desc"].(string)
  2788. child.AdviceDesc = childAdviceDesc
  2789. }
  2790. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  2791. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  2792. child.DrugSpec = childDrugSpec
  2793. }
  2794. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  2795. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  2796. child.DrugSpecUnit = childDrugSpecUnit
  2797. }
  2798. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "string" {
  2799. childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  2800. child.SingleDose = childSingleDose
  2801. }
  2802. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  2803. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  2804. child.SingleDoseUnit = childSingleDoseUnit
  2805. }
  2806. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "string" {
  2807. childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  2808. child.PrescribingNumber = childPrescribingNumber
  2809. }
  2810. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  2811. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  2812. child.PrescribingNumberUnit = childPrescribingNumberUnit
  2813. }
  2814. child.DeliveryWay = advice.DeliveryWay
  2815. child.ExecutionFrequency = advice.ExecutionFrequency
  2816. advice.Children = append(advice.Children, &child)
  2817. }
  2818. }
  2819. }
  2820. advices = append(advices, &advice)
  2821. }
  2822. list, err := service.CreateMGroupAdvice(adminUserInfo.CurrentOrgId, advices, groupNo)
  2823. if err != nil {
  2824. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  2825. return
  2826. }
  2827. c.ServeSuccessJSON(map[string]interface{}{
  2828. "msg": "ok",
  2829. "advices": list,
  2830. })
  2831. return
  2832. }
  2833. func (c *DialysisApiController) GetSolution() {
  2834. patient_id, _ := c.GetInt64("patient_id")
  2835. mode_id, _ := c.GetInt64("mode_id")
  2836. adminUserInfo := c.GetAdminUserInfo()
  2837. solution, err := service.MobileGetDialysisSolutionByModeId(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  2838. prescription, err := service.MobileGetLastDialysisPrescribeByModeId(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  2839. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeId(adminUserInfo.CurrentOrgId, mode_id)
  2840. if err != nil {
  2841. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2842. return
  2843. }
  2844. c.ServeSuccessJSON(map[string]interface{}{
  2845. "solution": solution,
  2846. "prescription": prescription,
  2847. "system_prescription": system_prescription,
  2848. })
  2849. }
  2850. func (c *DialysisApiController) GetSchedule() {
  2851. schedual_type, _ := c.GetInt64("schedual_type")
  2852. adminUserInfo := c.GetAdminUserInfo()
  2853. //timeLayout := "2006-01-02 15:04:05"
  2854. //
  2855. //date := time.Now().Format("2006-01-02") + " 00:00:00"
  2856. //loc, _ := time.LoadLocation("Local")
  2857. //theStartTime, _ := time.ParseInLocation(timeLayout, date, loc)
  2858. //scheduleTime := theStartTime.Unix()
  2859. scheduleTime, _ := c.GetInt64("record_date")
  2860. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.CurrentOrgId, scheduleTime, schedual_type)
  2861. c.ServeSuccessJSON(map[string]interface{}{
  2862. "number": deviceNumber,
  2863. })
  2864. }
  2865. func (this *DialysisApiController) GetTodayMonitor() {
  2866. thisTime := time.Now()
  2867. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  2868. timeLayout := "2006-01-02 15:04:05"
  2869. loc, _ := time.LoadLocation("Local")
  2870. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2871. theAssessmentDateTime := theStartTime.Unix()
  2872. patientID, _ := this.GetInt64("patient_id")
  2873. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  2874. adminInfo := this.GetAdminUserInfo()
  2875. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  2876. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  2877. template, _ := service.GetOrgInfoTemplate(adminInfo.CurrentOrgId)
  2878. var ultrafiltration_rate float64
  2879. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
  2880. //针对福建医师汇 获取透前评估预增脱水量
  2881. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
  2882. fmt.Println("透前评估数据", evaluation)
  2883. if prescription.ID > 0 {
  2884. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  2885. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2886. if template.TemplateId == 6 { //adminInfo.CurrentOrgId == 9538
  2887. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2888. record.UltrafiltrationRate = ultrafiltration_rate
  2889. }
  2890. if template.TemplateId == 6 && adminInfo.CurrentOrgId == 10121 {
  2891. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  2892. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  2893. record.UltrafiltrationRate = ultrafiltration_rate
  2894. }
  2895. if template.TemplateId == 6 && adminInfo.CurrentOrgId == 10234 {
  2896. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  2897. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  2898. record.UltrafiltrationRate = ultrafiltration_rate
  2899. }
  2900. if template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 { //adminInfo.CurrentOrgId == 9538
  2901. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  2902. record.UltrafiltrationRate = ultrafiltration_rate
  2903. }
  2904. if template.TemplateId == 41 { //adminInfo.CurrentOrgId == 9538
  2905. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2906. record.UltrafiltrationRate = ultrafiltration_rate
  2907. }
  2908. if template.TemplateId == 43 { //adminInfo.CurrentOrgId == 9538
  2909. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  2910. record.UltrafiltrationRate = ultrafiltration_rate
  2911. }
  2912. // 只针对方济医院
  2913. if template.TemplateId == 1 && adminInfo.CurrentOrgId != 9849 {
  2914. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  2915. ultrafiltration_rate = value
  2916. record.UltrafiltrationRate = ultrafiltration_rate
  2917. }
  2918. }
  2919. }
  2920. // record.UltrafiltrationRate = ultrafiltration_rate
  2921. record.UltrafiltrationVolume = 0
  2922. if template.TemplateId == 1 && adminInfo.CurrentOrgId != 9849 {
  2923. if ultrafiltration_rate > 0 {
  2924. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  2925. record.UltrafiltrationVolume = value
  2926. }
  2927. }
  2928. if template.TemplateId == 6 || template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 41 || template.TemplateId == 43 {
  2929. if ultrafiltration_rate > 0 && adminInfo.CurrentOrgId != 9538 {
  2930. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  2931. record.UltrafiltrationVolume = ultrafiltration_volume
  2932. }
  2933. }
  2934. this.ServeSuccessJSON(map[string]interface{}{
  2935. "monitor": record,
  2936. })
  2937. }
  2938. func (c *DialysisApiController) UploadDryWeight() {
  2939. patient_id, _ := c.GetInt64("id")
  2940. dry_weight, _ := c.GetFloat("dry_weight")
  2941. doctor_id, _ := c.GetInt64("doctor_id")
  2942. remark := c.GetString("remark")
  2943. adminUserInfo := c.GetAdminUserInfo()
  2944. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.CurrentOrgId, patient_id)
  2945. fmt.Println(err)
  2946. if err == gorm.ErrRecordNotFound {
  2947. dryWeight := &models.SgjPatientDryweight{
  2948. PatientId: patient_id,
  2949. DryWeight: dry_weight,
  2950. Remakes: remark,
  2951. Ctime: time.Now().Unix(),
  2952. Mtime: time.Now().Unix(),
  2953. Creator: doctor_id,
  2954. Status: 1,
  2955. UserOrgId: adminUserInfo.CurrentOrgId,
  2956. AdjustedValue: "/",
  2957. UserId: adminUserInfo.AdminUser.Id,
  2958. }
  2959. createErr := service.CreatePatientWeightAdjust(dryWeight)
  2960. if createErr == nil {
  2961. c.ServeSuccessJSON(map[string]interface{}{
  2962. "msg": "提交成功",
  2963. "weight": dryWeight,
  2964. })
  2965. }
  2966. } else {
  2967. dryWeight := &models.SgjPatientDryweight{
  2968. PatientId: patient_id,
  2969. DryWeight: dry_weight,
  2970. Remakes: remark,
  2971. Ctime: time.Now().Unix(),
  2972. Mtime: time.Now().Unix(),
  2973. Creator: doctor_id,
  2974. Status: 1,
  2975. UserOrgId: adminUserInfo.CurrentOrgId,
  2976. AdjustedValue: "/",
  2977. UserId: adminUserInfo.AdminUser.Id,
  2978. }
  2979. var value float64
  2980. value = dry_weight - weightAdjust.DryWeight
  2981. fmt.Println(value)
  2982. if value < 0 {
  2983. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  2984. } else if value == 0 {
  2985. dryWeight.AdjustedValue = "/"
  2986. } else if value > 0 {
  2987. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  2988. }
  2989. fmt.Println(value)
  2990. createErr := service.CreatePatientWeightAdjust(dryWeight)
  2991. if createErr == nil {
  2992. c.ServeSuccessJSON(map[string]interface{}{
  2993. "msg": "提交成功",
  2994. "weight": dryWeight,
  2995. })
  2996. }
  2997. }
  2998. }
  2999. func (this *DialysisApiController) GetFuncPurview() {
  3000. adminUserInfo := this.GetAdminUserInfo()
  3001. user_id := adminUserInfo.AdminUser.Id
  3002. app_id := adminUserInfo.CurrentAppId
  3003. org_id := adminUserInfo.CurrentOrgId
  3004. create_url := this.GetString("create_url")
  3005. modify_url := this.GetString("modify_url")
  3006. modify_other_url := this.GetString("modify_other_url")
  3007. del_url := this.GetString("del_url")
  3008. del_other_url := this.GetString("del_other_url")
  3009. exce_url := this.GetString("exce_url")
  3010. check_url := this.GetString("check_url")
  3011. modify_exce_url := this.GetString("modify_exce_url")
  3012. module, _ := this.GetInt64("module", 0)
  3013. app_role, _ := service.GetAppRole(org_id, app_id, user_id)
  3014. var is_has_create bool
  3015. var is_has_modify bool
  3016. var is_has_modify_other bool
  3017. var is_has_del bool
  3018. var is_has_del_other bool
  3019. var is_has_exce bool
  3020. var is_has_check bool
  3021. var is_has_modify_exce bool
  3022. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  3023. if adminUserInfo.AdminUser.Id != org.Creator {
  3024. if app_role != nil {
  3025. if len(app_role.RoleIds) > 0 {
  3026. roles := strings.Split(app_role.RoleIds, ",")
  3027. var userRolePurviews string
  3028. for _, item := range roles {
  3029. role_id, _ := strconv.ParseInt(item, 10, 64)
  3030. purviews, _ := service.GetRoleFuncPurviewIds(role_id)
  3031. if len(userRolePurviews) == 0 {
  3032. userRolePurviews = purviews
  3033. } else {
  3034. userRolePurviews = userRolePurviews + "," + purviews
  3035. }
  3036. }
  3037. userRolePurviewsArr := RemoveRepeatedPurviewElement2(strings.Split(userRolePurviews, ","))
  3038. funcPurviews, _ := service.FindAllFuncPurview(userRolePurviewsArr)
  3039. for _, item := range funcPurviews {
  3040. //for _, url := range strings.Split(item.Urlfor,","){
  3041. if strings.Split(item.Urlfor, ",")[1] == create_url {
  3042. is_has_create = true
  3043. }
  3044. if strings.Split(item.Urlfor, ",")[1] == modify_url {
  3045. is_has_modify = true
  3046. }
  3047. if strings.Split(item.Urlfor, ",")[1] == modify_other_url {
  3048. is_has_modify_other = true
  3049. }
  3050. if strings.Split(item.Urlfor, ",")[1] == del_url {
  3051. is_has_del = true
  3052. }
  3053. if strings.Split(item.Urlfor, ",")[1] == del_other_url {
  3054. is_has_del_other = true
  3055. }
  3056. if strings.Split(item.Urlfor, ",")[1] == exce_url {
  3057. is_has_exce = true
  3058. }
  3059. if strings.Split(item.Urlfor, ",")[1] == check_url {
  3060. is_has_check = true
  3061. }
  3062. if strings.Split(item.Urlfor, ",")[1] == modify_exce_url {
  3063. is_has_modify_exce = true
  3064. }
  3065. }
  3066. } else {
  3067. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRole)
  3068. return
  3069. }
  3070. this.ServeSuccessJSON(map[string]interface{}{
  3071. "is_has_create": is_has_create,
  3072. "is_has_modify": is_has_modify,
  3073. "is_has_modify_other": is_has_modify_other,
  3074. "is_has_del": is_has_del,
  3075. "is_has_del_other": is_has_del_other,
  3076. "is_has_exce": is_has_exce,
  3077. "is_has_check": is_has_check,
  3078. "is_has_modify_exce": is_has_modify_exce,
  3079. "module": module,
  3080. })
  3081. } else {
  3082. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserIsExit)
  3083. return
  3084. }
  3085. } else {
  3086. this.ServeSuccessJSON(map[string]interface{}{
  3087. "is_has_create": true,
  3088. "is_has_modify": true,
  3089. "is_has_modify_other": true,
  3090. "is_has_del": true,
  3091. "is_has_del_other": true,
  3092. "is_has_exce": true,
  3093. "is_has_check": true,
  3094. "is_has_modify_exce": true,
  3095. "module": true,
  3096. })
  3097. }
  3098. }
  3099. func (this *DialysisApiController) GetLastOrNextDoctorAdvice() {
  3100. change_type, _ := this.GetInt64("type", 0)
  3101. record_date := this.GetString("record_time")
  3102. patient_id, _ := this.GetInt64("patient_id", 0)
  3103. timeLayout := "2006-01-02"
  3104. loc, _ := time.LoadLocation("Local")
  3105. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3106. record_time := theAdviceRecordTime.Unix()
  3107. adminUserInfo := this.GetAdminUserInfo()
  3108. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id)
  3109. if err == nil {
  3110. if len(advices) == 0 {
  3111. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  3112. return
  3113. } else {
  3114. this.ServeSuccessJSON(map[string]interface{}{
  3115. "advices": advices,
  3116. "schedule": sch,
  3117. })
  3118. return
  3119. }
  3120. } else {
  3121. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3122. return
  3123. }
  3124. }
  3125. func (c *DialysisApiController) GetDialysisGoods() {
  3126. schedualDate := c.GetString("schedule_date")
  3127. schedule_type, _ := c.GetInt64("schedule_type")
  3128. partition_id, _ := c.GetInt64("partition_id")
  3129. page, _ := c.GetInt("page")
  3130. limit, _ := c.GetInt("limit")
  3131. keywords := c.GetString("keywords")
  3132. patient_id, _ := c.GetInt64("patient_id")
  3133. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  3134. if parseDateErr != nil && len(schedualDate) != 0 {
  3135. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3136. return
  3137. }
  3138. schedualEndDate := int64(0)
  3139. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  3140. if parseDateErr != nil && len(schedualDate) != 0 {
  3141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3142. return
  3143. }
  3144. schedualEndDate = endDate.Unix()
  3145. adminUser := c.GetAdminUserInfo()
  3146. _, err := service.FindStockOutByIsSys(adminUser.CurrentOrgId, 1, date.Unix())
  3147. goodTypes, _ := service.FindAllGoodType(adminUser.CurrentOrgId)
  3148. if err == gorm.ErrRecordNotFound {
  3149. dialysisGoods, _, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate)
  3150. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  3151. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  3152. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  3153. item.LastAutomaticReduceDetail = goodUser
  3154. item.LastDialysisBeforePrepare = lastGoodUserDetial
  3155. }
  3156. c.ServeSuccessJSON(map[string]interface{}{
  3157. "dialysis_goods": dialysisGoods,
  3158. "good_type": goodTypes,
  3159. "total": total,
  3160. })
  3161. return
  3162. } else if err == nil {
  3163. //获取当天排班的每个患者的库存使用情况
  3164. dialysisGoods, err, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate)
  3165. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  3166. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  3167. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  3168. fmt.Println(goodUser)
  3169. fmt.Println(lastGoodUserDetial)
  3170. item.LastAutomaticReduceDetail = goodUser
  3171. item.LastDialysisBeforePrepare = lastGoodUserDetial
  3172. }
  3173. if err == nil {
  3174. c.ServeSuccessJSON(map[string]interface{}{
  3175. "dialysis_goods": dialysisGoods,
  3176. "good_type": goodTypes,
  3177. "total": total,
  3178. })
  3179. return
  3180. } else {
  3181. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3182. return
  3183. }
  3184. } else if err != nil {
  3185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3186. return
  3187. }
  3188. }
  3189. func (c *DialysisApiController) GetDialysisGoodsStatistics() {
  3190. start_time := c.GetString("start_time")
  3191. end_time := c.GetString("end_time")
  3192. timeLayout := "2006-01-02"
  3193. loc, _ := time.LoadLocation("Local")
  3194. var theStartTime int64
  3195. if len(start_time) > 0 {
  3196. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3197. if err != nil {
  3198. utils.ErrorLog(err.Error())
  3199. }
  3200. theStartTime = theTime.Unix()
  3201. }
  3202. var theEndtTime int64
  3203. if len(end_time) > 0 {
  3204. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3205. if err != nil {
  3206. utils.ErrorLog(err.Error())
  3207. }
  3208. theEndtTime = theTime.Unix()
  3209. }
  3210. adminUser := c.GetAdminUserInfo()
  3211. outInfo, err := service.MobileGetGoodsStatistics(adminUser.CurrentOrgId, theStartTime, theEndtTime)
  3212. if err == nil {
  3213. c.ServeSuccessJSON(map[string]interface{}{
  3214. "stock_out": outInfo,
  3215. })
  3216. return
  3217. } else {
  3218. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3219. return
  3220. }
  3221. }