patient_api_controller.go 93KB

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