dialysis_api_controller.go 133KB

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