dialysis_api_controller.go 150KB

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