patient_api_controller.go 115KB

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