patient_api_controller.go 113KB

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