patient_api_controller.go 206KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "github.com/jinzhu/gorm"
  9. //"github.com/jinzhu/gorm"
  10. "math"
  11. "math/rand"
  12. "reflect"
  13. "regexp"
  14. "strconv"
  15. "strings"
  16. "time"
  17. "fmt"
  18. "github.com/astaxie/beego"
  19. )
  20. type PatientApiController struct {
  21. BaseAuthAPIController
  22. }
  23. func PatientApiRegistRouters() {
  24. beego.Router("/api/patients", &PatientApiController{}, "get:GetPatientsList")
  25. beego.Router("/api/patients/all", &PatientApiController{}, "get:GetPatientsAllList")
  26. beego.Router("/api/patients/generatedialysisno", &PatientApiController{}, "get:GenerateDialysisNo")
  27. beego.Router("/api/patients/create", &PatientApiController{}, "Post:CreatePatient")
  28. beego.Router("/api/patients/total", &PatientApiController{}, "Get:GetPatientTotal")
  29. beego.Router("/api/patients/get", &PatientApiController{}, "Get:GetPatient")
  30. beego.Router("/api/patients/edit", &PatientApiController{}, "Put:EditPatient")
  31. beego.Router("/api/patients/dialysissolution/create", &PatientApiController{}, "Post:CreateDialysisSolution")
  32. beego.Router("/api/patients/dialysissolution/edit", &PatientApiController{}, "Put:UpdateDialysisSolution")
  33. beego.Router("/api/patients/dialysissolutions", &PatientApiController{}, "get:GetPatientDialysisSolutionList")
  34. beego.Router("/api/patients/dialysissolution/detail/edit", &PatientApiController{}, "Put:UpdateDialysisSolutionDetail")
  35. // beego.Router("/api/patients/dialysissolution/delete", &PatientApiController{}, "Delete:DeleteDialysisSolution")
  36. beego.Router("/api/patients/dryweight/get", &PatientApiController{}, "get:GetDryWeights")
  37. beego.Router("/api/patients/dryweight/create", &PatientApiController{}, "Post:CreateDryWeights")
  38. beego.Router("/api/patients/advice/create", &PatientApiController{}, "Post:CreateDoctorAdvice")
  39. beego.Router("/api/patients/advice/edit", &PatientApiController{}, "Put:UpdateDoctorAdvice")
  40. beego.Router("/api/patients/advice/exec", &PatientApiController{}, "Post:ExecDoctorAdvice")
  41. beego.Router("/api/patients/advice/check", &PatientApiController{}, "Post:CheckDoctorAdvice")
  42. beego.Router("/api/patients/advices", &PatientApiController{}, "Get:GetDoctorAdvices")
  43. beego.Router("/api/patients/advice/stop", &PatientApiController{}, "Post:StopDoctorAdvice")
  44. beego.Router("/api/patients/advice/delete", &PatientApiController{}, "Delete:DeleteDoctorAdvice")
  45. beego.Router("/api/patients/advice/creategroup", &PatientApiController{}, "Post:CreateGroupAdvice")
  46. beego.Router("/api/patients/advice/deletegroup", &PatientApiController{}, "Delete:DeleteGroupAdvice")
  47. beego.Router("/api/patients/advice/stopgroup", &PatientApiController{}, "Post:StopGroupAdvice")
  48. beego.Router("/api/patients/advice/execgroup", &PatientApiController{}, "Post:ExecGroupAdvice")
  49. beego.Router("/api/patients/advice/checkgroup", &PatientApiController{}, "Post:CheckGroupAdvice")
  50. beego.Router("/api/patients/schedules", &PatientApiController{}, "Get:GetPatientSchedules")
  51. beego.Router("/api/patients/dialysisrecords", &PatientApiController{}, "Get:GetPatientDialysisRecords")
  52. beego.Router("/api/patients/proeducation", &PatientApiController{}, "Get:ProEducation")
  53. beego.Router("/api/patients/lapseto/edit", &PatientApiController{}, "Post:EditLapseto")
  54. beego.Router("/api/patients/search", &PatientApiController{}, "Post:GetPatientsByKeyWord")
  55. beego.Router("/api/patients/querypatientbyId", &PatientApiController{}, "Get:QueryPatientById")
  56. beego.Router("/api/infectious/remind", &PatientApiController{}, "Get:GetRemindPatientList")
  57. beego.Router("/api/remind/is_open", &PatientApiController{}, "Post:PostIsOpenRemind")
  58. beego.Router("/api/patients/advices/getpatientschedules", &PatientApiController{}, "Get:GetPatientScheduleOne")
  59. beego.Router("/api/patients/export", &PatientApiController{}, "Post:ExportPatients")
  60. beego.Router("/api/patients/advices/saveditadvices", &PatientApiController{}, "Get:SaveEditAdvices")
  61. beego.Router("/api/patients/dialysis_no", &PatientApiController{}, "Get:GetMaxDialysisNo")
  62. beego.Router("/api/patients/banner", &PatientApiController{}, "Get:GetBanner")
  63. //长期医嘱新接口
  64. beego.Router("/api/patient/findepatientdialysislongsolutions", &PatientApiController{}, "Get:GetPatientDialysisLongSolution")
  65. beego.Router("/api/patient/getdialysissolutiondetaillist", &PatientApiController{}, "Get:GetDialysisSolutionDetailList")
  66. beego.Router("/api/patient/getexportlist", &PatientApiController{}, "Get:GetExportList")
  67. }
  68. func (c *PatientApiController) GetExportList() {
  69. startTime := c.GetString("start_time")
  70. endTime := c.GetString("end_time")
  71. schedulType, _ := c.GetInt64("schedul_type", 0)
  72. timeLayout := "2006-01-02"
  73. loc, _ := time.LoadLocation("Local")
  74. adminUserInfo := c.GetAdminUserInfo()
  75. var theStartTIme int64
  76. if len(startTime) > 0 {
  77. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  78. if err != nil {
  79. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  80. return
  81. }
  82. theStartTIme = theTime.Unix()
  83. }
  84. var theEndtTIme int64
  85. if len(endTime) > 0 {
  86. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  87. if err != nil {
  88. utils.ErrorLog(err.Error())
  89. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  90. return
  91. }
  92. theEndtTIme = theTime.Unix()
  93. }
  94. timeNowStr := time.Now().Format("2006-01-02")
  95. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  96. schedule, _ := service.GetPatientScheudleListTwenty(adminUserInfo.CurrentOrgId, schedulType, theStartTIme, theEndtTIme, timeNewDate.Unix())
  97. fmt.Println("schedule23333333333333333", schedule)
  98. patientsList, _ := service.GetAllpatient(adminUserInfo.CurrentOrgId)
  99. c.ServeSuccessJSON(map[string]interface{}{
  100. "schedule": schedule,
  101. "patientsList": patientsList,
  102. })
  103. return
  104. }
  105. // GetPatientsList 取患者列表
  106. func (c *PatientApiController) GetPatientsList() {
  107. var err error
  108. defer func() {
  109. if rec := recover(); rec != nil {
  110. err = fmt.Errorf("程序异常:%v", rec)
  111. }
  112. if err != nil {
  113. service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
  114. }
  115. }()
  116. page, _ := c.GetInt64("page", 1)
  117. limit, _ := c.GetInt64("limit", 10)
  118. schedulType, _ := c.GetInt64("schedul_type", 0)
  119. bindingState, _ := c.GetInt64("binding_state", 0)
  120. lapseto, _ := c.GetInt64("lapseto", 0)
  121. source, _ := c.GetInt64("source", 0)
  122. startTime := c.GetString("start_time", "")
  123. endTime := c.GetString("end_time", "")
  124. keywords := c.GetString("keywords", "")
  125. contagion, _ := c.GetInt64("contagion", 0)
  126. reimbursement_way, _ := c.GetInt64("reimbursement_way", 0)
  127. isscheduling, _ := c.GetInt64("isscheduling", 0)
  128. isprescription, _ := c.GetInt64("isprescription", 0)
  129. patientSoureType, _ := c.GetInt64("patientSoureType")
  130. nurse, _ := c.GetInt64("nurse")
  131. if page <= 0 {
  132. page = 1
  133. }
  134. if limit <= 0 {
  135. limit = 10
  136. }
  137. adminUserInfo := c.GetAdminUserInfo()
  138. timeLayout := "2006-01-02"
  139. loc, _ := time.LoadLocation("Local")
  140. var isStartTime bool
  141. var theStartTIme int64
  142. if len(startTime) > 0 {
  143. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  144. if err != nil {
  145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  146. return
  147. }
  148. isStartTime = true
  149. theStartTIme = theTime.Unix()
  150. }
  151. var isEndTime bool
  152. var theEndtTIme int64
  153. if len(endTime) > 0 {
  154. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  155. if err != nil {
  156. utils.ErrorLog(err.Error())
  157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  158. return
  159. }
  160. isEndTime = true
  161. theEndtTIme = theTime.Unix()
  162. }
  163. var patients []*models.Patients
  164. var total int64
  165. patients, total, err = service.GetPatientList(adminUserInfo.CurrentOrgId, keywords, page, limit, schedulType, bindingState, lapseto, source, theStartTIme, theEndtTIme, contagion, reimbursement_way, isscheduling, isprescription, isStartTime, isEndTime, patientSoureType, nurse)
  166. c.ServeSuccessJSON(map[string]interface{}{
  167. "patients": patients,
  168. "total": total,
  169. })
  170. return
  171. }
  172. // GetPatientTotal
  173. func (c *PatientApiController) GetPatientTotal() {
  174. adminUserInfo := c.GetAdminUserInfo()
  175. total := service.GetPatientCount(adminUserInfo.CurrentOrgId)
  176. c.ServeSuccessJSON(map[string]interface{}{
  177. "total": total,
  178. })
  179. return
  180. }
  181. func (c *PatientApiController) GetPatientsAllList() {
  182. adminUserInfo := c.GetAdminUserInfo()
  183. patients, total, _ := service.GetAllPatientList(adminUserInfo.CurrentOrgId)
  184. c.ServeSuccessJSON(map[string]interface{}{
  185. "patients": patients,
  186. "total": total,
  187. })
  188. return
  189. }
  190. // GenerateDialysisNo 生成透析号
  191. func (c *PatientApiController) GenerateDialysisNo() {
  192. adminUserInfo := c.GetAdminUserInfo()
  193. dialysisNo := service.ChechLastDialysisNo(adminUserInfo.CurrentOrgId)
  194. if dialysisNo == 0 {
  195. dialysisNo = 1
  196. } else {
  197. dialysisNo++
  198. }
  199. no := strconv.FormatInt(dialysisNo, 10)
  200. rep := 3 - len(no)
  201. if rep > 0 {
  202. no = strings.Repeat("0", rep) + no
  203. }
  204. c.ServeSuccessJSON(map[string]interface{}{
  205. "no": no,
  206. })
  207. return
  208. }
  209. // CreatePatient 创建患者
  210. func (c *PatientApiController) CreatePatient() {
  211. record_date := c.GetString("record_date")
  212. is_infectious, _ := c.GetInt64("is_infectious")
  213. remind_cycle, _ := c.GetInt64("remind_cycle")
  214. adminUserInfo := c.GetAdminUserInfo()
  215. //patientTotal := service.GetLapsetoPatientCount(adminUserInfo.CurrentOrgId, 1)
  216. //subscibes := adminUserInfo.Subscibes[adminUserInfo.CurrentOrgId]
  217. //if subscibes.State == 2 && patientTotal >= 20 { //免费试用版,不过期,限制患者数20
  218. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
  219. // return
  220. //} else if subscibes.State == 1 && patientTotal >= 60 { //标准版,不过期,限制患者数60
  221. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
  222. // return
  223. //}
  224. var patient models.Patients
  225. contagions, diseases, code, formItems := patientFormData(&patient, c.Ctx.Input.RequestBody, "create")
  226. fmt.Println(code)
  227. fmt.Println(patient)
  228. if code > 0 {
  229. c.ServeFailJSONWithSGJErrorCode(code)
  230. return
  231. }
  232. thisPatient, _ := service.FindPatientByDialysisNo(adminUserInfo.CurrentOrgId, patient.DialysisNo)
  233. if thisPatient.ID > 0 {
  234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisNoExist)
  235. return
  236. }
  237. thisPatient, _ = service.FindPatientByIdCardNo(adminUserInfo.CurrentOrgId, patient.IdCardNo)
  238. if thisPatient.ID > 0 {
  239. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIdCardNoExist)
  240. return
  241. }
  242. thisPatient, _ = service.FindPatientByMobile(adminUserInfo.CurrentOrgId, patient.Phone)
  243. if thisPatient.ID > 0 {
  244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientPhoneUsed)
  245. return
  246. }
  247. patient.RemindCycle = remind_cycle
  248. patient.IsInfectious = is_infectious
  249. patient.RegistrarsId = adminUserInfo.AdminUser.Id
  250. patient.Status = 1
  251. patient.CreatedTime = time.Now().Unix()
  252. patient.UserOrgId = adminUserInfo.CurrentOrgId
  253. patient.UpdatedTime = time.Now().Unix()
  254. patient.BindingState = 2
  255. // patient.Lapseto = 1
  256. err := service.CreatePatient(&patient, contagions, diseases)
  257. fmt.Println("创建病人失败err")
  258. if err != nil {
  259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePatient)
  260. return
  261. }
  262. //获取老表的最后一条数据
  263. patients, err := service.GetLastPatientData(adminUserInfo.CurrentOrgId)
  264. patientsNew := models.XtPatientsNew{
  265. UserOrgId: adminUserInfo.CurrentOrgId,
  266. UserId: 0,
  267. Avatar: patients.Avatar,
  268. PatientType: patients.PatientType,
  269. DialysisNo: patients.DialysisNo,
  270. AdmissionNumber: patients.AdmissionNumber,
  271. Source: patients.Source,
  272. Lapseto: patients.Lapseto,
  273. PartitionId: patients.PartitionId,
  274. BedId: patients.BedId,
  275. Name: patients.Name,
  276. Alias: patients.Alias,
  277. Gender: patients.Gender,
  278. MaritalStatus: patients.MaritalStatus,
  279. IdCardNo: patients.IdCardNo,
  280. Birthday: patients.Birthday,
  281. ReimbursementWayId: patients.ReimbursementWayId,
  282. HealthCareType: patients.HealthCareType,
  283. HealthCareNo: patients.HealthCareNo,
  284. HealthCareDueDate: patients.HealthCareDueDate,
  285. Height: patients.Height,
  286. BloodType: patients.BloodType,
  287. Rh: patients.Rh,
  288. HealthCareDueAlertDate: patients.HealthCareDueAlertDate,
  289. EducationLevel: patients.EducationLevel,
  290. Profession: patients.Profession,
  291. Phone: patients.Phone,
  292. HomeTelephone: patients.HomeTelephone,
  293. RelativePhone: patients.RelativePhone,
  294. RelativeRelations: patients.RelativeRelations,
  295. HomeAddress: patients.HomeAddress,
  296. WorkUnit: patients.WorkUnit,
  297. UnitAddress: patients.UnitAddress,
  298. Children: patients.Children,
  299. ReceivingDate: patients.ReceivingDate,
  300. IsHospitalFirstDialysis: patients.IsHospitalFirstDialysis,
  301. FirstDialysisDate: patients.FirstDialysisDate,
  302. FirstDialysisHospital: patients.FirstDialysisHospital,
  303. PredialysisCondition: patients.PredialysisCondition,
  304. PreHospitalDialysisFrequency: patients.PreHospitalDialysisFrequency,
  305. PreHospitalDialysisTimes: patients.PreHospitalDialysisTimes,
  306. HospitalFirstDialysisDate: patients.HospitalFirstDialysisDate,
  307. InductionPeriod: patients.InductionPeriod,
  308. InitialDialysis: patients.InitialDialysis,
  309. TotalDialysis: patients.TotalDialysis,
  310. AttendingDoctorId: patients.AttendingDoctorId,
  311. HeadNurseId: patients.HeadNurseId,
  312. Evaluate: patients.Evaluate,
  313. Diagnose: patients.Diagnose,
  314. Remark: patients.Remark,
  315. RegistrarsId: patients.RegistrarsId,
  316. Registrars: patients.Registrars,
  317. QrCode: patients.QrCode,
  318. BindingState: patients.BindingState,
  319. PatientComplains: patients.PatientComplains,
  320. PresentHistory: patients.PresentHistory,
  321. PastHistory: patients.PresentHistory,
  322. Temperature: patients.Temperature,
  323. Pulse: patients.Pulse,
  324. Respiratory: patients.Respiratory,
  325. Sbp: patients.SBP,
  326. Dbp: patients.DBP,
  327. Status: patients.Status,
  328. CreatedTime: patients.CreatedTime,
  329. UpdatedTime: patients.UpdatedTime,
  330. Nation: patients.Nation,
  331. NativePlace: patients.NativePlace,
  332. Age: patients.Age,
  333. InfectiousNextRecordTime: patients.InfectiousNextRecordTime,
  334. IsInfectious: patients.IsInfectious,
  335. RemindCycle: patients.RemindCycle,
  336. ResponseResult: patients.ResponseResult,
  337. IsOpenRemind: patients.IsOpenRemind,
  338. FirstTreatmentDate: patients.FirstTreatmentDate,
  339. DialysisAge: patients.DialysisAge,
  340. ExpenseKind: patients.ExpenseKind,
  341. TellPhone: patients.TellPhone,
  342. ContactName: patients.ContactName,
  343. BloodPatients: 1,
  344. SlowPatients: 0,
  345. MemberPatients: 0,
  346. EcommerPatients: "",
  347. BloodId: patients.ID,
  348. SlowId: 0,
  349. MemberId: 0,
  350. MemberFistdate: 0,
  351. MemberPatienttype: 0,
  352. MemberTreatement: 0,
  353. EquitmentId: "",
  354. UserSysBeforeCount: patient.UserSysBeforeCount,
  355. TrobleShoot: patient.TrobleShoot,
  356. TreatmentPlan: patient.TreatmentPlan,
  357. Doctor: patient.Doctor,
  358. RecordNumber: patient.RecordNumber,
  359. PatientSource: patient.PatientSource,
  360. PatientEndTime: patient.PatientEndTime,
  361. PatientStartTime: patient.PatientStartTime,
  362. InfectiousRemark: patient.InfectiousRemark,
  363. AllergicHistory: patient.AllergicHistory,
  364. PatientAddress: patient.PatientAddress,
  365. }
  366. err = service.CreatePatientsNew(&patientsNew)
  367. fmt.Print("创建失败", err)
  368. allergic := models.XtPatientAllergic{
  369. UserOrgId: adminUserInfo.CurrentOrgId,
  370. PatientId: patient.ID,
  371. StartTime: patient.PatientStartTime,
  372. EndTime: patient.PatientEndTime,
  373. PatientSource: patient.PatientSource,
  374. PatientAddress: patient.PatientAddress,
  375. Remake: patient.Remark,
  376. Status: 1,
  377. Ctime: time.Now().Unix(),
  378. }
  379. if len(patient.PatientAddress) > 0 {
  380. service.CreateAllergic(allergic)
  381. }
  382. if len(record_date) > 0 {
  383. var recordTime int64
  384. timeLayout := "2006-01-02"
  385. loc, _ := time.LoadLocation("Local")
  386. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  387. if err != nil {
  388. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  389. return
  390. }
  391. recordTime = theTime.Unix()
  392. inspections := make([]models.Inspection, 0)
  393. for _, item := range formItems {
  394. var inspection models.Inspection
  395. inspection.OrgId = adminUserInfo.CurrentOrgId
  396. inspection.PatientId = patient.ID
  397. inspection.ProjectId = item.ProjectId
  398. inspection.ItemId = item.ItemId
  399. inspection.ItemName = item.ItemName
  400. inspection.ProjectName = item.ProjectName
  401. inspection.InspectType = item.RangeType
  402. inspection.InspectValue = item.Value
  403. inspection.InspectDate = recordTime
  404. inspection.Status = 1
  405. inspection.CreatedTime = time.Now().Unix()
  406. inspection.UpdatedTime = time.Now().Unix()
  407. inspections = append(inspections, inspection)
  408. }
  409. err = service.CreatePatientInspection(inspections)
  410. infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient.ID, 14)
  411. var record_time int64
  412. switch remind_cycle {
  413. case 1: //1个月
  414. ts := time.Unix(infectiousRecord.InspectDate, 0)
  415. record_time = ts.AddDate(0, 1, 0).Unix()
  416. break
  417. case 2: //2个月
  418. ts := time.Unix(infectiousRecord.InspectDate, 0)
  419. record_time = ts.AddDate(0, 2, 0).Unix()
  420. break
  421. case 3: //3个月
  422. ts := time.Unix(infectiousRecord.InspectDate, 0)
  423. record_time = ts.AddDate(0, 3, 0).Unix()
  424. break
  425. case 4: //6个月
  426. ts := time.Unix(infectiousRecord.InspectDate, 0)
  427. record_time = ts.AddDate(0, 6, 0).Unix()
  428. break
  429. case 5: //12个月
  430. ts := time.Unix(infectiousRecord.InspectDate, 0)
  431. record_time = ts.AddDate(0, 12, 0).Unix()
  432. break
  433. }
  434. errs := service.UpDateInfectiousRecordTime(adminUserInfo.CurrentOrgId, patient.ID, record_time, remind_cycle)
  435. if errs != nil {
  436. utils.ErrorLog("更新日期出错:%v", errs)
  437. }
  438. }
  439. redis := service.RedisClient()
  440. defer redis.Close()
  441. redis.SAdd("sgj_patient:new_user_set", patient.UserId)
  442. c.ServeSuccessJSON(map[string]interface{}{
  443. "msg": "ok",
  444. })
  445. return
  446. }
  447. // EditPatient 修改
  448. func (c *PatientApiController) EditPatient() {
  449. id, _ := c.GetInt64("id", 0)
  450. record_date := c.GetString("record_date")
  451. is_infectious, _ := c.GetInt64("is_infectious")
  452. remind_cycle, _ := c.GetInt64("remind_cycle")
  453. if id <= 0 {
  454. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  455. return
  456. }
  457. adminUserInfo := c.GetAdminUserInfo()
  458. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  459. if patient.ID == 0 {
  460. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  461. return
  462. }
  463. contagions, diseases, code, formItems := patientFormData(&patient, c.Ctx.Input.RequestBody, "edit")
  464. if code > 0 {
  465. c.ServeFailJSONWithSGJErrorCode(code)
  466. return
  467. }
  468. thisPatientother, _ := service.FindPatientByDialysisNo(adminUserInfo.CurrentOrgId, patient.DialysisNo)
  469. if thisPatientother.ID > 0 && thisPatientother.ID != patient.ID {
  470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisNoExist)
  471. return
  472. }
  473. thisPatient, _ := service.FindPatientByIdCardNo(adminUserInfo.CurrentOrgId, patient.IdCardNo)
  474. if thisPatient.ID > 0 && thisPatient.ID != patient.ID {
  475. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIdCardNoExist)
  476. return
  477. }
  478. patient.UpdatedTime = time.Now().Unix()
  479. patient.IsInfectious = is_infectious
  480. patient.RemindCycle = remind_cycle
  481. err := service.UpdatePatient(&patient, contagions, diseases)
  482. if err != nil {
  483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdatePatient)
  484. return
  485. }
  486. ////更新转归状态
  487. //lapseto := models.PatientLapseto{
  488. // LapsetoType: patient.Lapseto,
  489. // LapsetoTime: time.Now().Unix(),
  490. // UpdatedTime: time.Now().Unix(),
  491. //}
  492. //err = service.UpdatePatientLapseto(patient.ID, lapseto)
  493. //fmt.Println("更新转归失败", err)
  494. if err != nil {
  495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdatePatient)
  496. return
  497. }
  498. patientsNew := models.XtPatientsNew{
  499. UserOrgId: patient.UserOrgId,
  500. UserId: patient.UserId,
  501. Avatar: patient.Avatar,
  502. PatientType: patient.PatientType,
  503. DialysisNo: patient.DialysisNo,
  504. AdmissionNumber: patient.AdmissionNumber,
  505. Source: patient.Source,
  506. PartitionId: patient.PartitionId,
  507. BedId: patient.BedId,
  508. Name: patient.Name,
  509. Alias: patient.Alias,
  510. Gender: patient.Gender,
  511. MaritalStatus: patient.MaritalStatus,
  512. IdCardNo: patient.IdCardNo,
  513. Birthday: patient.Birthday,
  514. ReimbursementWayId: patient.ReimbursementWayId,
  515. HealthCareType: patient.HealthCareType,
  516. HealthCareNo: patient.HealthCareNo,
  517. HealthCareDueDate: patient.HealthCareDueDate,
  518. Height: patient.Height,
  519. BloodType: patient.BloodType,
  520. Rh: patient.Rh,
  521. HealthCareDueAlertDate: patient.HealthCareDueAlertDate,
  522. EducationLevel: patient.EducationLevel,
  523. Profession: patient.Profession,
  524. Phone: patient.Phone,
  525. HomeTelephone: patient.HomeTelephone,
  526. RelativePhone: patient.RelativePhone,
  527. RelativeRelations: patient.RelativeRelations,
  528. HomeAddress: patient.HomeAddress,
  529. WorkUnit: patient.WorkUnit,
  530. UnitAddress: patient.UnitAddress,
  531. Children: patient.Children,
  532. ReceivingDate: patient.ReceivingDate,
  533. IsHospitalFirstDialysis: patient.IsHospitalFirstDialysis,
  534. FirstDialysisDate: patient.FirstDialysisDate,
  535. FirstDialysisHospital: patient.FirstDialysisHospital,
  536. PredialysisCondition: patient.PredialysisCondition,
  537. PreHospitalDialysisTimes: patient.PreHospitalDialysisTimes,
  538. HospitalFirstDialysisDate: patient.HospitalFirstDialysisDate,
  539. InductionPeriod: patient.InductionPeriod,
  540. InitialDialysis: patient.InitialDialysis,
  541. TotalDialysis: patient.TotalDialysis,
  542. AttendingDoctorId: patient.AttendingDoctorId,
  543. HeadNurseId: patient.HeadNurseId,
  544. Evaluate: patient.Evaluate,
  545. Diagnose: patient.Diagnose,
  546. Remark: patient.Remark,
  547. RegistrarsId: patient.RegistrarsId,
  548. Registrars: patient.Registrars,
  549. QrCode: patient.QrCode,
  550. BindingState: patient.BindingState,
  551. PatientComplains: patient.PatientComplains,
  552. PresentHistory: patient.PresentHistory,
  553. PastHistory: patient.PastHistory,
  554. Temperature: patient.Temperature,
  555. Pulse: patient.Pulse,
  556. Respiratory: patient.Respiratory,
  557. Sbp: patient.SBP,
  558. Dbp: patient.DBP,
  559. Nation: patient.Nation,
  560. NativePlace: patient.NativePlace,
  561. Age: patient.Age,
  562. InfectiousNextRecordTime: patient.InfectiousNextRecordTime,
  563. IsInfectious: patient.IsInfectious,
  564. RemindCycle: patient.RemindCycle,
  565. ResponseResult: patient.ResponseResult,
  566. IsOpenRemind: patient.IsOpenRemind,
  567. FirstTreatmentDate: patient.FirstTreatmentDate,
  568. DialysisAge: patient.DialysisAge,
  569. ExpenseKind: patient.ExpenseKind,
  570. TellPhone: patient.TellPhone,
  571. ContactName: patient.ContactName,
  572. UpdatedTime: time.Now().Unix(),
  573. BloodPatients: 1,
  574. Lapseto: patient.Lapseto,
  575. TrobleShoot: patient.TrobleShoot,
  576. SchRemark: patient.SchRemark,
  577. TreatmentPlan: patient.TreatmentPlan,
  578. RecordNumber: patient.RecordNumber,
  579. PatientSource: patient.PatientSource,
  580. PatientStartTime: patient.PatientStartTime,
  581. PatientEndTime: patient.PatientEndTime,
  582. InfectiousRemark: patient.InfectiousRemark,
  583. AllergicHistory: patient.AllergicHistory,
  584. PatientAddress: patient.PatientAddress,
  585. }
  586. // //更新病人ID获取新表病人ID
  587. err = service.UpdatepatientTwo(&patientsNew, id)
  588. allergic := models.XtPatientAllergic{
  589. PatientId: patient.ID,
  590. UserOrgId: adminUserInfo.CurrentOrgId,
  591. StartTime: patient.PatientStartTime,
  592. EndTime: patient.PatientEndTime,
  593. PatientSource: patient.PatientSource,
  594. Status: 1,
  595. Ctime: time.Now().Unix(),
  596. Mtime: time.Now().Unix(),
  597. Remake: patient.Remark,
  598. PatientAddress: patient.PatientAddress,
  599. }
  600. if len(patient.PatientAddress) > 0 {
  601. service.CreateAllergic(allergic)
  602. }
  603. nowTimeUinx := time.Now()
  604. today := nowTimeUinx.Format("2006-01-02")
  605. redis := service.RedisClient()
  606. defer redis.Close()
  607. key := "scheduals_" + today + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  608. redis.Set(key, "", time.Second*60*60*18)
  609. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":patient_info"
  610. redis.Set(keyOne, "", time.Second*60*60*18)
  611. if len(record_date) > 0 {
  612. var recordTime int64
  613. timeLayout := "2006-01-02"
  614. loc, _ := time.LoadLocation("Local")
  615. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  616. if err != nil {
  617. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  618. return
  619. }
  620. recordTime = theTime.Unix()
  621. inspections := make([]models.Inspection, 0)
  622. for _, item := range formItems {
  623. var inspection models.Inspection
  624. inspection.OrgId = adminUserInfo.CurrentOrgId
  625. inspection.PatientId = patient.ID
  626. inspection.ProjectId = item.ProjectId
  627. inspection.ItemId = item.ItemId
  628. inspection.ItemName = item.ItemName
  629. inspection.ProjectName = item.ProjectName
  630. inspection.InspectType = item.RangeType
  631. inspection.InspectValue = item.Value
  632. inspection.InspectDate = recordTime
  633. inspection.Status = 1
  634. inspection.CreatedTime = time.Now().Unix()
  635. inspection.UpdatedTime = time.Now().Unix()
  636. inspections = append(inspections, inspection)
  637. }
  638. err = service.CreatePatientInspection(inspections)
  639. infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient.ID, 14)
  640. var record_time int64
  641. switch remind_cycle {
  642. case 1: //1个月
  643. ts := time.Unix(infectiousRecord.InspectDate, 0)
  644. record_time = ts.AddDate(0, 1, 0).Unix()
  645. break
  646. case 2: //2个月
  647. ts := time.Unix(infectiousRecord.InspectDate, 0)
  648. record_time = ts.AddDate(0, 2, 0).Unix()
  649. break
  650. case 3: //3个月
  651. ts := time.Unix(infectiousRecord.InspectDate, 0)
  652. record_time = ts.AddDate(0, 3, 0).Unix()
  653. break
  654. case 4: //6个月
  655. ts := time.Unix(infectiousRecord.InspectDate, 0)
  656. record_time = ts.AddDate(0, 6, 0).Unix()
  657. break
  658. case 5: //12个月
  659. ts := time.Unix(infectiousRecord.InspectDate, 0)
  660. record_time = ts.AddDate(0, 12, 0).Unix()
  661. break
  662. }
  663. errs := service.UpDateInfectiousRecordTime(adminUserInfo.CurrentOrgId, patient.ID, record_time, remind_cycle)
  664. if errs != nil {
  665. utils.ErrorLog("更新日期出错:%v", errs)
  666. }
  667. }
  668. c.ServeSuccessJSON(map[string]interface{}{
  669. "msg": "ok",
  670. })
  671. return
  672. }
  673. func (c *PatientApiController) EditLapseto() {
  674. id, _ := c.GetInt64("id", 0)
  675. if id <= 0 {
  676. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  677. return
  678. }
  679. start_time := c.GetString("start_time")
  680. end_time := c.GetString("end_time")
  681. timeLayout := "2006-01-02"
  682. loc, _ := time.LoadLocation("Local")
  683. var startTime int64
  684. if len(start_time) > 0 {
  685. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  686. if err != nil {
  687. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  688. return
  689. }
  690. startTime = theTime.Unix()
  691. }
  692. var endTime int64
  693. if len(end_time) > 0 {
  694. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  695. if err != nil {
  696. utils.ErrorLog(err.Error())
  697. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  698. return
  699. }
  700. endTime = theTime.Unix()
  701. }
  702. patient_address := c.GetString("patient_address")
  703. adminUserInfo := c.GetAdminUserInfo()
  704. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  705. if patient.ID == 0 {
  706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  707. return
  708. }
  709. patientBody := make(map[string]interface{}, 0)
  710. err := json.Unmarshal(c.Ctx.Input.RequestBody, &patientBody)
  711. if err != nil {
  712. utils.ErrorLog(err.Error())
  713. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  714. return
  715. }
  716. var lapseto models.PatientLapseto
  717. lapseto.PatientId = patient.ID
  718. if patientBody["lapseto_type"] == nil || reflect.TypeOf(patientBody["lapseto_type"]).String() != "float64" {
  719. utils.ErrorLog("lapseto_type")
  720. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  721. return
  722. }
  723. lapsetoType := int64(patientBody["lapseto_type"].(float64))
  724. lapseto.LapsetoType = lapsetoType
  725. if patientBody["lapseto_time"] == nil || reflect.TypeOf(patientBody["lapseto_time"]).String() != "string" {
  726. utils.ErrorLog("lapseto_time")
  727. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoType)
  728. return
  729. }
  730. lapsetoTime, _ := patientBody["lapseto_time"].(string)
  731. //if len(lapsetoTime) == 0 {
  732. // utils.ErrorLog("len(lapsetoTime) == 0")
  733. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoTime)
  734. // return
  735. //}
  736. out_reason, _ := patientBody["out_reason"].(string)
  737. //if len(out_reason) == 0 {
  738. // utils.ErrorLog("len(out_reason) == 0")
  739. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoTime)
  740. // return
  741. //}
  742. lapsetoTimeUnix, err := time.ParseInLocation(timeLayout, lapsetoTime, loc)
  743. //if err != nil {
  744. // utils.ErrorLog("lapsetoTimeUnix")
  745. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoTime)
  746. // return
  747. //}
  748. lapseto.LapsetoTime = lapsetoTimeUnix.Unix()
  749. lapseto.UpdatedTime = time.Now().Unix()
  750. lapseto.CreatedTime = time.Now().Unix()
  751. lapseto.Status = 1
  752. patient.Lapseto = lapseto.LapsetoType
  753. patient.OutReason = out_reason
  754. patient.DeathTime = lapsetoTimeUnix.Unix()
  755. patient.PatientStartTime = startTime
  756. patient.PatientEndTime = endTime
  757. patient.PatientAddress = patient_address
  758. //if patient.Lapseto == 1 {
  759. // patientTotal := service.GetLapsetoPatientCount(adminUserInfo.CurrentOrgId, 1)
  760. // subscibes := adminUserInfo.Subscibes[adminUserInfo.CurrentOrgId]
  761. // if subscibes.State == 2 && patientTotal >= 100 { //免费试用版,不过期,限制患者数20
  762. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
  763. // return
  764. // } else if subscibes.State == 1 && patientTotal >= 200 { //标准版,不过期,限制患者数60
  765. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
  766. // return
  767. // }
  768. //}
  769. err = service.EditPatientLapseto(&patient, &lapseto)
  770. if lapseto.LapsetoType == 3 || lapseto.LapsetoType == 2 {
  771. timeStr := time.Now().Format("2006-01-02")
  772. timeLayout := "2006-01-02 15:04:05"
  773. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  774. timenow := timeStringToTime.Unix()
  775. service.UpdateScheduleByDeathTime(id, timenow)
  776. service.UpdateScheduleItemByPatientId(id)
  777. }
  778. allergic := models.XtPatientAllergic{
  779. UserOrgId: adminUserInfo.CurrentOrgId,
  780. PatientId: patient.ID,
  781. StartTime: patient.PatientStartTime,
  782. EndTime: patient.PatientEndTime,
  783. PatientSource: patient.Lapseto,
  784. PatientAddress: patient.PatientAddress,
  785. Remake: patient.Remark,
  786. Status: 1,
  787. Ctime: time.Now().Unix(),
  788. }
  789. if lapseto.LapsetoType == 2 || lapseto.LapsetoType == 3 {
  790. allergic.StartTime = lapseto.LapsetoTime
  791. allergic.EndTime = lapseto.LapsetoTime
  792. }
  793. service.CreateAllergic(allergic)
  794. if err != nil {
  795. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeEditLapsetoFail)
  796. return
  797. }
  798. c.ServeSuccessJSON(map[string]interface{}{
  799. "msg": "ok",
  800. })
  801. return
  802. }
  803. func (c *PatientApiController) GetPatient() {
  804. id, _ := c.GetInt64("id", 0)
  805. if id <= 0 {
  806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  807. return
  808. }
  809. adminUserInfo := c.GetAdminUserInfo()
  810. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  811. if patient.ID == 0 {
  812. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  813. return
  814. }
  815. infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient.ID, 14)
  816. infections, _ := service.GetAllInfectionRecord(infectiousRecord.InspectDate, adminUserInfo.CurrentOrgId, patient.ID, infectiousRecord.ProjectId)
  817. diseases := service.GetPatientDiseases(patient.ID)
  818. contagions := service.GetPatientContagions(patient.ID)
  819. c.ServeSuccessJSON(map[string]interface{}{
  820. "patient": patient,
  821. "diseases": diseases,
  822. "contagions": contagions,
  823. "infections": infections,
  824. })
  825. return
  826. }
  827. func (c *PatientApiController) CreateDialysisSolution() {
  828. id, _ := c.GetInt64("patient", 0)
  829. if id <= 0 {
  830. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  831. return
  832. }
  833. adminUserInfo := c.GetAdminUserInfo()
  834. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  835. if patient.ID == 0 {
  836. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  837. return
  838. }
  839. var solution models.DialysisSolution
  840. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "create")
  841. if code > 0 {
  842. c.ServeFailJSONWithSGJErrorCode(code)
  843. return
  844. }
  845. //thisSolution, _ := service.FindPatientDialysisSolutionByMode(adminUserInfo.CurrentOrgId, id, solution.ModeId)
  846. //if thisSolution.ID > 0 {
  847. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionExist)
  848. // return
  849. //}
  850. solution.RegistrarsId = adminUserInfo.AdminUser.Id
  851. solution.Doctor = adminUserInfo.AdminUser.Id
  852. solution.Status = 1
  853. solution.PatientId = id
  854. solution.CreatedTime = time.Now().Unix()
  855. solution.UserOrgId = adminUserInfo.CurrentOrgId
  856. solution.UpdatedTime = time.Now().Unix()
  857. solution.SubName = ""
  858. solution.ParentId = 0
  859. solution.SolutionStatus = 1
  860. //records, _ := service.GetAllSchedules()
  861. schs, _ := service.GetAllSchedulesByPatientInfo(adminUserInfo.CurrentOrgId, id, solution.ModeId)
  862. for _, sch := range schs {
  863. var DialysisMachineName string
  864. if len(solution.DialysisDialyszers) > 0 {
  865. DialysisMachineName = solution.DialysisDialyszers
  866. }
  867. if len(solution.DialyzerPerfusionApparatus) > 0 {
  868. DialysisMachineName = DialysisMachineName + "," + solution.DialyzerPerfusionApparatus
  869. }
  870. if len(solution.DialysisIrrigation) > 0 {
  871. DialysisMachineName = DialysisMachineName + "," + solution.DialysisIrrigation
  872. }
  873. sch.DialysisMachineName = DialysisMachineName
  874. service.UpdateSch(sch)
  875. }
  876. err := service.CreatePatientDialysisSolution(&solution)
  877. //获取最新1条
  878. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.CurrentOrgId)
  879. //更新状态
  880. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  881. if err != nil {
  882. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionCreate)
  883. return
  884. }
  885. c.ServeSuccessJSON(map[string]interface{}{
  886. "msg": "ok",
  887. "solution": solution,
  888. })
  889. return
  890. }
  891. func (c *PatientApiController) UpdateDialysisSolution() {
  892. patient, _ := c.GetInt64("patient", 0)
  893. id, _ := c.GetInt64("id", 0)
  894. if id <= 0 || patient <= 0 {
  895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  896. return
  897. }
  898. adminUserInfo := c.GetAdminUserInfo()
  899. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.CurrentOrgId, id)
  900. if solution.ID == 0 || solution.PatientId != patient {
  901. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  902. return
  903. }
  904. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "edit")
  905. if code > 0 {
  906. c.ServeFailJSONWithSGJErrorCode(code)
  907. return
  908. }
  909. solution.UpdatedTime = time.Now().Unix()
  910. err := service.UpdatePatientDialysisSolution(&solution)
  911. nowTimeUinx := time.Now()
  912. today := nowTimeUinx.Format("2006-01-02")
  913. timeLayout := "2006-01-02"
  914. loc, _ := time.LoadLocation("Local")
  915. todayTime, err := time.ParseInLocation(timeLayout, today, loc)
  916. if adminUserInfo.CurrentOrgId == 9538 {
  917. prescription := models.DialysisPrescription{
  918. Dialyzer: solution.Dialyzer,
  919. Anticoagulant: solution.Anticoagulant,
  920. AnticoagulantShouji: solution.AnticoagulantShouji,
  921. AnticoagulantWeichi: solution.AnticoagulantWeichi,
  922. AnticoagulantZongliang: solution.AnticoagulantZongliang,
  923. ModeId: solution.ModeId,
  924. DialysisDurationHour: solution.DialysisDurationHour,
  925. Kalium: solution.Kalium,
  926. Sodium: solution.Sodium,
  927. Calcium: solution.Calcium,
  928. TargetUltrafiltration: solution.TargetUltrafiltration,
  929. DialyzerPerfusionApparatus: solution.DialyzerPerfusionApparatus,
  930. BloodAccess: solution.BloodAccess,
  931. DialysateFlow: solution.DialysateFlow,
  932. DialysateTemperature: solution.DialysateTemperature,
  933. DialysisIrrigation: solution.DialysisIrrigation,
  934. DialysisDialyszers: solution.DialysisDialyszers,
  935. PlasmaSeparator: solution.PlasmaSeparator,
  936. BilirubinAdsorptionColumn: solution.BilirubinAdsorptionColumn,
  937. OxygenUptake: solution.OxygenUptake,
  938. OxygenFlow: solution.OxygenFlow,
  939. OxygenTime: solution.OxygenTime,
  940. MaxUltrafiltrationRate: solution.MaxUltrafiltrationRate,
  941. Amylaceum: solution.Amylaceum,
  942. DialysisStrainer: solution.DialysisStrainer,
  943. Chaptalization: solution.Chaptalization,
  944. BloodAccessPartId: solution.BloodAccessPartId,
  945. }
  946. service.UpdatePatientDialysisSolutionOne(solution.PatientId, adminUserInfo.CurrentOrgId, &prescription, todayTime.Unix())
  947. }
  948. schs, _ := service.GetAllSchedulesByPatientInfo(adminUserInfo.CurrentOrgId, solution.PatientId, solution.ModeId)
  949. for _, sch := range schs {
  950. var DialysisMachineName string
  951. if len(solution.DialysisDialyszers) > 0 {
  952. DialysisMachineName = solution.DialysisDialyszers
  953. }
  954. if len(solution.DialyzerPerfusionApparatus) > 0 {
  955. DialysisMachineName = DialysisMachineName + "," + solution.DialyzerPerfusionApparatus
  956. }
  957. if len(solution.DialysisIrrigation) > 0 {
  958. DialysisMachineName = DialysisMachineName + "," + solution.DialysisIrrigation
  959. }
  960. sch.DialysisMachineName = DialysisMachineName
  961. service.UpdateSch(sch)
  962. }
  963. if err != nil {
  964. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  965. return
  966. }
  967. c.ServeSuccessJSON(map[string]interface{}{
  968. "msg": "ok",
  969. "solution": solution,
  970. })
  971. return
  972. }
  973. func (c *PatientApiController) UpdateDialysisSolutionDetail() {
  974. patient, _ := c.GetInt64("patient", 0)
  975. id, _ := c.GetInt64("id", 0)
  976. if id <= 0 || patient <= 0 {
  977. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  978. return
  979. }
  980. adminUserInfo := c.GetAdminUserInfo()
  981. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.CurrentOrgId, id)
  982. if solution.ID == 0 || solution.PatientId != patient {
  983. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  984. return
  985. }
  986. code := solutionFormData(&solution, c.Ctx.Input.RequestBody)
  987. if code > 0 {
  988. c.ServeFailJSONWithSGJErrorCode(code)
  989. return
  990. }
  991. solution.UpdatedTime = time.Now().Unix()
  992. solution.AffirmState = 1
  993. err := service.UpdatePatientDialysisSolution(&solution)
  994. if err != nil {
  995. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  996. return
  997. }
  998. c.ServeSuccessJSON(map[string]interface{}{
  999. "msg": "ok",
  1000. "solution": solution,
  1001. })
  1002. return
  1003. }
  1004. func (c *PatientApiController) GetPatientDialysisSolutionList() {
  1005. id, _ := c.GetInt64("id", 0)
  1006. page, _ := c.GetInt64("page", 0)
  1007. limit, _ := c.GetInt64("limit", 0)
  1008. if id <= 0 {
  1009. c.ServeSuccessJSON(map[string]interface{}{
  1010. "solutions": nil,
  1011. })
  1012. return
  1013. }
  1014. if page <= 0 {
  1015. page = 1
  1016. }
  1017. if limit <= 0 {
  1018. limit = 10
  1019. }
  1020. adminUserInfo := c.GetAdminUserInfo()
  1021. solutions, total, _ := service.GetPatientDialysisSolutionList(adminUserInfo.CurrentOrgId, id, page, limit)
  1022. stockType, _ := service.GetStockType(adminUserInfo.CurrentOrgId)
  1023. c.ServeSuccessJSON(map[string]interface{}{
  1024. "solutions": solutions,
  1025. "total": total,
  1026. "stockType": stockType,
  1027. })
  1028. return
  1029. }
  1030. func (c *PatientApiController) DeleteDialysisSolution() {
  1031. id, _ := c.GetInt64("id", 0)
  1032. if id <= 0 {
  1033. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1034. return
  1035. }
  1036. adminUserInfo := c.GetAdminUserInfo()
  1037. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.CurrentOrgId, id)
  1038. if solution.ID == 0 {
  1039. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  1040. return
  1041. }
  1042. if solution.UseState == 1 {
  1043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUsed)
  1044. return
  1045. }
  1046. solution.UpdatedTime = time.Now().Unix()
  1047. solution.Status = 0
  1048. err := service.DeleteSolution(&solution)
  1049. if err != nil {
  1050. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionDelete)
  1051. return
  1052. }
  1053. c.ServeSuccessJSON(map[string]interface{}{
  1054. "msg": "ok",
  1055. })
  1056. return
  1057. }
  1058. // GetDryWeights 取患者干体重调整铺
  1059. func (c *PatientApiController) GetDryWeights() {
  1060. page, _ := c.GetInt64("page", 1)
  1061. limit, _ := c.GetInt64("limit", 10)
  1062. id, _ := c.GetInt64("id", 0)
  1063. if id <= 0 {
  1064. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1065. return
  1066. }
  1067. adminUserInfo := c.GetAdminUserInfo()
  1068. weights, total, _ := service.GetPatientDryWeightAdjustList(adminUserInfo.CurrentOrgId, id, page, limit)
  1069. c.ServeSuccessJSON(map[string]interface{}{
  1070. "weights": weights,
  1071. "total": total,
  1072. })
  1073. return
  1074. }
  1075. func (c *PatientApiController) CreateDryWeights() {
  1076. patient, _ := c.GetInt64("id", 0)
  1077. if patient <= 0 {
  1078. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1079. return
  1080. }
  1081. adminUserInfo := c.GetAdminUserInfo()
  1082. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1083. if patientInfo.ID == 0 {
  1084. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1085. return
  1086. }
  1087. var theWeight models.DryWeightAdjust
  1088. dataBody := make(map[string]interface{}, 0)
  1089. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1090. if err != nil {
  1091. utils.ErrorLog(err.Error())
  1092. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1093. return
  1094. }
  1095. if dataBody["weight"] == nil || reflect.TypeOf(dataBody["weight"]).String() != "string" {
  1096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1097. return
  1098. }
  1099. weight, _ := strconv.ParseFloat(dataBody["weight"].(string), 64)
  1100. theWeight.Weight = weight
  1101. // if dataBody["doctor"] == nil || reflect.TypeOf(dataBody["doctor"]).String() != "float64" {
  1102. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1103. // return
  1104. // }
  1105. // doctor := int64(dataBody["doctor"].(float64))
  1106. // theWeight.Doctor = doctor
  1107. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  1108. remark, _ := dataBody["remark"].(string)
  1109. theWeight.Remark = remark
  1110. }
  1111. theWeight.CreatedTime = time.Now().Unix()
  1112. theWeight.UpdatedTime = time.Now().Unix()
  1113. theWeight.Status = 1
  1114. theWeight.RegistrarsId = adminUserInfo.AdminUser.Id
  1115. theWeight.UserOrgId = adminUserInfo.CurrentOrgId
  1116. theWeight.PatientId = patient
  1117. theWeight.Doctor = adminUserInfo.AdminUser.Id
  1118. old, _ := service.FindPatientLastDryWeightAdjust(adminUserInfo.CurrentOrgId, patient)
  1119. if old.ID > 0 {
  1120. theWeight.AdjustedValue = theWeight.Weight - old.Weight
  1121. }
  1122. err = service.CreateDryWeightAdjust(&theWeight)
  1123. if err != nil {
  1124. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDryWeightFail)
  1125. return
  1126. }
  1127. c.ServeSuccessJSON(map[string]interface{}{
  1128. "msg": "ok",
  1129. "weight": theWeight,
  1130. })
  1131. return
  1132. }
  1133. func (c *PatientApiController) CreateGroupAdvice() {
  1134. var err error
  1135. defer func() {
  1136. if rec := recover(); rec != nil {
  1137. err = fmt.Errorf("程序异常:%v", rec)
  1138. }
  1139. if err != nil {
  1140. service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
  1141. }
  1142. }()
  1143. patient, _ := c.GetInt64("id", 0)
  1144. groupNo, _ := c.GetInt64("groupno", 0)
  1145. if patient <= 0 {
  1146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1147. return
  1148. }
  1149. adminUserInfo := c.GetAdminUserInfo()
  1150. var patientInfo models.Patients
  1151. patientInfo, err = service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1152. if patientInfo.ID == 0 {
  1153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1154. return
  1155. }
  1156. dataBody := make(map[string]interface{}, 0)
  1157. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1158. if err != nil {
  1159. utils.ErrorLog(err.Error())
  1160. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1161. return
  1162. }
  1163. utils.ErrorLog("%v", dataBody)
  1164. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1165. if appRole.UserType == 3 {
  1166. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1167. if getPermissionErr != nil {
  1168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1169. return
  1170. } else if headNursePermission == nil {
  1171. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1172. return
  1173. }
  1174. }
  1175. timeLayout := "2006-01-02"
  1176. loc, _ := time.LoadLocation("Local")
  1177. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  1178. utils.ErrorLog("advice_type")
  1179. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1180. return
  1181. }
  1182. adviceType := int64(dataBody["advice_type"].(float64))
  1183. if adviceType != 1 && adviceType != 2 && adviceType != 3 && adviceType != 4 {
  1184. utils.ErrorLog("advice_type != 1&&2")
  1185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1186. return
  1187. }
  1188. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  1189. utils.ErrorLog("advice_date")
  1190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1191. return
  1192. }
  1193. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  1194. utils.ErrorLog("start_time")
  1195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1196. return
  1197. }
  1198. startTime2, _ := dataBody["start_time"].(string)
  1199. time_arr := strings.Split(startTime2, " ")
  1200. if len(time_arr) > 0 {
  1201. startTime2 = time_arr[0]
  1202. }
  1203. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  1204. utils.ErrorLog("advice_date")
  1205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1206. return
  1207. }
  1208. adviceDate := startTime2
  1209. if len(adviceDate) == 0 {
  1210. utils.ErrorLog("len(adviceDate) == 0")
  1211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1212. return
  1213. }
  1214. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  1215. if err != nil {
  1216. utils.ErrorLog(err.Error())
  1217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1218. return
  1219. }
  1220. AdviceDate := theTime.Unix()
  1221. RecordDate := theTime.Unix()
  1222. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  1223. utils.ErrorLog("start_time")
  1224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1225. return
  1226. }
  1227. startTime, _ := dataBody["start_time"].(string)
  1228. if len(startTime) == 0 {
  1229. utils.ErrorLog("len(start_time) == 0")
  1230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1231. return
  1232. }
  1233. theTime, err = time.ParseInLocation(timeLayout+" 15:04", startTime, loc)
  1234. if err != nil {
  1235. utils.ErrorLog(err.Error())
  1236. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1237. return
  1238. }
  1239. StartTime := theTime.Unix()
  1240. Remark := ""
  1241. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  1242. remark, _ := dataBody["remark"].(string)
  1243. Remark = remark
  1244. }
  1245. var advices []*models.GroupAdvice
  1246. if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
  1247. utils.ErrorLog("adviceNames")
  1248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1249. return
  1250. }
  1251. adviceNames := dataBody["adviceNames"].([]interface{})
  1252. for _, adviceNameMap := range adviceNames {
  1253. adviceNameM := adviceNameMap.(map[string]interface{})
  1254. var advice models.GroupAdvice
  1255. advice.Remark = Remark
  1256. advice.AdviceType = adviceType
  1257. advice.StartTime = StartTime
  1258. advice.AdviceDate = AdviceDate
  1259. advice.RecordDate = RecordDate
  1260. advice.Status = 1
  1261. advice.CreatedTime = time.Now().Unix()
  1262. advice.UpdatedTime = time.Now().Unix()
  1263. advice.StopState = 2
  1264. advice.ExecutionState = 2
  1265. advice.UserOrgId = adminUserInfo.CurrentOrgId
  1266. advice.PatientId = patientInfo.ID
  1267. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  1268. advice.IsSettle = 2
  1269. //创建步骤表
  1270. finish := models.XtDialysisFinish{
  1271. IsFinish: 1,
  1272. UserOrgId: adminUserInfo.CurrentOrgId,
  1273. Status: 1,
  1274. Ctime: time.Now().Unix(),
  1275. Mtime: 0,
  1276. Module: 4,
  1277. RecordDate: advice.RecordDate,
  1278. Sourse: 1,
  1279. PatientId: patient,
  1280. }
  1281. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, advice.RecordDate, 4, patient)
  1282. if dialysisFinish.ID == 0 {
  1283. service.CreateDialysisFinish(finish)
  1284. }
  1285. // 查询信息规挡的设置天数
  1286. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1287. if infor.ID > 0 && infor.WeekDay > 0 {
  1288. var cha_time int64
  1289. timeNowStr := time.Now().Format("2006-01-02")
  1290. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1291. //今日的日期减去设置的日期
  1292. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1293. if cha_time >= advice.AdviceDate {
  1294. //查询审核是否允许
  1295. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  1296. //申请状态不允许的情况 拒绝修改
  1297. if infor.ApplicationStatus != 1 {
  1298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1299. return
  1300. }
  1301. }
  1302. }
  1303. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  1304. utils.ErrorLog("advice_name")
  1305. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1306. return
  1307. }
  1308. adviceName, _ := adviceNameM["advice_name"].(string)
  1309. if len(adviceName) == 0 {
  1310. utils.ErrorLog("len(advice_name) == 0")
  1311. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1312. return
  1313. }
  1314. advice.AdviceName = adviceName
  1315. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  1316. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  1317. advice.DrugSpec = drugSpec
  1318. }
  1319. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  1320. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  1321. advice.AdviceDesc = adviceDesc
  1322. }
  1323. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  1324. template_id, _ := adviceNameM["template_id"].(string)
  1325. advice.TemplateId = template_id
  1326. }
  1327. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  1328. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  1329. advice.DrugSpecUnit = drugSpecUnit
  1330. }
  1331. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  1332. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  1333. advice.SingleDose = singleDose
  1334. }
  1335. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  1336. singleDose := adviceNameM["single_dose"].(float64)
  1337. advice.SingleDose = singleDose
  1338. }
  1339. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  1340. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  1341. advice.SingleDoseUnit = singleDoseUnit
  1342. }
  1343. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
  1344. tmp := adviceNameM["single_dose_unit"].(float64)
  1345. singleDoseUnit := service.TypeConversion(tmp)
  1346. advice.SingleDoseUnit = singleDoseUnit
  1347. }
  1348. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  1349. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  1350. advice.PrescribingNumber = prescribingNumber
  1351. }
  1352. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  1353. prescribingNumber := adviceNameM["prescribing_number"].(float64)
  1354. advice.PrescribingNumber = prescribingNumber
  1355. }
  1356. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  1357. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  1358. advice.PrescribingNumberUnit = prescribingNumberUnit
  1359. }
  1360. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  1361. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  1362. advice.DeliveryWay = deliveryWay
  1363. }
  1364. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  1365. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  1366. advice.ExecutionFrequency = executionFrequency
  1367. }
  1368. if adviceNameM["way"] != nil && reflect.TypeOf(adviceNameM["way"]).String() == "string" {
  1369. way, _ := strconv.ParseFloat(adviceNameM["way"].(string), 64)
  1370. advice.Way = int64(way)
  1371. }
  1372. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  1373. way := int64(adviceNameM["way"].(float64))
  1374. advice.Way = way
  1375. }
  1376. if adviceNameM["drug_id"] != nil && reflect.TypeOf(adviceNameM["drug_id"]).String() == "string" {
  1377. drug_id, _ := strconv.ParseFloat(adviceNameM["drug_id"].(string), 64)
  1378. advice.DrugId = int64(drug_id)
  1379. }
  1380. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  1381. drug_id := int64(adviceNameM["drug_id"].(float64))
  1382. advice.DrugId = drug_id
  1383. }
  1384. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  1385. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  1386. advice.DrugNameId = drug_name_id
  1387. }
  1388. remark, _ := adviceNameM["remark"].(string)
  1389. advice.Remark = remark
  1390. if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 10340 || adminUserInfo.CurrentOrgId == 9671 {
  1391. if advice.PrescribingNumber == 0 {
  1392. advice.PrescribingNumber = 1
  1393. }
  1394. //查询该患者今日有没有双人核对
  1395. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.CurrentOrgId, patientInfo.ID, advice.AdviceDate)
  1396. fmt.Println("chek", check)
  1397. if check.ID > 0 {
  1398. advice.Checker = check.Modifier
  1399. advice.CheckState = 1
  1400. advice.CheckTime = time.Now().Unix()
  1401. }
  1402. }
  1403. if adviceType == 1 {
  1404. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  1405. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  1406. advice.FrequencyType = frequency_type
  1407. }
  1408. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "string" {
  1409. day_count, _ := strconv.ParseInt(adviceNameM["day_count"].(string), 10, 64)
  1410. advice.DayCount = day_count
  1411. }
  1412. if adviceNameM["week_days"] != nil && reflect.TypeOf(adviceNameM["week_days"]).String() == "string" {
  1413. week_day, _ := adviceNameM["week_days"].(string)
  1414. advice.WeekDay = week_day
  1415. }
  1416. if adviceNameM["push_start_time"] != nil && reflect.TypeOf(adviceNameM["push_start_time"]).String() == "string" {
  1417. push_start_time, _ := adviceNameM["push_start_time"].(string)
  1418. var startTime int64
  1419. if len(push_start_time) > 0 {
  1420. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", push_start_time+" 00:00:00", loc)
  1421. startTime = theTime.Unix()
  1422. }
  1423. advice.PushStartTime = startTime
  1424. }
  1425. }
  1426. if adviceNameM["children"] != nil && reflect.TypeOf(adviceNameM["children"]).String() == "string" {
  1427. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  1428. advice.ExecutionFrequency = executionFrequency
  1429. }
  1430. if adviceNameM["children"] != nil && reflect.TypeOf(adviceNameM["children"]).String() == "[]interface {}" {
  1431. children := adviceNameM["children"].([]interface{})
  1432. if len(children) > 0 {
  1433. for _, childrenMap := range children {
  1434. childMap := childrenMap.(map[string]interface{})
  1435. var child models.GroupAdvice
  1436. child.Remark = Remark
  1437. child.AdviceType = adviceType
  1438. child.StartTime = StartTime
  1439. child.AdviceDate = AdviceDate
  1440. child.RecordDate = RecordDate
  1441. child.Status = 1
  1442. child.CreatedTime = time.Now().Unix()
  1443. child.UpdatedTime = time.Now().Unix()
  1444. child.StopState = 2
  1445. child.ExecutionState = 2
  1446. child.UserOrgId = adminUserInfo.CurrentOrgId
  1447. child.PatientId = patientInfo.ID
  1448. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  1449. child.IsSettle = 2
  1450. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  1451. utils.ErrorLog("child advice_name")
  1452. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1453. return
  1454. }
  1455. childAdviceName, _ := childMap["advice_name"].(string)
  1456. if len(childAdviceName) == 0 {
  1457. utils.ErrorLog("len(child advice_name) == 0")
  1458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1459. return
  1460. }
  1461. child.AdviceName = childAdviceName
  1462. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  1463. childAdviceDesc, _ := childMap["advice_desc"].(string)
  1464. child.AdviceDesc = childAdviceDesc
  1465. }
  1466. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  1467. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  1468. child.DrugSpec = childDrugSpec
  1469. }
  1470. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  1471. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  1472. child.DrugSpecUnit = childDrugSpecUnit
  1473. }
  1474. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "string" {
  1475. childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  1476. child.SingleDose = childSingleDose
  1477. }
  1478. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  1479. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  1480. child.SingleDoseUnit = childSingleDoseUnit
  1481. }
  1482. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "string" {
  1483. childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  1484. child.PrescribingNumber = childPrescribingNumber
  1485. }
  1486. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  1487. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  1488. child.PrescribingNumberUnit = childPrescribingNumberUnit
  1489. }
  1490. if childMap["drug_id"] != nil && reflect.TypeOf(childMap["drug_id"]).String() == "float64" {
  1491. drug_id := int64(childMap["drug_id"].(float64))
  1492. child.DrugId = drug_id
  1493. }
  1494. if childMap["way"] != nil && reflect.TypeOf(childMap["way"]).String() == "float64" {
  1495. way := int64(childMap["way"].(float64))
  1496. child.Way = way
  1497. }
  1498. if childMap["drug_name_id"] != nil && reflect.TypeOf(childMap["drug_name_id"]).String() == "float64" {
  1499. drug_name_id := int64(childMap["drug_name_id"].(float64))
  1500. child.DrugNameId = drug_name_id
  1501. }
  1502. child.DeliveryWay = advice.DeliveryWay
  1503. child.ExecutionFrequency = advice.ExecutionFrequency
  1504. if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 10340 || adminUserInfo.CurrentOrgId == 9671 {
  1505. if child.PrescribingNumber == 0 {
  1506. child.PrescribingNumber = 1
  1507. }
  1508. //查询该患者今日有没有双人核对
  1509. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.CurrentOrgId, patientInfo.ID, child.AdviceDate)
  1510. if check.ID > 0 {
  1511. child.Checker = check.Modifier
  1512. child.CheckState = 1
  1513. child.CheckTime = time.Now().Unix()
  1514. }
  1515. }
  1516. advice.Children = append(advice.Children, &child)
  1517. }
  1518. }
  1519. }
  1520. advices = append(advices, &advice)
  1521. }
  1522. list, err := service.CreateMGroupAdvice(adminUserInfo.CurrentOrgId, advices, groupNo)
  1523. for _, item := range advices {
  1524. //记录日志
  1525. byterequest, _ := json.Marshal(item)
  1526. adviceLog := models.XtDoctorAdviceLog{
  1527. UserOrgId: item.UserOrgId,
  1528. PatientId: item.PatientId,
  1529. AdminUserId: adminUserInfo.AdminUser.Id,
  1530. Module: 1,
  1531. ErrLog: string(byterequest),
  1532. Status: 1,
  1533. Ctime: time.Now().Unix(),
  1534. Mtime: 0,
  1535. Source: "电导端批量插入医嘱",
  1536. RecordDate: item.AdviceDate,
  1537. }
  1538. service.CreateDoctorAdviceLog(adviceLog)
  1539. }
  1540. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  1541. redis := service.RedisClient()
  1542. defer redis.Close()
  1543. redis.Set(key, "", time.Second)
  1544. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  1545. redis.Set(keyOne, "", time.Second)
  1546. if err != nil {
  1547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  1548. return
  1549. }
  1550. c.ServeSuccessJSON(map[string]interface{}{
  1551. "msg": "ok",
  1552. "advices": list,
  1553. })
  1554. return
  1555. }
  1556. func (c *PatientApiController) CreateDoctorAdvice() {
  1557. patient, _ := c.GetInt64("id", 0)
  1558. if patient <= 0 {
  1559. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1560. return
  1561. }
  1562. adminUserInfo := c.GetAdminUserInfo()
  1563. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1564. if patientInfo.ID == 0 {
  1565. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1566. return
  1567. }
  1568. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1569. if appRole.UserType == 3 {
  1570. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1571. if getPermissionErr != nil {
  1572. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1573. return
  1574. } else if headNursePermission == nil {
  1575. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1576. return
  1577. }
  1578. }
  1579. var advice models.DoctorAdvice
  1580. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  1581. if code > 0 {
  1582. c.ServeFailJSONWithSGJErrorCode(code)
  1583. return
  1584. }
  1585. if advice.ParentId > 0 {
  1586. old, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, advice.ParentId)
  1587. if old.ID == 0 || old.PatientId != patient {
  1588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  1589. return
  1590. }
  1591. if old.StopState == 1 || old.ExecutionState == 1 {
  1592. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  1593. return
  1594. }
  1595. if old.ParentId > 0 {
  1596. advice.ParentId = old.ParentId
  1597. }
  1598. advice.StartTime = old.StartTime
  1599. advice.AdviceDoctor = old.AdviceDoctor
  1600. advice.DeliveryWay = old.DeliveryWay
  1601. advice.ExecutionFrequency = old.ExecutionFrequency
  1602. advice.GroupNo = old.GroupNo
  1603. }
  1604. advice.Status = 1
  1605. advice.CreatedTime = time.Now().Unix()
  1606. advice.UpdatedTime = time.Now().Unix()
  1607. advice.StopState = 2
  1608. advice.ExecutionState = 2
  1609. advice.UserOrgId = adminUserInfo.CurrentOrgId
  1610. advice.PatientId = patient
  1611. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  1612. // 查询信息规挡的设置天数
  1613. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1614. if infor.ID > 0 && infor.WeekDay > 0 {
  1615. var cha_time int64
  1616. timeNowStr := time.Now().Format("2006-01-02")
  1617. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1618. //今日的日期减去设置的日期
  1619. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1620. if cha_time >= advice.AdviceDate {
  1621. //查询审核是否允许
  1622. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  1623. //申请状态不允许的情况 拒绝修改
  1624. if infor.ApplicationStatus != 1 {
  1625. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1626. return
  1627. }
  1628. }
  1629. }
  1630. if advice.UserOrgId == 3877 || advice.UserOrgId == 10340 || advice.UserOrgId == 9671 {
  1631. if advice.PrescribingNumber == 0 {
  1632. advice.PrescribingNumber = 1
  1633. }
  1634. //查询该患者今日有没有双人核对
  1635. check, _ := service.MobileGetDoubleCheckSix(advice.UserOrgId, patientInfo.ID, advice.AdviceDate)
  1636. if check.ID > 0 {
  1637. advice.Checker = check.Modifier
  1638. advice.CheckState = 1
  1639. advice.CheckTime = time.Now().Unix()
  1640. }
  1641. }
  1642. err := service.CreateDoctorAdvice(&advice)
  1643. //记录日志
  1644. byterequest, _ := json.Marshal(advice)
  1645. adviceLog := models.XtDoctorAdviceLog{
  1646. UserOrgId: advice.UserOrgId,
  1647. PatientId: advice.PatientId,
  1648. AdminUserId: adminUserInfo.AdminUser.Id,
  1649. Module: 1,
  1650. ErrLog: string(byterequest),
  1651. Status: 1,
  1652. Ctime: time.Now().Unix(),
  1653. Mtime: 0,
  1654. Source: "电脑新增医嘱",
  1655. RecordDate: advice.RecordDate,
  1656. }
  1657. service.CreateDoctorAdviceLog(adviceLog)
  1658. //创建步骤表
  1659. finish := models.XtDialysisFinish{
  1660. IsFinish: 1,
  1661. UserOrgId: adminUserInfo.CurrentOrgId,
  1662. Status: 1,
  1663. Ctime: time.Now().Unix(),
  1664. Mtime: 0,
  1665. Module: 4,
  1666. RecordDate: advice.AdviceDate,
  1667. Sourse: 1,
  1668. PatientId: patient,
  1669. }
  1670. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, advice.AdviceDate, 4, patient)
  1671. if dialysisFinish.ID == 0 {
  1672. service.CreateDialysisFinish(finish)
  1673. }
  1674. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1675. redis := service.RedisClient()
  1676. defer redis.Close()
  1677. redis.Set(key, "", time.Second)
  1678. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1679. redis.Set(keyOne, "", time.Second)
  1680. if err != nil {
  1681. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  1682. return
  1683. }
  1684. c.ServeSuccessJSON(map[string]interface{}{
  1685. "msg": "ok",
  1686. "advice": advice,
  1687. })
  1688. return
  1689. }
  1690. func (c *PatientApiController) ExecGroupAdvice() {
  1691. groupNo, _ := c.GetInt64("groupno", 0)
  1692. executionTime := c.GetString("execution_time")
  1693. if groupNo <= 0 {
  1694. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1695. return
  1696. }
  1697. if len(executionTime) <= 0 {
  1698. utils.ErrorLog("execution_time")
  1699. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1700. return
  1701. }
  1702. adminUserInfo := c.GetAdminUserInfo()
  1703. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupNo)
  1704. if advice.ID == 0 {
  1705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1706. return
  1707. }
  1708. if advice.ExecutionState == 1 {
  1709. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1710. return
  1711. }
  1712. executionStaff := adminUserInfo.AdminUser.Id
  1713. // checker := adminUserInfo.AdminUser.Id
  1714. timeLayout := "2006-01-02 15:04:05"
  1715. loc, _ := time.LoadLocation("Local")
  1716. theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  1717. if err != nil {
  1718. utils.ErrorLog(err.Error())
  1719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1720. return
  1721. }
  1722. if advice.StartTime > theTime.Unix() {
  1723. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1724. return
  1725. }
  1726. exceAdvice := models.DoctorAdvice{
  1727. ExecutionStaff: executionStaff,
  1728. ExecutionTime: theTime.Unix(),
  1729. UpdatedTime: time.Now().Unix(),
  1730. }
  1731. err = service.ExceDoctorAdviceByGroupNo(&exceAdvice, groupNo, adminUserInfo.CurrentOrgId)
  1732. if err != nil {
  1733. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1734. return
  1735. }
  1736. //查询自动扣减是否开启
  1737. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  1738. //查询已经执行的医嘱
  1739. advicelist, _ := service.GetExceDoctorAdviceGroupNo(groupNo, adminUserInfo.CurrentOrgId)
  1740. if drugStockConfig.IsOpen == 1 {
  1741. for _, item := range advicelist {
  1742. medical, _ := service.GetBaseDrugMedical(advice.DrugId)
  1743. //查询这个患者这个患者这个药已经出库的所有数量
  1744. advicelist, _ := service.GetAllHisDoctorAdviceById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  1745. drugoutlist, _ := service.GetAllDrugFlowById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  1746. var total_count int64
  1747. var drug_count int64
  1748. for _, it := range advicelist {
  1749. if it.PrescribingNumberUnit == medical.MaxUnit {
  1750. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1751. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1752. total_count += prenumber * medical.MinNumber
  1753. }
  1754. if it.PrescribingNumberUnit == medical.MinUnit {
  1755. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1756. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1757. total_count += prenumber
  1758. }
  1759. }
  1760. for _, its := range drugoutlist {
  1761. if its.CountUnit == medical.MaxUnit {
  1762. drug_count += its.Count * medical.MinNumber
  1763. }
  1764. if its.CountUnit == medical.MinUnit {
  1765. drug_count += its.Count
  1766. }
  1767. }
  1768. if total_count == drug_count {
  1769. c.ServeSuccessJSON(map[string]interface{}{
  1770. "msg": "1",
  1771. "advice": advice,
  1772. })
  1773. return
  1774. }
  1775. var total int64
  1776. var prescribing_number_total int64
  1777. //查询默认出库仓库
  1778. houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  1779. //查询该药品在默认仓库是否有库存
  1780. list, _ := service.GetDrugTotalCountTwenty(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut)
  1781. //判断单位是否相等
  1782. if medical.MaxUnit == advice.PrescribingNumberUnit {
  1783. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1784. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1785. //转化为最小单位
  1786. total = list.Count*medical.MinNumber + list.StockMinNumber
  1787. prescribing_number_total = count * medical.MinNumber
  1788. }
  1789. if medical.MinUnit == advice.PrescribingNumberUnit {
  1790. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1791. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1792. total = list.Count*medical.MinNumber + list.StockMinNumber
  1793. prescribing_number_total = count
  1794. }
  1795. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1796. c.ServeSuccessJSON(map[string]interface{}{
  1797. "msg": "3",
  1798. "advice": advice,
  1799. })
  1800. return
  1801. }
  1802. if prescribing_number_total > total {
  1803. c.ServeSuccessJSON(map[string]interface{}{
  1804. "msg": "2",
  1805. "advice": advice,
  1806. })
  1807. return
  1808. }
  1809. if prescribing_number_total <= total {
  1810. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  1811. if medical.IsUse == 2 {
  1812. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  1813. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  1814. if drugOutInfo.ID == 0 {
  1815. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  1816. }
  1817. }
  1818. if pharmacyConfig.IsOpen != 1 {
  1819. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  1820. if drugOutInfo.ID == 0 {
  1821. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  1822. }
  1823. }
  1824. //查询默认仓库
  1825. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  1826. //查询默认仓库剩余多少库存
  1827. var sum_count int64
  1828. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1829. for _, its := range stockInfo {
  1830. if its.MaxUnit == medical.MaxUnit {
  1831. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1832. }
  1833. sum_count += its.StockMaxNumber + its.StockMinNumber
  1834. }
  1835. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1836. break
  1837. c.ServeSuccessJSON(map[string]interface{}{
  1838. "msg": "1",
  1839. "advice": advice,
  1840. })
  1841. return
  1842. }
  1843. if medical.IsUse == 1 {
  1844. c.ServeSuccessJSON(map[string]interface{}{
  1845. "msg": "1",
  1846. "advice": advice,
  1847. })
  1848. return
  1849. }
  1850. }
  1851. }
  1852. }
  1853. advice.ExecutionStaff = executionStaff
  1854. advice.ExecutionTime = theTime.Unix()
  1855. c.ServeSuccessJSON(map[string]interface{}{
  1856. "msg": "ok",
  1857. "advice": advice,
  1858. })
  1859. return
  1860. }
  1861. func (c *PatientApiController) ExecDoctorAdvice() {
  1862. origin, _ := c.GetInt64("origin", 0)
  1863. patient, _ := c.GetInt64("patient", 0)
  1864. id, _ := c.GetInt64("id", 0)
  1865. executionTime := c.GetString("execution_time")
  1866. if origin != 2 {
  1867. if id <= 0 || patient <= 0 {
  1868. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1869. return
  1870. }
  1871. if len(executionTime) <= 0 {
  1872. utils.ErrorLog("execution_time")
  1873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1874. return
  1875. }
  1876. adminUserInfo := c.GetAdminUserInfo()
  1877. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1878. if advice.ID == 0 || advice.PatientId != patient {
  1879. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1880. return
  1881. }
  1882. //医嘱已执行
  1883. if advice.ExecutionState == 1 {
  1884. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1885. return
  1886. }
  1887. executionStaff := adminUserInfo.AdminUser.Id
  1888. timeLayout := "2006-01-02 15:04:05"
  1889. loc, _ := time.LoadLocation("Local")
  1890. theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  1891. if err != nil {
  1892. utils.ErrorLog(err.Error())
  1893. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1894. return
  1895. }
  1896. if advice.StartTime > theTime.Unix() {
  1897. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1898. return
  1899. }
  1900. exceAdvice := models.DoctorAdvice{
  1901. ExecutionStaff: executionStaff,
  1902. ExecutionTime: theTime.Unix(),
  1903. UpdatedTime: time.Now().Unix(),
  1904. }
  1905. // 查询信息规挡的设置天数
  1906. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1907. if infor.ID > 0 && infor.WeekDay > 0 {
  1908. var cha_time int64
  1909. timeNowStr := time.Now().Format("2006-01-02")
  1910. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1911. //今日的日期减去设置的日期
  1912. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1913. if cha_time >= advice.AdviceDate {
  1914. //查询审核是否允许
  1915. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  1916. //申请状态不允许的情况 拒绝修改
  1917. if infor.ApplicationStatus != 1 {
  1918. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1919. return
  1920. }
  1921. }
  1922. }
  1923. if advice.ParentId > 0 {
  1924. err = service.ExceDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  1925. //记录日志
  1926. byterequest, _ := json.Marshal(exceAdvice)
  1927. doctorAdviceLog := models.XtDoctorAdviceLog{
  1928. UserOrgId: exceAdvice.UserOrgId,
  1929. PatientId: exceAdvice.PatientId,
  1930. AdminUserId: adminUserInfo.AdminUser.Id,
  1931. Module: 2,
  1932. ErrLog: string(byterequest),
  1933. Status: 1,
  1934. Ctime: time.Now().Unix(),
  1935. Mtime: 0,
  1936. Source: "电脑端执行医嘱",
  1937. RecordDate: exceAdvice.RecordDate,
  1938. }
  1939. service.CreateDoctorAdviceLog(doctorAdviceLog)
  1940. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1941. redis := service.RedisClient()
  1942. //清空key 值
  1943. redis.Set(key, "", time.Second)
  1944. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1945. redis.Set(keyTwo, "", time.Second)
  1946. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1947. redis.Set(keyThree, "", time.Second)
  1948. theTimes := theTime.Format("2006-01-02")
  1949. fmt.Println("theTIME", theTime)
  1950. keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1951. redis.Set(keyFour, "", time.Second)
  1952. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1953. redis.Set(keyFive, "", time.Second)
  1954. defer redis.Close()
  1955. } else {
  1956. err = service.ExceDoctorAdviceById(&exceAdvice, id, patient)
  1957. //记录日志
  1958. byterequest, _ := json.Marshal(exceAdvice)
  1959. doctorAdviceLog := models.XtDoctorAdviceLog{
  1960. UserOrgId: exceAdvice.UserOrgId,
  1961. PatientId: exceAdvice.PatientId,
  1962. AdminUserId: adminUserInfo.AdminUser.Id,
  1963. Module: 2,
  1964. ErrLog: string(byterequest),
  1965. Status: 1,
  1966. Ctime: time.Now().Unix(),
  1967. Mtime: 0,
  1968. Source: "电脑端执行医嘱",
  1969. RecordDate: exceAdvice.RecordDate,
  1970. }
  1971. service.CreateDoctorAdviceLog(doctorAdviceLog)
  1972. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1973. redis := service.RedisClient()
  1974. //清空key 值
  1975. redis.Set(key, "", time.Second)
  1976. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1977. redis.Set(keyTwo, "", time.Second)
  1978. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1979. redis.Set(keyThree, "", time.Second)
  1980. theTimes := theTime.Format("2006-01-02")
  1981. fmt.Println("theTIME", theTime)
  1982. keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1983. redis.Set(keyFour, "", time.Second)
  1984. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1985. redis.Set(keyFive, "", time.Second)
  1986. defer redis.Close()
  1987. }
  1988. if err != nil {
  1989. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1990. return
  1991. }
  1992. advice.ExecutionStaff = executionStaff
  1993. advice.ExecutionTime = theTime.Unix()
  1994. //处理出库相关逻辑
  1995. //1.判断是否启用药品管理和自备药出库功能
  1996. //药品管理信息
  1997. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  1998. //自备药信息
  1999. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.CurrentOrgId)
  2000. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  2001. if drugStockConfig.IsOpen == 1 {
  2002. var total int64
  2003. var prescribing_number_total int64
  2004. advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
  2005. for _, item := range advices {
  2006. houseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  2007. //查询该药品是否有库存
  2008. list, _ := service.GetDrugTotalCountTwenty(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  2009. //查询改药品信息
  2010. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  2011. //判断单位是否相等
  2012. if medical.MaxUnit == item.PrescribingNumberUnit {
  2013. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  2014. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2015. //转化为最小单位
  2016. total = list.Count*medical.MinNumber + list.StockMinNumber
  2017. prescribing_number_total = count * medical.MinNumber
  2018. }
  2019. if medical.MinUnit == item.PrescribingNumberUnit {
  2020. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2021. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2022. total = list.Count*medical.MinNumber + list.StockMinNumber
  2023. prescribing_number_total = count
  2024. }
  2025. if medical.IsUse != 1 {
  2026. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  2027. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  2028. advice.ExecutionState = 2
  2029. advice.ExecutionStaff = 0
  2030. advice.ExecutionTime = 0
  2031. c.ServeSuccessJSON(map[string]interface{}{
  2032. "msg": "3",
  2033. "advice": advice,
  2034. })
  2035. return
  2036. }
  2037. if prescribing_number_total > total {
  2038. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  2039. advice.ExecutionState = 2
  2040. advice.ExecutionStaff = 0
  2041. advice.ExecutionTime = 0
  2042. c.ServeSuccessJSON(map[string]interface{}{
  2043. "msg": "2",
  2044. "advice": advice,
  2045. })
  2046. return
  2047. }
  2048. }
  2049. if medical.IsUse == 1 {
  2050. c.ServeSuccessJSON(map[string]interface{}{
  2051. "msg": "1",
  2052. "advice": advice,
  2053. })
  2054. return
  2055. }
  2056. if prescribing_number_total <= total {
  2057. //查询是否门诊处方和临时医嘱同步到透析医嘱的开关是否开启
  2058. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  2059. if adviceSetting.IsAdviceOpen == 1 {
  2060. //查询是否出库按钮开启
  2061. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  2062. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  2063. if prescriptionConfig.IsOpen == 1 {
  2064. if medical.IsUse == 2 {
  2065. //是通过药房发药
  2066. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  2067. //执行出库
  2068. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  2069. if drugOutInfo.ID == 0 {
  2070. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2071. }
  2072. }
  2073. //不通过药房发药
  2074. if pharmacyConfig.IsOpen != 1 {
  2075. //执行出库
  2076. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  2077. if drugOutInfo.ID == 0 {
  2078. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2079. }
  2080. }
  2081. //查询默认仓库
  2082. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  2083. //查询默认仓库剩余多少库存
  2084. var sum_count int64
  2085. //更新字典里面的库存
  2086. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2087. for _, its := range stockInfo {
  2088. if its.MaxUnit == medical.MaxUnit {
  2089. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  2090. }
  2091. sum_count += its.StockMaxNumber + its.StockMinNumber
  2092. }
  2093. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2094. //剩余库存
  2095. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  2096. break
  2097. c.ServeSuccessJSON(map[string]interface{}{
  2098. "msg": "1",
  2099. "advice": advice,
  2100. })
  2101. return
  2102. }
  2103. if medical.IsUse == 1 {
  2104. c.ServeSuccessJSON(map[string]interface{}{
  2105. "msg": "1",
  2106. "advice": advice,
  2107. })
  2108. return
  2109. }
  2110. } else {
  2111. if medical.IsUse == 1 {
  2112. c.ServeSuccessJSON(map[string]interface{}{
  2113. "msg": "1",
  2114. "advice": advice,
  2115. })
  2116. return
  2117. }
  2118. }
  2119. } else {
  2120. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  2121. if medical.IsUse == 2 {
  2122. //是通过药房发药
  2123. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  2124. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  2125. if drugOutInfo.ID == 0 {
  2126. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2127. }
  2128. }
  2129. //不通过药房发药
  2130. if pharmacyConfig.IsOpen != 1 {
  2131. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  2132. if drugOutInfo.ID == 0 {
  2133. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2134. }
  2135. }
  2136. //更新字典里面的库存
  2137. var sum_count int64
  2138. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2139. for _, its := range stockInfo {
  2140. if its.MaxUnit == medical.MaxUnit {
  2141. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  2142. }
  2143. sum_count += its.StockMaxNumber + its.StockMinNumber
  2144. }
  2145. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2146. //剩余库存
  2147. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  2148. break
  2149. c.ServeSuccessJSON(map[string]interface{}{
  2150. "msg": "1",
  2151. "advice": advice,
  2152. })
  2153. return
  2154. }
  2155. if medical.IsUse == 1 {
  2156. c.ServeSuccessJSON(map[string]interface{}{
  2157. "msg": "1",
  2158. "advice": advice,
  2159. })
  2160. return
  2161. }
  2162. }
  2163. }
  2164. }
  2165. }
  2166. advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
  2167. for _, item := range advices {
  2168. if item.Way == 2 {
  2169. if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
  2170. if item.ExecutionState == 1 {
  2171. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  2172. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2173. timeStr := time.Now().Format("2006-01-02")
  2174. timeArr := strings.Split(timeStr, "-")
  2175. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
  2176. total = total + 1
  2177. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2178. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2179. number = number + total
  2180. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2181. //插入自备药出库单
  2182. outStock := models.XtSelfOutStock{
  2183. DrugName: item.AdviceName,
  2184. DrugNameId: item.DrugId,
  2185. DrugSpec: item.AdviceDesc,
  2186. OutstoreNumber: count,
  2187. AdminUserId: adminUserInfo.AdminUser.Id,
  2188. StorckTime: item.RecordDate,
  2189. UserOrgId: adminUserInfo.CurrentOrgId,
  2190. CreatedTime: time.Now().Unix(),
  2191. Status: 1,
  2192. PatientId: item.PatientId,
  2193. ExitMode: 2,
  2194. MedicId: item.DrugId,
  2195. StockOutNumber: warehousing_out_order,
  2196. }
  2197. service.CreateOutStock(&outStock)
  2198. }
  2199. }
  2200. }
  2201. }
  2202. c.ServeSuccessJSON(map[string]interface{}{
  2203. "msg": "1",
  2204. "advice": advice,
  2205. })
  2206. return
  2207. } else {
  2208. if id <= 0 || patient <= 0 {
  2209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2210. return
  2211. }
  2212. if len(executionTime) <= 0 {
  2213. utils.ErrorLog("execution_time")
  2214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2215. return
  2216. }
  2217. adminUserInfo := c.GetAdminUserInfo()
  2218. advice, _ := service.FindHisDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2219. if advice.ID == 0 || advice.PatientId != patient {
  2220. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2221. return
  2222. }
  2223. //医嘱已执行
  2224. if advice.ExecutionState == 1 {
  2225. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  2226. return
  2227. }
  2228. executionStaff := adminUserInfo.AdminUser.Id
  2229. timeLayout := "2006-01-02 15:04:05"
  2230. loc, _ := time.LoadLocation("Local")
  2231. theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  2232. if err != nil {
  2233. utils.ErrorLog(err.Error())
  2234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2235. return
  2236. }
  2237. if advice.StartTime > theTime.Unix() {
  2238. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2239. return
  2240. }
  2241. exceAdvice := models.HisDoctorAdviceInfo{
  2242. ExecutionStaff: executionStaff,
  2243. ExecutionTime: theTime.Unix(),
  2244. UpdatedTime: time.Now().Unix(),
  2245. }
  2246. if advice.ParentId > 0 {
  2247. err = service.ExceHidDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  2248. //记录日志
  2249. byterequest, _ := json.Marshal(exceAdvice)
  2250. doctorAdviceLog := models.XtDoctorAdviceLog{
  2251. UserOrgId: exceAdvice.UserOrgId,
  2252. PatientId: exceAdvice.PatientId,
  2253. AdminUserId: adminUserInfo.AdminUser.Id,
  2254. Module: 2,
  2255. ErrLog: string(byterequest),
  2256. Status: 1,
  2257. Ctime: time.Now().Unix(),
  2258. Mtime: 0,
  2259. Source: "电脑端执行His医嘱",
  2260. RecordDate: exceAdvice.RecordDate,
  2261. }
  2262. service.CreateDoctorAdviceLog(doctorAdviceLog)
  2263. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2264. redis := service.RedisClient()
  2265. //清空key 值
  2266. redis.Set(key, "", time.Second)
  2267. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2268. redis.Set(keyTwo, "", time.Second)
  2269. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2270. redis.Set(keyThree, "", time.Second)
  2271. theTimes := theTime.Format("2006-01-02")
  2272. keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2273. redis.Set(keyFour, "", time.Second)
  2274. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2275. redis.Set(keyFive, "", time.Second)
  2276. defer redis.Close()
  2277. } else {
  2278. err = service.ExceHidDoctorAdviceById(&exceAdvice, id, patient)
  2279. //记录日志
  2280. byterequest, _ := json.Marshal(exceAdvice)
  2281. doctorAdviceLog := models.XtDoctorAdviceLog{
  2282. UserOrgId: exceAdvice.UserOrgId,
  2283. PatientId: exceAdvice.PatientId,
  2284. AdminUserId: adminUserInfo.AdminUser.Id,
  2285. Module: 2,
  2286. ErrLog: string(byterequest),
  2287. Status: 1,
  2288. Ctime: time.Now().Unix(),
  2289. Mtime: 0,
  2290. Source: "电脑端执行His医嘱",
  2291. RecordDate: exceAdvice.RecordDate,
  2292. }
  2293. service.CreateDoctorAdviceLog(doctorAdviceLog)
  2294. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2295. redis := service.RedisClient()
  2296. //清空key 值
  2297. redis.Set(key, "", time.Second)
  2298. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2299. redis.Set(keyTwo, "", time.Second)
  2300. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2301. redis.Set(keyThree, "", time.Second)
  2302. theTimes := theTime.Format("2006-01-02")
  2303. fmt.Println("theTIME", theTime)
  2304. keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2305. redis.Set(keyFour, "", time.Second)
  2306. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2307. redis.Set(keyFive, "", time.Second)
  2308. defer redis.Close()
  2309. }
  2310. if err != nil {
  2311. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2312. return
  2313. }
  2314. advice.ExecutionStaff = executionStaff
  2315. advice.ExecutionTime = theTime.Unix()
  2316. //处理出库相关逻辑
  2317. //1.判断是否启用药品管理和自备药出库功能
  2318. //药品管理信息
  2319. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  2320. if drugStockConfig.IsOpen == 1 {
  2321. //查询已经执行的医嘱
  2322. advices, _ := service.GetHisExecutionDoctorsTwo(adminUserInfo.CurrentOrgId, patient, id)
  2323. for _, item := range advices {
  2324. medical, _ := service.GetBaseDrugMedical(advice.DrugId)
  2325. //查询这个患者这个患者这个药已经出库的所有数量
  2326. //advicelist, _ := service.GetAllHisDoctorAdviceById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  2327. //drugoutlist, _ := service.GetAllDrugFlowById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  2328. //var total_count int64 // 现在出库的
  2329. //var drug_count int64 // 已经出库的
  2330. //for _, it := range advicelist {
  2331. // if it.PrescribingNumberUnit == medical.MaxUnit {
  2332. // prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  2333. // prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2334. // total_count += prenumber * medical.MinNumber
  2335. // }
  2336. // if it.PrescribingNumberUnit == medical.MinUnit {
  2337. // prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  2338. // prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2339. // total_count += prenumber
  2340. // }
  2341. //
  2342. //}
  2343. //
  2344. //
  2345. //for _, its := range drugoutlist {
  2346. // if its.CountUnit == medical.MaxUnit {
  2347. // drug_count += its.Count * medical.MinNumber
  2348. // }
  2349. // if its.CountUnit == medical.MinUnit {
  2350. // drug_count += its.Count
  2351. // }
  2352. //}
  2353. //fmt.Println("total_count23232323232323232wode",total_count)
  2354. //fmt.Println("total_count23232323232323232wode",drug_count)
  2355. //if total_count == drug_count {
  2356. // c.ServeSuccessJSON(map[string]interface{}{
  2357. // "msg": "1",
  2358. // "advice": advice,
  2359. // })
  2360. // return
  2361. //}
  2362. var total int64
  2363. var prescribing_number_total int64
  2364. config, _ := service.GetDrugOpenConfigOne(adminUserInfo.CurrentOrgId)
  2365. if config.IsOpen != 1 {
  2366. //查询默认出库仓库
  2367. houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  2368. //查询该药品在默认仓库是否有库存
  2369. list, _ := service.GetDrugTotalCountTwenty(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut)
  2370. //判断单位是否相等
  2371. if medical.MaxUnit == advice.PrescribingNumberUnit {
  2372. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2373. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2374. //转化为最小单位
  2375. total = list.Count*medical.MinNumber + list.StockMinNumber
  2376. prescribing_number_total = count * medical.MinNumber
  2377. }
  2378. if medical.MinUnit == advice.PrescribingNumberUnit {
  2379. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2380. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2381. total = list.Count*medical.MinNumber + list.StockMinNumber
  2382. prescribing_number_total = count
  2383. }
  2384. if medical.IsUse == 1 {
  2385. drugError := models.XtDrugError{
  2386. UserOrgId: item.UserOrgId,
  2387. DrugId: item.DrugId,
  2388. RecordDate: item.AdviceDate,
  2389. PatientId: item.PatientId,
  2390. Remark: "电脑端零用药品",
  2391. Status: 1,
  2392. Ctime: time.Now().Unix(),
  2393. Mtime: 0,
  2394. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2395. Prescribingnumber: item.PrescribingNumber,
  2396. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2397. }
  2398. service.CreateDrugError(drugError)
  2399. c.ServeSuccessJSON(map[string]interface{}{
  2400. "msg": "1",
  2401. "advice": advice,
  2402. })
  2403. return
  2404. }
  2405. if medical.IsUse != 1 {
  2406. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  2407. drugError := models.XtDrugError{
  2408. UserOrgId: item.UserOrgId,
  2409. DrugId: item.DrugId,
  2410. RecordDate: item.AdviceDate,
  2411. PatientId: item.PatientId,
  2412. Remark: "电脑端药品库存不足",
  2413. Status: 1,
  2414. Ctime: time.Now().Unix(),
  2415. Mtime: 0,
  2416. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2417. Prescribingnumber: item.PrescribingNumber,
  2418. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2419. }
  2420. service.CreateDrugError(drugError)
  2421. c.ServeSuccessJSON(map[string]interface{}{
  2422. "msg": "3",
  2423. "advice": advice,
  2424. })
  2425. return
  2426. }
  2427. if prescribing_number_total > total {
  2428. drugError := models.XtDrugError{
  2429. UserOrgId: item.UserOrgId,
  2430. DrugId: item.DrugId,
  2431. RecordDate: item.AdviceDate,
  2432. PatientId: item.PatientId,
  2433. Remark: "电脑端出库数量大于总库存",
  2434. Status: 1,
  2435. Ctime: time.Now().Unix(),
  2436. Mtime: 0,
  2437. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2438. Prescribingnumber: item.PrescribingNumber,
  2439. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2440. }
  2441. service.CreateDrugError(drugError)
  2442. c.ServeSuccessJSON(map[string]interface{}{
  2443. "msg": "2",
  2444. "advice": advice,
  2445. })
  2446. return
  2447. }
  2448. }
  2449. if prescribing_number_total <= total {
  2450. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  2451. if medical.IsUse == 2 {
  2452. if config.IsOpen != 1 {
  2453. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  2454. service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2455. if item.UserOrgId == 3877 || item.UserOrgId == 10265 {
  2456. //查询该药品是否有出库记录
  2457. flowMap, _ := service.GetDrugFLowByAdviceById(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate)
  2458. if len(flowMap) == 0 {
  2459. errs := service.UpdateHisAdviceById(item.ID)
  2460. if errs != nil {
  2461. drugError := models.XtDrugError{
  2462. UserOrgId: item.UserOrgId,
  2463. DrugId: item.DrugId,
  2464. RecordDate: item.AdviceDate,
  2465. PatientId: item.PatientId,
  2466. Remark: "出库记录为空,更新执行人失败",
  2467. Status: 1,
  2468. Ctime: time.Now().Unix(),
  2469. Mtime: 0,
  2470. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2471. Prescribingnumber: item.PrescribingNumber,
  2472. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2473. }
  2474. service.CreateDrugError(drugError)
  2475. }
  2476. c.ServeSuccessJSON(map[string]interface{}{
  2477. "msg": "6",
  2478. "advice": advice,
  2479. })
  2480. return
  2481. }
  2482. }
  2483. }
  2484. //不通过药房发药
  2485. if pharmacyConfig.IsOpen != 1 {
  2486. service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2487. if item.UserOrgId == 3877 || item.UserOrgId == 10265 {
  2488. //查询该药品是否有出库记录
  2489. flowMap, _ := service.GetDrugFLowByAdviceById(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate)
  2490. if len(flowMap) == 0 {
  2491. errs := service.UpdateHisAdviceById(item.ID)
  2492. if errs != nil {
  2493. drugError := models.XtDrugError{
  2494. UserOrgId: item.UserOrgId,
  2495. DrugId: item.DrugId,
  2496. RecordDate: item.AdviceDate,
  2497. PatientId: item.PatientId,
  2498. Remark: "出库记录为空,更新执行人失败",
  2499. Status: 1,
  2500. Ctime: time.Now().Unix(),
  2501. Mtime: 0,
  2502. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2503. Prescribingnumber: item.PrescribingNumber,
  2504. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2505. }
  2506. service.CreateDrugError(drugError)
  2507. }
  2508. c.ServeSuccessJSON(map[string]interface{}{
  2509. "msg": "6",
  2510. "advice": advice,
  2511. })
  2512. return
  2513. }
  2514. }
  2515. }
  2516. //查询默认仓库
  2517. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  2518. //查询默认仓库剩余多少库存
  2519. var sum_count int64
  2520. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2521. for _, its := range stockInfo {
  2522. if its.MaxUnit == medical.MaxUnit {
  2523. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  2524. }
  2525. sum_count += its.StockMaxNumber + its.StockMinNumber
  2526. }
  2527. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2528. //出库数量累加
  2529. //service.AddDrugCount(item.DrugId,item.UserOrgId,storeHouseConfig.DrugStorehouseOut,prescribing_number_total)
  2530. //剩余库存
  2531. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  2532. break
  2533. c.ServeSuccessJSON(map[string]interface{}{
  2534. "msg": "1",
  2535. "advice": advice,
  2536. })
  2537. return
  2538. }
  2539. }
  2540. if medical.IsUse == 1 {
  2541. c.ServeSuccessJSON(map[string]interface{}{
  2542. "msg": "1",
  2543. "advice": advice,
  2544. })
  2545. return
  2546. }
  2547. }
  2548. }
  2549. }
  2550. }
  2551. c.ServeSuccessJSON(map[string]interface{}{
  2552. "msg": "1",
  2553. "advice": advice,
  2554. })
  2555. return
  2556. }
  2557. }
  2558. func (c *PatientApiController) CheckGroupAdvice() {
  2559. groupno, _ := c.GetInt64("groupno", 0)
  2560. if groupno <= 0 {
  2561. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2562. return
  2563. }
  2564. adminUserInfo := c.GetAdminUserInfo()
  2565. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupno)
  2566. if advice.ID == 0 {
  2567. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2568. return
  2569. }
  2570. if advice.CheckState == 1 {
  2571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2572. return
  2573. }
  2574. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2575. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2576. return
  2577. }
  2578. checker := adminUserInfo.AdminUser.Id
  2579. theTime := time.Now()
  2580. exceAdvice := models.DoctorAdvice{
  2581. Checker: checker,
  2582. CheckTime: theTime.Unix(),
  2583. UpdatedTime: time.Now().Unix(),
  2584. }
  2585. var err error
  2586. err = service.CheckDoctorAdviceByGroupNo(&exceAdvice, groupno, adminUserInfo.CurrentOrgId)
  2587. if err != nil {
  2588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2589. return
  2590. }
  2591. advice.Checker = checker
  2592. advice.CheckTime = theTime.Unix()
  2593. c.ServeSuccessJSON(map[string]interface{}{
  2594. "msg": "ok",
  2595. "advice": advice,
  2596. })
  2597. return
  2598. }
  2599. func (c *PatientApiController) CheckDoctorAdvice() {
  2600. patient, _ := c.GetInt64("patient", 0)
  2601. id, _ := c.GetInt64("id", 0)
  2602. origin, _ := c.GetInt64("origin", 0)
  2603. if origin != 2 {
  2604. // executionTime := c.GetString("execution_time")
  2605. if id <= 0 || patient <= 0 {
  2606. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2607. return
  2608. }
  2609. adminUserInfo := c.GetAdminUserInfo()
  2610. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2611. if advice.ID == 0 || advice.PatientId != patient {
  2612. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2613. return
  2614. }
  2615. if advice.CheckState == 1 {
  2616. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2617. return
  2618. }
  2619. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2621. return
  2622. }
  2623. // executionStaff := adminUserInfo.AdminUser.Id
  2624. checker := adminUserInfo.AdminUser.Id
  2625. // timeLayout := "2006-01-02 15:04:05"
  2626. // loc, _ := time.LoadLocation("Local")
  2627. // theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  2628. // if err != nil {
  2629. // utils.ErrorLog(err.Error())
  2630. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2631. // return
  2632. // }
  2633. theTime := time.Now()
  2634. if advice.ExecutionTime > theTime.Unix() {
  2635. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  2636. return
  2637. }
  2638. exceAdvice := models.DoctorAdvice{
  2639. Checker: checker,
  2640. CheckTime: theTime.Unix(),
  2641. UpdatedTime: time.Now().Unix(),
  2642. }
  2643. var err error
  2644. // 查询信息规挡的设置天数
  2645. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  2646. if infor.ID > 0 && infor.WeekDay > 0 {
  2647. var cha_time int64
  2648. timeNowStr := time.Now().Format("2006-01-02")
  2649. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2650. //今日的日期减去设置的日期
  2651. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2652. if cha_time >= advice.AdviceDate {
  2653. //查询审核是否允许
  2654. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  2655. //申请状态不允许的情况 拒绝修改
  2656. if infor.ApplicationStatus != 1 {
  2657. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2658. return
  2659. }
  2660. }
  2661. }
  2662. if advice.ParentId > 0 {
  2663. err = service.CheckDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  2664. //记录日志
  2665. byterequest, _ := json.Marshal(exceAdvice)
  2666. adviceLog := models.XtDoctorAdviceLog{
  2667. UserOrgId: exceAdvice.UserOrgId,
  2668. PatientId: exceAdvice.PatientId,
  2669. AdminUserId: adminUserInfo.AdminUser.Id,
  2670. Module: 3,
  2671. ErrLog: string(byterequest),
  2672. Status: 1,
  2673. Ctime: time.Now().Unix(),
  2674. Mtime: 0,
  2675. Source: "核对医嘱",
  2676. RecordDate: exceAdvice.AdviceDate,
  2677. }
  2678. service.CreateDoctorAdviceLog(adviceLog)
  2679. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2680. redis := service.RedisClient()
  2681. //清空key 值
  2682. redis.Set(key, "", time.Second)
  2683. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2684. redis.Set(keyTwo, "", time.Second)
  2685. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2686. redis.Set(keyThree, "", time.Second)
  2687. recordDate := theTime.Format("2006-01-02")
  2688. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2689. redis.Set(keyFour, "", time.Second)
  2690. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2691. redis.Set(keyFive, "", time.Second)
  2692. } else {
  2693. err = service.CheckDoctorAdviceById(&exceAdvice, id, patient)
  2694. //记录日志
  2695. byterequest, _ := json.Marshal(exceAdvice)
  2696. adviceLog := models.XtDoctorAdviceLog{
  2697. UserOrgId: exceAdvice.UserOrgId,
  2698. PatientId: exceAdvice.PatientId,
  2699. AdminUserId: adminUserInfo.AdminUser.Id,
  2700. Module: 3,
  2701. ErrLog: string(byterequest),
  2702. Status: 1,
  2703. Ctime: time.Now().Unix(),
  2704. Mtime: 0,
  2705. Source: "核对医嘱",
  2706. RecordDate: exceAdvice.AdviceDate,
  2707. }
  2708. service.CreateDoctorAdviceLog(adviceLog)
  2709. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2710. redis := service.RedisClient()
  2711. //清空key 值
  2712. redis.Set(key, "", time.Second)
  2713. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2714. redis.Set(keyTwo, "", time.Second)
  2715. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2716. redis.Set(keyThree, "", time.Second)
  2717. recordDate := theTime.Format("2006-01-02")
  2718. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2719. redis.Set(keyFour, "", time.Second)
  2720. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2721. redis.Set(keyFive, "", time.Second)
  2722. }
  2723. if err != nil {
  2724. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2725. return
  2726. }
  2727. // advice.ExecutionStaff = executionStaff
  2728. // advice.ExecutionTime = theTime.Unix()
  2729. advice.Checker = checker
  2730. advice.CheckTime = theTime.Unix()
  2731. c.ServeSuccessJSON(map[string]interface{}{
  2732. "msg": "ok",
  2733. "advice": advice,
  2734. })
  2735. return
  2736. } else {
  2737. if id <= 0 || patient <= 0 {
  2738. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2739. return
  2740. }
  2741. adminUserInfo := c.GetAdminUserInfo()
  2742. advice, _ := service.FindHisDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2743. if advice.ID == 0 || advice.PatientId != patient {
  2744. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2745. return
  2746. }
  2747. if advice.CheckState == 1 {
  2748. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2749. return
  2750. }
  2751. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2752. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2753. return
  2754. }
  2755. checker := adminUserInfo.AdminUser.Id
  2756. theTime := time.Now()
  2757. if advice.ExecutionTime > theTime.Unix() {
  2758. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  2759. return
  2760. }
  2761. exceAdvice := models.HisDoctorAdviceInfo{
  2762. Checker: checker,
  2763. CheckTime: theTime.Unix(),
  2764. UpdatedTime: time.Now().Unix(),
  2765. }
  2766. var err error
  2767. if advice.ParentId > 0 {
  2768. err = service.CheckHisDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  2769. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2770. redis := service.RedisClient()
  2771. //清空key 值
  2772. redis.Set(key, "", time.Second)
  2773. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2774. redis.Set(keyTwo, "", time.Second)
  2775. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2776. redis.Set(keyThree, "", time.Second)
  2777. recordDate := theTime.Format("2006-01-02")
  2778. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2779. redis.Set(keyFour, "", time.Second)
  2780. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2781. redis.Set(keyFive, "", time.Second)
  2782. } else {
  2783. err = service.CheckHisDoctorAdviceById(&exceAdvice, id, patient)
  2784. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2785. redis := service.RedisClient()
  2786. //清空key 值
  2787. redis.Set(key, "", time.Second)
  2788. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2789. redis.Set(keyTwo, "", time.Second)
  2790. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2791. redis.Set(keyThree, "", time.Second)
  2792. recordDate := theTime.Format("2006-01-02")
  2793. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2794. redis.Set(keyFour, "", time.Second)
  2795. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2796. redis.Set(keyFive, "", time.Second)
  2797. }
  2798. if err != nil {
  2799. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2800. return
  2801. }
  2802. // advice.ExecutionStaff = executionStaff
  2803. // advice.ExecutionTime = theTime.Unix()
  2804. advice.Checker = checker
  2805. advice.CheckTime = theTime.Unix()
  2806. c.ServeSuccessJSON(map[string]interface{}{
  2807. "msg": "ok",
  2808. "advice": advice,
  2809. })
  2810. return
  2811. }
  2812. }
  2813. func (c *PatientApiController) UpdateDoctorAdvice() {
  2814. patient, _ := c.GetInt64("patient", 0)
  2815. id, _ := c.GetInt64("id", 0)
  2816. if id <= 0 || patient <= 0 {
  2817. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2818. return
  2819. }
  2820. adminUserInfo := c.GetAdminUserInfo()
  2821. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2822. if advice.ID == 0 || advice.PatientId != patient {
  2823. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2824. return
  2825. }
  2826. //if advice.AdviceType == 1 {
  2827. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeLongTimeAdviceNotCanntEdit)
  2828. // return
  2829. //}
  2830. if advice.StopState == 1 || advice.ExecutionState == 1 {
  2831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  2832. return
  2833. }
  2834. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2835. //if appRole.UserType == 3 {
  2836. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2837. // if getPermissionErr != nil {
  2838. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2839. // return
  2840. // } else if headNursePermission == nil {
  2841. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2842. // return
  2843. // }
  2844. //}
  2845. //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  2846. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCanotEditOtherAdvice)
  2847. // return
  2848. //}
  2849. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
  2850. if code > 0 {
  2851. c.ServeFailJSONWithSGJErrorCode(code)
  2852. return
  2853. }
  2854. advice.UpdatedTime = time.Now().Unix()
  2855. advice.Modifier = adminUserInfo.AdminUser.Id
  2856. // 查询信息规挡的设置天数
  2857. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  2858. if infor.ID > 0 && infor.WeekDay > 0 {
  2859. var cha_time int64
  2860. timeNowStr := time.Now().Format("2006-01-02")
  2861. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2862. //今日的日期减去设置的日期
  2863. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2864. if cha_time >= advice.AdviceDate {
  2865. //查询审核是否允许
  2866. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  2867. //申请状态不允许的情况 拒绝修改
  2868. if infor.ApplicationStatus != 1 {
  2869. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2870. return
  2871. }
  2872. }
  2873. }
  2874. err := service.UpdateDoctorAdvice(&advice)
  2875. //记录日志
  2876. byterequest, _ := json.Marshal(advice)
  2877. doctorAdviceLog := models.XtDoctorAdviceLog{
  2878. UserOrgId: advice.UserOrgId,
  2879. PatientId: advice.PatientId,
  2880. AdminUserId: adminUserInfo.AdminUser.Id,
  2881. Module: 1,
  2882. ErrLog: string(byterequest),
  2883. Status: 1,
  2884. Ctime: time.Now().Unix(),
  2885. Mtime: 0,
  2886. Source: "电脑端修改医嘱",
  2887. RecordDate: advice.AdviceDate,
  2888. }
  2889. service.CreateDoctorAdviceLog(doctorAdviceLog)
  2890. redis := service.RedisClient()
  2891. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2892. redis.Set(key, "", time.Second)
  2893. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2894. redis.Set(keyOne, "", time.Second)
  2895. defer redis.Close()
  2896. if err != nil {
  2897. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2898. return
  2899. }
  2900. c.ServeSuccessJSON(map[string]interface{}{
  2901. "msg": "ok",
  2902. "advice": advice,
  2903. })
  2904. return
  2905. }
  2906. func (c *PatientApiController) StopGroupAdvice() {
  2907. groupNo, _ := c.GetInt64("groupno", 0)
  2908. if groupNo <= 0 {
  2909. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2910. return
  2911. }
  2912. adminUserInfo := c.GetAdminUserInfo()
  2913. advice, _ := service.FindDoctorAdviceByGoroupNo(adminUserInfo.CurrentOrgId, groupNo)
  2914. if advice.ID == 0 {
  2915. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2916. return
  2917. }
  2918. if advice.StopState == 1 || advice.ExecutionState == 1 {
  2919. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  2920. return
  2921. }
  2922. dataBody := make(map[string]interface{}, 0)
  2923. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2924. if err != nil {
  2925. utils.ErrorLog(err.Error())
  2926. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2927. return
  2928. }
  2929. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  2930. utils.ErrorLog("stop_time")
  2931. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2932. return
  2933. }
  2934. stopTime, _ := dataBody["stop_time"].(string)
  2935. if len(stopTime) == 0 {
  2936. utils.ErrorLog("len(stop_time) == 0")
  2937. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2938. return
  2939. }
  2940. timeLayout := "2006-01-02"
  2941. loc, _ := time.LoadLocation("Local")
  2942. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  2943. if err != nil {
  2944. utils.ErrorLog(err.Error())
  2945. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2946. return
  2947. }
  2948. advice.StopTime = theTime.Unix()
  2949. if dataBody["stop_reason"] != nil && reflect.TypeOf(dataBody["stop_reason"]).String() == "string" {
  2950. stopReason, _ := dataBody["stop_reason"].(string)
  2951. advice.StopReason = stopReason
  2952. }
  2953. advice.UpdatedTime = time.Now().Unix()
  2954. advice.StopDoctor = adminUserInfo.AdminUser.Id
  2955. advice.StopState = 1
  2956. err = service.StopGroupAdvice(adminUserInfo.CurrentOrgId, groupNo, &advice)
  2957. if err != nil {
  2958. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  2959. return
  2960. }
  2961. c.ServeSuccessJSON(map[string]interface{}{
  2962. "msg": "ok",
  2963. })
  2964. return
  2965. }
  2966. func (c *PatientApiController) StopDoctorAdvice() {
  2967. id, _ := c.GetInt64("id", 0)
  2968. if id <= 0 {
  2969. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2970. return
  2971. }
  2972. adminUserInfo := c.GetAdminUserInfo()
  2973. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2974. //
  2975. //if appRole.UserType == 3 {
  2976. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2977. // if getPermissionErr != nil {
  2978. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2979. // return
  2980. // } else if headNursePermission == nil {
  2981. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2982. // return
  2983. // }
  2984. //}
  2985. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2986. if advice.ID == 0 {
  2987. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2988. return
  2989. }
  2990. if advice.StopState == 1 || advice.ExecutionState == 1 {
  2991. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  2992. return
  2993. }
  2994. dataBody := make(map[string]interface{}, 0)
  2995. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2996. if err != nil {
  2997. utils.ErrorLog(err.Error())
  2998. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2999. return
  3000. }
  3001. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  3002. utils.ErrorLog("stop_time")
  3003. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3004. return
  3005. }
  3006. stopTime, _ := dataBody["stop_time"].(string)
  3007. if len(stopTime) == 0 {
  3008. utils.ErrorLog("len(stop_time) == 0")
  3009. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3010. return
  3011. }
  3012. timeLayout := "2006-01-02"
  3013. loc, _ := time.LoadLocation("Local")
  3014. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  3015. if err != nil {
  3016. utils.ErrorLog(err.Error())
  3017. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3018. return
  3019. }
  3020. advice.StopTime = theTime.Unix()
  3021. if dataBody["stop_reason"] != nil && reflect.TypeOf(dataBody["stop_reason"]).String() == "string" {
  3022. stopReason, _ := dataBody["stop_reason"].(string)
  3023. advice.StopReason = stopReason
  3024. }
  3025. advice.UpdatedTime = time.Now().Unix()
  3026. advice.StopDoctor = adminUserInfo.AdminUser.Id
  3027. advice.StopState = 1
  3028. err = service.StopDoctorAdvice(&advice)
  3029. if err != nil {
  3030. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  3031. return
  3032. }
  3033. c.ServeSuccessJSON(map[string]interface{}{
  3034. "msg": "ok",
  3035. "advice": advice,
  3036. })
  3037. return
  3038. }
  3039. func (c *PatientApiController) DeleteDoctorAdvice() {
  3040. id, _ := c.GetInt64("id", 0)
  3041. if id <= 0 {
  3042. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3043. return
  3044. }
  3045. adminUserInfo := c.GetAdminUserInfo()
  3046. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  3047. if advice.ID == 0 {
  3048. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3049. return
  3050. }
  3051. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  3052. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3053. // return
  3054. //}
  3055. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  3056. //
  3057. //if appRole.UserType == 3 {
  3058. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3059. // if getPermissionErr != nil {
  3060. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3061. // return
  3062. // } else if headNursePermission == nil {
  3063. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3064. // return
  3065. // }
  3066. //}
  3067. advice.UpdatedTime = time.Now().Unix()
  3068. advice.Status = 0
  3069. advice.Modifier = adminUserInfo.AdminUser.Id
  3070. // 查询信息规挡的设置天数
  3071. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3072. if infor.ID > 0 && infor.WeekDay > 0 {
  3073. var cha_time int64
  3074. timeNowStr := time.Now().Format("2006-01-02")
  3075. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3076. //今日的日期减去设置的日期
  3077. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3078. if cha_time >= advice.AdviceDate {
  3079. //查询审核是否允许
  3080. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  3081. //申请状态不允许的情况 拒绝修改
  3082. if infor.ApplicationStatus != 1 {
  3083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3084. return
  3085. }
  3086. }
  3087. }
  3088. err := service.DeleteDoctorAdvice(&advice)
  3089. //记录日志
  3090. byterequest, _ := json.Marshal(advice)
  3091. doctorAdviceLog := models.XtDoctorAdviceLog{
  3092. UserOrgId: advice.UserOrgId,
  3093. PatientId: advice.PatientId,
  3094. AdminUserId: adminUserInfo.AdminUser.Id,
  3095. Module: 4,
  3096. ErrLog: string(byterequest),
  3097. Status: 1,
  3098. Ctime: time.Now().Unix(),
  3099. Mtime: 0,
  3100. Source: "电脑端删除医嘱",
  3101. RecordDate: advice.RecordDate,
  3102. }
  3103. service.CreateDoctorAdviceLog(doctorAdviceLog)
  3104. redis := service.RedisClient()
  3105. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3106. redis.Set(keyOne, "", time.Second)
  3107. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3108. redis.Set(key, "", time.Second)
  3109. redis.Close()
  3110. if err != nil {
  3111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  3112. return
  3113. }
  3114. c.ServeSuccessJSON(map[string]interface{}{
  3115. "msg": "ok",
  3116. })
  3117. return
  3118. }
  3119. func (c *PatientApiController) DeleteGroupAdvice() {
  3120. groupNo, _ := c.GetInt64("groupno", 0)
  3121. if groupNo <= 0 {
  3122. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3123. return
  3124. }
  3125. adminUserInfo := c.GetAdminUserInfo()
  3126. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupNo)
  3127. if advice.ID == 0 {
  3128. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3129. return
  3130. }
  3131. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  3132. //if appRole.UserType == 3 {
  3133. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3134. // if getPermissionErr != nil {
  3135. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3136. // return
  3137. // } else if headNursePermission == nil {
  3138. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3139. // return
  3140. // }
  3141. //}
  3142. // 查询信息规挡的设置天数
  3143. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3144. if infor.ID > 0 && infor.WeekDay > 0 {
  3145. var cha_time int64
  3146. timeNowStr := time.Now().Format("2006-01-02")
  3147. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3148. //今日的日期减去设置的日期
  3149. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3150. if cha_time >= advice.AdviceDate {
  3151. //查询审核是否允许
  3152. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  3153. //申请状态不允许的情况 拒绝修改
  3154. if infor.ApplicationStatus != 1 {
  3155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3156. return
  3157. }
  3158. }
  3159. }
  3160. err := service.DeleteGroupAdvice(adminUserInfo.CurrentOrgId, groupNo, adminUserInfo.AdminUser.Id)
  3161. byterequest, _ := json.Marshal(advice)
  3162. doctorAdviceLog := models.XtDoctorAdviceLog{
  3163. UserOrgId: advice.UserOrgId,
  3164. PatientId: advice.PatientId,
  3165. AdminUserId: adminUserInfo.AdminUser.Id,
  3166. Module: 4,
  3167. ErrLog: string(byterequest),
  3168. Status: 1,
  3169. Ctime: time.Now().Unix(),
  3170. Mtime: 0,
  3171. Source: "电脑端批量删除医嘱",
  3172. RecordDate: advice.RecordDate,
  3173. }
  3174. service.CreateDoctorAdviceLog(doctorAdviceLog)
  3175. key := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3176. redis := service.RedisClient()
  3177. redis.Set(key, "", time.Second)
  3178. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3179. redis.Set(keyOne, "", time.Second)
  3180. defer redis.Close()
  3181. if err != nil {
  3182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  3183. return
  3184. }
  3185. c.ServeSuccessJSON(map[string]interface{}{
  3186. "msg": "ok",
  3187. })
  3188. return
  3189. }
  3190. // GetDoctorAdvices 医嘱列表
  3191. func (c *PatientApiController) GetDoctorAdvices() {
  3192. id, _ := c.GetInt64("id", 0)
  3193. adviceType, _ := c.GetInt64("advice_type", 0)
  3194. stopType, _ := c.GetInt64("stop_state", 0)
  3195. startTime := c.GetString("start_time", "")
  3196. endTime := c.GetString("end_time", "")
  3197. keywords := c.GetString("keywords", "")
  3198. page, _ := c.GetInt64("page")
  3199. fmt.Println("page", page)
  3200. limit, _ := c.GetInt64("limit")
  3201. fmt.Println("limit", limit)
  3202. adminUserInfo := c.GetAdminUserInfo()
  3203. operatorIDs := make([]int64, 0)
  3204. timeLayout := "2006-01-02"
  3205. loc, _ := time.LoadLocation("Local")
  3206. var theStartTIme int64
  3207. if len(startTime) > 0 {
  3208. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3209. if err != nil {
  3210. utils.ErrorLog(err.Error())
  3211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3212. return
  3213. }
  3214. theStartTIme = theTime.Unix()
  3215. }
  3216. var theEndtTIme int64
  3217. if len(endTime) > 0 {
  3218. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3219. if err != nil {
  3220. utils.ErrorLog(err.Error())
  3221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3222. return
  3223. }
  3224. theEndtTIme = theTime.Unix()
  3225. }
  3226. hisconfig, _ := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  3227. if hisconfig.IsOpen == 1 {
  3228. advices, total, _ := service.GetDoctorAdviceListThree(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
  3229. advicestwo, _, _ := service.GetDoctorAdviceListFour(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page)
  3230. if len(advices) > 0 {
  3231. for _, item := range advices {
  3232. if item.AdviceDoctor > 0 {
  3233. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  3234. }
  3235. if item.ExecutionStaff > 0 {
  3236. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  3237. }
  3238. if item.Checker > 0 {
  3239. operatorIDs = append(operatorIDs, item.Checker)
  3240. }
  3241. if item.StopDoctor > 0 {
  3242. operatorIDs = append(operatorIDs, item.StopDoctor)
  3243. }
  3244. }
  3245. }
  3246. //相关操作对应的操作人
  3247. operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  3248. //获取长期医嘱
  3249. longAdvice, _, _ := service.GetLongDoctorAdviceList(adminUserInfo.CurrentOrgId, id, 1, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
  3250. c.ServeSuccessJSON(map[string]interface{}{
  3251. "advices": advices,
  3252. "operators": operators,
  3253. "total": total,
  3254. "advicetwo": advicestwo,
  3255. "longAdvice": longAdvice,
  3256. "is_open": hisconfig.IsOpen,
  3257. })
  3258. return
  3259. } else {
  3260. advices, total, _ := service.GetDoctorAdviceListOne(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
  3261. advicestwo, _, _ := service.GetDoctorAdviceListTwo(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page)
  3262. if len(advices) > 0 {
  3263. for _, item := range advices {
  3264. if item.AdviceDoctor > 0 {
  3265. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  3266. }
  3267. if item.ExecutionStaff > 0 {
  3268. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  3269. }
  3270. if item.Checker > 0 {
  3271. operatorIDs = append(operatorIDs, item.Checker)
  3272. }
  3273. if item.StopDoctor > 0 {
  3274. operatorIDs = append(operatorIDs, item.StopDoctor)
  3275. }
  3276. }
  3277. }
  3278. //相关操作对应的操作人
  3279. operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  3280. c.ServeSuccessJSON(map[string]interface{}{
  3281. "advices": advices,
  3282. "operators": operators,
  3283. "total": total,
  3284. "advicetwo": advicestwo,
  3285. "is_open": hisconfig.IsOpen,
  3286. })
  3287. return
  3288. }
  3289. }
  3290. func (c *PatientApiController) GetPatientSchedules() {
  3291. id, _ := c.GetInt64("id", 0)
  3292. if id <= 0 {
  3293. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3294. return
  3295. }
  3296. adminUserInfo := c.GetAdminUserInfo()
  3297. todayTime := time.Now().Format("2006-01-02")
  3298. timeLayout := "2006-01-02 15:04:05"
  3299. loc, _ := time.LoadLocation("Local")
  3300. var theStartTime int64
  3301. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  3302. theStartTime = theTime.Unix()
  3303. schedules, _ := service.GetPatientScheduleFormToday(adminUserInfo.CurrentOrgId, id, theStartTime)
  3304. if len(schedules) > 0 {
  3305. for index, item := range schedules {
  3306. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  3307. schedules[index].Week = int64(week)
  3308. }
  3309. }
  3310. c.ServeSuccessJSON(map[string]interface{}{
  3311. "schedules": schedules,
  3312. })
  3313. return
  3314. }
  3315. func (c *PatientApiController) GetPatientDialysisRecords() {
  3316. patientID, _ := c.GetInt64("patient_id", 0)
  3317. page, _ := c.GetInt64("page", 0)
  3318. limit, _ := c.GetInt64("limit", 0)
  3319. startTime := c.GetString("start_time", "")
  3320. endTime := c.GetString("end_time", "")
  3321. mode_id, _ := c.GetInt64("mode_id", 0)
  3322. if page <= 0 {
  3323. page = 1
  3324. }
  3325. if limit <= 0 {
  3326. limit = 10
  3327. }
  3328. if patientID <= 0 {
  3329. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3330. return
  3331. }
  3332. timeLayout := "2006-01-02"
  3333. loc, _ := time.LoadLocation("Local")
  3334. var theStartTIme int64
  3335. if len(startTime) > 0 {
  3336. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3337. if err != nil {
  3338. theStartTIme = 0
  3339. }
  3340. theStartTIme = theTime.Unix()
  3341. }
  3342. var theEndtTIme int64
  3343. if len(endTime) > 0 {
  3344. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3345. if err != nil {
  3346. theEndtTIme = 0
  3347. }
  3348. theEndtTIme = theTime.Unix()
  3349. }
  3350. adminInfo := c.GetAdminUserInfo()
  3351. records, total, _ := service.GetPatientDialysisRecord(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  3352. c.ServeSuccessJSON(map[string]interface{}{
  3353. "total": total,
  3354. "records": records,
  3355. })
  3356. return
  3357. }
  3358. func (c *PatientApiController) ProEducation() {
  3359. patientID, _ := c.GetInt64("patient_id", 0)
  3360. page, _ := c.GetInt64("page", 0)
  3361. limit, _ := c.GetInt64("limit", 0)
  3362. startTime := c.GetString("start_time", "")
  3363. endTime := c.GetString("end_time", "")
  3364. if page <= 0 {
  3365. page = 1
  3366. }
  3367. if limit <= 0 {
  3368. limit = 10
  3369. }
  3370. if patientID <= 0 {
  3371. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3372. return
  3373. }
  3374. timeLayout := "2006-01-02"
  3375. loc, _ := time.LoadLocation("Local")
  3376. var theStartTIme int64
  3377. if len(startTime) > 0 {
  3378. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3379. if err != nil {
  3380. theStartTIme = 0
  3381. }
  3382. theStartTIme = theTime.Unix()
  3383. }
  3384. var theEndtTIme int64
  3385. if len(endTime) > 0 {
  3386. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3387. if err != nil {
  3388. theEndtTIme = 0
  3389. }
  3390. theEndtTIme = theTime.Unix()
  3391. }
  3392. adminInfo := c.GetAdminUserInfo()
  3393. edus, total, _ := service.GetPatientTreatmentSummaryList(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme)
  3394. c.ServeSuccessJSON(map[string]interface{}{
  3395. "total": total,
  3396. "edus": edus,
  3397. })
  3398. return
  3399. }
  3400. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  3401. dataBody := make(map[string]interface{}, 0)
  3402. err := json.Unmarshal(data, &dataBody)
  3403. if err != nil {
  3404. utils.ErrorLog(err.Error())
  3405. code = enums.ErrorCodeParamWrong
  3406. return
  3407. }
  3408. timeLayout := "2006-01-02"
  3409. loc, _ := time.LoadLocation("Local")
  3410. isChild := false
  3411. if action == "create" {
  3412. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  3413. utils.ErrorLog("advice_type")
  3414. code = enums.ErrorCodeParamWrong
  3415. return
  3416. }
  3417. adviceType := int64(dataBody["advice_type"].(float64))
  3418. if adviceType != 1 && adviceType != 2 && adviceType != 3 && adviceType != 4 {
  3419. utils.ErrorLog("advice_type != 1&&2")
  3420. code = enums.ErrorCodeParamWrong
  3421. return
  3422. }
  3423. advice.AdviceType = adviceType
  3424. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  3425. utils.ErrorLog("advice_date")
  3426. code = enums.ErrorCodeParamWrong
  3427. return
  3428. }
  3429. adviceDate, _ := dataBody["advice_date"].(string)
  3430. if len(adviceDate) == 0 {
  3431. utils.ErrorLog("len(adviceDate) == 0")
  3432. code = enums.ErrorCodeParamWrong
  3433. return
  3434. }
  3435. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  3436. if err != nil {
  3437. utils.ErrorLog(err.Error())
  3438. code = enums.ErrorCodeParamWrong
  3439. return
  3440. }
  3441. advice.AdviceDate = theTime.Unix()
  3442. advice.RecordDate = theTime.Unix()
  3443. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  3444. parentId := int64(dataBody["parent_id"].(float64))
  3445. advice.ParentId = parentId
  3446. if parentId > 0 {
  3447. isChild = true
  3448. }
  3449. }
  3450. }
  3451. if !isChild {
  3452. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3453. utils.ErrorLog("start_time")
  3454. code = enums.ErrorCodeParamWrong
  3455. return
  3456. }
  3457. startTime, _ := dataBody["start_time"].(string)
  3458. if len(startTime) == 0 {
  3459. utils.ErrorLog("len(start_time) == 0")
  3460. code = enums.ErrorCodeParamWrong
  3461. return
  3462. }
  3463. theTime, err := time.ParseInLocation(timeLayout+" 15:04", startTime, loc)
  3464. if err != nil {
  3465. utils.ErrorLog(err.Error())
  3466. code = enums.ErrorCodeParamWrong
  3467. return
  3468. }
  3469. advice.StartTime = theTime.Unix()
  3470. // if dataBody["advice_doctor"] == nil || reflect.TypeOf(dataBody["advice_doctor"]).String() != "float64" {
  3471. // utils.ErrorLog("advice_doctor")
  3472. // code = enums.ErrorCodeParamWrong
  3473. // return
  3474. // }
  3475. // adviceDoctor := int64(dataBody["advice_doctor"].(float64))
  3476. // if adviceDoctor <= 0 {
  3477. // utils.ErrorLog("advice_doctor <=0")
  3478. // code = enums.ErrorCodeParamWrong
  3479. // return
  3480. // }
  3481. // advice.AdviceDoctor = adviceDoctor
  3482. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  3483. deliveryWay, _ := dataBody["delivery_way"].(string)
  3484. advice.DeliveryWay = deliveryWay
  3485. }
  3486. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  3487. executionFrequency, _ := dataBody["execution_frequency"].(string)
  3488. advice.ExecutionFrequency = executionFrequency
  3489. }
  3490. if advice.AdviceType == 1 && advice.ParentId == 0 {
  3491. if dataBody["frequency_type"] != nil || reflect.TypeOf(dataBody["frequency_type"]).String() == "float64" {
  3492. frequency_type := int64(dataBody["frequency_type"].(float64))
  3493. advice.FrequencyType = frequency_type
  3494. }
  3495. if dataBody["day_count"] != nil || reflect.TypeOf(dataBody["day_count"]).String() == "string" {
  3496. day_count, _ := strconv.ParseInt(dataBody["day_count"].(string), 10, 64)
  3497. advice.DayCount = day_count
  3498. }
  3499. if dataBody["week_days"] != nil && reflect.TypeOf(dataBody["week_days"]).String() == "string" {
  3500. week_day, _ := dataBody["week_days"].(string)
  3501. advice.WeekDay = week_day
  3502. }
  3503. }
  3504. }
  3505. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  3506. utils.ErrorLog("advice_name")
  3507. code = enums.ErrorCodeParamWrong
  3508. return
  3509. }
  3510. adviceName, _ := dataBody["advice_name"].(string)
  3511. if len(adviceName) == 0 {
  3512. utils.ErrorLog("len(advice_name) == 0")
  3513. code = enums.ErrorCodeParamWrong
  3514. return
  3515. }
  3516. advice.AdviceName = adviceName
  3517. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  3518. adviceDsc, _ := dataBody["advice_desc"].(string)
  3519. advice.AdviceDesc = adviceDsc
  3520. }
  3521. if dataBody["dialysis_order_id"] != nil && reflect.TypeOf(dataBody["dialysis_order_id"]).String() == "float64" {
  3522. dialysisOrderId, _ := dataBody["dialysis_order_id"].(float64)
  3523. advice.DialysisOrderId = int64(dialysisOrderId)
  3524. }
  3525. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  3526. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  3527. advice.SingleDose = singleDose
  3528. }
  3529. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "float64" {
  3530. singleDose := dataBody["single_dose"].(float64)
  3531. advice.SingleDose = singleDose
  3532. }
  3533. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  3534. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  3535. advice.SingleDoseUnit = singleDoseUnit
  3536. }
  3537. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "float64" {
  3538. tmp := dataBody["single_dose_unit"].(float64)
  3539. singleDoseUnit := service.TypeConversion(tmp)
  3540. advice.SingleDoseUnit = singleDoseUnit
  3541. }
  3542. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  3543. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  3544. advice.DrugSpec = drugSpec
  3545. }
  3546. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  3547. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  3548. advice.DrugSpecUnit = drugSpecUnit
  3549. }
  3550. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  3551. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  3552. advice.PrescribingNumber = prescribingNumber
  3553. }
  3554. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "float64" {
  3555. prescribingNumber := dataBody["prescribing_number"].(float64)
  3556. advice.PrescribingNumber = prescribingNumber
  3557. }
  3558. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  3559. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  3560. advice.PrescribingNumberUnit = prescribingNumberUnit
  3561. }
  3562. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3563. remark, _ := dataBody["remark"].(string)
  3564. advice.Remark = remark
  3565. }
  3566. if dataBody["drug_id"] != nil && reflect.TypeOf(dataBody["drug_id"]).String() == "string" {
  3567. drug_id, _ := dataBody["drug_id"].(string)
  3568. tmpDrugId, _ := strconv.ParseInt(drug_id, 10, 64)
  3569. advice.DrugId = tmpDrugId
  3570. }
  3571. if dataBody["drug_id"] != nil && reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
  3572. drug_id, _ := dataBody["drug_id"].(float64)
  3573. advice.DrugId = int64(drug_id)
  3574. }
  3575. if dataBody["drug_name_id"] != nil && reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
  3576. drug_name_id, _ := dataBody["drug_name_id"].(float64)
  3577. advice.DrugNameId = int64(drug_name_id)
  3578. }
  3579. if dataBody["way"] != nil && reflect.TypeOf(dataBody["way"]).String() == "float64" {
  3580. way, _ := dataBody["way"].(float64)
  3581. advice.Way = int64(way)
  3582. }
  3583. if dataBody["push_start_time"] != nil && reflect.TypeOf(dataBody["push_start_time"]).String() == "string" {
  3584. push_start_time, _ := dataBody["push_start_time"].(string)
  3585. var startTime int64
  3586. if len(push_start_time) > 0 {
  3587. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", push_start_time+" 00:00:00", loc)
  3588. startTime = theTime.Unix()
  3589. }
  3590. advice.PushStartTime = startTime
  3591. }
  3592. return
  3593. }
  3594. func solutionFormData(solution *models.DialysisSolution, data []byte) (code int) {
  3595. dataBody := make(map[string]interface{}, 0)
  3596. err := json.Unmarshal(data, &dataBody)
  3597. utils.InfoLog(string(data))
  3598. if err != nil {
  3599. utils.ErrorLog(err.Error())
  3600. code = enums.ErrorCodeParamWrong
  3601. return
  3602. }
  3603. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  3604. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  3605. solution.DialysisDuration = dialysisDuration
  3606. }
  3607. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  3608. replacementWay := int64(dataBody["replacement_way"].(float64))
  3609. solution.ReplacementWay = replacementWay
  3610. }
  3611. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  3612. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  3613. solution.BloodFlowVolume = bloodFlowVolume
  3614. }
  3615. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  3616. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  3617. solution.HemodialysisMachine = hemodialysisMachine
  3618. }
  3619. if dataBody["blood_filter"] != nil && reflect.TypeOf(dataBody["blood_filter"]).String() == "float64" {
  3620. bloodFilter := int64(dataBody["blood_filter"].(float64))
  3621. solution.BloodFilter = bloodFilter
  3622. }
  3623. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  3624. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  3625. solution.PerfusionApparatus = perfusionApparatus
  3626. }
  3627. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  3628. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  3629. solution.DialysateFlow = dialysateFlow
  3630. }
  3631. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  3632. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  3633. solution.Kalium = kalium
  3634. }
  3635. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  3636. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  3637. solution.Sodium = sodium
  3638. }
  3639. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  3640. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  3641. solution.Calcium = calcium
  3642. }
  3643. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  3644. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  3645. solution.Bicarbonate = bicarbonate
  3646. }
  3647. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  3648. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  3649. solution.Anticoagulant = anticoagulant
  3650. }
  3651. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  3652. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  3653. solution.AnticoagulantShouji = anticoagulantShouji
  3654. }
  3655. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  3656. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  3657. solution.AnticoagulantWeichi = anticoagulantWeichi
  3658. }
  3659. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  3660. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  3661. solution.AnticoagulantZongliang = anticoagulantZongliang
  3662. }
  3663. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  3664. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  3665. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  3666. }
  3667. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  3668. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  3669. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  3670. }
  3671. return
  3672. }
  3673. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  3674. dataBody := make(map[string]interface{}, 0)
  3675. err := json.Unmarshal(data, &dataBody)
  3676. utils.InfoLog(string(data))
  3677. if err != nil {
  3678. utils.ErrorLog(err.Error())
  3679. code = enums.ErrorCodeParamWrong
  3680. return
  3681. }
  3682. if method == "create" {
  3683. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  3684. utils.ErrorLog("mode")
  3685. code = enums.ErrorCodeParamWrong
  3686. return
  3687. }
  3688. mode := int64(dataBody["mode"].(float64))
  3689. if mode <= 0 {
  3690. utils.ErrorLog("mode <= 0")
  3691. code = enums.ErrorCodeParamWrong
  3692. return
  3693. }
  3694. solution.ModeId = mode
  3695. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  3696. utils.ErrorLog("mode_name")
  3697. code = enums.ErrorCodeParamWrong
  3698. return
  3699. }
  3700. modeName, _ := dataBody["mode_name"].(string)
  3701. if len(modeName) == 0 {
  3702. utils.ErrorLog("len(mode_name) == 0")
  3703. code = enums.ErrorCodeParamWrong
  3704. return
  3705. }
  3706. solution.ModeName = modeName
  3707. solution.Name = modeName
  3708. }
  3709. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  3710. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  3711. solution.DialysisDuration = dialysisDuration
  3712. }
  3713. if dataBody["target_ultrafiltration"] != nil && reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  3714. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  3715. solution.TargetUltrafiltration = targetUltrafiltration
  3716. }
  3717. if dataBody["dialysate_formulation"] != nil && reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  3718. dialysateFormulation := int64(dataBody["dialysate_formulation"].(float64))
  3719. solution.DialysateFormulation = dialysateFormulation
  3720. }
  3721. if dataBody["dialysis_duration_hour"] != nil && reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  3722. dialysisDurationHour, _ := strconv.ParseFloat(dataBody["dialysis_duration_hour"].(string), 64)
  3723. solution.DialysisDurationHour = int64(dialysisDurationHour)
  3724. }
  3725. if dataBody["dialysis_duration_minute"] != nil && reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  3726. dialysisDurationMinute, _ := strconv.ParseFloat(dataBody["dialysis_duration_minute"].(string), 64)
  3727. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  3728. }
  3729. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  3730. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  3731. solution.HemodialysisMachine = hemodialysisMachine
  3732. }
  3733. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  3734. dialyzer := int64(dataBody["dialyzer"].(float64))
  3735. solution.Dialyzer = dialyzer
  3736. }
  3737. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  3738. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  3739. solution.PerfusionApparatus = perfusionApparatus
  3740. }
  3741. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  3742. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  3743. solution.BloodFlowVolume = bloodFlowVolume
  3744. }
  3745. if dataBody["dewater"] != nil && reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  3746. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  3747. solution.Dewater = dewater
  3748. }
  3749. if dataBody["displace_liqui"] != nil && reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  3750. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  3751. solution.DisplaceLiqui = displaceLiqui
  3752. }
  3753. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  3754. replacementWay := int64(dataBody["replacement_way"].(float64))
  3755. solution.ReplacementWay = replacementWay
  3756. }
  3757. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  3758. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  3759. solution.Anticoagulant = anticoagulant
  3760. }
  3761. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  3762. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  3763. solution.AnticoagulantShouji = anticoagulantShouji
  3764. }
  3765. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  3766. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  3767. solution.AnticoagulantWeichi = anticoagulantWeichi
  3768. }
  3769. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  3770. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  3771. solution.AnticoagulantZongliang = anticoagulantZongliang
  3772. }
  3773. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  3774. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  3775. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  3776. }
  3777. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  3778. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  3779. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  3780. }
  3781. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  3782. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  3783. solution.Kalium = kalium
  3784. }
  3785. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  3786. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  3787. solution.Sodium = sodium
  3788. }
  3789. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  3790. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  3791. solution.Calcium = calcium
  3792. }
  3793. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  3794. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  3795. solution.Bicarbonate = bicarbonate
  3796. }
  3797. if dataBody["glucose"] != nil && reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  3798. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  3799. solution.Glucose = glucose
  3800. }
  3801. // if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  3802. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  3803. // solution.DryWeight = dryWeight
  3804. // }
  3805. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  3806. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  3807. solution.DialysateFlow = dialysateFlow
  3808. }
  3809. if dataBody["dialysate_temperature"] != nil && reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  3810. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  3811. solution.DialysateTemperature = dialysateTemperature
  3812. }
  3813. if dataBody["conductivity"] != nil && reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  3814. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  3815. solution.Conductivity = conductivity
  3816. }
  3817. if dataBody["replacement_total"] != nil && reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  3818. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  3819. solution.ReplacementTotal = replacementTotal
  3820. }
  3821. if dataBody["dialyzer_perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["dialyzer_perfusion_apparatus"]).String() == "string" {
  3822. dialyzer_perfusion_apparatus := dataBody["dialyzer_perfusion_apparatus"].(string)
  3823. solution.DialyzerPerfusionApparatus = dialyzer_perfusion_apparatus
  3824. }
  3825. if dataBody["body_fluid"] != nil && reflect.TypeOf(dataBody["body_fluid"]).String() == "float64" {
  3826. body_fluid := int64(dataBody["body_fluid"].(float64))
  3827. solution.BodyFluid = body_fluid
  3828. }
  3829. if dataBody["body_fluid_other"] != nil && reflect.TypeOf(dataBody["body_fluid_other"]).String() == "string" {
  3830. body_fluid_other := dataBody["body_fluid_other"].(string)
  3831. solution.BodyFluidOther = body_fluid_other
  3832. }
  3833. if dataBody["special_medicine"] != nil && reflect.TypeOf(dataBody["special_medicine"]).String() == "float64" {
  3834. special_medicine := int64(dataBody["special_medicine"].(float64))
  3835. solution.SpecialMedicine = special_medicine
  3836. }
  3837. if dataBody["special_medicine_other"] != nil && reflect.TypeOf(dataBody["special_medicine_other"]).String() == "string" {
  3838. special_medicine_other := dataBody["special_medicine_other"].(string)
  3839. solution.SpecialMedicineOther = special_medicine_other
  3840. }
  3841. if dataBody["displace_liqui_part"] != nil && reflect.TypeOf(dataBody["displace_liqui_part"]).String() == "float64" {
  3842. displace_liqui_part := int64(dataBody["displace_liqui_part"].(float64))
  3843. solution.DisplaceLiquiPart = displace_liqui_part
  3844. }
  3845. if dataBody["displace_liqui_value"] != nil && reflect.TypeOf(dataBody["displace_liqui_value"]).String() == "string" {
  3846. displace_liqui_value, _ := strconv.ParseFloat(dataBody["displace_liqui_value"].(string), 64)
  3847. solution.DisplaceLiquiValue = displace_liqui_value
  3848. }
  3849. if dataBody["blood_access"] != nil && reflect.TypeOf(dataBody["blood_access"]).String() == "float64" {
  3850. blood_access := int64(dataBody["blood_access"].(float64))
  3851. solution.BloodAccess = blood_access
  3852. }
  3853. if dataBody["ultrafiltration"] != nil && reflect.TypeOf(dataBody["ultrafiltration"]).String() == "string" {
  3854. ultrafiltration, _ := strconv.ParseFloat(dataBody["ultrafiltration"].(string), 64)
  3855. solution.Ultrafiltration = ultrafiltration
  3856. }
  3857. if dataBody["target_ktv"] != nil && reflect.TypeOf(dataBody["target_ktv"]).String() == "string" {
  3858. target_ktv, _ := strconv.ParseFloat(dataBody["target_ktv"].(string), 64)
  3859. solution.TargetKtv = target_ktv
  3860. }
  3861. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3862. remark := dataBody["remark"].(string)
  3863. solution.Remark = remark
  3864. }
  3865. if dataBody["hemodialysis_pipelines"] != nil && reflect.TypeOf(dataBody["hemodialysis_pipelines"]).String() == "string" {
  3866. hemodialysis_pipelines := dataBody["hemodialysis_pipelines"].(string)
  3867. solution.HemodialysisPipelines = hemodialysis_pipelines
  3868. }
  3869. if dataBody["hemodialysis_pipelines_count"] != nil && reflect.TypeOf(dataBody["hemodialysis_pipelines_count"]).String() == "string" {
  3870. hemodialysis_pipelines_count, _ := strconv.ParseFloat(dataBody["hemodialysis_pipelines_count"].(string), 64)
  3871. solution.HemodialysisPipelinesCount = hemodialysis_pipelines_count
  3872. }
  3873. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  3874. puncture_needle := dataBody["puncture_needle"].(string)
  3875. solution.PunctureNeedle = puncture_needle
  3876. }
  3877. if dataBody["puncture_needle_count"] != nil && reflect.TypeOf(dataBody["puncture_needle_count"]).String() == "string" {
  3878. puncture_needle_count, _ := strconv.ParseFloat(dataBody["puncture_needle_count"].(string), 64)
  3879. solution.PunctureNeedleCount = puncture_needle_count
  3880. }
  3881. if dataBody["epo"] != nil && reflect.TypeOf(dataBody["epo"]).String() == "string" {
  3882. epo := dataBody["epo"].(string)
  3883. solution.Epo = epo
  3884. }
  3885. if dataBody["epo_count"] != nil && reflect.TypeOf(dataBody["epo_count"]).String() == "string" {
  3886. epo_count, _ := strconv.ParseFloat(dataBody["epo_count"].(string), 64)
  3887. solution.EpoCount = epo_count
  3888. }
  3889. if dataBody["created_time"] != nil && reflect.TypeOf(dataBody["created_time"]).String() == "float64" {
  3890. created_time := int64(dataBody["created_time"].(float64))
  3891. solution.CreatedTime = created_time
  3892. }
  3893. if dataBody["dialysis_dialyszers"] != nil && reflect.TypeOf(dataBody["dialysis_dialyszers"]).String() == "string" {
  3894. dialysisDialyszers := dataBody["dialysis_dialyszers"].(string)
  3895. solution.DialysisDialyszers = dialysisDialyszers
  3896. }
  3897. if dataBody["dialysis_irrigation"] != nil && reflect.TypeOf(dataBody["dialysis_irrigation"]).String() == "string" {
  3898. dialysisIrrigation := dataBody["dialysis_irrigation"].(string)
  3899. solution.DialysisIrrigation = dialysisIrrigation
  3900. }
  3901. if dataBody["dialysis_strainer"] != nil && reflect.TypeOf(dataBody["dialysis_strainer"]).String() == "string" {
  3902. dialysis_strainer := dataBody["dialysis_strainer"].(string)
  3903. solution.DialysisStrainer = dialysis_strainer
  3904. }
  3905. if dataBody["plasma_separator"] != nil && reflect.TypeOf(dataBody["plasma_separator"]).String() == "string" {
  3906. plasmaSeparator := dataBody["plasma_separator"].(string)
  3907. solution.PlasmaSeparator = plasmaSeparator
  3908. }
  3909. if dataBody["bilirubin_adsorption_column"] != nil && reflect.TypeOf(dataBody["bilirubin_adsorption_column"]).String() == "string" {
  3910. bilirubinAdsorptionColumn := dataBody["bilirubin_adsorption_column"].(string)
  3911. solution.BilirubinAdsorptionColumn = bilirubinAdsorptionColumn
  3912. }
  3913. if dataBody["oxygen_uptake"] != nil && reflect.TypeOf(dataBody["oxygen_uptake"]).String() == "float64" {
  3914. oxygen_uptake := int64(dataBody["oxygen_uptake"].(float64))
  3915. solution.OxygenUptake = oxygen_uptake
  3916. }
  3917. if dataBody["oxygen_flow"] != nil && reflect.TypeOf(dataBody["oxygen_flow"]).String() == "string" {
  3918. oxygen_flow := dataBody["oxygen_flow"].(string)
  3919. solution.OxygenFlow = oxygen_flow
  3920. }
  3921. if dataBody["oxygen_time"] != nil && reflect.TypeOf(dataBody["oxygen_time"]).String() == "string" {
  3922. oxygen_time := dataBody["oxygen_time"].(string)
  3923. solution.OxygenTime = oxygen_time
  3924. }
  3925. if dataBody["max_ultrafiltration_rate"] != nil && reflect.TypeOf(dataBody["max_ultrafiltration_rate"]).String() == "string" {
  3926. max_ultrafiltration_rate, _ := strconv.ParseFloat(dataBody["max_ultrafiltration_rate"].(string), 64)
  3927. solution.MaxUltrafiltrationRate = max_ultrafiltration_rate
  3928. }
  3929. if dataBody["amylaceum"] != nil && reflect.TypeOf(dataBody["amylaceum"]).String() == "string" {
  3930. amylaceum := dataBody["amylaceum"].(string)
  3931. solution.Amylaceum = amylaceum
  3932. }
  3933. if dataBody["chaptalization"] != nil && reflect.TypeOf(dataBody["chaptalization"]).String() == "string" {
  3934. chaptalization := dataBody["chaptalization"].(string)
  3935. solution.Chaptalization = chaptalization
  3936. }
  3937. return
  3938. }
  3939. func childSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  3940. dataBody := make(map[string]interface{}, 0)
  3941. err := json.Unmarshal(data, &dataBody)
  3942. utils.InfoLog(string(data))
  3943. if err != nil {
  3944. utils.ErrorLog(err.Error())
  3945. code = enums.ErrorCodeParamWrong
  3946. return
  3947. }
  3948. if method == "create" {
  3949. if dataBody["parent_id"] == nil || reflect.TypeOf(dataBody["parent_id"]).String() != "float64" {
  3950. utils.ErrorLog("parent_id")
  3951. code = enums.ErrorCodeParamWrong
  3952. return
  3953. }
  3954. parentID := int64(dataBody["parent_id"].(float64))
  3955. if parentID <= 0 {
  3956. utils.ErrorLog("parentID <= 0")
  3957. code = enums.ErrorCodeParamWrong
  3958. return
  3959. }
  3960. solution.ParentId = parentID
  3961. if dataBody["sub_name"] == nil || reflect.TypeOf(dataBody["sub_name"]).String() != "string" {
  3962. utils.ErrorLog("sub_name")
  3963. code = enums.ErrorCodeParamWrong
  3964. return
  3965. }
  3966. subName, _ := dataBody["sub_name"].(string)
  3967. if len(subName) == 0 {
  3968. utils.ErrorLog("len(sub_name) == 0")
  3969. code = enums.ErrorCodeParamWrong
  3970. return
  3971. }
  3972. solution.SubName = subName
  3973. }
  3974. if dataBody["initiate_mode"] == nil || reflect.TypeOf(dataBody["initiate_mode"]).String() != "float64" {
  3975. utils.ErrorLog("initiate_mode")
  3976. code = enums.ErrorCodeParamWrong
  3977. return
  3978. }
  3979. initiateMode := int64(dataBody["initiate_mode"].(float64))
  3980. if initiateMode != 1 && initiateMode != 2 {
  3981. utils.ErrorLog("initiateMode != 1 && initiateMode != 2")
  3982. code = enums.ErrorCodeParamWrong
  3983. return
  3984. }
  3985. solution.InitiateMode = initiateMode
  3986. if dataBody["doctor"] == nil || reflect.TypeOf(dataBody["doctor"]).String() != "float64" {
  3987. utils.ErrorLog("doctor")
  3988. code = enums.ErrorCodeParamWrong
  3989. return
  3990. }
  3991. doctor := int64(dataBody["doctor"].(float64))
  3992. if doctor <= 0 {
  3993. utils.ErrorLog("doctor <= 0")
  3994. code = enums.ErrorCodeParamWrong
  3995. return
  3996. }
  3997. solution.Doctor = doctor
  3998. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  3999. blood_access_part_id, _ := dataBody["blood_access_part_id"].(string)
  4000. solution.BloodAccessPartId = blood_access_part_id
  4001. }
  4002. return
  4003. }
  4004. func patientFormData(patient *models.Patients, data []byte, method string) (contagions []int64, diseases []int64, code int, formItems []*models.FormItem) {
  4005. patientBody := make(map[string]interface{}, 0)
  4006. err := json.Unmarshal(data, &patientBody)
  4007. if err != nil {
  4008. utils.ErrorLog(err.Error())
  4009. code = enums.ErrorCodeParamWrong
  4010. return
  4011. }
  4012. if patientBody["formItem"] != nil && reflect.TypeOf(patientBody["formItem"]).String() == "[]interface {}" {
  4013. formItem, _ := patientBody["formItem"].([]interface{})
  4014. if len(formItem) > 0 {
  4015. for _, item := range formItem {
  4016. items := item.(map[string]interface{})
  4017. project_name, _ := items["project_name"].(string)
  4018. fmt.Println(project_name)
  4019. range_type := int64(items["range_type"].(float64))
  4020. fmt.Println(range_type)
  4021. project_id := int64(items["project_id"].(float64))
  4022. fmt.Println(project_id)
  4023. item_id := int64(items["item_id"].(float64))
  4024. fmt.Println(item_id)
  4025. item, _ := items["item"].(string)
  4026. fmt.Println(items["item"].(string))
  4027. item_name, _ := items["item_name"].(string)
  4028. fmt.Println(item_name)
  4029. value, _ := items["value"].(string)
  4030. fmt.Println(items["value"].(string))
  4031. var form models.FormItem
  4032. form.ProjectName = project_name
  4033. form.RangeType = range_type
  4034. form.ProjectId = project_id
  4035. form.ItemId = item_id
  4036. form.Item = item
  4037. form.ItemName = item_name
  4038. form.Value = value
  4039. formItems = append(formItems, &form)
  4040. }
  4041. }
  4042. }
  4043. if patientBody["avatar"] == nil || reflect.TypeOf(patientBody["avatar"]).String() != "string" {
  4044. utils.ErrorLog("avatar")
  4045. code = enums.ErrorCodeParamWrong
  4046. return
  4047. }
  4048. avatar, _ := patientBody["avatar"].(string)
  4049. if len(avatar) == 0 {
  4050. utils.ErrorLog("len(avatar) == 0")
  4051. code = enums.ErrorCodeParamWrong
  4052. return
  4053. }
  4054. patient.Avatar = avatar
  4055. if patientBody["name"] == nil || reflect.TypeOf(patientBody["name"]).String() != "string" {
  4056. utils.ErrorLog("name")
  4057. code = enums.ErrorCodeParamWrong
  4058. return
  4059. }
  4060. name, _ := patientBody["name"].(string)
  4061. if len(name) == 0 {
  4062. utils.ErrorLog("len(name) == 0")
  4063. code = enums.ErrorCodeParamWrong
  4064. return
  4065. }
  4066. patient.Name = name
  4067. if patientBody["alias"] != nil && reflect.TypeOf(patientBody["alias"]).String() == "string" {
  4068. alias := patientBody["alias"].(string)
  4069. patient.Alias = alias
  4070. }
  4071. if patientBody["nation"] != nil && reflect.TypeOf(patientBody["nation"]).String() == "string" {
  4072. nation := patientBody["nation"].(string)
  4073. patient.Nation = nation
  4074. }
  4075. if patientBody["native_place"] != nil && reflect.TypeOf(patientBody["native_place"]).String() == "string" {
  4076. native_place := patientBody["native_place"].(string)
  4077. patient.NativePlace = native_place
  4078. }
  4079. if patientBody["idCardNo"] == nil || reflect.TypeOf(patientBody["idCardNo"]).String() != "string" {
  4080. utils.ErrorLog("idCardNo")
  4081. code = enums.ErrorCodeParamWrong
  4082. return
  4083. }
  4084. idCardNo, _ := patientBody["idCardNo"].(string)
  4085. if len(idCardNo) == 0 {
  4086. utils.ErrorLog("len(idCardNo) == 0")
  4087. code = enums.ErrorCodeParamWrong
  4088. return
  4089. }
  4090. patient.IdCardNo = idCardNo
  4091. patient.PatientType = 1
  4092. if patientBody["dialysisNo"] == nil || reflect.TypeOf(patientBody["dialysisNo"]).String() != "string" {
  4093. utils.ErrorLog("dialysisNo")
  4094. code = enums.ErrorCodeParamWrong
  4095. return
  4096. }
  4097. dialysisNo, _ := patientBody["dialysisNo"].(string)
  4098. if len(dialysisNo) == 0 {
  4099. utils.ErrorLog("len(dialysisNo) == 0")
  4100. code = enums.ErrorCodeParamWrong
  4101. return
  4102. }
  4103. patient.DialysisNo = dialysisNo
  4104. // }
  4105. if patientBody["lapseto"] == nil || reflect.TypeOf(patientBody["lapseto"]).String() != "float64" {
  4106. utils.ErrorLog("lapseto")
  4107. code = enums.ErrorCodeParamWrong
  4108. return
  4109. }
  4110. lapseto := int64(patientBody["lapseto"].(float64))
  4111. if lapseto <= 0 {
  4112. utils.ErrorLog("lapseto == 0")
  4113. code = enums.ErrorCodeParamWrong
  4114. return
  4115. }
  4116. patient.Lapseto = lapseto
  4117. if patientBody["gender"] == nil || reflect.TypeOf(patientBody["gender"]).String() != "float64" {
  4118. utils.ErrorLog("gender")
  4119. code = enums.ErrorCodeParamWrong
  4120. return
  4121. }
  4122. gender := int64(patientBody["gender"].(float64))
  4123. if gender <= 0 {
  4124. utils.ErrorLog("gender <= 0")
  4125. code = enums.ErrorCodeParamWrong
  4126. return
  4127. }
  4128. patient.Gender = gender
  4129. if patientBody["response_result"] != nil && reflect.TypeOf(patientBody["response_result"]).String() == "string" {
  4130. response_result := patientBody["response_result"].(string)
  4131. patient.ResponseResult = response_result
  4132. }
  4133. if patientBody["age"] == nil || reflect.TypeOf(patientBody["age"]).String() != "float64" {
  4134. utils.ErrorLog("age")
  4135. code = enums.ErrorCodeParamWrong
  4136. return
  4137. }
  4138. age := int64(patientBody["age"].(float64))
  4139. patient.Age = age
  4140. if patientBody["user_sys_before_count"] != nil || reflect.TypeOf(patientBody["user_sys_before_count"]).String() == "string" {
  4141. user_sys_before_count := patientBody["user_sys_before_count"].(string)
  4142. count, _ := strconv.ParseInt(user_sys_before_count, 10, 64)
  4143. patient.UserSysBeforeCount = count
  4144. }
  4145. timeLayout := "2006-01-02"
  4146. loc, _ := time.LoadLocation("Local")
  4147. if patientBody["birth"] == nil || reflect.TypeOf(patientBody["birth"]).String() != "string" {
  4148. utils.ErrorLog("birth")
  4149. code = enums.ErrorCodeParamWrong
  4150. return
  4151. }
  4152. birth, _ := patientBody["birth"].(string)
  4153. if len(birth) == 0 {
  4154. utils.ErrorLog("len(birth) == 0")
  4155. code = enums.ErrorCodeParamWrong
  4156. return
  4157. }
  4158. birthTime, err := time.ParseInLocation(timeLayout, birth, loc)
  4159. if err != nil {
  4160. utils.ErrorLog("birthTime")
  4161. code = enums.ErrorCodeParamWrong
  4162. return
  4163. }
  4164. patient.Birthday = birthTime.Unix()
  4165. if patientBody["height"] != nil && reflect.TypeOf(patientBody["height"]).String() == "string" {
  4166. height, _ := strconv.ParseInt(patientBody["height"].(string), 10, 64)
  4167. patient.Height = height
  4168. }
  4169. if patientBody["maritalStatus"] != nil && reflect.TypeOf(patientBody["maritalStatus"]).String() == "float64" {
  4170. maritalStatus := int64(patientBody["maritalStatus"].(float64))
  4171. patient.MaritalStatus = maritalStatus
  4172. }
  4173. if patientBody["children"] != nil && reflect.TypeOf(patientBody["children"]).String() == "string" {
  4174. children, _ := strconv.ParseInt(patientBody["children"].(string), 10, 64)
  4175. patient.Children = children
  4176. }
  4177. if patientBody["admissionNumber"] != nil && reflect.TypeOf(patientBody["admissionNumber"]).String() == "string" {
  4178. admissionNumber, _ := patientBody["admissionNumber"].(string)
  4179. patient.AdmissionNumber = admissionNumber
  4180. }
  4181. if patientBody["reimbursementWayID"] != nil && reflect.TypeOf(patientBody["reimbursementWayID"]).String() == "float64" {
  4182. reimbursementWayID := int64(patientBody["reimbursementWayID"].(float64))
  4183. patient.ReimbursementWayId = reimbursementWayID
  4184. }
  4185. if patientBody["healthCareNo"] != nil && reflect.TypeOf(patientBody["healthCareNo"]).String() == "string" {
  4186. healthCareNo := patientBody["healthCareNo"].(string)
  4187. patient.HealthCareNo = healthCareNo
  4188. }
  4189. if patientBody["phone"] == nil || reflect.TypeOf(patientBody["phone"]).String() != "string" {
  4190. utils.ErrorLog("phone")
  4191. code = enums.ErrorCodeParamWrong
  4192. return
  4193. }
  4194. phone := patientBody["phone"].(string)
  4195. if len(phone) == 0 {
  4196. utils.ErrorLog("len(phone) == 0")
  4197. code = enums.ErrorCodeParamWrong
  4198. return
  4199. }
  4200. if !utils.CheckMobile(phone) {
  4201. utils.ErrorLog("!phone")
  4202. code = enums.ErrorCodeMobileFormat
  4203. return
  4204. }
  4205. patient.Phone = phone
  4206. if patientBody["homeTelephone"] != nil && reflect.TypeOf(patientBody["homeTelephone"]).String() == "string" {
  4207. homeTelephone := patientBody["homeTelephone"].(string)
  4208. patient.HomeTelephone = homeTelephone
  4209. }
  4210. if patientBody["relative_phone"] != nil && reflect.TypeOf(patientBody["relative_phone"]).String() == "string" {
  4211. relativePhone := patientBody["relative_phone"].(string)
  4212. patient.RelativePhone = relativePhone
  4213. }
  4214. if patientBody["relative_relations"] != nil && reflect.TypeOf(patientBody["relative_relations"]).String() == "string" {
  4215. relativeRelations := patientBody["relative_relations"].(string)
  4216. patient.RelativeRelations = relativeRelations
  4217. }
  4218. if patientBody["homeAddress"] != nil && reflect.TypeOf(patientBody["homeAddress"]).String() == "string" {
  4219. homeAddress := patientBody["homeAddress"].(string)
  4220. patient.HomeAddress = homeAddress
  4221. }
  4222. if patientBody["work"] != nil && reflect.TypeOf(patientBody["work"]).String() == "string" {
  4223. work := patientBody["work"].(string)
  4224. patient.WorkUnit = work
  4225. }
  4226. if patientBody["unit_address"] != nil && reflect.TypeOf(patientBody["unit_address"]).String() == "string" {
  4227. unitAddress := patientBody["unit_address"].(string)
  4228. patient.UnitAddress = unitAddress
  4229. }
  4230. if patientBody["profession"] != nil && reflect.TypeOf(patientBody["profession"]).String() == "float64" {
  4231. profession := int64(patientBody["profession"].(float64))
  4232. patient.Profession = profession
  4233. }
  4234. if patientBody["education"] != nil && reflect.TypeOf(patientBody["education"]).String() == "float64" {
  4235. education := int64(patientBody["education"].(float64))
  4236. patient.EducationLevel = education
  4237. }
  4238. if patientBody["source"] == nil || reflect.TypeOf(patientBody["source"]).String() != "float64" {
  4239. utils.ErrorLog("source")
  4240. code = enums.ErrorCodeParamWrong
  4241. return
  4242. }
  4243. source := int64(patientBody["source"].(float64))
  4244. if source <= 0 {
  4245. utils.ErrorLog("source <= 0")
  4246. code = enums.ErrorCodeParamWrong
  4247. return
  4248. }
  4249. patient.Source = source
  4250. zb_patient_id := patientBody["zb_patient_id"].(string)
  4251. patient.ZbPatientId = zb_patient_id
  4252. if patientBody["is_hospital_first_dialysis"] != nil && reflect.TypeOf(patientBody["is_hospital_first_dialysis"]).String() == "float64" {
  4253. isHospitalFirstDialysis := int64(patientBody["is_hospital_first_dialysis"].(float64))
  4254. patient.IsHospitalFirstDialysis = isHospitalFirstDialysis
  4255. }
  4256. if patientBody["firstDialysisDate"] != nil && reflect.TypeOf(patientBody["firstDialysisDate"]).String() == "string" {
  4257. firstDialysisDate := patientBody["firstDialysisDate"].(string)
  4258. firstDialysisDateTime, err := time.ParseInLocation(timeLayout, firstDialysisDate, loc)
  4259. if err == nil {
  4260. patient.FirstDialysisDate = firstDialysisDateTime.Unix()
  4261. }
  4262. }
  4263. if patientBody["first_dialysis_hospital"] != nil && reflect.TypeOf(patientBody["first_dialysis_hospital"]).String() == "string" {
  4264. firstDialysisHospital := patientBody["first_dialysis_hospital"].(string)
  4265. patient.FirstDialysisHospital = firstDialysisHospital
  4266. }
  4267. if patientBody["predialysis_condition"] != nil && reflect.TypeOf(patientBody["predialysis_condition"]).String() == "[]interface {}" {
  4268. thePredialysisCondition, _ := patientBody["predialysis_condition"].([]interface{})
  4269. if len(thePredialysisCondition) > 0 {
  4270. conditions := make([]string, 0)
  4271. for _, item := range thePredialysisCondition {
  4272. if reflect.TypeOf(item).String() != "string" {
  4273. continue
  4274. }
  4275. condition := item.(string)
  4276. if len(condition) > 0 {
  4277. conditions = append(conditions, condition)
  4278. }
  4279. }
  4280. patient.PredialysisCondition = strings.Join(conditions, ",")
  4281. }
  4282. }
  4283. if patientBody["pre_hospital_dialysis_frequency"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_frequency"]).String() == "string" {
  4284. preHospitalDialysisFrequency := patientBody["pre_hospital_dialysis_frequency"].(string)
  4285. patient.PreHospitalDialysisFrequency = preHospitalDialysisFrequency
  4286. }
  4287. if patientBody["pre_hospital_dialysis_times"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_times"]).String() == "string" {
  4288. preHospitalDialysisTimes, _ := strconv.ParseInt(patientBody["pre_hospital_dialysis_times"].(string), 10, 64)
  4289. patient.PreHospitalDialysisTimes = preHospitalDialysisTimes
  4290. }
  4291. if patientBody["hospital_first_dialysis_date"] != nil && reflect.TypeOf(patientBody["hospital_first_dialysis_date"]).String() == "string" {
  4292. hospitalFirstDialysisDate := patientBody["hospital_first_dialysis_date"].(string)
  4293. hospitalFirstDialysisDateTime, err := time.ParseInLocation(timeLayout, hospitalFirstDialysisDate, loc)
  4294. if err == nil {
  4295. patient.HospitalFirstDialysisDate = hospitalFirstDialysisDateTime.Unix()
  4296. }
  4297. }
  4298. if patientBody["partition"] != nil && reflect.TypeOf(patientBody["partition"]).String() == "float64" {
  4299. partition := int64(patientBody["partition"].(float64))
  4300. patient.PartitionId = partition
  4301. }
  4302. if patientBody["bed"] != nil && reflect.TypeOf(patientBody["bed"]).String() == "string" {
  4303. bed, _ := strconv.ParseInt(patientBody["bed"].(string), 10, 64)
  4304. patient.BedId = bed
  4305. }
  4306. if patientBody["healthCareDueDate"] != nil && reflect.TypeOf(patientBody["healthCareDueDate"]).String() == "string" {
  4307. healthCareDueDate := patientBody["healthCareDueDate"].(string)
  4308. healthCareDueDateTime, err := time.ParseInLocation(timeLayout, healthCareDueDate, loc)
  4309. if err == nil {
  4310. patient.HealthCareDueDate = healthCareDueDateTime.Unix()
  4311. }
  4312. }
  4313. if patientBody["blood"] != nil && reflect.TypeOf(patientBody["blood"]).String() == "float64" {
  4314. blood := int64(patientBody["blood"].(float64))
  4315. patient.BloodType = blood
  4316. }
  4317. if patientBody["rh"] != nil && reflect.TypeOf(patientBody["rh"]).String() == "float64" {
  4318. rh := int64(patientBody["rh"].(float64))
  4319. patient.Rh = rh
  4320. }
  4321. if patientBody["healthCareDueAlertDate"] != nil && reflect.TypeOf(patientBody["healthCareDueAlertDate"]).String() == "string" {
  4322. healthCareDueAlertDate := patientBody["healthCareDueAlertDate"].(string)
  4323. healthCareDueAlertDateTime, err := time.ParseInLocation(timeLayout, healthCareDueAlertDate, loc)
  4324. if err == nil {
  4325. patient.HealthCareDueAlertDate = healthCareDueAlertDateTime.Unix()
  4326. }
  4327. }
  4328. if patientBody["receivingDate"] != nil && reflect.TypeOf(patientBody["receivingDate"]).String() == "string" {
  4329. receivingDate := patientBody["receivingDate"].(string)
  4330. receivingDateTime, err := time.ParseInLocation(timeLayout, receivingDate, loc)
  4331. if err == nil {
  4332. patient.ReceivingDate = receivingDateTime.Unix()
  4333. }
  4334. }
  4335. if patientBody["induction"] != nil && reflect.TypeOf(patientBody["induction"]).String() == "float64" {
  4336. induction := int64(patientBody["induction"].(float64))
  4337. patient.InductionPeriod = induction
  4338. }
  4339. if patientBody["initial"] != nil && reflect.TypeOf(patientBody["initial"]).String() == "string" {
  4340. initial, _ := strconv.ParseInt(patientBody["initial"].(string), 10, 64)
  4341. patient.InitialDialysis = initial
  4342. }
  4343. if patientBody["dialysisTotal"] != nil && reflect.TypeOf(patientBody["dialysisTotal"]).String() == "string" {
  4344. dialysisTotal, _ := strconv.ParseInt(patientBody["dialysisTotal"].(string), 10, 64)
  4345. patient.TotalDialysis = dialysisTotal
  4346. }
  4347. if patientBody["contagions"] != nil && reflect.TypeOf(patientBody["contagions"]).String() == "[]interface {}" {
  4348. thisContagions, _ := patientBody["contagions"].([]interface{})
  4349. if len(thisContagions) > 0 {
  4350. for _, item := range thisContagions {
  4351. if reflect.TypeOf(item).String() != "float64" {
  4352. continue
  4353. }
  4354. contagion := int64(item.(float64))
  4355. if contagion > 0 {
  4356. contagions = append(contagions, contagion)
  4357. }
  4358. }
  4359. }
  4360. }
  4361. if patientBody["doctor"] != nil && reflect.TypeOf(patientBody["doctor"]).String() == "float64" {
  4362. doctor := int64(patientBody["doctor"].(float64))
  4363. patient.AttendingDoctorId = doctor
  4364. }
  4365. if patientBody["nurse"] != nil && reflect.TypeOf(patientBody["nurse"]).String() == "float64" {
  4366. nurse := int64(patientBody["nurse"].(float64))
  4367. patient.HeadNurseId = nurse
  4368. }
  4369. if patientBody["assessment"] != nil && reflect.TypeOf(patientBody["assessment"]).String() == "string" {
  4370. assessment := patientBody["assessment"].(string)
  4371. patient.Evaluate = assessment
  4372. }
  4373. if patientBody["diseases"] != nil && reflect.TypeOf(patientBody["diseases"]).String() == "[]interface {}" {
  4374. thisDiseases, _ := patientBody["diseases"].([]interface{})
  4375. if len(thisDiseases) > 0 {
  4376. for _, item := range thisDiseases {
  4377. if reflect.TypeOf(item).String() != "float64" {
  4378. continue
  4379. }
  4380. disease := int64(item.(float64))
  4381. if disease > 0 {
  4382. diseases = append(diseases, disease)
  4383. }
  4384. }
  4385. }
  4386. }
  4387. if patientBody["diagnose"] != nil && reflect.TypeOf(patientBody["diagnose"]).String() == "string" {
  4388. diagnose := patientBody["diagnose"].(string)
  4389. patient.Diagnose = diagnose
  4390. }
  4391. if patientBody["remark"] != nil && reflect.TypeOf(patientBody["remark"]).String() == "string" {
  4392. remark := patientBody["remark"].(string)
  4393. patient.Remark = remark
  4394. }
  4395. if patientBody["sch_remark"] != nil && reflect.TypeOf(patientBody["sch_remark"]).String() == "string" {
  4396. sch_remark := patientBody["sch_remark"].(string)
  4397. patient.SchRemark = sch_remark
  4398. }
  4399. if patientBody["patient_complains"] != nil && reflect.TypeOf(patientBody["patient_complains"]).String() == "string" {
  4400. patient_complains := patientBody["patient_complains"].(string)
  4401. patient.PatientComplains = patient_complains
  4402. }
  4403. if patientBody["present_history"] != nil && reflect.TypeOf(patientBody["present_history"]).String() == "string" {
  4404. present_history := patientBody["present_history"].(string)
  4405. patient.PresentHistory = present_history
  4406. }
  4407. if patientBody["past_history"] != nil && reflect.TypeOf(patientBody["past_history"]).String() == "string" {
  4408. past_history := patientBody["past_history"].(string)
  4409. patient.PastHistory = past_history
  4410. }
  4411. if patientBody["temperature"] != nil && reflect.TypeOf(patientBody["temperature"]).String() == "string" {
  4412. temperature, _ := strconv.ParseFloat(patientBody["temperature"].(string), 64)
  4413. patient.Temperature = temperature
  4414. }
  4415. if patientBody["pulse"] != nil && reflect.TypeOf(patientBody["pulse"]).String() == "string" {
  4416. pulse, _ := strconv.ParseInt(patientBody["pulse"].(string), 10, 64)
  4417. patient.Pulse = pulse
  4418. }
  4419. if patientBody["respiratory"] != nil && reflect.TypeOf(patientBody["respiratory"]).String() == "string" {
  4420. respiratory, _ := strconv.ParseInt(patientBody["respiratory"].(string), 10, 64)
  4421. patient.Respiratory = respiratory
  4422. }
  4423. if patientBody["sbp"] != nil && reflect.TypeOf(patientBody["sbp"]).String() == "string" {
  4424. sbp, _ := strconv.ParseInt(patientBody["sbp"].(string), 10, 64)
  4425. patient.SBP = sbp
  4426. }
  4427. if patientBody["dbp"] != nil && reflect.TypeOf(patientBody["dbp"]).String() == "string" {
  4428. dbp, _ := strconv.ParseInt(patientBody["dbp"].(string), 10, 64)
  4429. patient.DBP = dbp
  4430. }
  4431. if patientBody["dialysis_age"] != nil && reflect.TypeOf(patientBody["dialysis_age"]).String() == "string" {
  4432. dialysis_age, _ := strconv.ParseInt(patientBody["dialysis_age"].(string), 10, 64)
  4433. patient.DialysisAge = dialysis_age
  4434. }
  4435. fmt.Println(patient.DialysisAge)
  4436. if patientBody["first_treatment_date"] != nil && reflect.TypeOf(patientBody["first_treatment_date"]).String() == "string" {
  4437. first_treatment_date := patientBody["first_treatment_date"].(string)
  4438. first_treatment_time, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
  4439. if err == nil {
  4440. patient.FirstTreatmentDate = first_treatment_time.Unix()
  4441. }
  4442. }
  4443. if patientBody["expense_kind"] != nil && reflect.TypeOf(patientBody["expense_kind"]).String() == "float64" {
  4444. expense_kind := int64(patientBody["expense_kind"].(float64))
  4445. patient.ExpenseKind = expense_kind
  4446. }
  4447. fmt.Println(patient.ExpenseKind)
  4448. if patientBody["tell_phone"] != nil && reflect.TypeOf(patientBody["tell_phone"]).String() == "string" {
  4449. tell_phone := patientBody["tell_phone"].(string)
  4450. patient.TellPhone = tell_phone
  4451. }
  4452. if patientBody["contact_name"] != nil && reflect.TypeOf(patientBody["contact_name"]).String() == "string" {
  4453. contact_name := patientBody["contact_name"].(string)
  4454. patient.ContactName = contact_name
  4455. }
  4456. if patientBody["troble_shoot"] != nil && reflect.TypeOf(patientBody["troble_shoot"]).String() == "float64" {
  4457. troble_shoot := int64(patientBody["troble_shoot"].(float64))
  4458. patient.TrobleShoot = troble_shoot
  4459. }
  4460. if patientBody["treatment_plan"] != nil && reflect.TypeOf(patientBody["treatment_plan"]).String() == "string" {
  4461. treatment_plan := patientBody["treatment_plan"].(string)
  4462. patient.TreatmentPlan = treatment_plan
  4463. }
  4464. if patientBody["doctor"] != nil && reflect.TypeOf(patientBody["doctor"]).String() == "float64" {
  4465. doctor := int64(patientBody["doctor"].(float64))
  4466. patient.Doctor = doctor
  4467. }
  4468. if patientBody["record_number"] != nil && reflect.TypeOf(patientBody["record_number"]).String() == "string" {
  4469. record_number := patientBody["record_number"].(string)
  4470. patient.RecordNumber = record_number
  4471. }
  4472. patient_source := int64(patientBody["patient_source"].(float64))
  4473. if patient_source <= 0 {
  4474. utils.ErrorLog("patient_source <= 0")
  4475. code = enums.ErrorCodeParamWrong
  4476. return
  4477. }
  4478. patient.PatientSource = patient_source
  4479. if patientBody["patient_start_time"] != nil && reflect.TypeOf(patientBody["patient_start_time"]).String() == "string" {
  4480. patient_start_time := patientBody["patient_start_time"].(string)
  4481. var startTime int64
  4482. if len(patient_start_time) > 0 {
  4483. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", patient_start_time+" 00:00:00", loc)
  4484. startTime = theTime.Unix()
  4485. }
  4486. patient.PatientStartTime = startTime
  4487. }
  4488. if patientBody["patient_end_time"] != nil && reflect.TypeOf(patientBody["patient_end_time"]).String() == "string" {
  4489. patient_end_time := patientBody["patient_end_time"].(string)
  4490. var endTime int64
  4491. if len(patient_end_time) > 0 {
  4492. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", patient_end_time+" 00:00:00", loc)
  4493. endTime = theTime.Unix()
  4494. }
  4495. patient.PatientEndTime = endTime
  4496. }
  4497. if patientBody["infectious_remark"] != nil && reflect.TypeOf(patientBody["infectious_remark"]).String() == "string" {
  4498. record_number := patientBody["infectious_remark"].(string)
  4499. patient.InfectiousRemark = record_number
  4500. }
  4501. if patientBody["allergic_history"] != nil && reflect.TypeOf(patientBody["allergic_history"]).String() == "string" {
  4502. allergic_history := patientBody["allergic_history"].(string)
  4503. patient.AllergicHistory = allergic_history
  4504. }
  4505. if patientBody["patient_address"] != nil && reflect.TypeOf(patientBody["patient_address"]).String() == "string" {
  4506. patient_address := patientBody["patient_address"].(string)
  4507. patient.PatientAddress = patient_address
  4508. }
  4509. return
  4510. }
  4511. func (c *PatientApiController) GetPatientsByKeyWord() {
  4512. keyWord := c.GetString("keyword")
  4513. adminUserInfo := c.GetAdminUserInfo()
  4514. patient, err := service.GetPatientByKeyWord(adminUserInfo.CurrentOrgId, keyWord)
  4515. if err != nil {
  4516. utils.ErrorLog(err.Error())
  4517. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4518. return
  4519. }
  4520. c.ServeSuccessJSON(map[string]interface{}{
  4521. "patient": patient,
  4522. })
  4523. }
  4524. func (c *PatientApiController) QueryPatientById() {
  4525. id, _ := c.GetInt64("id")
  4526. fmt.Println(id)
  4527. patientInfo := service.QueryPatientById(id)
  4528. c.ServeSuccessJSON(map[string]interface{}{
  4529. "patient": patientInfo,
  4530. })
  4531. return
  4532. }
  4533. func (c *PatientApiController) GetRemindPatientList() {
  4534. page, _ := c.GetInt64("page", 1)
  4535. limit, _ := c.GetInt64("limit", 10)
  4536. adminUserInfo := c.GetAdminUserInfo()
  4537. total, patients, _ := service.GetAllWaitRemindPatient(adminUserInfo.CurrentOrgId, page, limit)
  4538. _, errcode := service.GetOrgFollowIsExist(c.GetAdminUserInfo().CurrentOrgId)
  4539. if errcode == gorm.ErrRecordNotFound {
  4540. information, err := service.GetAdminUserRoleInformation(0)
  4541. if err != nil {
  4542. utils.ErrorLog(err.Error())
  4543. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4544. return
  4545. }
  4546. c.ServeSuccessJSON(map[string]interface{}{
  4547. "total": total,
  4548. "patients": patients,
  4549. "information": information,
  4550. })
  4551. } else if errcode == nil {
  4552. information, err := service.GetAdminUserRoleInformation(c.GetAdminUserInfo().CurrentOrgId)
  4553. if err != nil {
  4554. utils.ErrorLog(err.Error())
  4555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4556. return
  4557. }
  4558. c.ServeSuccessJSON(map[string]interface{}{
  4559. "total": total,
  4560. "patients": patients,
  4561. "information": information,
  4562. })
  4563. }
  4564. }
  4565. func (c *PatientApiController) PostIsOpenRemind() {
  4566. patient_id, _ := c.GetInt64("id", 1)
  4567. is_open_remind, _ := c.GetInt64("is_open_remind", 1)
  4568. adminUserInfo := c.GetAdminUserInfo()
  4569. err := service.UpdatePatientRemindStatus(patient_id, is_open_remind, adminUserInfo.CurrentOrgId)
  4570. if err == nil {
  4571. c.ServeSuccessJSON(map[string]interface{}{
  4572. "msg": "成功",
  4573. "is_open_remind": is_open_remind,
  4574. })
  4575. } else if err != nil {
  4576. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4577. }
  4578. }
  4579. func (c *PatientApiController) GetPatientScheduleOne() {
  4580. id, _ := c.GetInt64("id")
  4581. //查询该病人是否当天是排班
  4582. nowDateTime := time.Now()
  4583. nowDate := nowDateTime.Format("2006-01-02")
  4584. nowDate += " 00:00:00"
  4585. timeLayout := "2006-01-02"
  4586. loc, _ := time.LoadLocation("Local")
  4587. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", nowDate, loc)
  4588. nowdate := theTime.Unix()
  4589. fmt.Println("nowdate", nowdate)
  4590. adminUser := c.GetAdminUserInfo()
  4591. orgId := adminUser.CurrentOrgId
  4592. fmt.Println("orgid", orgId)
  4593. scheduls, err := service.GetPatientScheduleOne(id, nowdate, orgId)
  4594. if err != nil {
  4595. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4596. return
  4597. }
  4598. c.ServeSuccessJSON(map[string]interface{}{
  4599. "scheduls": scheduls,
  4600. })
  4601. }
  4602. func (c *PatientApiController) ExportPatients() {
  4603. dataBody := make(map[string]interface{}, 0)
  4604. all_patient, _, _ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId)
  4605. //all_patient, _,_ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId )
  4606. org, _ := service.GetOrgById(c.GetAdminUserInfo().CurrentOrgId)
  4607. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4608. if err != nil {
  4609. utils.ErrorLog(err.Error())
  4610. return
  4611. }
  4612. utils.ErrorLog("%v", dataBody)
  4613. export_time := time.Now().Unix()
  4614. var patients []*models.Patients
  4615. var total_patients []interface{}
  4616. if dataBody["patients"] != nil || reflect.TypeOf(dataBody["patients"]).String() == "[]interface {}" {
  4617. tempPatients := dataBody["patients"].([]interface{})
  4618. total_patients = tempPatients
  4619. for index, patientMap := range tempPatients {
  4620. patientNameM := patientMap.(map[string]interface{})
  4621. var patient models.Patients
  4622. if patientNameM["name"] == nil || reflect.TypeOf(patientNameM["name"]).String() != "string" {
  4623. utils.ErrorLog("name")
  4624. return
  4625. }
  4626. name, _ := patientNameM["name"].(string)
  4627. if len(name) == 0 { //名字为空则生成一条导入错误日志
  4628. err_log := models.ExportErrLog{
  4629. LogType: 1,
  4630. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4631. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的姓名不能为空",
  4632. Status: 1,
  4633. CreateTime: time.Now().Unix(),
  4634. UpdateTime: time.Now().Unix(),
  4635. ExportTime: export_time,
  4636. }
  4637. service.CreateExportErrLog(&err_log)
  4638. continue
  4639. }
  4640. patient.Name = name
  4641. if patientNameM["gender"] != nil || reflect.TypeOf(patientNameM["gender"]).String() == "string" {
  4642. gender, _ := strconv.ParseInt(patientNameM["gender"].(string), 10, 64)
  4643. if gender == 0 { //性别不符合要求则生成一条导入错误日志
  4644. err_log := models.ExportErrLog{
  4645. LogType: 1,
  4646. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4647. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的性别不符合要求",
  4648. Status: 1,
  4649. CreateTime: time.Now().Unix(),
  4650. UpdateTime: time.Now().Unix(),
  4651. ExportTime: export_time,
  4652. }
  4653. service.CreateExportErrLog(&err_log)
  4654. continue
  4655. } else {
  4656. patient.Gender = gender
  4657. }
  4658. }
  4659. if patientNameM["phone"] != nil || reflect.TypeOf(patientNameM["phone"]).String() == "string" {
  4660. phone, _ := patientNameM["phone"].(string)
  4661. if utils.CellPhoneRegexp().MatchString(phone) == false { //手机号码不符合要求则生成一条导入错误日志
  4662. if len(phone) == 0 {
  4663. err_log := models.ExportErrLog{
  4664. LogType: 1,
  4665. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4666. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码不能为空",
  4667. Status: 1,
  4668. CreateTime: time.Now().Unix(),
  4669. UpdateTime: time.Now().Unix(),
  4670. ExportTime: export_time,
  4671. }
  4672. service.CreateExportErrLog(&err_log)
  4673. continue
  4674. } else {
  4675. err_log := models.ExportErrLog{
  4676. LogType: 1,
  4677. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4678. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码格式不符合要求",
  4679. Status: 1,
  4680. CreateTime: time.Now().Unix(),
  4681. UpdateTime: time.Now().Unix(),
  4682. ExportTime: export_time,
  4683. }
  4684. service.CreateExportErrLog(&err_log)
  4685. continue
  4686. }
  4687. } else {
  4688. //var tempPatient *models.Patients
  4689. //for _, item := range all_patient {
  4690. // if item.Phone == phone {
  4691. // tempPatient = item
  4692. // }
  4693. //}
  4694. //需要判断该号码是否已经在系统内存在了,存在了则生成一条导入错误日志
  4695. count := service.FindPatientPhoneIsExist(phone, c.GetAdminUserInfo().CurrentOrgId)
  4696. if count >= 1 {
  4697. err_log := models.ExportErrLog{
  4698. LogType: 1,
  4699. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4700. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码在系统中已经存在",
  4701. Status: 1,
  4702. CreateTime: time.Now().Unix(),
  4703. UpdateTime: time.Now().Unix(),
  4704. ExportTime: export_time,
  4705. }
  4706. service.CreateExportErrLog(&err_log)
  4707. continue
  4708. }
  4709. patient.Phone = phone
  4710. }
  4711. }
  4712. if patientNameM["id_card_no"] != nil || reflect.TypeOf(patientNameM["id_card_no"]).String() == "string" {
  4713. id_card_no, _ := patientNameM["id_card_no"].(string)
  4714. if IsIdCard(id_card_no) == false { //身份证号码不符合要求则生成一条导入错误日志
  4715. if len(id_card_no) == 0 {
  4716. err_log := models.ExportErrLog{
  4717. LogType: 1,
  4718. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4719. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码不能为空",
  4720. Status: 1,
  4721. CreateTime: time.Now().Unix(),
  4722. UpdateTime: time.Now().Unix(),
  4723. ExportTime: export_time,
  4724. }
  4725. service.CreateExportErrLog(&err_log)
  4726. continue
  4727. } else {
  4728. err_log := models.ExportErrLog{
  4729. LogType: 1,
  4730. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4731. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码格式不符合要求",
  4732. Status: 1,
  4733. CreateTime: time.Now().Unix(),
  4734. UpdateTime: time.Now().Unix(),
  4735. ExportTime: export_time,
  4736. }
  4737. service.CreateExportErrLog(&err_log)
  4738. continue
  4739. }
  4740. } else {
  4741. //var tempPatient *models.Patients
  4742. //for _, item := range all_patient {
  4743. // if item.IdCardNo == id_card_no {
  4744. // tempPatient = item
  4745. // }
  4746. //}
  4747. count := service.FindPatientIdCardNoIsExist(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  4748. if count >= 1 {
  4749. //if tempPatient != nil && tempPatient.ID > 0 {
  4750. err_log := models.ExportErrLog{
  4751. LogType: 1,
  4752. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4753. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码在系统中已经存在",
  4754. Status: 1,
  4755. CreateTime: time.Now().Unix(),
  4756. UpdateTime: time.Now().Unix(),
  4757. ExportTime: export_time,
  4758. }
  4759. service.CreateExportErrLog(&err_log)
  4760. continue
  4761. }
  4762. //}
  4763. patient.IdCardNo = id_card_no
  4764. //patient.Birthday = GetBirthDay(id_card_no).Unix()
  4765. if GetBirthDay(id_card_no) == nil {
  4766. patient.Birthday = 0
  4767. } else {
  4768. patient.Birthday = GetBirthDay(id_card_no).Unix()
  4769. }
  4770. }
  4771. }
  4772. fmt.Println("111112222")
  4773. if patientNameM["first_treatment_date"] != nil || reflect.TypeOf(patientNameM["first_treatment_date"]).String() == "string" {
  4774. first_treatment_date, _ := patientNameM["first_treatment_date"].(string)
  4775. timeLayout := "2006/01/02"
  4776. loc, _ := time.LoadLocation("Local")
  4777. first_dialysis_date, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
  4778. if err != nil { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
  4779. if len(first_treatment_date) == 0 {
  4780. err_log := models.ExportErrLog{
  4781. LogType: 1,
  4782. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4783. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间不能为空",
  4784. Status: 1,
  4785. CreateTime: time.Now().Unix(),
  4786. UpdateTime: time.Now().Unix(),
  4787. ExportTime: export_time,
  4788. }
  4789. service.CreateExportErrLog(&err_log)
  4790. continue
  4791. } else {
  4792. err_log := models.ExportErrLog{
  4793. LogType: 1,
  4794. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4795. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间格式不符合要求",
  4796. Status: 1,
  4797. CreateTime: time.Now().Unix(),
  4798. UpdateTime: time.Now().Unix(),
  4799. ExportTime: export_time,
  4800. }
  4801. service.CreateExportErrLog(&err_log)
  4802. continue
  4803. }
  4804. } else {
  4805. if len(first_treatment_date) == 0 {
  4806. err_log := models.ExportErrLog{
  4807. LogType: 1,
  4808. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4809. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间不能为空",
  4810. Status: 1,
  4811. CreateTime: time.Now().Unix(),
  4812. UpdateTime: time.Now().Unix(),
  4813. ExportTime: export_time,
  4814. }
  4815. service.CreateExportErrLog(&err_log)
  4816. continue
  4817. } else {
  4818. if first_dialysis_date.Unix() == 0 { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
  4819. err_log := models.ExportErrLog{
  4820. LogType: 1,
  4821. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4822. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间格式不符合要求",
  4823. Status: 1,
  4824. CreateTime: time.Now().Unix(),
  4825. UpdateTime: time.Now().Unix(),
  4826. ExportTime: export_time,
  4827. }
  4828. service.CreateExportErrLog(&err_log)
  4829. continue
  4830. } else {
  4831. patient.FirstDialysisDate = first_dialysis_date.Unix()
  4832. }
  4833. }
  4834. }
  4835. }
  4836. if patientNameM["source"] != nil || reflect.TypeOf(patientNameM["source"]).String() == "string" {
  4837. source, _ := strconv.ParseInt(patientNameM["source"].(string), 10, 64)
  4838. if source == 0 { //患者来源不符合要求则生成一条导入错误日志
  4839. err_log := models.ExportErrLog{
  4840. LogType: 1,
  4841. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4842. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的患者来源不符合要求",
  4843. Status: 1,
  4844. CreateTime: time.Now().Unix(),
  4845. UpdateTime: time.Now().Unix(),
  4846. ExportTime: export_time,
  4847. }
  4848. service.CreateExportErrLog(&err_log)
  4849. continue
  4850. } else if source == 3 {
  4851. err_log := models.ExportErrLog{
  4852. LogType: 1,
  4853. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4854. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的患者来源不能为空",
  4855. Status: 1,
  4856. CreateTime: time.Now().Unix(),
  4857. UpdateTime: time.Now().Unix(),
  4858. ExportTime: export_time,
  4859. }
  4860. service.CreateExportErrLog(&err_log)
  4861. continue
  4862. } else {
  4863. patient.Source = source
  4864. }
  4865. }
  4866. if patientNameM["lapseto"] != nil || reflect.TypeOf(patientNameM["lapseto"]).String() == "string" {
  4867. lapseto, _ := strconv.ParseInt(patientNameM["lapseto"].(string), 10, 64)
  4868. if lapseto == 0 { //治疗状态不符合要求则生成一条导入错误日志
  4869. err_log := models.ExportErrLog{
  4870. LogType: 1,
  4871. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4872. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的治疗状态不符合要求",
  4873. Status: 1,
  4874. CreateTime: time.Now().Unix(),
  4875. UpdateTime: time.Now().Unix(),
  4876. ExportTime: export_time,
  4877. }
  4878. service.CreateExportErrLog(&err_log)
  4879. continue
  4880. } else if lapseto == 3 {
  4881. err_log := models.ExportErrLog{
  4882. LogType: 1,
  4883. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4884. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的治疗状态不能为空",
  4885. Status: 1,
  4886. CreateTime: time.Now().Unix(),
  4887. UpdateTime: time.Now().Unix(),
  4888. ExportTime: export_time,
  4889. }
  4890. service.CreateExportErrLog(&err_log)
  4891. continue
  4892. } else {
  4893. patient.Lapseto = lapseto
  4894. }
  4895. }
  4896. if patientNameM["is_infectious"] != nil || reflect.TypeOf(patientNameM["is_infectious"]).String() == "string" {
  4897. is_infectious, _ := strconv.ParseInt(patientNameM["is_infectious"].(string), 10, 64)
  4898. if is_infectious == 0 { //传染病不符合要求则生成一条导入错误日志
  4899. err_log := models.ExportErrLog{
  4900. LogType: 1,
  4901. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4902. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的传染病状态不符合要求",
  4903. Status: 1,
  4904. CreateTime: time.Now().Unix(),
  4905. UpdateTime: time.Now().Unix(),
  4906. ExportTime: export_time,
  4907. }
  4908. service.CreateExportErrLog(&err_log)
  4909. continue
  4910. } else if is_infectious == 3 {
  4911. err_log := models.ExportErrLog{
  4912. LogType: 1,
  4913. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4914. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的传染病状态不能为空",
  4915. Status: 1,
  4916. CreateTime: time.Now().Unix(),
  4917. UpdateTime: time.Now().Unix(),
  4918. ExportTime: export_time,
  4919. }
  4920. service.CreateExportErrLog(&err_log)
  4921. continue
  4922. } else {
  4923. patient.IsInfectious = is_infectious
  4924. }
  4925. }
  4926. if patientNameM["contagions"] != nil && reflect.TypeOf(patientNameM["contagions"]).String() == "[]interface {}" {
  4927. var contagions []int64
  4928. thisContagions, _ := patientNameM["contagions"].([]interface{})
  4929. if len(thisContagions) > 0 {
  4930. for _, item := range thisContagions {
  4931. if reflect.TypeOf(item).String() != "float64" {
  4932. continue
  4933. }
  4934. contagion := int64(item.(float64))
  4935. if contagion > 0 {
  4936. contagions = append(contagions, contagion)
  4937. }
  4938. }
  4939. }
  4940. patient.ContagionIds = contagions
  4941. }
  4942. if patientNameM["diagnose"] != nil || reflect.TypeOf(patientNameM["diagnose"]).String() == "string" {
  4943. diagnose, _ := patientNameM["diagnose"].(string)
  4944. patient.Diagnose = diagnose
  4945. }
  4946. if patientNameM["dialysis_no"] != nil || reflect.TypeOf(patientNameM["dialysis_no"]).String() == "string" {
  4947. dialysis_no, _ := patientNameM["dialysis_no"].(string)
  4948. var tempPatient *models.Patients
  4949. for _, item := range all_patient {
  4950. if item.DialysisNo == dialysis_no {
  4951. tempPatient = item
  4952. }
  4953. }
  4954. if tempPatient != nil && tempPatient.ID > 0 {
  4955. patient.DialysisNo = GenerateDialysisNoTwo(patients)
  4956. } else {
  4957. patient.DialysisNo = dialysis_no
  4958. }
  4959. }
  4960. if patientNameM["height"] != nil || reflect.TypeOf(patientNameM["height"]).String() == "string" {
  4961. height, _ := patientNameM["height"].(string)
  4962. heights, _ := strconv.ParseFloat(height, 64)
  4963. patient.Height = int64(heights)
  4964. }
  4965. if patientNameM["home_address"] != nil || reflect.TypeOf(patientNameM["home_address"]).String() == "string" {
  4966. home_address, _ := patientNameM["home_address"].(string)
  4967. patient.HomeAddress = home_address
  4968. }
  4969. if patientNameM["dry_weight"] != nil || reflect.TypeOf(patientNameM["dry_weight"]).String() == "string" {
  4970. dry_weight, _ := patientNameM["dry_weight"].(string)
  4971. dry_weights, _ := strconv.ParseFloat(dry_weight, 64)
  4972. patient.DryWeight = dry_weights
  4973. }
  4974. patient.CreatedTime = time.Now().Unix()
  4975. patient.UpdatedTime = time.Now().Unix()
  4976. patient.Status = 1
  4977. patient.Avatar = "https://images.shengws.com/201809182128111.png"
  4978. patient.UserOrgId = c.GetAdminUserInfo().CurrentOrgId
  4979. patient.IsExcelExport = 1
  4980. patient.PatientType = 1
  4981. patients = append(patients, &patient)
  4982. }
  4983. }
  4984. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  4985. if len(patients) > 0 {
  4986. for _, item := range patients {
  4987. service.CreateExportPatient(item, item.ContagionIds, org.Creator)
  4988. }
  4989. log := models.ExportLog{
  4990. LogType: 1,
  4991. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4992. TotalNum: int64(len(total_patients)),
  4993. FailNum: int64(len(errLogs)),
  4994. SuccessNum: int64(len(patients)),
  4995. CreateTime: time.Now().Unix(),
  4996. UpdateTime: time.Now().Unix(),
  4997. ExportTime: export_time,
  4998. Status: 1,
  4999. }
  5000. service.CreateExportLog(&log)
  5001. c.ServeSuccessJSON(map[string]interface{}{
  5002. "msg": "导入成功",
  5003. "total_num": len(total_patients),
  5004. "success_num": len(patients),
  5005. "fail_num": int64(len(errLogs)),
  5006. })
  5007. } else {
  5008. log := models.ExportLog{
  5009. LogType: 1,
  5010. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5011. TotalNum: int64(len(total_patients)),
  5012. FailNum: int64(len(errLogs)),
  5013. SuccessNum: int64(len(patients)),
  5014. CreateTime: time.Now().Unix(),
  5015. UpdateTime: time.Now().Unix(),
  5016. ExportTime: export_time,
  5017. Status: 1,
  5018. }
  5019. service.CreateExportLog(&log)
  5020. c.ServeSuccessJSON(map[string]interface{}{
  5021. "msg": "导入成功",
  5022. "total_num": len(total_patients),
  5023. "success_num": len(patients),
  5024. "fail_num": int64(len(errLogs)),
  5025. })
  5026. }
  5027. }
  5028. func GetBirthDay(IDCardNo string) *time.Time {
  5029. dayStr := IDCardNo[6:14]
  5030. birthDay, err := time.Parse("20060102", dayStr)
  5031. if err != nil {
  5032. fmt.Println(err)
  5033. return nil
  5034. }
  5035. return &birthDay
  5036. }
  5037. func IsIdCard(id string) (res bool) {
  5038. id = strings.ToUpper(id)
  5039. if len(id) != 15 && len(id) != 18 {
  5040. fmt.Println("1111111")
  5041. return false
  5042. }
  5043. r := regexp.MustCompile("(\\d{15})|(\\d{17}([0-9]|X))")
  5044. if !r.MatchString(id) {
  5045. fmt.Println("222222")
  5046. return false
  5047. }
  5048. if len(id) == 15 {
  5049. tm2, _ := time.Parse("01/02/2006", string([]byte(id)[8:10])+"/"+string([]byte(id)[10:12])+"/"+"19"+string([]byte(id)[6:8]))
  5050. if tm2.Unix() == 0 {
  5051. fmt.Println("44444443333")
  5052. return false
  5053. }
  5054. return true
  5055. } else {
  5056. tm2, _ := time.Parse("01/02/2006", string([]byte(id)[10:12])+"/"+string([]byte(id)[12:14])+"/"+string([]byte(id)[6:10]))
  5057. fmt.Println(string([]byte(id)[10:12]) + "/" + string([]byte(id)[12:14]) + "/" + string([]byte(id)[6:10]))
  5058. fmt.Println(tm2.Unix())
  5059. if tm2.Unix() == 0 {
  5060. fmt.Println("44445555555")
  5061. return false
  5062. }
  5063. //检验18位身份证的校验码是否正确。
  5064. //校验位按照ISO 7064:1983.MOD 11-2的规定生成,X可以认为是数字10。
  5065. arr_int := []int{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2}
  5066. arr_ch := []string{"1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"}
  5067. sign := 0
  5068. for k, v := range arr_int {
  5069. int_temp, _ := strconv.Atoi(string([]byte(id)[k : k+1]))
  5070. sign += int_temp * v
  5071. }
  5072. n := sign % 11
  5073. val_num := arr_ch[n]
  5074. if val_num != string([]byte(id)[17:18]) {
  5075. fmt.Println("5556666666")
  5076. return false
  5077. }
  5078. return true
  5079. }
  5080. }
  5081. func (c *PatientApiController) SaveEditAdvices() {
  5082. adminInfo := c.GetAdminUserInfo()
  5083. orgid := adminInfo.CurrentOrgId
  5084. startTime := c.GetString("start_time")
  5085. theTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", startTime)
  5086. groupno, _ := c.GetInt64("groupno")
  5087. fmt.Println("组", groupno)
  5088. date, _ := c.GetInt64("date")
  5089. fmt.Println("date", date)
  5090. patient_id, _ := c.GetInt64("patient_id")
  5091. fmt.Println("paitent_id", patient_id)
  5092. advice := models.XtDoctorAdvice{
  5093. StartTime: theTime.Unix(),
  5094. }
  5095. err := service.UpdateDoctorEditAdvice(advice, orgid, groupno, date, patient_id)
  5096. key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(date, 10) + ":doctor_advices"
  5097. redis := service.RedisClient()
  5098. redis.Set(key, "", time.Second)
  5099. keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(date, 10) + ":advice_list_all"
  5100. redis.Set(keyOne, "", time.Second)
  5101. scheduleTime := theTime.Format("2006-01-02")
  5102. keyFour := "scheduals_" + scheduleTime + "_" + strconv.FormatInt(orgid, 10)
  5103. fmt.Println("keyFour323223323232323232", keyFour)
  5104. redis.Set(keyFour, "", time.Second)
  5105. defer redis.Close()
  5106. if err != nil {
  5107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5108. return
  5109. }
  5110. c.ServeSuccessJSON(map[string]interface{}{
  5111. "advice": advice,
  5112. })
  5113. }
  5114. func (c *PatientApiController) GetMaxDialysisNo() {
  5115. dialysisNo := service.ChechLastDialysisNo(c.GetAdminUserInfo().CurrentOrgId)
  5116. c.ServeSuccessJSON(map[string]interface{}{
  5117. "dialysis_no": dialysisNo,
  5118. })
  5119. }
  5120. func GenerateDialysisNoTwo(patients []*models.Patients) string {
  5121. dialysisNo2 := fmt.Sprintf("%06v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(1000000))
  5122. var tempPatient *models.Patients
  5123. for _, item := range patients {
  5124. if item.DialysisNo == dialysisNo2 {
  5125. tempPatient = item
  5126. }
  5127. }
  5128. if tempPatient == nil || tempPatient.ID == 0 {
  5129. return dialysisNo2
  5130. }
  5131. return GenerateDialysisNoTwo(patients)
  5132. }
  5133. func (c *PatientApiController) GetBanner() {
  5134. orgId := c.GetAdminUserInfo().CurrentOrgId
  5135. _, errcodes := service.GetOrgFollowIsExist(orgId)
  5136. if errcodes == gorm.ErrRecordNotFound {
  5137. information, err := service.GetAdminUserRoleInformation(0)
  5138. if err != nil {
  5139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5140. return
  5141. }
  5142. c.ServeSuccessJSON(map[string]interface{}{
  5143. "information": information,
  5144. })
  5145. } else if errcodes == nil {
  5146. information, err := service.GetAdminUserRoleInformation(orgId)
  5147. if err != nil {
  5148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5149. return
  5150. }
  5151. c.ServeSuccessJSON(map[string]interface{}{
  5152. "information": information,
  5153. })
  5154. }
  5155. }
  5156. func (c *PatientApiController) GetPatientDialysisLongSolution() {
  5157. patient_id, _ := c.GetInt64("id", 0)
  5158. page, _ := c.GetInt64("page", 0)
  5159. limit, _ := c.GetInt64("limit", 0)
  5160. if patient_id <= 0 {
  5161. c.ServeSuccessJSON(map[string]interface{}{
  5162. "solutions": nil,
  5163. })
  5164. return
  5165. }
  5166. if page <= 0 {
  5167. page = 1
  5168. }
  5169. if limit <= 0 {
  5170. limit = 10
  5171. }
  5172. adminUserInfo := c.GetAdminUserInfo()
  5173. //获取该患者分组的透析模式
  5174. list, _ := service.GetPatientSolutionGroupList(patient_id, adminUserInfo.CurrentOrgId)
  5175. for _, item := range list {
  5176. //获取该模式最新的1条数据
  5177. solution, _ := service.GetNewPatientSolutionByModeId(patient_id, item.ModeId, adminUserInfo.CurrentOrgId)
  5178. //更新状态值
  5179. service.UpdateDialysisSolutionStatus(solution.ID, item.ModeId, adminUserInfo.CurrentOrgId, patient_id)
  5180. }
  5181. solution, total, err := service.GetPatientDialysisLongSolution(patient_id, page, limit, adminUserInfo.CurrentOrgId)
  5182. stockType, _ := service.GetStockType(adminUserInfo.CurrentOrgId)
  5183. if err != nil {
  5184. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5185. return
  5186. }
  5187. c.ServeSuccessJSON(map[string]interface{}{
  5188. "solutions": solution,
  5189. "total": total,
  5190. "stockType": stockType,
  5191. })
  5192. }
  5193. func (c *PatientApiController) GetDialysisSolutionDetailList() {
  5194. patient_id, _ := c.GetInt64("patient_id")
  5195. mode_id, _ := c.GetInt64("mode_id")
  5196. page, _ := c.GetInt64("page")
  5197. limit, _ := c.GetInt64("limit")
  5198. orgId := c.GetAdminUserInfo().CurrentOrgId
  5199. list, total, err := service.GetDialysisSolutionDetailList(orgId, patient_id, mode_id, page, limit)
  5200. if err != nil {
  5201. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5202. return
  5203. }
  5204. c.ServeSuccessJSON(map[string]interface{}{
  5205. "list": list,
  5206. "total": total,
  5207. })
  5208. }