patient_api_controller.go 145KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069
  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. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  209. redis := service.RedisClient()
  210. defer redis.Close()
  211. redis.Set(key, "", time.Second)
  212. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  213. redis.Set(keyOne, "", time.Second)
  214. if err != nil {
  215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  216. return
  217. }
  218. c.ServeSuccessJSON(map[string]interface{}{
  219. "msg": "ok",
  220. "advice": advice,
  221. })
  222. return
  223. }
  224. func (c *PatientApiController) EditDoctorAdvice() {
  225. id, _ := c.GetInt64("id", 0)
  226. patient_id, _ := c.GetInt64("patient_id")
  227. doc_advice_date, _ := c.GetInt64("advice_date")
  228. if id <= 0 {
  229. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  230. return
  231. }
  232. redis := service.RedisClient()
  233. adminUserInfo := c.GetMobileAdminUserInfo()
  234. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  235. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  236. //
  237. //if appRole.UserType == 3 {
  238. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  239. // if getPermissionErr != nil {
  240. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  241. // return
  242. // } else if headNursePermission == nil {
  243. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  244. // return
  245. // }
  246. //}
  247. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  248. if advice.ID == 0 {
  249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  250. return
  251. }
  252. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
  253. if code > 0 {
  254. c.ServeFailJSONWithSGJErrorCode(code)
  255. return
  256. }
  257. advice.Status = 1
  258. advice.UpdatedTime = time.Now().Unix()
  259. advice.UserOrgId = adminUserInfo.Org.Id
  260. advice.Modifier = adminUserInfo.AdminUser.Id
  261. //处理修改医嘱开始时间逻辑(不包括子医嘱)
  262. //1.一组医嘱内只有一条医嘱(不包括子医嘱)的情况下,只需要直接修改医嘱开始时间,不需要重新分配组号
  263. //2.一组医嘱内有多条医嘱(不包括子医嘱)的情况下,需要为修改的那条医嘱重新分配组号,并修改医嘱开始时间
  264. var err error
  265. var isChangeGroup bool
  266. if advice.ParentId == 0 {
  267. adviceSlice, _ := service.FindAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
  268. sourceAdvice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice.ID)
  269. if len(adviceSlice) == 1 {
  270. //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要修改子医嘱的开始时间,如果相同直接修改,不需要修改子医嘱的开始时间
  271. if advice.StartTime == sourceAdvice.StartTime {
  272. err = service.UpdateDoctorAdvice(&advice)
  273. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  274. defer redis.Close()
  275. redis.Set(key, "", time.Second)
  276. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":advice_list_all"
  277. redis.Set(keyOne, "", time.Second)
  278. isChangeGroup = false
  279. } else {
  280. err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
  281. isChangeGroup = false
  282. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  283. defer redis.Close()
  284. redis.Set(key, "", time.Second)
  285. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  286. redis.Set(keyOne, "", time.Second)
  287. }
  288. } else if len(adviceSlice) > 1 {
  289. //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要重新分配组,如果相同直接修改,不需要分配组
  290. if advice.StartTime == sourceAdvice.StartTime {
  291. err = service.UpdateDoctorAdvice(&advice)
  292. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  293. defer redis.Close()
  294. redis.Set(key, "", time.Second)
  295. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  296. redis.Set(keyOne, "", time.Second)
  297. isChangeGroup = false
  298. } else {
  299. gruopNo := service.GetMaxAdviceGroupID(adminUserInfo.Org.Id)
  300. gruopNo = gruopNo + 1
  301. advice.GroupNo = gruopNo
  302. err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
  303. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  304. defer redis.Close()
  305. redis.Set(key, "", time.Second)
  306. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  307. redis.Set(keyOne, "", time.Second)
  308. isChangeGroup = true
  309. }
  310. }
  311. } else {
  312. isChangeGroup = false
  313. err = service.UpdateDoctorAdvice(&advice)
  314. redis := service.RedisClient()
  315. defer redis.Close()
  316. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  317. redis.Set(key, "", time.Second)
  318. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  319. redis.Set(keyOne, "", time.Second)
  320. }
  321. if err != nil {
  322. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  323. return
  324. }
  325. if !isChangeGroup {
  326. c.ServeSuccessJSON(map[string]interface{}{
  327. "msg": "ok",
  328. "advice": advice,
  329. "isChange": isChangeGroup, //方便前端处理数据
  330. })
  331. } else {
  332. newGroupAdvice, err := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
  333. if err != nil {
  334. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  335. return
  336. }
  337. c.ServeSuccessJSON(map[string]interface{}{
  338. "msg": "ok",
  339. "advice": newGroupAdvice,
  340. "isChange": isChangeGroup, //方便前端处理数据
  341. })
  342. }
  343. return
  344. }
  345. func (c *PatientApiController) StopDoctorAdvice() {
  346. id, _ := c.GetInt64("id", 0)
  347. if id <= 0 {
  348. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  349. return
  350. }
  351. adminUserInfo := c.GetMobileAdminUserInfo()
  352. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  353. if advice.ID == 0 {
  354. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  355. return
  356. }
  357. //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  358. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  359. // return
  360. //}
  361. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  362. //
  363. //if appRole.UserType == 3 {
  364. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  365. // if getPermissionErr != nil {
  366. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  367. // return
  368. // } else if headNursePermission == nil {
  369. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  370. // return
  371. // }
  372. //}
  373. if advice.StopState == 1 {
  374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  375. return
  376. }
  377. dataBody := make(map[string]interface{}, 0)
  378. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  379. if err != nil {
  380. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  381. return
  382. }
  383. timeLayout := "2006-01-02"
  384. loc, _ := time.LoadLocation("Local")
  385. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  386. utils.ErrorLog("stop_time")
  387. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  388. return
  389. }
  390. stopTime, _ := dataBody["stop_time"].(string)
  391. if len(stopTime) == 0 {
  392. utils.ErrorLog("len(stop_time) == 0")
  393. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  394. return
  395. }
  396. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  397. if err != nil {
  398. utils.ErrorLog(err.Error())
  399. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  400. return
  401. }
  402. advice.StopTime = theTime.Unix()
  403. if dataBody["stop_reason"] == nil || reflect.TypeOf(dataBody["stop_reason"]).String() != "string" {
  404. utils.ErrorLog("stop_reason")
  405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  406. return
  407. }
  408. stopReason, _ := dataBody["stop_reason"].(string)
  409. if len(stopReason) == 0 {
  410. utils.ErrorLog("len(stop_reason) == 0")
  411. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  412. return
  413. }
  414. advice.StopReason = stopReason
  415. advice.Status = 1
  416. advice.UpdatedTime = time.Now().Unix()
  417. advice.StopDoctor = adminUserInfo.AdminUser.Id
  418. advice.StopState = 1
  419. advice.StopTime = time.Now().Unix()
  420. advice.Modifier = adminUserInfo.AdminUser.Id
  421. err = service.StopDoctorAdvice(&advice)
  422. if err != nil {
  423. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  424. return
  425. }
  426. c.ServeSuccessJSON(map[string]interface{}{
  427. "msg": "ok",
  428. "advice": advice,
  429. })
  430. return
  431. }
  432. func (c *PatientApiController) DeleteDoctorAdvice() {
  433. id, _ := c.GetInt64("id", 0)
  434. if id <= 0 {
  435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  436. return
  437. }
  438. adminUserInfo := c.GetMobileAdminUserInfo()
  439. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  440. if advice.ID == 0 {
  441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  442. return
  443. }
  444. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  445. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  446. // return
  447. //}
  448. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  449. //
  450. //if appRole.UserType == 3 {
  451. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  452. // if getPermissionErr != nil {
  453. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  454. // return
  455. // } else if headNursePermission == nil {
  456. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  457. // return
  458. // }
  459. //}
  460. advice.UpdatedTime = time.Now().Unix()
  461. advice.Status = 0
  462. advice.Modifier = adminUserInfo.AdminUser.Id
  463. err := service.DeleteDoctorAdvice(&advice)
  464. if err != nil {
  465. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  466. return
  467. }
  468. c.ServeSuccessJSON(map[string]interface{}{
  469. "msg": "ok",
  470. })
  471. return
  472. }
  473. func (c *PatientApiController) ExecDoctorAdvice() {
  474. execution_time := c.GetString("execution_time")
  475. origin, _ := c.GetInt64("origin", 0)
  476. groupno, _ := c.GetInt64("groupno", -1)
  477. if origin != 2 {
  478. var ids []string
  479. if groupno == 0 {
  480. advice_ids := c.GetString("advice_id")
  481. ids = strings.Split(advice_ids, ",")
  482. }
  483. if groupno < 0 {
  484. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  485. return
  486. }
  487. if len(execution_time) <= 0 {
  488. utils.ErrorLog("execution_time")
  489. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  490. return
  491. }
  492. timeLayout2 := "2006-01-02 15:04:05"
  493. loc, _ := time.LoadLocation("Local")
  494. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  495. if errs != nil {
  496. utils.ErrorLog(errs.Error())
  497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  498. return
  499. }
  500. adminUserInfo := c.GetMobileAdminUserInfo()
  501. var advice models.DoctorAdvice
  502. if groupno > 0 {
  503. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  504. for _, item := range advices {
  505. if item.ExecutionState == 2 {
  506. advice = item
  507. }
  508. }
  509. } else {
  510. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  511. for _, item := range advices {
  512. if item.ExecutionState == 2 {
  513. advice = item
  514. }
  515. }
  516. }
  517. if advice.ExecutionState == 1 {
  518. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  519. return
  520. }
  521. if advice.Checker >= 0 && advice.Checker == adminUserInfo.AdminUser.Id {
  522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  523. return
  524. }
  525. if advice.StartTime > theTime.Unix() {
  526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  527. return
  528. }
  529. execution_staff := adminUserInfo.AdminUser.Id
  530. advices := models.DoctorAdvice{
  531. ExecutionStaff: execution_staff,
  532. ExecutionTime: theTime.Unix(),
  533. UpdatedTime: time.Now().Unix(),
  534. }
  535. var err error
  536. if groupno > 0 {
  537. err = service.ExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  538. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  539. redis := service.RedisClient()
  540. //清空key 值
  541. redis.Set(key, "", time.Second)
  542. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  543. redis.Set(keyTwo, "", time.Second)
  544. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  545. redis.Set(keyThree, "", time.Second)
  546. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
  547. theTime := toTime.Format("2006-01-02")
  548. fmt.Println("theTIME", theTime)
  549. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  550. redis.Set(keyFour, "", time.Second)
  551. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  552. redis.Set(keyFive, "", time.Second)
  553. defer redis.Close()
  554. } else {
  555. err = service.BatchExceOldDoctorAdvice(&advices, ids)
  556. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  557. redis := service.RedisClient()
  558. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  559. redis.Set(keyTwo, "", time.Second)
  560. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  561. redis.Set(keyThree, "", time.Second)
  562. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
  563. theTime := toTime.Format("2006-01-02")
  564. fmt.Println("theTIME", theTime)
  565. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  566. redis.Set(keyFour, "", time.Second)
  567. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  568. redis.Set(keySix, "", time.Second)
  569. defer redis.Close()
  570. //清空key 值
  571. redis.Set(key, "", time.Second)
  572. }
  573. if err != nil {
  574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  575. return
  576. }
  577. advice.ExecutionStaff = execution_staff
  578. advice.ExecutionTime = theTime.Unix()
  579. advice.ExecutionState = 1
  580. advice.Modifier = adminUserInfo.AdminUser.Id
  581. //处理出库相关逻辑
  582. //1.判断是否启用药品管理和自备药出库功能
  583. //药品管理信息
  584. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
  585. //自备药信息
  586. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.Org.Id)
  587. if drugStockConfig.IsOpen == 1 {
  588. if groupno > 0 {
  589. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  590. isHasWay := false //用来判断是否包含来自药品库的医嘱
  591. for _, item := range advices {
  592. if item.Way == 1 {
  593. isHasWay = true
  594. }
  595. }
  596. if isHasWay {
  597. var total int64
  598. var prescribing_number_total int64
  599. for _, item := range advices {
  600. if item.Way == 1 {
  601. //查询该药品的剩余库存
  602. list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId)
  603. //查询改药品信息
  604. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  605. //判断单位是否相等
  606. if medical.MaxUnit == item.PrescribingNumberUnit {
  607. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  608. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  609. //转化为最小单位
  610. total = list.Count * medical.MinNumber
  611. prescribing_number_total = count * medical.MinNumber
  612. }
  613. if medical.MinUnit == item.PrescribingNumberUnit {
  614. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  615. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  616. total = list.Count*medical.MinNumber + list.StockMinNumber
  617. prescribing_number_total = count
  618. }
  619. fmt.Println("开医嘱数量", prescribing_number_total)
  620. fmt.Println("剩余库存", total)
  621. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  622. c.ServeSuccessJSON(map[string]interface{}{
  623. "msg": "3",
  624. "advice": advice,
  625. "ids": ids,
  626. })
  627. return
  628. }
  629. if prescribing_number_total > total {
  630. c.ServeSuccessJSON(map[string]interface{}{
  631. "msg": "2",
  632. "advice": advice,
  633. "ids": ids,
  634. })
  635. return
  636. }
  637. if prescribing_number_total <= total {
  638. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  639. }
  640. }
  641. }
  642. }
  643. c.ServeSuccessJSON(map[string]interface{}{
  644. "msg": "1",
  645. "advice": advice,
  646. "ids": ids,
  647. })
  648. return
  649. } else {
  650. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  651. isHasWay := false //用来判断是否包含来自药品库的医嘱
  652. for _, item := range advices {
  653. if item.Way == 1 {
  654. isHasWay = true
  655. }
  656. }
  657. if isHasWay {
  658. var total int64
  659. var prescribing_number_total int64
  660. for _, item := range advices {
  661. if item.Way == 1 {
  662. //查询该药品的剩余库存
  663. list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId)
  664. //查询改药品信息
  665. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  666. //判断单位是否相等
  667. if medical.MaxUnit == item.PrescribingNumberUnit {
  668. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  669. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  670. //转化为最小单位
  671. total = list.Count*medical.MinNumber + list.StockMinNumber
  672. prescribing_number_total = count * medical.MinNumber
  673. }
  674. if medical.MinUnit == item.PrescribingNumberUnit {
  675. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  676. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  677. total = list.Count*medical.MinNumber + list.StockMinNumber
  678. prescribing_number_total = count
  679. }
  680. fmt.Println("开医嘱数量", prescribing_number_total)
  681. fmt.Println("剩余库存", total)
  682. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  683. c.ServeSuccessJSON(map[string]interface{}{
  684. "msg": "3",
  685. "advice": advice,
  686. "ids": ids,
  687. })
  688. return
  689. }
  690. if prescribing_number_total > total {
  691. c.ServeSuccessJSON(map[string]interface{}{
  692. "msg": "2",
  693. "advice": advice,
  694. "ids": ids,
  695. })
  696. return
  697. }
  698. if prescribing_number_total <= total {
  699. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  700. c.ServeSuccessJSON(map[string]interface{}{
  701. "msg": "1",
  702. "advice": advice,
  703. "ids": ids,
  704. })
  705. return
  706. }
  707. }
  708. }
  709. }
  710. }
  711. }
  712. if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
  713. if groupno > 0 {
  714. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  715. for _, item := range advices {
  716. if item.ExecutionState == 1 && item.Way == 2 {
  717. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  718. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  719. timeStr := time.Now().Format("2006-01-02")
  720. timeArr := strings.Split(timeStr, "-")
  721. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
  722. total = total + 1
  723. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  724. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  725. number = number + total
  726. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  727. //插入自备药出库单
  728. outStock := models.XtSelfOutStock{
  729. DrugName: item.AdviceName,
  730. DrugNameId: item.DrugNameId,
  731. DrugSpec: item.AdviceDesc,
  732. OutstoreNumber: count,
  733. AdminUserId: adminUserInfo.AdminUser.Id,
  734. StorckTime: item.AdviceDate,
  735. UserOrgId: adminUserInfo.Org.Id,
  736. CreatedTime: time.Now().Unix(),
  737. Status: 1,
  738. PatientId: item.PatientId,
  739. ExitMode: 2,
  740. MedicId: item.DrugId,
  741. StockOutNumber: warehousing_out_order,
  742. }
  743. //查询 该患者是否已出库
  744. out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
  745. if errcode == gorm.ErrRecordNotFound {
  746. service.CreateOutStock(&outStock)
  747. } else if errcode == nil {
  748. err := service.UpdatedSelfOutSatock(out.ID, &outStock)
  749. fmt.Println("err", err)
  750. }
  751. }
  752. }
  753. } else {
  754. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  755. for _, item := range advices {
  756. if item.ExecutionState == 1 && item.Way == 2 {
  757. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  758. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  759. timeStr := time.Now().Format("2006-01-02")
  760. timeArr := strings.Split(timeStr, "-")
  761. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
  762. total = total + 1
  763. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  764. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  765. number = number + total
  766. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  767. //插入自备药出库单
  768. outStock := models.XtSelfOutStock{
  769. DrugName: item.AdviceName,
  770. DrugNameId: item.DrugNameId,
  771. DrugSpec: item.AdviceDesc,
  772. OutstoreNumber: count,
  773. AdminUserId: adminUserInfo.AdminUser.Id,
  774. StorckTime: item.AdviceDate,
  775. UserOrgId: adminUserInfo.Org.Id,
  776. CreatedTime: time.Now().Unix(),
  777. Status: 1,
  778. PatientId: item.PatientId,
  779. ExitMode: 2,
  780. MedicId: item.DrugId,
  781. StockOutNumber: warehousing_out_order,
  782. }
  783. //查询 该患者是否已出库
  784. out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
  785. if errcode == gorm.ErrRecordNotFound {
  786. service.CreateOutStock(&outStock)
  787. } else if errcode == nil {
  788. err := service.UpdatedSelfOutSatock(out.ID, &outStock)
  789. fmt.Println("err", err)
  790. }
  791. }
  792. }
  793. c.ServeSuccessJSON(map[string]interface{}{
  794. "msg": "1",
  795. "advice": advice,
  796. "ids": ids,
  797. })
  798. return
  799. }
  800. }
  801. c.ServeSuccessJSON(map[string]interface{}{
  802. "msg": "1",
  803. "advice": advice,
  804. "ids": ids,
  805. })
  806. return
  807. } else if origin == 2 {
  808. var ids []string
  809. advice_ids := c.GetString("advice_id")
  810. ids = strings.Split(advice_ids, ",")
  811. if len(execution_time) <= 0 {
  812. utils.ErrorLog("execution_time")
  813. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  814. return
  815. }
  816. timeLayout2 := "2006-01-02 15:04:05"
  817. loc, _ := time.LoadLocation("Local")
  818. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  819. if errs != nil {
  820. utils.ErrorLog(errs.Error())
  821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  822. return
  823. }
  824. adminInfo := c.GetMobileAdminUserInfo()
  825. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  826. advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
  827. var err error
  828. for _, item := range advices {
  829. if item.ExecutionState == 1 {
  830. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  831. return
  832. }
  833. if item.Checker >= 0 && item.Checker == adminInfo.AdminUser.Id {
  834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  835. return
  836. }
  837. if item.StartTime > theTime.Unix() {
  838. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  839. return
  840. }
  841. item.ExecutionState = 1
  842. item.ExecutionStaff = adminInfo.AdminUser.Id
  843. item.ExecutionTime = theTime.Unix()
  844. err = service.SaveHisDoctorAdvice(item)
  845. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  846. redis := service.RedisClient()
  847. //清空key 值
  848. redis.Set(key, "", time.Second)
  849. keyTwo := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  850. redis.Set(keyTwo, "", time.Second)
  851. keyThree := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  852. redis.Set(keyThree, "", time.Second)
  853. recordDate := theTime.Format("2006-01-02")
  854. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminInfo.Org.Id, 10)
  855. redis.Set(keyFour, "", time.Second)
  856. keyFive := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  857. redis.Set(keyFive, "", time.Second)
  858. defer redis.Close()
  859. }
  860. if err == nil {
  861. //药品管理信息
  862. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  863. if drugStockConfig.IsOpen == 1 {
  864. for _, item := range advices {
  865. //查询改药品信息
  866. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  867. //查询这个患者这个患者这个药已经出库的所有数量
  868. advicelist, _ := service.GetAllHisDoctorAdviceById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  869. drugoutlist, _ := service.GetAllDrugFlowById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  870. var total_count int64
  871. var drug_count int64
  872. for _, it := range advicelist {
  873. if it.PrescribingNumberUnit == medical.MaxUnit {
  874. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  875. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  876. total_count += prenumber * medical.MinNumber
  877. }
  878. if it.PrescribingNumberUnit == medical.MinUnit {
  879. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  880. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  881. total_count += prenumber
  882. }
  883. }
  884. for _, its := range drugoutlist {
  885. if its.CountUnit == medical.MaxUnit {
  886. drug_count += its.Count * medical.MinNumber
  887. }
  888. if its.CountUnit == medical.MinUnit {
  889. drug_count += its.Count
  890. }
  891. }
  892. if total_count == drug_count {
  893. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  894. c.ServeSuccessJSON(map[string]interface{}{
  895. "msg": "1",
  896. "advice": advice,
  897. "ids": ids,
  898. })
  899. return
  900. }
  901. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  902. var total int64
  903. var prescribing_number_total int64
  904. //查询该药品是否有库存
  905. list, _ := service.GetDrugTotalCount(advice.DrugId, advice.UserOrgId)
  906. //判断单位是否相等
  907. if medical.MaxUnit == advice.PrescribingNumberUnit {
  908. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  909. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  910. //转化为最小单位
  911. total = list.Count*medical.MinNumber + list.StockMinNumber
  912. prescribing_number_total = count * medical.MinNumber
  913. }
  914. fmt.Println("医嘱开的数量", total)
  915. if medical.MinUnit == advice.PrescribingNumberUnit {
  916. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  917. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  918. total = list.Count*medical.MinNumber + list.StockMinNumber
  919. prescribing_number_total = count
  920. }
  921. fmt.Println("数量一", prescribing_number_total)
  922. fmt.Println("数量二", total)
  923. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  924. c.ServeSuccessJSON(map[string]interface{}{
  925. "msg": "3",
  926. "advice": advice,
  927. "ids": ids,
  928. })
  929. return
  930. }
  931. if prescribing_number_total > total {
  932. c.ServeSuccessJSON(map[string]interface{}{
  933. "msg": "2",
  934. "advice": advice,
  935. "ids": ids,
  936. })
  937. return
  938. }
  939. if prescribing_number_total <= total {
  940. service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
  941. }
  942. }
  943. }
  944. for _, item := range advices {
  945. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  946. c.ServeSuccessJSON(map[string]interface{}{
  947. "msg": "1",
  948. "advice": advice,
  949. "ids": ids,
  950. })
  951. }
  952. } else {
  953. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  954. }
  955. }
  956. }
  957. func (c *PatientApiController) ModifyExecDoctorAdvice() {
  958. execution_time := c.GetString("execution_time")
  959. fmt.Println("execution_time", execution_time)
  960. groupno, _ := c.GetInt64("groupno", -1)
  961. var ids []string
  962. if groupno == 0 {
  963. advice_ids := c.GetString("advice_id")
  964. ids = strings.Split(advice_ids, ",")
  965. }
  966. if groupno < 0 {
  967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  968. return
  969. }
  970. if len(execution_time) <= 0 {
  971. utils.ErrorLog("execution_time")
  972. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  973. return
  974. }
  975. timeLayout2 := "2006-01-02 15:04:05"
  976. loc, _ := time.LoadLocation("Local")
  977. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  978. if errs != nil {
  979. utils.ErrorLog(errs.Error())
  980. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  981. return
  982. }
  983. adminUserInfo := c.GetMobileAdminUserInfo()
  984. var advice models.DoctorAdvice
  985. if groupno > 0 {
  986. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  987. for _, item := range advices {
  988. if item.ExecutionState == 1 {
  989. advice = item
  990. }
  991. }
  992. } else {
  993. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  994. for _, item := range advices {
  995. if item.ExecutionState == 1 {
  996. advice = item
  997. }
  998. }
  999. }
  1000. //if advice.ExecutionStaff != adminUserInfo.AdminUser.Id {
  1001. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1002. // if getPermissionErr != nil {
  1003. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1004. // return
  1005. // } else if headNursePermission == nil {
  1006. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1007. // return
  1008. // }
  1009. //}
  1010. if advice.StartTime > theTime.Unix() {
  1011. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1012. return
  1013. }
  1014. advices := models.DoctorAdvice{
  1015. ExecutionTime: theTime.Unix(),
  1016. UpdatedTime: time.Now().Unix(),
  1017. }
  1018. var err error
  1019. if groupno > 0 {
  1020. err = service.ModifyExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  1021. redis := service.RedisClient()
  1022. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1023. fmt.Println("keyThh322323232323232323223", key)
  1024. redis.Set(key, "", time.Second)
  1025. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1026. redis.Set(keyOne, "", time.Second)
  1027. defer redis.Close()
  1028. } else {
  1029. err = service.BatchModifyExceOldDoctorAdvice(&advices, ids)
  1030. err = service.ModifyExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  1031. redis := service.RedisClient()
  1032. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1033. fmt.Println("keyTwohh322323232323232323223", key)
  1034. redis.Set(key, "", time.Second)
  1035. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1036. redis.Set(keyOne, "", time.Second)
  1037. defer redis.Close()
  1038. }
  1039. //判断是否开启his
  1040. errs, config := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  1041. //如果开启去修改执行时间
  1042. if config.IsOpen == 1 {
  1043. advicesinfo := models.HisDoctorAdviceInfo{
  1044. ExecutionTime: theTime.Unix(),
  1045. UpdatedTime: time.Now().Unix(),
  1046. }
  1047. fmt.Println("ids2323232232323", ids)
  1048. var advicehis models.HisDoctorAdviceInfo
  1049. service.ModifyExceDoctorAdviceById(&advicesinfo, ids)
  1050. his_advices, _ := service.FindHisDoctorAdviceByIdOne(adminUserInfo.Org.Id, ids)
  1051. for _, item := range his_advices {
  1052. if item.ExecutionState == 1 {
  1053. advicehis = item
  1054. }
  1055. }
  1056. redis := service.RedisClient()
  1057. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicehis.PatientId, 10) + ":" + strconv.FormatInt(advicehis.AdviceDate, 10) + ":his_doctor_advice"
  1058. redis.Set(keyThree, "", time.Second)
  1059. recordDate := theTime.Format("2006-01-02")
  1060. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1061. redis.Set(keyFour, "", time.Second)
  1062. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicehis.AdviceDate, 10) + ":his_advices_list_all"
  1063. redis.Set(keyFive, "", time.Second)
  1064. defer redis.Close()
  1065. project := models.HisPrescriptionProject{
  1066. ExecutionTime: theTime.Unix(),
  1067. Mtime: time.Now().Unix(),
  1068. }
  1069. service.ModifyHisPrescriptionProject(&project, ids)
  1070. keyEnd := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicesinfo.PatientId, 10) + ":" + strconv.FormatInt(advicesinfo.AdviceDate, 10) + ":his_doctor_advice"
  1071. redis.Set(keyEnd, "", time.Second)
  1072. keyFours := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1073. redis.Set(keyFours, "", time.Second)
  1074. keyFives := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicesinfo.AdviceDate, 10) + ":his_advices_list_all"
  1075. redis.Set(keyFives, "", time.Second)
  1076. defer redis.Close()
  1077. }
  1078. if err != nil {
  1079. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1080. return
  1081. }
  1082. advice.ExecutionTime = theTime.Unix()
  1083. c.ServeSuccessJSON(map[string]interface{}{
  1084. "msg": "ok",
  1085. "advice": advice,
  1086. "ids": ids,
  1087. })
  1088. return
  1089. }
  1090. func (c *PatientApiController) CheckDoctorAdvice() {
  1091. origin, _ := c.GetInt64("origin", 0)
  1092. if origin != 2 {
  1093. groupno, _ := c.GetInt64("groupno", -1)
  1094. var ids []string
  1095. if groupno == 0 {
  1096. advice_ids := c.GetString("advice_id")
  1097. if advice_ids == "" {
  1098. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1099. return
  1100. } else {
  1101. ids = strings.Split(advice_ids, ",")
  1102. if len(ids) <= 0 {
  1103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1104. return
  1105. }
  1106. }
  1107. }
  1108. if groupno < 0 {
  1109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1110. return
  1111. }
  1112. adminUserInfo := c.GetMobileAdminUserInfo()
  1113. var advice models.DoctorAdvice
  1114. if groupno > 0 {
  1115. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  1116. for _, item := range advices {
  1117. if item.CheckState == 0 {
  1118. advice = item
  1119. }
  1120. }
  1121. if advice.CheckState == 1 {
  1122. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1123. return
  1124. }
  1125. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1126. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1127. return
  1128. }
  1129. } else {
  1130. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  1131. for _, item := range advices {
  1132. if item.CheckState == 0 {
  1133. advice = item
  1134. }
  1135. }
  1136. if advice.CheckState == 1 {
  1137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1138. return
  1139. }
  1140. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1142. return
  1143. }
  1144. }
  1145. checker := adminUserInfo.AdminUser.Id
  1146. theTime := time.Now()
  1147. advices := models.DoctorAdvice{
  1148. CheckTime: theTime.Unix(),
  1149. Checker: checker,
  1150. UpdatedTime: time.Now().Unix(),
  1151. }
  1152. var err error
  1153. if groupno > 0 {
  1154. err = service.CheckDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  1155. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1156. redis := service.RedisClient()
  1157. //清空key 值
  1158. redis.Set(key, "", time.Second)
  1159. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1160. redis.Set(keyTwo, "", time.Second)
  1161. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1162. redis.Set(keyThree, "", time.Second)
  1163. recordDate := theTime.Format("2006-01-02")
  1164. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1165. redis.Set(keyFour, "", time.Second)
  1166. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1167. redis.Set(keyFive, "", time.Second)
  1168. defer redis.Close()
  1169. } else {
  1170. if len(ids[0]) <= 0 {
  1171. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1172. return
  1173. } else {
  1174. //t := time.Now().Format("2006-01-02")/**/
  1175. //timeLayout2 := "2006-01-02"
  1176. //loc, _ := time.LoadLocation("Local")
  1177. //theTime, _ := time.ParseInLocation(timeLayout2, t, loc)
  1178. err = service.BatchCheckOldDoctorAdvice(&advices, ids, adminUserInfo.Org.Id, advice.AdviceDate)
  1179. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1180. redis := service.RedisClient()
  1181. //清空key 值
  1182. redis.Set(key, "", time.Second)
  1183. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1184. redis.Set(keyTwo, "", time.Second)
  1185. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1186. redis.Set(keyThree, "", time.Second)
  1187. recordDate := theTime.Format("2006-01-02")
  1188. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1189. redis.Set(keyFour, "", time.Second)
  1190. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1191. redis.Set(keyFive, "", time.Second)
  1192. defer redis.Close()
  1193. }
  1194. }
  1195. if err != nil {
  1196. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1197. return
  1198. }
  1199. advice.Checker = checker
  1200. advice.CheckTime = theTime.Unix()
  1201. advice.CheckState = 1
  1202. c.ServeSuccessJSON(map[string]interface{}{
  1203. "msg": "ok",
  1204. "advice": advice,
  1205. })
  1206. } else if origin == 2 {
  1207. adminInfo := c.GetMobileAdminUserInfo()
  1208. var ids []string
  1209. advice_ids := c.GetString("advice_id")
  1210. ids = strings.Split(advice_ids, ",")
  1211. advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
  1212. var err error
  1213. for _, item := range advices {
  1214. if item.CheckState == 1 {
  1215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1216. return
  1217. }
  1218. if item.ExecutionStaff >= 0 && item.ExecutionStaff == adminInfo.AdminUser.Id {
  1219. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1220. return
  1221. }
  1222. item.Checker = adminInfo.AdminUser.Id
  1223. item.CheckTime = time.Now().Unix()
  1224. item.CheckState = 1
  1225. err = service.SaveHisDoctorAdvice(item)
  1226. redis := service.RedisClient()
  1227. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1228. //清空key 值
  1229. redis.Set(key, "", time.Second)
  1230. keyTwo := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1231. redis.Set(keyTwo, "", time.Second)
  1232. keyThree := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  1233. redis.Set(keyThree, "", time.Second)
  1234. theTime := time.Now()
  1235. recordDate := theTime.Format("2006-01-02")
  1236. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminInfo.Org.Id, 10)
  1237. redis.Set(keyFour, "", time.Second)
  1238. keyFive := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  1239. redis.Set(keyFive, "", time.Second)
  1240. defer redis.Close()
  1241. }
  1242. if err == nil {
  1243. c.ServeSuccessJSON(map[string]interface{}{
  1244. "msg": "ok",
  1245. "advice": advices,
  1246. })
  1247. } else {
  1248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1249. return
  1250. }
  1251. }
  1252. return
  1253. }
  1254. func (c *PatientApiController) EditAssessmentBeforeDislysis() {
  1255. id, _ := c.GetInt64("patient", 0)
  1256. assessmentDate := c.GetString("assessment_date", "")
  1257. if id <= 0 || len(assessmentDate) != 10 {
  1258. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1259. return
  1260. }
  1261. timeLayout := "2006-01-02"
  1262. loc, _ := time.LoadLocation("Local")
  1263. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", assessmentDate+" 00:00:00", loc)
  1264. if err != nil {
  1265. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1266. return
  1267. }
  1268. theAssessmentDateTime := theTime.Unix()
  1269. adminUserInfo := c.GetMobileAdminUserInfo()
  1270. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1271. if patient.ID == 0 {
  1272. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1273. return
  1274. }
  1275. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluationSeven(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  1276. if getPEErr != nil {
  1277. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  1278. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1279. return
  1280. }
  1281. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1282. //templateInfo,_ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1283. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1284. var evaluation models.PredialysisEvaluation
  1285. if theEvaluation != nil {
  1286. evaluation = *theEvaluation
  1287. }
  1288. code := predialysisEvaluationFormData(&evaluation, c.Ctx.Input.RequestBody)
  1289. if code > 0 {
  1290. c.ServeFailJSONWithSGJErrorCode(code)
  1291. return
  1292. }
  1293. if theEvaluation == nil {
  1294. evaluation.CreatedTime = time.Now().Unix()
  1295. evaluation.Status = 1
  1296. evaluation.AssessmentDate = theAssessmentDateTime
  1297. evaluation.PatientId = id
  1298. evaluation.UserOrgId = adminUserInfo.Org.Id
  1299. if appRole.UserType == 2 || appRole.UserType == 1 {
  1300. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1301. evaluation.AssessmentTime = time.Now().Unix()
  1302. } else {
  1303. evaluation.Creater = adminUserInfo.AdminUser.Id
  1304. }
  1305. } else {
  1306. evaluation.UpdatedTime = time.Now().Unix()
  1307. evaluation.Evaluator = adminUserInfo.AdminUser.Id
  1308. if appRole.UserType == 2 || appRole.UserType == 1 {
  1309. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1310. evaluation.AssessmentTime = time.Now().Unix()
  1311. } else {
  1312. evaluation.Modifier = adminUserInfo.AdminUser.Id
  1313. if evaluation.Creater == 0 {
  1314. evaluation.Creater = adminUserInfo.AdminUser.Id
  1315. }
  1316. }
  1317. }
  1318. //新增逻辑
  1319. var dewater_amount float64
  1320. dewater_amount = 0
  1321. if evaluation.DryWeight > 0 {
  1322. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  1323. if template.TemplateId == 17 || template.TemplateId == 22 || template.TemplateId == 21 || template.TemplateId == 26 || template.TemplateId == 34 || template.TemplateId == 32 {
  1324. dewater_amount = dewater_amount * 1000
  1325. }
  1326. if dewater_amount <= 0 {
  1327. dewater_amount = 0
  1328. }
  1329. } else {
  1330. dewater_amount = 0
  1331. }
  1332. // 计算透析处方的相关超滤量
  1333. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.Org.Id, patient.ID, theAssessmentDateTime)
  1334. var lastDialysisPrescribe *models.DialysisPrescription
  1335. var dialysisSolution *models.DialysisSolution
  1336. var dialysisPrescribe *models.DialysisPrescription
  1337. var system_dialysisPrescribe *models.SystemPrescription
  1338. var mode_id int64
  1339. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  1340. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  1341. if schedual != nil {
  1342. // 获取透析模版
  1343. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  1344. system_dialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, schedual.ModeId)
  1345. mode_id = schedual.ModeId
  1346. } else {
  1347. // 获取透析模版
  1348. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.Org.Id, id)
  1349. if dialysisPrescribe == nil && dialysisSolution != nil {
  1350. mode_id = dialysisSolution.ModeId
  1351. }
  1352. if dialysisPrescribe == nil && dialysisSolution == nil {
  1353. mode_id = 0
  1354. }
  1355. }
  1356. // 插入透析处方
  1357. if dialysisPrescribe == nil && dialysisSolution != nil {
  1358. var newprescribe models.DialysisPrescription
  1359. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  1360. newprescribe.PatientId = dialysisSolution.PatientId
  1361. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  1362. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  1363. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  1364. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  1365. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  1366. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  1367. newprescribe.ModeId = dialysisSolution.ModeId
  1368. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  1369. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  1370. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  1371. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  1372. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  1373. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  1374. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  1375. newprescribe.Glucose = dialysisSolution.Glucose
  1376. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  1377. newprescribe.Kalium = dialysisSolution.Kalium
  1378. newprescribe.Sodium = dialysisSolution.Sodium
  1379. newprescribe.Calcium = dialysisSolution.Calcium
  1380. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  1381. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  1382. newprescribe.Conductivity = dialysisSolution.Conductivity
  1383. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  1384. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  1385. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  1386. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  1387. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  1388. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  1389. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  1390. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  1391. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  1392. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  1393. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  1394. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  1395. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  1396. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  1397. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  1398. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  1399. newprescribe.CreatedTime = time.Now().Unix()
  1400. newprescribe.UpdatedTime = time.Now().Unix()
  1401. newprescribe.RecordDate = theAssessmentDateTime
  1402. newprescribe.DewaterAmount = dewater_amount
  1403. newprescribe.TargetUltrafiltration = dewater_amount
  1404. newprescribe.Status = 1
  1405. newprescribe.DialysisDialyszers = dialysisSolution.DialysisDialyszers
  1406. newprescribe.DialysisIrrigation = dialysisSolution.DialysisIrrigation
  1407. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  1408. newprescribe.ID = dialysisPrescription.ID
  1409. if dialysisPrescription.ID == 0 {
  1410. fmt.Println("处方11111111111")
  1411. err := service.AddSigleRecord(&newprescribe)
  1412. //获取key,清空redis
  1413. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1414. redis := service.RedisClient()
  1415. //清空key 值
  1416. redis.Set(key, "", time.Second)
  1417. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1418. //清空key 值
  1419. redis.Set(keyOne, "", time.Second)
  1420. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1421. //清空key 值
  1422. redis.Set(keyTwo, "", time.Second)
  1423. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1424. redis.Set(keySix, "", time.Second)
  1425. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1426. redis.Set(keySeven, "", time.Second)
  1427. if err != nil {
  1428. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1429. }
  1430. } else {
  1431. err := service.UpDateDialysisPrescription(&newprescribe)
  1432. //获取key,清空redis
  1433. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1434. redis := service.RedisClient()
  1435. //清空key 值
  1436. redis.Set(key, "", time.Second)
  1437. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1438. //清空key 值
  1439. redis.Set(keyOne, "", time.Second)
  1440. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1441. //清空key 值
  1442. redis.Set(keyTwo, "", time.Second)
  1443. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1444. redis.Set(keySix, "", time.Second)
  1445. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1446. redis.Set(keySeven, "", time.Second)
  1447. if err != nil {
  1448. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1449. }
  1450. }
  1451. }
  1452. if dialysisPrescribe == nil && dialysisSolution == nil {
  1453. if lastDialysisPrescribe != nil {
  1454. var newprescribe models.DialysisPrescription
  1455. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  1456. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  1457. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  1458. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  1459. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  1460. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  1461. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  1462. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  1463. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  1464. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  1465. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  1466. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  1467. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  1468. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  1469. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  1470. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  1471. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  1472. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  1473. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  1474. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  1475. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  1476. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  1477. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  1478. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  1479. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  1480. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  1481. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  1482. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  1483. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  1484. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  1485. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  1486. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  1487. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  1488. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  1489. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  1490. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  1491. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  1492. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  1493. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  1494. newprescribe.CreatedTime = time.Now().Unix()
  1495. newprescribe.UpdatedTime = time.Now().Unix()
  1496. newprescribe.RecordDate = theAssessmentDateTime
  1497. newprescribe.DewaterAmount = dewater_amount
  1498. newprescribe.TargetUltrafiltration = dewater_amount
  1499. newprescribe.Status = 1
  1500. newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
  1501. newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
  1502. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  1503. newprescribe.ID = dialysisPrescription.ID
  1504. if dialysisPrescription.ID == 0 {
  1505. err := service.AddSigleRecord(&newprescribe)
  1506. //获取key,清空redis
  1507. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1508. redis := service.RedisClient()
  1509. //清空key 值
  1510. redis.Set(key, "", time.Second)
  1511. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1512. //清空key 值
  1513. redis.Set(keyOne, "", time.Second)
  1514. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1515. //清空key 值
  1516. redis.Set(keyTwo, "", time.Second)
  1517. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1518. redis.Set(keySix, "", time.Second)
  1519. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1520. redis.Set(keySeven, "", time.Second)
  1521. fmt.Println("处方2222222222")
  1522. if err != nil {
  1523. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1524. }
  1525. } else {
  1526. err := service.UpDateDialysisPrescription(&newprescribe)
  1527. //获取key,清空redis
  1528. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1529. redis := service.RedisClient()
  1530. //清空key 值
  1531. redis.Set(key, "", time.Second)
  1532. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1533. //清空key 值
  1534. redis.Set(keyOne, "", time.Second)
  1535. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1536. //清空key 值
  1537. redis.Set(keyTwo, "", time.Second)
  1538. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1539. redis.Set(keySix, "", time.Second)
  1540. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1541. redis.Set(keySeven, "", time.Second)
  1542. if err != nil {
  1543. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1544. }
  1545. }
  1546. if err != nil {
  1547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1548. }
  1549. } else if system_dialysisPrescribe != nil {
  1550. var newprescribe models.DialysisPrescription
  1551. newprescribe.UserOrgId = system_dialysisPrescribe.UserOrgId
  1552. newprescribe.PatientId = id
  1553. newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
  1554. newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
  1555. newprescribe.AnticoagulantWeichi = system_dialysisPrescribe.AnticoagulantWeichi
  1556. newprescribe.AnticoagulantZongliang = system_dialysisPrescribe.AnticoagulantZongliang
  1557. newprescribe.AnticoagulantGaimingcheng = system_dialysisPrescribe.AnticoagulantGaimingcheng
  1558. newprescribe.AnticoagulantGaijiliang = system_dialysisPrescribe.AnticoagulantGaijiliang
  1559. newprescribe.ModeId = system_dialysisPrescribe.ModeId
  1560. newprescribe.DialysisDuration = system_dialysisPrescribe.DialysisDuration
  1561. newprescribe.ReplacementWay = system_dialysisPrescribe.ReplacementWay
  1562. newprescribe.HemodialysisMachine = system_dialysisPrescribe.HemodialysisMachine
  1563. newprescribe.BloodFilter = system_dialysisPrescribe.BloodFilter
  1564. newprescribe.PerfusionApparatus = system_dialysisPrescribe.PerfusionApparatus
  1565. newprescribe.BloodFlowVolume = system_dialysisPrescribe.BloodFlowVolume
  1566. newprescribe.DisplaceLiqui = system_dialysisPrescribe.DisplaceLiqui
  1567. newprescribe.Glucose = system_dialysisPrescribe.Glucose
  1568. newprescribe.DialysateFlow = system_dialysisPrescribe.DialysateFlow
  1569. newprescribe.Kalium = system_dialysisPrescribe.Kalium
  1570. newprescribe.Sodium = system_dialysisPrescribe.Sodium
  1571. newprescribe.Calcium = system_dialysisPrescribe.Calcium
  1572. newprescribe.Bicarbonate = system_dialysisPrescribe.Bicarbonate
  1573. newprescribe.DialysateTemperature = system_dialysisPrescribe.DialysateTemperature
  1574. newprescribe.Conductivity = system_dialysisPrescribe.Conductivity
  1575. newprescribe.BodyFluid = system_dialysisPrescribe.BodyFluid
  1576. newprescribe.SpecialMedicine = system_dialysisPrescribe.SpecialMedicine
  1577. newprescribe.SpecialMedicineOther = system_dialysisPrescribe.SpecialMedicineOther
  1578. newprescribe.DisplaceLiquiPart = system_dialysisPrescribe.DisplaceLiquiPart
  1579. newprescribe.DisplaceLiquiValue = system_dialysisPrescribe.DisplaceLiquiValue
  1580. newprescribe.BloodAccess = system_dialysisPrescribe.BloodAccess
  1581. newprescribe.Ultrafiltration = system_dialysisPrescribe.Ultrafiltration
  1582. newprescribe.DialysisDurationHour = system_dialysisPrescribe.DialysisDurationHour
  1583. newprescribe.DialysisDurationMinute = system_dialysisPrescribe.DialysisDurationMinute
  1584. newprescribe.DialysateFormulation = system_dialysisPrescribe.DialysateFormulation
  1585. newprescribe.Dialyzer = system_dialysisPrescribe.Dialyzer
  1586. newprescribe.ReplacementTotal = system_dialysisPrescribe.ReplacementTotal
  1587. newprescribe.DialyzerPerfusionApparatus = system_dialysisPrescribe.DialyzerPerfusionApparatus
  1588. newprescribe.BodyFluidOther = system_dialysisPrescribe.BodyFluidOther
  1589. newprescribe.TargetKtv = system_dialysisPrescribe.TargetKtv
  1590. newprescribe.CreatedTime = time.Now().Unix()
  1591. newprescribe.UpdatedTime = time.Now().Unix()
  1592. newprescribe.RecordDate = theAssessmentDateTime
  1593. newprescribe.DewaterAmount = dewater_amount
  1594. newprescribe.TargetUltrafiltration = dewater_amount
  1595. newprescribe.Status = 1
  1596. newprescribe.DialysisDialyszers = system_dialysisPrescribe.DialysisDialyszers
  1597. newprescribe.DialysisIrrigation = system_dialysisPrescribe.DialysisIrrigation
  1598. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  1599. newprescribe.ID = dialysisPrescription.ID
  1600. if dialysisPrescription.ID == 0 {
  1601. err := service.AddSigleRecord(&newprescribe)
  1602. fmt.Println("处方2222222222")
  1603. //获取key,清空redis
  1604. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1605. redis := service.RedisClient()
  1606. //清空key 值
  1607. redis.Set(key, "", time.Second)
  1608. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1609. //清空key 值
  1610. redis.Set(keyOne, "", time.Second)
  1611. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1612. //清空key 值
  1613. redis.Set(keyTwo, "", time.Second)
  1614. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1615. redis.Set(keySix, "", time.Second)
  1616. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1617. redis.Set(keySeven, "", time.Second)
  1618. if err != nil {
  1619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1620. }
  1621. } else {
  1622. err := service.UpDateDialysisPrescription(&newprescribe)
  1623. //获取key,清空redis
  1624. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1625. redis := service.RedisClient()
  1626. //清空key 值
  1627. redis.Set(key, "", time.Second)
  1628. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1629. //清空key 值
  1630. redis.Set(keyOne, "", time.Second)
  1631. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1632. //清空key 值
  1633. redis.Set(keyTwo, "", time.Second)
  1634. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1635. redis.Set(keySix, "", time.Second)
  1636. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1637. redis.Set(keySeven, "", time.Second)
  1638. if err != nil {
  1639. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1640. }
  1641. }
  1642. if err != nil {
  1643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1644. }
  1645. } else {
  1646. var newprescribe models.DialysisPrescription
  1647. newprescribe.UserOrgId = adminUserInfo.Org.Id
  1648. newprescribe.PatientId = id
  1649. newprescribe.ModeId = mode_id
  1650. newprescribe.CreatedTime = time.Now().Unix()
  1651. newprescribe.UpdatedTime = time.Now().Unix()
  1652. newprescribe.RecordDate = theAssessmentDateTime
  1653. newprescribe.DewaterAmount = dewater_amount
  1654. newprescribe.TargetUltrafiltration = dewater_amount
  1655. newprescribe.Status = 1
  1656. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  1657. newprescribe.ID = dialysisPrescription.ID
  1658. if dialysisPrescription.ID == 0 {
  1659. err := service.AddSigleRecord(&newprescribe)
  1660. fmt.Println("处方44444444444")
  1661. //获取key,清空redis
  1662. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1663. redis := service.RedisClient()
  1664. //清空key 值
  1665. redis.Set(key, "", time.Second)
  1666. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1667. //清空key 值
  1668. redis.Set(keyOne, "", time.Second)
  1669. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1670. //清空key 值
  1671. redis.Set(keyTwo, "", time.Second)
  1672. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1673. redis.Set(keySix, "", time.Second)
  1674. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1675. redis.Set(keySeven, "", time.Second)
  1676. if err != nil {
  1677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1678. }
  1679. } else {
  1680. err := service.UpDateDialysisPrescription(&newprescribe)
  1681. //获取key,清空redis
  1682. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1683. redis := service.RedisClient()
  1684. //清空key 值
  1685. redis.Set(key, "", time.Second)
  1686. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1687. //清空key 值
  1688. redis.Set(keyOne, "", time.Second)
  1689. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1690. //清空key 值
  1691. redis.Set(keyTwo, "", time.Second)
  1692. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1693. redis.Set(keySix, "", time.Second)
  1694. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1695. redis.Set(keySeven, "", time.Second)
  1696. if err != nil {
  1697. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1698. }
  1699. }
  1700. if err != nil {
  1701. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1702. }
  1703. }
  1704. }
  1705. // 手动修改透前评估的时候,如果透析处方已经存在,则不修改对应的透析处方
  1706. // if dialysisPrescribe != nil {
  1707. // dialysisPrescribe.UpdatedTime = time.Now().Unix()
  1708. // dialysisPrescribe.RecordDate = theAssessmentDateTime
  1709. // dialysisPrescribe.DewaterAmount = dewater_amount
  1710. // dialysisPrescribe.TargetUltrafiltration = dewater_amount
  1711. // dialysisPrescribe.Status = 1
  1712. // updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
  1713. // if updateErr != nil {
  1714. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1715. // }
  1716. // }
  1717. err = service.UpadatePredialysisEvaluation(&evaluation)
  1718. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_before_dislysis"
  1719. redis := service.RedisClient()
  1720. defer redis.Close()
  1721. //清空key 值
  1722. redis.Set(key, "", time.Second)
  1723. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_befores_list_all"
  1724. redis.Set(keyOne, "", time.Second)
  1725. keyTwo := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1726. redis.Set(keyTwo, "", time.Second)
  1727. if err != nil {
  1728. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1729. return
  1730. }
  1731. c.ServeSuccessJSON(map[string]interface{}{
  1732. "msg": "ok",
  1733. "evaluation": evaluation,
  1734. })
  1735. return
  1736. }
  1737. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  1738. dataBody := make(map[string]interface{}, 0)
  1739. err := json.Unmarshal(data, &dataBody)
  1740. utils.InfoLog(string(data))
  1741. if err != nil {
  1742. utils.ErrorLog(err.Error())
  1743. code = enums.ErrorCodeParamWrong
  1744. return
  1745. }
  1746. // if method == "create" {
  1747. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  1748. utils.ErrorLog("mode")
  1749. code = enums.ErrorCodeParamWrong
  1750. return
  1751. }
  1752. mode := int64(dataBody["mode"].(float64))
  1753. if mode <= 0 {
  1754. utils.ErrorLog("mode <= 0")
  1755. code = enums.ErrorCodeParamWrong
  1756. return
  1757. }
  1758. solution.ModeId = mode
  1759. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  1760. utils.ErrorLog("mode_name")
  1761. code = enums.ErrorCodeParamWrong
  1762. return
  1763. }
  1764. modeName, _ := dataBody["mode_name"].(string)
  1765. if len(modeName) == 0 {
  1766. utils.ErrorLog("len(mode_name) == 0")
  1767. code = enums.ErrorCodeParamWrong
  1768. return
  1769. }
  1770. solution.ModeName = modeName
  1771. solution.Name = modeName
  1772. // }
  1773. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  1774. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  1775. solution.DialysisDuration = dialysisDuration
  1776. }
  1777. if dataBody["dialysis_duration"] != nil {
  1778. if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  1779. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  1780. solution.DialysisDuration = dialysisDuration
  1781. } else if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "float64" {
  1782. dialysisDuration := dataBody["dialysis_duration"].(float64)
  1783. solution.DialysisDuration = dialysisDuration
  1784. }
  1785. }
  1786. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  1787. dialyzer := int64(dataBody["dialyzer"].(float64))
  1788. solution.Dialyzer = dialyzer
  1789. }
  1790. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  1791. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  1792. solution.PerfusionApparatus = perfusionApparatus
  1793. }
  1794. if dataBody["blood_flow_volume"] != nil {
  1795. if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  1796. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  1797. solution.BloodFlowVolume = bloodFlowVolume
  1798. } else if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "float64" {
  1799. bloodFlowVolume := dataBody["blood_flow_volume"].(float64)
  1800. solution.BloodFlowVolume = bloodFlowVolume
  1801. }
  1802. }
  1803. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  1804. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  1805. solution.HemodialysisMachine = hemodialysisMachine
  1806. }
  1807. if dataBody["dewater"] != nil {
  1808. if reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  1809. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  1810. solution.Dewater = dewater
  1811. } else if reflect.TypeOf(dataBody["dewater"]).String() == "float64" {
  1812. dewater := dataBody["dewater"].(float64)
  1813. solution.Dewater = dewater
  1814. }
  1815. }
  1816. if dataBody["replacement_total"] != nil {
  1817. if reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  1818. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  1819. solution.ReplacementTotal = replacementTotal
  1820. } else if reflect.TypeOf(dataBody["replacement_total"]).String() == "float64" {
  1821. replacementTotal := dataBody["replacement_total"].(float64)
  1822. solution.ReplacementTotal = replacementTotal
  1823. }
  1824. }
  1825. if dataBody["displace_liqui"] != nil {
  1826. if reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  1827. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  1828. solution.DisplaceLiqui = displaceLiqui
  1829. } else if reflect.TypeOf(dataBody["displace_liqui"]).String() == "float64" {
  1830. displaceLiqui := dataBody["displace_liqui"].(float64)
  1831. solution.DisplaceLiqui = displaceLiqui
  1832. }
  1833. }
  1834. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  1835. replacementWay := int64(dataBody["replacement_way"].(float64))
  1836. solution.ReplacementWay = replacementWay
  1837. }
  1838. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  1839. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  1840. solution.Anticoagulant = anticoagulant
  1841. }
  1842. if dataBody["anticoagulant_shouji"] != nil {
  1843. if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  1844. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  1845. solution.AnticoagulantShouji = anticoagulantShouji
  1846. } else if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "float64" {
  1847. anticoagulantShouji := dataBody["anticoagulant_shouji"].(float64)
  1848. solution.AnticoagulantShouji = anticoagulantShouji
  1849. }
  1850. }
  1851. if dataBody["anticoagulant_weichi"] != nil {
  1852. if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  1853. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  1854. solution.AnticoagulantWeichi = anticoagulantWeichi
  1855. } else if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "float64" {
  1856. anticoagulantWeichi := dataBody["anticoagulant_weichi"].(float64)
  1857. solution.AnticoagulantWeichi = anticoagulantWeichi
  1858. }
  1859. }
  1860. if dataBody["anticoagulant_zongliang"] != nil {
  1861. if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  1862. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  1863. solution.AnticoagulantZongliang = anticoagulantZongliang
  1864. } else if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "float64" {
  1865. anticoagulantZongliang := dataBody["anticoagulant_zongliang"].(float64)
  1866. solution.AnticoagulantZongliang = anticoagulantZongliang
  1867. }
  1868. }
  1869. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  1870. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  1871. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  1872. }
  1873. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  1874. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  1875. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  1876. }
  1877. if dataBody["kalium"] != nil {
  1878. if reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  1879. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  1880. solution.Kalium = kalium
  1881. } else if reflect.TypeOf(dataBody["kalium"]).String() == "float64" {
  1882. kalium := dataBody["kalium"].(float64)
  1883. solution.Kalium = kalium
  1884. }
  1885. }
  1886. if dataBody["sodium"] != nil {
  1887. if reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  1888. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  1889. solution.Sodium = sodium
  1890. } else if reflect.TypeOf(dataBody["sodium"]).String() == "float64" {
  1891. sodium := dataBody["sodium"].(float64)
  1892. solution.Sodium = sodium
  1893. }
  1894. }
  1895. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  1896. if reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  1897. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  1898. solution.Calcium = calcium
  1899. } else if reflect.TypeOf(dataBody["calcium"]).String() == "float64" {
  1900. calcium := dataBody["calcium"].(float64)
  1901. solution.Calcium = calcium
  1902. }
  1903. }
  1904. if dataBody["bicarbonate"] != nil {
  1905. if reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  1906. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  1907. solution.Bicarbonate = bicarbonate
  1908. } else if reflect.TypeOf(dataBody["bicarbonate"]).String() == "float64" {
  1909. bicarbonate := dataBody["bicarbonate"].(float64)
  1910. solution.Bicarbonate = bicarbonate
  1911. }
  1912. }
  1913. if dataBody["glucose"] != nil {
  1914. if reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  1915. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  1916. solution.Glucose = glucose
  1917. } else if reflect.TypeOf(dataBody["glucose"]).String() == "float64" {
  1918. glucose := dataBody["glucose"].(float64)
  1919. solution.Glucose = glucose
  1920. }
  1921. }
  1922. // if dataBody["dry_weight"] != nil {
  1923. // if reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  1924. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  1925. // solution.DryWeight = dryWeight
  1926. // } else if reflect.TypeOf(dataBody["dry_weight"]).String() == "float64" {
  1927. // dryWeight := dataBody["dry_weight"].(float64)
  1928. // solution.DryWeight = dryWeight
  1929. // }
  1930. // }
  1931. if dataBody["dialysate_flow"] != nil {
  1932. if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  1933. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  1934. solution.DialysateFlow = dialysateFlow
  1935. } else if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "float64" {
  1936. dialysateFlow := dataBody["dialysate_flow"].(float64)
  1937. solution.DialysateFlow = dialysateFlow
  1938. }
  1939. }
  1940. if dataBody["dialysate_temperature"] != nil {
  1941. if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  1942. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  1943. solution.DialysateTemperature = dialysateTemperature
  1944. } else if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "float64" {
  1945. dialysateTemperature := dataBody["dialysate_temperature"].(float64)
  1946. solution.DialysateTemperature = dialysateTemperature
  1947. }
  1948. }
  1949. if dataBody["conductivity"] != nil {
  1950. if reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  1951. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  1952. solution.Conductivity = conductivity
  1953. } else if reflect.TypeOf(dataBody["conductivity"]).String() == "float64" {
  1954. conductivity := dataBody["conductivity"].(float64)
  1955. solution.Conductivity = conductivity
  1956. }
  1957. }
  1958. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  1959. remark := dataBody["remark"].(string)
  1960. solution.Remark = remark
  1961. }
  1962. if dataBody["dialysis_duration_hour"] != nil {
  1963. if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  1964. dialysisDurationHour, _ := strconv.ParseInt(dataBody["dialysis_duration_hour"].(string), 10, 64)
  1965. solution.DialysisDurationHour = dialysisDurationHour
  1966. } else if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "float64" {
  1967. dialysisDurationHour := dataBody["dialysis_duration_hour"].(float64)
  1968. solution.DialysisDurationHour = int64(dialysisDurationHour)
  1969. }
  1970. }
  1971. if dataBody["dialysis_duration_minute"] != nil {
  1972. if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  1973. dialysisDurationMinute, _ := strconv.ParseInt(dataBody["dialysis_duration_minute"].(string), 10, 64)
  1974. solution.DialysisDurationMinute = dialysisDurationMinute
  1975. } else if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "float64" {
  1976. dialysisDurationMinute := dataBody["dialysis_duration_minute"].(float64)
  1977. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  1978. }
  1979. }
  1980. if dataBody["target_ultrafiltration"] != nil {
  1981. if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  1982. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  1983. solution.TargetUltrafiltration = targetUltrafiltration
  1984. } else if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "float64" {
  1985. targetUltrafiltration := dataBody["target_ultrafiltration"].(float64)
  1986. solution.TargetUltrafiltration = targetUltrafiltration
  1987. }
  1988. }
  1989. if dataBody["dialysate_formulation"] != nil {
  1990. if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "string" {
  1991. dialysateFormulation, _ := strconv.ParseInt(dataBody["dialysate_formulation"].(string), 10, 64)
  1992. solution.DialysateFormulation = dialysateFormulation
  1993. } else if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  1994. dialysateFormulation := dataBody["dialysate_formulation"].(float64)
  1995. solution.DialysateFormulation = int64(dialysateFormulation)
  1996. }
  1997. }
  1998. return
  1999. }
  2000. func predialysisEvaluationFormData(evaluation *models.PredialysisEvaluation, data []byte) (code int) {
  2001. dataBody := make(map[string]interface{}, 0)
  2002. err := json.Unmarshal(data, &dataBody)
  2003. utils.InfoLog(string(data))
  2004. if err != nil {
  2005. utils.ErrorLog(err.Error())
  2006. code = enums.ErrorCodeParamWrong
  2007. return
  2008. }
  2009. if dataBody["weight_before"] != nil && reflect.TypeOf(dataBody["weight_before"]).String() == "string" {
  2010. weightVefore, _ := strconv.ParseFloat(dataBody["weight_before"].(string), 64)
  2011. evaluation.WeightBefore = weightVefore
  2012. }
  2013. // fmt.Println(dataBody["dry_weight"])
  2014. // fmt.Println(reflect.TypeOf(dataBody["dry_weight"]).String())
  2015. if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  2016. additionalWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  2017. fmt.Println(additionalWeight)
  2018. evaluation.DryWeight = additionalWeight
  2019. }
  2020. if dataBody["additional_weight"] != nil && reflect.TypeOf(dataBody["additional_weight"]).String() == "string" {
  2021. additionalWeight, _ := strconv.ParseFloat(dataBody["additional_weight"].(string), 64)
  2022. fmt.Println(additionalWeight)
  2023. evaluation.AdditionalWeight = additionalWeight
  2024. }
  2025. if dataBody["temperature"] != nil && reflect.TypeOf(dataBody["temperature"]).String() == "string" {
  2026. Temperature, _ := strconv.ParseFloat(dataBody["temperature"].(string), 64)
  2027. evaluation.Temperature = Temperature
  2028. }
  2029. if dataBody["systolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["systolic_blood_pressure"]).String() == "string" {
  2030. systolicBloodPressure, _ := strconv.ParseFloat(dataBody["systolic_blood_pressure"].(string), 64)
  2031. evaluation.SystolicBloodPressure = systolicBloodPressure
  2032. }
  2033. if dataBody["diastolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["diastolic_blood_pressure"]).String() == "string" {
  2034. diastolicBloodPressure, _ := strconv.ParseFloat(dataBody["diastolic_blood_pressure"].(string), 64)
  2035. evaluation.DiastolicBloodPressure = diastolicBloodPressure
  2036. }
  2037. if dataBody["pulse_frequency"] != nil && reflect.TypeOf(dataBody["pulse_frequency"]).String() == "string" {
  2038. pulseFrequency, _ := strconv.ParseFloat(dataBody["pulse_frequency"].(string), 64)
  2039. evaluation.PulseFrequency = pulseFrequency
  2040. }
  2041. if dataBody["breathing_rate"] != nil && reflect.TypeOf(dataBody["breathing_rate"]).String() == "string" {
  2042. breathingRate, _ := strconv.ParseFloat(dataBody["breathing_rate"].(string), 64)
  2043. evaluation.BreathingRate = breathingRate
  2044. }
  2045. if dataBody["last_post_dialysis"] != nil && reflect.TypeOf(dataBody["last_post_dialysis"]).String() == "string" {
  2046. lastPostDialysis, _ := dataBody["last_post_dialysis"].(string)
  2047. evaluation.LastPostDialysis = lastPostDialysis
  2048. }
  2049. if dataBody["dialysis_interphase"] != nil && reflect.TypeOf(dataBody["dialysis_interphase"]).String() == "string" {
  2050. dialysisInterphase, _ := dataBody["dialysis_interphase"].(string)
  2051. evaluation.DialysisInterphase = dialysisInterphase
  2052. }
  2053. if dataBody["symptom_before_dialysis"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis"]).String() == "string" {
  2054. symptomBeforeDialysis, _ := dataBody["symptom_before_dialysis"].(string)
  2055. evaluation.SymptomBeforeDialysis = symptomBeforeDialysis
  2056. }
  2057. if dataBody["catheter"] != nil && reflect.TypeOf(dataBody["catheter"]).String() == "string" {
  2058. catheter, _ := dataBody["catheter"].(string)
  2059. evaluation.Catheter = catheter
  2060. }
  2061. if dataBody["catheter_bend"] != nil && reflect.TypeOf(dataBody["catheter_bend"]).String() == "float64" {
  2062. catheter_bend := int(dataBody["catheter_bend"].(float64))
  2063. evaluation.CatheterBend = catheter_bend
  2064. }
  2065. if dataBody["complication"] != nil && reflect.TypeOf(dataBody["complication"]).String() == "string" {
  2066. Complication, _ := dataBody["complication"].(string)
  2067. evaluation.Complication = Complication
  2068. }
  2069. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2070. remark := dataBody["remark"].(string)
  2071. evaluation.Remark = remark
  2072. }
  2073. if dataBody["machine_type"] != nil && reflect.TypeOf(dataBody["machine_type"]).String() == "string" {
  2074. machine_type := dataBody["machine_type"].(string)
  2075. evaluation.MachineType = machine_type
  2076. }
  2077. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  2078. blood_access_part_id := dataBody["blood_access_part_id"].(string)
  2079. evaluation.BloodAccessPartId = blood_access_part_id
  2080. }
  2081. //if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "float64" {
  2082. // blood_access_part_id := int64(dataBody["blood_access_part_id"].(float64))
  2083. // evaluation.BloodAccessPartId = blood_access_part_id
  2084. //}
  2085. if dataBody["blood_access_part_opera_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_opera_id"]).String() == "float64" {
  2086. blood_access_part_opera_id := int64(dataBody["blood_access_part_opera_id"].(float64))
  2087. evaluation.BloodAccessPartOperaId = blood_access_part_opera_id
  2088. }
  2089. if dataBody["internal_fistula"] != nil && reflect.TypeOf(dataBody["internal_fistula"]).String() == "string" {
  2090. internal_fistula, _ := dataBody["internal_fistula"].(string)
  2091. evaluation.InternalFistula = internal_fistula
  2092. }
  2093. if dataBody["internal_fistula_skin"] != nil && reflect.TypeOf(dataBody["internal_fistula_skin"]).String() == "string" {
  2094. internal_fistula_skin := dataBody["internal_fistula_skin"].(string)
  2095. evaluation.InternalFistulaSkin = internal_fistula_skin
  2096. }
  2097. if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "string" {
  2098. ishemorrhage, _ := dataBody["is_hemorrhage"].(string)
  2099. is_hemorrhage, _ := strconv.ParseInt(ishemorrhage, 10, 64)
  2100. evaluation.IsHemorrhage = is_hemorrhage
  2101. //if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "float64" {
  2102. // is_hemorrhage := int64(dataBody["is_hemorrhage"].(float64))
  2103. // fmt.Println("is_hemorrhage2222222222222222",is_hemorrhage)
  2104. if is_hemorrhage != 1 && is_hemorrhage != 2 {
  2105. is_hemorrhage = 0
  2106. }
  2107. evaluation.IsHemorrhage = is_hemorrhage
  2108. if is_hemorrhage == 1 {
  2109. if dataBody["hemorrhage"] != nil && reflect.TypeOf(dataBody["hemorrhage"]).String() == "string" {
  2110. hemorrhage, _ := dataBody["hemorrhage"].(string)
  2111. evaluation.Hemorrhage = hemorrhage
  2112. }
  2113. if dataBody["hemorrhage_other"] != nil && reflect.TypeOf(dataBody["hemorrhage_other"]).String() == "string" {
  2114. hemorrhage_other, _ := dataBody["hemorrhage_other"].(string)
  2115. evaluation.HemorrhageOther = hemorrhage_other
  2116. }
  2117. }
  2118. } else {
  2119. evaluation.IsHemorrhage = 0
  2120. }
  2121. if dataBody["blood_access_internal_fistula"] != nil && reflect.TypeOf(dataBody["blood_access_internal_fistula"]).String() == "string" {
  2122. blood_access_internal_fistula, _ := dataBody["blood_access_internal_fistula"].(string)
  2123. evaluation.BloodAccessInternalFistula = blood_access_internal_fistula
  2124. }
  2125. if dataBody["internal_fistula_other"] != nil && reflect.TypeOf(dataBody["internal_fistula_other"]).String() == "string" {
  2126. internal_fistula_other, _ := dataBody["internal_fistula_other"].(string)
  2127. evaluation.InternalFistulaOther = internal_fistula_other
  2128. }
  2129. if dataBody["blood_access_noise"] != nil && reflect.TypeOf(dataBody["blood_access_noise"]).String() == "float64" {
  2130. blood_access_noise := int64(dataBody["blood_access_noise"].(float64))
  2131. evaluation.BloodAccessNoise = blood_access_noise
  2132. }
  2133. if dataBody["puncture_way"] != nil && reflect.TypeOf(dataBody["puncture_way"]).String() == "string" {
  2134. //puncture_way := int64(dataBody["puncture_way"].(float64))
  2135. puncture_way := dataBody["puncture_way"].(string)
  2136. evaluation.PunctureWay = puncture_way
  2137. }
  2138. if dataBody["venous_catheterization"] != nil && reflect.TypeOf(dataBody["venous_catheterization"]).String() == "float64" {
  2139. venous_catheterization := int64(dataBody["venous_catheterization"].(float64))
  2140. evaluation.VenousCatheterization = venous_catheterization
  2141. }
  2142. if dataBody["venous_catheterization_part"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part"]).String() == "float64" {
  2143. venous_catheterization_part := int64(dataBody["venous_catheterization_part"].(float64))
  2144. evaluation.VenousCatheterizationPart = venous_catheterization_part
  2145. }
  2146. if dataBody["venous_catheterization_part_other"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part_other"]).String() == "string" {
  2147. venous_catheterization_part_other, _ := dataBody["venous_catheterization_part_other"].(string)
  2148. evaluation.VenousCatheterizationPartOther = venous_catheterization_part_other
  2149. }
  2150. if dataBody["ductus_arantii"] != nil && reflect.TypeOf(dataBody["ductus_arantii"]).String() == "string" {
  2151. ductus_arantii, _ := dataBody["ductus_arantii"].(string)
  2152. evaluation.DuctusArantii = ductus_arantii
  2153. }
  2154. if dataBody["emergency_treatment"] != nil && reflect.TypeOf(dataBody["emergency_treatment"]).String() == "float64" {
  2155. emergency_treatment := int64(dataBody["emergency_treatment"].(float64))
  2156. evaluation.EmergencyTreatment = emergency_treatment
  2157. }
  2158. if dataBody["emergency_treatment_other"] != nil && reflect.TypeOf(dataBody["emergency_treatment_other"]).String() == "string" {
  2159. emergency_treatment_other, _ := dataBody["emergency_treatment_other"].(string)
  2160. evaluation.EmergencyTreatmentOther = emergency_treatment_other
  2161. }
  2162. if dataBody["dialysis_count"] != nil && reflect.TypeOf(dataBody["dialysis_count"]).String() == "string" {
  2163. dialysis_count, _ := dataBody["dialysis_count"].(string)
  2164. //count, _ := strconv.ParseInt(dialysis_count, 10, 64)
  2165. evaluation.DialysisCount = dialysis_count
  2166. }
  2167. if dataBody["is_infect"] != nil && reflect.TypeOf(dataBody["is_infect"]).String() == "string" {
  2168. is_infect, _ := dataBody["is_infect"].(string)
  2169. infect, _ := strconv.ParseInt(is_infect, 10, 64)
  2170. evaluation.IsInfect = infect
  2171. }
  2172. if dataBody["exposed"] != nil && reflect.TypeOf(dataBody["exposed"]).String() == "string" {
  2173. exposed, _ := strconv.ParseFloat(dataBody["exposed"].(string), 64)
  2174. evaluation.Exposed = exposed
  2175. }
  2176. if dataBody["skin"] != nil && reflect.TypeOf(dataBody["skin"]).String() == "string" {
  2177. skin, _ := dataBody["skin"].(string)
  2178. //skins, _ := strconv.ParseInt(skin, 10, 64)
  2179. evaluation.Skin = skin
  2180. }
  2181. if dataBody["skin_other"] != nil && reflect.TypeOf(dataBody["skin_other"]).String() == "string" {
  2182. skin_other, _ := dataBody["skin_other"].(string)
  2183. evaluation.SkinOther = skin_other
  2184. }
  2185. if dataBody["infect_other"] != nil && reflect.TypeOf(dataBody["infect_other"]).String() == "string" {
  2186. infect_other, _ := dataBody["infect_other"].(string)
  2187. evaluation.InfectOther = infect_other
  2188. }
  2189. if dataBody["ductus_arantii_other"] != nil && reflect.TypeOf(dataBody["ductus_arantii_other"]).String() == "string" {
  2190. ductus_arantii_other, _ := dataBody["ductus_arantii_other"].(string)
  2191. evaluation.DuctusArantiiOther = ductus_arantii_other
  2192. }
  2193. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  2194. punctureNeedle, _ := dataBody["puncture_needle"].(string)
  2195. evaluation.PunctureNeedle = punctureNeedle
  2196. }
  2197. if dataBody["humor_excessive_symptom"] != nil && reflect.TypeOf(dataBody["humor_excessive_symptom"]).String() == "string" {
  2198. humor_excessive_symptom, _ := dataBody["humor_excessive_symptom"].(string)
  2199. evaluation.HumorExcessiveSymptom = humor_excessive_symptom
  2200. }
  2201. if dataBody["pinholing"] != nil && reflect.TypeOf(dataBody["pinholing"]).String() == "string" {
  2202. pinholing := dataBody["pinholing"].(string)
  2203. evaluation.Phinholing = pinholing
  2204. }
  2205. if dataBody["catheter_suture"] != nil && reflect.TypeOf(dataBody["catheter_suture"]).String() == "string" {
  2206. catheter_suture := dataBody["catheter_suture"].(string)
  2207. evaluation.CatheterSuture = catheter_suture
  2208. }
  2209. if dataBody["catheter_suture_other"] != nil && reflect.TypeOf(dataBody["catheter_suture_other"]).String() == "string" {
  2210. catheter_suture_other := dataBody["catheter_suture_other"].(string)
  2211. evaluation.CatheterSutureOther = catheter_suture_other
  2212. }
  2213. if dataBody["urine_volume"] != nil && reflect.TypeOf(dataBody["urine_volume"]).String() == "string" {
  2214. urine_volume, _ := strconv.ParseFloat(dataBody["urine_volume"].(string), 64)
  2215. evaluation.UrineVolume = urine_volume
  2216. }
  2217. if dataBody["edema"] != nil && reflect.TypeOf(dataBody["edema"]).String() == "string" {
  2218. edema := dataBody["edema"].(string)
  2219. evaluation.Edema = edema
  2220. }
  2221. if dataBody["special_treatment"] != nil && reflect.TypeOf(dataBody["special_treatment"]).String() == "string" {
  2222. specialTreatment := dataBody["special_treatment"].(string)
  2223. evaluation.SpecialTreatment = specialTreatment
  2224. }
  2225. if dataBody["catheter_maintenance"] != nil && reflect.TypeOf(dataBody["catheter_maintenance"]).String() == "string" {
  2226. catheter_maintenance := dataBody["catheter_maintenance"].(string)
  2227. evaluation.CatheterMaintenance = catheter_maintenance
  2228. }
  2229. if dataBody["thromubus_type"] != nil && reflect.TypeOf(dataBody["thromubus_type"]).String() == "float64" {
  2230. thromubusType := int64(dataBody["thromubus_type"].(float64))
  2231. evaluation.ThromubusType = thromubusType
  2232. }
  2233. if dataBody["thrombus_av"] != nil && reflect.TypeOf(dataBody["thrombus_av"]).String() == "string" {
  2234. thrombus_av := dataBody["thrombus_av"].(string)
  2235. evaluation.ThrombusAv = thrombus_av
  2236. }
  2237. if dataBody["thromubus_a"] != nil && reflect.TypeOf(dataBody["thromubus_a"]).String() == "string" {
  2238. thromubus_a := dataBody["thromubus_a"].(string)
  2239. evaluation.ThromubusA = thromubus_a
  2240. }
  2241. if dataBody["thromubus_v"] != nil && reflect.TypeOf(dataBody["thromubus_v"]).String() == "string" {
  2242. thromubus_v := dataBody["thromubus_v"].(string)
  2243. evaluation.ThromubusV = thromubus_v
  2244. }
  2245. if dataBody["dehydration"] != nil && reflect.TypeOf(dataBody["dehydration"]).String() == "string" {
  2246. dehydration := dataBody["dehydration"].(string)
  2247. evaluation.Dehydration = dehydration
  2248. }
  2249. if dataBody["period"] != nil && reflect.TypeOf(dataBody["period"]).String() == "float64" {
  2250. period := int64(dataBody["period"].(float64))
  2251. evaluation.Period = period
  2252. }
  2253. if dataBody["estimated_food_intake"] != nil && reflect.TypeOf(dataBody["estimated_food_intake"]).String() == "string" {
  2254. estimated_food_intake := dataBody["estimated_food_intake"].(string)
  2255. evaluation.EstimatedFoodIntake = estimated_food_intake
  2256. }
  2257. if dataBody["blood_pressure_during_dialysis"] != nil && reflect.TypeOf(dataBody["blood_pressure_during_dialysis"]).String() == "string" {
  2258. blood_pressure_during_dialysis := dataBody["blood_pressure_during_dialysis"].(string)
  2259. evaluation.BloodPressureDuringDialysis = blood_pressure_during_dialysis
  2260. }
  2261. if dataBody["pre_dialysis_drugs"] != nil && reflect.TypeOf(dataBody["pre_dialysis_drugs"]).String() == "string" {
  2262. pre_dialysis_drugs := dataBody["pre_dialysis_drugs"].(string)
  2263. evaluation.PreDialysisDrugs = pre_dialysis_drugs
  2264. }
  2265. if dataBody["urea_befor"] != nil && reflect.TypeOf(dataBody["urea_befor"]).String() == "string" {
  2266. urea_befor := dataBody["urea_befor"].(string)
  2267. evaluation.UreaBefor = urea_befor
  2268. }
  2269. return
  2270. }
  2271. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  2272. dataBody := make(map[string]interface{}, 0)
  2273. err := json.Unmarshal(data, &dataBody)
  2274. if err != nil {
  2275. utils.ErrorLog(err.Error())
  2276. code = enums.ErrorCodeParamWrong
  2277. return
  2278. }
  2279. timeLayout := "2006-01-02"
  2280. loc, _ := time.LoadLocation("Local")
  2281. isChild := false
  2282. if action == "create" {
  2283. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2284. utils.ErrorLog("advice_type")
  2285. code = enums.ErrorCodeParamWrong
  2286. return
  2287. }
  2288. adviceType := int64(dataBody["advice_type"].(float64))
  2289. if adviceType != 1 && adviceType != 2 {
  2290. utils.ErrorLog("advice_type != 1&&2")
  2291. code = enums.ErrorCodeParamWrong
  2292. return
  2293. }
  2294. advice.AdviceType = adviceType
  2295. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2296. utils.ErrorLog("advice_date")
  2297. code = enums.ErrorCodeParamWrong
  2298. return
  2299. }
  2300. adviceDate, _ := dataBody["advice_date"].(string)
  2301. if len(adviceDate) == 0 {
  2302. utils.ErrorLog("len(adviceDate) == 0")
  2303. code = enums.ErrorCodeParamWrong
  2304. return
  2305. }
  2306. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  2307. if err != nil {
  2308. utils.ErrorLog(err.Error())
  2309. code = enums.ErrorCodeParamWrong
  2310. return
  2311. }
  2312. advice.AdviceDate = theTime.Unix()
  2313. advice.RecordDate = theTime.Unix()
  2314. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  2315. parentId := int64(dataBody["parent_id"].(float64))
  2316. advice.ParentId = parentId
  2317. if parentId > 0 {
  2318. isChild = true
  2319. }
  2320. }
  2321. } else {
  2322. isChild = advice.ParentId > 0
  2323. }
  2324. if !isChild {
  2325. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2326. utils.ErrorLog("start_time")
  2327. code = enums.ErrorCodeParamWrong
  2328. return
  2329. }
  2330. startTime, _ := dataBody["start_time"].(string)
  2331. if len(startTime) == 0 {
  2332. utils.ErrorLog("len(start_time) == 0")
  2333. code = enums.ErrorCodeParamWrong
  2334. return
  2335. }
  2336. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  2337. if err != nil {
  2338. utils.ErrorLog(err.Error())
  2339. code = enums.ErrorCodeParamWrong
  2340. return
  2341. }
  2342. advice.StartTime = theTime.Unix()
  2343. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  2344. deliveryWay, _ := dataBody["delivery_way"].(string)
  2345. advice.DeliveryWay = deliveryWay
  2346. }
  2347. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  2348. executionFrequency, _ := dataBody["execution_frequency"].(string)
  2349. advice.ExecutionFrequency = executionFrequency
  2350. }
  2351. }
  2352. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  2353. deliveryWay, _ := dataBody["delivery_way"].(string)
  2354. advice.DeliveryWay = deliveryWay
  2355. }
  2356. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  2357. executionFrequency, _ := dataBody["execution_frequency"].(string)
  2358. advice.ExecutionFrequency = executionFrequency
  2359. }
  2360. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  2361. utils.ErrorLog("advice_name")
  2362. code = enums.ErrorCodeParamWrong
  2363. return
  2364. }
  2365. adviceName, _ := dataBody["advice_name"].(string)
  2366. if len(adviceName) == 0 {
  2367. utils.ErrorLog("len(advice_name) == 0")
  2368. code = enums.ErrorCodeParamWrong
  2369. return
  2370. }
  2371. advice.AdviceName = adviceName
  2372. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  2373. adviceDsc, _ := dataBody["advice_desc"].(string)
  2374. advice.AdviceDesc = adviceDsc
  2375. }
  2376. if dataBody["way"] == nil {
  2377. advice.Way = 0
  2378. } else {
  2379. if dataBody["way"] != nil || reflect.TypeOf(dataBody["way"]).String() == "float64" {
  2380. way := int64(dataBody["way"].(float64))
  2381. advice.Way = way
  2382. }
  2383. }
  2384. if dataBody["drug_id"] == nil {
  2385. advice.DrugId = 0
  2386. } else {
  2387. if dataBody["drug_id"] != nil || reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
  2388. drug_id := int64(dataBody["drug_id"].(float64))
  2389. advice.DrugId = drug_id
  2390. }
  2391. }
  2392. if dataBody["drug_name_id"] == nil {
  2393. advice.DrugNameId = 0
  2394. } else {
  2395. if dataBody["drug_name_id"] != nil || reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
  2396. drug_name_id := int64(dataBody["drug_name_id"].(float64))
  2397. advice.DrugNameId = drug_name_id
  2398. fmt.Println("0000000000", advice.DrugNameId)
  2399. }
  2400. }
  2401. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  2402. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  2403. advice.SingleDose = singleDose
  2404. }
  2405. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  2406. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  2407. advice.SingleDoseUnit = singleDoseUnit
  2408. }
  2409. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  2410. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  2411. advice.DrugSpec = drugSpec
  2412. }
  2413. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  2414. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  2415. advice.DrugSpecUnit = drugSpecUnit
  2416. }
  2417. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  2418. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  2419. advice.PrescribingNumber = prescribingNumber
  2420. }
  2421. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  2422. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  2423. advice.PrescribingNumberUnit = prescribingNumberUnit
  2424. }
  2425. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2426. remark, _ := dataBody["remark"].(string)
  2427. advice.Remark = remark
  2428. }
  2429. return
  2430. }
  2431. func (c *PatientApiController) GetPatientEducation() {
  2432. patientID, _ := c.GetInt64("patient_id", 0)
  2433. page, _ := c.GetInt64("page", 0)
  2434. limit, _ := c.GetInt64("limit", 0)
  2435. startTime := c.GetString("start_time", "")
  2436. endTime := c.GetString("end_time", "")
  2437. if page <= 0 {
  2438. page = 1
  2439. }
  2440. if limit <= 0 {
  2441. limit = 10
  2442. }
  2443. if patientID <= 0 {
  2444. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2445. return
  2446. }
  2447. timeLayout := "2006-01-02"
  2448. loc, _ := time.LoadLocation("Local")
  2449. var theStartTIme int64
  2450. if len(startTime) > 0 {
  2451. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  2452. if err != nil {
  2453. theStartTIme = 0
  2454. }
  2455. theStartTIme = theTime.Unix()
  2456. }
  2457. var theEndtTIme int64
  2458. if len(endTime) > 0 {
  2459. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  2460. if err != nil {
  2461. theEndtTIme = 0
  2462. }
  2463. theEndtTIme = theTime.Unix()
  2464. }
  2465. adminUserInfo := c.GetMobileAdminUserInfo()
  2466. edus, total, _ := service.GetPatientTreatmentSummaryList(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme)
  2467. c.ServeSuccessJSON(map[string]interface{}{
  2468. "total": total,
  2469. "edus": edus,
  2470. })
  2471. return
  2472. }
  2473. func (c *PatientApiController) GetPatientSchedulesList() {
  2474. patientID, _ := c.GetInt64("patient_id", 0)
  2475. page, _ := c.GetInt64("page", 0)
  2476. limit, _ := c.GetInt64("limit", 0)
  2477. if patientID <= 0 {
  2478. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2479. return
  2480. }
  2481. adminUserInfo := c.GetMobileAdminUserInfo()
  2482. todayTime := time.Now().Format("2006-01-02")
  2483. timeLayout := "2006-01-02 15:04:05"
  2484. loc, _ := time.LoadLocation("Local")
  2485. var theStartTime int64
  2486. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  2487. theStartTime = theTime.Unix()
  2488. schedules, _ := service.GetPatientScheduleList(adminUserInfo.Org.Id, patientID, page, limit, theStartTime)
  2489. if len(schedules) > 0 {
  2490. for index, item := range schedules {
  2491. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  2492. schedules[index].Week = int64(week)
  2493. }
  2494. }
  2495. c.ServeSuccessJSON(map[string]interface{}{
  2496. "schedules": schedules,
  2497. })
  2498. return
  2499. }
  2500. func (c *PatientApiController) GetRecords() {
  2501. patientID, _ := c.GetInt64("patient_id", 0)
  2502. page, _ := c.GetInt64("page", 0)
  2503. limit, _ := c.GetInt64("limit", 0)
  2504. startTime := c.GetString("start_time", "")
  2505. endTime := c.GetString("end_time", "")
  2506. mode_id, _ := c.GetInt64("mode_id", 0)
  2507. if page <= 0 {
  2508. page = 1
  2509. }
  2510. if limit <= 0 {
  2511. limit = 10
  2512. }
  2513. if patientID <= 0 {
  2514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2515. return
  2516. }
  2517. timeLayout := "2006-01-02"
  2518. loc, _ := time.LoadLocation("Local")
  2519. var theStartTIme int64
  2520. if len(startTime) > 0 {
  2521. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  2522. if err != nil {
  2523. theStartTIme = 0
  2524. }
  2525. theStartTIme = theTime.Unix()
  2526. }
  2527. var theEndtTIme int64
  2528. if len(endTime) > 0 {
  2529. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  2530. if err != nil {
  2531. theEndtTIme = 0
  2532. }
  2533. theEndtTIme = theTime.Unix()
  2534. }
  2535. adminUserInfo := c.GetMobileAdminUserInfo()
  2536. records, total, _ := service.GetPatientDialysisRecord(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  2537. c.ServeSuccessJSON(map[string]interface{}{
  2538. "total": total,
  2539. "records": records,
  2540. })
  2541. return
  2542. }
  2543. func (c *PatientApiController) GetPatientMonitor() {
  2544. partition, _ := c.GetInt64("partition")
  2545. monitorDate := c.GetString("date")
  2546. patient_id, _ := c.GetInt64("patient_id")
  2547. timeLayout := "2006-01-02"
  2548. loc, _ := time.LoadLocation("Local")
  2549. var theStartTime int64
  2550. if len(monitorDate) > 0 {
  2551. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  2552. if err != nil {
  2553. theStartTime = 0
  2554. }
  2555. theStartTime = theTime.Unix()
  2556. }
  2557. adminInfo := c.GetMobileAdminUserInfo()
  2558. orgID := adminInfo.Org.Id
  2559. monitor, err := service.GetMonitorRecord(orgID, theStartTime, partition, patient_id)
  2560. if err != nil {
  2561. c.ErrorLog("获取排班信息失败:%v", err)
  2562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2563. } else {
  2564. if len(monitor) > 0 {
  2565. //获取所有床位
  2566. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  2567. //获取所有分区
  2568. zoneList, _ := service.GetAllZoneByList(orgID)
  2569. //获取透析处方
  2570. prescriptions, _ := service.GetAllPrescriptionByList(orgID, theStartTime)
  2571. //获取透前评估
  2572. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  2573. //获取上机
  2574. dialysisOrders, _ := service.GetAllDialysisOrdersByListSix(orgID, theStartTime)
  2575. //获取透后
  2576. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListOne(orgID, theStartTime)
  2577. //获取透后监测
  2578. monitorlist, _ := service.GetAllMonitorList(orgID, theStartTime)
  2579. //获取所有的患者
  2580. patients, _ := service.GetAllPatientListByListOne(orgID)
  2581. //获取所有透析模式
  2582. treatments, _ := service.GetAllTreatModeByList(orgID)
  2583. for key, item := range monitor {
  2584. // 获取床位信息
  2585. for _, it := range numberList {
  2586. if item.BedId == it.ID {
  2587. monitor[key].DeviceNumber = it
  2588. break
  2589. }
  2590. }
  2591. //获取分区信息
  2592. for _, it := range zoneList {
  2593. if item.PartitionId == it.ID {
  2594. monitor[key].DeviceZone = it
  2595. }
  2596. }
  2597. for _, prescription := range prescriptions {
  2598. if item.PatientId == prescription.PatientId {
  2599. monitor[key].Prescription = prescription
  2600. break
  2601. }
  2602. }
  2603. // 透前评估
  2604. for _, assessmentBefore := range assessmentBefores {
  2605. if item.PatientId == assessmentBefore.PatientId {
  2606. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  2607. break
  2608. }
  2609. }
  2610. // 透析上下机
  2611. for _, dialysisOrder := range dialysisOrders {
  2612. if item.PatientId == dialysisOrder.PatientId {
  2613. monitor[key].DialysisOrder = dialysisOrder
  2614. break
  2615. }
  2616. }
  2617. // 治疗小节
  2618. for _, afterDislysis := range AssessmentAfterDislysis {
  2619. if item.PatientId == afterDislysis.PatientId {
  2620. monitor[key].AssessmentAfterDislysis = afterDislysis
  2621. break
  2622. }
  2623. }
  2624. for _, it := range monitorlist {
  2625. if item.PatientId == it.PatientId {
  2626. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  2627. }
  2628. }
  2629. for _, patient := range patients {
  2630. if item.PatientId == patient.ID {
  2631. monitor[key].MonitorPatients = patient
  2632. break
  2633. }
  2634. }
  2635. for _, treatment := range treatments {
  2636. if item.ModeId == treatment.ID {
  2637. monitor[key].TreatmentMode = treatment
  2638. break
  2639. }
  2640. }
  2641. }
  2642. }
  2643. }
  2644. //获取患者的透析次数
  2645. count, err := service.GetDialysisCount(orgID, partition)
  2646. patients, err := service.GetAllpatient(orgID)
  2647. if err == nil {
  2648. c.ServeSuccessJSON(map[string]interface{}{
  2649. "monitor": monitor,
  2650. "patientCount": count,
  2651. "patients": patients,
  2652. })
  2653. } else {
  2654. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2655. }
  2656. }
  2657. // /m/api/monitor/patient [get] 搜索病人的测量记录
  2658. // @param keyword:string 病人姓名或透析号
  2659. // @param page:int
  2660. func (this *PatientApiController) SearchMonitorPatient() {
  2661. keyword := this.GetString("keyword")
  2662. page, _ := this.GetInt("page")
  2663. if page <= 0 {
  2664. page = 1
  2665. }
  2666. if len(keyword) == 0 {
  2667. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2668. return
  2669. }
  2670. adminUserInfo := this.GetMobileAdminUserInfo()
  2671. monitors, getMonitorErr := service.MobileGetMonitorsWithPatient(adminUserInfo.Org.Id, keyword, page)
  2672. if getMonitorErr != nil {
  2673. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2674. return
  2675. } else {
  2676. this.ServeSuccessJSON(map[string]interface{}{
  2677. "monitor": monitors,
  2678. })
  2679. }
  2680. }
  2681. func (c *PatientApiController) GetPatientDialysisSolutionList() {
  2682. id, _ := c.GetInt64("id", 0)
  2683. page, _ := c.GetInt64("page", 0)
  2684. limit, _ := c.GetInt64("limit", 0)
  2685. if id <= 0 {
  2686. c.ServeSuccessJSON(map[string]interface{}{
  2687. "solutions": nil,
  2688. })
  2689. return
  2690. }
  2691. if page <= 0 {
  2692. page = 1
  2693. }
  2694. if limit <= 0 {
  2695. limit = 10
  2696. }
  2697. adminInfo := c.GetMobileAdminUserInfo()
  2698. solutions, total, _ := service.GetPatientDialysisSolutionList(adminInfo.Org.Id, id, page, limit)
  2699. c.ServeSuccessJSON(map[string]interface{}{
  2700. "solutions": solutions,
  2701. "total": total,
  2702. })
  2703. return
  2704. }
  2705. //GetDoctorAdvices 医嘱列表
  2706. func (c *PatientApiController) GetDoctorAdvices() {
  2707. id, _ := c.GetInt64("id", 0)
  2708. adviceType, _ := c.GetInt64("advice_type", 0)
  2709. stopType, _ := c.GetInt64("stop_state", 0)
  2710. startTime := c.GetString("start_time", "")
  2711. endTime := c.GetString("end_time", "")
  2712. keywords := c.GetString("keywords", "")
  2713. need, _ := c.GetInt64("need_doctor", 0)
  2714. adminUserInfo := c.GetMobileAdminUserInfo()
  2715. timeLayout := "2006-01-02"
  2716. loc, _ := time.LoadLocation("Local")
  2717. var theStartTIme int64
  2718. if len(startTime) > 0 {
  2719. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  2720. if err != nil {
  2721. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2722. return
  2723. }
  2724. theStartTIme = theTime.Unix()
  2725. }
  2726. var theEndtTIme int64
  2727. if len(endTime) > 0 {
  2728. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  2729. if err != nil {
  2730. utils.ErrorLog(err.Error())
  2731. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2732. return
  2733. }
  2734. theEndtTIme = theTime.Unix()
  2735. }
  2736. advices, total, _ := service.GetDoctorAdviceList(adminUserInfo.Org.Id, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords)
  2737. if need == 1 {
  2738. users, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  2739. c.ServeSuccessJSON(map[string]interface{}{
  2740. "advices": advices,
  2741. "total": total,
  2742. "users": users,
  2743. })
  2744. } else {
  2745. c.ServeSuccessJSON(map[string]interface{}{
  2746. "advices": advices,
  2747. "total": total,
  2748. "users": []string{},
  2749. })
  2750. }
  2751. return
  2752. }
  2753. func (c *PatientApiController) GetPrintDialysisOrder() {
  2754. xtno := c.GetString("xtno")
  2755. xtdate := c.GetString("xtdate")
  2756. timeLayout := "2006-01-02"
  2757. loc, _ := time.LoadLocation("Local")
  2758. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  2759. if err != nil {
  2760. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2761. return
  2762. }
  2763. xttime := theTime.Unix()
  2764. //获取当前日期月份的第一天
  2765. firstmonth := service.GetFirstDateOfMonth(theTime)
  2766. firstMonthDate := firstmonth.Unix()
  2767. operatorIDs := make([]int64, 0)
  2768. adminUserInfo := c.GetMobileAdminUserInfo()
  2769. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  2770. patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.Org.Id, xtno, xttime)
  2771. //透析单
  2772. dialysisOrder, _ := service.MobileGetSchedualDialysisRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2773. if dialysisOrder != nil {
  2774. if dialysisOrder.FinishNurse > 0 {
  2775. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  2776. }
  2777. if dialysisOrder.StartNurse > 0 {
  2778. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  2779. }
  2780. }
  2781. last_order, _ := service.GetLastTimeOrder(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2782. //透前评估
  2783. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2784. //透后评估
  2785. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2786. if AssessmentAfterDislysis.Modifier > 0 {
  2787. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  2788. }
  2789. //透析处方
  2790. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2791. if dialysisPrescription.PrescriptionDoctor > 0 {
  2792. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  2793. }
  2794. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2795. patientInfo.TotalDialysis = dialysis_count
  2796. //临时医嘱
  2797. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2798. hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2799. config, err := service.GetHisDoctorConfig(adminUserInfo.Org.Id)
  2800. project_config, _ := service.GetHisProjectConfig(adminUserInfo.Org.Id)
  2801. projects, _ := service.FindAllHisProjectById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2802. if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
  2803. for _, item := range projects {
  2804. cnt, _ := strconv.ParseFloat(item.Count, 64)
  2805. var advice models.HisDoctorAdviceInfo
  2806. advice.ID = item.ID
  2807. advice.Checker = item.Checker
  2808. advice.CheckTime = item.CheckTime
  2809. advice.CheckState = item.CheckState
  2810. advice.ExecutionState = item.ExecutionState
  2811. advice.ExecutionStaff = item.ExecutionStaff
  2812. //advice.PrescribingNumber = float64(item.Count)
  2813. advice.PrescribingNumber = cnt
  2814. advice.PrescribingNumberUnit = item.Unit
  2815. advice.AdviceDoctor = item.Doctor
  2816. if item.Type == 3 {
  2817. advice.AdviceName = item.GoodInfo.GoodName
  2818. advice.PrescribingNumberUnit = item.GoodInfo.PackingUnit
  2819. } else if item.Type == 2 {
  2820. advice.AdviceName = item.HisProject.ProjectName
  2821. }
  2822. advice.StartTime = item.StartTime
  2823. hisAdvice = append(hisAdvice, &advice)
  2824. }
  2825. }
  2826. if len(DoctorAdvice) > 0 {
  2827. for _, item := range DoctorAdvice {
  2828. if item.AdviceDoctor > 0 {
  2829. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  2830. }
  2831. if item.ExecutionStaff > 0 {
  2832. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  2833. }
  2834. if item.Checker > 0 {
  2835. operatorIDs = append(operatorIDs, item.Checker)
  2836. }
  2837. }
  2838. }
  2839. //DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2840. //透析监测
  2841. Record, _ := service.FindAllMonitorRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2842. //透析小结
  2843. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2844. //接诊评估
  2845. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2846. //相关操作对应的操作人
  2847. //operators, _ := service.GetAdminUserES(adminUserInfo.Org.Id, adminUserInfo.App.Id, operatorIDs)
  2848. operators, err := service.GetAllStarfEs(adminUserInfo.Org.Id)
  2849. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2850. check, _ := service.FindDoubleCheckById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2851. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.Org.Id)
  2852. if config.IsOpen == 1 {
  2853. c.ServeSuccessJSON(map[string]interface{}{
  2854. "users": adminUser,
  2855. "patientInfo": patientInfo,
  2856. "PredialysisEvaluation": PredialysisEvaluation,
  2857. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  2858. "dialysisPrescription": dialysisPrescription,
  2859. "advices": hisAdvice,
  2860. "monitors": Record,
  2861. "summary": TreatmentSummary,
  2862. "receiverTreatmentAccess": receiverTreatmentAccess,
  2863. "dialysisOrder": dialysisOrder,
  2864. "operators": operators,
  2865. "org_template_info": templateInfo,
  2866. "check": check,
  2867. "dialysiscount": dialysiscount,
  2868. "last_order": last_order,
  2869. "projects": projects,
  2870. "project_config": project_config,
  2871. })
  2872. }
  2873. if config.IsOpen == 0 || config.IsOpen == 2 {
  2874. c.ServeSuccessJSON(map[string]interface{}{
  2875. "users": adminUser,
  2876. "patientInfo": patientInfo,
  2877. "PredialysisEvaluation": PredialysisEvaluation,
  2878. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  2879. "dialysisPrescription": dialysisPrescription,
  2880. "advices": DoctorAdvice,
  2881. "monitors": Record,
  2882. "summary": TreatmentSummary,
  2883. "receiverTreatmentAccess": receiverTreatmentAccess,
  2884. "dialysisOrder": dialysisOrder,
  2885. "operators": operators,
  2886. "org_template_info": templateInfo,
  2887. "check": check,
  2888. "dialysiscount": dialysiscount,
  2889. "last_order": last_order,
  2890. "projects": projects,
  2891. "project_config": project_config,
  2892. })
  2893. }
  2894. }
  2895. func (c *PatientApiController) CreateGroupAdvice() {
  2896. is_child, _ := c.GetInt64("is_child", 0)
  2897. if is_child == 1 {
  2898. patient, _ := c.GetInt64("id", 0)
  2899. if patient <= 0 {
  2900. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2901. return
  2902. }
  2903. adminUserInfo := c.GetMobileAdminUserInfo()
  2904. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  2905. if patientInfo.ID == 0 {
  2906. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2907. return
  2908. }
  2909. group_no, _ := c.GetInt64("group_no")
  2910. if group_no <= 0 {
  2911. group_no = 0
  2912. }
  2913. dataBody := make(map[string]interface{}, 0)
  2914. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2915. if err != nil {
  2916. utils.ErrorLog(err.Error())
  2917. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2918. return
  2919. }
  2920. timeLayout := "2006-01-02"
  2921. loc, _ := time.LoadLocation("Local")
  2922. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2923. utils.ErrorLog("advice_type")
  2924. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2925. return
  2926. }
  2927. adviceType := int64(dataBody["advice_type"].(float64))
  2928. if adviceType != 1 && adviceType != 2 {
  2929. utils.ErrorLog("advice_type != 1&&2")
  2930. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2931. return
  2932. }
  2933. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2934. utils.ErrorLog("start_time")
  2935. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2936. return
  2937. }
  2938. startTime2, _ := dataBody["start_time"].(string)
  2939. time_arr := strings.Split(startTime2, " ")
  2940. if len(time_arr) > 0 {
  2941. startTime2 = time_arr[0]
  2942. }
  2943. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2944. utils.ErrorLog("advice_date")
  2945. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2946. return
  2947. }
  2948. adviceDate := startTime2
  2949. if len(adviceDate) == 0 {
  2950. utils.ErrorLog("len(adviceDate) == 0")
  2951. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2952. return
  2953. }
  2954. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  2955. if err != nil {
  2956. utils.ErrorLog(err.Error())
  2957. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2958. return
  2959. }
  2960. AdviceDate := theTime.Unix()
  2961. RecordDate := theTime.Unix()
  2962. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2963. utils.ErrorLog("start_time")
  2964. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2965. return
  2966. }
  2967. startTime, _ := dataBody["start_time"].(string)
  2968. if len(startTime) == 0 {
  2969. utils.ErrorLog("len(start_time) == 0")
  2970. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2971. return
  2972. }
  2973. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  2974. if err != nil {
  2975. utils.ErrorLog(err.Error())
  2976. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2977. return
  2978. }
  2979. StartTime := theTime.Unix()
  2980. Remark := ""
  2981. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2982. remark, _ := dataBody["remark"].(string)
  2983. Remark = remark
  2984. }
  2985. var advices []*models.GroupAdvice
  2986. // utils.TraceLog("%+v", dataBody["adviceNames"])
  2987. if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
  2988. utils.ErrorLog("adviceNames")
  2989. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2990. return
  2991. }
  2992. adviceNames := dataBody["adviceNames"].([]interface{})
  2993. for _, adviceNameMap := range adviceNames {
  2994. adviceNameM := adviceNameMap.(map[string]interface{})
  2995. var advice models.GroupAdvice
  2996. advice.Remark = Remark
  2997. advice.AdviceType = adviceType
  2998. advice.StartTime = StartTime
  2999. advice.AdviceDate = AdviceDate
  3000. advice.RecordDate = RecordDate
  3001. advice.Status = 1
  3002. advice.CreatedTime = time.Now().Unix()
  3003. advice.UpdatedTime = time.Now().Unix()
  3004. advice.StopState = 2
  3005. advice.ExecutionState = 2
  3006. advice.UserOrgId = adminUserInfo.Org.Id
  3007. advice.PatientId = patientInfo.ID
  3008. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  3009. //入口
  3010. errcode := c.setAdviceWithJSON(&advice, adviceNameM)
  3011. if errcode > 0 {
  3012. c.ServeFailJSONWithSGJErrorCode(errcode)
  3013. return
  3014. }
  3015. if adviceNameM["subdrugs"] != nil && reflect.TypeOf(adviceNameM["subdrugs"]).String() == "[]interface {}" {
  3016. subdrugs := adviceNameM["subdrugs"].([]interface{})
  3017. if len(subdrugs) > 0 {
  3018. for _, subdrug := range subdrugs {
  3019. var s models.GroupAdvice
  3020. s.Remark = Remark
  3021. s.AdviceType = adviceType
  3022. s.StartTime = StartTime
  3023. s.AdviceDate = AdviceDate
  3024. s.RecordDate = RecordDate
  3025. s.Status = 1
  3026. s.CreatedTime = time.Now().Unix()
  3027. s.UpdatedTime = time.Now().Unix()
  3028. s.StopState = 2
  3029. s.ExecutionState = 2
  3030. s.UserOrgId = adminUserInfo.Org.Id
  3031. s.PatientId = patientInfo.ID
  3032. s.AdviceDoctor = adminUserInfo.AdminUser.Id
  3033. errcode := c.setAdviceWithJSON(&s, subdrug.(map[string]interface{}))
  3034. if errcode > 0 {
  3035. c.ServeFailJSONWithSGJErrorCode(errcode)
  3036. return
  3037. }
  3038. advice.Children = append(advice.Children, &s)
  3039. }
  3040. }
  3041. }
  3042. advices = append(advices, &advice)
  3043. }
  3044. newAdvices, createErr := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, group_no)
  3045. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  3046. redis := service.RedisClient()
  3047. //清空key 值
  3048. redis.Set(key, "", time.Second)
  3049. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  3050. redis.Set(keyOne, "", time.Second)
  3051. defer redis.Close()
  3052. if createErr != nil {
  3053. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  3054. return
  3055. }
  3056. c.ServeSuccessJSON(map[string]interface{}{
  3057. "msg": "ok",
  3058. "advices": newAdvices,
  3059. })
  3060. return
  3061. } else if is_child == 2 {
  3062. patient, _ := c.GetInt64("id", 0)
  3063. if patient <= 0 {
  3064. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3065. return
  3066. }
  3067. adminUserInfo := c.GetMobileAdminUserInfo()
  3068. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  3069. if patientInfo.ID == 0 {
  3070. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3071. return
  3072. }
  3073. var advice models.DoctorAdvice
  3074. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  3075. if code > 0 {
  3076. c.ServeFailJSONWithSGJErrorCode(code)
  3077. return
  3078. }
  3079. if advice.ParentId > 0 {
  3080. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  3081. if old.ID == 0 || old.PatientId != patient {
  3082. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  3083. return
  3084. }
  3085. if old.StopState == 1 || old.ExecutionState == 1 {
  3086. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  3087. return
  3088. }
  3089. if old.ParentId > 0 {
  3090. advice.ParentId = old.ParentId
  3091. }
  3092. advice.StartTime = old.StartTime
  3093. advice.AdviceDoctor = old.AdviceDoctor
  3094. advice.DeliveryWay = old.DeliveryWay
  3095. advice.ExecutionFrequency = old.ExecutionFrequency
  3096. advice.GroupNo = old.GroupNo
  3097. }
  3098. advice.Status = 1
  3099. advice.CreatedTime = time.Now().Unix()
  3100. advice.UpdatedTime = time.Now().Unix()
  3101. advice.StopState = 2
  3102. advice.ExecutionState = 2
  3103. advice.UserOrgId = adminUserInfo.Org.Id
  3104. advice.PatientId = patient
  3105. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  3106. err := service.CreateDoctorAdvice(&advice)
  3107. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3108. redis := service.RedisClient()
  3109. //清空key 值
  3110. redis.Set(key, "", time.Second)
  3111. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3112. redis.Set(keyOne, "", time.Second)
  3113. fmt.Println("key`2232333332233223233232", key)
  3114. defer redis.Close()
  3115. if err != nil {
  3116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  3117. return
  3118. }
  3119. c.ServeSuccessJSON(map[string]interface{}{
  3120. "msg": "ok",
  3121. "advice": advice,
  3122. })
  3123. return
  3124. }
  3125. }
  3126. func (c *PatientApiController) setAdviceWithJSON(advice *models.GroupAdvice, json map[string]interface{}) int {
  3127. if json["advice_name"] == nil || reflect.TypeOf(json["advice_name"]).String() != "string" {
  3128. utils.ErrorLog("advice_name")
  3129. return enums.ErrorCodeParamWrong
  3130. }
  3131. adviceName, _ := json["advice_name"].(string)
  3132. if len(adviceName) == 0 {
  3133. utils.ErrorLog("len(advice_name) == 0")
  3134. return enums.ErrorCodeParamWrong
  3135. }
  3136. advice.AdviceName = adviceName
  3137. adviceDesc, _ := json["advice_desc"].(string)
  3138. advice.AdviceDesc = adviceDesc
  3139. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  3140. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  3141. advice.DrugSpec = drugSpec
  3142. }
  3143. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3144. remark, _ := json["remark"].(string)
  3145. advice.Remark = remark
  3146. }
  3147. //if json["src_type"] != nil || reflect.TypeOf(json["src_type"]).String() == "float64" {
  3148. // src_type, _ := strconv.ParseInt(json["src_type"].(string),10)
  3149. // advice.Way = src_type
  3150. //}
  3151. if json["way"] == nil {
  3152. advice.Way = 0
  3153. } else {
  3154. if json["way"] != nil || reflect.TypeOf(json["way"]).String() == "float64" {
  3155. way := int64(json["way"].(float64))
  3156. advice.Way = way
  3157. }
  3158. }
  3159. if json["drug_id"] == nil {
  3160. advice.DrugId = 0
  3161. } else {
  3162. if json["drug_id"] != nil || reflect.TypeOf(json["drug_id"]).String() == "float64" {
  3163. drug_id := int64(json["drug_id"].(float64))
  3164. advice.DrugId = drug_id
  3165. }
  3166. }
  3167. if json["drug_name_id"] == nil {
  3168. advice.DrugNameId = 0
  3169. } else {
  3170. if json["drug_name_id"] != nil || reflect.TypeOf(json["drug_name_id"]).String() == "float64" {
  3171. drug_name_id := int64(json["drug_name_id"].(float64))
  3172. advice.DrugNameId = drug_name_id
  3173. }
  3174. }
  3175. if json["drug_spec_unit"] != nil && reflect.TypeOf(json["drug_spec_unit"]).String() == "string" {
  3176. drugSpecUnit, _ := json["drug_spec_unit"].(string)
  3177. advice.DrugSpecUnit = drugSpecUnit
  3178. }
  3179. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3180. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3181. advice.SingleDose = singleDose
  3182. }
  3183. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3184. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3185. advice.SingleDoseUnit = singleDoseUnit
  3186. }
  3187. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3188. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3189. advice.PrescribingNumber = prescribingNumber
  3190. }
  3191. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3192. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3193. advice.PrescribingNumberUnit = prescribingNumberUnit
  3194. }
  3195. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3196. deliveryWay, _ := json["delivery_way"].(string)
  3197. advice.DeliveryWay = deliveryWay
  3198. }
  3199. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3200. executionFrequency, _ := json["execution_frequency"].(string)
  3201. advice.ExecutionFrequency = executionFrequency
  3202. }
  3203. return 0
  3204. }
  3205. func (c *PatientApiController) DelDoctorAdvice() {
  3206. groupno, _ := c.GetInt64("groupno", -1)
  3207. is_sub, _ := c.GetInt64("is_sub", -1) //是否子药
  3208. patient_id, _ := c.GetInt64("patient_id")
  3209. doc_advice_date, _ := c.GetInt64("advice_date")
  3210. redis := service.RedisClient()
  3211. if is_sub == 1 { //是
  3212. advice_id, _ := c.GetInt64("advice_id")
  3213. adminUserInfo := c.GetMobileAdminUserInfo()
  3214. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  3215. if advice.ID == 0 {
  3216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3217. return
  3218. }
  3219. advice.Status = 0
  3220. advice.UpdatedTime = time.Now().Unix()
  3221. advice.Modifier = adminUserInfo.AdminUser.Id
  3222. err := service.DeleteDoctorAdvice(&advice)
  3223. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  3224. redis.Set(key, "", time.Second)
  3225. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  3226. redis.Set(keyTwo, "", time.Second)
  3227. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  3228. redis.Set(keyThree, "", time.Second)
  3229. redis.Close()
  3230. if err != nil {
  3231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  3232. return
  3233. }
  3234. c.ServeSuccessJSON(map[string]interface{}{
  3235. "msg": "ok",
  3236. })
  3237. return
  3238. } else { //
  3239. var ids []string
  3240. if groupno == 0 {
  3241. advice_id := c.GetString("advice_id")
  3242. ids = strings.Split(advice_id, ",")
  3243. if len(ids) <= 0 {
  3244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3245. return
  3246. }
  3247. }
  3248. if groupno < 0 {
  3249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3250. return
  3251. }
  3252. adminUserInfo := c.GetMobileAdminUserInfo()
  3253. var advice models.DoctorAdvice
  3254. if groupno > 0 {
  3255. advice, _ = service.FindDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  3256. if advice.ID == 0 {
  3257. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3258. return
  3259. }
  3260. } else {
  3261. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  3262. for _, item := range advices {
  3263. if item.ID == 0 {
  3264. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3265. return
  3266. }
  3267. }
  3268. }
  3269. advice.UpdatedTime = time.Now().Unix()
  3270. advice.Status = 0
  3271. advice.GroupNo = groupno
  3272. advice.Modifier = adminUserInfo.AdminUser.Id
  3273. var err error
  3274. if groupno > 0 {
  3275. err = service.DeleteDoctorAdviceByGroupNo(&advice)
  3276. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  3277. fmt.Println("key2332323223323232323232323", key)
  3278. redis.Set(key, "", time.Second)
  3279. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  3280. redis.Set(keyTwo, "", time.Second)
  3281. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  3282. redis.Set(keyThree, "", time.Second)
  3283. } else {
  3284. err = service.BatchDeleteDoctorAdvice(ids, adminUserInfo.AdminUser.Id)
  3285. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  3286. redis.Set(key, "", time.Second)
  3287. fmt.Println("key2332323223323232323232323", key)
  3288. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  3289. fmt.Println("key2332323223323232323232323", keyTwo)
  3290. redis.Set(keyTwo, "", time.Second)
  3291. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  3292. redis.Set(keyThree, "", time.Second)
  3293. redis.Close()
  3294. }
  3295. if err != nil {
  3296. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  3297. return
  3298. }
  3299. c.ServeSuccessJSON(map[string]interface{}{
  3300. "msg": "ok",
  3301. })
  3302. return
  3303. }
  3304. }
  3305. // /m/api/advice/group/modify_starttime [post]
  3306. // @param group_no:int
  3307. // @param start_time:string yyyy-MM-dd hh:mm:ss
  3308. func (this *PatientApiController) ModifyAdviceGroupStartTime() {
  3309. group_no, _ := this.GetInt64("group_no")
  3310. start_time_str := this.GetString("start_time")
  3311. if group_no <= 0 || len(start_time_str) == 0 {
  3312. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3313. return
  3314. }
  3315. startTime, parseTimeErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time_str)
  3316. if parseTimeErr != nil {
  3317. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  3318. return
  3319. }
  3320. adminUserInfo := this.GetMobileAdminUserInfo()
  3321. updateStartTimeErr := service.UpdateAdviceGroupStartTime(adminUserInfo.Org.Id, group_no, startTime.Unix(), adminUserInfo.AdminUser.Id)
  3322. if updateStartTimeErr != nil {
  3323. utils.ErrorLog("修改医嘱分组的开始时间失败:%v", updateStartTimeErr)
  3324. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3325. return
  3326. }
  3327. this.ServeSuccessJSON(map[string]interface{}{
  3328. "start_time": startTime.Unix(),
  3329. })
  3330. }
  3331. func (this *PatientApiController) DelSubDoctorAdvice() {
  3332. advice_id, _ := this.GetInt64("advice_id")
  3333. adminUserInfo := this.GetMobileAdminUserInfo()
  3334. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  3335. if advice.ID == 0 {
  3336. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3337. return
  3338. }
  3339. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  3340. // this.ServeFailJSONWithSGJErrorCode(enums. bh)
  3341. // return
  3342. //}
  3343. advice.Status = 0
  3344. advice.UpdatedTime = time.Now().Unix()
  3345. advice.Modifier = adminUserInfo.AdminUser.Id
  3346. err := service.DeleteDoctorAdvice(&advice)
  3347. if err != nil {
  3348. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  3349. return
  3350. }
  3351. this.ServeSuccessJSON(map[string]interface{}{
  3352. "msg": "ok",
  3353. })
  3354. return
  3355. }
  3356. func (this *PatientApiController) GetAdviceUnReadMessage() {
  3357. //adminUserInfo := this.GetMobileAdminUserInfo()
  3358. //service.FindUnReadDoctorAdviceMessage()
  3359. }
  3360. func (this *PatientApiController) GetPatientsByKeyWord() {
  3361. keyWord := this.GetString("keyword")
  3362. adminUserInfo := this.GetMobileAdminUserInfo()
  3363. today := utils.ZeroHourTimeOfDay(time.Now())
  3364. patient, err := service.GetSchedualPatientByKeyWord(adminUserInfo.Org.Id, keyWord, today.Unix())
  3365. if err != nil {
  3366. utils.ErrorLog(err.Error())
  3367. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3368. return
  3369. }
  3370. this.ServeSuccessJSON(map[string]interface{}{
  3371. "patient": patient,
  3372. })
  3373. }
  3374. func (this *PatientApiController) GetSearchPatient() {
  3375. keyWord := this.GetString("keyword")
  3376. adminUserInfo := this.GetMobileAdminUserInfo()
  3377. patient, err := service.GetPatientsByKey(adminUserInfo.Org.Id, keyWord)
  3378. if err != nil {
  3379. utils.ErrorLog(err.Error())
  3380. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3381. return
  3382. }
  3383. this.ServeSuccessJSON(map[string]interface{}{
  3384. "patient": patient,
  3385. })
  3386. }
  3387. func (c *PatientApiController) ExecProject() {
  3388. execution_time := c.GetString("execution_time")
  3389. project_id, _ := c.GetInt64("project_id")
  3390. team_id, _ := c.GetInt64("team_id")
  3391. is_check_team, _ := c.GetInt64("is_check_team")
  3392. if len(execution_time) <= 0 {
  3393. utils.ErrorLog("execution_time")
  3394. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3395. return
  3396. }
  3397. timeLayout2 := "2006-01-02 15:04:05"
  3398. loc, _ := time.LoadLocation("Local")
  3399. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  3400. if errs != nil {
  3401. utils.ErrorLog(errs.Error())
  3402. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3403. return
  3404. }
  3405. adminInfo := c.GetMobileAdminUserInfo()
  3406. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  3407. if project.ExecutionState == 1 {
  3408. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  3409. return
  3410. }
  3411. if project.Checker >= 0 && project.Checker == adminInfo.AdminUser.Id {
  3412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  3413. return
  3414. }
  3415. project.ExecutionState = 1
  3416. project.ExecutionStaff = adminInfo.AdminUser.Id
  3417. project.ExecutionTime = theTime.Unix()
  3418. if team_id == 0 {
  3419. err := service.SaveHisProject(&project)
  3420. if err == nil {
  3421. c.ServeSuccessJSON(map[string]interface{}{
  3422. "project": project,
  3423. })
  3424. } else {
  3425. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3426. return
  3427. }
  3428. } else {
  3429. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  3430. err := service.SaveHisProject(&project)
  3431. if err == nil {
  3432. c.ServeSuccessJSON(map[string]interface{}{
  3433. "project": project,
  3434. })
  3435. } else {
  3436. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3437. return
  3438. }
  3439. } else {
  3440. ps, _ := service.GetCheckTeamProject(team_id, project.PatientId, project.RecordDate, project.UserOrgId)
  3441. var ids []int64
  3442. for _, items := range ps {
  3443. ids = append(ids, items.ID)
  3444. }
  3445. err := service.UpdateTeamProjectExceStatus(ids, adminInfo.AdminUser.Id, theTime.Unix())
  3446. if err == nil {
  3447. c.ServeSuccessJSON(map[string]interface{}{
  3448. "project": project,
  3449. })
  3450. } else {
  3451. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3452. return
  3453. }
  3454. }
  3455. }
  3456. }
  3457. func (c *PatientApiController) CheckProject() {
  3458. adminInfo := c.GetMobileAdminUserInfo()
  3459. project_id, _ := c.GetInt64("project_id")
  3460. team_id, _ := c.GetInt64("team_id")
  3461. is_check_team, _ := c.GetInt64("is_check_team")
  3462. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  3463. if project.CheckState == 1 {
  3464. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  3465. return
  3466. }
  3467. if project.ExecutionStaff >= 0 && project.ExecutionStaff == adminInfo.AdminUser.Id {
  3468. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  3469. return
  3470. }
  3471. project.Checker = adminInfo.AdminUser.Id
  3472. project.CheckTime = time.Now().Unix()
  3473. project.CheckState = 1
  3474. if team_id == 0 {
  3475. err := service.SaveHisProject(&project)
  3476. if err == nil {
  3477. c.ServeSuccessJSON(map[string]interface{}{
  3478. "msg": "ok",
  3479. "project": project,
  3480. })
  3481. } else {
  3482. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3483. return
  3484. }
  3485. } else {
  3486. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  3487. err := service.SaveHisProject(&project)
  3488. if err == nil {
  3489. c.ServeSuccessJSON(map[string]interface{}{
  3490. "msg": "ok",
  3491. "project": project,
  3492. })
  3493. } else {
  3494. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3495. return
  3496. }
  3497. } else {
  3498. ps, _ := service.GetCheckTeamProject(team_id, project.PatientId, project.RecordDate, project.UserOrgId)
  3499. var ids []int64
  3500. for _, items := range ps {
  3501. ids = append(ids, items.ID)
  3502. }
  3503. err := service.UpdateTeamProjectCheckStatus(ids, project.PatientId, project.RecordDate, project.UserOrgId, adminInfo.AdminUser.Id, time.Now().Unix())
  3504. if err == nil {
  3505. c.ServeSuccessJSON(map[string]interface{}{
  3506. "project": project,
  3507. })
  3508. } else {
  3509. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3510. return
  3511. }
  3512. }
  3513. }
  3514. }