patient_api_controller.go 184KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203
  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. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  272. if infor.ID > 0 {
  273. var cha_time int64
  274. timeNowStr := time.Now().Format("2006-01-02")
  275. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  276. //今日的日期减去设置的日期
  277. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  278. if cha_time >= sourceAdvice.AdviceDate {
  279. //查询审核是否允许
  280. infor, _ := service.GetDialysisInformationByRecordDate(id, sourceAdvice.AdviceDate, adminUserInfo.Org.Id)
  281. //申请状态不允许的情况 拒绝修改
  282. if infor.ApplicationStatus != 1 {
  283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  284. return
  285. }
  286. }
  287. }
  288. //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要修改子医嘱的开始时间,如果相同直接修改,不需要修改子医嘱的开始时间
  289. if advice.StartTime == sourceAdvice.StartTime {
  290. err = service.UpdateDoctorAdvice(&advice)
  291. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  292. defer redis.Close()
  293. redis.Set(key, "", time.Second)
  294. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":advice_list_all"
  295. redis.Set(keyOne, "", time.Second)
  296. isChangeGroup = false
  297. } else {
  298. err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
  299. isChangeGroup = false
  300. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  301. defer redis.Close()
  302. redis.Set(key, "", time.Second)
  303. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  304. redis.Set(keyOne, "", time.Second)
  305. }
  306. } else if len(adviceSlice) > 1 {
  307. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  308. if infor.ID > 0 {
  309. var cha_time int64
  310. timeNowStr := time.Now().Format("2006-01-02")
  311. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  312. //今日的日期减去设置的日期
  313. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  314. if cha_time >= sourceAdvice.AdviceDate {
  315. //查询审核是否允许
  316. infor, _ := service.GetDialysisInformationByRecordDate(id, sourceAdvice.AdviceDate, adminUserInfo.Org.Id)
  317. //申请状态不允许的情况 拒绝修改
  318. if infor.ApplicationStatus != 1 {
  319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  320. return
  321. }
  322. }
  323. }
  324. //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要重新分配组,如果相同直接修改,不需要分配组
  325. if advice.StartTime == sourceAdvice.StartTime {
  326. err = service.UpdateDoctorAdvice(&advice)
  327. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  328. defer redis.Close()
  329. redis.Set(key, "", time.Second)
  330. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  331. redis.Set(keyOne, "", time.Second)
  332. isChangeGroup = false
  333. } else {
  334. gruopNo := service.GetMaxAdviceGroupID(adminUserInfo.Org.Id)
  335. gruopNo = gruopNo + 1
  336. advice.GroupNo = gruopNo
  337. err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
  338. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  339. defer redis.Close()
  340. redis.Set(key, "", time.Second)
  341. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  342. redis.Set(keyOne, "", time.Second)
  343. isChangeGroup = true
  344. }
  345. }
  346. } else {
  347. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  348. if infor.ID > 0 {
  349. var cha_time int64
  350. timeNowStr := time.Now().Format("2006-01-02")
  351. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  352. //今日的日期减去设置的日期
  353. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  354. if cha_time >= advice.AdviceDate {
  355. //查询审核是否允许
  356. infor, _ := service.GetDialysisInformationByRecordDate(id, advice.AdviceDate, adminUserInfo.Org.Id)
  357. //申请状态不允许的情况 拒绝修改
  358. if infor.ApplicationStatus != 1 {
  359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  360. return
  361. }
  362. }
  363. }
  364. isChangeGroup = false
  365. err = service.UpdateDoctorAdvice(&advice)
  366. redis := service.RedisClient()
  367. defer redis.Close()
  368. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  369. redis.Set(key, "", time.Second)
  370. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  371. redis.Set(keyOne, "", time.Second)
  372. }
  373. if err != nil {
  374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  375. return
  376. }
  377. if !isChangeGroup {
  378. c.ServeSuccessJSON(map[string]interface{}{
  379. "msg": "ok",
  380. "advice": advice,
  381. "isChange": isChangeGroup, //方便前端处理数据
  382. })
  383. } else {
  384. newGroupAdvice, err := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
  385. if err != nil {
  386. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  387. return
  388. }
  389. c.ServeSuccessJSON(map[string]interface{}{
  390. "msg": "ok",
  391. "advice": newGroupAdvice,
  392. "isChange": isChangeGroup, //方便前端处理数据
  393. })
  394. }
  395. return
  396. }
  397. func (c *PatientApiController) StopDoctorAdvice() {
  398. id, _ := c.GetInt64("id", 0)
  399. if id <= 0 {
  400. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  401. return
  402. }
  403. adminUserInfo := c.GetMobileAdminUserInfo()
  404. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  405. if advice.ID == 0 {
  406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  407. return
  408. }
  409. //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  410. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  411. // return
  412. //}
  413. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  414. //
  415. //if appRole.UserType == 3 {
  416. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  417. // if getPermissionErr != nil {
  418. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  419. // return
  420. // } else if headNursePermission == nil {
  421. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  422. // return
  423. // }
  424. //}
  425. if advice.StopState == 1 {
  426. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  427. return
  428. }
  429. dataBody := make(map[string]interface{}, 0)
  430. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  431. if err != nil {
  432. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  433. return
  434. }
  435. timeLayout := "2006-01-02"
  436. loc, _ := time.LoadLocation("Local")
  437. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  438. utils.ErrorLog("stop_time")
  439. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  440. return
  441. }
  442. stopTime, _ := dataBody["stop_time"].(string)
  443. if len(stopTime) == 0 {
  444. utils.ErrorLog("len(stop_time) == 0")
  445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  446. return
  447. }
  448. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  449. if err != nil {
  450. utils.ErrorLog(err.Error())
  451. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  452. return
  453. }
  454. advice.StopTime = theTime.Unix()
  455. if dataBody["stop_reason"] == nil || reflect.TypeOf(dataBody["stop_reason"]).String() != "string" {
  456. utils.ErrorLog("stop_reason")
  457. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  458. return
  459. }
  460. stopReason, _ := dataBody["stop_reason"].(string)
  461. if len(stopReason) == 0 {
  462. utils.ErrorLog("len(stop_reason) == 0")
  463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  464. return
  465. }
  466. advice.StopReason = stopReason
  467. advice.Status = 1
  468. advice.UpdatedTime = time.Now().Unix()
  469. advice.StopDoctor = adminUserInfo.AdminUser.Id
  470. advice.StopState = 1
  471. advice.StopTime = time.Now().Unix()
  472. advice.Modifier = adminUserInfo.AdminUser.Id
  473. err = service.StopDoctorAdvice(&advice)
  474. if err != nil {
  475. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  476. return
  477. }
  478. c.ServeSuccessJSON(map[string]interface{}{
  479. "msg": "ok",
  480. "advice": advice,
  481. })
  482. return
  483. }
  484. func (c *PatientApiController) DeleteDoctorAdvice() {
  485. id, _ := c.GetInt64("id", 0)
  486. if id <= 0 {
  487. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  488. return
  489. }
  490. adminUserInfo := c.GetMobileAdminUserInfo()
  491. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  492. if advice.ID == 0 {
  493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  494. return
  495. }
  496. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  497. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  498. // return
  499. //}
  500. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  501. //
  502. //if appRole.UserType == 3 {
  503. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  504. // if getPermissionErr != nil {
  505. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  506. // return
  507. // } else if headNursePermission == nil {
  508. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  509. // return
  510. // }
  511. //}
  512. advice.UpdatedTime = time.Now().Unix()
  513. advice.Status = 0
  514. advice.Modifier = adminUserInfo.AdminUser.Id
  515. err := service.DeleteDoctorAdvice(&advice)
  516. if err != nil {
  517. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  518. return
  519. }
  520. c.ServeSuccessJSON(map[string]interface{}{
  521. "msg": "ok",
  522. })
  523. return
  524. }
  525. func (c *PatientApiController) ExecDoctorAdvice() {
  526. execution_time := c.GetString("execution_time")
  527. origin, _ := c.GetInt64("origin", 0)
  528. groupno, _ := c.GetInt64("groupno", -1)
  529. fmt.Println("orgind===2=323322323232323", origin)
  530. fmt.Println("groupno233333333333333333333", groupno)
  531. if origin != 2 {
  532. adminUserInfo := c.GetMobileAdminUserInfo()
  533. execution_staff := adminUserInfo.AdminUser.Id
  534. var ids []string
  535. advice_ids := c.GetString("advice_id")
  536. if groupno == 0 {
  537. ids = strings.Split(advice_ids, ",")
  538. }
  539. if groupno < 0 {
  540. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  541. return
  542. }
  543. if len(execution_time) <= 0 {
  544. utils.ErrorLog("execution_time")
  545. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  546. return
  547. }
  548. timeLayout2 := "2006-01-02 15:04:05"
  549. loc, _ := time.LoadLocation("Local")
  550. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  551. if errs != nil {
  552. utils.ErrorLog(errs.Error())
  553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  554. return
  555. }
  556. var advice models.DoctorAdvice
  557. if groupno > 0 {
  558. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  559. for _, item := range advices {
  560. if item.ExecutionState == 2 {
  561. advice = item
  562. }
  563. }
  564. } else {
  565. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  566. for _, item := range advices {
  567. if item.ExecutionState == 2 {
  568. advice = item
  569. }
  570. }
  571. }
  572. if advice.ExecutionState == 1 {
  573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  574. return
  575. }
  576. if advice.Checker >= 0 && advice.Checker == adminUserInfo.AdminUser.Id {
  577. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  578. return
  579. }
  580. if advice.StartTime > theTime.Unix() {
  581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  582. return
  583. }
  584. advices := models.DoctorAdvice{
  585. ExecutionStaff: execution_staff,
  586. ExecutionTime: theTime.Unix(),
  587. UpdatedTime: time.Now().Unix(),
  588. }
  589. var err error
  590. fmt.Println("groupno==============", groupno)
  591. if groupno > 0 {
  592. // 查询信息规挡的设置天数
  593. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  594. if infor.ID > 0 {
  595. var cha_time int64
  596. timeNowStr := time.Now().Format("2006-01-02")
  597. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  598. //今日的日期减去设置的日期
  599. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  600. if cha_time >= advices.AdviceDate {
  601. //查询审核是否允许
  602. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id)
  603. //申请状态不允许的情况 拒绝修改
  604. if infor.ApplicationStatus != 1 {
  605. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  606. return
  607. }
  608. }
  609. }
  610. err = service.ExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  611. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  612. redis := service.RedisClient()
  613. //清空key 值
  614. redis.Set(key, "", time.Second)
  615. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  616. redis.Set(keyTwo, "", time.Second)
  617. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  618. redis.Set(keyThree, "", time.Second)
  619. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
  620. theTime := toTime.Format("2006-01-02")
  621. fmt.Println("theTIME", theTime)
  622. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  623. redis.Set(keyFour, "", time.Second)
  624. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  625. redis.Set(keyFive, "", time.Second)
  626. defer redis.Close()
  627. } else {
  628. // 查询信息规挡的设置天数
  629. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  630. if infor.ID > 0 {
  631. var cha_time int64
  632. timeNowStr := time.Now().Format("2006-01-02")
  633. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  634. //今日的日期减去设置的日期
  635. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  636. if cha_time >= advices.AdviceDate {
  637. //查询审核是否允许
  638. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id)
  639. //申请状态不允许的情况 拒绝修改
  640. if infor.ApplicationStatus != 1 {
  641. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  642. return
  643. }
  644. }
  645. }
  646. err = service.BatchExceOldDoctorAdvice(&advices, ids)
  647. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  648. redis := service.RedisClient()
  649. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  650. redis.Set(keyTwo, "", time.Second)
  651. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  652. redis.Set(keyThree, "", time.Second)
  653. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
  654. theTime := toTime.Format("2006-01-02")
  655. fmt.Println("theTIME", theTime)
  656. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  657. redis.Set(keyFour, "", time.Second)
  658. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  659. redis.Set(keySix, "", time.Second)
  660. defer redis.Close()
  661. //清空key 值
  662. redis.Set(key, "", time.Second)
  663. }
  664. if err != nil {
  665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  666. return
  667. }
  668. advice.ExecutionStaff = execution_staff
  669. advice.ExecutionTime = theTime.Unix()
  670. advice.ExecutionState = 1
  671. advice.Modifier = adminUserInfo.AdminUser.Id
  672. //处理出库相关逻辑
  673. //1.判断是否启用药品管理和自备药出库功能
  674. //药品管理信息
  675. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
  676. //自备药信息
  677. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.Org.Id)
  678. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.Org.Id)
  679. if drugStockConfig.IsOpen == 1 {
  680. if groupno > 0 {
  681. advices, _ := service.FindAllDoctorAdviceByGoroupNoTwety(adminUserInfo.Org.Id, groupno)
  682. if len(advices) > 0 {
  683. var total int64
  684. var prescribing_number_total int64
  685. //出库
  686. for _, item := range advices {
  687. if item.Way == 1 {
  688. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  689. //查询该药品的剩余库存
  690. list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  691. //查询改药品信息
  692. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  693. //判断单位是否相等
  694. if medical.MaxUnit == item.PrescribingNumberUnit {
  695. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  696. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  697. //转化为最小单位
  698. total = list.Count * medical.MinNumber
  699. prescribing_number_total = count * medical.MinNumber
  700. }
  701. if medical.MinUnit == item.PrescribingNumberUnit {
  702. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  703. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  704. total = list.Count*medical.MinNumber + list.StockMinNumber
  705. prescribing_number_total = count
  706. }
  707. if medical.IsUse == 1 {
  708. c.ServeSuccessJSON(map[string]interface{}{
  709. "msg": "1",
  710. "advice": advice,
  711. "ids": ids,
  712. })
  713. return
  714. }
  715. if medical.IsUse != 1 {
  716. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  717. if advice.UserOrgId != 10278 {
  718. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  719. advice.ExecutionTime = 0
  720. advice.ExecutionState = 2
  721. advice.ExecutionStaff = 0
  722. }
  723. c.ServeSuccessJSON(map[string]interface{}{
  724. "msg": "3",
  725. "advice": advice,
  726. "ids": ids,
  727. })
  728. return
  729. }
  730. if prescribing_number_total > total {
  731. if advice.UserOrgId != 10278 {
  732. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  733. advice.ExecutionTime = 0
  734. advice.ExecutionState = 2
  735. advice.ExecutionStaff = 0
  736. }
  737. c.ServeSuccessJSON(map[string]interface{}{
  738. "msg": "2",
  739. "advice": advice,
  740. "ids": ids,
  741. })
  742. return
  743. }
  744. }
  745. //查询是否出库按钮开启
  746. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  747. if adviceSetting.IsAdviceOpen == 1 {
  748. //查询是否出库按钮开启
  749. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  750. //患者发药
  751. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  752. if prescriptionConfig.IsOpen == 1 {
  753. if medical.IsUse == 2 {
  754. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  755. //查询今日是否出库
  756. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  757. if drugOutInfo.ID == 0 {
  758. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  759. }
  760. }
  761. if pharmacyConfig.IsOpen != 1 {
  762. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  763. if drugOutInfo.ID == 0 {
  764. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  765. }
  766. }
  767. //更新字典里面的库存
  768. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  769. var sum_count int64
  770. for _, its := range stockInfo {
  771. if its.MaxUnit == medical.MaxUnit {
  772. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  773. }
  774. sum_count += its.StockMaxNumber + its.StockMinNumber
  775. }
  776. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  777. //剩余库存
  778. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  779. }
  780. }
  781. } else {
  782. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  783. if medical.IsUse == 2 {
  784. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  785. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  786. if drugOutInfo.ID == 0 {
  787. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  788. }
  789. }
  790. if pharmacyConfig.IsOpen != 1 {
  791. drugError := models.XtDrugError{
  792. ID: 0,
  793. UserOrgId: item.UserOrgId,
  794. DrugId: item.DrugId,
  795. RecordDate: item.AdviceDate,
  796. PatientId: item.PatientId,
  797. Remark: "恒泰中医院出库开始",
  798. Status: 1,
  799. Ctime: time.Now().Unix(),
  800. Mtime: 0,
  801. Prescribingnumber: item.PrescribingNumber,
  802. PrescribingNumberUnit: item.PrescribingNumberUnit,
  803. SumCount: 0,
  804. }
  805. service.CreateDrugError(drugError)
  806. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  807. if drugOutInfo.ID == 0 {
  808. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  809. }
  810. }
  811. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  812. var sum_count int64
  813. for _, its := range stockInfo {
  814. if its.MaxUnit == medical.MaxUnit {
  815. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  816. }
  817. sum_count += its.StockMaxNumber + its.StockMinNumber
  818. }
  819. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  820. //剩余库存
  821. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  822. }
  823. }
  824. }
  825. }
  826. }
  827. c.ServeSuccessJSON(map[string]interface{}{
  828. "msg": "1",
  829. "advice": advice,
  830. "ids": ids,
  831. })
  832. return
  833. } else {
  834. advices, _ := service.FindDoctorAdviceByIdsTwety(adminUserInfo.Org.Id, ids)
  835. if len(advices) > 0 {
  836. var total int64
  837. var prescribing_number_total int64
  838. for _, item := range advices {
  839. if item.Way == 1 {
  840. //查询改药品信息
  841. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  842. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  843. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  844. //查询该药品的剩余库存
  845. list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  846. //判断单位是否相等
  847. if medical.MaxUnit == item.PrescribingNumberUnit {
  848. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  849. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  850. //转化为最小单位
  851. total = list.Count*medical.MinNumber + list.StockMinNumber
  852. prescribing_number_total = count * medical.MinNumber
  853. }
  854. if medical.MinUnit == item.PrescribingNumberUnit {
  855. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  856. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  857. total = list.Count*medical.MinNumber + list.StockMinNumber
  858. prescribing_number_total = count
  859. }
  860. if medical.IsUse == 1 {
  861. c.ServeSuccessJSON(map[string]interface{}{
  862. "msg": "1",
  863. "advice": advice,
  864. "ids": ids,
  865. })
  866. return
  867. }
  868. if medical.IsUse != 1 {
  869. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  870. if advice.UserOrgId != 10278 {
  871. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  872. advice.ExecutionTime = 0
  873. advice.ExecutionState = 2
  874. advice.ExecutionStaff = 0
  875. }
  876. c.ServeSuccessJSON(map[string]interface{}{
  877. "msg": "3",
  878. "advice": advice,
  879. "ids": ids,
  880. })
  881. return
  882. }
  883. if prescribing_number_total > total {
  884. if advice.UserOrgId != 10278 {
  885. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  886. advice.ExecutionTime = 0
  887. advice.ExecutionState = 2
  888. advice.ExecutionStaff = 0
  889. }
  890. c.ServeSuccessJSON(map[string]interface{}{
  891. "msg": "2",
  892. "advice": advice,
  893. "ids": ids,
  894. })
  895. return
  896. }
  897. }
  898. if medical.IsUse == 2 {
  899. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  900. //查询今日是否出库
  901. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  902. if drugOutInfo.ID == 0 {
  903. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  904. }
  905. }
  906. if pharmacyConfig.IsOpen != 1 {
  907. //查询今日是否出库
  908. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  909. if drugOutInfo.ID == 0 {
  910. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  911. }
  912. }
  913. //更新字典里面的库存
  914. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  915. var sum_count int64
  916. for _, its := range stockInfo {
  917. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  918. if its.MaxUnit == baseDrug.MaxUnit {
  919. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  920. }
  921. sum_count += its.StockMaxNumber + its.StockMinNumber
  922. }
  923. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  924. //剩余库存
  925. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  926. }
  927. if medical.IsUse == 1 {
  928. c.ServeSuccessJSON(map[string]interface{}{
  929. "msg": "1",
  930. "advice": advice,
  931. "ids": ids,
  932. })
  933. return
  934. }
  935. }
  936. }
  937. }
  938. c.ServeSuccessJSON(map[string]interface{}{
  939. "msg": "1",
  940. "advice": advice,
  941. "ids": ids,
  942. })
  943. return
  944. }
  945. }
  946. if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
  947. if groupno > 0 {
  948. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  949. for _, item := range advices {
  950. if item.ExecutionState == 1 && item.Way == 2 {
  951. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  952. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  953. timeStr := time.Now().Format("2006-01-02")
  954. timeArr := strings.Split(timeStr, "-")
  955. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
  956. total = total + 1
  957. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  958. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  959. number = number + total
  960. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  961. //插入自备药出库单
  962. outStock := models.XtSelfOutStock{
  963. DrugName: item.AdviceName,
  964. DrugNameId: item.DrugNameId,
  965. DrugSpec: item.AdviceDesc,
  966. OutstoreNumber: count,
  967. AdminUserId: adminUserInfo.AdminUser.Id,
  968. StorckTime: item.AdviceDate,
  969. UserOrgId: adminUserInfo.Org.Id,
  970. CreatedTime: time.Now().Unix(),
  971. Status: 1,
  972. PatientId: item.PatientId,
  973. ExitMode: 2,
  974. MedicId: item.DrugId,
  975. StockOutNumber: warehousing_out_order,
  976. }
  977. //查询 该患者是否已出库
  978. out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
  979. if errcode == gorm.ErrRecordNotFound {
  980. service.CreateOutStock(&outStock)
  981. } else if errcode == nil {
  982. err := service.UpdatedSelfOutSatock(out.ID, &outStock)
  983. fmt.Println("err", err)
  984. }
  985. }
  986. }
  987. } else {
  988. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  989. for _, item := range advices {
  990. if item.ExecutionState == 1 && item.Way == 2 {
  991. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  992. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  993. timeStr := time.Now().Format("2006-01-02")
  994. timeArr := strings.Split(timeStr, "-")
  995. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
  996. total = total + 1
  997. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  998. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  999. number = number + total
  1000. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1001. //插入自备药出库单
  1002. outStock := models.XtSelfOutStock{
  1003. DrugName: item.AdviceName,
  1004. DrugNameId: item.DrugNameId,
  1005. DrugSpec: item.AdviceDesc,
  1006. OutstoreNumber: count,
  1007. AdminUserId: adminUserInfo.AdminUser.Id,
  1008. StorckTime: item.AdviceDate,
  1009. UserOrgId: adminUserInfo.Org.Id,
  1010. CreatedTime: time.Now().Unix(),
  1011. Status: 1,
  1012. PatientId: item.PatientId,
  1013. ExitMode: 2,
  1014. MedicId: item.DrugId,
  1015. StockOutNumber: warehousing_out_order,
  1016. }
  1017. //查询 该患者是否已出库
  1018. out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
  1019. if errcode == gorm.ErrRecordNotFound {
  1020. service.CreateOutStock(&outStock)
  1021. } else if errcode == nil {
  1022. err := service.UpdatedSelfOutSatock(out.ID, &outStock)
  1023. fmt.Println("err", err)
  1024. }
  1025. }
  1026. }
  1027. c.ServeSuccessJSON(map[string]interface{}{
  1028. "msg": "1",
  1029. "advice": advice,
  1030. "ids": ids,
  1031. })
  1032. return
  1033. }
  1034. }
  1035. c.ServeSuccessJSON(map[string]interface{}{
  1036. "msg": "1",
  1037. "advice": advice,
  1038. "ids": ids,
  1039. })
  1040. return
  1041. } else if origin == 2 {
  1042. adminInfo := c.GetMobileAdminUserInfo()
  1043. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  1044. var ids []string
  1045. advice_ids := c.GetString("advice_id")
  1046. ids = strings.Split(advice_ids, ",")
  1047. if len(execution_time) <= 0 {
  1048. utils.ErrorLog("execution_time")
  1049. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1050. return
  1051. }
  1052. timeLayout2 := "2006-01-02 15:04:05"
  1053. loc, _ := time.LoadLocation("Local")
  1054. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  1055. if errs != nil {
  1056. utils.ErrorLog(errs.Error())
  1057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1058. return
  1059. }
  1060. advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
  1061. var err error
  1062. for _, item := range advices {
  1063. if item.ExecutionState == 1 {
  1064. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1065. return
  1066. }
  1067. if item.Checker >= 0 && item.Checker == adminInfo.AdminUser.Id {
  1068. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1069. return
  1070. }
  1071. if item.StartTime > theTime.Unix() {
  1072. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1073. return
  1074. }
  1075. item.ExecutionState = 1
  1076. item.ExecutionStaff = adminInfo.AdminUser.Id
  1077. item.ExecutionTime = theTime.Unix()
  1078. item.IsMobile = 1
  1079. // 查询信息规挡的设置天数
  1080. infor, _ := service.GetDialysisInformationSetting(item.UserOrgId)
  1081. if infor.ID > 0 {
  1082. var cha_time int64
  1083. timeNowStr := time.Now().Format("2006-01-02")
  1084. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1085. //今日的日期减去设置的日期
  1086. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1087. if cha_time >= item.AdviceDate {
  1088. //查询审核是否允许
  1089. infor, _ := service.GetDialysisInformationByRecordDate(item.PatientId, item.AdviceDate, item.UserOrgId)
  1090. //申请状态不允许的情况 拒绝修改
  1091. if infor.ApplicationStatus != 1 {
  1092. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1093. return
  1094. }
  1095. }
  1096. }
  1097. err = service.SaveHisDoctorAdvice(item)
  1098. if err == nil {
  1099. drugError := models.XtDrugError{
  1100. UserOrgId: adminInfo.Org.Id,
  1101. DrugId: item.DrugId,
  1102. RecordDate: item.AdviceDate,
  1103. PatientId: item.PatientId,
  1104. Remark: "执行成功",
  1105. Status: 1,
  1106. Ctime: time.Now().Unix(),
  1107. Mtime: 0,
  1108. SumCount: 0,
  1109. Prescribingnumber: item.PrescribingNumber,
  1110. PrescribingNumberUnit: item.PrescribingNumberUnit,
  1111. }
  1112. service.CreateDrugError(drugError)
  1113. }
  1114. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1115. redis := service.RedisClient()
  1116. //清空key 值
  1117. redis.Set(key, "", time.Second)
  1118. keyTwo := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1119. redis.Set(keyTwo, "", time.Second)
  1120. keyThree := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  1121. redis.Set(keyThree, "", time.Second)
  1122. recordDate := theTime.Format("2006-01-02")
  1123. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminInfo.Org.Id, 10)
  1124. redis.Set(keyFour, "", time.Second)
  1125. keyFive := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  1126. redis.Set(keyFive, "", time.Second)
  1127. defer redis.Close()
  1128. }
  1129. if err == nil {
  1130. //药品管理信息
  1131. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  1132. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  1133. if drugStockConfig.IsOpen == 1 {
  1134. for _, item := range advices {
  1135. //查询改药品信息
  1136. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  1137. //判断单位是否合格
  1138. if item.PrescribingNumberUnit != medical.MaxUnit && item.PrescribingNumberUnit != medical.MinUnit {
  1139. //查询该药品是否有出库记录
  1140. flowMap, _ := service.GetDrugFLowByAdviceById(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate)
  1141. if len(flowMap) == 0 {
  1142. errs := service.UpdateHisAdviceById(item.ID)
  1143. if errs != nil {
  1144. drugError := models.XtDrugError{
  1145. UserOrgId: adminInfo.Org.Id,
  1146. DrugId: item.DrugId,
  1147. RecordDate: item.AdviceDate,
  1148. PatientId: item.PatientId,
  1149. Remark: "单位不统一,执行失败",
  1150. Status: 1,
  1151. Ctime: time.Now().Unix(),
  1152. Mtime: 0,
  1153. SumCount: 0,
  1154. Prescribingnumber: item.PrescribingNumber,
  1155. PrescribingNumberUnit: item.PrescribingNumberUnit,
  1156. }
  1157. service.CreateDrugError(drugError)
  1158. }
  1159. }
  1160. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  1161. c.ServeSuccessJSON(map[string]interface{}{
  1162. "msg": "7",
  1163. "advice": advice,
  1164. "ids": ids,
  1165. })
  1166. return
  1167. }
  1168. //查询这个患者这个患者这个药已经出库的所有数量
  1169. advicelist, _ := service.GetAllHisDoctorAdviceById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  1170. drugoutlist, _ := service.GetAllDrugFlowById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  1171. var total_count int64
  1172. var drug_count int64
  1173. for _, it := range advicelist {
  1174. if it.PrescribingNumberUnit == medical.MaxUnit {
  1175. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1176. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1177. total_count += prenumber * medical.MinNumber
  1178. }
  1179. if it.PrescribingNumberUnit == medical.MinUnit {
  1180. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1181. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1182. total_count += prenumber
  1183. }
  1184. }
  1185. for _, its := range drugoutlist {
  1186. if its.CountUnit == medical.MaxUnit {
  1187. drug_count += its.Count * medical.MinNumber
  1188. }
  1189. if its.CountUnit == medical.MinUnit {
  1190. drug_count += its.Count
  1191. }
  1192. }
  1193. if total_count == drug_count {
  1194. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  1195. c.ServeSuccessJSON(map[string]interface{}{
  1196. "msg": "1",
  1197. "advice": advice,
  1198. "ids": ids,
  1199. })
  1200. return
  1201. }
  1202. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  1203. var total int64
  1204. var prescribing_number_total int64
  1205. config, _ := service.GetDrugOpenConfigOne(adminInfo.Org.Id)
  1206. if config.IsOpen != 1 {
  1207. //查询该药品是否有库存
  1208. houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  1209. list, _ := service.GetDrugTotalCount(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut)
  1210. //判断单位是否相等
  1211. if medical.MaxUnit == advice.PrescribingNumberUnit {
  1212. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1213. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1214. //转化为最小单位
  1215. total = list.Count*medical.MinNumber + list.StockMinNumber
  1216. prescribing_number_total = count * medical.MinNumber
  1217. }
  1218. //fmt.Println("医嘱开的数量", total)
  1219. if medical.MinUnit == advice.PrescribingNumberUnit {
  1220. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1221. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1222. total = list.Count*medical.MinNumber + list.StockMinNumber
  1223. prescribing_number_total = count
  1224. }
  1225. if medical.IsUse == 1 {
  1226. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1227. drugError := models.XtDrugError{
  1228. UserOrgId: adminInfo.Org.Id,
  1229. DrugId: item.DrugId,
  1230. RecordDate: item.AdviceDate,
  1231. PatientId: item.PatientId,
  1232. Remark: "零用药品库存不足",
  1233. Status: 1,
  1234. Ctime: time.Now().Unix(),
  1235. Mtime: 0,
  1236. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1237. Prescribingnumber: advice.PrescribingNumber,
  1238. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1239. }
  1240. service.CreateDrugError(drugError)
  1241. c.ServeSuccessJSON(map[string]interface{}{
  1242. "msg": "1",
  1243. "advice": advice,
  1244. "ids": ids,
  1245. })
  1246. return
  1247. }
  1248. }
  1249. if medical.IsUse != 1 {
  1250. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1251. drugError := models.XtDrugError{
  1252. UserOrgId: adminInfo.Org.Id,
  1253. DrugId: item.DrugId,
  1254. RecordDate: item.AdviceDate,
  1255. PatientId: item.PatientId,
  1256. Remark: "药品库存不足",
  1257. Status: 1,
  1258. Ctime: time.Now().Unix(),
  1259. Mtime: 0,
  1260. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1261. Prescribingnumber: advice.PrescribingNumber,
  1262. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1263. }
  1264. service.CreateDrugError(drugError)
  1265. c.ServeSuccessJSON(map[string]interface{}{
  1266. "msg": "3",
  1267. "advice": advice,
  1268. "ids": ids,
  1269. })
  1270. return
  1271. }
  1272. if prescribing_number_total > total {
  1273. drugError := models.XtDrugError{
  1274. UserOrgId: adminInfo.Org.Id,
  1275. DrugId: item.DrugId,
  1276. RecordDate: item.AdviceDate,
  1277. PatientId: item.PatientId,
  1278. Remark: "出库数量大于库存",
  1279. Status: 1,
  1280. Ctime: time.Now().Unix(),
  1281. Mtime: 0,
  1282. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1283. Prescribingnumber: advice.PrescribingNumber,
  1284. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1285. }
  1286. service.CreateDrugError(drugError)
  1287. c.ServeSuccessJSON(map[string]interface{}{
  1288. "msg": "2",
  1289. "advice": advice,
  1290. "ids": ids,
  1291. })
  1292. return
  1293. }
  1294. }
  1295. if prescribing_number_total <= total {
  1296. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  1297. //判断药品是否零用
  1298. if medical.IsUse == 2 {
  1299. if config.IsOpen != 1 {
  1300. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  1301. service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
  1302. if adminInfo.Org.Id == 3877 || adminInfo.Org.Id == 10265 {
  1303. //查询该药品是否有出库记录
  1304. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  1305. if len(flowMap) == 0 {
  1306. errs := service.UpdateHisAdviceById(advice.ID)
  1307. if errs != nil {
  1308. drugError := models.XtDrugError{
  1309. UserOrgId: adminInfo.Org.Id,
  1310. DrugId: item.DrugId,
  1311. RecordDate: item.AdviceDate,
  1312. PatientId: item.PatientId,
  1313. Remark: "出库记录为空,更新执行人失败",
  1314. Status: 1,
  1315. Ctime: time.Now().Unix(),
  1316. Mtime: 0,
  1317. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1318. Prescribingnumber: advice.PrescribingNumber,
  1319. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1320. }
  1321. service.CreateDrugError(drugError)
  1322. }
  1323. c.ServeSuccessJSON(map[string]interface{}{
  1324. "msg": "6",
  1325. "advice": advice,
  1326. "ids": ids,
  1327. })
  1328. return
  1329. }
  1330. }
  1331. }
  1332. if pharmacyConfig.IsOpen != 1 {
  1333. service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
  1334. if adminInfo.Org.Id == 3877 || adminInfo.Org.Id == 10265 {
  1335. //查询该药品是否有出库记录
  1336. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  1337. if len(flowMap) == 0 {
  1338. errs := service.UpdateHisAdviceById(advice.ID)
  1339. if errs != nil {
  1340. drugError := models.XtDrugError{
  1341. UserOrgId: adminInfo.Org.Id,
  1342. DrugId: item.DrugId,
  1343. RecordDate: item.AdviceDate,
  1344. PatientId: item.PatientId,
  1345. Remark: "出库记录为空,更新执行人失败",
  1346. Status: 1,
  1347. Ctime: time.Now().Unix(),
  1348. Mtime: 0,
  1349. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1350. Prescribingnumber: advice.PrescribingNumber,
  1351. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1352. }
  1353. service.CreateDrugError(drugError)
  1354. }
  1355. c.ServeSuccessJSON(map[string]interface{}{
  1356. "msg": "6",
  1357. "advice": advice,
  1358. "ids": ids,
  1359. })
  1360. return
  1361. }
  1362. }
  1363. }
  1364. //更新字典里面的库存
  1365. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1366. var sum_count int64
  1367. for _, its := range stockInfo {
  1368. if its.MaxUnit == medical.MaxUnit {
  1369. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1370. }
  1371. sum_count += its.StockMaxNumber + its.StockMinNumber
  1372. }
  1373. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1374. //剩余库存
  1375. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  1376. }
  1377. }
  1378. }
  1379. }
  1380. //
  1381. if config.IsOpen == 1 && item.UserOrgId == 10028 {
  1382. service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
  1383. //更新字典里面的库存
  1384. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1385. var sum_count int64
  1386. for _, its := range stockInfo {
  1387. if its.MaxUnit == medical.MaxUnit {
  1388. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1389. }
  1390. sum_count += its.StockMaxNumber + its.StockMinNumber
  1391. }
  1392. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1393. //剩余库存
  1394. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  1395. }
  1396. }
  1397. }
  1398. for _, item := range advices {
  1399. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  1400. c.ServeSuccessJSON(map[string]interface{}{
  1401. "msg": "1",
  1402. "advice": advice,
  1403. "ids": ids,
  1404. })
  1405. }
  1406. } else {
  1407. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1408. }
  1409. }
  1410. }
  1411. func (c *PatientApiController) ModifyExecDoctorAdvice() {
  1412. execution_time := c.GetString("execution_time")
  1413. fmt.Println("execution_time", execution_time)
  1414. groupno, _ := c.GetInt64("groupno", -1)
  1415. //patient_id, _ := c.GetInt64("patient_id")
  1416. advice_date, _ := c.GetInt64("advice_date")
  1417. var ids []string
  1418. if groupno == 0 {
  1419. advice_ids := c.GetString("advice_id")
  1420. ids = strings.Split(advice_ids, ",")
  1421. }
  1422. if groupno < 0 {
  1423. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1424. return
  1425. }
  1426. if len(execution_time) <= 0 {
  1427. utils.ErrorLog("execution_time")
  1428. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1429. return
  1430. }
  1431. timeLayout2 := "2006-01-02 15:04:05"
  1432. loc, _ := time.LoadLocation("Local")
  1433. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  1434. if errs != nil {
  1435. utils.ErrorLog(errs.Error())
  1436. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1437. return
  1438. }
  1439. adminUserInfo := c.GetMobileAdminUserInfo()
  1440. var advice models.DoctorAdvice
  1441. if groupno > 0 {
  1442. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  1443. for _, item := range advices {
  1444. if item.ExecutionState == 1 {
  1445. advice = item
  1446. }
  1447. }
  1448. } else {
  1449. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  1450. for _, item := range advices {
  1451. if item.ExecutionState == 1 {
  1452. advice = item
  1453. }
  1454. }
  1455. }
  1456. //if advice.ExecutionStaff != adminUserInfo.AdminUser.Id {
  1457. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1458. // if getPermissionErr != nil {
  1459. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1460. // return
  1461. // } else if headNursePermission == nil {
  1462. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1463. // return
  1464. // }
  1465. //}
  1466. if advice.StartTime > theTime.Unix() {
  1467. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1468. return
  1469. }
  1470. advices := models.DoctorAdvice{
  1471. ExecutionTime: theTime.Unix(),
  1472. UpdatedTime: time.Now().Unix(),
  1473. }
  1474. var err error
  1475. if groupno > 0 {
  1476. // 查询信息规挡的设置天数
  1477. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1478. if infor.ID > 0 {
  1479. var cha_time int64
  1480. timeNowStr := time.Now().Format("2006-01-02")
  1481. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1482. //今日的日期减去设置的日期
  1483. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1484. if cha_time >= advices.AdviceDate {
  1485. //查询审核是否允许
  1486. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advices.AdviceDate, adminUserInfo.Org.Id)
  1487. //申请状态不允许的情况 拒绝修改
  1488. if infor.ApplicationStatus != 1 {
  1489. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1490. return
  1491. }
  1492. }
  1493. }
  1494. err = service.ModifyExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  1495. redis := service.RedisClient()
  1496. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1497. redis.Set(key, "", time.Second)
  1498. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1499. redis.Set(keyOne, "", time.Second)
  1500. defer redis.Close()
  1501. } else {
  1502. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1503. if infor.ID > 0 {
  1504. var cha_time int64
  1505. timeNowStr := time.Now().Format("2006-01-02")
  1506. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1507. //今日的日期减去设置的日期
  1508. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1509. if cha_time >= advices.AdviceDate {
  1510. //查询审核是否允许
  1511. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advices.AdviceDate, adminUserInfo.Org.Id)
  1512. //申请状态不允许的情况 拒绝修改
  1513. if infor.ApplicationStatus != 1 {
  1514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1515. return
  1516. }
  1517. }
  1518. }
  1519. err = service.BatchModifyExceOldDoctorAdvice(&advices, ids)
  1520. err = service.ModifyExceDoctorAdviceByGroupNoOne(&advices, ids)
  1521. redis := service.RedisClient()
  1522. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1523. redis.Set(key, "", time.Second)
  1524. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice_date, 10) + ":advice_list_all"
  1525. redis.Set(keyOne, "", time.Second)
  1526. defer redis.Close()
  1527. }
  1528. //判断是否开启his
  1529. errs, config := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  1530. //如果开启去修改执行时间
  1531. if config.IsOpen == 1 {
  1532. advicesinfo := models.HisDoctorAdviceInfo{
  1533. ExecutionTime: theTime.Unix(),
  1534. UpdatedTime: time.Now().Unix(),
  1535. }
  1536. var advicehis models.HisDoctorAdviceInfo
  1537. service.ModifyExceDoctorAdviceById(&advicesinfo, ids)
  1538. his_advices, _ := service.FindHisDoctorAdviceByIdOne(adminUserInfo.Org.Id, ids)
  1539. for _, item := range his_advices {
  1540. if item.ExecutionState == 1 {
  1541. advicehis = item
  1542. }
  1543. }
  1544. redis := service.RedisClient()
  1545. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicehis.PatientId, 10) + ":" + strconv.FormatInt(advicehis.AdviceDate, 10) + ":his_doctor_advice"
  1546. redis.Set(keyThree, "", time.Second)
  1547. recordDate := theTime.Format("2006-01-02")
  1548. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1549. redis.Set(keyFour, "", time.Second)
  1550. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicehis.AdviceDate, 10) + ":his_advices_list_all"
  1551. redis.Set(keyFive, "", time.Second)
  1552. defer redis.Close()
  1553. project := models.HisPrescriptionProject{
  1554. ExecutionTime: theTime.Unix(),
  1555. Mtime: time.Now().Unix(),
  1556. }
  1557. service.ModifyHisPrescriptionProject(&project, ids)
  1558. keyEnd := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicesinfo.PatientId, 10) + ":" + strconv.FormatInt(advicesinfo.AdviceDate, 10) + ":his_doctor_advice"
  1559. redis.Set(keyEnd, "", time.Second)
  1560. keyFours := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1561. redis.Set(keyFours, "", time.Second)
  1562. keyFives := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicesinfo.AdviceDate, 10) + ":his_advices_list_all"
  1563. redis.Set(keyFives, "", time.Second)
  1564. defer redis.Close()
  1565. }
  1566. if err != nil {
  1567. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1568. return
  1569. }
  1570. advice.ExecutionTime = theTime.Unix()
  1571. c.ServeSuccessJSON(map[string]interface{}{
  1572. "msg": "ok",
  1573. "advice": advice,
  1574. "ids": ids,
  1575. })
  1576. return
  1577. }
  1578. func (c *PatientApiController) CheckDoctorAdvice() {
  1579. origin, _ := c.GetInt64("origin", 0)
  1580. if origin != 2 {
  1581. groupno, _ := c.GetInt64("groupno", -1)
  1582. var ids []string
  1583. if groupno == 0 {
  1584. advice_ids := c.GetString("advice_id")
  1585. if advice_ids == "" {
  1586. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1587. return
  1588. } else {
  1589. ids = strings.Split(advice_ids, ",")
  1590. if len(ids) <= 0 {
  1591. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1592. return
  1593. }
  1594. }
  1595. }
  1596. if groupno < 0 {
  1597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1598. return
  1599. }
  1600. adminUserInfo := c.GetMobileAdminUserInfo()
  1601. var advice models.DoctorAdvice
  1602. if groupno > 0 {
  1603. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  1604. for _, item := range advices {
  1605. if item.CheckState == 0 {
  1606. advice = item
  1607. }
  1608. }
  1609. if advice.CheckState == 1 {
  1610. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1611. return
  1612. }
  1613. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1614. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1615. return
  1616. }
  1617. } else {
  1618. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  1619. for _, item := range advices {
  1620. if item.CheckState == 0 {
  1621. advice = item
  1622. }
  1623. }
  1624. if advice.CheckState == 1 {
  1625. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1626. return
  1627. }
  1628. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1629. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1630. return
  1631. }
  1632. }
  1633. checker := adminUserInfo.AdminUser.Id
  1634. theTime := time.Now()
  1635. advices := models.DoctorAdvice{
  1636. CheckTime: theTime.Unix(),
  1637. Checker: checker,
  1638. UpdatedTime: time.Now().Unix(),
  1639. }
  1640. var err error
  1641. if groupno > 0 {
  1642. // 查询信息规挡的设置天数
  1643. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1644. if infor.ID > 0 {
  1645. var cha_time int64
  1646. timeNowStr := time.Now().Format("2006-01-02")
  1647. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1648. //今日的日期减去设置的日期
  1649. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1650. if cha_time >= advices.AdviceDate {
  1651. //查询审核是否允许
  1652. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id)
  1653. //申请状态不允许的情况 拒绝修改
  1654. if infor.ApplicationStatus != 1 {
  1655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1656. return
  1657. }
  1658. }
  1659. }
  1660. err = service.CheckDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  1661. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1662. redis := service.RedisClient()
  1663. //清空key 值
  1664. redis.Set(key, "", time.Second)
  1665. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1666. redis.Set(keyTwo, "", time.Second)
  1667. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1668. redis.Set(keyThree, "", time.Second)
  1669. recordDate := theTime.Format("2006-01-02")
  1670. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1671. redis.Set(keyFour, "", time.Second)
  1672. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1673. redis.Set(keyFive, "", time.Second)
  1674. defer redis.Close()
  1675. } else {
  1676. if len(ids[0]) <= 0 {
  1677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1678. return
  1679. } else {
  1680. //t := time.Now().Format("2006-01-02")/**/
  1681. //timeLayout2 := "2006-01-02"
  1682. //loc, _ := time.LoadLocation("Local")
  1683. //theTime, _ := time.ParseInLocation(timeLayout2, t, loc)
  1684. // 查询信息规挡的设置天数
  1685. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1686. if infor.ID > 0 {
  1687. var cha_time int64
  1688. timeNowStr := time.Now().Format("2006-01-02")
  1689. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1690. //今日的日期减去设置的日期
  1691. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1692. if cha_time >= advices.AdviceDate {
  1693. //查询审核是否允许
  1694. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id)
  1695. //申请状态不允许的情况 拒绝修改
  1696. if infor.ApplicationStatus != 1 {
  1697. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1698. return
  1699. }
  1700. }
  1701. }
  1702. err = service.BatchCheckOldDoctorAdvice(&advices, ids, adminUserInfo.Org.Id, advice.AdviceDate)
  1703. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1704. redis := service.RedisClient()
  1705. //清空key 值
  1706. redis.Set(key, "", time.Second)
  1707. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1708. redis.Set(keyTwo, "", time.Second)
  1709. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1710. redis.Set(keyThree, "", time.Second)
  1711. recordDate := theTime.Format("2006-01-02")
  1712. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1713. redis.Set(keyFour, "", time.Second)
  1714. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1715. redis.Set(keyFive, "", time.Second)
  1716. defer redis.Close()
  1717. }
  1718. }
  1719. if err != nil {
  1720. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1721. return
  1722. }
  1723. advice.Checker = checker
  1724. advice.CheckTime = theTime.Unix()
  1725. advice.CheckState = 1
  1726. c.ServeSuccessJSON(map[string]interface{}{
  1727. "msg": "ok",
  1728. "advice": advice,
  1729. })
  1730. } else if origin == 2 {
  1731. adminInfo := c.GetMobileAdminUserInfo()
  1732. var ids []string
  1733. advice_ids := c.GetString("advice_id")
  1734. ids = strings.Split(advice_ids, ",")
  1735. advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
  1736. var err error
  1737. for _, item := range advices {
  1738. if item.CheckState == 1 {
  1739. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1740. return
  1741. }
  1742. if item.ExecutionStaff >= 0 && item.ExecutionStaff == adminInfo.AdminUser.Id {
  1743. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1744. return
  1745. }
  1746. item.Checker = adminInfo.AdminUser.Id
  1747. item.CheckTime = time.Now().Unix()
  1748. item.CheckState = 1
  1749. // 查询信息规挡的设置天数
  1750. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  1751. if infor.ID > 0 {
  1752. var cha_time int64
  1753. timeNowStr := time.Now().Format("2006-01-02")
  1754. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1755. //今日的日期减去设置的日期
  1756. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1757. if cha_time >= item.AdviceDate {
  1758. //查询审核是否允许
  1759. infor, _ := service.GetDialysisInformationByRecordDate(item.PatientId, item.AdviceDate, adminInfo.Org.Id)
  1760. //申请状态不允许的情况 拒绝修改
  1761. if infor.ApplicationStatus != 1 {
  1762. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1763. return
  1764. }
  1765. }
  1766. }
  1767. err = service.SaveHisDoctorAdvice(item)
  1768. redis := service.RedisClient()
  1769. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1770. //清空key 值
  1771. redis.Set(key, "", time.Second)
  1772. keyTwo := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1773. redis.Set(keyTwo, "", time.Second)
  1774. keyThree := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  1775. redis.Set(keyThree, "", time.Second)
  1776. theTime := time.Now()
  1777. recordDate := theTime.Format("2006-01-02")
  1778. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminInfo.Org.Id, 10)
  1779. redis.Set(keyFour, "", time.Second)
  1780. keyFive := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  1781. redis.Set(keyFive, "", time.Second)
  1782. defer redis.Close()
  1783. }
  1784. if err == nil {
  1785. c.ServeSuccessJSON(map[string]interface{}{
  1786. "msg": "ok",
  1787. "advice": advices,
  1788. })
  1789. } else {
  1790. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1791. return
  1792. }
  1793. }
  1794. return
  1795. }
  1796. func (c *PatientApiController) EditAssessmentBeforeDislysis() {
  1797. id, _ := c.GetInt64("patient", 0)
  1798. assessmentDate := c.GetString("assessment_date", "")
  1799. if id <= 0 || len(assessmentDate) != 10 {
  1800. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1801. return
  1802. }
  1803. timeLayout := "2006-01-02"
  1804. loc, _ := time.LoadLocation("Local")
  1805. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", assessmentDate+" 00:00:00", loc)
  1806. if err != nil {
  1807. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1808. return
  1809. }
  1810. theAssessmentDateTime := theTime.Unix()
  1811. adminUserInfo := c.GetMobileAdminUserInfo()
  1812. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1813. if patient.ID == 0 {
  1814. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1815. return
  1816. }
  1817. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluationSeven(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  1818. if getPEErr != nil {
  1819. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  1820. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1821. return
  1822. }
  1823. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1824. //templateInfo,_ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1825. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1826. var evaluation models.PredialysisEvaluation
  1827. if theEvaluation != nil {
  1828. evaluation = *theEvaluation
  1829. }
  1830. code := predialysisEvaluationFormData(&evaluation, c.Ctx.Input.RequestBody)
  1831. if code > 0 {
  1832. c.ServeFailJSONWithSGJErrorCode(code)
  1833. return
  1834. }
  1835. if theEvaluation == nil {
  1836. evaluation.CreatedTime = time.Now().Unix()
  1837. evaluation.Status = 1
  1838. evaluation.AssessmentDate = theAssessmentDateTime
  1839. evaluation.PatientId = id
  1840. evaluation.UserOrgId = adminUserInfo.Org.Id
  1841. if appRole.UserType == 2 || appRole.UserType == 1 {
  1842. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1843. evaluation.AssessmentTime = time.Now().Unix()
  1844. } else {
  1845. evaluation.Creater = adminUserInfo.AdminUser.Id
  1846. }
  1847. } else {
  1848. evaluation.UpdatedTime = time.Now().Unix()
  1849. evaluation.Evaluator = adminUserInfo.AdminUser.Id
  1850. if appRole.UserType == 2 || appRole.UserType == 1 {
  1851. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1852. evaluation.AssessmentTime = time.Now().Unix()
  1853. } else {
  1854. evaluation.Modifier = adminUserInfo.AdminUser.Id
  1855. if evaluation.Creater == 0 {
  1856. evaluation.Creater = adminUserInfo.AdminUser.Id
  1857. }
  1858. }
  1859. }
  1860. //新增逻辑
  1861. var dewater_amount float64
  1862. dewater_amount = 0
  1863. if evaluation.DryWeight > 0 {
  1864. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  1865. if template.TemplateId == 17 || template.TemplateId == 22 || template.TemplateId == 21 || template.TemplateId == 26 || template.TemplateId == 34 || template.TemplateId == 32 || adminUserInfo.Org.Id == 10469 || adminUserInfo.Org.Id == 3877 {
  1866. dewater_amount = dewater_amount * 1000
  1867. }
  1868. if dewater_amount <= 0 {
  1869. dewater_amount = 0
  1870. }
  1871. } else {
  1872. dewater_amount = 0
  1873. }
  1874. // 计算透析处方的相关超滤量
  1875. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.Org.Id, patient.ID, theAssessmentDateTime)
  1876. lastDialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient.ID, adminUserInfo.Org.Id)
  1877. var lastDialysisPrescribe *models.DialysisPrescription
  1878. var dialysisSolution *models.DialysisSolution
  1879. var dialysisPrescribe *models.DialysisPrescription
  1880. var system_dialysisPrescribe *models.SystemPrescription
  1881. var mode_id int64
  1882. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  1883. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  1884. if schedual != nil {
  1885. // 获取透析模版
  1886. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  1887. system_dialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, schedual.ModeId)
  1888. mode_id = schedual.ModeId
  1889. } else {
  1890. // 获取透析模版
  1891. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.Org.Id, id)
  1892. if dialysisPrescribe == nil && dialysisSolution != nil {
  1893. mode_id = dialysisSolution.ModeId
  1894. }
  1895. if dialysisPrescribe == nil && dialysisSolution == nil {
  1896. mode_id = 0
  1897. }
  1898. }
  1899. // 插入透析处方
  1900. if dialysisPrescribe == nil && dialysisSolution != nil {
  1901. var newprescribe models.DialysisPrescription
  1902. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  1903. newprescribe.PatientId = dialysisSolution.PatientId
  1904. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  1905. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  1906. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  1907. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  1908. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  1909. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  1910. newprescribe.ModeId = dialysisSolution.ModeId
  1911. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  1912. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  1913. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  1914. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  1915. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  1916. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  1917. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  1918. newprescribe.Glucose = dialysisSolution.Glucose
  1919. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  1920. newprescribe.Kalium = dialysisSolution.Kalium
  1921. newprescribe.Sodium = dialysisSolution.Sodium
  1922. newprescribe.Calcium = dialysisSolution.Calcium
  1923. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  1924. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  1925. newprescribe.Conductivity = dialysisSolution.Conductivity
  1926. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  1927. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  1928. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  1929. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  1930. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  1931. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  1932. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  1933. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  1934. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  1935. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  1936. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  1937. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  1938. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  1939. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  1940. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  1941. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  1942. newprescribe.CreatedTime = time.Now().Unix()
  1943. newprescribe.UpdatedTime = time.Now().Unix()
  1944. newprescribe.RecordDate = theAssessmentDateTime
  1945. newprescribe.DewaterAmount = dewater_amount
  1946. newprescribe.TargetUltrafiltration = dewater_amount
  1947. newprescribe.Status = 1
  1948. newprescribe.DialysisDialyszers = dialysisSolution.DialysisDialyszers
  1949. newprescribe.DialysisIrrigation = dialysisSolution.DialysisIrrigation
  1950. newprescribe.Remark = lastDialysisPrescription.Remark
  1951. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  1952. newprescribe.ID = dialysisPrescription.ID
  1953. if dialysisPrescription.ID == 0 {
  1954. if adminUserInfo.Org.Id == 10340 {
  1955. newprescribe.Sodium = 138
  1956. newprescribe.Bicarbonate = 31.1
  1957. newprescribe.DialysateFlow = 500
  1958. newprescribe.PrescribingNumber = 1
  1959. }
  1960. err := service.AddSigleRecord(&newprescribe)
  1961. //获取key,清空redis
  1962. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1963. redis := service.RedisClient()
  1964. //清空key 值
  1965. redis.Set(key, "", time.Second)
  1966. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1967. //清空key 值
  1968. redis.Set(keyOne, "", time.Second)
  1969. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1970. //清空key 值
  1971. redis.Set(keyTwo, "", time.Second)
  1972. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1973. redis.Set(keySix, "", time.Second)
  1974. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1975. redis.Set(keySeven, "", time.Second)
  1976. if err != nil {
  1977. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1978. }
  1979. } else {
  1980. if adminUserInfo.Org.Id == 10340 {
  1981. newprescribe.Sodium = 138
  1982. newprescribe.Bicarbonate = 31.1
  1983. newprescribe.DialysateFlow = 500
  1984. }
  1985. err := service.UpDateDialysisPrescription(&newprescribe)
  1986. //获取key,清空redis
  1987. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1988. redis := service.RedisClient()
  1989. //清空key 值
  1990. redis.Set(key, "", time.Second)
  1991. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1992. //清空key 值
  1993. redis.Set(keyOne, "", time.Second)
  1994. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1995. //清空key 值
  1996. redis.Set(keyTwo, "", time.Second)
  1997. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1998. redis.Set(keySix, "", time.Second)
  1999. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2000. redis.Set(keySeven, "", time.Second)
  2001. if err != nil {
  2002. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2003. }
  2004. }
  2005. }
  2006. if dialysisPrescribe == nil && dialysisSolution == nil {
  2007. if lastDialysisPrescribe != nil {
  2008. var newprescribe models.DialysisPrescription
  2009. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  2010. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  2011. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  2012. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  2013. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  2014. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  2015. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  2016. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  2017. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  2018. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  2019. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  2020. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  2021. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  2022. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  2023. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  2024. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  2025. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  2026. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  2027. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  2028. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  2029. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  2030. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  2031. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  2032. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  2033. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  2034. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  2035. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  2036. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  2037. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  2038. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  2039. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  2040. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  2041. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  2042. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  2043. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  2044. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  2045. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  2046. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  2047. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  2048. newprescribe.CreatedTime = time.Now().Unix()
  2049. newprescribe.UpdatedTime = time.Now().Unix()
  2050. newprescribe.RecordDate = theAssessmentDateTime
  2051. newprescribe.DewaterAmount = dewater_amount
  2052. newprescribe.TargetUltrafiltration = dewater_amount
  2053. newprescribe.Status = 1
  2054. newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
  2055. newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
  2056. newprescribe.Remark = lastDialysisPrescription.Remark
  2057. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  2058. newprescribe.ID = dialysisPrescription.ID
  2059. if dialysisPrescription.ID == 0 {
  2060. if adminUserInfo.Org.Id == 10340 {
  2061. newprescribe.Sodium = 138
  2062. newprescribe.Bicarbonate = 31.1
  2063. newprescribe.DialysateFlow = 500
  2064. }
  2065. err := service.AddSigleRecord(&newprescribe)
  2066. //获取key,清空redis
  2067. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2068. redis := service.RedisClient()
  2069. //清空key 值
  2070. redis.Set(key, "", time.Second)
  2071. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2072. //清空key 值
  2073. redis.Set(keyOne, "", time.Second)
  2074. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2075. //清空key 值
  2076. redis.Set(keyTwo, "", time.Second)
  2077. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2078. redis.Set(keySix, "", time.Second)
  2079. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2080. redis.Set(keySeven, "", time.Second)
  2081. if err != nil {
  2082. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2083. }
  2084. } else {
  2085. err := service.UpDateDialysisPrescription(&newprescribe)
  2086. //获取key,清空redis
  2087. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2088. redis := service.RedisClient()
  2089. //清空key 值
  2090. redis.Set(key, "", time.Second)
  2091. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2092. //清空key 值
  2093. redis.Set(keyOne, "", time.Second)
  2094. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2095. //清空key 值
  2096. redis.Set(keyTwo, "", time.Second)
  2097. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2098. redis.Set(keySix, "", time.Second)
  2099. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2100. redis.Set(keySeven, "", time.Second)
  2101. if err != nil {
  2102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2103. }
  2104. }
  2105. if err != nil {
  2106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2107. }
  2108. } else if system_dialysisPrescribe != nil {
  2109. var newprescribe models.DialysisPrescription
  2110. newprescribe.UserOrgId = system_dialysisPrescribe.UserOrgId
  2111. newprescribe.PatientId = id
  2112. newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
  2113. newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
  2114. newprescribe.AnticoagulantWeichi = system_dialysisPrescribe.AnticoagulantWeichi
  2115. newprescribe.AnticoagulantZongliang = system_dialysisPrescribe.AnticoagulantZongliang
  2116. newprescribe.AnticoagulantGaimingcheng = system_dialysisPrescribe.AnticoagulantGaimingcheng
  2117. newprescribe.AnticoagulantGaijiliang = system_dialysisPrescribe.AnticoagulantGaijiliang
  2118. newprescribe.ModeId = system_dialysisPrescribe.ModeId
  2119. newprescribe.DialysisDuration = system_dialysisPrescribe.DialysisDuration
  2120. newprescribe.ReplacementWay = system_dialysisPrescribe.ReplacementWay
  2121. newprescribe.HemodialysisMachine = system_dialysisPrescribe.HemodialysisMachine
  2122. newprescribe.BloodFilter = system_dialysisPrescribe.BloodFilter
  2123. newprescribe.PerfusionApparatus = system_dialysisPrescribe.PerfusionApparatus
  2124. newprescribe.BloodFlowVolume = system_dialysisPrescribe.BloodFlowVolume
  2125. newprescribe.DisplaceLiqui = system_dialysisPrescribe.DisplaceLiqui
  2126. newprescribe.Glucose = system_dialysisPrescribe.Glucose
  2127. newprescribe.DialysateFlow = system_dialysisPrescribe.DialysateFlow
  2128. newprescribe.Kalium = system_dialysisPrescribe.Kalium
  2129. newprescribe.Sodium = system_dialysisPrescribe.Sodium
  2130. newprescribe.Calcium = system_dialysisPrescribe.Calcium
  2131. newprescribe.Bicarbonate = system_dialysisPrescribe.Bicarbonate
  2132. newprescribe.DialysateTemperature = system_dialysisPrescribe.DialysateTemperature
  2133. newprescribe.Conductivity = system_dialysisPrescribe.Conductivity
  2134. newprescribe.BodyFluid = system_dialysisPrescribe.BodyFluid
  2135. newprescribe.SpecialMedicine = system_dialysisPrescribe.SpecialMedicine
  2136. newprescribe.SpecialMedicineOther = system_dialysisPrescribe.SpecialMedicineOther
  2137. newprescribe.DisplaceLiquiPart = system_dialysisPrescribe.DisplaceLiquiPart
  2138. newprescribe.DisplaceLiquiValue = system_dialysisPrescribe.DisplaceLiquiValue
  2139. newprescribe.BloodAccess = system_dialysisPrescribe.BloodAccess
  2140. newprescribe.Ultrafiltration = system_dialysisPrescribe.Ultrafiltration
  2141. newprescribe.DialysisDurationHour = system_dialysisPrescribe.DialysisDurationHour
  2142. newprescribe.DialysisDurationMinute = system_dialysisPrescribe.DialysisDurationMinute
  2143. newprescribe.DialysateFormulation = system_dialysisPrescribe.DialysateFormulation
  2144. newprescribe.Dialyzer = system_dialysisPrescribe.Dialyzer
  2145. newprescribe.ReplacementTotal = system_dialysisPrescribe.ReplacementTotal
  2146. newprescribe.DialyzerPerfusionApparatus = system_dialysisPrescribe.DialyzerPerfusionApparatus
  2147. newprescribe.BodyFluidOther = system_dialysisPrescribe.BodyFluidOther
  2148. newprescribe.TargetKtv = system_dialysisPrescribe.TargetKtv
  2149. newprescribe.CreatedTime = time.Now().Unix()
  2150. newprescribe.UpdatedTime = time.Now().Unix()
  2151. newprescribe.RecordDate = theAssessmentDateTime
  2152. newprescribe.DewaterAmount = dewater_amount
  2153. newprescribe.TargetUltrafiltration = dewater_amount
  2154. newprescribe.Status = 1
  2155. newprescribe.DialysisDialyszers = system_dialysisPrescribe.DialysisDialyszers
  2156. newprescribe.DialysisIrrigation = system_dialysisPrescribe.DialysisIrrigation
  2157. newprescribe.Remark = lastDialysisPrescription.Remark
  2158. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  2159. newprescribe.ID = dialysisPrescription.ID
  2160. if dialysisPrescription.ID == 0 {
  2161. if adminUserInfo.Org.Id == 10340 {
  2162. newprescribe.Sodium = 138
  2163. newprescribe.Bicarbonate = 31.1
  2164. newprescribe.DialysateFlow = 500
  2165. }
  2166. err := service.AddSigleRecord(&newprescribe)
  2167. //获取key,清空redis
  2168. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2169. redis := service.RedisClient()
  2170. //清空key 值
  2171. redis.Set(key, "", time.Second)
  2172. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2173. //清空key 值
  2174. redis.Set(keyOne, "", time.Second)
  2175. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2176. //清空key 值
  2177. redis.Set(keyTwo, "", time.Second)
  2178. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2179. redis.Set(keySix, "", time.Second)
  2180. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2181. redis.Set(keySeven, "", time.Second)
  2182. if err != nil {
  2183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2184. }
  2185. } else {
  2186. if adminUserInfo.Org.Id == 10340 {
  2187. newprescribe.Sodium = 138
  2188. newprescribe.Bicarbonate = 31.1
  2189. newprescribe.DialysateFlow = 500
  2190. }
  2191. err := service.UpDateDialysisPrescription(&newprescribe)
  2192. //获取key,清空redis
  2193. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2194. redis := service.RedisClient()
  2195. //清空key 值
  2196. redis.Set(key, "", time.Second)
  2197. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2198. //清空key 值
  2199. redis.Set(keyOne, "", time.Second)
  2200. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2201. //清空key 值
  2202. redis.Set(keyTwo, "", time.Second)
  2203. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2204. redis.Set(keySix, "", time.Second)
  2205. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2206. redis.Set(keySeven, "", time.Second)
  2207. if err != nil {
  2208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2209. }
  2210. }
  2211. if err != nil {
  2212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2213. }
  2214. } else {
  2215. var newprescribe models.DialysisPrescription
  2216. newprescribe.UserOrgId = adminUserInfo.Org.Id
  2217. newprescribe.PatientId = id
  2218. newprescribe.ModeId = mode_id
  2219. newprescribe.CreatedTime = time.Now().Unix()
  2220. newprescribe.UpdatedTime = time.Now().Unix()
  2221. newprescribe.RecordDate = theAssessmentDateTime
  2222. newprescribe.DewaterAmount = dewater_amount
  2223. newprescribe.TargetUltrafiltration = dewater_amount
  2224. newprescribe.Status = 1
  2225. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  2226. newprescribe.ID = dialysisPrescription.ID
  2227. if dialysisPrescription.ID == 0 {
  2228. if adminUserInfo.Org.Id == 10340 {
  2229. newprescribe.Sodium = 138
  2230. newprescribe.Bicarbonate = 31.1
  2231. newprescribe.DialysateFlow = 500
  2232. }
  2233. err := service.AddSigleRecord(&newprescribe)
  2234. //获取key,清空redis
  2235. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2236. redis := service.RedisClient()
  2237. //清空key 值
  2238. redis.Set(key, "", time.Second)
  2239. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2240. //清空key 值
  2241. redis.Set(keyOne, "", time.Second)
  2242. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2243. //清空key 值
  2244. redis.Set(keyTwo, "", time.Second)
  2245. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2246. redis.Set(keySix, "", time.Second)
  2247. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2248. redis.Set(keySeven, "", time.Second)
  2249. if err != nil {
  2250. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2251. }
  2252. } else {
  2253. if adminUserInfo.Org.Id == 10340 {
  2254. newprescribe.Sodium = 138
  2255. newprescribe.Bicarbonate = 31.1
  2256. newprescribe.DialysateFlow = 500
  2257. }
  2258. err := service.UpDateDialysisPrescription(&newprescribe)
  2259. //获取key,清空redis
  2260. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2261. redis := service.RedisClient()
  2262. //清空key 值
  2263. redis.Set(key, "", time.Second)
  2264. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2265. //清空key 值
  2266. redis.Set(keyOne, "", time.Second)
  2267. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2268. //清空key 值
  2269. redis.Set(keyTwo, "", time.Second)
  2270. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2271. redis.Set(keySix, "", time.Second)
  2272. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2273. redis.Set(keySeven, "", time.Second)
  2274. if err != nil {
  2275. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2276. }
  2277. }
  2278. if err != nil {
  2279. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2280. }
  2281. }
  2282. }
  2283. // 手动修改透前评估的时候,如果透析处方已经存在,则不修改对应的透析处方
  2284. // if dialysisPrescribe != nil {
  2285. // dialysisPrescribe.UpdatedTime = time.Now().Unix()
  2286. // dialysisPrescribe.RecordDate = theAssessmentDateTime
  2287. // dialysisPrescribe.DewaterAmount = dewater_amount
  2288. // dialysisPrescribe.TargetUltrafiltration = dewater_amount
  2289. // dialysisPrescribe.Status = 1
  2290. // updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
  2291. // if updateErr != nil {
  2292. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2293. // }
  2294. // }
  2295. // 查询信息规挡的设置天数
  2296. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2297. if infor.ID > 0 {
  2298. var cha_time int64
  2299. timeNowStr := time.Now().Format("2006-01-02")
  2300. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2301. //今日的日期减去设置的日期
  2302. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2303. if cha_time >= evaluation.AssessmentDate {
  2304. //查询审核是否允许
  2305. infor, _ := service.GetDialysisInformationByRecordDate(id, evaluation.AssessmentDate, adminUserInfo.Org.Id)
  2306. //申请状态不允许的情况 拒绝修改
  2307. if infor.ApplicationStatus != 1 {
  2308. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2309. return
  2310. }
  2311. }
  2312. }
  2313. err = service.UpadatePredialysisEvaluation(&evaluation)
  2314. finish := models.XtDialysisFinish{
  2315. IsFinish: 1,
  2316. UserOrgId: adminUserInfo.Org.Id,
  2317. Status: 1,
  2318. Ctime: time.Now().Unix(),
  2319. Mtime: 0,
  2320. Module: 3,
  2321. RecordDate: evaluation.AssessmentDate,
  2322. Sourse: 1,
  2323. }
  2324. dialysisFinish, err := service.GetDialysisFinish(adminUserInfo.Org.Id, evaluation.AssessmentDate, 3)
  2325. if dialysisFinish.ID == 0 {
  2326. service.CreateDialysisFinish(finish)
  2327. }
  2328. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_before_dislysis"
  2329. redis := service.RedisClient()
  2330. defer redis.Close()
  2331. //清空key 值
  2332. redis.Set(key, "", time.Second)
  2333. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_befores_list_all"
  2334. redis.Set(keyOne, "", time.Second)
  2335. keyTwo := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2336. redis.Set(keyTwo, "", time.Second)
  2337. if err != nil {
  2338. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  2339. return
  2340. }
  2341. c.ServeSuccessJSON(map[string]interface{}{
  2342. "msg": "ok",
  2343. "evaluation": evaluation,
  2344. })
  2345. return
  2346. }
  2347. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  2348. dataBody := make(map[string]interface{}, 0)
  2349. err := json.Unmarshal(data, &dataBody)
  2350. utils.InfoLog(string(data))
  2351. if err != nil {
  2352. utils.ErrorLog(err.Error())
  2353. code = enums.ErrorCodeParamWrong
  2354. return
  2355. }
  2356. // if method == "create" {
  2357. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  2358. utils.ErrorLog("mode")
  2359. code = enums.ErrorCodeParamWrong
  2360. return
  2361. }
  2362. mode := int64(dataBody["mode"].(float64))
  2363. if mode <= 0 {
  2364. utils.ErrorLog("mode <= 0")
  2365. code = enums.ErrorCodeParamWrong
  2366. return
  2367. }
  2368. solution.ModeId = mode
  2369. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  2370. utils.ErrorLog("mode_name")
  2371. code = enums.ErrorCodeParamWrong
  2372. return
  2373. }
  2374. modeName, _ := dataBody["mode_name"].(string)
  2375. if len(modeName) == 0 {
  2376. utils.ErrorLog("len(mode_name) == 0")
  2377. code = enums.ErrorCodeParamWrong
  2378. return
  2379. }
  2380. solution.ModeName = modeName
  2381. solution.Name = modeName
  2382. // }
  2383. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  2384. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  2385. solution.DialysisDuration = dialysisDuration
  2386. }
  2387. if dataBody["dialysis_duration"] != nil {
  2388. if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  2389. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  2390. solution.DialysisDuration = dialysisDuration
  2391. } else if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "float64" {
  2392. dialysisDuration := dataBody["dialysis_duration"].(float64)
  2393. solution.DialysisDuration = dialysisDuration
  2394. }
  2395. }
  2396. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  2397. dialyzer := int64(dataBody["dialyzer"].(float64))
  2398. solution.Dialyzer = dialyzer
  2399. }
  2400. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  2401. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  2402. solution.PerfusionApparatus = perfusionApparatus
  2403. }
  2404. if dataBody["blood_flow_volume"] != nil {
  2405. if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  2406. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  2407. solution.BloodFlowVolume = bloodFlowVolume
  2408. } else if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "float64" {
  2409. bloodFlowVolume := dataBody["blood_flow_volume"].(float64)
  2410. solution.BloodFlowVolume = bloodFlowVolume
  2411. }
  2412. }
  2413. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  2414. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  2415. solution.HemodialysisMachine = hemodialysisMachine
  2416. }
  2417. if dataBody["dewater"] != nil {
  2418. if reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  2419. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  2420. solution.Dewater = dewater
  2421. } else if reflect.TypeOf(dataBody["dewater"]).String() == "float64" {
  2422. dewater := dataBody["dewater"].(float64)
  2423. solution.Dewater = dewater
  2424. }
  2425. }
  2426. if dataBody["replacement_total"] != nil {
  2427. if reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  2428. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  2429. solution.ReplacementTotal = replacementTotal
  2430. } else if reflect.TypeOf(dataBody["replacement_total"]).String() == "float64" {
  2431. replacementTotal := dataBody["replacement_total"].(float64)
  2432. solution.ReplacementTotal = replacementTotal
  2433. }
  2434. }
  2435. if dataBody["displace_liqui"] != nil {
  2436. if reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  2437. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  2438. solution.DisplaceLiqui = displaceLiqui
  2439. } else if reflect.TypeOf(dataBody["displace_liqui"]).String() == "float64" {
  2440. displaceLiqui := dataBody["displace_liqui"].(float64)
  2441. solution.DisplaceLiqui = displaceLiqui
  2442. }
  2443. }
  2444. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  2445. replacementWay := int64(dataBody["replacement_way"].(float64))
  2446. solution.ReplacementWay = replacementWay
  2447. }
  2448. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  2449. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  2450. solution.Anticoagulant = anticoagulant
  2451. }
  2452. if dataBody["anticoagulant_shouji"] != nil {
  2453. if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  2454. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  2455. solution.AnticoagulantShouji = anticoagulantShouji
  2456. } else if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "float64" {
  2457. anticoagulantShouji := dataBody["anticoagulant_shouji"].(float64)
  2458. solution.AnticoagulantShouji = anticoagulantShouji
  2459. }
  2460. }
  2461. if dataBody["anticoagulant_weichi"] != nil {
  2462. if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  2463. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  2464. solution.AnticoagulantWeichi = anticoagulantWeichi
  2465. } else if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "float64" {
  2466. anticoagulantWeichi := dataBody["anticoagulant_weichi"].(float64)
  2467. solution.AnticoagulantWeichi = anticoagulantWeichi
  2468. }
  2469. }
  2470. if dataBody["anticoagulant_zongliang"] != nil {
  2471. if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  2472. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  2473. solution.AnticoagulantZongliang = anticoagulantZongliang
  2474. } else if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "float64" {
  2475. anticoagulantZongliang := dataBody["anticoagulant_zongliang"].(float64)
  2476. solution.AnticoagulantZongliang = anticoagulantZongliang
  2477. }
  2478. }
  2479. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  2480. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  2481. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  2482. }
  2483. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  2484. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  2485. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  2486. }
  2487. if dataBody["kalium"] != nil {
  2488. if reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  2489. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  2490. solution.Kalium = kalium
  2491. } else if reflect.TypeOf(dataBody["kalium"]).String() == "float64" {
  2492. kalium := dataBody["kalium"].(float64)
  2493. solution.Kalium = kalium
  2494. }
  2495. }
  2496. if dataBody["sodium"] != nil {
  2497. if reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  2498. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  2499. solution.Sodium = sodium
  2500. } else if reflect.TypeOf(dataBody["sodium"]).String() == "float64" {
  2501. sodium := dataBody["sodium"].(float64)
  2502. solution.Sodium = sodium
  2503. }
  2504. }
  2505. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  2506. if reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  2507. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  2508. solution.Calcium = calcium
  2509. } else if reflect.TypeOf(dataBody["calcium"]).String() == "float64" {
  2510. calcium := dataBody["calcium"].(float64)
  2511. solution.Calcium = calcium
  2512. }
  2513. }
  2514. if dataBody["bicarbonate"] != nil {
  2515. if reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  2516. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  2517. solution.Bicarbonate = bicarbonate
  2518. } else if reflect.TypeOf(dataBody["bicarbonate"]).String() == "float64" {
  2519. bicarbonate := dataBody["bicarbonate"].(float64)
  2520. solution.Bicarbonate = bicarbonate
  2521. }
  2522. }
  2523. if dataBody["glucose"] != nil {
  2524. if reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  2525. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  2526. solution.Glucose = glucose
  2527. } else if reflect.TypeOf(dataBody["glucose"]).String() == "float64" {
  2528. glucose := dataBody["glucose"].(float64)
  2529. solution.Glucose = glucose
  2530. }
  2531. }
  2532. // if dataBody["dry_weight"] != nil {
  2533. // if reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  2534. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  2535. // solution.DryWeight = dryWeight
  2536. // } else if reflect.TypeOf(dataBody["dry_weight"]).String() == "float64" {
  2537. // dryWeight := dataBody["dry_weight"].(float64)
  2538. // solution.DryWeight = dryWeight
  2539. // }
  2540. // }
  2541. if dataBody["dialysate_flow"] != nil {
  2542. if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  2543. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  2544. solution.DialysateFlow = dialysateFlow
  2545. } else if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "float64" {
  2546. dialysateFlow := dataBody["dialysate_flow"].(float64)
  2547. solution.DialysateFlow = dialysateFlow
  2548. }
  2549. }
  2550. if dataBody["dialysate_temperature"] != nil {
  2551. if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  2552. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  2553. solution.DialysateTemperature = dialysateTemperature
  2554. } else if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "float64" {
  2555. dialysateTemperature := dataBody["dialysate_temperature"].(float64)
  2556. solution.DialysateTemperature = dialysateTemperature
  2557. }
  2558. }
  2559. if dataBody["conductivity"] != nil {
  2560. if reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  2561. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  2562. solution.Conductivity = conductivity
  2563. } else if reflect.TypeOf(dataBody["conductivity"]).String() == "float64" {
  2564. conductivity := dataBody["conductivity"].(float64)
  2565. solution.Conductivity = conductivity
  2566. }
  2567. }
  2568. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2569. remark := dataBody["remark"].(string)
  2570. solution.Remark = remark
  2571. }
  2572. if dataBody["dialysis_duration_hour"] != nil {
  2573. if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  2574. dialysisDurationHour, _ := strconv.ParseInt(dataBody["dialysis_duration_hour"].(string), 10, 64)
  2575. solution.DialysisDurationHour = dialysisDurationHour
  2576. } else if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "float64" {
  2577. dialysisDurationHour := dataBody["dialysis_duration_hour"].(float64)
  2578. solution.DialysisDurationHour = int64(dialysisDurationHour)
  2579. }
  2580. }
  2581. if dataBody["dialysis_duration_minute"] != nil {
  2582. if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  2583. dialysisDurationMinute, _ := strconv.ParseInt(dataBody["dialysis_duration_minute"].(string), 10, 64)
  2584. solution.DialysisDurationMinute = dialysisDurationMinute
  2585. } else if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "float64" {
  2586. dialysisDurationMinute := dataBody["dialysis_duration_minute"].(float64)
  2587. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  2588. }
  2589. }
  2590. if dataBody["target_ultrafiltration"] != nil {
  2591. if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  2592. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  2593. solution.TargetUltrafiltration = targetUltrafiltration
  2594. } else if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "float64" {
  2595. targetUltrafiltration := dataBody["target_ultrafiltration"].(float64)
  2596. solution.TargetUltrafiltration = targetUltrafiltration
  2597. }
  2598. }
  2599. if dataBody["dialysate_formulation"] != nil {
  2600. if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "string" {
  2601. dialysateFormulation, _ := strconv.ParseInt(dataBody["dialysate_formulation"].(string), 10, 64)
  2602. solution.DialysateFormulation = dialysateFormulation
  2603. } else if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  2604. dialysateFormulation := dataBody["dialysate_formulation"].(float64)
  2605. solution.DialysateFormulation = int64(dialysateFormulation)
  2606. }
  2607. }
  2608. return
  2609. }
  2610. func predialysisEvaluationFormData(evaluation *models.PredialysisEvaluation, data []byte) (code int) {
  2611. dataBody := make(map[string]interface{}, 0)
  2612. err := json.Unmarshal(data, &dataBody)
  2613. utils.InfoLog(string(data))
  2614. if err != nil {
  2615. utils.ErrorLog(err.Error())
  2616. code = enums.ErrorCodeParamWrong
  2617. return
  2618. }
  2619. if dataBody["weight_before"] != nil && reflect.TypeOf(dataBody["weight_before"]).String() == "string" {
  2620. weightVefore, _ := strconv.ParseFloat(dataBody["weight_before"].(string), 64)
  2621. evaluation.WeightBefore = weightVefore
  2622. }
  2623. // fmt.Println(dataBody["dry_weight"])
  2624. // fmt.Println(reflect.TypeOf(dataBody["dry_weight"]).String())
  2625. if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  2626. additionalWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  2627. fmt.Println(additionalWeight)
  2628. evaluation.DryWeight = additionalWeight
  2629. }
  2630. if dataBody["additional_weight"] != nil && reflect.TypeOf(dataBody["additional_weight"]).String() == "string" {
  2631. additionalWeight, _ := strconv.ParseFloat(dataBody["additional_weight"].(string), 64)
  2632. fmt.Println(additionalWeight)
  2633. evaluation.AdditionalWeight = additionalWeight
  2634. }
  2635. if dataBody["temperature"] != nil && reflect.TypeOf(dataBody["temperature"]).String() == "string" {
  2636. Temperature, _ := strconv.ParseFloat(dataBody["temperature"].(string), 64)
  2637. evaluation.Temperature = Temperature
  2638. }
  2639. if dataBody["systolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["systolic_blood_pressure"]).String() == "string" {
  2640. systolicBloodPressure, _ := strconv.ParseFloat(dataBody["systolic_blood_pressure"].(string), 64)
  2641. evaluation.SystolicBloodPressure = systolicBloodPressure
  2642. }
  2643. if dataBody["diastolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["diastolic_blood_pressure"]).String() == "string" {
  2644. diastolicBloodPressure, _ := strconv.ParseFloat(dataBody["diastolic_blood_pressure"].(string), 64)
  2645. evaluation.DiastolicBloodPressure = diastolicBloodPressure
  2646. }
  2647. if dataBody["pulse_frequency"] != nil && reflect.TypeOf(dataBody["pulse_frequency"]).String() == "string" {
  2648. pulseFrequency, _ := strconv.ParseFloat(dataBody["pulse_frequency"].(string), 64)
  2649. evaluation.PulseFrequency = pulseFrequency
  2650. }
  2651. if dataBody["breathing_rate"] != nil && reflect.TypeOf(dataBody["breathing_rate"]).String() == "string" {
  2652. breathingRate := dataBody["breathing_rate"].(string)
  2653. evaluation.BreathingRate = breathingRate
  2654. }
  2655. if dataBody["last_post_dialysis"] != nil && reflect.TypeOf(dataBody["last_post_dialysis"]).String() == "string" {
  2656. lastPostDialysis, _ := dataBody["last_post_dialysis"].(string)
  2657. evaluation.LastPostDialysis = lastPostDialysis
  2658. }
  2659. if dataBody["dialysis_interphase"] != nil && reflect.TypeOf(dataBody["dialysis_interphase"]).String() == "string" {
  2660. dialysisInterphase, _ := dataBody["dialysis_interphase"].(string)
  2661. evaluation.DialysisInterphase = dialysisInterphase
  2662. }
  2663. if dataBody["symptom_before_dialysis"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis"]).String() == "string" {
  2664. symptomBeforeDialysis, _ := dataBody["symptom_before_dialysis"].(string)
  2665. evaluation.SymptomBeforeDialysis = symptomBeforeDialysis
  2666. }
  2667. if dataBody["catheter"] != nil && reflect.TypeOf(dataBody["catheter"]).String() == "string" {
  2668. catheter, _ := dataBody["catheter"].(string)
  2669. evaluation.Catheter = catheter
  2670. }
  2671. if dataBody["catheter_bend"] != nil && reflect.TypeOf(dataBody["catheter_bend"]).String() == "float64" {
  2672. catheter_bend := int(dataBody["catheter_bend"].(float64))
  2673. evaluation.CatheterBend = catheter_bend
  2674. }
  2675. if dataBody["complication"] != nil && reflect.TypeOf(dataBody["complication"]).String() == "string" {
  2676. Complication, _ := dataBody["complication"].(string)
  2677. evaluation.Complication = Complication
  2678. }
  2679. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2680. remark := dataBody["remark"].(string)
  2681. evaluation.Remark = remark
  2682. }
  2683. if dataBody["machine_type"] != nil && reflect.TypeOf(dataBody["machine_type"]).String() == "string" {
  2684. machine_type := dataBody["machine_type"].(string)
  2685. evaluation.MachineType = machine_type
  2686. }
  2687. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  2688. blood_access_part_id := dataBody["blood_access_part_id"].(string)
  2689. evaluation.BloodAccessPartId = blood_access_part_id
  2690. }
  2691. //if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "float64" {
  2692. // blood_access_part_id := int64(dataBody["blood_access_part_id"].(float64))
  2693. // evaluation.BloodAccessPartId = blood_access_part_id
  2694. //}
  2695. if dataBody["blood_access_part_opera_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_opera_id"]).String() == "float64" {
  2696. blood_access_part_opera_id := int64(dataBody["blood_access_part_opera_id"].(float64))
  2697. evaluation.BloodAccessPartOperaId = blood_access_part_opera_id
  2698. }
  2699. if dataBody["internal_fistula"] != nil && reflect.TypeOf(dataBody["internal_fistula"]).String() == "string" {
  2700. internal_fistula, _ := dataBody["internal_fistula"].(string)
  2701. evaluation.InternalFistula = internal_fistula
  2702. }
  2703. if dataBody["internal_fistula_skin"] != nil && reflect.TypeOf(dataBody["internal_fistula_skin"]).String() == "string" {
  2704. internal_fistula_skin := dataBody["internal_fistula_skin"].(string)
  2705. evaluation.InternalFistulaSkin = internal_fistula_skin
  2706. }
  2707. if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "string" {
  2708. ishemorrhage, _ := dataBody["is_hemorrhage"].(string)
  2709. is_hemorrhage, _ := strconv.ParseInt(ishemorrhage, 10, 64)
  2710. evaluation.IsHemorrhage = is_hemorrhage
  2711. //if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "float64" {
  2712. // is_hemorrhage := int64(dataBody["is_hemorrhage"].(float64))
  2713. // fmt.Println("is_hemorrhage2222222222222222",is_hemorrhage)
  2714. if is_hemorrhage != 1 && is_hemorrhage != 2 {
  2715. is_hemorrhage = 0
  2716. }
  2717. evaluation.IsHemorrhage = is_hemorrhage
  2718. if is_hemorrhage == 1 {
  2719. if dataBody["hemorrhage"] != nil && reflect.TypeOf(dataBody["hemorrhage"]).String() == "string" {
  2720. hemorrhage, _ := dataBody["hemorrhage"].(string)
  2721. evaluation.Hemorrhage = hemorrhage
  2722. }
  2723. if dataBody["hemorrhage_other"] != nil && reflect.TypeOf(dataBody["hemorrhage_other"]).String() == "string" {
  2724. hemorrhage_other, _ := dataBody["hemorrhage_other"].(string)
  2725. evaluation.HemorrhageOther = hemorrhage_other
  2726. }
  2727. }
  2728. } else {
  2729. evaluation.IsHemorrhage = 0
  2730. }
  2731. if dataBody["blood_access_internal_fistula"] != nil && reflect.TypeOf(dataBody["blood_access_internal_fistula"]).String() == "string" {
  2732. blood_access_internal_fistula, _ := dataBody["blood_access_internal_fistula"].(string)
  2733. evaluation.BloodAccessInternalFistula = blood_access_internal_fistula
  2734. }
  2735. if dataBody["internal_fistula_other"] != nil && reflect.TypeOf(dataBody["internal_fistula_other"]).String() == "string" {
  2736. internal_fistula_other, _ := dataBody["internal_fistula_other"].(string)
  2737. evaluation.InternalFistulaOther = internal_fistula_other
  2738. }
  2739. if dataBody["blood_access_noise"] != nil && reflect.TypeOf(dataBody["blood_access_noise"]).String() == "float64" {
  2740. blood_access_noise := int64(dataBody["blood_access_noise"].(float64))
  2741. evaluation.BloodAccessNoise = blood_access_noise
  2742. }
  2743. if dataBody["puncture_way"] != nil && reflect.TypeOf(dataBody["puncture_way"]).String() == "string" {
  2744. //puncture_way := int64(dataBody["puncture_way"].(float64))
  2745. puncture_way := dataBody["puncture_way"].(string)
  2746. evaluation.PunctureWay = puncture_way
  2747. }
  2748. if dataBody["venous_catheterization"] != nil && reflect.TypeOf(dataBody["venous_catheterization"]).String() == "float64" {
  2749. venous_catheterization := int64(dataBody["venous_catheterization"].(float64))
  2750. evaluation.VenousCatheterization = venous_catheterization
  2751. }
  2752. if dataBody["venous_catheterization_part"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part"]).String() == "float64" {
  2753. venous_catheterization_part := int64(dataBody["venous_catheterization_part"].(float64))
  2754. evaluation.VenousCatheterizationPart = venous_catheterization_part
  2755. }
  2756. if dataBody["venous_catheterization_part_other"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part_other"]).String() == "string" {
  2757. venous_catheterization_part_other, _ := dataBody["venous_catheterization_part_other"].(string)
  2758. evaluation.VenousCatheterizationPartOther = venous_catheterization_part_other
  2759. }
  2760. if dataBody["ductus_arantii"] != nil && reflect.TypeOf(dataBody["ductus_arantii"]).String() == "string" {
  2761. ductus_arantii, _ := dataBody["ductus_arantii"].(string)
  2762. evaluation.DuctusArantii = ductus_arantii
  2763. }
  2764. if dataBody["emergency_treatment"] != nil && reflect.TypeOf(dataBody["emergency_treatment"]).String() == "float64" {
  2765. emergency_treatment := int64(dataBody["emergency_treatment"].(float64))
  2766. evaluation.EmergencyTreatment = emergency_treatment
  2767. }
  2768. if dataBody["emergency_treatment_other"] != nil && reflect.TypeOf(dataBody["emergency_treatment_other"]).String() == "string" {
  2769. emergency_treatment_other, _ := dataBody["emergency_treatment_other"].(string)
  2770. evaluation.EmergencyTreatmentOther = emergency_treatment_other
  2771. }
  2772. if dataBody["dialysis_count"] != nil && reflect.TypeOf(dataBody["dialysis_count"]).String() == "string" {
  2773. dialysis_count, _ := dataBody["dialysis_count"].(string)
  2774. //count, _ := strconv.ParseInt(dialysis_count, 10, 64)
  2775. evaluation.DialysisCount = dialysis_count
  2776. }
  2777. if dataBody["is_infect"] != nil && reflect.TypeOf(dataBody["is_infect"]).String() == "string" {
  2778. is_infect, _ := dataBody["is_infect"].(string)
  2779. infect, _ := strconv.ParseInt(is_infect, 10, 64)
  2780. evaluation.IsInfect = infect
  2781. }
  2782. if dataBody["exposed"] != nil && reflect.TypeOf(dataBody["exposed"]).String() == "string" {
  2783. exposed, _ := strconv.ParseFloat(dataBody["exposed"].(string), 64)
  2784. evaluation.Exposed = exposed
  2785. }
  2786. if dataBody["skin"] != nil && reflect.TypeOf(dataBody["skin"]).String() == "string" {
  2787. skin, _ := dataBody["skin"].(string)
  2788. //skins, _ := strconv.ParseInt(skin, 10, 64)
  2789. evaluation.Skin = skin
  2790. }
  2791. if dataBody["skin_other"] != nil && reflect.TypeOf(dataBody["skin_other"]).String() == "string" {
  2792. skin_other, _ := dataBody["skin_other"].(string)
  2793. evaluation.SkinOther = skin_other
  2794. }
  2795. if dataBody["infect_other"] != nil && reflect.TypeOf(dataBody["infect_other"]).String() == "string" {
  2796. infect_other, _ := dataBody["infect_other"].(string)
  2797. evaluation.InfectOther = infect_other
  2798. }
  2799. if dataBody["ductus_arantii_other"] != nil && reflect.TypeOf(dataBody["ductus_arantii_other"]).String() == "string" {
  2800. ductus_arantii_other, _ := dataBody["ductus_arantii_other"].(string)
  2801. evaluation.DuctusArantiiOther = ductus_arantii_other
  2802. }
  2803. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  2804. punctureNeedle, _ := dataBody["puncture_needle"].(string)
  2805. evaluation.PunctureNeedle = punctureNeedle
  2806. }
  2807. if dataBody["humor_excessive_symptom"] != nil && reflect.TypeOf(dataBody["humor_excessive_symptom"]).String() == "string" {
  2808. humor_excessive_symptom, _ := dataBody["humor_excessive_symptom"].(string)
  2809. evaluation.HumorExcessiveSymptom = humor_excessive_symptom
  2810. }
  2811. if dataBody["pinholing"] != nil && reflect.TypeOf(dataBody["pinholing"]).String() == "string" {
  2812. pinholing := dataBody["pinholing"].(string)
  2813. evaluation.Phinholing = pinholing
  2814. }
  2815. if dataBody["catheter_suture"] != nil && reflect.TypeOf(dataBody["catheter_suture"]).String() == "string" {
  2816. catheter_suture := dataBody["catheter_suture"].(string)
  2817. evaluation.CatheterSuture = catheter_suture
  2818. }
  2819. if dataBody["catheter_suture_other"] != nil && reflect.TypeOf(dataBody["catheter_suture_other"]).String() == "string" {
  2820. catheter_suture_other := dataBody["catheter_suture_other"].(string)
  2821. evaluation.CatheterSutureOther = catheter_suture_other
  2822. }
  2823. if dataBody["urine_volume"] != nil && reflect.TypeOf(dataBody["urine_volume"]).String() == "string" {
  2824. urine_volume, _ := strconv.ParseFloat(dataBody["urine_volume"].(string), 64)
  2825. evaluation.UrineVolume = urine_volume
  2826. }
  2827. if dataBody["edema"] != nil && reflect.TypeOf(dataBody["edema"]).String() == "string" {
  2828. edema := dataBody["edema"].(string)
  2829. evaluation.Edema = edema
  2830. }
  2831. if dataBody["special_treatment"] != nil && reflect.TypeOf(dataBody["special_treatment"]).String() == "string" {
  2832. specialTreatment := dataBody["special_treatment"].(string)
  2833. evaluation.SpecialTreatment = specialTreatment
  2834. }
  2835. if dataBody["catheter_maintenance"] != nil && reflect.TypeOf(dataBody["catheter_maintenance"]).String() == "string" {
  2836. catheter_maintenance := dataBody["catheter_maintenance"].(string)
  2837. evaluation.CatheterMaintenance = catheter_maintenance
  2838. }
  2839. if dataBody["thromubus_type"] != nil && reflect.TypeOf(dataBody["thromubus_type"]).String() == "float64" {
  2840. thromubusType := int64(dataBody["thromubus_type"].(float64))
  2841. evaluation.ThromubusType = thromubusType
  2842. }
  2843. if dataBody["thrombus_av"] != nil && reflect.TypeOf(dataBody["thrombus_av"]).String() == "string" {
  2844. thrombus_av := dataBody["thrombus_av"].(string)
  2845. evaluation.ThrombusAv = thrombus_av
  2846. }
  2847. if dataBody["thromubus_a"] != nil && reflect.TypeOf(dataBody["thromubus_a"]).String() == "string" {
  2848. thromubus_a := dataBody["thromubus_a"].(string)
  2849. evaluation.ThromubusA = thromubus_a
  2850. }
  2851. if dataBody["thromubus_v"] != nil && reflect.TypeOf(dataBody["thromubus_v"]).String() == "string" {
  2852. thromubus_v := dataBody["thromubus_v"].(string)
  2853. evaluation.ThromubusV = thromubus_v
  2854. }
  2855. if dataBody["dehydration"] != nil && reflect.TypeOf(dataBody["dehydration"]).String() == "string" {
  2856. dehydration := dataBody["dehydration"].(string)
  2857. evaluation.Dehydration = dehydration
  2858. }
  2859. if dataBody["period"] != nil && reflect.TypeOf(dataBody["period"]).String() == "float64" {
  2860. period := int64(dataBody["period"].(float64))
  2861. evaluation.Period = period
  2862. }
  2863. if dataBody["estimated_food_intake"] != nil && reflect.TypeOf(dataBody["estimated_food_intake"]).String() == "string" {
  2864. estimated_food_intake := dataBody["estimated_food_intake"].(string)
  2865. evaluation.EstimatedFoodIntake = estimated_food_intake
  2866. }
  2867. if dataBody["blood_pressure_during_dialysis"] != nil && reflect.TypeOf(dataBody["blood_pressure_during_dialysis"]).String() == "string" {
  2868. blood_pressure_during_dialysis := dataBody["blood_pressure_during_dialysis"].(string)
  2869. evaluation.BloodPressureDuringDialysis = blood_pressure_during_dialysis
  2870. }
  2871. if dataBody["pre_dialysis_drugs"] != nil && reflect.TypeOf(dataBody["pre_dialysis_drugs"]).String() == "string" {
  2872. pre_dialysis_drugs := dataBody["pre_dialysis_drugs"].(string)
  2873. evaluation.PreDialysisDrugs = pre_dialysis_drugs
  2874. }
  2875. if dataBody["urea_befor"] != nil && reflect.TypeOf(dataBody["urea_befor"]).String() == "string" {
  2876. urea_befor := dataBody["urea_befor"].(string)
  2877. evaluation.UreaBefor = urea_befor
  2878. }
  2879. if dataBody["suction"] != nil && reflect.TypeOf(dataBody["suction"]).String() == "string" {
  2880. suction := dataBody["suction"].(string)
  2881. evaluation.Suction = suction
  2882. }
  2883. if dataBody["weight_befor_remake"] != nil && reflect.TypeOf(dataBody["weight_befor_remake"]).String() == "string" {
  2884. weight_befor_remake := dataBody["weight_befor_remake"].(string)
  2885. evaluation.WeightBeforRemake = weight_befor_remake
  2886. }
  2887. if dataBody["height"] != nil && reflect.TypeOf(dataBody["height"]).String() == "string" {
  2888. height := dataBody["height"].(string)
  2889. evaluation.Height = height
  2890. }
  2891. if dataBody["age"] != nil && reflect.TypeOf(dataBody["age"]).String() == "string" {
  2892. age := dataBody["age"].(string)
  2893. evaluation.Age = age
  2894. }
  2895. if dataBody["his_department"] != nil && reflect.TypeOf(dataBody["his_department"]).String() == "string" {
  2896. his_department := dataBody["his_department"].(string)
  2897. evaluation.HisDepartment = his_department
  2898. }
  2899. if dataBody["his_bed"] != nil && reflect.TypeOf(dataBody["his_bed"]).String() == "string" {
  2900. his_bed := dataBody["his_bed"].(string)
  2901. evaluation.HisBed = his_bed
  2902. }
  2903. if dataBody["point_puncture"] != nil && reflect.TypeOf(dataBody["point_puncture"]).String() == "string" {
  2904. point_puncture := dataBody["point_puncture"].(string)
  2905. evaluation.PointPuncture = point_puncture
  2906. }
  2907. return
  2908. }
  2909. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  2910. dataBody := make(map[string]interface{}, 0)
  2911. err := json.Unmarshal(data, &dataBody)
  2912. if err != nil {
  2913. utils.ErrorLog(err.Error())
  2914. code = enums.ErrorCodeParamWrong
  2915. return
  2916. }
  2917. timeLayout := "2006-01-02"
  2918. loc, _ := time.LoadLocation("Local")
  2919. isChild := false
  2920. if action == "create" {
  2921. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2922. utils.ErrorLog("advice_type")
  2923. code = enums.ErrorCodeParamWrong
  2924. return
  2925. }
  2926. adviceType := int64(dataBody["advice_type"].(float64))
  2927. if adviceType != 1 && adviceType != 2 {
  2928. utils.ErrorLog("advice_type != 1&&2")
  2929. code = enums.ErrorCodeParamWrong
  2930. return
  2931. }
  2932. advice.AdviceType = adviceType
  2933. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2934. utils.ErrorLog("advice_date")
  2935. code = enums.ErrorCodeParamWrong
  2936. return
  2937. }
  2938. adviceDate, _ := dataBody["advice_date"].(string)
  2939. if len(adviceDate) == 0 {
  2940. utils.ErrorLog("len(adviceDate) == 0")
  2941. code = enums.ErrorCodeParamWrong
  2942. return
  2943. }
  2944. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  2945. if err != nil {
  2946. utils.ErrorLog(err.Error())
  2947. code = enums.ErrorCodeParamWrong
  2948. return
  2949. }
  2950. advice.AdviceDate = theTime.Unix()
  2951. advice.RecordDate = theTime.Unix()
  2952. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  2953. parentId := int64(dataBody["parent_id"].(float64))
  2954. advice.ParentId = parentId
  2955. if parentId > 0 {
  2956. isChild = true
  2957. }
  2958. }
  2959. } else {
  2960. isChild = advice.ParentId > 0
  2961. }
  2962. if !isChild {
  2963. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2964. utils.ErrorLog("start_time")
  2965. code = enums.ErrorCodeParamWrong
  2966. return
  2967. }
  2968. startTime, _ := dataBody["start_time"].(string)
  2969. if len(startTime) == 0 {
  2970. utils.ErrorLog("len(start_time) == 0")
  2971. code = enums.ErrorCodeParamWrong
  2972. return
  2973. }
  2974. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  2975. if err != nil {
  2976. utils.ErrorLog(err.Error())
  2977. code = enums.ErrorCodeParamWrong
  2978. return
  2979. }
  2980. advice.StartTime = theTime.Unix()
  2981. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  2982. deliveryWay, _ := dataBody["delivery_way"].(string)
  2983. advice.DeliveryWay = deliveryWay
  2984. }
  2985. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  2986. executionFrequency, _ := dataBody["execution_frequency"].(string)
  2987. advice.ExecutionFrequency = executionFrequency
  2988. }
  2989. }
  2990. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  2991. deliveryWay, _ := dataBody["delivery_way"].(string)
  2992. advice.DeliveryWay = deliveryWay
  2993. }
  2994. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  2995. executionFrequency, _ := dataBody["execution_frequency"].(string)
  2996. advice.ExecutionFrequency = executionFrequency
  2997. }
  2998. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  2999. utils.ErrorLog("advice_name")
  3000. code = enums.ErrorCodeParamWrong
  3001. return
  3002. }
  3003. adviceName, _ := dataBody["advice_name"].(string)
  3004. if len(adviceName) == 0 {
  3005. utils.ErrorLog("len(advice_name) == 0")
  3006. code = enums.ErrorCodeParamWrong
  3007. return
  3008. }
  3009. advice.AdviceName = adviceName
  3010. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  3011. adviceDsc, _ := dataBody["advice_desc"].(string)
  3012. advice.AdviceDesc = adviceDsc
  3013. }
  3014. if dataBody["way"] == nil {
  3015. advice.Way = 0
  3016. } else {
  3017. if dataBody["way"] != nil || reflect.TypeOf(dataBody["way"]).String() == "float64" {
  3018. way := int64(dataBody["way"].(float64))
  3019. advice.Way = way
  3020. }
  3021. }
  3022. if dataBody["drug_id"] == nil {
  3023. advice.DrugId = 0
  3024. } else {
  3025. if dataBody["drug_id"] != nil || reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
  3026. drug_id := int64(dataBody["drug_id"].(float64))
  3027. advice.DrugId = drug_id
  3028. }
  3029. }
  3030. if dataBody["drug_name_id"] == nil {
  3031. advice.DrugNameId = 0
  3032. } else {
  3033. if dataBody["drug_name_id"] != nil || reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
  3034. drug_name_id := int64(dataBody["drug_name_id"].(float64))
  3035. advice.DrugNameId = drug_name_id
  3036. }
  3037. }
  3038. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  3039. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  3040. advice.SingleDose = singleDose
  3041. }
  3042. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  3043. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  3044. advice.SingleDoseUnit = singleDoseUnit
  3045. }
  3046. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  3047. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  3048. advice.DrugSpec = drugSpec
  3049. }
  3050. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  3051. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  3052. advice.DrugSpecUnit = drugSpecUnit
  3053. }
  3054. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  3055. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  3056. advice.PrescribingNumber = prescribingNumber
  3057. }
  3058. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  3059. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  3060. advice.PrescribingNumberUnit = prescribingNumberUnit
  3061. }
  3062. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3063. remark, _ := dataBody["remark"].(string)
  3064. advice.Remark = remark
  3065. }
  3066. return
  3067. }
  3068. func (c *PatientApiController) GetPatientEducation() {
  3069. patientID, _ := c.GetInt64("patient_id", 0)
  3070. page, _ := c.GetInt64("page", 0)
  3071. limit, _ := c.GetInt64("limit", 0)
  3072. startTime := c.GetString("start_time", "")
  3073. endTime := c.GetString("end_time", "")
  3074. if page <= 0 {
  3075. page = 1
  3076. }
  3077. if limit <= 0 {
  3078. limit = 10
  3079. }
  3080. if patientID <= 0 {
  3081. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3082. return
  3083. }
  3084. timeLayout := "2006-01-02"
  3085. loc, _ := time.LoadLocation("Local")
  3086. var theStartTIme int64
  3087. if len(startTime) > 0 {
  3088. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3089. if err != nil {
  3090. theStartTIme = 0
  3091. }
  3092. theStartTIme = theTime.Unix()
  3093. }
  3094. var theEndtTIme int64
  3095. if len(endTime) > 0 {
  3096. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3097. if err != nil {
  3098. theEndtTIme = 0
  3099. }
  3100. theEndtTIme = theTime.Unix()
  3101. }
  3102. adminUserInfo := c.GetMobileAdminUserInfo()
  3103. edus, total, _ := service.GetPatientTreatmentSummaryList(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme)
  3104. c.ServeSuccessJSON(map[string]interface{}{
  3105. "total": total,
  3106. "edus": edus,
  3107. })
  3108. return
  3109. }
  3110. func (c *PatientApiController) GetPatientSchedulesList() {
  3111. patientID, _ := c.GetInt64("patient_id", 0)
  3112. page, _ := c.GetInt64("page", 0)
  3113. limit, _ := c.GetInt64("limit", 0)
  3114. if patientID <= 0 {
  3115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3116. return
  3117. }
  3118. adminUserInfo := c.GetMobileAdminUserInfo()
  3119. todayTime := time.Now().Format("2006-01-02")
  3120. timeLayout := "2006-01-02 15:04:05"
  3121. loc, _ := time.LoadLocation("Local")
  3122. var theStartTime int64
  3123. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  3124. theStartTime = theTime.Unix()
  3125. schedules, _ := service.GetPatientScheduleList(adminUserInfo.Org.Id, patientID, page, limit, theStartTime)
  3126. if len(schedules) > 0 {
  3127. for index, item := range schedules {
  3128. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  3129. schedules[index].Week = int64(week)
  3130. }
  3131. }
  3132. c.ServeSuccessJSON(map[string]interface{}{
  3133. "schedules": schedules,
  3134. })
  3135. return
  3136. }
  3137. func (c *PatientApiController) GetRecords() {
  3138. patientID, _ := c.GetInt64("patient_id", 0)
  3139. page, _ := c.GetInt64("page", 0)
  3140. limit, _ := c.GetInt64("limit", 0)
  3141. startTime := c.GetString("start_time", "")
  3142. endTime := c.GetString("end_time", "")
  3143. mode_id, _ := c.GetInt64("mode_id", 0)
  3144. if page <= 0 {
  3145. page = 1
  3146. }
  3147. if limit <= 0 {
  3148. limit = 10
  3149. }
  3150. if patientID <= 0 {
  3151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3152. return
  3153. }
  3154. timeLayout := "2006-01-02"
  3155. loc, _ := time.LoadLocation("Local")
  3156. var theStartTIme int64
  3157. if len(startTime) > 0 {
  3158. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3159. if err != nil {
  3160. theStartTIme = 0
  3161. }
  3162. theStartTIme = theTime.Unix()
  3163. }
  3164. var theEndtTIme int64
  3165. if len(endTime) > 0 {
  3166. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3167. if err != nil {
  3168. theEndtTIme = 0
  3169. }
  3170. theEndtTIme = theTime.Unix()
  3171. }
  3172. adminUserInfo := c.GetMobileAdminUserInfo()
  3173. records, total, _ := service.GetPatientDialysisRecord(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  3174. c.ServeSuccessJSON(map[string]interface{}{
  3175. "total": total,
  3176. "records": records,
  3177. })
  3178. return
  3179. }
  3180. func (c *PatientApiController) GetPatientMonitor() {
  3181. partition, _ := c.GetInt64("partition")
  3182. monitorDate := c.GetString("date")
  3183. patient_id, _ := c.GetInt64("patient_id")
  3184. timeLayout := "2006-01-02"
  3185. loc, _ := time.LoadLocation("Local")
  3186. var theStartTime int64
  3187. if len(monitorDate) > 0 {
  3188. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  3189. if err != nil {
  3190. theStartTime = 0
  3191. }
  3192. theStartTime = theTime.Unix()
  3193. }
  3194. adminInfo := c.GetMobileAdminUserInfo()
  3195. orgID := adminInfo.Org.Id
  3196. monitor, err := service.GetMonitorRecord(orgID, theStartTime, partition, patient_id)
  3197. fmt.Println("monitor-------------------", monitor)
  3198. if err != nil {
  3199. c.ErrorLog("获取排班信息失败:%v", err)
  3200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3201. } else {
  3202. if len(monitor) > 0 {
  3203. //获取所有床位
  3204. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  3205. //获取所有分区
  3206. zoneList, _ := service.GetAllZoneByList(orgID)
  3207. //获取透析处方
  3208. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  3209. //获取透前评估
  3210. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  3211. //获取上机
  3212. dialysisOrders, _ := service.GetAllDialysisOrdersByListSix(orgID, theStartTime)
  3213. //获取透后
  3214. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  3215. //获取透后监测
  3216. monitorlist, _ := service.GetAllMonitorList(orgID, theStartTime)
  3217. //获取所有的患者
  3218. patients, _ := service.GetAllPatientListByListOne(orgID)
  3219. //获取所有透析模式
  3220. treatments, _ := service.GetAllTreatModeByList(orgID)
  3221. for key, item := range monitor {
  3222. // 获取床位信息
  3223. for _, it := range numberList {
  3224. if item.BedId == it.ID {
  3225. monitor[key].DeviceNumber = it
  3226. break
  3227. }
  3228. }
  3229. //获取分区信息
  3230. for _, it := range zoneList {
  3231. if item.PartitionId == it.ID {
  3232. monitor[key].DeviceZone = it
  3233. }
  3234. }
  3235. for _, prescription := range prescriptions {
  3236. if item.PatientId == prescription.PatientId {
  3237. monitor[key].Prescription = prescription
  3238. break
  3239. }
  3240. }
  3241. // 透前评估
  3242. for _, assessmentBefore := range assessmentBefores {
  3243. if item.PatientId == assessmentBefore.PatientId {
  3244. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  3245. break
  3246. }
  3247. }
  3248. // 透析上下机
  3249. for _, dialysisOrder := range dialysisOrders {
  3250. if item.PatientId == dialysisOrder.PatientId {
  3251. monitor[key].DialysisOrder = dialysisOrder
  3252. break
  3253. }
  3254. }
  3255. // 治疗小节
  3256. for _, afterDislysis := range AssessmentAfterDislysis {
  3257. if item.PatientId == afterDislysis.PatientId {
  3258. monitor[key].AssessmentAfterDislysis = afterDislysis
  3259. break
  3260. }
  3261. }
  3262. for _, it := range monitorlist {
  3263. if item.PatientId == it.PatientId {
  3264. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  3265. }
  3266. }
  3267. for _, patient := range patients {
  3268. if item.PatientId == patient.ID {
  3269. monitor[key].MonitorPatients = patient
  3270. break
  3271. }
  3272. }
  3273. for _, treatment := range treatments {
  3274. if item.ModeId == treatment.ID {
  3275. monitor[key].TreatmentMode = treatment
  3276. break
  3277. }
  3278. }
  3279. }
  3280. }
  3281. }
  3282. //获取患者的透析次数
  3283. count, err := service.GetDialysisCount(orgID, partition)
  3284. patients, err := service.GetAllpatientThirty(orgID)
  3285. if err == nil {
  3286. c.ServeSuccessJSON(map[string]interface{}{
  3287. "monitor": monitor,
  3288. "patientCount": count,
  3289. "patients": patients,
  3290. })
  3291. } else {
  3292. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3293. }
  3294. }
  3295. // /m/api/monitor/patient [get] 搜索病人的测量记录
  3296. // @param keyword:string 病人姓名或透析号
  3297. // @param page:int
  3298. func (this *PatientApiController) SearchMonitorPatient() {
  3299. keyword := this.GetString("keyword")
  3300. page, _ := this.GetInt("page")
  3301. if page <= 0 {
  3302. page = 1
  3303. }
  3304. if len(keyword) == 0 {
  3305. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3306. return
  3307. }
  3308. adminUserInfo := this.GetMobileAdminUserInfo()
  3309. monitors, getMonitorErr := service.MobileGetMonitorsWithPatient(adminUserInfo.Org.Id, keyword, page)
  3310. if getMonitorErr != nil {
  3311. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3312. return
  3313. } else {
  3314. this.ServeSuccessJSON(map[string]interface{}{
  3315. "monitor": monitors,
  3316. })
  3317. }
  3318. }
  3319. func (c *PatientApiController) GetPatientDialysisSolutionList() {
  3320. id, _ := c.GetInt64("id", 0)
  3321. page, _ := c.GetInt64("page", 0)
  3322. limit, _ := c.GetInt64("limit", 0)
  3323. if id <= 0 {
  3324. c.ServeSuccessJSON(map[string]interface{}{
  3325. "solutions": nil,
  3326. })
  3327. return
  3328. }
  3329. if page <= 0 {
  3330. page = 1
  3331. }
  3332. if limit <= 0 {
  3333. limit = 10
  3334. }
  3335. adminInfo := c.GetMobileAdminUserInfo()
  3336. solutions, total, _ := service.GetPatientDialysisSolutionList(adminInfo.Org.Id, id, page, limit)
  3337. c.ServeSuccessJSON(map[string]interface{}{
  3338. "solutions": solutions,
  3339. "total": total,
  3340. })
  3341. return
  3342. }
  3343. // GetDoctorAdvices 医嘱列表
  3344. func (c *PatientApiController) GetDoctorAdvices() {
  3345. id, _ := c.GetInt64("id", 0)
  3346. adviceType, _ := c.GetInt64("advice_type", 0)
  3347. stopType, _ := c.GetInt64("stop_state", 0)
  3348. startTime := c.GetString("start_time", "")
  3349. endTime := c.GetString("end_time", "")
  3350. keywords := c.GetString("keywords", "")
  3351. need, _ := c.GetInt64("need_doctor", 0)
  3352. adminUserInfo := c.GetMobileAdminUserInfo()
  3353. timeLayout := "2006-01-02"
  3354. loc, _ := time.LoadLocation("Local")
  3355. var theStartTIme int64
  3356. if len(startTime) > 0 {
  3357. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3358. if err != nil {
  3359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3360. return
  3361. }
  3362. theStartTIme = theTime.Unix()
  3363. }
  3364. var theEndtTIme int64
  3365. if len(endTime) > 0 {
  3366. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3367. if err != nil {
  3368. utils.ErrorLog(err.Error())
  3369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3370. return
  3371. }
  3372. theEndtTIme = theTime.Unix()
  3373. }
  3374. advices, total, _ := service.GetDoctorAdviceList(adminUserInfo.Org.Id, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords)
  3375. if need == 1 {
  3376. users, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  3377. c.ServeSuccessJSON(map[string]interface{}{
  3378. "advices": advices,
  3379. "total": total,
  3380. "users": users,
  3381. })
  3382. } else {
  3383. c.ServeSuccessJSON(map[string]interface{}{
  3384. "advices": advices,
  3385. "total": total,
  3386. "users": []string{},
  3387. })
  3388. }
  3389. return
  3390. }
  3391. func (c *PatientApiController) GetPrintDialysisOrder() {
  3392. xtno := c.GetString("xtno")
  3393. xtdate := c.GetString("xtdate")
  3394. timeLayout := "2006-01-02"
  3395. loc, _ := time.LoadLocation("Local")
  3396. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  3397. if err != nil {
  3398. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3399. return
  3400. }
  3401. xttime := theTime.Unix()
  3402. //获取当前日期月份的第一天
  3403. firstmonth := service.GetFirstDateOfMonth(theTime)
  3404. firstMonthDate := firstmonth.Unix()
  3405. operatorIDs := make([]int64, 0)
  3406. adminUserInfo := c.GetMobileAdminUserInfo()
  3407. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  3408. patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.Org.Id, xtno, xttime)
  3409. //透析单
  3410. dialysisOrder, _ := service.MobileGetSchedualDialysisRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3411. if dialysisOrder != nil {
  3412. if dialysisOrder.FinishNurse > 0 {
  3413. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  3414. }
  3415. if dialysisOrder.StartNurse > 0 {
  3416. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  3417. }
  3418. }
  3419. last_order, _ := service.GetLastTimeOrder(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3420. //透前评估
  3421. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3422. //透后评估
  3423. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3424. if AssessmentAfterDislysis.Modifier > 0 {
  3425. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  3426. }
  3427. //透析处方
  3428. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3429. if dialysisPrescription.PrescriptionDoctor > 0 {
  3430. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  3431. }
  3432. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3433. patientInfo.TotalDialysis = dialysis_count
  3434. //临时医嘱
  3435. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3436. fmt.Println("DoctorAdvice3223323323232323223323323223332232332wode", DoctorAdvice)
  3437. hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3438. config, err := service.GetHisDoctorConfig(adminUserInfo.Org.Id)
  3439. project_config, _ := service.GetHisProjectConfig(adminUserInfo.Org.Id)
  3440. projects, _ := service.FindAllHisProjectById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3441. if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
  3442. for _, item := range projects {
  3443. cnt, _ := strconv.ParseFloat(item.Count, 64)
  3444. var advice models.HisDoctorAdviceInfo
  3445. advice.ID = item.ID
  3446. advice.Checker = item.Checker
  3447. advice.CheckTime = item.CheckTime
  3448. advice.CheckState = item.CheckState
  3449. advice.ExecutionState = item.ExecutionState
  3450. advice.ExecutionStaff = item.ExecutionStaff
  3451. //advice.PrescribingNumber = float64(item.Count)
  3452. advice.PrescribingNumber = cnt
  3453. advice.PrescribingNumberUnit = item.Unit
  3454. advice.AdviceDoctor = item.Doctor
  3455. if item.Type == 3 {
  3456. advice.AdviceName = item.GoodInfo.GoodName
  3457. advice.PrescribingNumberUnit = item.GoodInfo.PackingUnit
  3458. } else if item.Type == 2 {
  3459. advice.AdviceName = item.HisProject.ProjectName
  3460. }
  3461. advice.StartTime = item.StartTime
  3462. hisAdvice = append(hisAdvice, &advice)
  3463. }
  3464. }
  3465. if len(DoctorAdvice) > 0 {
  3466. for _, item := range DoctorAdvice {
  3467. if item.AdviceDoctor > 0 {
  3468. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  3469. }
  3470. if item.ExecutionStaff > 0 {
  3471. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  3472. }
  3473. if item.Checker > 0 {
  3474. operatorIDs = append(operatorIDs, item.Checker)
  3475. }
  3476. }
  3477. }
  3478. //DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3479. //透析监测
  3480. Record, _ := service.FindAllMonitorRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3481. //透析小结
  3482. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3483. //接诊评估
  3484. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3485. //相关操作对应的操作人
  3486. //operators, _ := service.GetAdminUserES(adminUserInfo.Org.Id, adminUserInfo.App.Id, operatorIDs)
  3487. operators, err := service.GetAllStarfEs(adminUserInfo.Org.Id)
  3488. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3489. check, _ := service.FindDoubleCheckById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3490. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.Org.Id)
  3491. lastWeight, _ := service.MobileGetLast(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3492. if config.IsOpen == 1 {
  3493. c.ServeSuccessJSON(map[string]interface{}{
  3494. "users": adminUser,
  3495. "patientInfo": patientInfo,
  3496. "PredialysisEvaluation": PredialysisEvaluation,
  3497. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  3498. "dialysisPrescription": dialysisPrescription,
  3499. "advices": hisAdvice,
  3500. "monitors": Record,
  3501. "summary": TreatmentSummary,
  3502. "receiverTreatmentAccess": receiverTreatmentAccess,
  3503. "dialysisOrder": dialysisOrder,
  3504. "operators": operators,
  3505. "org_template_info": templateInfo,
  3506. "check": check,
  3507. "dialysiscount": dialysiscount,
  3508. "last_order": last_order,
  3509. "projects": projects,
  3510. "project_config": project_config,
  3511. "lastWeight": lastWeight,
  3512. })
  3513. }
  3514. if config.IsOpen == 0 || config.IsOpen == 2 {
  3515. c.ServeSuccessJSON(map[string]interface{}{
  3516. "users": adminUser,
  3517. "patientInfo": patientInfo,
  3518. "PredialysisEvaluation": PredialysisEvaluation,
  3519. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  3520. "dialysisPrescription": dialysisPrescription,
  3521. "advices": DoctorAdvice,
  3522. "monitors": Record,
  3523. "summary": TreatmentSummary,
  3524. "receiverTreatmentAccess": receiverTreatmentAccess,
  3525. "dialysisOrder": dialysisOrder,
  3526. "operators": operators,
  3527. "org_template_info": templateInfo,
  3528. "check": check,
  3529. "dialysiscount": dialysiscount,
  3530. "last_order": last_order,
  3531. "projects": projects,
  3532. "project_config": project_config,
  3533. "lastWeight": lastWeight,
  3534. })
  3535. }
  3536. }
  3537. func (c *PatientApiController) CreateGroupAdvice() {
  3538. is_child, _ := c.GetInt64("is_child", 0)
  3539. if is_child == 1 {
  3540. patient, _ := c.GetInt64("id", 0)
  3541. if patient <= 0 {
  3542. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3543. return
  3544. }
  3545. adminUserInfo := c.GetMobileAdminUserInfo()
  3546. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  3547. if patientInfo.ID == 0 {
  3548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3549. return
  3550. }
  3551. group_no, _ := c.GetInt64("group_no")
  3552. if group_no <= 0 {
  3553. group_no = 0
  3554. }
  3555. dataBody := make(map[string]interface{}, 0)
  3556. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3557. if err != nil {
  3558. utils.ErrorLog(err.Error())
  3559. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3560. return
  3561. }
  3562. timeLayout := "2006-01-02"
  3563. loc, _ := time.LoadLocation("Local")
  3564. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  3565. utils.ErrorLog("advice_type")
  3566. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3567. return
  3568. }
  3569. adviceType := int64(dataBody["advice_type"].(float64))
  3570. if adviceType != 1 && adviceType != 2 {
  3571. utils.ErrorLog("advice_type != 1&&2")
  3572. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3573. return
  3574. }
  3575. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3576. utils.ErrorLog("start_time")
  3577. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3578. return
  3579. }
  3580. startTime2, _ := dataBody["start_time"].(string)
  3581. time_arr := strings.Split(startTime2, " ")
  3582. if len(time_arr) > 0 {
  3583. startTime2 = time_arr[0]
  3584. }
  3585. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  3586. utils.ErrorLog("advice_date")
  3587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3588. return
  3589. }
  3590. advice_date, _ := dataBody["advice_date"].(string)
  3591. var advicedateunix int64
  3592. if len(advice_date) > 0 {
  3593. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  3594. if err != nil {
  3595. fmt.Println(err)
  3596. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3597. return
  3598. }
  3599. advicedateunix = theTime.Unix()
  3600. }
  3601. adviceDate := startTime2
  3602. if len(adviceDate) == 0 {
  3603. utils.ErrorLog("len(adviceDate) == 0")
  3604. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3605. return
  3606. }
  3607. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  3608. if err != nil {
  3609. utils.ErrorLog(err.Error())
  3610. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3611. return
  3612. }
  3613. AdviceDate := advicedateunix
  3614. RecordDate := advicedateunix
  3615. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3616. utils.ErrorLog("start_time")
  3617. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3618. return
  3619. }
  3620. startTime, _ := dataBody["start_time"].(string)
  3621. if len(startTime) == 0 {
  3622. utils.ErrorLog("len(start_time) == 0")
  3623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3624. return
  3625. }
  3626. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  3627. theTimeOne, _ := time.ParseInLocation("2006-01-02 15:04:05", startTime2+" 00:00:00", loc)
  3628. if err != nil {
  3629. utils.ErrorLog(err.Error())
  3630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3631. return
  3632. }
  3633. StartTime := theTime.Unix()
  3634. Remark := ""
  3635. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3636. remark, _ := dataBody["remark"].(string)
  3637. Remark = remark
  3638. }
  3639. Startdate := int64(dataBody["record_date"].(float64))
  3640. var advices []*models.GroupAdvice
  3641. // utils.TraceLog("%+v", dataBody["adviceNames"])
  3642. if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
  3643. utils.ErrorLog("adviceNames")
  3644. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3645. return
  3646. }
  3647. adviceNames := dataBody["adviceNames"].([]interface{})
  3648. for _, adviceNameMap := range adviceNames {
  3649. adviceNameM := adviceNameMap.(map[string]interface{})
  3650. var advice models.GroupAdvice
  3651. advice.Remark = Remark
  3652. advice.AdviceType = adviceType
  3653. advice.StartTime = StartTime
  3654. if adminUserInfo.Org.Id == 10340 {
  3655. advice.AdviceDate = AdviceDate
  3656. advice.RecordDate = RecordDate
  3657. }
  3658. if adminUserInfo.Org.Id != 10340 {
  3659. advice.AdviceDate = theTimeOne.Unix()
  3660. advice.RecordDate = theTimeOne.Unix()
  3661. }
  3662. advice.Status = 1
  3663. advice.CreatedTime = time.Now().Unix()
  3664. advice.UpdatedTime = time.Now().Unix()
  3665. advice.StopState = 2
  3666. advice.ExecutionState = 2
  3667. advice.UserOrgId = adminUserInfo.Org.Id
  3668. advice.PatientId = patientInfo.ID
  3669. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  3670. advice.IsSettle = 2
  3671. //入口
  3672. errcode := c.setAdviceWithJSON(&advice, adviceNameM)
  3673. if errcode > 0 {
  3674. c.ServeFailJSONWithSGJErrorCode(errcode)
  3675. return
  3676. }
  3677. if adviceNameM["subdrugs"] != nil && reflect.TypeOf(adviceNameM["subdrugs"]).String() == "[]interface {}" {
  3678. subdrugs := adviceNameM["subdrugs"].([]interface{})
  3679. if len(subdrugs) > 0 {
  3680. for _, subdrug := range subdrugs {
  3681. var s models.GroupAdvice
  3682. s.Remark = Remark
  3683. s.AdviceType = adviceType
  3684. s.StartTime = StartTime
  3685. s.AdviceDate = AdviceDate
  3686. s.RecordDate = RecordDate
  3687. s.Status = 1
  3688. s.CreatedTime = time.Now().Unix()
  3689. s.UpdatedTime = time.Now().Unix()
  3690. s.StopState = 2
  3691. s.ExecutionState = 2
  3692. s.UserOrgId = adminUserInfo.Org.Id
  3693. s.PatientId = patientInfo.ID
  3694. s.AdviceDoctor = adminUserInfo.AdminUser.Id
  3695. s.IsSettle = 2
  3696. errcode := c.setAdviceWithJSON(&s, subdrug.(map[string]interface{}))
  3697. if errcode > 0 {
  3698. c.ServeFailJSONWithSGJErrorCode(errcode)
  3699. return
  3700. }
  3701. advice.Children = append(advice.Children, &s)
  3702. }
  3703. }
  3704. }
  3705. //长沙南雅
  3706. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9671 {
  3707. //查询该患者今日有没有双人核对
  3708. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.Org.Id, patientInfo.ID, RecordDate)
  3709. if check.ID > 0 {
  3710. advice.Checker = check.Modifier
  3711. advice.CheckState = 1
  3712. advice.CheckTime = time.Now().Unix()
  3713. }
  3714. }
  3715. advices = append(advices, &advice)
  3716. }
  3717. // 查询信息规挡的设置天数
  3718. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3719. if infor.ID > 0 {
  3720. var cha_time int64
  3721. timeNowStr := time.Now().Format("2006-01-02")
  3722. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3723. //今日的日期减去设置的日期
  3724. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3725. fmt.Println("RecordDate------------------", Startdate)
  3726. if cha_time >= Startdate {
  3727. //查询审核是否允许
  3728. infor, _ := service.GetDialysisInformationByRecordDate(patient, Startdate, adminUserInfo.Org.Id)
  3729. //申请状态不允许的情况 拒绝修改
  3730. if infor.ApplicationStatus != 1 {
  3731. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3732. return
  3733. }
  3734. }
  3735. }
  3736. newAdvices, createErr := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, group_no)
  3737. finish := models.XtDialysisFinish{
  3738. IsFinish: 1,
  3739. UserOrgId: adminUserInfo.Org.Id,
  3740. Status: 1,
  3741. Ctime: time.Now().Unix(),
  3742. Mtime: 0,
  3743. Module: 4,
  3744. RecordDate: advicedateunix,
  3745. Sourse: 1,
  3746. }
  3747. dialysisFinish, err := service.GetDialysisFinish(adminUserInfo.Org.Id, advicedateunix, 4)
  3748. if dialysisFinish.ID == 0 {
  3749. service.CreateDialysisFinish(finish)
  3750. }
  3751. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  3752. redis := service.RedisClient()
  3753. //清空key 值
  3754. redis.Set(key, "", time.Second)
  3755. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  3756. redis.Set(keyOne, "", time.Second)
  3757. defer redis.Close()
  3758. if createErr != nil {
  3759. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  3760. return
  3761. }
  3762. c.ServeSuccessJSON(map[string]interface{}{
  3763. "msg": "ok",
  3764. "advices": newAdvices,
  3765. })
  3766. return
  3767. } else if is_child == 2 {
  3768. patient, _ := c.GetInt64("id", 0)
  3769. if patient <= 0 {
  3770. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3771. return
  3772. }
  3773. adminUserInfo := c.GetMobileAdminUserInfo()
  3774. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  3775. if patientInfo.ID == 0 {
  3776. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3777. return
  3778. }
  3779. var advice models.DoctorAdvice
  3780. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  3781. if code > 0 {
  3782. c.ServeFailJSONWithSGJErrorCode(code)
  3783. return
  3784. }
  3785. if advice.ParentId > 0 {
  3786. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  3787. if old.ID == 0 || old.PatientId != patient {
  3788. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  3789. return
  3790. }
  3791. if old.StopState == 1 || old.ExecutionState == 1 {
  3792. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  3793. return
  3794. }
  3795. if old.ParentId > 0 {
  3796. advice.ParentId = old.ParentId
  3797. }
  3798. advice.StartTime = old.StartTime
  3799. advice.AdviceDoctor = old.AdviceDoctor
  3800. advice.DeliveryWay = old.DeliveryWay
  3801. advice.ExecutionFrequency = old.ExecutionFrequency
  3802. advice.GroupNo = old.GroupNo
  3803. }
  3804. advice.Status = 1
  3805. advice.CreatedTime = time.Now().Unix()
  3806. advice.UpdatedTime = time.Now().Unix()
  3807. advice.StopState = 2
  3808. advice.ExecutionState = 2
  3809. advice.UserOrgId = adminUserInfo.Org.Id
  3810. advice.PatientId = patient
  3811. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  3812. advice.IsSettle = 2
  3813. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9671 {
  3814. if advice.PrescribingNumber == 0 {
  3815. advice.PrescribingNumber = 1
  3816. }
  3817. //查询该患者今日有没有双人核对
  3818. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.Org.Id, patientInfo.ID, advice.AdviceDate)
  3819. if check.ID > 0 {
  3820. advice.Checker = check.Modifier
  3821. advice.CheckState = 1
  3822. advice.CheckTime = time.Now().Unix()
  3823. }
  3824. }
  3825. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3826. if infor.ID > 0 {
  3827. var cha_time int64
  3828. timeNowStr := time.Now().Format("2006-01-02")
  3829. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3830. //今日的日期减去设置的日期
  3831. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3832. if cha_time >= advice.RecordDate {
  3833. //查询审核是否允许
  3834. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.RecordDate, adminUserInfo.Org.Id)
  3835. //申请状态不允许的情况 拒绝修改
  3836. if infor.ApplicationStatus != 1 {
  3837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3838. return
  3839. }
  3840. }
  3841. }
  3842. err := service.CreateDoctorAdvice(&advice)
  3843. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3844. redis := service.RedisClient()
  3845. //清空key 值
  3846. redis.Set(key, "", time.Second)
  3847. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3848. redis.Set(keyOne, "", time.Second)
  3849. defer redis.Close()
  3850. if err != nil {
  3851. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  3852. return
  3853. }
  3854. c.ServeSuccessJSON(map[string]interface{}{
  3855. "msg": "ok",
  3856. "advice": advice,
  3857. })
  3858. return
  3859. }
  3860. }
  3861. func (c *PatientApiController) setAdviceWithJSON(advice *models.GroupAdvice, json map[string]interface{}) int {
  3862. if json["advice_name"] == nil || reflect.TypeOf(json["advice_name"]).String() != "string" {
  3863. utils.ErrorLog("advice_name")
  3864. return enums.ErrorCodeParamWrong
  3865. }
  3866. adviceName, _ := json["advice_name"].(string)
  3867. if len(adviceName) == 0 {
  3868. utils.ErrorLog("len(advice_name) == 0")
  3869. return enums.ErrorCodeParamWrong
  3870. }
  3871. advice.AdviceName = adviceName
  3872. adviceDesc, _ := json["advice_desc"].(string)
  3873. advice.AdviceDesc = adviceDesc
  3874. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  3875. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  3876. advice.DrugSpec = drugSpec
  3877. }
  3878. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3879. remark, _ := json["remark"].(string)
  3880. advice.Remark = remark
  3881. }
  3882. //if json["src_type"] != nil || reflect.TypeOf(json["src_type"]).String() == "float64" {
  3883. // src_type, _ := strconv.ParseInt(json["src_type"].(string),10)
  3884. // advice.Way = src_type
  3885. //}
  3886. if json["way"] == nil {
  3887. advice.Way = 0
  3888. } else {
  3889. if json["way"] != nil || reflect.TypeOf(json["way"]).String() == "float64" {
  3890. way := int64(json["way"].(float64))
  3891. advice.Way = way
  3892. }
  3893. }
  3894. if json["drug_id"] == nil {
  3895. advice.DrugId = 0
  3896. } else {
  3897. if json["drug_id"] != nil || reflect.TypeOf(json["drug_id"]).String() == "float64" {
  3898. drug_id := int64(json["drug_id"].(float64))
  3899. advice.DrugId = drug_id
  3900. }
  3901. }
  3902. if json["drug_name_id"] == nil {
  3903. advice.DrugNameId = 0
  3904. } else {
  3905. if json["drug_name_id"] != nil || reflect.TypeOf(json["drug_name_id"]).String() == "float64" {
  3906. drug_name_id := int64(json["drug_name_id"].(float64))
  3907. advice.DrugNameId = drug_name_id
  3908. }
  3909. }
  3910. if json["drug_spec_unit"] != nil && reflect.TypeOf(json["drug_spec_unit"]).String() == "string" {
  3911. drugSpecUnit, _ := json["drug_spec_unit"].(string)
  3912. advice.DrugSpecUnit = drugSpecUnit
  3913. }
  3914. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3915. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3916. advice.SingleDose = singleDose
  3917. }
  3918. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3919. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3920. advice.SingleDoseUnit = singleDoseUnit
  3921. }
  3922. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3923. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3924. advice.PrescribingNumber = prescribingNumber
  3925. }
  3926. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3927. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3928. advice.PrescribingNumberUnit = prescribingNumberUnit
  3929. }
  3930. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3931. deliveryWay, _ := json["delivery_way"].(string)
  3932. advice.DeliveryWay = deliveryWay
  3933. }
  3934. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3935. executionFrequency, _ := json["execution_frequency"].(string)
  3936. advice.ExecutionFrequency = executionFrequency
  3937. }
  3938. return 0
  3939. }
  3940. func (c *PatientApiController) DelDoctorAdvice() {
  3941. groupno, _ := c.GetInt64("groupno", -1)
  3942. is_sub, _ := c.GetInt64("is_sub", -1) //是否子药
  3943. patient_id, _ := c.GetInt64("patient_id")
  3944. doc_advice_date, _ := c.GetInt64("advice_date")
  3945. redis := service.RedisClient()
  3946. if is_sub == 1 { //是
  3947. advice_id, _ := c.GetInt64("advice_id")
  3948. adminUserInfo := c.GetMobileAdminUserInfo()
  3949. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  3950. if advice.ID == 0 {
  3951. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3952. return
  3953. }
  3954. advice.Status = 0
  3955. advice.UpdatedTime = time.Now().Unix()
  3956. advice.Modifier = adminUserInfo.AdminUser.Id
  3957. // 查询信息规挡的设置天数
  3958. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3959. if infor.ID > 0 {
  3960. var cha_time int64
  3961. timeNowStr := time.Now().Format("2006-01-02")
  3962. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3963. //今日的日期减去设置的日期
  3964. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3965. if cha_time >= advice.AdviceDate {
  3966. //查询审核是否允许
  3967. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id)
  3968. //申请状态不允许的情况 拒绝修改
  3969. if infor.ApplicationStatus != 1 {
  3970. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3971. return
  3972. }
  3973. }
  3974. }
  3975. err := service.DeleteDoctorAdvice(&advice)
  3976. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  3977. redis.Set(key, "", time.Second)
  3978. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  3979. redis.Set(keyTwo, "", time.Second)
  3980. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  3981. redis.Set(keyThree, "", time.Second)
  3982. redis.Close()
  3983. if err != nil {
  3984. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  3985. return
  3986. }
  3987. c.ServeSuccessJSON(map[string]interface{}{
  3988. "msg": "ok",
  3989. })
  3990. return
  3991. } else { //
  3992. var ids []string
  3993. if groupno == 0 {
  3994. advice_id := c.GetString("advice_id")
  3995. ids = strings.Split(advice_id, ",")
  3996. if len(ids) <= 0 {
  3997. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3998. return
  3999. }
  4000. }
  4001. if groupno < 0 {
  4002. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4003. return
  4004. }
  4005. adminUserInfo := c.GetMobileAdminUserInfo()
  4006. var advice models.DoctorAdvice
  4007. if groupno > 0 {
  4008. advice, _ = service.FindDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  4009. if advice.ID == 0 {
  4010. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  4011. return
  4012. }
  4013. } else {
  4014. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  4015. for _, item := range advices {
  4016. if item.ID == 0 {
  4017. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  4018. return
  4019. }
  4020. }
  4021. }
  4022. advice.UpdatedTime = time.Now().Unix()
  4023. advice.Status = 0
  4024. advice.GroupNo = groupno
  4025. advice.Modifier = adminUserInfo.AdminUser.Id
  4026. var err error
  4027. if groupno > 0 {
  4028. // 查询信息规挡的设置天数
  4029. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4030. if infor.ID > 0 {
  4031. var cha_time int64
  4032. timeNowStr := time.Now().Format("2006-01-02")
  4033. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4034. //今日的日期减去设置的日期
  4035. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4036. if cha_time >= advice.AdviceDate {
  4037. //查询审核是否允许
  4038. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id)
  4039. //申请状态不允许的情况 拒绝修改
  4040. if infor.ApplicationStatus != 1 {
  4041. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4042. return
  4043. }
  4044. }
  4045. }
  4046. err = service.DeleteDoctorAdviceByGroupNo(&advice)
  4047. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  4048. redis.Set(key, "", time.Second)
  4049. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  4050. redis.Set(keyTwo, "", time.Second)
  4051. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  4052. redis.Set(keyThree, "", time.Second)
  4053. } else {
  4054. // 查询信息规挡的设置天数
  4055. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4056. if infor.ID > 0 {
  4057. var cha_time int64
  4058. timeNowStr := time.Now().Format("2006-01-02")
  4059. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4060. //今日的日期减去设置的日期
  4061. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4062. if cha_time >= advice.AdviceDate {
  4063. //查询审核是否允许
  4064. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id)
  4065. //申请状态不允许的情况 拒绝修改
  4066. if infor.ApplicationStatus != 1 {
  4067. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4068. return
  4069. }
  4070. }
  4071. }
  4072. err = service.BatchDeleteDoctorAdvice(ids, adminUserInfo.AdminUser.Id)
  4073. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  4074. redis.Set(key, "", time.Second)
  4075. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  4076. redis.Set(keyTwo, "", time.Second)
  4077. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  4078. redis.Set(keyThree, "", time.Second)
  4079. redis.Close()
  4080. }
  4081. if err != nil {
  4082. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  4083. return
  4084. }
  4085. c.ServeSuccessJSON(map[string]interface{}{
  4086. "msg": "ok",
  4087. })
  4088. return
  4089. }
  4090. }
  4091. // /m/api/advice/group/modify_starttime [post]
  4092. // @param group_no:int
  4093. // @param start_time:string yyyy-MM-dd hh:mm:ss
  4094. func (this *PatientApiController) ModifyAdviceGroupStartTime() {
  4095. group_no, _ := this.GetInt64("group_no")
  4096. start_time_str := this.GetString("start_time")
  4097. if group_no <= 0 || len(start_time_str) == 0 {
  4098. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4099. return
  4100. }
  4101. startTime, parseTimeErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time_str)
  4102. if parseTimeErr != nil {
  4103. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  4104. return
  4105. }
  4106. adminUserInfo := this.GetMobileAdminUserInfo()
  4107. updateStartTimeErr := service.UpdateAdviceGroupStartTime(adminUserInfo.Org.Id, group_no, startTime.Unix(), adminUserInfo.AdminUser.Id)
  4108. if updateStartTimeErr != nil {
  4109. utils.ErrorLog("修改医嘱分组的开始时间失败:%v", updateStartTimeErr)
  4110. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4111. return
  4112. }
  4113. this.ServeSuccessJSON(map[string]interface{}{
  4114. "start_time": startTime.Unix(),
  4115. })
  4116. }
  4117. func (this *PatientApiController) DelSubDoctorAdvice() {
  4118. advice_id, _ := this.GetInt64("advice_id")
  4119. adminUserInfo := this.GetMobileAdminUserInfo()
  4120. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  4121. if advice.ID == 0 {
  4122. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  4123. return
  4124. }
  4125. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  4126. // this.ServeFailJSONWithSGJErrorCode(enums. bh)
  4127. // return
  4128. //}
  4129. advice.Status = 0
  4130. advice.UpdatedTime = time.Now().Unix()
  4131. advice.Modifier = adminUserInfo.AdminUser.Id
  4132. err := service.DeleteDoctorAdvice(&advice)
  4133. if err != nil {
  4134. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  4135. return
  4136. }
  4137. this.ServeSuccessJSON(map[string]interface{}{
  4138. "msg": "ok",
  4139. })
  4140. return
  4141. }
  4142. func (this *PatientApiController) GetAdviceUnReadMessage() {
  4143. //adminUserInfo := this.GetMobileAdminUserInfo()
  4144. //service.FindUnReadDoctorAdviceMessage()
  4145. }
  4146. func (this *PatientApiController) GetPatientsByKeyWord() {
  4147. keyWord := this.GetString("keyword")
  4148. adminUserInfo := this.GetMobileAdminUserInfo()
  4149. today := utils.ZeroHourTimeOfDay(time.Now())
  4150. patient, err := service.GetSchedualPatientByKeyWord(adminUserInfo.Org.Id, keyWord, today.Unix())
  4151. if err != nil {
  4152. utils.ErrorLog(err.Error())
  4153. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4154. return
  4155. }
  4156. this.ServeSuccessJSON(map[string]interface{}{
  4157. "patient": patient,
  4158. })
  4159. }
  4160. func (this *PatientApiController) GetSearchPatient() {
  4161. keyWord := this.GetString("keyword")
  4162. adminUserInfo := this.GetMobileAdminUserInfo()
  4163. patient, err := service.GetPatientsByKey(adminUserInfo.Org.Id, keyWord)
  4164. if err != nil {
  4165. utils.ErrorLog(err.Error())
  4166. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4167. return
  4168. }
  4169. this.ServeSuccessJSON(map[string]interface{}{
  4170. "patient": patient,
  4171. })
  4172. }
  4173. func (c *PatientApiController) ExecProject() {
  4174. execution_time := c.GetString("execution_time")
  4175. project_id, _ := c.GetInt64("project_id")
  4176. team_id, _ := c.GetInt64("team_id")
  4177. is_check_team, _ := c.GetInt64("is_check_team")
  4178. if len(execution_time) <= 0 {
  4179. utils.ErrorLog("execution_time")
  4180. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4181. return
  4182. }
  4183. timeLayout2 := "2006-01-02 15:04:05"
  4184. loc, _ := time.LoadLocation("Local")
  4185. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  4186. if errs != nil {
  4187. utils.ErrorLog(errs.Error())
  4188. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4189. return
  4190. }
  4191. adminInfo := c.GetMobileAdminUserInfo()
  4192. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  4193. if project.Type == 3 {
  4194. good, _ := service.GetGoodInformationByGoodId(project.ProjectId)
  4195. if good.IsUser != 1 {
  4196. //查询开关是否开启
  4197. stockSetting, _ := service.FindStockSettingById(adminInfo.Org.Id)
  4198. //开关已经开启
  4199. if stockSetting.IsType == 1 {
  4200. theTime, _ := time.ParseInLocation(timeLayout2, execution_time, loc)
  4201. scheduleDateStart := theTime.Format("2006-01-02")
  4202. timeLayout3 := "2006-01-02"
  4203. loc, _ := time.LoadLocation("Local")
  4204. execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
  4205. //查询该耗材是否已经出库
  4206. auto, _ := service.GetAutoWarehouseOutList(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
  4207. if auto.ID == 0 {
  4208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
  4209. return
  4210. }
  4211. }
  4212. }
  4213. if good.IsUser == 1 && good.IsWarehouse == 1 {
  4214. //查询开关是否开启
  4215. stockSetting, _ := service.FindStockSettingById(adminInfo.Org.Id)
  4216. //开关已经开启
  4217. if stockSetting.IsType == 1 {
  4218. theTime, _ := time.ParseInLocation(timeLayout2, execution_time, loc)
  4219. scheduleDateStart := theTime.Format("2006-01-02")
  4220. timeLayout3 := "2006-01-02"
  4221. loc, _ := time.LoadLocation("Local")
  4222. execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
  4223. //查询该耗材是否已经出库
  4224. auto, _ := service.GetAutoWarehouseOutList(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
  4225. if auto.ID == 0 {
  4226. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
  4227. return
  4228. }
  4229. }
  4230. }
  4231. }
  4232. if project.ExecutionState == 1 {
  4233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  4234. return
  4235. }
  4236. if project.Checker >= 0 && project.Checker == adminInfo.AdminUser.Id {
  4237. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  4238. return
  4239. }
  4240. project.ExecutionState = 1
  4241. project.ExecutionStaff = adminInfo.AdminUser.Id
  4242. project.ExecutionTime = theTime.Unix()
  4243. if team_id == 0 {
  4244. // 查询信息规挡的设置天数
  4245. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  4246. if infor.ID > 0 {
  4247. var cha_time int64
  4248. timeNowStr := time.Now().Format("2006-01-02")
  4249. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4250. //今日的日期减去设置的日期
  4251. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4252. if cha_time >= project.RecordDate {
  4253. //查询审核是否允许
  4254. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId)
  4255. //申请状态不允许的情况 拒绝修改
  4256. if infor.ApplicationStatus != 1 {
  4257. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4258. return
  4259. }
  4260. }
  4261. }
  4262. err := service.SaveHisProject(&project)
  4263. if err == nil {
  4264. c.ServeSuccessJSON(map[string]interface{}{
  4265. "project": project,
  4266. })
  4267. } else {
  4268. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4269. return
  4270. }
  4271. } else {
  4272. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  4273. // 查询信息规挡的设置天数
  4274. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  4275. if infor.ID > 0 {
  4276. var cha_time int64
  4277. timeNowStr := time.Now().Format("2006-01-02")
  4278. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4279. //今日的日期减去设置的日期
  4280. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4281. if cha_time >= project.RecordDate {
  4282. //查询审核是否允许
  4283. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId)
  4284. //申请状态不允许的情况 拒绝修改
  4285. if infor.ApplicationStatus != 1 {
  4286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4287. return
  4288. }
  4289. }
  4290. }
  4291. err := service.SaveHisProject(&project)
  4292. if err == nil {
  4293. c.ServeSuccessJSON(map[string]interface{}{
  4294. "project": project,
  4295. })
  4296. } else {
  4297. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4298. return
  4299. }
  4300. } else {
  4301. // 查询信息规挡的设置天数
  4302. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  4303. if infor.ID > 0 {
  4304. var cha_time int64
  4305. timeNowStr := time.Now().Format("2006-01-02")
  4306. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4307. //今日的日期减去设置的日期
  4308. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4309. if cha_time >= project.RecordDate {
  4310. //查询审核是否允许
  4311. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId)
  4312. //申请状态不允许的情况 拒绝修改
  4313. if infor.ApplicationStatus != 1 {
  4314. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4315. return
  4316. }
  4317. }
  4318. }
  4319. ps, _ := service.GetCheckTeamProject(team_id, project.PatientId, project.RecordDate, project.UserOrgId)
  4320. var ids []int64
  4321. for _, items := range ps {
  4322. ids = append(ids, items.ID)
  4323. }
  4324. err := service.UpdateTeamProjectExceStatus(ids, adminInfo.AdminUser.Id, theTime.Unix())
  4325. if err == nil {
  4326. c.ServeSuccessJSON(map[string]interface{}{
  4327. "project": project,
  4328. })
  4329. } else {
  4330. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4331. return
  4332. }
  4333. }
  4334. }
  4335. }
  4336. func (c *PatientApiController) CheckProject() {
  4337. adminInfo := c.GetMobileAdminUserInfo()
  4338. project_id, _ := c.GetInt64("project_id")
  4339. team_id, _ := c.GetInt64("team_id")
  4340. is_check_team, _ := c.GetInt64("is_check_team")
  4341. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  4342. if project.CheckState == 1 {
  4343. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  4344. return
  4345. }
  4346. if project.ExecutionStaff >= 0 && project.ExecutionStaff == adminInfo.AdminUser.Id {
  4347. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  4348. return
  4349. }
  4350. project.Checker = adminInfo.AdminUser.Id
  4351. project.CheckTime = time.Now().Unix()
  4352. project.CheckState = 1
  4353. if team_id == 0 {
  4354. // 查询信息规挡的设置天数
  4355. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  4356. if infor.ID > 0 {
  4357. var cha_time int64
  4358. timeNowStr := time.Now().Format("2006-01-02")
  4359. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4360. //今日的日期减去设置的日期
  4361. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4362. if cha_time >= project.RecordDate {
  4363. //查询审核是否允许
  4364. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId)
  4365. //申请状态不允许的情况 拒绝修改
  4366. if infor.ApplicationStatus != 1 {
  4367. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4368. return
  4369. }
  4370. }
  4371. }
  4372. err := service.SaveHisProject(&project)
  4373. if err == nil {
  4374. c.ServeSuccessJSON(map[string]interface{}{
  4375. "msg": "ok",
  4376. "project": project,
  4377. })
  4378. } else {
  4379. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4380. return
  4381. }
  4382. } else {
  4383. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  4384. // 查询信息规挡的设置天数
  4385. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  4386. if infor.ID > 0 {
  4387. var cha_time int64
  4388. timeNowStr := time.Now().Format("2006-01-02")
  4389. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4390. //今日的日期减去设置的日期
  4391. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4392. if cha_time >= project.RecordDate {
  4393. //查询审核是否允许
  4394. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId)
  4395. //申请状态不允许的情况 拒绝修改
  4396. if infor.ApplicationStatus != 1 {
  4397. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4398. return
  4399. }
  4400. }
  4401. }
  4402. err := service.SaveHisProject(&project)
  4403. if err == nil {
  4404. c.ServeSuccessJSON(map[string]interface{}{
  4405. "msg": "ok",
  4406. "project": project,
  4407. })
  4408. } else {
  4409. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4410. return
  4411. }
  4412. } else {
  4413. // 查询信息规挡的设置天数
  4414. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  4415. if infor.ID > 0 {
  4416. var cha_time int64
  4417. timeNowStr := time.Now().Format("2006-01-02")
  4418. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4419. //今日的日期减去设置的日期
  4420. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4421. if cha_time >= project.RecordDate {
  4422. //查询审核是否允许
  4423. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId)
  4424. //申请状态不允许的情况 拒绝修改
  4425. if infor.ApplicationStatus != 1 {
  4426. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4427. return
  4428. }
  4429. }
  4430. }
  4431. ps, _ := service.GetCheckTeamProject(team_id, project.PatientId, project.RecordDate, project.UserOrgId)
  4432. var ids []int64
  4433. for _, items := range ps {
  4434. ids = append(ids, items.ID)
  4435. }
  4436. err := service.UpdateTeamProjectCheckStatus(ids, project.PatientId, project.RecordDate, project.UserOrgId, adminInfo.AdminUser.Id, time.Now().Unix())
  4437. if err == nil {
  4438. c.ServeSuccessJSON(map[string]interface{}{
  4439. "project": project,
  4440. })
  4441. } else {
  4442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4443. return
  4444. }
  4445. }
  4446. }
  4447. }