dialysis_api_controller.go 122KB

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