dialysis_api_controller.go 115KB

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