patient_api_controller.go 89KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608
  1. package mobile_api_controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "strings"
  10. // "fmt"
  11. "reflect"
  12. "strconv"
  13. "time"
  14. )
  15. type PatientApiController struct {
  16. MobileBaseAPIAuthController
  17. }
  18. func (c *PatientApiController) GetPatientInfoWithDiseases() {
  19. id, _ := c.GetInt64("patient", 0)
  20. if id <= 0 {
  21. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  22. return
  23. }
  24. adminUserInfo := c.GetMobileAdminUserInfo()
  25. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  26. if patient.ID == 0 {
  27. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  28. return
  29. }
  30. Registrars, err := service.GetAdminUser(adminUserInfo.Org.Id, adminUserInfo.App.Id, patient.RegistrarsId)
  31. if err != nil {
  32. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  33. return
  34. }
  35. if Registrars != nil {
  36. patient.Registrars = Registrars.Name
  37. }
  38. c.ServeSuccessJSON(map[string]interface{}{
  39. "patient": patient,
  40. })
  41. return
  42. }
  43. func (c *PatientApiController) CreateDialysisSolution() {
  44. id, _ := c.GetInt64("patient", 0)
  45. if id <= 0 {
  46. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  47. return
  48. }
  49. adminUserInfo := c.GetMobileAdminUserInfo()
  50. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  51. if patient.ID == 0 {
  52. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  53. return
  54. }
  55. //根据路由来做权限
  56. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  57. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  58. //if template.TemplateId == 2 || template.TemplateId == 6 {
  59. // if appRole.UserType == 3 {
  60. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  61. // if getPermissionErr != nil {
  62. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  63. // return
  64. // } else if headNursePermission == nil {
  65. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  66. // return
  67. // }
  68. // }
  69. //}
  70. var solution models.DialysisSolution
  71. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "create")
  72. if code > 0 {
  73. c.ServeFailJSONWithSGJErrorCode(code)
  74. return
  75. }
  76. solution.RegistrarsId = adminUserInfo.AdminUser.Id
  77. solution.Doctor = adminUserInfo.AdminUser.Id
  78. solution.Status = 1
  79. solution.PatientId = id
  80. solution.CreatedTime = time.Now().Unix()
  81. solution.UserOrgId = adminUserInfo.Org.Id
  82. solution.UpdatedTime = time.Now().Unix()
  83. solution.SubName = ""
  84. solution.ParentId = 0
  85. err := service.CreatePatientDialysisSolution(&solution)
  86. if err != nil {
  87. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionCreate)
  88. return
  89. }
  90. c.ServeSuccessJSON(map[string]interface{}{
  91. "msg": "ok",
  92. "solution": solution,
  93. })
  94. return
  95. }
  96. func (c *PatientApiController) EditDialysisSolution() {
  97. id, _ := c.GetInt64("id", 0)
  98. if id <= 0 {
  99. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  100. return
  101. }
  102. adminUserInfo := c.GetMobileAdminUserInfo()
  103. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.Org.Id, id)
  104. if solution.ID == 0 {
  105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  106. return
  107. }
  108. //if solution.Doctor != adminUserInfo.AdminUser.Id {
  109. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  110. // if getPermissionErr != nil {
  111. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  112. // return
  113. // } else if headNursePermission == nil {
  114. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  115. // return
  116. // }
  117. //}
  118. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "update")
  119. if code > 0 {
  120. c.ServeFailJSONWithSGJErrorCode(code)
  121. return
  122. }
  123. // solution.RegistrarsId = adminUserInfo.AdminUser.Id
  124. solution.Doctor = adminUserInfo.AdminUser.Id
  125. solution.Status = 1
  126. // solution.PatientId = id
  127. // solution.CreatedTime = time.Now().Unix()
  128. // solution.UserOrgId = adminUserInfo.Org.Id
  129. solution.UpdatedTime = time.Now().Unix()
  130. // solution.SubName = ""
  131. // solution.ParentId = 0
  132. err := service.UpdatePatientDialysisSolution(&solution)
  133. if err != nil {
  134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  135. return
  136. }
  137. c.ServeSuccessJSON(map[string]interface{}{
  138. "msg": "ok",
  139. "solution": solution,
  140. })
  141. return
  142. }
  143. func (c *PatientApiController) CreateDoctorAdvice() {
  144. patient, _ := c.GetInt64("id", 0)
  145. if patient <= 0 {
  146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  147. return
  148. }
  149. adminUserInfo := c.GetMobileAdminUserInfo()
  150. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  151. if patientInfo.ID == 0 {
  152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  153. return
  154. }
  155. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  156. //if appRole.UserType == 3{
  157. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdvicePermissionDeniedModify)
  158. // return
  159. //}
  160. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  161. //
  162. //if appRole.UserType == 3 {
  163. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  164. // if getPermissionErr != nil {
  165. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  166. // return
  167. // } else if headNursePermission == nil {
  168. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  169. // return
  170. // }
  171. //}
  172. var advice models.DoctorAdvice
  173. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  174. if code > 0 {
  175. c.ServeFailJSONWithSGJErrorCode(code)
  176. return
  177. }
  178. if advice.ParentId > 0 {
  179. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  180. if old.ID == 0 || old.PatientId != patient {
  181. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  182. return
  183. }
  184. if old.StopState == 1 || old.ExecutionState == 1 {
  185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  186. return
  187. }
  188. if old.ParentId > 0 {
  189. advice.ParentId = old.ParentId
  190. }
  191. advice.StartTime = old.StartTime
  192. advice.AdviceDoctor = old.AdviceDoctor
  193. advice.DeliveryWay = old.DeliveryWay
  194. advice.ExecutionFrequency = old.ExecutionFrequency
  195. advice.GroupNo = old.GroupNo
  196. }
  197. advice.Status = 1
  198. advice.CreatedTime = time.Now().Unix()
  199. advice.UpdatedTime = time.Now().Unix()
  200. advice.StopState = 2
  201. advice.ExecutionState = 2
  202. advice.UserOrgId = adminUserInfo.Org.Id
  203. advice.PatientId = patient
  204. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  205. err := service.CreateDoctorAdvice(&advice)
  206. if err != nil {
  207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  208. return
  209. }
  210. c.ServeSuccessJSON(map[string]interface{}{
  211. "msg": "ok",
  212. "advice": advice,
  213. })
  214. return
  215. }
  216. func (c *PatientApiController) EditDoctorAdvice() {
  217. id, _ := c.GetInt64("id", 0)
  218. if id <= 0 {
  219. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  220. return
  221. }
  222. adminUserInfo := c.GetMobileAdminUserInfo()
  223. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  224. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  225. //
  226. //if appRole.UserType == 3 {
  227. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  228. // if getPermissionErr != nil {
  229. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  230. // return
  231. // } else if headNursePermission == nil {
  232. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  233. // return
  234. // }
  235. //}
  236. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  237. if advice.ID == 0 {
  238. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  239. return
  240. }
  241. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
  242. if code > 0 {
  243. c.ServeFailJSONWithSGJErrorCode(code)
  244. return
  245. }
  246. advice.Status = 1
  247. advice.UpdatedTime = time.Now().Unix()
  248. advice.UserOrgId = adminUserInfo.Org.Id
  249. advice.Modifier = adminUserInfo.AdminUser.Id
  250. //处理修改医嘱开始时间逻辑(不包括子医嘱)
  251. //1.一组医嘱内只有一条医嘱(不包括子医嘱)的情况下,只需要直接修改医嘱开始时间,不需要重新分配组号
  252. //2.一组医嘱内有多条医嘱(不包括子医嘱)的情况下,需要为修改的那条医嘱重新分配组号,并修改医嘱开始时间
  253. var err error
  254. var isChangeGroup bool
  255. if advice.ParentId == 0 {
  256. adviceSlice, _ := service.FindAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
  257. sourceAdvice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice.ID)
  258. if len(adviceSlice) == 1 {
  259. //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要修改子医嘱的开始时间,如果相同直接修改,不需要修改子医嘱的开始时间
  260. if advice.StartTime == sourceAdvice.StartTime {
  261. err = service.UpdateDoctorAdvice(&advice)
  262. isChangeGroup = false
  263. } else {
  264. err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
  265. isChangeGroup = false
  266. }
  267. } else if len(adviceSlice) > 1 {
  268. //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要重新分配组,如果相同直接修改,不需要分配组
  269. if advice.StartTime == sourceAdvice.StartTime {
  270. err = service.UpdateDoctorAdvice(&advice)
  271. isChangeGroup = false
  272. } else {
  273. gruopNo := service.GetMaxAdviceGroupID(adminUserInfo.Org.Id)
  274. gruopNo = gruopNo + 1
  275. advice.GroupNo = gruopNo
  276. err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
  277. isChangeGroup = true
  278. }
  279. }
  280. } else {
  281. isChangeGroup = false
  282. err = service.UpdateDoctorAdvice(&advice)
  283. }
  284. if err != nil {
  285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  286. return
  287. }
  288. if !isChangeGroup {
  289. c.ServeSuccessJSON(map[string]interface{}{
  290. "msg": "ok",
  291. "advice": advice,
  292. "isChange": isChangeGroup, //方便前端处理数据
  293. })
  294. } else {
  295. newGroupAdvice, err := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
  296. if err != nil {
  297. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  298. return
  299. }
  300. c.ServeSuccessJSON(map[string]interface{}{
  301. "msg": "ok",
  302. "advice": newGroupAdvice,
  303. "isChange": isChangeGroup, //方便前端处理数据
  304. })
  305. }
  306. return
  307. }
  308. func (c *PatientApiController) StopDoctorAdvice() {
  309. id, _ := c.GetInt64("id", 0)
  310. if id <= 0 {
  311. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  312. return
  313. }
  314. adminUserInfo := c.GetMobileAdminUserInfo()
  315. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  316. if advice.ID == 0 {
  317. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  318. return
  319. }
  320. //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  321. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  322. // return
  323. //}
  324. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  325. //
  326. //if appRole.UserType == 3 {
  327. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  328. // if getPermissionErr != nil {
  329. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  330. // return
  331. // } else if headNursePermission == nil {
  332. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  333. // return
  334. // }
  335. //}
  336. if advice.StopState == 1 {
  337. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  338. return
  339. }
  340. dataBody := make(map[string]interface{}, 0)
  341. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  342. if err != nil {
  343. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  344. return
  345. }
  346. timeLayout := "2006-01-02"
  347. loc, _ := time.LoadLocation("Local")
  348. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  349. utils.ErrorLog("stop_time")
  350. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  351. return
  352. }
  353. stopTime, _ := dataBody["stop_time"].(string)
  354. if len(stopTime) == 0 {
  355. utils.ErrorLog("len(stop_time) == 0")
  356. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  357. return
  358. }
  359. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  360. if err != nil {
  361. utils.ErrorLog(err.Error())
  362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  363. return
  364. }
  365. advice.StopTime = theTime.Unix()
  366. if dataBody["stop_reason"] == nil || reflect.TypeOf(dataBody["stop_reason"]).String() != "string" {
  367. utils.ErrorLog("stop_reason")
  368. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  369. return
  370. }
  371. stopReason, _ := dataBody["stop_reason"].(string)
  372. if len(stopReason) == 0 {
  373. utils.ErrorLog("len(stop_reason) == 0")
  374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  375. return
  376. }
  377. advice.StopReason = stopReason
  378. advice.Status = 1
  379. advice.UpdatedTime = time.Now().Unix()
  380. advice.StopDoctor = adminUserInfo.AdminUser.Id
  381. advice.StopState = 1
  382. advice.StopTime = time.Now().Unix()
  383. advice.Modifier = adminUserInfo.AdminUser.Id
  384. err = service.StopDoctorAdvice(&advice)
  385. if err != nil {
  386. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  387. return
  388. }
  389. c.ServeSuccessJSON(map[string]interface{}{
  390. "msg": "ok",
  391. "advice": advice,
  392. })
  393. return
  394. }
  395. func (c *PatientApiController) DeleteDoctorAdvice() {
  396. id, _ := c.GetInt64("id", 0)
  397. if id <= 0 {
  398. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  399. return
  400. }
  401. adminUserInfo := c.GetMobileAdminUserInfo()
  402. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  403. if advice.ID == 0 {
  404. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  405. return
  406. }
  407. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  408. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  409. // return
  410. //}
  411. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  412. //
  413. //if appRole.UserType == 3 {
  414. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  415. // if getPermissionErr != nil {
  416. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  417. // return
  418. // } else if headNursePermission == nil {
  419. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  420. // return
  421. // }
  422. //}
  423. advice.UpdatedTime = time.Now().Unix()
  424. advice.Status = 0
  425. advice.Modifier = adminUserInfo.AdminUser.Id
  426. err := service.DeleteDoctorAdvice(&advice)
  427. if err != nil {
  428. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  429. return
  430. }
  431. c.ServeSuccessJSON(map[string]interface{}{
  432. "msg": "ok",
  433. })
  434. return
  435. }
  436. func (c *PatientApiController) ExecDoctorAdvice() {
  437. execution_time := c.GetString("execution_time")
  438. groupno, _ := c.GetInt64("groupno", -1)
  439. var ids []string
  440. if groupno == 0 {
  441. advice_ids := c.GetString("advice_id")
  442. ids = strings.Split(advice_ids, ",")
  443. }
  444. if groupno < 0 {
  445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  446. return
  447. }
  448. if len(execution_time) <= 0 {
  449. utils.ErrorLog("execution_time")
  450. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  451. return
  452. }
  453. timeLayout2 := "2006-01-02 15:04:05"
  454. loc, _ := time.LoadLocation("Local")
  455. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  456. if errs != nil {
  457. utils.ErrorLog(errs.Error())
  458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  459. return
  460. }
  461. adminUserInfo := c.GetMobileAdminUserInfo()
  462. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  463. //
  464. //if appRole.UserType == 2 || appRole.UserType == 1 {
  465. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  466. // if getPermissionErr != nil {
  467. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  468. // return
  469. // } else if headNursePermission == nil {
  470. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  471. // return
  472. // }
  473. //}
  474. var advice models.DoctorAdvice
  475. if groupno > 0 {
  476. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  477. for _, item := range advices {
  478. if item.ExecutionState == 2 {
  479. advice = item
  480. }
  481. }
  482. } else {
  483. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  484. for _, item := range advices {
  485. if item.ExecutionState == 2 {
  486. advice = item
  487. }
  488. }
  489. }
  490. if advice.ExecutionState == 1 {
  491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  492. return
  493. }
  494. if advice.Checker >= 0 && advice.Checker == adminUserInfo.AdminUser.Id {
  495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  496. return
  497. }
  498. fmt.Println(theTime)
  499. fmt.Println(theTime.Unix())
  500. fmt.Println(advice.StartTime)
  501. if advice.StartTime > theTime.Unix() {
  502. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  503. return
  504. }
  505. execution_staff := adminUserInfo.AdminUser.Id
  506. advices := models.DoctorAdvice{
  507. ExecutionStaff: execution_staff,
  508. ExecutionTime: theTime.Unix(),
  509. UpdatedTime: time.Now().Unix(),
  510. }
  511. var err error
  512. if groupno > 0 {
  513. err = service.ExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  514. } else {
  515. err = service.BatchExceOldDoctorAdvice(&advices, ids)
  516. }
  517. if err != nil {
  518. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  519. return
  520. }
  521. advice.ExecutionStaff = execution_staff
  522. advice.ExecutionTime = theTime.Unix()
  523. advice.ExecutionState = 1
  524. c.ServeSuccessJSON(map[string]interface{}{
  525. "msg": "ok",
  526. "advice": advice,
  527. "ids": ids,
  528. })
  529. return
  530. }
  531. func (c *PatientApiController) ModifyExecDoctorAdvice() {
  532. execution_time := c.GetString("execution_time")
  533. groupno, _ := c.GetInt64("groupno", -1)
  534. var ids []string
  535. if groupno == 0 {
  536. advice_ids := c.GetString("advice_id")
  537. ids = strings.Split(advice_ids, ",")
  538. }
  539. if groupno < 0 {
  540. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  541. return
  542. }
  543. if len(execution_time) <= 0 {
  544. utils.ErrorLog("execution_time")
  545. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  546. return
  547. }
  548. timeLayout2 := "2006-01-02 15:04:05"
  549. loc, _ := time.LoadLocation("Local")
  550. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  551. if errs != nil {
  552. utils.ErrorLog(errs.Error())
  553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  554. return
  555. }
  556. adminUserInfo := c.GetMobileAdminUserInfo()
  557. var advice models.DoctorAdvice
  558. if groupno > 0 {
  559. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  560. for _, item := range advices {
  561. if item.ExecutionState == 1 {
  562. advice = item
  563. }
  564. }
  565. } else {
  566. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  567. for _, item := range advices {
  568. if item.ExecutionState == 1 {
  569. advice = item
  570. }
  571. }
  572. }
  573. //if advice.ExecutionStaff != adminUserInfo.AdminUser.Id {
  574. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  575. // if getPermissionErr != nil {
  576. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  577. // return
  578. // } else if headNursePermission == nil {
  579. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  580. // return
  581. // }
  582. //}
  583. if advice.StartTime > theTime.Unix() {
  584. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  585. return
  586. }
  587. advices := models.DoctorAdvice{
  588. ExecutionTime: theTime.Unix(),
  589. UpdatedTime: time.Now().Unix(),
  590. }
  591. var err error
  592. if groupno > 0 {
  593. err = service.ModifyExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  594. } else {
  595. err = service.BatchModifyExceOldDoctorAdvice(&advices, ids)
  596. }
  597. if err != nil {
  598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  599. return
  600. }
  601. advice.ExecutionTime = theTime.Unix()
  602. c.ServeSuccessJSON(map[string]interface{}{
  603. "msg": "ok",
  604. "advice": advice,
  605. "ids": ids,
  606. })
  607. return
  608. }
  609. func (c *PatientApiController) CheckDoctorAdvice() {
  610. groupno, _ := c.GetInt64("groupno", -1)
  611. var ids []string
  612. if groupno == 0 {
  613. advice_ids := c.GetString("advice_id")
  614. ids = strings.Split(advice_ids, ",")
  615. if len(ids) <= 0 {
  616. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  617. return
  618. }
  619. }
  620. if groupno < 0 {
  621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  622. return
  623. }
  624. adminUserInfo := c.GetMobileAdminUserInfo()
  625. //
  626. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  627. //if appRole.UserType != 3 {
  628. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  629. // if getPermissionErr != nil {
  630. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  631. // return
  632. // } else if headNursePermission == nil {
  633. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  634. // return
  635. // }
  636. //}
  637. var advice models.DoctorAdvice
  638. if groupno > 0 {
  639. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  640. for _, item := range advices {
  641. if item.CheckState == 0 {
  642. advice = item
  643. }
  644. }
  645. if advice.CheckState == 1 {
  646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  647. return
  648. }
  649. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  650. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  651. return
  652. }
  653. } else {
  654. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  655. for _, item := range advices {
  656. if item.CheckState == 0 {
  657. advice = item
  658. }
  659. }
  660. if advice.CheckState == 1 {
  661. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  662. return
  663. }
  664. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  666. return
  667. }
  668. }
  669. checker := adminUserInfo.AdminUser.Id
  670. theTime := time.Now()
  671. advices := models.DoctorAdvice{
  672. CheckTime: theTime.Unix(),
  673. Checker: checker,
  674. UpdatedTime: time.Now().Unix(),
  675. }
  676. fmt.Println()
  677. var err error
  678. if groupno > 0 {
  679. err = service.CheckDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  680. } else {
  681. err = service.BatchCheckOldDoctorAdvice(&advices, ids)
  682. }
  683. if err != nil {
  684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  685. return
  686. }
  687. advice.Checker = checker
  688. advice.CheckTime = theTime.Unix()
  689. advice.CheckState = 1
  690. c.ServeSuccessJSON(map[string]interface{}{
  691. "msg": "ok",
  692. "advice": advice,
  693. })
  694. return
  695. }
  696. func (c *PatientApiController) EditAssessmentBeforeDislysis() {
  697. id, _ := c.GetInt64("patient", 0)
  698. assessmentDate := c.GetString("assessment_date", "")
  699. if id <= 0 || len(assessmentDate) != 10 {
  700. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  701. return
  702. }
  703. timeLayout := "2006-01-02"
  704. loc, _ := time.LoadLocation("Local")
  705. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", assessmentDate+" 00:00:00", loc)
  706. if err != nil {
  707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  708. return
  709. }
  710. theAssessmentDateTime := theTime.Unix()
  711. adminUserInfo := c.GetMobileAdminUserInfo()
  712. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  713. if patient.ID == 0 {
  714. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  715. return
  716. }
  717. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  718. if getPEErr != nil {
  719. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  720. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  721. return
  722. }
  723. //templateInfo,_ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  724. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  725. var evaluation models.PredialysisEvaluation
  726. if theEvaluation != nil {
  727. //if appRole.UserType == 2 || appRole.UserType == 1 {
  728. evaluation = *theEvaluation
  729. //} else {
  730. // if theEvaluation.Creater != adminUserInfo.AdminUser.Id && theEvaluation.Creater != 0 {
  731. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  732. // if getPermissionErr != nil {
  733. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  734. // return
  735. // } else if headNursePermission == nil {
  736. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  737. // return
  738. // }
  739. // } else {
  740. // evaluation = *theEvaluation
  741. // }
  742. //}
  743. }
  744. code := predialysisEvaluationFormData(&evaluation, c.Ctx.Input.RequestBody)
  745. if code > 0 {
  746. c.ServeFailJSONWithSGJErrorCode(code)
  747. return
  748. }
  749. if theEvaluation == nil {
  750. evaluation.CreatedTime = time.Now().Unix()
  751. evaluation.Status = 1
  752. evaluation.AssessmentDate = theAssessmentDateTime
  753. evaluation.PatientId = id
  754. evaluation.UserOrgId = adminUserInfo.Org.Id
  755. //if appRole.UserType == 2 || appRole.UserType == 1 {
  756. // evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  757. // evaluation.AssessmentTime = time.Now().Unix()
  758. //} else {
  759. evaluation.Creater = adminUserInfo.AdminUser.Id
  760. //}
  761. } else {
  762. evaluation.UpdatedTime = time.Now().Unix()
  763. evaluation.Evaluator = adminUserInfo.AdminUser.Id
  764. //if appRole.UserType == 2 || appRole.UserType == 1 {
  765. // evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  766. // evaluation.AssessmentTime = time.Now().Unix()
  767. //} else {
  768. evaluation.Modifier = adminUserInfo.AdminUser.Id
  769. if evaluation.Creater == 0 {
  770. evaluation.Creater = adminUserInfo.AdminUser.Id
  771. }
  772. //}
  773. }
  774. //新增逻辑
  775. var dewater_amount float64
  776. dewater_amount = 0
  777. if evaluation.DryWeight > 0 {
  778. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  779. if dewater_amount <= 0 {
  780. dewater_amount = 0
  781. }
  782. } else {
  783. dewater_amount = 0
  784. }
  785. // 计算透析处方的相关超滤量
  786. schedual, _ := service.MobileGetSchedualDetail(adminUserInfo.Org.Id, patient.ID, theAssessmentDateTime)
  787. var lastDialysisPrescribe *models.DialysisPrescription
  788. var dialysisSolution *models.DialysisSolution
  789. var dialysisPrescribe *models.DialysisPrescription
  790. var system_dialysisPrescribe *models.SystemPrescription
  791. var mode_id int64
  792. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  793. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeId(adminUserInfo.Org.Id, id, schedual.ModeId)
  794. if schedual != nil {
  795. // 获取透析模版
  796. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminUserInfo.Org.Id, id, schedual.ModeId)
  797. system_dialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminUserInfo.Org.Id, schedual.ModeId)
  798. mode_id = schedual.ModeId
  799. } else {
  800. // 获取透析模版
  801. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.Org.Id, id)
  802. if dialysisPrescribe == nil && dialysisSolution != nil {
  803. mode_id = dialysisSolution.ModeId
  804. }
  805. if dialysisPrescribe == nil && dialysisSolution == nil {
  806. mode_id = 0
  807. }
  808. }
  809. // 插入透析处方
  810. if dialysisPrescribe == nil && dialysisSolution != nil {
  811. var newprescribe models.DialysisPrescription
  812. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  813. newprescribe.PatientId = dialysisSolution.PatientId
  814. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  815. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  816. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  817. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  818. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  819. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  820. newprescribe.ModeId = dialysisSolution.ModeId
  821. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  822. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  823. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  824. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  825. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  826. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  827. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  828. newprescribe.Glucose = dialysisSolution.Glucose
  829. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  830. newprescribe.Kalium = dialysisSolution.Kalium
  831. newprescribe.Sodium = dialysisSolution.Sodium
  832. newprescribe.Calcium = dialysisSolution.Calcium
  833. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  834. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  835. newprescribe.Conductivity = dialysisSolution.Conductivity
  836. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  837. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  838. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  839. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  840. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  841. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  842. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  843. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  844. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  845. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  846. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  847. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  848. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  849. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  850. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  851. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  852. newprescribe.CreatedTime = time.Now().Unix()
  853. newprescribe.UpdatedTime = time.Now().Unix()
  854. newprescribe.RecordDate = theAssessmentDateTime
  855. newprescribe.DewaterAmount = dewater_amount
  856. newprescribe.TargetUltrafiltration = dewater_amount
  857. newprescribe.Status = 1
  858. err := service.AddSigleRecord(&newprescribe)
  859. if err != nil {
  860. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  861. }
  862. }
  863. if dialysisPrescribe == nil && dialysisSolution == nil {
  864. if lastDialysisPrescribe != nil {
  865. var newprescribe models.DialysisPrescription
  866. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  867. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  868. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  869. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  870. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  871. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  872. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  873. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  874. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  875. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  876. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  877. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  878. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  879. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  880. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  881. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  882. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  883. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  884. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  885. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  886. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  887. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  888. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  889. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  890. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  891. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  892. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  893. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  894. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  895. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  896. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  897. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  898. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  899. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  900. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  901. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  902. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  903. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  904. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  905. newprescribe.CreatedTime = time.Now().Unix()
  906. newprescribe.UpdatedTime = time.Now().Unix()
  907. newprescribe.RecordDate = theAssessmentDateTime
  908. newprescribe.DewaterAmount = dewater_amount
  909. newprescribe.TargetUltrafiltration = dewater_amount
  910. newprescribe.Status = 1
  911. err := service.AddSigleRecord(&newprescribe)
  912. if err != nil {
  913. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  914. }
  915. } else if system_dialysisPrescribe != nil {
  916. var newprescribe models.DialysisPrescription
  917. newprescribe.UserOrgId = system_dialysisPrescribe.UserOrgId
  918. newprescribe.PatientId = id
  919. newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
  920. newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
  921. newprescribe.AnticoagulantWeichi = system_dialysisPrescribe.AnticoagulantWeichi
  922. newprescribe.AnticoagulantZongliang = system_dialysisPrescribe.AnticoagulantZongliang
  923. newprescribe.AnticoagulantGaimingcheng = system_dialysisPrescribe.AnticoagulantGaimingcheng
  924. newprescribe.AnticoagulantGaijiliang = system_dialysisPrescribe.AnticoagulantGaijiliang
  925. newprescribe.ModeId = system_dialysisPrescribe.ModeId
  926. newprescribe.DialysisDuration = system_dialysisPrescribe.DialysisDuration
  927. newprescribe.ReplacementWay = system_dialysisPrescribe.ReplacementWay
  928. newprescribe.HemodialysisMachine = system_dialysisPrescribe.HemodialysisMachine
  929. newprescribe.BloodFilter = system_dialysisPrescribe.BloodFilter
  930. newprescribe.PerfusionApparatus = system_dialysisPrescribe.PerfusionApparatus
  931. newprescribe.BloodFlowVolume = system_dialysisPrescribe.BloodFlowVolume
  932. newprescribe.DisplaceLiqui = system_dialysisPrescribe.DisplaceLiqui
  933. newprescribe.Glucose = system_dialysisPrescribe.Glucose
  934. newprescribe.DialysateFlow = system_dialysisPrescribe.DialysateFlow
  935. newprescribe.Kalium = system_dialysisPrescribe.Kalium
  936. newprescribe.Sodium = system_dialysisPrescribe.Sodium
  937. newprescribe.Calcium = system_dialysisPrescribe.Calcium
  938. newprescribe.Bicarbonate = system_dialysisPrescribe.Bicarbonate
  939. newprescribe.DialysateTemperature = system_dialysisPrescribe.DialysateTemperature
  940. newprescribe.Conductivity = system_dialysisPrescribe.Conductivity
  941. newprescribe.BodyFluid = system_dialysisPrescribe.BodyFluid
  942. newprescribe.SpecialMedicine = system_dialysisPrescribe.SpecialMedicine
  943. newprescribe.SpecialMedicineOther = system_dialysisPrescribe.SpecialMedicineOther
  944. newprescribe.DisplaceLiquiPart = system_dialysisPrescribe.DisplaceLiquiPart
  945. newprescribe.DisplaceLiquiValue = system_dialysisPrescribe.DisplaceLiquiValue
  946. newprescribe.BloodAccess = system_dialysisPrescribe.BloodAccess
  947. newprescribe.Ultrafiltration = system_dialysisPrescribe.Ultrafiltration
  948. newprescribe.DialysisDurationHour = system_dialysisPrescribe.DialysisDurationHour
  949. newprescribe.DialysisDurationMinute = system_dialysisPrescribe.DialysisDurationMinute
  950. newprescribe.DialysateFormulation = system_dialysisPrescribe.DialysateFormulation
  951. newprescribe.Dialyzer = system_dialysisPrescribe.Dialyzer
  952. newprescribe.ReplacementTotal = system_dialysisPrescribe.ReplacementTotal
  953. newprescribe.DialyzerPerfusionApparatus = system_dialysisPrescribe.DialyzerPerfusionApparatus
  954. newprescribe.BodyFluidOther = system_dialysisPrescribe.BodyFluidOther
  955. newprescribe.TargetKtv = system_dialysisPrescribe.TargetKtv
  956. newprescribe.CreatedTime = time.Now().Unix()
  957. newprescribe.UpdatedTime = time.Now().Unix()
  958. newprescribe.RecordDate = theAssessmentDateTime
  959. newprescribe.DewaterAmount = dewater_amount
  960. newprescribe.TargetUltrafiltration = dewater_amount
  961. newprescribe.Status = 1
  962. err := service.AddSigleRecord(&newprescribe)
  963. if err != nil {
  964. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  965. }
  966. } else {
  967. var newprescribe models.DialysisPrescription
  968. newprescribe.UserOrgId = adminUserInfo.Org.Id
  969. newprescribe.PatientId = id
  970. newprescribe.ModeId = mode_id
  971. newprescribe.CreatedTime = time.Now().Unix()
  972. newprescribe.UpdatedTime = time.Now().Unix()
  973. newprescribe.RecordDate = theAssessmentDateTime
  974. newprescribe.DewaterAmount = dewater_amount
  975. newprescribe.TargetUltrafiltration = dewater_amount
  976. newprescribe.Status = 1
  977. err := service.AddSigleRecord(&newprescribe)
  978. if err != nil {
  979. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  980. }
  981. }
  982. }
  983. // 手动修改透前评估的时候,如果透析处方已经存在,则不修改对应的透析处方
  984. // if dialysisPrescribe != nil {
  985. // dialysisPrescribe.UpdatedTime = time.Now().Unix()
  986. // dialysisPrescribe.RecordDate = theAssessmentDateTime
  987. // dialysisPrescribe.DewaterAmount = dewater_amount
  988. // dialysisPrescribe.TargetUltrafiltration = dewater_amount
  989. // dialysisPrescribe.Status = 1
  990. // updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
  991. // if updateErr != nil {
  992. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  993. // }
  994. // }
  995. err = service.UpadatePredialysisEvaluation(&evaluation)
  996. if err != nil {
  997. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  998. return
  999. }
  1000. c.ServeSuccessJSON(map[string]interface{}{
  1001. "msg": "ok",
  1002. "evaluation": evaluation,
  1003. })
  1004. return
  1005. }
  1006. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  1007. dataBody := make(map[string]interface{}, 0)
  1008. err := json.Unmarshal(data, &dataBody)
  1009. utils.InfoLog(string(data))
  1010. if err != nil {
  1011. utils.ErrorLog(err.Error())
  1012. code = enums.ErrorCodeParamWrong
  1013. return
  1014. }
  1015. // if method == "create" {
  1016. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  1017. utils.ErrorLog("mode")
  1018. code = enums.ErrorCodeParamWrong
  1019. return
  1020. }
  1021. mode := int64(dataBody["mode"].(float64))
  1022. if mode <= 0 {
  1023. utils.ErrorLog("mode <= 0")
  1024. code = enums.ErrorCodeParamWrong
  1025. return
  1026. }
  1027. solution.ModeId = mode
  1028. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  1029. utils.ErrorLog("mode_name")
  1030. code = enums.ErrorCodeParamWrong
  1031. return
  1032. }
  1033. modeName, _ := dataBody["mode_name"].(string)
  1034. if len(modeName) == 0 {
  1035. utils.ErrorLog("len(mode_name) == 0")
  1036. code = enums.ErrorCodeParamWrong
  1037. return
  1038. }
  1039. solution.ModeName = modeName
  1040. solution.Name = modeName
  1041. // }
  1042. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  1043. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  1044. solution.DialysisDuration = dialysisDuration
  1045. }
  1046. if dataBody["dialysis_duration"] != nil {
  1047. if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  1048. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  1049. solution.DialysisDuration = dialysisDuration
  1050. } else if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "float64" {
  1051. dialysisDuration := dataBody["dialysis_duration"].(float64)
  1052. solution.DialysisDuration = dialysisDuration
  1053. }
  1054. }
  1055. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  1056. dialyzer := int64(dataBody["dialyzer"].(float64))
  1057. solution.Dialyzer = dialyzer
  1058. }
  1059. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  1060. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  1061. solution.PerfusionApparatus = perfusionApparatus
  1062. }
  1063. if dataBody["blood_flow_volume"] != nil {
  1064. if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  1065. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  1066. solution.BloodFlowVolume = bloodFlowVolume
  1067. } else if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "float64" {
  1068. bloodFlowVolume := dataBody["blood_flow_volume"].(float64)
  1069. solution.BloodFlowVolume = bloodFlowVolume
  1070. }
  1071. }
  1072. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  1073. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  1074. solution.HemodialysisMachine = hemodialysisMachine
  1075. }
  1076. if dataBody["dewater"] != nil {
  1077. if reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  1078. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  1079. solution.Dewater = dewater
  1080. } else if reflect.TypeOf(dataBody["dewater"]).String() == "float64" {
  1081. dewater := dataBody["dewater"].(float64)
  1082. solution.Dewater = dewater
  1083. }
  1084. }
  1085. if dataBody["replacement_total"] != nil {
  1086. if reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  1087. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  1088. solution.ReplacementTotal = replacementTotal
  1089. } else if reflect.TypeOf(dataBody["replacement_total"]).String() == "float64" {
  1090. replacementTotal := dataBody["replacement_total"].(float64)
  1091. solution.ReplacementTotal = replacementTotal
  1092. }
  1093. }
  1094. if dataBody["displace_liqui"] != nil {
  1095. if reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  1096. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  1097. solution.DisplaceLiqui = displaceLiqui
  1098. } else if reflect.TypeOf(dataBody["displace_liqui"]).String() == "float64" {
  1099. displaceLiqui := dataBody["displace_liqui"].(float64)
  1100. solution.DisplaceLiqui = displaceLiqui
  1101. }
  1102. }
  1103. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  1104. replacementWay := int64(dataBody["replacement_way"].(float64))
  1105. solution.ReplacementWay = replacementWay
  1106. }
  1107. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  1108. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  1109. solution.Anticoagulant = anticoagulant
  1110. }
  1111. if dataBody["anticoagulant_shouji"] != nil {
  1112. if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  1113. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  1114. solution.AnticoagulantShouji = anticoagulantShouji
  1115. } else if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "float64" {
  1116. anticoagulantShouji := dataBody["anticoagulant_shouji"].(float64)
  1117. solution.AnticoagulantShouji = anticoagulantShouji
  1118. }
  1119. }
  1120. if dataBody["anticoagulant_weichi"] != nil {
  1121. if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  1122. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  1123. solution.AnticoagulantWeichi = anticoagulantWeichi
  1124. } else if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "float64" {
  1125. anticoagulantWeichi := dataBody["anticoagulant_weichi"].(float64)
  1126. solution.AnticoagulantWeichi = anticoagulantWeichi
  1127. }
  1128. }
  1129. if dataBody["anticoagulant_zongliang"] != nil {
  1130. if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  1131. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  1132. solution.AnticoagulantZongliang = anticoagulantZongliang
  1133. } else if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "float64" {
  1134. anticoagulantZongliang := dataBody["anticoagulant_zongliang"].(float64)
  1135. solution.AnticoagulantZongliang = anticoagulantZongliang
  1136. }
  1137. }
  1138. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  1139. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  1140. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  1141. }
  1142. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  1143. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  1144. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  1145. }
  1146. if dataBody["kalium"] != nil {
  1147. if reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  1148. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  1149. solution.Kalium = kalium
  1150. } else if reflect.TypeOf(dataBody["kalium"]).String() == "float64" {
  1151. kalium := dataBody["kalium"].(float64)
  1152. solution.Kalium = kalium
  1153. }
  1154. }
  1155. if dataBody["sodium"] != nil {
  1156. if reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  1157. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  1158. solution.Sodium = sodium
  1159. } else if reflect.TypeOf(dataBody["sodium"]).String() == "float64" {
  1160. sodium := dataBody["sodium"].(float64)
  1161. solution.Sodium = sodium
  1162. }
  1163. }
  1164. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  1165. if reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  1166. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  1167. solution.Calcium = calcium
  1168. } else if reflect.TypeOf(dataBody["calcium"]).String() == "float64" {
  1169. calcium := dataBody["calcium"].(float64)
  1170. solution.Calcium = calcium
  1171. }
  1172. }
  1173. if dataBody["bicarbonate"] != nil {
  1174. if reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  1175. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  1176. solution.Bicarbonate = bicarbonate
  1177. } else if reflect.TypeOf(dataBody["bicarbonate"]).String() == "float64" {
  1178. bicarbonate := dataBody["bicarbonate"].(float64)
  1179. solution.Bicarbonate = bicarbonate
  1180. }
  1181. }
  1182. if dataBody["glucose"] != nil {
  1183. if reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  1184. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  1185. solution.Glucose = glucose
  1186. } else if reflect.TypeOf(dataBody["glucose"]).String() == "float64" {
  1187. glucose := dataBody["glucose"].(float64)
  1188. solution.Glucose = glucose
  1189. }
  1190. }
  1191. // if dataBody["dry_weight"] != nil {
  1192. // if reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  1193. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  1194. // solution.DryWeight = dryWeight
  1195. // } else if reflect.TypeOf(dataBody["dry_weight"]).String() == "float64" {
  1196. // dryWeight := dataBody["dry_weight"].(float64)
  1197. // solution.DryWeight = dryWeight
  1198. // }
  1199. // }
  1200. if dataBody["dialysate_flow"] != nil {
  1201. if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  1202. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  1203. solution.DialysateFlow = dialysateFlow
  1204. } else if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "float64" {
  1205. dialysateFlow := dataBody["dialysate_flow"].(float64)
  1206. solution.DialysateFlow = dialysateFlow
  1207. }
  1208. }
  1209. if dataBody["dialysate_temperature"] != nil {
  1210. if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  1211. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  1212. solution.DialysateTemperature = dialysateTemperature
  1213. } else if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "float64" {
  1214. dialysateTemperature := dataBody["dialysate_temperature"].(float64)
  1215. solution.DialysateTemperature = dialysateTemperature
  1216. }
  1217. }
  1218. if dataBody["conductivity"] != nil {
  1219. if reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  1220. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  1221. solution.Conductivity = conductivity
  1222. } else if reflect.TypeOf(dataBody["conductivity"]).String() == "float64" {
  1223. conductivity := dataBody["conductivity"].(float64)
  1224. solution.Conductivity = conductivity
  1225. }
  1226. }
  1227. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  1228. remark := dataBody["remark"].(string)
  1229. solution.Remark = remark
  1230. }
  1231. if dataBody["dialysis_duration_hour"] != nil {
  1232. if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  1233. dialysisDurationHour, _ := strconv.ParseInt(dataBody["dialysis_duration_hour"].(string), 10, 64)
  1234. solution.DialysisDurationHour = dialysisDurationHour
  1235. } else if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "float64" {
  1236. dialysisDurationHour := dataBody["dialysis_duration_hour"].(float64)
  1237. solution.DialysisDurationHour = int64(dialysisDurationHour)
  1238. }
  1239. }
  1240. if dataBody["dialysis_duration_minute"] != nil {
  1241. if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  1242. dialysisDurationMinute, _ := strconv.ParseInt(dataBody["dialysis_duration_minute"].(string), 10, 64)
  1243. solution.DialysisDurationMinute = dialysisDurationMinute
  1244. } else if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "float64" {
  1245. dialysisDurationMinute := dataBody["dialysis_duration_minute"].(float64)
  1246. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  1247. }
  1248. }
  1249. if dataBody["target_ultrafiltration"] != nil {
  1250. if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  1251. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  1252. solution.TargetUltrafiltration = targetUltrafiltration
  1253. } else if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "float64" {
  1254. targetUltrafiltration := dataBody["target_ultrafiltration"].(float64)
  1255. solution.TargetUltrafiltration = targetUltrafiltration
  1256. }
  1257. }
  1258. if dataBody["dialysate_formulation"] != nil {
  1259. if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "string" {
  1260. dialysateFormulation, _ := strconv.ParseInt(dataBody["dialysate_formulation"].(string), 10, 64)
  1261. solution.DialysateFormulation = dialysateFormulation
  1262. } else if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  1263. dialysateFormulation := dataBody["dialysate_formulation"].(float64)
  1264. solution.DialysateFormulation = int64(dialysateFormulation)
  1265. }
  1266. }
  1267. return
  1268. }
  1269. func predialysisEvaluationFormData(evaluation *models.PredialysisEvaluation, data []byte) (code int) {
  1270. dataBody := make(map[string]interface{}, 0)
  1271. err := json.Unmarshal(data, &dataBody)
  1272. utils.InfoLog(string(data))
  1273. if err != nil {
  1274. utils.ErrorLog(err.Error())
  1275. code = enums.ErrorCodeParamWrong
  1276. return
  1277. }
  1278. if dataBody["weight_before"] != nil && reflect.TypeOf(dataBody["weight_before"]).String() == "string" {
  1279. weightVefore, _ := strconv.ParseFloat(dataBody["weight_before"].(string), 64)
  1280. evaluation.WeightBefore = weightVefore
  1281. }
  1282. // fmt.Println(dataBody["dry_weight"])
  1283. // fmt.Println(reflect.TypeOf(dataBody["dry_weight"]).String())
  1284. if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  1285. additionalWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  1286. fmt.Println(additionalWeight)
  1287. evaluation.DryWeight = additionalWeight
  1288. }
  1289. if dataBody["additional_weight"] != nil && reflect.TypeOf(dataBody["additional_weight"]).String() == "string" {
  1290. additionalWeight, _ := strconv.ParseFloat(dataBody["additional_weight"].(string), 64)
  1291. fmt.Println(additionalWeight)
  1292. evaluation.AdditionalWeight = additionalWeight
  1293. }
  1294. if dataBody["temperature"] != nil && reflect.TypeOf(dataBody["temperature"]).String() == "string" {
  1295. Temperature, _ := strconv.ParseFloat(dataBody["temperature"].(string), 64)
  1296. evaluation.Temperature = Temperature
  1297. }
  1298. if dataBody["systolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["systolic_blood_pressure"]).String() == "string" {
  1299. systolicBloodPressure, _ := strconv.ParseFloat(dataBody["systolic_blood_pressure"].(string), 64)
  1300. evaluation.SystolicBloodPressure = systolicBloodPressure
  1301. }
  1302. if dataBody["diastolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["diastolic_blood_pressure"]).String() == "string" {
  1303. diastolicBloodPressure, _ := strconv.ParseFloat(dataBody["diastolic_blood_pressure"].(string), 64)
  1304. evaluation.DiastolicBloodPressure = diastolicBloodPressure
  1305. }
  1306. if dataBody["pulse_frequency"] != nil && reflect.TypeOf(dataBody["pulse_frequency"]).String() == "string" {
  1307. pulseFrequency, _ := strconv.ParseFloat(dataBody["pulse_frequency"].(string), 64)
  1308. evaluation.PulseFrequency = pulseFrequency
  1309. }
  1310. if dataBody["breathing_rate"] != nil && reflect.TypeOf(dataBody["breathing_rate"]).String() == "string" {
  1311. breathingRate, _ := strconv.ParseFloat(dataBody["breathing_rate"].(string), 64)
  1312. evaluation.BreathingRate = breathingRate
  1313. }
  1314. if dataBody["last_post_dialysis"] != nil && reflect.TypeOf(dataBody["last_post_dialysis"]).String() == "string" {
  1315. lastPostDialysis, _ := dataBody["last_post_dialysis"].(string)
  1316. evaluation.LastPostDialysis = lastPostDialysis
  1317. }
  1318. if dataBody["dialysis_interphase"] != nil && reflect.TypeOf(dataBody["dialysis_interphase"]).String() == "string" {
  1319. dialysisInterphase, _ := dataBody["dialysis_interphase"].(string)
  1320. evaluation.DialysisInterphase = dialysisInterphase
  1321. }
  1322. if dataBody["symptom_before_dialysis"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis"]).String() == "string" {
  1323. symptomBeforeDialysis, _ := dataBody["symptom_before_dialysis"].(string)
  1324. evaluation.SymptomBeforeDialysis = symptomBeforeDialysis
  1325. }
  1326. if dataBody["catheter"] != nil && reflect.TypeOf(dataBody["catheter"]).String() == "string" {
  1327. catheter, _ := dataBody["catheter"].(string)
  1328. evaluation.Catheter = catheter
  1329. }
  1330. if dataBody["catheter_bend"] != nil && reflect.TypeOf(dataBody["catheter_bend"]).String() == "float64" {
  1331. catheter_bend := int(dataBody["catheter_bend"].(float64))
  1332. evaluation.CatheterBend = catheter_bend
  1333. }
  1334. if dataBody["complication"] != nil && reflect.TypeOf(dataBody["complication"]).String() == "string" {
  1335. Complication, _ := dataBody["complication"].(string)
  1336. evaluation.Complication = Complication
  1337. }
  1338. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  1339. remark := dataBody["remark"].(string)
  1340. evaluation.Remark = remark
  1341. }
  1342. if dataBody["machine_type"] != nil && reflect.TypeOf(dataBody["machine_type"]).String() == "string" {
  1343. machine_type := dataBody["machine_type"].(string)
  1344. evaluation.MachineType = machine_type
  1345. }
  1346. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "float64" {
  1347. blood_access_part_id := int64(dataBody["blood_access_part_id"].(float64))
  1348. evaluation.BloodAccessPartId = blood_access_part_id
  1349. }
  1350. if dataBody["blood_access_part_opera_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_opera_id"]).String() == "float64" {
  1351. blood_access_part_opera_id := int64(dataBody["blood_access_part_opera_id"].(float64))
  1352. evaluation.BloodAccessPartOperaId = blood_access_part_opera_id
  1353. }
  1354. if dataBody["internal_fistula"] != nil && reflect.TypeOf(dataBody["internal_fistula"]).String() == "string" {
  1355. internal_fistula, _ := dataBody["internal_fistula"].(string)
  1356. evaluation.InternalFistula = internal_fistula
  1357. }
  1358. if dataBody["internal_fistula_skin"] != nil && reflect.TypeOf(dataBody["internal_fistula_skin"]).String() == "string" {
  1359. internal_fistula_skin := dataBody["internal_fistula_skin"].(string)
  1360. evaluation.InternalFistulaSkin = internal_fistula_skin
  1361. }
  1362. if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "float64" {
  1363. is_hemorrhage := int64(dataBody["is_hemorrhage"].(float64))
  1364. if is_hemorrhage != 1 && is_hemorrhage != 2 {
  1365. is_hemorrhage = 0
  1366. }
  1367. evaluation.IsHemorrhage = is_hemorrhage
  1368. if is_hemorrhage == 1 {
  1369. if dataBody["hemorrhage"] != nil && reflect.TypeOf(dataBody["hemorrhage"]).String() == "string" {
  1370. hemorrhage, _ := dataBody["hemorrhage"].(string)
  1371. evaluation.Hemorrhage = hemorrhage
  1372. }
  1373. if dataBody["hemorrhage_other"] != nil && reflect.TypeOf(dataBody["hemorrhage_other"]).String() == "string" {
  1374. hemorrhage_other, _ := dataBody["hemorrhage_other"].(string)
  1375. evaluation.HemorrhageOther = hemorrhage_other
  1376. }
  1377. }
  1378. } else {
  1379. evaluation.IsHemorrhage = 0
  1380. }
  1381. if dataBody["blood_access_internal_fistula"] != nil && reflect.TypeOf(dataBody["blood_access_internal_fistula"]).String() == "string" {
  1382. blood_access_internal_fistula, _ := dataBody["blood_access_internal_fistula"].(string)
  1383. evaluation.BloodAccessInternalFistula = blood_access_internal_fistula
  1384. }
  1385. if dataBody["internal_fistula_other"] != nil && reflect.TypeOf(dataBody["internal_fistula_other"]).String() == "string" {
  1386. internal_fistula_other, _ := dataBody["internal_fistula_other"].(string)
  1387. evaluation.InternalFistulaOther = internal_fistula_other
  1388. }
  1389. if dataBody["blood_access_noise"] != nil && reflect.TypeOf(dataBody["blood_access_noise"]).String() == "float64" {
  1390. blood_access_noise := int64(dataBody["blood_access_noise"].(float64))
  1391. evaluation.BloodAccessNoise = blood_access_noise
  1392. }
  1393. if dataBody["puncture_way"] != nil && reflect.TypeOf(dataBody["puncture_way"]).String() == "float64" {
  1394. puncture_way := int64(dataBody["puncture_way"].(float64))
  1395. evaluation.PunctureWay = puncture_way
  1396. }
  1397. if dataBody["venous_catheterization"] != nil && reflect.TypeOf(dataBody["venous_catheterization"]).String() == "float64" {
  1398. venous_catheterization := int64(dataBody["venous_catheterization"].(float64))
  1399. evaluation.VenousCatheterization = venous_catheterization
  1400. }
  1401. if dataBody["venous_catheterization_part"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part"]).String() == "float64" {
  1402. venous_catheterization_part := int64(dataBody["venous_catheterization_part"].(float64))
  1403. evaluation.VenousCatheterizationPart = venous_catheterization_part
  1404. }
  1405. if dataBody["venous_catheterization_part_other"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part_other"]).String() == "string" {
  1406. venous_catheterization_part_other, _ := dataBody["venous_catheterization_part_other"].(string)
  1407. evaluation.VenousCatheterizationPartOther = venous_catheterization_part_other
  1408. }
  1409. if dataBody["ductus_arantii"] != nil && reflect.TypeOf(dataBody["ductus_arantii"]).String() == "string" {
  1410. ductus_arantii, _ := dataBody["ductus_arantii"].(string)
  1411. evaluation.DuctusArantii = ductus_arantii
  1412. }
  1413. if dataBody["emergency_treatment"] != nil && reflect.TypeOf(dataBody["emergency_treatment"]).String() == "float64" {
  1414. emergency_treatment := int64(dataBody["emergency_treatment"].(float64))
  1415. evaluation.EmergencyTreatment = emergency_treatment
  1416. }
  1417. if dataBody["emergency_treatment_other"] != nil && reflect.TypeOf(dataBody["emergency_treatment_other"]).String() == "string" {
  1418. emergency_treatment_other, _ := dataBody["emergency_treatment_other"].(string)
  1419. evaluation.EmergencyTreatmentOther = emergency_treatment_other
  1420. }
  1421. if dataBody["dialysis_count"] != nil && reflect.TypeOf(dataBody["dialysis_count"]).String() == "string" {
  1422. dialysis_count, _ := dataBody["dialysis_count"].(string)
  1423. count, _ := strconv.ParseInt(dialysis_count, 10, 64)
  1424. evaluation.DialysisCount = count
  1425. }
  1426. if dataBody["is_infect"] != nil && reflect.TypeOf(dataBody["is_infect"]).String() == "string" {
  1427. is_infect, _ := dataBody["is_infect"].(string)
  1428. infect, _ := strconv.ParseInt(is_infect, 10, 64)
  1429. evaluation.IsInfect = infect
  1430. }
  1431. if dataBody["exposed"] != nil && reflect.TypeOf(dataBody["exposed"]).String() == "string" {
  1432. exposed, _ := strconv.ParseFloat(dataBody["exposed"].(string), 64)
  1433. evaluation.Exposed = exposed
  1434. }
  1435. if dataBody["skin"] != nil && reflect.TypeOf(dataBody["skin"]).String() == "string" {
  1436. skin, _ := dataBody["skin"].(string)
  1437. skins, _ := strconv.ParseInt(skin, 10, 64)
  1438. evaluation.Skin = skins
  1439. }
  1440. if dataBody["skin_other"] != nil && reflect.TypeOf(dataBody["skin_other"]).String() == "string" {
  1441. skin_other, _ := dataBody["skin_other"].(string)
  1442. evaluation.SkinOther = skin_other
  1443. }
  1444. if dataBody["infect_other"] != nil && reflect.TypeOf(dataBody["infect_other"]).String() == "string" {
  1445. infect_other, _ := dataBody["infect_other"].(string)
  1446. evaluation.InfectOther = infect_other
  1447. }
  1448. if dataBody["ductus_arantii_other"] != nil && reflect.TypeOf(dataBody["ductus_arantii_other"]).String() == "string" {
  1449. ductus_arantii_other, _ := dataBody["ductus_arantii_other"].(string)
  1450. evaluation.DuctusArantiiOther = ductus_arantii_other
  1451. }
  1452. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  1453. punctureNeedle, _ := dataBody["puncture_needle"].(string)
  1454. evaluation.PunctureNeedle = punctureNeedle
  1455. }
  1456. return
  1457. }
  1458. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  1459. dataBody := make(map[string]interface{}, 0)
  1460. err := json.Unmarshal(data, &dataBody)
  1461. if err != nil {
  1462. utils.ErrorLog(err.Error())
  1463. code = enums.ErrorCodeParamWrong
  1464. return
  1465. }
  1466. timeLayout := "2006-01-02"
  1467. loc, _ := time.LoadLocation("Local")
  1468. isChild := false
  1469. if action == "create" {
  1470. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  1471. utils.ErrorLog("advice_type")
  1472. code = enums.ErrorCodeParamWrong
  1473. return
  1474. }
  1475. adviceType := int64(dataBody["advice_type"].(float64))
  1476. if adviceType != 1 && adviceType != 2 {
  1477. utils.ErrorLog("advice_type != 1&&2")
  1478. code = enums.ErrorCodeParamWrong
  1479. return
  1480. }
  1481. advice.AdviceType = adviceType
  1482. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  1483. utils.ErrorLog("advice_date")
  1484. code = enums.ErrorCodeParamWrong
  1485. return
  1486. }
  1487. adviceDate, _ := dataBody["advice_date"].(string)
  1488. if len(adviceDate) == 0 {
  1489. utils.ErrorLog("len(adviceDate) == 0")
  1490. code = enums.ErrorCodeParamWrong
  1491. return
  1492. }
  1493. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  1494. if err != nil {
  1495. utils.ErrorLog(err.Error())
  1496. code = enums.ErrorCodeParamWrong
  1497. return
  1498. }
  1499. advice.AdviceDate = theTime.Unix()
  1500. advice.RecordDate = theTime.Unix()
  1501. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  1502. parentId := int64(dataBody["parent_id"].(float64))
  1503. advice.ParentId = parentId
  1504. if parentId > 0 {
  1505. isChild = true
  1506. }
  1507. }
  1508. } else {
  1509. isChild = advice.ParentId > 0
  1510. }
  1511. if !isChild {
  1512. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  1513. utils.ErrorLog("start_time")
  1514. code = enums.ErrorCodeParamWrong
  1515. return
  1516. }
  1517. startTime, _ := dataBody["start_time"].(string)
  1518. fmt.Println(startTime)
  1519. if len(startTime) == 0 {
  1520. utils.ErrorLog("len(start_time) == 0")
  1521. code = enums.ErrorCodeParamWrong
  1522. return
  1523. }
  1524. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  1525. if err != nil {
  1526. utils.ErrorLog(err.Error())
  1527. code = enums.ErrorCodeParamWrong
  1528. return
  1529. }
  1530. advice.StartTime = theTime.Unix()
  1531. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  1532. deliveryWay, _ := dataBody["delivery_way"].(string)
  1533. advice.DeliveryWay = deliveryWay
  1534. }
  1535. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  1536. executionFrequency, _ := dataBody["execution_frequency"].(string)
  1537. advice.ExecutionFrequency = executionFrequency
  1538. }
  1539. }
  1540. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  1541. deliveryWay, _ := dataBody["delivery_way"].(string)
  1542. advice.DeliveryWay = deliveryWay
  1543. }
  1544. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  1545. executionFrequency, _ := dataBody["execution_frequency"].(string)
  1546. advice.ExecutionFrequency = executionFrequency
  1547. }
  1548. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  1549. utils.ErrorLog("advice_name")
  1550. code = enums.ErrorCodeParamWrong
  1551. return
  1552. }
  1553. adviceName, _ := dataBody["advice_name"].(string)
  1554. if len(adviceName) == 0 {
  1555. utils.ErrorLog("len(advice_name) == 0")
  1556. code = enums.ErrorCodeParamWrong
  1557. return
  1558. }
  1559. advice.AdviceName = adviceName
  1560. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  1561. adviceDsc, _ := dataBody["advice_desc"].(string)
  1562. advice.AdviceDesc = adviceDsc
  1563. }
  1564. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  1565. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  1566. advice.SingleDose = singleDose
  1567. }
  1568. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  1569. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  1570. advice.SingleDoseUnit = singleDoseUnit
  1571. }
  1572. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  1573. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  1574. advice.DrugSpec = drugSpec
  1575. }
  1576. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  1577. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  1578. advice.DrugSpecUnit = drugSpecUnit
  1579. }
  1580. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  1581. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  1582. advice.PrescribingNumber = prescribingNumber
  1583. }
  1584. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  1585. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  1586. advice.PrescribingNumberUnit = prescribingNumberUnit
  1587. }
  1588. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  1589. remark, _ := dataBody["remark"].(string)
  1590. advice.Remark = remark
  1591. }
  1592. return
  1593. }
  1594. func (c *PatientApiController) GetPatientEducation() {
  1595. patientID, _ := c.GetInt64("patient_id", 0)
  1596. page, _ := c.GetInt64("page", 0)
  1597. limit, _ := c.GetInt64("limit", 0)
  1598. startTime := c.GetString("start_time", "")
  1599. endTime := c.GetString("end_time", "")
  1600. if page <= 0 {
  1601. page = 1
  1602. }
  1603. if limit <= 0 {
  1604. limit = 10
  1605. }
  1606. if patientID <= 0 {
  1607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1608. return
  1609. }
  1610. timeLayout := "2006-01-02"
  1611. loc, _ := time.LoadLocation("Local")
  1612. var theStartTIme int64
  1613. if len(startTime) > 0 {
  1614. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  1615. if err != nil {
  1616. theStartTIme = 0
  1617. }
  1618. theStartTIme = theTime.Unix()
  1619. }
  1620. var theEndtTIme int64
  1621. if len(endTime) > 0 {
  1622. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  1623. if err != nil {
  1624. theEndtTIme = 0
  1625. }
  1626. theEndtTIme = theTime.Unix()
  1627. }
  1628. adminUserInfo := c.GetMobileAdminUserInfo()
  1629. edus, total, _ := service.GetPatientTreatmentSummaryList(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme)
  1630. c.ServeSuccessJSON(map[string]interface{}{
  1631. "total": total,
  1632. "edus": edus,
  1633. })
  1634. return
  1635. }
  1636. func (c *PatientApiController) GetPatientSchedulesList() {
  1637. patientID, _ := c.GetInt64("patient_id", 0)
  1638. page, _ := c.GetInt64("page", 0)
  1639. limit, _ := c.GetInt64("limit", 0)
  1640. if patientID <= 0 {
  1641. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1642. return
  1643. }
  1644. adminUserInfo := c.GetMobileAdminUserInfo()
  1645. todayTime := time.Now().Format("2006-01-02")
  1646. timeLayout := "2006-01-02 15:04:05"
  1647. loc, _ := time.LoadLocation("Local")
  1648. var theStartTime int64
  1649. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  1650. theStartTime = theTime.Unix()
  1651. schedules, _ := service.GetPatientScheduleList(adminUserInfo.Org.Id, patientID, page, limit, theStartTime)
  1652. if len(schedules) > 0 {
  1653. for index, item := range schedules {
  1654. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  1655. schedules[index].Week = int64(week)
  1656. }
  1657. }
  1658. c.ServeSuccessJSON(map[string]interface{}{
  1659. "schedules": schedules,
  1660. })
  1661. return
  1662. }
  1663. func (c *PatientApiController) GetRecords() {
  1664. patientID, _ := c.GetInt64("patient_id", 0)
  1665. page, _ := c.GetInt64("page", 0)
  1666. limit, _ := c.GetInt64("limit", 0)
  1667. startTime := c.GetString("start_time", "")
  1668. endTime := c.GetString("end_time", "")
  1669. mode_id, _ := c.GetInt64("mode_id", 0)
  1670. if page <= 0 {
  1671. page = 1
  1672. }
  1673. if limit <= 0 {
  1674. limit = 10
  1675. }
  1676. if patientID <= 0 {
  1677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1678. return
  1679. }
  1680. timeLayout := "2006-01-02"
  1681. loc, _ := time.LoadLocation("Local")
  1682. var theStartTIme int64
  1683. if len(startTime) > 0 {
  1684. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  1685. if err != nil {
  1686. theStartTIme = 0
  1687. }
  1688. theStartTIme = theTime.Unix()
  1689. }
  1690. var theEndtTIme int64
  1691. if len(endTime) > 0 {
  1692. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  1693. if err != nil {
  1694. theEndtTIme = 0
  1695. }
  1696. theEndtTIme = theTime.Unix()
  1697. }
  1698. adminUserInfo := c.GetMobileAdminUserInfo()
  1699. records, total, _ := service.GetPatientDialysisRecord(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  1700. c.ServeSuccessJSON(map[string]interface{}{
  1701. "total": total,
  1702. "records": records,
  1703. })
  1704. return
  1705. }
  1706. func (c *PatientApiController) GetPatientMonitor() {
  1707. partition, _ := c.GetInt64("partition")
  1708. monitorDate := c.GetString("date")
  1709. timeLayout := "2006-01-02"
  1710. loc, _ := time.LoadLocation("Local")
  1711. var theStartTime int64
  1712. if len(monitorDate) > 0 {
  1713. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  1714. if err != nil {
  1715. theStartTime = 0
  1716. }
  1717. theStartTime = theTime.Unix()
  1718. }
  1719. adminInfo := c.GetMobileAdminUserInfo()
  1720. orgID := adminInfo.Org.Id
  1721. monitor, err := service.GetMonitorRecord(orgID, theStartTime, partition)
  1722. if err == nil {
  1723. c.ServeSuccessJSON(map[string]interface{}{
  1724. "monitor": monitor,
  1725. })
  1726. } else {
  1727. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1728. }
  1729. }
  1730. // /m/api/monitor/patient [get] 搜索病人的测量记录
  1731. // @param keyword:string 病人姓名或透析号
  1732. // @param page:int
  1733. func (this *PatientApiController) SearchMonitorPatient() {
  1734. keyword := this.GetString("keyword")
  1735. page, _ := this.GetInt("page")
  1736. if page <= 0 {
  1737. page = 1
  1738. }
  1739. if len(keyword) == 0 {
  1740. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1741. return
  1742. }
  1743. adminUserInfo := this.GetMobileAdminUserInfo()
  1744. monitors, getMonitorErr := service.MobileGetMonitorsWithPatient(adminUserInfo.Org.Id, keyword, page)
  1745. if getMonitorErr != nil {
  1746. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1747. return
  1748. } else {
  1749. this.ServeSuccessJSON(map[string]interface{}{
  1750. "monitor": monitors,
  1751. })
  1752. }
  1753. }
  1754. func (c *PatientApiController) GetPatientDialysisSolutionList() {
  1755. id, _ := c.GetInt64("id", 0)
  1756. page, _ := c.GetInt64("page", 0)
  1757. limit, _ := c.GetInt64("limit", 0)
  1758. if id <= 0 {
  1759. c.ServeSuccessJSON(map[string]interface{}{
  1760. "solutions": nil,
  1761. })
  1762. return
  1763. }
  1764. if page <= 0 {
  1765. page = 1
  1766. }
  1767. if limit <= 0 {
  1768. limit = 10
  1769. }
  1770. adminInfo := c.GetMobileAdminUserInfo()
  1771. solutions, total, _ := service.GetPatientDialysisSolutionList(adminInfo.Org.Id, id, page, limit)
  1772. c.ServeSuccessJSON(map[string]interface{}{
  1773. "solutions": solutions,
  1774. "total": total,
  1775. })
  1776. return
  1777. }
  1778. //GetDoctorAdvices 医嘱列表
  1779. func (c *PatientApiController) GetDoctorAdvices() {
  1780. id, _ := c.GetInt64("id", 0)
  1781. adviceType, _ := c.GetInt64("advice_type", 0)
  1782. stopType, _ := c.GetInt64("stop_state", 0)
  1783. startTime := c.GetString("start_time", "")
  1784. endTime := c.GetString("end_time", "")
  1785. keywords := c.GetString("keywords", "")
  1786. need, _ := c.GetInt64("need_doctor", 0)
  1787. adminUserInfo := c.GetMobileAdminUserInfo()
  1788. timeLayout := "2006-01-02"
  1789. loc, _ := time.LoadLocation("Local")
  1790. var theStartTIme int64
  1791. if len(startTime) > 0 {
  1792. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  1793. if err != nil {
  1794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1795. return
  1796. }
  1797. theStartTIme = theTime.Unix()
  1798. }
  1799. var theEndtTIme int64
  1800. if len(endTime) > 0 {
  1801. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  1802. if err != nil {
  1803. utils.ErrorLog(err.Error())
  1804. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1805. return
  1806. }
  1807. theEndtTIme = theTime.Unix()
  1808. }
  1809. advices, total, _ := service.GetDoctorAdviceList(adminUserInfo.Org.Id, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords)
  1810. if need == 1 {
  1811. users, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  1812. c.ServeSuccessJSON(map[string]interface{}{
  1813. "advices": advices,
  1814. "total": total,
  1815. "users": users,
  1816. })
  1817. } else {
  1818. c.ServeSuccessJSON(map[string]interface{}{
  1819. "advices": advices,
  1820. "total": total,
  1821. "users": []string{},
  1822. })
  1823. }
  1824. return
  1825. }
  1826. func (c *PatientApiController) GetPrintDialysisOrder() {
  1827. xtno := c.GetString("xtno")
  1828. xtdate := c.GetString("xtdate")
  1829. timeLayout := "2006-01-02"
  1830. loc, _ := time.LoadLocation("Local")
  1831. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  1832. if err != nil {
  1833. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1834. return
  1835. }
  1836. xttime := theTime.Unix()
  1837. operatorIDs := make([]int64, 0)
  1838. adminUserInfo := c.GetMobileAdminUserInfo()
  1839. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  1840. patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.Org.Id, xtno, xttime)
  1841. //透析单
  1842. dialysisOrder, _ := service.MobileGetSchedualDialysisRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  1843. if dialysisOrder != nil {
  1844. if dialysisOrder.FinishNurse > 0 {
  1845. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  1846. }
  1847. if dialysisOrder.StartNurse > 0 {
  1848. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  1849. }
  1850. }
  1851. //透前评估
  1852. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  1853. //透后评估
  1854. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  1855. if AssessmentAfterDislysis.Modifier > 0 {
  1856. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  1857. }
  1858. //透析处方
  1859. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  1860. if dialysisPrescription.PrescriptionDoctor > 0 {
  1861. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  1862. }
  1863. //临时医嘱
  1864. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  1865. if len(DoctorAdvice) > 0 {
  1866. for _, item := range DoctorAdvice {
  1867. if item.AdviceDoctor > 0 {
  1868. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  1869. }
  1870. if item.ExecutionStaff > 0 {
  1871. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  1872. }
  1873. if item.Checker > 0 {
  1874. operatorIDs = append(operatorIDs, item.Checker)
  1875. }
  1876. }
  1877. }
  1878. //透析监测
  1879. Record, _ := service.FindAllMonitorRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  1880. //透析小结
  1881. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  1882. //接诊评估
  1883. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  1884. //相关操作对应的操作人
  1885. operators, _ := service.GetAdminUserES(adminUserInfo.Org.Id, adminUserInfo.App.Id, operatorIDs)
  1886. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1887. check, _ := service.FindDoubleCheckById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  1888. c.ServeSuccessJSON(map[string]interface{}{
  1889. "users": adminUser,
  1890. "patientInfo": patientInfo,
  1891. "PredialysisEvaluation": PredialysisEvaluation,
  1892. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  1893. "dialysisPrescription": dialysisPrescription,
  1894. "advices": DoctorAdvice,
  1895. "monitors": Record,
  1896. "summary": TreatmentSummary,
  1897. "receiverTreatmentAccess": receiverTreatmentAccess,
  1898. "dialysisOrder": dialysisOrder,
  1899. "operators": operators,
  1900. "org_template_info": templateInfo,
  1901. "check": check,
  1902. })
  1903. }
  1904. func (c *PatientApiController) CreateGroupAdvice() {
  1905. patient, _ := c.GetInt64("id", 0)
  1906. if patient <= 0 {
  1907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1908. return
  1909. }
  1910. adminUserInfo := c.GetMobileAdminUserInfo()
  1911. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  1912. if patientInfo.ID == 0 {
  1913. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1914. return
  1915. }
  1916. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1917. //if appRole.UserType == 3{
  1918. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdvicePermissionDeniedModify)
  1919. // return
  1920. //}
  1921. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1922. //if appRole.UserType == 3 {
  1923. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1924. // if getPermissionErr != nil {
  1925. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1926. // return
  1927. // } else if headNursePermission == nil {
  1928. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1929. // return
  1930. // }
  1931. //}
  1932. //TODO根据路由做权限
  1933. group_no, _ := c.GetInt64("group_no")
  1934. if group_no <= 0 {
  1935. group_no = 0
  1936. }
  1937. dataBody := make(map[string]interface{}, 0)
  1938. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1939. if err != nil {
  1940. utils.ErrorLog(err.Error())
  1941. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1942. return
  1943. }
  1944. timeLayout := "2006-01-02"
  1945. loc, _ := time.LoadLocation("Local")
  1946. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  1947. utils.ErrorLog("advice_type")
  1948. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1949. return
  1950. }
  1951. adviceType := int64(dataBody["advice_type"].(float64))
  1952. if adviceType != 1 && adviceType != 2 {
  1953. utils.ErrorLog("advice_type != 1&&2")
  1954. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1955. return
  1956. }
  1957. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  1958. utils.ErrorLog("advice_date")
  1959. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1960. return
  1961. }
  1962. adviceDate, _ := dataBody["advice_date"].(string)
  1963. if len(adviceDate) == 0 {
  1964. utils.ErrorLog("len(adviceDate) == 0")
  1965. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1966. return
  1967. }
  1968. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  1969. if err != nil {
  1970. utils.ErrorLog(err.Error())
  1971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1972. return
  1973. }
  1974. AdviceDate := theTime.Unix()
  1975. RecordDate := theTime.Unix()
  1976. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  1977. utils.ErrorLog("start_time")
  1978. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1979. return
  1980. }
  1981. startTime, _ := dataBody["start_time"].(string)
  1982. if len(startTime) == 0 {
  1983. utils.ErrorLog("len(start_time) == 0")
  1984. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1985. return
  1986. }
  1987. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  1988. if err != nil {
  1989. utils.ErrorLog(err.Error())
  1990. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1991. return
  1992. }
  1993. StartTime := theTime.Unix()
  1994. Remark := ""
  1995. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  1996. remark, _ := dataBody["remark"].(string)
  1997. Remark = remark
  1998. }
  1999. var advices []*models.GroupAdvice
  2000. // utils.TraceLog("%+v", dataBody["adviceNames"])
  2001. if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
  2002. utils.ErrorLog("adviceNames")
  2003. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2004. return
  2005. }
  2006. adviceNames := dataBody["adviceNames"].([]interface{})
  2007. for _, adviceNameMap := range adviceNames {
  2008. adviceNameM := adviceNameMap.(map[string]interface{})
  2009. var advice models.GroupAdvice
  2010. advice.Remark = Remark
  2011. advice.AdviceType = adviceType
  2012. advice.StartTime = StartTime
  2013. advice.AdviceDate = AdviceDate
  2014. advice.RecordDate = RecordDate
  2015. advice.Status = 1
  2016. advice.CreatedTime = time.Now().Unix()
  2017. advice.UpdatedTime = time.Now().Unix()
  2018. advice.StopState = 2
  2019. advice.ExecutionState = 2
  2020. advice.UserOrgId = adminUserInfo.Org.Id
  2021. advice.PatientId = patientInfo.ID
  2022. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  2023. errcode := c.setAdviceWithJSON(&advice, adviceNameM)
  2024. if errcode > 0 {
  2025. c.ServeFailJSONWithSGJErrorCode(errcode)
  2026. return
  2027. }
  2028. if adviceNameM["subdrugs"] != nil && reflect.TypeOf(adviceNameM["subdrugs"]).String() == "[]interface {}" {
  2029. subdrugs := adviceNameM["subdrugs"].([]interface{})
  2030. if len(subdrugs) > 0 {
  2031. for _, subdrug := range subdrugs {
  2032. var s models.GroupAdvice
  2033. s.Remark = Remark
  2034. s.AdviceType = adviceType
  2035. s.StartTime = StartTime
  2036. s.AdviceDate = AdviceDate
  2037. s.RecordDate = RecordDate
  2038. s.Status = 1
  2039. s.CreatedTime = time.Now().Unix()
  2040. s.UpdatedTime = time.Now().Unix()
  2041. s.StopState = 2
  2042. s.ExecutionState = 2
  2043. s.UserOrgId = adminUserInfo.Org.Id
  2044. s.PatientId = patientInfo.ID
  2045. s.AdviceDoctor = adminUserInfo.AdminUser.Id
  2046. errcode := c.setAdviceWithJSON(&s, subdrug.(map[string]interface{}))
  2047. if errcode > 0 {
  2048. c.ServeFailJSONWithSGJErrorCode(errcode)
  2049. return
  2050. }
  2051. advice.Children = append(advice.Children, &s)
  2052. }
  2053. }
  2054. }
  2055. advices = append(advices, &advice)
  2056. }
  2057. newAdvices, createErr := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, group_no)
  2058. if createErr != nil {
  2059. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  2060. return
  2061. }
  2062. c.ServeSuccessJSON(map[string]interface{}{
  2063. "msg": "ok",
  2064. "advices": newAdvices,
  2065. })
  2066. return
  2067. }
  2068. func (c *PatientApiController) setAdviceWithJSON(advice *models.GroupAdvice, json map[string]interface{}) int {
  2069. if json["advice_name"] == nil || reflect.TypeOf(json["advice_name"]).String() != "string" {
  2070. utils.ErrorLog("advice_name")
  2071. return enums.ErrorCodeParamWrong
  2072. }
  2073. adviceName, _ := json["advice_name"].(string)
  2074. if len(adviceName) == 0 {
  2075. utils.ErrorLog("len(advice_name) == 0")
  2076. return enums.ErrorCodeParamWrong
  2077. }
  2078. advice.AdviceName = adviceName
  2079. adviceDesc, _ := json["advice_desc"].(string)
  2080. advice.AdviceDesc = adviceDesc
  2081. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  2082. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  2083. advice.DrugSpec = drugSpec
  2084. }
  2085. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  2086. remark, _ := json["remark"].(string)
  2087. advice.Remark = remark
  2088. }
  2089. if json["drug_spec_unit"] != nil && reflect.TypeOf(json["drug_spec_unit"]).String() == "string" {
  2090. drugSpecUnit, _ := json["drug_spec_unit"].(string)
  2091. advice.DrugSpecUnit = drugSpecUnit
  2092. }
  2093. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  2094. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  2095. advice.SingleDose = singleDose
  2096. }
  2097. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  2098. singleDoseUnit, _ := json["single_dose_unit"].(string)
  2099. advice.SingleDoseUnit = singleDoseUnit
  2100. }
  2101. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  2102. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  2103. advice.PrescribingNumber = prescribingNumber
  2104. }
  2105. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  2106. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  2107. advice.PrescribingNumberUnit = prescribingNumberUnit
  2108. }
  2109. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  2110. deliveryWay, _ := json["delivery_way"].(string)
  2111. advice.DeliveryWay = deliveryWay
  2112. }
  2113. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  2114. executionFrequency, _ := json["execution_frequency"].(string)
  2115. advice.ExecutionFrequency = executionFrequency
  2116. }
  2117. return 0
  2118. }
  2119. func (c *PatientApiController) DelDoctorAdvice() {
  2120. groupno, _ := c.GetInt64("groupno", -1)
  2121. is_sub, _ := c.GetInt64("is_sub", -1) //是否子药
  2122. if is_sub == 1 { //是
  2123. advice_id, _ := c.GetInt64("advice_id")
  2124. adminUserInfo := c.GetMobileAdminUserInfo()
  2125. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  2126. if advice.ID == 0 {
  2127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2128. return
  2129. }
  2130. //TODO 根据路由来做权限
  2131. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  2132. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2133. // return
  2134. //}
  2135. advice.Status = 0
  2136. advice.UpdatedTime = time.Now().Unix()
  2137. advice.Modifier = adminUserInfo.AdminUser.Id
  2138. err := service.DeleteDoctorAdvice(&advice)
  2139. if err != nil {
  2140. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  2141. return
  2142. }
  2143. c.ServeSuccessJSON(map[string]interface{}{
  2144. "msg": "ok",
  2145. })
  2146. return
  2147. } else { //
  2148. var ids []string
  2149. if groupno == 0 {
  2150. advice_id := c.GetString("advice_id")
  2151. ids = strings.Split(advice_id, ",")
  2152. if len(ids) <= 0 {
  2153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2154. return
  2155. }
  2156. }
  2157. if groupno < 0 {
  2158. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2159. return
  2160. }
  2161. adminUserInfo := c.GetMobileAdminUserInfo()
  2162. var advice models.DoctorAdvice
  2163. if groupno > 0 {
  2164. advice, _ = service.FindDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  2165. if advice.ID == 0 {
  2166. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2167. return
  2168. }
  2169. } else {
  2170. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  2171. for _, item := range advices {
  2172. if item.ID == 0 {
  2173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2174. return
  2175. }
  2176. }
  2177. }
  2178. advice.UpdatedTime = time.Now().Unix()
  2179. advice.Status = 0
  2180. advice.GroupNo = groupno
  2181. var err error
  2182. if groupno > 0 {
  2183. err = service.DeleteDoctorAdviceByGroupNo(&advice)
  2184. } else {
  2185. err = service.BatchDeleteDoctorAdvice(ids)
  2186. }
  2187. if err != nil {
  2188. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  2189. return
  2190. }
  2191. c.ServeSuccessJSON(map[string]interface{}{
  2192. "msg": "ok",
  2193. })
  2194. return
  2195. }
  2196. }
  2197. // /m/api/advice/group/modify_starttime [post]
  2198. // @param group_no:int
  2199. // @param start_time:string yyyy-MM-dd hh:mm:ss
  2200. func (this *PatientApiController) ModifyAdviceGroupStartTime() {
  2201. group_no, _ := this.GetInt64("group_no")
  2202. start_time_str := this.GetString("start_time")
  2203. if group_no <= 0 || len(start_time_str) == 0 {
  2204. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2205. return
  2206. }
  2207. startTime, parseTimeErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time_str)
  2208. if parseTimeErr != nil {
  2209. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  2210. return
  2211. }
  2212. adminUserInfo := this.GetMobileAdminUserInfo()
  2213. updateStartTimeErr := service.UpdateAdviceGroupStartTime(adminUserInfo.Org.Id, group_no, startTime.Unix(), adminUserInfo.AdminUser.Id)
  2214. if updateStartTimeErr != nil {
  2215. utils.ErrorLog("修改医嘱分组的开始时间失败:%v", updateStartTimeErr)
  2216. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2217. return
  2218. }
  2219. this.ServeSuccessJSON(map[string]interface{}{
  2220. "start_time": startTime.Unix(),
  2221. })
  2222. }
  2223. func (this *PatientApiController) DelSubDoctorAdvice() {
  2224. advice_id, _ := this.GetInt64("advice_id")
  2225. adminUserInfo := this.GetMobileAdminUserInfo()
  2226. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  2227. if advice.ID == 0 {
  2228. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2229. return
  2230. }
  2231. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  2232. // this.ServeFailJSONWithSGJErrorCode(enums. bh)
  2233. // return
  2234. //}
  2235. advice.Status = 0
  2236. advice.UpdatedTime = time.Now().Unix()
  2237. advice.Modifier = adminUserInfo.AdminUser.Id
  2238. err := service.DeleteDoctorAdvice(&advice)
  2239. if err != nil {
  2240. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  2241. return
  2242. }
  2243. this.ServeSuccessJSON(map[string]interface{}{
  2244. "msg": "ok",
  2245. })
  2246. return
  2247. }
  2248. func (this *PatientApiController) GetAdviceUnReadMessage() {
  2249. //adminUserInfo := this.GetMobileAdminUserInfo()
  2250. //service.FindUnReadDoctorAdviceMessage()
  2251. }
  2252. func (this *PatientApiController) GetPatientsByKeyWord() {
  2253. keyWord := this.GetString("keyword")
  2254. adminUserInfo := this.GetMobileAdminUserInfo()
  2255. today := utils.ZeroHourTimeOfDay(time.Now())
  2256. patient, err := service.GetSchedualPatientByKeyWord(adminUserInfo.Org.Id, keyWord, today.Unix())
  2257. if err != nil {
  2258. utils.ErrorLog(err.Error())
  2259. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2260. return
  2261. }
  2262. this.ServeSuccessJSON(map[string]interface{}{
  2263. "patient": patient,
  2264. })
  2265. }