patient_api_controller.go 93KB

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