dialysis_api_controller.go 133KB

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