patient_api_controller.go 88KB

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