patient_api_controller.go 210KB

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