patient_api_controller.go 96KB

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