dialysis_api_controller.go 148KB

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