dialysis_api_controller.go 131KB

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