patient_api_controller.go 90KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671
  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. advice.Modifier = adminUserInfo.AdminUser.Id
  525. c.ServeSuccessJSON(map[string]interface{}{
  526. "msg": "ok",
  527. "advice": advice,
  528. "ids": ids,
  529. })
  530. return
  531. }
  532. func (c *PatientApiController) ModifyExecDoctorAdvice() {
  533. execution_time := c.GetString("execution_time")
  534. groupno, _ := c.GetInt64("groupno", -1)
  535. var ids []string
  536. if groupno == 0 {
  537. advice_ids := c.GetString("advice_id")
  538. ids = strings.Split(advice_ids, ",")
  539. }
  540. if groupno < 0 {
  541. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  542. return
  543. }
  544. if len(execution_time) <= 0 {
  545. utils.ErrorLog("execution_time")
  546. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  547. return
  548. }
  549. timeLayout2 := "2006-01-02 15:04:05"
  550. loc, _ := time.LoadLocation("Local")
  551. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  552. if errs != nil {
  553. utils.ErrorLog(errs.Error())
  554. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  555. return
  556. }
  557. adminUserInfo := c.GetMobileAdminUserInfo()
  558. var advice models.DoctorAdvice
  559. if groupno > 0 {
  560. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  561. for _, item := range advices {
  562. if item.ExecutionState == 1 {
  563. advice = item
  564. }
  565. }
  566. } else {
  567. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  568. for _, item := range advices {
  569. if item.ExecutionState == 1 {
  570. advice = item
  571. }
  572. }
  573. }
  574. //if advice.ExecutionStaff != adminUserInfo.AdminUser.Id {
  575. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  576. // if getPermissionErr != nil {
  577. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  578. // return
  579. // } else if headNursePermission == nil {
  580. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  581. // return
  582. // }
  583. //}
  584. if advice.StartTime > theTime.Unix() {
  585. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  586. return
  587. }
  588. advices := models.DoctorAdvice{
  589. ExecutionTime: theTime.Unix(),
  590. UpdatedTime: time.Now().Unix(),
  591. }
  592. var err error
  593. if groupno > 0 {
  594. err = service.ModifyExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  595. } else {
  596. err = service.BatchModifyExceOldDoctorAdvice(&advices, ids)
  597. }
  598. if err != nil {
  599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  600. return
  601. }
  602. advice.ExecutionTime = theTime.Unix()
  603. c.ServeSuccessJSON(map[string]interface{}{
  604. "msg": "ok",
  605. "advice": advice,
  606. "ids": ids,
  607. })
  608. return
  609. }
  610. func (c *PatientApiController) CheckDoctorAdvice() {
  611. groupno, _ := c.GetInt64("groupno", -1)
  612. var ids []string
  613. if groupno == 0 {
  614. advice_ids := c.GetString("advice_id")
  615. if advice_ids == "" {
  616. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  617. return
  618. } else {
  619. ids = strings.Split(advice_ids, ",")
  620. if len(ids) <= 0 {
  621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  622. return
  623. }
  624. }
  625. }
  626. if groupno < 0 {
  627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  628. return
  629. }
  630. adminUserInfo := c.GetMobileAdminUserInfo()
  631. var advice models.DoctorAdvice
  632. if groupno > 0 {
  633. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  634. for _, item := range advices {
  635. if item.CheckState == 0 {
  636. advice = item
  637. }
  638. }
  639. if advice.CheckState == 1 {
  640. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  641. return
  642. }
  643. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  644. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  645. return
  646. }
  647. } else {
  648. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  649. for _, item := range advices {
  650. if item.CheckState == 0 {
  651. advice = item
  652. }
  653. }
  654. if advice.CheckState == 1 {
  655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  656. return
  657. }
  658. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  660. return
  661. }
  662. }
  663. checker := adminUserInfo.AdminUser.Id
  664. theTime := time.Now()
  665. advices := models.DoctorAdvice{
  666. CheckTime: theTime.Unix(),
  667. Checker: checker,
  668. UpdatedTime: time.Now().Unix(),
  669. }
  670. var err error
  671. if groupno > 0 {
  672. err = service.CheckDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  673. } else {
  674. if len(ids[0]) <= 0 {
  675. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  676. return
  677. } else {
  678. t := time.Now().Format("2006-01-02")
  679. timeLayout2 := "2006-01-02"
  680. loc, _ := time.LoadLocation("Local")
  681. theTime, _ := time.ParseInLocation(timeLayout2, t, loc)
  682. err = service.BatchCheckOldDoctorAdvice(&advices, ids, adminUserInfo.Org.Id, theTime.Unix())
  683. }
  684. }
  685. if err != nil {
  686. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  687. return
  688. }
  689. advice.Checker = checker
  690. advice.CheckTime = theTime.Unix()
  691. advice.CheckState = 1
  692. c.ServeSuccessJSON(map[string]interface{}{
  693. "msg": "ok",
  694. "advice": advice,
  695. })
  696. return
  697. }
  698. func (c *PatientApiController) EditAssessmentBeforeDislysis() {
  699. id, _ := c.GetInt64("patient", 0)
  700. assessmentDate := c.GetString("assessment_date", "")
  701. if id <= 0 || len(assessmentDate) != 10 {
  702. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  703. return
  704. }
  705. timeLayout := "2006-01-02"
  706. loc, _ := time.LoadLocation("Local")
  707. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", assessmentDate+" 00:00:00", loc)
  708. if err != nil {
  709. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  710. return
  711. }
  712. theAssessmentDateTime := theTime.Unix()
  713. adminUserInfo := c.GetMobileAdminUserInfo()
  714. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  715. if patient.ID == 0 {
  716. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  717. return
  718. }
  719. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  720. if getPEErr != nil {
  721. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  722. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  723. return
  724. }
  725. //templateInfo,_ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  726. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  727. var evaluation models.PredialysisEvaluation
  728. if theEvaluation != nil {
  729. evaluation = *theEvaluation
  730. }
  731. code := predialysisEvaluationFormData(&evaluation, c.Ctx.Input.RequestBody)
  732. if code > 0 {
  733. c.ServeFailJSONWithSGJErrorCode(code)
  734. return
  735. }
  736. if theEvaluation == nil {
  737. evaluation.CreatedTime = time.Now().Unix()
  738. evaluation.Status = 1
  739. evaluation.AssessmentDate = theAssessmentDateTime
  740. evaluation.PatientId = id
  741. evaluation.UserOrgId = adminUserInfo.Org.Id
  742. if appRole.UserType == 2 || appRole.UserType == 1 {
  743. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  744. evaluation.AssessmentTime = time.Now().Unix()
  745. } else {
  746. evaluation.Creater = adminUserInfo.AdminUser.Id
  747. }
  748. } else {
  749. evaluation.UpdatedTime = time.Now().Unix()
  750. evaluation.Evaluator = adminUserInfo.AdminUser.Id
  751. if appRole.UserType == 2 || appRole.UserType == 1 {
  752. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  753. evaluation.AssessmentTime = time.Now().Unix()
  754. } else {
  755. evaluation.Modifier = adminUserInfo.AdminUser.Id
  756. if evaluation.Creater == 0 {
  757. evaluation.Creater = adminUserInfo.AdminUser.Id
  758. }
  759. }
  760. }
  761. //新增逻辑
  762. var dewater_amount float64
  763. dewater_amount = 0
  764. if evaluation.DryWeight > 0 {
  765. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  766. if dewater_amount <= 0 {
  767. dewater_amount = 0
  768. }
  769. } else {
  770. dewater_amount = 0
  771. }
  772. // 计算透析处方的相关超滤量
  773. schedual, _ := service.MobileGetSchedualDetail(adminUserInfo.Org.Id, patient.ID, theAssessmentDateTime)
  774. var lastDialysisPrescribe *models.DialysisPrescription
  775. var dialysisSolution *models.DialysisSolution
  776. var dialysisPrescribe *models.DialysisPrescription
  777. var system_dialysisPrescribe *models.SystemPrescription
  778. var mode_id int64
  779. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  780. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeId(adminUserInfo.Org.Id, id, schedual.ModeId)
  781. if schedual != nil {
  782. // 获取透析模版
  783. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminUserInfo.Org.Id, id, schedual.ModeId)
  784. system_dialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminUserInfo.Org.Id, schedual.ModeId)
  785. mode_id = schedual.ModeId
  786. } else {
  787. // 获取透析模版
  788. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.Org.Id, id)
  789. if dialysisPrescribe == nil && dialysisSolution != nil {
  790. mode_id = dialysisSolution.ModeId
  791. }
  792. if dialysisPrescribe == nil && dialysisSolution == nil {
  793. mode_id = 0
  794. }
  795. }
  796. // 插入透析处方
  797. if dialysisPrescribe == nil && dialysisSolution != nil {
  798. var newprescribe models.DialysisPrescription
  799. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  800. newprescribe.PatientId = dialysisSolution.PatientId
  801. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  802. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  803. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  804. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  805. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  806. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  807. newprescribe.ModeId = dialysisSolution.ModeId
  808. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  809. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  810. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  811. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  812. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  813. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  814. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  815. newprescribe.Glucose = dialysisSolution.Glucose
  816. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  817. newprescribe.Kalium = dialysisSolution.Kalium
  818. newprescribe.Sodium = dialysisSolution.Sodium
  819. newprescribe.Calcium = dialysisSolution.Calcium
  820. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  821. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  822. newprescribe.Conductivity = dialysisSolution.Conductivity
  823. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  824. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  825. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  826. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  827. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  828. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  829. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  830. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  831. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  832. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  833. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  834. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  835. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  836. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  837. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  838. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  839. newprescribe.CreatedTime = time.Now().Unix()
  840. newprescribe.UpdatedTime = time.Now().Unix()
  841. newprescribe.RecordDate = theAssessmentDateTime
  842. newprescribe.DewaterAmount = dewater_amount
  843. newprescribe.TargetUltrafiltration = dewater_amount
  844. newprescribe.Status = 1
  845. err := service.AddSigleRecord(&newprescribe)
  846. if err != nil {
  847. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  848. }
  849. }
  850. if dialysisPrescribe == nil && dialysisSolution == nil {
  851. if lastDialysisPrescribe != nil {
  852. var newprescribe models.DialysisPrescription
  853. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  854. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  855. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  856. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  857. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  858. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  859. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  860. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  861. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  862. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  863. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  864. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  865. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  866. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  867. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  868. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  869. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  870. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  871. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  872. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  873. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  874. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  875. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  876. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  877. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  878. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  879. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  880. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  881. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  882. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  883. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  884. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  885. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  886. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  887. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  888. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  889. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  890. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  891. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  892. newprescribe.CreatedTime = time.Now().Unix()
  893. newprescribe.UpdatedTime = time.Now().Unix()
  894. newprescribe.RecordDate = theAssessmentDateTime
  895. newprescribe.DewaterAmount = dewater_amount
  896. newprescribe.TargetUltrafiltration = dewater_amount
  897. newprescribe.Status = 1
  898. err := service.AddSigleRecord(&newprescribe)
  899. if err != nil {
  900. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  901. }
  902. } else if system_dialysisPrescribe != nil {
  903. var newprescribe models.DialysisPrescription
  904. newprescribe.UserOrgId = system_dialysisPrescribe.UserOrgId
  905. newprescribe.PatientId = id
  906. newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
  907. newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
  908. newprescribe.AnticoagulantWeichi = system_dialysisPrescribe.AnticoagulantWeichi
  909. newprescribe.AnticoagulantZongliang = system_dialysisPrescribe.AnticoagulantZongliang
  910. newprescribe.AnticoagulantGaimingcheng = system_dialysisPrescribe.AnticoagulantGaimingcheng
  911. newprescribe.AnticoagulantGaijiliang = system_dialysisPrescribe.AnticoagulantGaijiliang
  912. newprescribe.ModeId = system_dialysisPrescribe.ModeId
  913. newprescribe.DialysisDuration = system_dialysisPrescribe.DialysisDuration
  914. newprescribe.ReplacementWay = system_dialysisPrescribe.ReplacementWay
  915. newprescribe.HemodialysisMachine = system_dialysisPrescribe.HemodialysisMachine
  916. newprescribe.BloodFilter = system_dialysisPrescribe.BloodFilter
  917. newprescribe.PerfusionApparatus = system_dialysisPrescribe.PerfusionApparatus
  918. newprescribe.BloodFlowVolume = system_dialysisPrescribe.BloodFlowVolume
  919. newprescribe.DisplaceLiqui = system_dialysisPrescribe.DisplaceLiqui
  920. newprescribe.Glucose = system_dialysisPrescribe.Glucose
  921. newprescribe.DialysateFlow = system_dialysisPrescribe.DialysateFlow
  922. newprescribe.Kalium = system_dialysisPrescribe.Kalium
  923. newprescribe.Sodium = system_dialysisPrescribe.Sodium
  924. newprescribe.Calcium = system_dialysisPrescribe.Calcium
  925. newprescribe.Bicarbonate = system_dialysisPrescribe.Bicarbonate
  926. newprescribe.DialysateTemperature = system_dialysisPrescribe.DialysateTemperature
  927. newprescribe.Conductivity = system_dialysisPrescribe.Conductivity
  928. newprescribe.BodyFluid = system_dialysisPrescribe.BodyFluid
  929. newprescribe.SpecialMedicine = system_dialysisPrescribe.SpecialMedicine
  930. newprescribe.SpecialMedicineOther = system_dialysisPrescribe.SpecialMedicineOther
  931. newprescribe.DisplaceLiquiPart = system_dialysisPrescribe.DisplaceLiquiPart
  932. newprescribe.DisplaceLiquiValue = system_dialysisPrescribe.DisplaceLiquiValue
  933. newprescribe.BloodAccess = system_dialysisPrescribe.BloodAccess
  934. newprescribe.Ultrafiltration = system_dialysisPrescribe.Ultrafiltration
  935. newprescribe.DialysisDurationHour = system_dialysisPrescribe.DialysisDurationHour
  936. newprescribe.DialysisDurationMinute = system_dialysisPrescribe.DialysisDurationMinute
  937. newprescribe.DialysateFormulation = system_dialysisPrescribe.DialysateFormulation
  938. newprescribe.Dialyzer = system_dialysisPrescribe.Dialyzer
  939. newprescribe.ReplacementTotal = system_dialysisPrescribe.ReplacementTotal
  940. newprescribe.DialyzerPerfusionApparatus = system_dialysisPrescribe.DialyzerPerfusionApparatus
  941. newprescribe.BodyFluidOther = system_dialysisPrescribe.BodyFluidOther
  942. newprescribe.TargetKtv = system_dialysisPrescribe.TargetKtv
  943. newprescribe.CreatedTime = time.Now().Unix()
  944. newprescribe.UpdatedTime = time.Now().Unix()
  945. newprescribe.RecordDate = theAssessmentDateTime
  946. newprescribe.DewaterAmount = dewater_amount
  947. newprescribe.TargetUltrafiltration = dewater_amount
  948. newprescribe.Status = 1
  949. err := service.AddSigleRecord(&newprescribe)
  950. if err != nil {
  951. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  952. }
  953. } else {
  954. var newprescribe models.DialysisPrescription
  955. newprescribe.UserOrgId = adminUserInfo.Org.Id
  956. newprescribe.PatientId = id
  957. newprescribe.ModeId = mode_id
  958. newprescribe.CreatedTime = time.Now().Unix()
  959. newprescribe.UpdatedTime = time.Now().Unix()
  960. newprescribe.RecordDate = theAssessmentDateTime
  961. newprescribe.DewaterAmount = dewater_amount
  962. newprescribe.TargetUltrafiltration = dewater_amount
  963. newprescribe.Status = 1
  964. err := service.AddSigleRecord(&newprescribe)
  965. if err != nil {
  966. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  967. }
  968. }
  969. }
  970. // 手动修改透前评估的时候,如果透析处方已经存在,则不修改对应的透析处方
  971. // if dialysisPrescribe != nil {
  972. // dialysisPrescribe.UpdatedTime = time.Now().Unix()
  973. // dialysisPrescribe.RecordDate = theAssessmentDateTime
  974. // dialysisPrescribe.DewaterAmount = dewater_amount
  975. // dialysisPrescribe.TargetUltrafiltration = dewater_amount
  976. // dialysisPrescribe.Status = 1
  977. // updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
  978. // if updateErr != nil {
  979. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  980. // }
  981. // }
  982. err = service.UpadatePredialysisEvaluation(&evaluation)
  983. if err != nil {
  984. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  985. return
  986. }
  987. c.ServeSuccessJSON(map[string]interface{}{
  988. "msg": "ok",
  989. "evaluation": evaluation,
  990. })
  991. return
  992. }
  993. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  994. dataBody := make(map[string]interface{}, 0)
  995. err := json.Unmarshal(data, &dataBody)
  996. utils.InfoLog(string(data))
  997. if err != nil {
  998. utils.ErrorLog(err.Error())
  999. code = enums.ErrorCodeParamWrong
  1000. return
  1001. }
  1002. // if method == "create" {
  1003. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  1004. utils.ErrorLog("mode")
  1005. code = enums.ErrorCodeParamWrong
  1006. return
  1007. }
  1008. mode := int64(dataBody["mode"].(float64))
  1009. if mode <= 0 {
  1010. utils.ErrorLog("mode <= 0")
  1011. code = enums.ErrorCodeParamWrong
  1012. return
  1013. }
  1014. solution.ModeId = mode
  1015. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  1016. utils.ErrorLog("mode_name")
  1017. code = enums.ErrorCodeParamWrong
  1018. return
  1019. }
  1020. modeName, _ := dataBody["mode_name"].(string)
  1021. if len(modeName) == 0 {
  1022. utils.ErrorLog("len(mode_name) == 0")
  1023. code = enums.ErrorCodeParamWrong
  1024. return
  1025. }
  1026. solution.ModeName = modeName
  1027. solution.Name = modeName
  1028. // }
  1029. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  1030. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  1031. solution.DialysisDuration = dialysisDuration
  1032. }
  1033. if dataBody["dialysis_duration"] != nil {
  1034. if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  1035. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  1036. solution.DialysisDuration = dialysisDuration
  1037. } else if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "float64" {
  1038. dialysisDuration := dataBody["dialysis_duration"].(float64)
  1039. solution.DialysisDuration = dialysisDuration
  1040. }
  1041. }
  1042. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  1043. dialyzer := int64(dataBody["dialyzer"].(float64))
  1044. solution.Dialyzer = dialyzer
  1045. }
  1046. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  1047. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  1048. solution.PerfusionApparatus = perfusionApparatus
  1049. }
  1050. if dataBody["blood_flow_volume"] != nil {
  1051. if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  1052. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  1053. solution.BloodFlowVolume = bloodFlowVolume
  1054. } else if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "float64" {
  1055. bloodFlowVolume := dataBody["blood_flow_volume"].(float64)
  1056. solution.BloodFlowVolume = bloodFlowVolume
  1057. }
  1058. }
  1059. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  1060. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  1061. solution.HemodialysisMachine = hemodialysisMachine
  1062. }
  1063. if dataBody["dewater"] != nil {
  1064. if reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  1065. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  1066. solution.Dewater = dewater
  1067. } else if reflect.TypeOf(dataBody["dewater"]).String() == "float64" {
  1068. dewater := dataBody["dewater"].(float64)
  1069. solution.Dewater = dewater
  1070. }
  1071. }
  1072. if dataBody["replacement_total"] != nil {
  1073. if reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  1074. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  1075. solution.ReplacementTotal = replacementTotal
  1076. } else if reflect.TypeOf(dataBody["replacement_total"]).String() == "float64" {
  1077. replacementTotal := dataBody["replacement_total"].(float64)
  1078. solution.ReplacementTotal = replacementTotal
  1079. }
  1080. }
  1081. if dataBody["displace_liqui"] != nil {
  1082. if reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  1083. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  1084. solution.DisplaceLiqui = displaceLiqui
  1085. } else if reflect.TypeOf(dataBody["displace_liqui"]).String() == "float64" {
  1086. displaceLiqui := dataBody["displace_liqui"].(float64)
  1087. solution.DisplaceLiqui = displaceLiqui
  1088. }
  1089. }
  1090. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  1091. replacementWay := int64(dataBody["replacement_way"].(float64))
  1092. solution.ReplacementWay = replacementWay
  1093. }
  1094. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  1095. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  1096. solution.Anticoagulant = anticoagulant
  1097. }
  1098. if dataBody["anticoagulant_shouji"] != nil {
  1099. if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  1100. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  1101. solution.AnticoagulantShouji = anticoagulantShouji
  1102. } else if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "float64" {
  1103. anticoagulantShouji := dataBody["anticoagulant_shouji"].(float64)
  1104. solution.AnticoagulantShouji = anticoagulantShouji
  1105. }
  1106. }
  1107. if dataBody["anticoagulant_weichi"] != nil {
  1108. if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  1109. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  1110. solution.AnticoagulantWeichi = anticoagulantWeichi
  1111. } else if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "float64" {
  1112. anticoagulantWeichi := dataBody["anticoagulant_weichi"].(float64)
  1113. solution.AnticoagulantWeichi = anticoagulantWeichi
  1114. }
  1115. }
  1116. if dataBody["anticoagulant_zongliang"] != nil {
  1117. if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  1118. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  1119. solution.AnticoagulantZongliang = anticoagulantZongliang
  1120. } else if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "float64" {
  1121. anticoagulantZongliang := dataBody["anticoagulant_zongliang"].(float64)
  1122. solution.AnticoagulantZongliang = anticoagulantZongliang
  1123. }
  1124. }
  1125. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  1126. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  1127. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  1128. }
  1129. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  1130. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  1131. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  1132. }
  1133. if dataBody["kalium"] != nil {
  1134. if reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  1135. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  1136. solution.Kalium = kalium
  1137. } else if reflect.TypeOf(dataBody["kalium"]).String() == "float64" {
  1138. kalium := dataBody["kalium"].(float64)
  1139. solution.Kalium = kalium
  1140. }
  1141. }
  1142. if dataBody["sodium"] != nil {
  1143. if reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  1144. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  1145. solution.Sodium = sodium
  1146. } else if reflect.TypeOf(dataBody["sodium"]).String() == "float64" {
  1147. sodium := dataBody["sodium"].(float64)
  1148. solution.Sodium = sodium
  1149. }
  1150. }
  1151. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  1152. if reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  1153. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  1154. solution.Calcium = calcium
  1155. } else if reflect.TypeOf(dataBody["calcium"]).String() == "float64" {
  1156. calcium := dataBody["calcium"].(float64)
  1157. solution.Calcium = calcium
  1158. }
  1159. }
  1160. if dataBody["bicarbonate"] != nil {
  1161. if reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  1162. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  1163. solution.Bicarbonate = bicarbonate
  1164. } else if reflect.TypeOf(dataBody["bicarbonate"]).String() == "float64" {
  1165. bicarbonate := dataBody["bicarbonate"].(float64)
  1166. solution.Bicarbonate = bicarbonate
  1167. }
  1168. }
  1169. if dataBody["glucose"] != nil {
  1170. if reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  1171. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  1172. solution.Glucose = glucose
  1173. } else if reflect.TypeOf(dataBody["glucose"]).String() == "float64" {
  1174. glucose := dataBody["glucose"].(float64)
  1175. solution.Glucose = glucose
  1176. }
  1177. }
  1178. // if dataBody["dry_weight"] != nil {
  1179. // if reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  1180. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  1181. // solution.DryWeight = dryWeight
  1182. // } else if reflect.TypeOf(dataBody["dry_weight"]).String() == "float64" {
  1183. // dryWeight := dataBody["dry_weight"].(float64)
  1184. // solution.DryWeight = dryWeight
  1185. // }
  1186. // }
  1187. if dataBody["dialysate_flow"] != nil {
  1188. if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  1189. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  1190. solution.DialysateFlow = dialysateFlow
  1191. } else if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "float64" {
  1192. dialysateFlow := dataBody["dialysate_flow"].(float64)
  1193. solution.DialysateFlow = dialysateFlow
  1194. }
  1195. }
  1196. if dataBody["dialysate_temperature"] != nil {
  1197. if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  1198. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  1199. solution.DialysateTemperature = dialysateTemperature
  1200. } else if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "float64" {
  1201. dialysateTemperature := dataBody["dialysate_temperature"].(float64)
  1202. solution.DialysateTemperature = dialysateTemperature
  1203. }
  1204. }
  1205. if dataBody["conductivity"] != nil {
  1206. if reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  1207. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  1208. solution.Conductivity = conductivity
  1209. } else if reflect.TypeOf(dataBody["conductivity"]).String() == "float64" {
  1210. conductivity := dataBody["conductivity"].(float64)
  1211. solution.Conductivity = conductivity
  1212. }
  1213. }
  1214. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  1215. remark := dataBody["remark"].(string)
  1216. solution.Remark = remark
  1217. }
  1218. if dataBody["dialysis_duration_hour"] != nil {
  1219. if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  1220. dialysisDurationHour, _ := strconv.ParseInt(dataBody["dialysis_duration_hour"].(string), 10, 64)
  1221. solution.DialysisDurationHour = dialysisDurationHour
  1222. } else if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "float64" {
  1223. dialysisDurationHour := dataBody["dialysis_duration_hour"].(float64)
  1224. solution.DialysisDurationHour = int64(dialysisDurationHour)
  1225. }
  1226. }
  1227. if dataBody["dialysis_duration_minute"] != nil {
  1228. if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  1229. dialysisDurationMinute, _ := strconv.ParseInt(dataBody["dialysis_duration_minute"].(string), 10, 64)
  1230. solution.DialysisDurationMinute = dialysisDurationMinute
  1231. } else if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "float64" {
  1232. dialysisDurationMinute := dataBody["dialysis_duration_minute"].(float64)
  1233. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  1234. }
  1235. }
  1236. if dataBody["target_ultrafiltration"] != nil {
  1237. if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  1238. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  1239. solution.TargetUltrafiltration = targetUltrafiltration
  1240. } else if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "float64" {
  1241. targetUltrafiltration := dataBody["target_ultrafiltration"].(float64)
  1242. solution.TargetUltrafiltration = targetUltrafiltration
  1243. }
  1244. }
  1245. if dataBody["dialysate_formulation"] != nil {
  1246. if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "string" {
  1247. dialysateFormulation, _ := strconv.ParseInt(dataBody["dialysate_formulation"].(string), 10, 64)
  1248. solution.DialysateFormulation = dialysateFormulation
  1249. } else if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  1250. dialysateFormulation := dataBody["dialysate_formulation"].(float64)
  1251. solution.DialysateFormulation = int64(dialysateFormulation)
  1252. }
  1253. }
  1254. return
  1255. }
  1256. func predialysisEvaluationFormData(evaluation *models.PredialysisEvaluation, data []byte) (code int) {
  1257. dataBody := make(map[string]interface{}, 0)
  1258. err := json.Unmarshal(data, &dataBody)
  1259. utils.InfoLog(string(data))
  1260. if err != nil {
  1261. utils.ErrorLog(err.Error())
  1262. code = enums.ErrorCodeParamWrong
  1263. return
  1264. }
  1265. if dataBody["weight_before"] != nil && reflect.TypeOf(dataBody["weight_before"]).String() == "string" {
  1266. weightVefore, _ := strconv.ParseFloat(dataBody["weight_before"].(string), 64)
  1267. evaluation.WeightBefore = weightVefore
  1268. }
  1269. // fmt.Println(dataBody["dry_weight"])
  1270. // fmt.Println(reflect.TypeOf(dataBody["dry_weight"]).String())
  1271. if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  1272. additionalWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  1273. fmt.Println(additionalWeight)
  1274. evaluation.DryWeight = additionalWeight
  1275. }
  1276. if dataBody["additional_weight"] != nil && reflect.TypeOf(dataBody["additional_weight"]).String() == "string" {
  1277. additionalWeight, _ := strconv.ParseFloat(dataBody["additional_weight"].(string), 64)
  1278. fmt.Println(additionalWeight)
  1279. evaluation.AdditionalWeight = additionalWeight
  1280. }
  1281. if dataBody["temperature"] != nil && reflect.TypeOf(dataBody["temperature"]).String() == "string" {
  1282. Temperature, _ := strconv.ParseFloat(dataBody["temperature"].(string), 64)
  1283. evaluation.Temperature = Temperature
  1284. }
  1285. if dataBody["systolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["systolic_blood_pressure"]).String() == "string" {
  1286. systolicBloodPressure, _ := strconv.ParseFloat(dataBody["systolic_blood_pressure"].(string), 64)
  1287. evaluation.SystolicBloodPressure = systolicBloodPressure
  1288. }
  1289. if dataBody["diastolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["diastolic_blood_pressure"]).String() == "string" {
  1290. diastolicBloodPressure, _ := strconv.ParseFloat(dataBody["diastolic_blood_pressure"].(string), 64)
  1291. evaluation.DiastolicBloodPressure = diastolicBloodPressure
  1292. }
  1293. if dataBody["pulse_frequency"] != nil && reflect.TypeOf(dataBody["pulse_frequency"]).String() == "string" {
  1294. pulseFrequency, _ := strconv.ParseFloat(dataBody["pulse_frequency"].(string), 64)
  1295. evaluation.PulseFrequency = pulseFrequency
  1296. }
  1297. if dataBody["breathing_rate"] != nil && reflect.TypeOf(dataBody["breathing_rate"]).String() == "string" {
  1298. breathingRate, _ := strconv.ParseFloat(dataBody["breathing_rate"].(string), 64)
  1299. evaluation.BreathingRate = breathingRate
  1300. }
  1301. if dataBody["last_post_dialysis"] != nil && reflect.TypeOf(dataBody["last_post_dialysis"]).String() == "string" {
  1302. lastPostDialysis, _ := dataBody["last_post_dialysis"].(string)
  1303. evaluation.LastPostDialysis = lastPostDialysis
  1304. }
  1305. if dataBody["dialysis_interphase"] != nil && reflect.TypeOf(dataBody["dialysis_interphase"]).String() == "string" {
  1306. dialysisInterphase, _ := dataBody["dialysis_interphase"].(string)
  1307. evaluation.DialysisInterphase = dialysisInterphase
  1308. }
  1309. if dataBody["symptom_before_dialysis"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis"]).String() == "string" {
  1310. symptomBeforeDialysis, _ := dataBody["symptom_before_dialysis"].(string)
  1311. evaluation.SymptomBeforeDialysis = symptomBeforeDialysis
  1312. }
  1313. if dataBody["catheter"] != nil && reflect.TypeOf(dataBody["catheter"]).String() == "string" {
  1314. catheter, _ := dataBody["catheter"].(string)
  1315. evaluation.Catheter = catheter
  1316. }
  1317. if dataBody["catheter_bend"] != nil && reflect.TypeOf(dataBody["catheter_bend"]).String() == "float64" {
  1318. catheter_bend := int(dataBody["catheter_bend"].(float64))
  1319. evaluation.CatheterBend = catheter_bend
  1320. }
  1321. if dataBody["complication"] != nil && reflect.TypeOf(dataBody["complication"]).String() == "string" {
  1322. Complication, _ := dataBody["complication"].(string)
  1323. evaluation.Complication = Complication
  1324. }
  1325. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  1326. remark := dataBody["remark"].(string)
  1327. evaluation.Remark = remark
  1328. }
  1329. if dataBody["machine_type"] != nil && reflect.TypeOf(dataBody["machine_type"]).String() == "string" {
  1330. machine_type := dataBody["machine_type"].(string)
  1331. evaluation.MachineType = machine_type
  1332. }
  1333. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "float64" {
  1334. blood_access_part_id := int64(dataBody["blood_access_part_id"].(float64))
  1335. evaluation.BloodAccessPartId = blood_access_part_id
  1336. }
  1337. if dataBody["blood_access_part_opera_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_opera_id"]).String() == "float64" {
  1338. blood_access_part_opera_id := int64(dataBody["blood_access_part_opera_id"].(float64))
  1339. evaluation.BloodAccessPartOperaId = blood_access_part_opera_id
  1340. }
  1341. if dataBody["internal_fistula"] != nil && reflect.TypeOf(dataBody["internal_fistula"]).String() == "string" {
  1342. internal_fistula, _ := dataBody["internal_fistula"].(string)
  1343. evaluation.InternalFistula = internal_fistula
  1344. }
  1345. if dataBody["internal_fistula_skin"] != nil && reflect.TypeOf(dataBody["internal_fistula_skin"]).String() == "string" {
  1346. internal_fistula_skin := dataBody["internal_fistula_skin"].(string)
  1347. evaluation.InternalFistulaSkin = internal_fistula_skin
  1348. }
  1349. if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "float64" {
  1350. is_hemorrhage := int64(dataBody["is_hemorrhage"].(float64))
  1351. if is_hemorrhage != 1 && is_hemorrhage != 2 {
  1352. is_hemorrhage = 0
  1353. }
  1354. evaluation.IsHemorrhage = is_hemorrhage
  1355. if is_hemorrhage == 1 {
  1356. if dataBody["hemorrhage"] != nil && reflect.TypeOf(dataBody["hemorrhage"]).String() == "string" {
  1357. hemorrhage, _ := dataBody["hemorrhage"].(string)
  1358. evaluation.Hemorrhage = hemorrhage
  1359. }
  1360. if dataBody["hemorrhage_other"] != nil && reflect.TypeOf(dataBody["hemorrhage_other"]).String() == "string" {
  1361. hemorrhage_other, _ := dataBody["hemorrhage_other"].(string)
  1362. evaluation.HemorrhageOther = hemorrhage_other
  1363. }
  1364. }
  1365. } else {
  1366. evaluation.IsHemorrhage = 0
  1367. }
  1368. if dataBody["blood_access_internal_fistula"] != nil && reflect.TypeOf(dataBody["blood_access_internal_fistula"]).String() == "string" {
  1369. blood_access_internal_fistula, _ := dataBody["blood_access_internal_fistula"].(string)
  1370. evaluation.BloodAccessInternalFistula = blood_access_internal_fistula
  1371. }
  1372. if dataBody["internal_fistula_other"] != nil && reflect.TypeOf(dataBody["internal_fistula_other"]).String() == "string" {
  1373. internal_fistula_other, _ := dataBody["internal_fistula_other"].(string)
  1374. evaluation.InternalFistulaOther = internal_fistula_other
  1375. }
  1376. if dataBody["blood_access_noise"] != nil && reflect.TypeOf(dataBody["blood_access_noise"]).String() == "float64" {
  1377. blood_access_noise := int64(dataBody["blood_access_noise"].(float64))
  1378. evaluation.BloodAccessNoise = blood_access_noise
  1379. }
  1380. if dataBody["puncture_way"] != nil && reflect.TypeOf(dataBody["puncture_way"]).String() == "float64" {
  1381. puncture_way := int64(dataBody["puncture_way"].(float64))
  1382. evaluation.PunctureWay = puncture_way
  1383. }
  1384. if dataBody["venous_catheterization"] != nil && reflect.TypeOf(dataBody["venous_catheterization"]).String() == "float64" {
  1385. venous_catheterization := int64(dataBody["venous_catheterization"].(float64))
  1386. evaluation.VenousCatheterization = venous_catheterization
  1387. }
  1388. if dataBody["venous_catheterization_part"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part"]).String() == "float64" {
  1389. venous_catheterization_part := int64(dataBody["venous_catheterization_part"].(float64))
  1390. evaluation.VenousCatheterizationPart = venous_catheterization_part
  1391. }
  1392. if dataBody["venous_catheterization_part_other"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part_other"]).String() == "string" {
  1393. venous_catheterization_part_other, _ := dataBody["venous_catheterization_part_other"].(string)
  1394. evaluation.VenousCatheterizationPartOther = venous_catheterization_part_other
  1395. }
  1396. if dataBody["ductus_arantii"] != nil && reflect.TypeOf(dataBody["ductus_arantii"]).String() == "string" {
  1397. ductus_arantii, _ := dataBody["ductus_arantii"].(string)
  1398. evaluation.DuctusArantii = ductus_arantii
  1399. }
  1400. if dataBody["emergency_treatment"] != nil && reflect.TypeOf(dataBody["emergency_treatment"]).String() == "float64" {
  1401. emergency_treatment := int64(dataBody["emergency_treatment"].(float64))
  1402. evaluation.EmergencyTreatment = emergency_treatment
  1403. }
  1404. if dataBody["emergency_treatment_other"] != nil && reflect.TypeOf(dataBody["emergency_treatment_other"]).String() == "string" {
  1405. emergency_treatment_other, _ := dataBody["emergency_treatment_other"].(string)
  1406. evaluation.EmergencyTreatmentOther = emergency_treatment_other
  1407. }
  1408. if dataBody["dialysis_count"] != nil && reflect.TypeOf(dataBody["dialysis_count"]).String() == "string" {
  1409. dialysis_count, _ := dataBody["dialysis_count"].(string)
  1410. count, _ := strconv.ParseInt(dialysis_count, 10, 64)
  1411. evaluation.DialysisCount = count
  1412. }
  1413. if dataBody["is_infect"] != nil && reflect.TypeOf(dataBody["is_infect"]).String() == "string" {
  1414. is_infect, _ := dataBody["is_infect"].(string)
  1415. infect, _ := strconv.ParseInt(is_infect, 10, 64)
  1416. evaluation.IsInfect = infect
  1417. }
  1418. if dataBody["exposed"] != nil && reflect.TypeOf(dataBody["exposed"]).String() == "string" {
  1419. exposed, _ := strconv.ParseFloat(dataBody["exposed"].(string), 64)
  1420. evaluation.Exposed = exposed
  1421. }
  1422. if dataBody["skin"] != nil && reflect.TypeOf(dataBody["skin"]).String() == "string" {
  1423. skin, _ := dataBody["skin"].(string)
  1424. skins, _ := strconv.ParseInt(skin, 10, 64)
  1425. evaluation.Skin = skins
  1426. }
  1427. if dataBody["skin_other"] != nil && reflect.TypeOf(dataBody["skin_other"]).String() == "string" {
  1428. skin_other, _ := dataBody["skin_other"].(string)
  1429. evaluation.SkinOther = skin_other
  1430. }
  1431. if dataBody["infect_other"] != nil && reflect.TypeOf(dataBody["infect_other"]).String() == "string" {
  1432. infect_other, _ := dataBody["infect_other"].(string)
  1433. evaluation.InfectOther = infect_other
  1434. }
  1435. if dataBody["ductus_arantii_other"] != nil && reflect.TypeOf(dataBody["ductus_arantii_other"]).String() == "string" {
  1436. ductus_arantii_other, _ := dataBody["ductus_arantii_other"].(string)
  1437. evaluation.DuctusArantiiOther = ductus_arantii_other
  1438. }
  1439. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  1440. punctureNeedle, _ := dataBody["puncture_needle"].(string)
  1441. evaluation.PunctureNeedle = punctureNeedle
  1442. }
  1443. return
  1444. }
  1445. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  1446. dataBody := make(map[string]interface{}, 0)
  1447. err := json.Unmarshal(data, &dataBody)
  1448. if err != nil {
  1449. utils.ErrorLog(err.Error())
  1450. code = enums.ErrorCodeParamWrong
  1451. return
  1452. }
  1453. timeLayout := "2006-01-02"
  1454. loc, _ := time.LoadLocation("Local")
  1455. isChild := false
  1456. if action == "create" {
  1457. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  1458. utils.ErrorLog("advice_type")
  1459. code = enums.ErrorCodeParamWrong
  1460. return
  1461. }
  1462. adviceType := int64(dataBody["advice_type"].(float64))
  1463. if adviceType != 1 && adviceType != 2 {
  1464. utils.ErrorLog("advice_type != 1&&2")
  1465. code = enums.ErrorCodeParamWrong
  1466. return
  1467. }
  1468. advice.AdviceType = adviceType
  1469. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  1470. utils.ErrorLog("advice_date")
  1471. code = enums.ErrorCodeParamWrong
  1472. return
  1473. }
  1474. adviceDate, _ := dataBody["advice_date"].(string)
  1475. if len(adviceDate) == 0 {
  1476. utils.ErrorLog("len(adviceDate) == 0")
  1477. code = enums.ErrorCodeParamWrong
  1478. return
  1479. }
  1480. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  1481. if err != nil {
  1482. utils.ErrorLog(err.Error())
  1483. code = enums.ErrorCodeParamWrong
  1484. return
  1485. }
  1486. advice.AdviceDate = theTime.Unix()
  1487. advice.RecordDate = theTime.Unix()
  1488. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  1489. parentId := int64(dataBody["parent_id"].(float64))
  1490. advice.ParentId = parentId
  1491. if parentId > 0 {
  1492. isChild = true
  1493. }
  1494. }
  1495. } else {
  1496. isChild = advice.ParentId > 0
  1497. }
  1498. if !isChild {
  1499. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  1500. utils.ErrorLog("start_time")
  1501. code = enums.ErrorCodeParamWrong
  1502. return
  1503. }
  1504. startTime, _ := dataBody["start_time"].(string)
  1505. fmt.Println(startTime)
  1506. if len(startTime) == 0 {
  1507. utils.ErrorLog("len(start_time) == 0")
  1508. code = enums.ErrorCodeParamWrong
  1509. return
  1510. }
  1511. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  1512. if err != nil {
  1513. utils.ErrorLog(err.Error())
  1514. code = enums.ErrorCodeParamWrong
  1515. return
  1516. }
  1517. advice.StartTime = theTime.Unix()
  1518. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  1519. deliveryWay, _ := dataBody["delivery_way"].(string)
  1520. advice.DeliveryWay = deliveryWay
  1521. }
  1522. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  1523. executionFrequency, _ := dataBody["execution_frequency"].(string)
  1524. advice.ExecutionFrequency = executionFrequency
  1525. }
  1526. }
  1527. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  1528. deliveryWay, _ := dataBody["delivery_way"].(string)
  1529. advice.DeliveryWay = deliveryWay
  1530. }
  1531. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  1532. executionFrequency, _ := dataBody["execution_frequency"].(string)
  1533. advice.ExecutionFrequency = executionFrequency
  1534. }
  1535. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  1536. utils.ErrorLog("advice_name")
  1537. code = enums.ErrorCodeParamWrong
  1538. return
  1539. }
  1540. adviceName, _ := dataBody["advice_name"].(string)
  1541. if len(adviceName) == 0 {
  1542. utils.ErrorLog("len(advice_name) == 0")
  1543. code = enums.ErrorCodeParamWrong
  1544. return
  1545. }
  1546. advice.AdviceName = adviceName
  1547. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  1548. adviceDsc, _ := dataBody["advice_desc"].(string)
  1549. advice.AdviceDesc = adviceDsc
  1550. }
  1551. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  1552. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  1553. advice.SingleDose = singleDose
  1554. }
  1555. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  1556. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  1557. advice.SingleDoseUnit = singleDoseUnit
  1558. }
  1559. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  1560. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  1561. advice.DrugSpec = drugSpec
  1562. }
  1563. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  1564. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  1565. advice.DrugSpecUnit = drugSpecUnit
  1566. }
  1567. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  1568. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  1569. advice.PrescribingNumber = prescribingNumber
  1570. }
  1571. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  1572. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  1573. advice.PrescribingNumberUnit = prescribingNumberUnit
  1574. }
  1575. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  1576. remark, _ := dataBody["remark"].(string)
  1577. advice.Remark = remark
  1578. }
  1579. return
  1580. }
  1581. func (c *PatientApiController) GetPatientEducation() {
  1582. patientID, _ := c.GetInt64("patient_id", 0)
  1583. page, _ := c.GetInt64("page", 0)
  1584. limit, _ := c.GetInt64("limit", 0)
  1585. startTime := c.GetString("start_time", "")
  1586. endTime := c.GetString("end_time", "")
  1587. if page <= 0 {
  1588. page = 1
  1589. }
  1590. if limit <= 0 {
  1591. limit = 10
  1592. }
  1593. if patientID <= 0 {
  1594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1595. return
  1596. }
  1597. timeLayout := "2006-01-02"
  1598. loc, _ := time.LoadLocation("Local")
  1599. var theStartTIme int64
  1600. if len(startTime) > 0 {
  1601. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  1602. if err != nil {
  1603. theStartTIme = 0
  1604. }
  1605. theStartTIme = theTime.Unix()
  1606. }
  1607. var theEndtTIme int64
  1608. if len(endTime) > 0 {
  1609. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  1610. if err != nil {
  1611. theEndtTIme = 0
  1612. }
  1613. theEndtTIme = theTime.Unix()
  1614. }
  1615. adminUserInfo := c.GetMobileAdminUserInfo()
  1616. edus, total, _ := service.GetPatientTreatmentSummaryList(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme)
  1617. c.ServeSuccessJSON(map[string]interface{}{
  1618. "total": total,
  1619. "edus": edus,
  1620. })
  1621. return
  1622. }
  1623. func (c *PatientApiController) GetPatientSchedulesList() {
  1624. patientID, _ := c.GetInt64("patient_id", 0)
  1625. page, _ := c.GetInt64("page", 0)
  1626. limit, _ := c.GetInt64("limit", 0)
  1627. if patientID <= 0 {
  1628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1629. return
  1630. }
  1631. adminUserInfo := c.GetMobileAdminUserInfo()
  1632. todayTime := time.Now().Format("2006-01-02")
  1633. timeLayout := "2006-01-02 15:04:05"
  1634. loc, _ := time.LoadLocation("Local")
  1635. var theStartTime int64
  1636. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  1637. theStartTime = theTime.Unix()
  1638. schedules, _ := service.GetPatientScheduleList(adminUserInfo.Org.Id, patientID, page, limit, theStartTime)
  1639. if len(schedules) > 0 {
  1640. for index, item := range schedules {
  1641. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  1642. schedules[index].Week = int64(week)
  1643. }
  1644. }
  1645. c.ServeSuccessJSON(map[string]interface{}{
  1646. "schedules": schedules,
  1647. })
  1648. return
  1649. }
  1650. func (c *PatientApiController) GetRecords() {
  1651. patientID, _ := c.GetInt64("patient_id", 0)
  1652. page, _ := c.GetInt64("page", 0)
  1653. limit, _ := c.GetInt64("limit", 0)
  1654. startTime := c.GetString("start_time", "")
  1655. endTime := c.GetString("end_time", "")
  1656. mode_id, _ := c.GetInt64("mode_id", 0)
  1657. if page <= 0 {
  1658. page = 1
  1659. }
  1660. if limit <= 0 {
  1661. limit = 10
  1662. }
  1663. if patientID <= 0 {
  1664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1665. return
  1666. }
  1667. timeLayout := "2006-01-02"
  1668. loc, _ := time.LoadLocation("Local")
  1669. var theStartTIme int64
  1670. if len(startTime) > 0 {
  1671. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  1672. if err != nil {
  1673. theStartTIme = 0
  1674. }
  1675. theStartTIme = theTime.Unix()
  1676. }
  1677. var theEndtTIme int64
  1678. if len(endTime) > 0 {
  1679. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  1680. if err != nil {
  1681. theEndtTIme = 0
  1682. }
  1683. theEndtTIme = theTime.Unix()
  1684. }
  1685. adminUserInfo := c.GetMobileAdminUserInfo()
  1686. records, total, _ := service.GetPatientDialysisRecord(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  1687. c.ServeSuccessJSON(map[string]interface{}{
  1688. "total": total,
  1689. "records": records,
  1690. })
  1691. return
  1692. }
  1693. func (c *PatientApiController) GetPatientMonitor() {
  1694. partition, _ := c.GetInt64("partition")
  1695. monitorDate := c.GetString("date")
  1696. timeLayout := "2006-01-02"
  1697. loc, _ := time.LoadLocation("Local")
  1698. var theStartTime int64
  1699. if len(monitorDate) > 0 {
  1700. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  1701. if err != nil {
  1702. theStartTime = 0
  1703. }
  1704. theStartTime = theTime.Unix()
  1705. }
  1706. adminInfo := c.GetMobileAdminUserInfo()
  1707. orgID := adminInfo.Org.Id
  1708. monitor, err := service.GetMonitorRecord(orgID, theStartTime, partition)
  1709. if err == nil {
  1710. c.ServeSuccessJSON(map[string]interface{}{
  1711. "monitor": monitor,
  1712. })
  1713. } else {
  1714. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1715. }
  1716. }
  1717. // /m/api/monitor/patient [get] 搜索病人的测量记录
  1718. // @param keyword:string 病人姓名或透析号
  1719. // @param page:int
  1720. func (this *PatientApiController) SearchMonitorPatient() {
  1721. keyword := this.GetString("keyword")
  1722. page, _ := this.GetInt("page")
  1723. if page <= 0 {
  1724. page = 1
  1725. }
  1726. if len(keyword) == 0 {
  1727. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1728. return
  1729. }
  1730. adminUserInfo := this.GetMobileAdminUserInfo()
  1731. monitors, getMonitorErr := service.MobileGetMonitorsWithPatient(adminUserInfo.Org.Id, keyword, page)
  1732. if getMonitorErr != nil {
  1733. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1734. return
  1735. } else {
  1736. this.ServeSuccessJSON(map[string]interface{}{
  1737. "monitor": monitors,
  1738. })
  1739. }
  1740. }
  1741. func (c *PatientApiController) GetPatientDialysisSolutionList() {
  1742. id, _ := c.GetInt64("id", 0)
  1743. page, _ := c.GetInt64("page", 0)
  1744. limit, _ := c.GetInt64("limit", 0)
  1745. if id <= 0 {
  1746. c.ServeSuccessJSON(map[string]interface{}{
  1747. "solutions": nil,
  1748. })
  1749. return
  1750. }
  1751. if page <= 0 {
  1752. page = 1
  1753. }
  1754. if limit <= 0 {
  1755. limit = 10
  1756. }
  1757. adminInfo := c.GetMobileAdminUserInfo()
  1758. solutions, total, _ := service.GetPatientDialysisSolutionList(adminInfo.Org.Id, id, page, limit)
  1759. c.ServeSuccessJSON(map[string]interface{}{
  1760. "solutions": solutions,
  1761. "total": total,
  1762. })
  1763. return
  1764. }
  1765. //GetDoctorAdvices 医嘱列表
  1766. func (c *PatientApiController) GetDoctorAdvices() {
  1767. id, _ := c.GetInt64("id", 0)
  1768. adviceType, _ := c.GetInt64("advice_type", 0)
  1769. stopType, _ := c.GetInt64("stop_state", 0)
  1770. startTime := c.GetString("start_time", "")
  1771. endTime := c.GetString("end_time", "")
  1772. keywords := c.GetString("keywords", "")
  1773. need, _ := c.GetInt64("need_doctor", 0)
  1774. adminUserInfo := c.GetMobileAdminUserInfo()
  1775. timeLayout := "2006-01-02"
  1776. loc, _ := time.LoadLocation("Local")
  1777. var theStartTIme int64
  1778. if len(startTime) > 0 {
  1779. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  1780. if err != nil {
  1781. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1782. return
  1783. }
  1784. theStartTIme = theTime.Unix()
  1785. }
  1786. var theEndtTIme int64
  1787. if len(endTime) > 0 {
  1788. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  1789. if err != nil {
  1790. utils.ErrorLog(err.Error())
  1791. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1792. return
  1793. }
  1794. theEndtTIme = theTime.Unix()
  1795. }
  1796. advices, total, _ := service.GetDoctorAdviceList(adminUserInfo.Org.Id, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords)
  1797. if need == 1 {
  1798. users, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  1799. c.ServeSuccessJSON(map[string]interface{}{
  1800. "advices": advices,
  1801. "total": total,
  1802. "users": users,
  1803. })
  1804. } else {
  1805. c.ServeSuccessJSON(map[string]interface{}{
  1806. "advices": advices,
  1807. "total": total,
  1808. "users": []string{},
  1809. })
  1810. }
  1811. return
  1812. }
  1813. func (c *PatientApiController) GetPrintDialysisOrder() {
  1814. xtno := c.GetString("xtno")
  1815. xtdate := c.GetString("xtdate")
  1816. timeLayout := "2006-01-02"
  1817. loc, _ := time.LoadLocation("Local")
  1818. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  1819. if err != nil {
  1820. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1821. return
  1822. }
  1823. xttime := theTime.Unix()
  1824. operatorIDs := make([]int64, 0)
  1825. adminUserInfo := c.GetMobileAdminUserInfo()
  1826. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  1827. patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.Org.Id, xtno, xttime)
  1828. //透析单
  1829. dialysisOrder, _ := service.MobileGetSchedualDialysisRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  1830. if dialysisOrder != nil {
  1831. if dialysisOrder.FinishNurse > 0 {
  1832. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  1833. }
  1834. if dialysisOrder.StartNurse > 0 {
  1835. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  1836. }
  1837. }
  1838. //透前评估
  1839. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  1840. //透后评估
  1841. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  1842. if AssessmentAfterDislysis.Modifier > 0 {
  1843. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  1844. }
  1845. //透析处方
  1846. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  1847. if dialysisPrescription.PrescriptionDoctor > 0 {
  1848. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  1849. }
  1850. //临时医嘱
  1851. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  1852. if len(DoctorAdvice) > 0 {
  1853. for _, item := range DoctorAdvice {
  1854. if item.AdviceDoctor > 0 {
  1855. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  1856. }
  1857. if item.ExecutionStaff > 0 {
  1858. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  1859. }
  1860. if item.Checker > 0 {
  1861. operatorIDs = append(operatorIDs, item.Checker)
  1862. }
  1863. }
  1864. }
  1865. //透析监测
  1866. Record, _ := service.FindAllMonitorRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  1867. //透析小结
  1868. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  1869. //接诊评估
  1870. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  1871. //相关操作对应的操作人
  1872. //operators, _ := service.GetAdminUserES(adminUserInfo.Org.Id, adminUserInfo.App.Id, operatorIDs)
  1873. operators, err := service.GetAllStarfEs(adminUserInfo.Org.Id)
  1874. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1875. check, _ := service.FindDoubleCheckById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  1876. c.ServeSuccessJSON(map[string]interface{}{
  1877. "users": adminUser,
  1878. "patientInfo": patientInfo,
  1879. "PredialysisEvaluation": PredialysisEvaluation,
  1880. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  1881. "dialysisPrescription": dialysisPrescription,
  1882. "advices": DoctorAdvice,
  1883. "monitors": Record,
  1884. "summary": TreatmentSummary,
  1885. "receiverTreatmentAccess": receiverTreatmentAccess,
  1886. "dialysisOrder": dialysisOrder,
  1887. "operators": operators,
  1888. "org_template_info": templateInfo,
  1889. "check": check,
  1890. })
  1891. }
  1892. func (c *PatientApiController) CreateGroupAdvice() {
  1893. is_child, _ := c.GetInt64("is_child", 0)
  1894. if is_child == 1 {
  1895. patient, _ := c.GetInt64("id", 0)
  1896. if patient <= 0 {
  1897. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1898. return
  1899. }
  1900. adminUserInfo := c.GetMobileAdminUserInfo()
  1901. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  1902. if patientInfo.ID == 0 {
  1903. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1904. return
  1905. }
  1906. group_no, _ := c.GetInt64("group_no")
  1907. if group_no <= 0 {
  1908. group_no = 0
  1909. }
  1910. dataBody := make(map[string]interface{}, 0)
  1911. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1912. if err != nil {
  1913. utils.ErrorLog(err.Error())
  1914. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1915. return
  1916. }
  1917. timeLayout := "2006-01-02"
  1918. loc, _ := time.LoadLocation("Local")
  1919. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  1920. utils.ErrorLog("advice_type")
  1921. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1922. return
  1923. }
  1924. adviceType := int64(dataBody["advice_type"].(float64))
  1925. if adviceType != 1 && adviceType != 2 {
  1926. utils.ErrorLog("advice_type != 1&&2")
  1927. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1928. return
  1929. }
  1930. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  1931. utils.ErrorLog("start_time")
  1932. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1933. return
  1934. }
  1935. startTime2, _ := dataBody["start_time"].(string)
  1936. time_arr := strings.Split(startTime2, " ")
  1937. if len(time_arr) > 0 {
  1938. startTime2 = time_arr[0]
  1939. }
  1940. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  1941. utils.ErrorLog("advice_date")
  1942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1943. return
  1944. }
  1945. adviceDate := startTime2
  1946. if len(adviceDate) == 0 {
  1947. utils.ErrorLog("len(adviceDate) == 0")
  1948. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1949. return
  1950. }
  1951. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  1952. if err != nil {
  1953. utils.ErrorLog(err.Error())
  1954. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1955. return
  1956. }
  1957. AdviceDate := theTime.Unix()
  1958. RecordDate := theTime.Unix()
  1959. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  1960. utils.ErrorLog("start_time")
  1961. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1962. return
  1963. }
  1964. startTime, _ := dataBody["start_time"].(string)
  1965. if len(startTime) == 0 {
  1966. utils.ErrorLog("len(start_time) == 0")
  1967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1968. return
  1969. }
  1970. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  1971. if err != nil {
  1972. utils.ErrorLog(err.Error())
  1973. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1974. return
  1975. }
  1976. StartTime := theTime.Unix()
  1977. Remark := ""
  1978. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  1979. remark, _ := dataBody["remark"].(string)
  1980. Remark = remark
  1981. }
  1982. var advices []*models.GroupAdvice
  1983. // utils.TraceLog("%+v", dataBody["adviceNames"])
  1984. if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
  1985. utils.ErrorLog("adviceNames")
  1986. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1987. return
  1988. }
  1989. adviceNames := dataBody["adviceNames"].([]interface{})
  1990. for _, adviceNameMap := range adviceNames {
  1991. adviceNameM := adviceNameMap.(map[string]interface{})
  1992. var advice models.GroupAdvice
  1993. advice.Remark = Remark
  1994. advice.AdviceType = adviceType
  1995. advice.StartTime = StartTime
  1996. advice.AdviceDate = AdviceDate
  1997. advice.RecordDate = RecordDate
  1998. advice.Status = 1
  1999. advice.CreatedTime = time.Now().Unix()
  2000. advice.UpdatedTime = time.Now().Unix()
  2001. advice.StopState = 2
  2002. advice.ExecutionState = 2
  2003. advice.UserOrgId = adminUserInfo.Org.Id
  2004. advice.PatientId = patientInfo.ID
  2005. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  2006. errcode := c.setAdviceWithJSON(&advice, adviceNameM)
  2007. if errcode > 0 {
  2008. c.ServeFailJSONWithSGJErrorCode(errcode)
  2009. return
  2010. }
  2011. if adviceNameM["subdrugs"] != nil && reflect.TypeOf(adviceNameM["subdrugs"]).String() == "[]interface {}" {
  2012. subdrugs := adviceNameM["subdrugs"].([]interface{})
  2013. if len(subdrugs) > 0 {
  2014. for _, subdrug := range subdrugs {
  2015. var s models.GroupAdvice
  2016. s.Remark = Remark
  2017. s.AdviceType = adviceType
  2018. s.StartTime = StartTime
  2019. s.AdviceDate = AdviceDate
  2020. s.RecordDate = RecordDate
  2021. s.Status = 1
  2022. s.CreatedTime = time.Now().Unix()
  2023. s.UpdatedTime = time.Now().Unix()
  2024. s.StopState = 2
  2025. s.ExecutionState = 2
  2026. s.UserOrgId = adminUserInfo.Org.Id
  2027. s.PatientId = patientInfo.ID
  2028. s.AdviceDoctor = adminUserInfo.AdminUser.Id
  2029. errcode := c.setAdviceWithJSON(&s, subdrug.(map[string]interface{}))
  2030. if errcode > 0 {
  2031. c.ServeFailJSONWithSGJErrorCode(errcode)
  2032. return
  2033. }
  2034. advice.Children = append(advice.Children, &s)
  2035. }
  2036. }
  2037. }
  2038. advices = append(advices, &advice)
  2039. }
  2040. newAdvices, createErr := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, group_no)
  2041. if createErr != nil {
  2042. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  2043. return
  2044. }
  2045. c.ServeSuccessJSON(map[string]interface{}{
  2046. "msg": "ok",
  2047. "advices": newAdvices,
  2048. })
  2049. return
  2050. } else if is_child == 2 {
  2051. patient, _ := c.GetInt64("id", 0)
  2052. if patient <= 0 {
  2053. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2054. return
  2055. }
  2056. adminUserInfo := c.GetMobileAdminUserInfo()
  2057. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  2058. if patientInfo.ID == 0 {
  2059. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2060. return
  2061. }
  2062. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2063. //if appRole.UserType == 3{
  2064. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdvicePermissionDeniedModify)
  2065. // return
  2066. //}
  2067. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2068. //
  2069. //if appRole.UserType == 3 {
  2070. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2071. // if getPermissionErr != nil {
  2072. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2073. // return
  2074. // } else if headNursePermission == nil {
  2075. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2076. // return
  2077. // }
  2078. //}
  2079. var advice models.DoctorAdvice
  2080. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  2081. if code > 0 {
  2082. c.ServeFailJSONWithSGJErrorCode(code)
  2083. return
  2084. }
  2085. if advice.ParentId > 0 {
  2086. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  2087. if old.ID == 0 || old.PatientId != patient {
  2088. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  2089. return
  2090. }
  2091. if old.StopState == 1 || old.ExecutionState == 1 {
  2092. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  2093. return
  2094. }
  2095. if old.ParentId > 0 {
  2096. advice.ParentId = old.ParentId
  2097. }
  2098. advice.StartTime = old.StartTime
  2099. advice.AdviceDoctor = old.AdviceDoctor
  2100. advice.DeliveryWay = old.DeliveryWay
  2101. advice.ExecutionFrequency = old.ExecutionFrequency
  2102. advice.GroupNo = old.GroupNo
  2103. }
  2104. advice.Status = 1
  2105. advice.CreatedTime = time.Now().Unix()
  2106. advice.UpdatedTime = time.Now().Unix()
  2107. advice.StopState = 2
  2108. advice.ExecutionState = 2
  2109. advice.UserOrgId = adminUserInfo.Org.Id
  2110. advice.PatientId = patient
  2111. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  2112. err := service.CreateDoctorAdvice(&advice)
  2113. if err != nil {
  2114. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  2115. return
  2116. }
  2117. c.ServeSuccessJSON(map[string]interface{}{
  2118. "msg": "ok",
  2119. "advice": advice,
  2120. })
  2121. return
  2122. }
  2123. }
  2124. func (c *PatientApiController) setAdviceWithJSON(advice *models.GroupAdvice, json map[string]interface{}) int {
  2125. if json["advice_name"] == nil || reflect.TypeOf(json["advice_name"]).String() != "string" {
  2126. utils.ErrorLog("advice_name")
  2127. return enums.ErrorCodeParamWrong
  2128. }
  2129. adviceName, _ := json["advice_name"].(string)
  2130. if len(adviceName) == 0 {
  2131. utils.ErrorLog("len(advice_name) == 0")
  2132. return enums.ErrorCodeParamWrong
  2133. }
  2134. advice.AdviceName = adviceName
  2135. adviceDesc, _ := json["advice_desc"].(string)
  2136. advice.AdviceDesc = adviceDesc
  2137. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  2138. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  2139. advice.DrugSpec = drugSpec
  2140. }
  2141. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  2142. remark, _ := json["remark"].(string)
  2143. advice.Remark = remark
  2144. }
  2145. if json["drug_spec_unit"] != nil && reflect.TypeOf(json["drug_spec_unit"]).String() == "string" {
  2146. drugSpecUnit, _ := json["drug_spec_unit"].(string)
  2147. advice.DrugSpecUnit = drugSpecUnit
  2148. }
  2149. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  2150. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  2151. advice.SingleDose = singleDose
  2152. }
  2153. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  2154. singleDoseUnit, _ := json["single_dose_unit"].(string)
  2155. advice.SingleDoseUnit = singleDoseUnit
  2156. }
  2157. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  2158. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  2159. advice.PrescribingNumber = prescribingNumber
  2160. }
  2161. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  2162. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  2163. advice.PrescribingNumberUnit = prescribingNumberUnit
  2164. }
  2165. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  2166. deliveryWay, _ := json["delivery_way"].(string)
  2167. advice.DeliveryWay = deliveryWay
  2168. }
  2169. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  2170. executionFrequency, _ := json["execution_frequency"].(string)
  2171. advice.ExecutionFrequency = executionFrequency
  2172. }
  2173. return 0
  2174. }
  2175. func (c *PatientApiController) DelDoctorAdvice() {
  2176. groupno, _ := c.GetInt64("groupno", -1)
  2177. is_sub, _ := c.GetInt64("is_sub", -1) //是否子药
  2178. if is_sub == 1 { //是
  2179. advice_id, _ := c.GetInt64("advice_id")
  2180. adminUserInfo := c.GetMobileAdminUserInfo()
  2181. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  2182. if advice.ID == 0 {
  2183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2184. return
  2185. }
  2186. advice.Status = 0
  2187. advice.UpdatedTime = time.Now().Unix()
  2188. advice.Modifier = adminUserInfo.AdminUser.Id
  2189. err := service.DeleteDoctorAdvice(&advice)
  2190. if err != nil {
  2191. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  2192. return
  2193. }
  2194. c.ServeSuccessJSON(map[string]interface{}{
  2195. "msg": "ok",
  2196. })
  2197. return
  2198. } else { //
  2199. var ids []string
  2200. if groupno == 0 {
  2201. advice_id := c.GetString("advice_id")
  2202. ids = strings.Split(advice_id, ",")
  2203. if len(ids) <= 0 {
  2204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2205. return
  2206. }
  2207. }
  2208. if groupno < 0 {
  2209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2210. return
  2211. }
  2212. adminUserInfo := c.GetMobileAdminUserInfo()
  2213. var advice models.DoctorAdvice
  2214. if groupno > 0 {
  2215. advice, _ = service.FindDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  2216. if advice.ID == 0 {
  2217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2218. return
  2219. }
  2220. } else {
  2221. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  2222. for _, item := range advices {
  2223. if item.ID == 0 {
  2224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2225. return
  2226. }
  2227. }
  2228. }
  2229. advice.UpdatedTime = time.Now().Unix()
  2230. advice.Status = 0
  2231. advice.GroupNo = groupno
  2232. advice.Modifier = adminUserInfo.AdminUser.Id
  2233. var err error
  2234. if groupno > 0 {
  2235. err = service.DeleteDoctorAdviceByGroupNo(&advice)
  2236. } else {
  2237. err = service.BatchDeleteDoctorAdvice(ids, adminUserInfo.AdminUser.Id)
  2238. }
  2239. if err != nil {
  2240. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  2241. return
  2242. }
  2243. c.ServeSuccessJSON(map[string]interface{}{
  2244. "msg": "ok",
  2245. })
  2246. return
  2247. }
  2248. }
  2249. // /m/api/advice/group/modify_starttime [post]
  2250. // @param group_no:int
  2251. // @param start_time:string yyyy-MM-dd hh:mm:ss
  2252. func (this *PatientApiController) ModifyAdviceGroupStartTime() {
  2253. group_no, _ := this.GetInt64("group_no")
  2254. start_time_str := this.GetString("start_time")
  2255. if group_no <= 0 || len(start_time_str) == 0 {
  2256. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2257. return
  2258. }
  2259. startTime, parseTimeErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time_str)
  2260. if parseTimeErr != nil {
  2261. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  2262. return
  2263. }
  2264. adminUserInfo := this.GetMobileAdminUserInfo()
  2265. updateStartTimeErr := service.UpdateAdviceGroupStartTime(adminUserInfo.Org.Id, group_no, startTime.Unix(), adminUserInfo.AdminUser.Id)
  2266. if updateStartTimeErr != nil {
  2267. utils.ErrorLog("修改医嘱分组的开始时间失败:%v", updateStartTimeErr)
  2268. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2269. return
  2270. }
  2271. this.ServeSuccessJSON(map[string]interface{}{
  2272. "start_time": startTime.Unix(),
  2273. })
  2274. }
  2275. func (this *PatientApiController) DelSubDoctorAdvice() {
  2276. advice_id, _ := this.GetInt64("advice_id")
  2277. adminUserInfo := this.GetMobileAdminUserInfo()
  2278. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  2279. if advice.ID == 0 {
  2280. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2281. return
  2282. }
  2283. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  2284. // this.ServeFailJSONWithSGJErrorCode(enums. bh)
  2285. // return
  2286. //}
  2287. advice.Status = 0
  2288. advice.UpdatedTime = time.Now().Unix()
  2289. advice.Modifier = adminUserInfo.AdminUser.Id
  2290. err := service.DeleteDoctorAdvice(&advice)
  2291. if err != nil {
  2292. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  2293. return
  2294. }
  2295. this.ServeSuccessJSON(map[string]interface{}{
  2296. "msg": "ok",
  2297. })
  2298. return
  2299. }
  2300. func (this *PatientApiController) GetAdviceUnReadMessage() {
  2301. //adminUserInfo := this.GetMobileAdminUserInfo()
  2302. //service.FindUnReadDoctorAdviceMessage()
  2303. }
  2304. func (this *PatientApiController) GetPatientsByKeyWord() {
  2305. keyWord := this.GetString("keyword")
  2306. adminUserInfo := this.GetMobileAdminUserInfo()
  2307. today := utils.ZeroHourTimeOfDay(time.Now())
  2308. patient, err := service.GetSchedualPatientByKeyWord(adminUserInfo.Org.Id, keyWord, today.Unix())
  2309. if err != nil {
  2310. utils.ErrorLog(err.Error())
  2311. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2312. return
  2313. }
  2314. this.ServeSuccessJSON(map[string]interface{}{
  2315. "patient": patient,
  2316. })
  2317. }