patient_api_controller.go 188KB

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