patient_api_controller.go 257KB

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