dialysis_api_controller.go 127KB

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