dialysis_api_controller.go 147KB

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