dialysis_api_controller.go 159KB

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