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