patient_api_controller.go 91KB

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