patient_api_controller.go 205KB

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