patient_api_controller.go 117KB

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