patient_api_controller.go 150KB

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