123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699 |
- package controllers
-
- import (
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "encoding/json"
- "fmt"
- "github.com/astaxie/beego"
- "github.com/jinzhu/gorm"
- "github.com/shopspring/decimal"
- "math/rand"
- "reflect"
- "strconv"
- "strings"
- "syscall"
- "time"
- "unsafe"
- )
-
- type HisApiController struct {
- BaseAuthAPIController
- }
-
- func HisManagerApiRegistRouters() {
-
- beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
- beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
- beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
- beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
- beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
- beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
- beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
- beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
- beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
- beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
- beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
- beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
- beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
- beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
- beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
- beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
- beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
- beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
- beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
- beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
- beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
- beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
- beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
- beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
- beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
-
- //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
- //新增附加费用
- //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
- //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
- beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
- beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
- beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
- beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
- beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
- beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
- beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
- beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
- beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
- beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
- beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
- beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
- beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
-
- beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
- //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
- beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
-
- beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
-
- beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
-
- beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
-
- beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
-
- beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
-
- beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
- beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
-
- beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
-
- beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
- beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
- beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
-
- beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
-
- beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
-
- }
-
- func (c *PublicApiController) GetBaiLinExportData() {
- data := service.GetBaiLinOrderData()
- fmt.Println(len(data))
- var new_data []*models.NewCustomHisOrder
- for _, item := range data {
- if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
- new_data = append(new_data, item)
- }
-
- }
- fmt.Println(len(new_data))
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": new_data,
- })
- }
-
- func (c *HisApiController) GetHisUnChargePatientList() {
- record_date := c.GetString("record_date")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDateTime := theTime.Unix()
- adminInfo := c.GetAdminUserInfo()
- var tempPatients []*service.NewTempPatients
- //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
- tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
- var patients []*service.NewTempPatients
- var patients_two []*service.NewTempPatients
-
- for _, item := range tempPatients {
- //过滤掉没挂号的和没开处方的
- if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
- patients = append(patients, item)
- }
-
- //过滤掉没挂号的
- if len(item.HisPatient) > 0 {
- patients_two = append(patients_two, item)
- }
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "list": patients,
- "list_two": patients_two,
- })
- }
-
- func (c *HisApiController) GetPrivateExpensesOrder() {
- //id, _ := c.GetInt64("id")
- //record_time := c.GetString("record_time")
- order_id, _ := c.GetInt64("order_id")
- admin_user_id, _ := c.GetInt64("admin_user_id")
-
- //timeLayout := "2006-01-02"
- //loc, _ := time.LoadLocation("Local")
- //
- //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
- //if err != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- //}
- //recordDateTime := theTime.Unix()
- adminUser := c.GetAdminUserInfo()
- order, _ := service.GetHisOrderByID(order_id)
-
- his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
- his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
-
- orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
- miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
-
- //var config []*models.HisXtDiagnoseConfig
-
- var name string
- if order.PType == 1 {
- diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
- for _, item := range diagnosis_ids {
- id, _ := strconv.ParseInt(item, 10, 64)
- diagnosisConfig, _ := service.FindDiagnoseById(id)
- if len(name) == 0 {
- name = diagnosisConfig.ClassName
-
- } else {
- name = name + "," + diagnosisConfig.ClassName
- }
- }
- } else {
- diagnosis_ids := strings.Split(his.Diagnosis, ",")
-
- for _, item := range diagnosis_ids {
- id, _ := strconv.ParseInt(item, 10, 64)
- diagnosisConfig, _ := service.FindDiagnoseById(id)
- if len(name) == 0 {
- name = diagnosisConfig.ClassName
-
- } else {
- name = name + "," + diagnosisConfig.ClassName
- }
- }
- }
-
- var bedCostTotal float64 = 0 //床位总费
- //var bedCostSelfTotal float64 = 0 //床位自费
- var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
-
- var operationCostTotal float64 = 0 //手术费
- //var operationCostSelfTotal float64 = 0 //手术费
- var operationCostPartSelfTotal float64 = 0 //手术费
-
- var otherCostTotal float64 = 0 //其他费用
- //var otherCostSelfTotal float64 = 0 //其他费用
- var otherCostPartSelfTotal float64 = 0 //其他费用
-
- var materialCostTotal float64 = 0 //材料费
- //var materialCostSelfTotal float64 = 0 //材料费
- var materialCostPartSelfTotal float64 = 0 //材料费
-
- var westernMedicineCostTotal float64 = 0 //西药费
- //var westernMedicineCostSelfTotal float64 = 0 //西药费
- var westernMedicineCostPartSelfTotal float64 = 0 //西药费
-
- var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
- //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
- var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
-
- var checkCostTotal float64 = 0 //检查费
- //var checkCostSelfTotal float64 = 0 //检查费
- var checkCostPartSelfTotal float64 = 0 //检查费
-
- var laboratoryCostTotal float64 = 0 //化验费
- //var laboratoryCostSelfTotal float64 = 0 //化验费
- var laboratoryCostPartSelfTotal float64 = 0 //化验费
-
- var treatCostTotal float64 = 0 //治疗费用
- //var treatCostSelfTotal float64 = 0 //治疗费用
- var treatCostPartSelfTotal float64 = 0 //治疗费用
-
- var zhenChaCostTotal float64 = 0 //其他费用
- //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
-
- decimal.DivisionPrecision = 2
-
- for _, item := range orderInfos {
- item.FulamtOwnpayAmt = item.DetItemFeeSumamt
- if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
- item.MedChrgitmType = "09"
- }
- if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
- if item.HisPrescriptionProject.Type == 2 {
- if c.GetAdminUserInfo().CurrentOrgId == 10215 {
- fmt.Println("CostClassify")
- fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
- switch item.HisPrescriptionProject.VMHisProject.CostClassify {
- case 0:
- item.MedChrgitmType = "0"
- break
- case 1:
- item.MedChrgitmType = "14"
- break
- case 2:
- item.MedChrgitmType = "05"
-
- break
- case 3:
- item.MedChrgitmType = "03"
-
- break
- case 4:
- item.MedChrgitmType = "03"
-
- break
- case 5:
- item.MedChrgitmType = "08"
-
- break
- case 6:
- item.MedChrgitmType = "14"
-
- break
- case 7:
- item.MedChrgitmType = "14"
-
- break
- case 8:
- item.MedChrgitmType = "03"
- break
- case 9:
- item.MedChrgitmType = "14"
- break
- case 10:
- item.MedChrgitmType = "14"
- break
- case 11:
- item.MedChrgitmType = "06"
- break
- case 12:
- item.MedChrgitmType = "12"
- break
- case 13:
- item.MedChrgitmType = "01"
- break
- case 14:
- item.MedChrgitmType = "04"
- break
- case 15:
- item.MedChrgitmType = "14"
- break
-
- }
-
- } else {
- switch item.HisPrescriptionProject.VMHisProject.CostClassify {
- case 1:
- item.MedChrgitmType = "14"
- break
- case 2:
- item.MedChrgitmType = "05"
-
- break
- case 3:
- item.MedChrgitmType = "04"
-
- break
- case 4:
- item.MedChrgitmType = "14"
-
- break
- case 5:
- item.MedChrgitmType = "08"
-
- break
- case 6:
- item.MedChrgitmType = "14"
- break
- case 7:
- item.MedChrgitmType = "14"
- break
- case 8:
- item.MedChrgitmType = "03"
- break
- case 9:
- item.MedChrgitmType = "14"
- break
- }
- }
- } else if item.HisPrescriptionProject.Type == 3 {
- item.MedChrgitmType = "08"
- }
- }
- }
-
- order.PsnCashPay = order.MedfeeSumamt
-
- for _, item := range orderInfos {
- if item.MedChrgitmType == "01" { //床位费
- bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
- if item.MedChrgitmType == "02" { //诊察费
- zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //zhenChaCostSelfTotal = zhenChaCostTotal
- }
-
- if item.MedChrgitmType == "03" { //检查费
- checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "02" { //检查费
- checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "04" { //化验费
- laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
- treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "06" { //手术费
- operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "08" { //材料费
- materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "09" { //西药费
- westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "11" { //中成费
- chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
- otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
- }
-
- org, _ := service.GetOrgById(adminUser.CurrentOrgId)
- printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
- charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
-
- patient, _ := service.GetPatientByID(order.UserOrgId, order.PatientId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "patient": patient,
- "order_infos": orderInfos,
- "diagnosis": name,
- "bedCostTotal": bedCostTotal,
- "bedCostSelfTotal": bedCostTotal,
- "bedCostPartSelfTotal": bedCostPartSelfTotal,
- "operationCostTotal": operationCostTotal,
- "operationCostSelfTotal": operationCostTotal,
- "operationCostPartSelfTotal": operationCostPartSelfTotal,
- "otherCostTotal": otherCostTotal,
- "otherCostSelfTotal": otherCostTotal,
- "otherCostPartSelfTotal": otherCostPartSelfTotal,
- "materialCostTotal": materialCostTotal,
- "materialCostSelfTotal": materialCostTotal,
- "materialCostPartSelfTotal": materialCostPartSelfTotal,
- "westernMedicineCostTotal": westernMedicineCostTotal,
- "westernMedicineCostSelfTotal": westernMedicineCostTotal,
- "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
- "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
- "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
- "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
- "checkCostTotal": checkCostTotal,
- "checkCostSelfTotal": checkCostTotal,
- "zhenChaCostTotal": zhenChaCostTotal,
- "zhenChaCostSelfTotal": zhenChaCostTotal,
- "checkCostPartSelfTotal": checkCostPartSelfTotal,
- "laboratoryCostTotal": laboratoryCostTotal,
- "laboratoryCostSelfTotal": laboratoryCostTotal,
- "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
- "treatCostTotal": treatCostTotal,
- "treatCostSelfTotal": treatCostTotal,
- "treatCostPartSelfTotal": treatCostPartSelfTotal,
- "charge_admin": charge_admin,
- "printor_admin": printor_admin,
- "org_name": org.OrgName,
- "org_code": miConfig.Code,
- "name": patient.Name,
- "number": order.MdtrtId,
- "date": order.SettleAccountsDate,
- "info": order,
- "his_hospital": his_hospital,
- "his": his,
- })
-
- }
-
- func (c *HisApiController) RefudDetail() {
- order_id, _ := c.GetInt64("order_id")
- order, _ := service.GetHisOrderByID(order_id)
- adminUser := c.GetAdminUserInfo()
- service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "撤销成功",
- })
- }
-
- func (c *HisApiController) Sscard() {
- //r := CardInit()
- //if r == 0 {
- // GetBaseInfo()
- //}
- //c.ServeSuccessJSON(map[string]interface{}{
- // "list": "11",
- //})
-
- }
-
- func GetBaseInfo() error {
- //handle := syscall.MustLoadDLL("SSCard.dll")
- //ReadCardBas := handle.MustFindProc("ReadCardBas")
- //
- //str := make([]byte, 256)
- //str1 := make([]byte, 256)
- //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
- //if ferr != nil {
- // fmt.Println("ReadCardBas 报错", ferr.Error())
- // return ferr
- //}
- //
- //fmt.Println(string(str))
- //
- //fmt.Println(r)
- return nil
- }
-
- func CardInit() int {
- //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
- //add := DllTestDef.MustFindProc("Init")
- //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
- //if err != nil {
- // fmt.Println("SSCard的运算结果为:", ret)
- //}
- //result := int(ret)
- return 0
- }
-
- func IntPtr(n int) uintptr {
- return uintptr(n)
- }
-
- func StrPtr(s string) uintptr {
- return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
- }
-
- func (c *HisApiController) GetHisPatientList() {
- //types, _ := c.GetInt64("type", 0)
- record_date := c.GetString("record_date")
- sch_type, _ := c.GetInt64("sch_type")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDateTime := theTime.Unix()
- adminInfo := c.GetAdminUserInfo()
- //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
- patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
- patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
- //获取当前用户的信息
- adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
- doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
- //获取所有科室信息
- department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": patients,
- "list_two": patients_two,
- "info": adminUserInfo,
- "doctors": doctors,
- "department": department,
- })
- }
-
- type CustomTemplate struct {
- ID int64 `gorm:"column:id" json:"id" form:"id"`
- UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
- RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
- PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
- Status int64 `gorm:"column:status" json:"status" form:"status"`
- Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
- Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
- Type int64 `gorm:"column:type" json:"type" form:"type"`
- Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
- Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
- PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
- PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
- HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
- HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
- MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
- }
-
- func (c *HisApiController) GetHisPatientInfo() {
- patient_id, _ := c.GetInt64("patient_id")
- his_patient_id, _ := c.GetInt64("his_patient_id")
- record_date := c.GetString("record_date")
- number := c.GetString("number")
- //start_time := c.GetString("start_time")
- //end_time := c.GetString("end_time")
- p_type, _ := c.GetInt64("p_type")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDateTime := theTime.Unix()
- //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- //if err != nil {
- //
- //}
- //startRecordDateTime := startTime.Unix()
- //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- //if err != nil {
- //
- //}
- //endRecordDateTime := endTime.Unix()
- admin := c.GetAdminUserInfo()
- his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
- //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
-
- xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
-
- count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
-
- var prescriptions []*models.HisPrescription
- var last_prescriptions []*models.HisPrescription
- var sch_prescriptions []CustomTemplate
- last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
- if p_type == 1 { //住院
- prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
- for _, item := range prescriptions {
- for _, subItem := range item.HisDoctorAdviceInfo {
- info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
- if info.RetailPrice > 0 {
- subItem.Drug.MinPrice = info.RetailPrice
- }
- }
- }
- last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
- } else { //门诊
- prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
- for _, item := range prescriptions {
- for _, subItem := range item.HisDoctorAdviceInfo {
- info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
- if info.RetailPrice > 0 {
- subItem.Drug.MinPrice = info.RetailPrice
- }
- }
- }
- last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
- }
-
- sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
- if sch.ID > 0 {
- var week string
- t := time.Now()
- switch t.Weekday().String() {
- case "Monday":
- week = "周一"
- break
- case "Tuesday":
- week = "周二"
-
- break
- case "Wednesday":
- week = "周三"
-
- break
- case "Thursday":
- week = "周四"
-
- break
- case "Friday":
- week = "周五"
-
- break
- case "Saturday":
- week = "周六"
-
- break
- case "Sunday":
- week = "周日"
-
- break
-
- }
-
- mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
- temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
-
- //根据推送频率组装新的数组
- for _, item := range temp_sch_prescriptions {
- var cus CustomTemplate
- cus.ID = item.ID
- cus.UserOrgId = item.UserOrgId
- cus.PatientId = item.PatientId
- cus.MedType = item.MedType
- cus.RecordDate = item.RecordDate
- cus.Type = item.Type
- cus.PType = item.PType
- for _, subItem := range item.HisPrescriptionAdviceTemplate {
- if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
- if subItem.FrequencyType == 1 { //每次必推
- cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
- }
-
- if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
- cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
- }
-
- if subItem.FrequencyType == 2 { //按照天数频率
- p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
- now := p.Unix()
- dayStr := strconv.FormatInt(subItem.DayCount, 10)
- dayStr2 := "-" + dayStr
- count, _ := strconv.ParseInt(dayStr2, 10, 64)
- oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
- advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
- if len(advices) == 0 {
- cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
- }
- }
- }
- }
-
- for _, subItem := range item.HisPrescriptionProjectTemplate {
-
- if subItem.Type == 2 {
- if subItem.XtHisProject.MedicalStatus != 1 {
- if subItem.FrequencyType == 1 {
- cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
- }
-
- if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
- cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
- }
-
- if subItem.FrequencyType == 2 {
- p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
- now := p.Unix()
- dayStr := strconv.FormatInt(subItem.DayCount, 10)
- dayStr2 := "-" + dayStr
- count, _ := strconv.ParseInt(dayStr2, 10, 64)
- oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
- projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
- if len(projects) == 0 {
- cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
- }
- }
-
- }
-
- } else if subItem.Type == 3 {
- if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
- if subItem.FrequencyType == 1 {
- cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
- }
-
- if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
- cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
- }
-
- if subItem.FrequencyType == 2 {
- p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
- now := p.Unix()
- dayStr := strconv.FormatInt(subItem.DayCount, 10)
- dayStr2 := "-" + dayStr
- count, _ := strconv.ParseInt(dayStr2, 10, 64)
- oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
- projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
- if len(projects) == 0 {
- cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
- }
- }
- }
- }
- }
- sch_prescriptions = append(sch_prescriptions, cus)
- }
-
- for _, item := range sch_prescriptions {
- if len(item.HisPrescriptionProjectTemplate) == 0 {
- item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
- }
- if len(item.HisPrescriptionAdviceTemplate) == 0 {
- item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
- }
-
- }
- }
- _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
- if config.ID > 0 && config.IsOpen == 1 {
- for _, item := range sch_prescriptions {
- for _, subItem := range item.HisPrescriptionAdviceTemplate {
- info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
- if info.RetailPrice > 0 {
- subItem.Drug.MinPrice = info.RetailPrice
- }
- }
- }
- }
-
- if config.ID > 0 && config.IsOpen == 1 {
- for _, item := range sch_prescriptions {
- for _, subItem := range item.HisPrescriptionProjectTemplate {
- if subItem.Type == 3 {
- info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
- if info.Price > 0 {
- subItem.GoodInfo.PackingPrice = info.Price
- }
- }
- }
- }
- }
-
- //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
- //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
- case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
- patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
- lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
-
- order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
- doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
-
- _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
-
- //获取所有科室信息
- department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "his_info": his_patient_info,
- "xt_info": xt_patient_info,
- "prescription": prescriptions,
- "case_history": case_history,
- "info": patientPrescriptionInfo,
- //"month_prescriptions": monthPrescriptions,
- "order": order,
- "doctors": doctors,
- "department": department,
- "sch_prescriptions": sch_prescriptions,
- "last_prescriptions": last_prescriptions,
- "schedule": sch,
- "count": count,
- "drugStockConfig": drugStockConfig,
- "last_info": lastPatientPrescriptionInfo,
- })
- return
-
- }
-
- func (c *HisApiController) GetHisPrescriptionConfig() {
- adminInfo := c.GetAdminUserInfo()
- //获取医嘱模版
- advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
-
- houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
- if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
- //获取所有基础药
- drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
- _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
- if config.ID > 0 && config.IsOpen == 1 {
- for _, item := range drugs {
- var index = 0
- for _, subItem := range item.OtherDrugWarehouseInfo {
- if index == 0 {
- index = index + 1
- if subItem.RetailPrice > 0 {
- item.MinPrice = subItem.RetailPrice
-
- }
- }
- }
- }
- }
-
- manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
- drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
- efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
- doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
- //获取所有科室信息
- department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
- //获取诊断信息
- sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
- diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
- additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "drugs": drugs,
- "advices_template": advices,
- "drugways": drugways,
- "efs": efs,
- "doctors": doctors,
- "department": department,
- "sick": sick,
- "additions": additions,
- "diagnose": diagnose,
- "manufacturers": manufacturers,
- })
- }
- if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
- //获取所有基础药
- drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
- _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
- if config.ID > 0 && config.IsOpen == 1 {
- for _, item := range drugs {
- var index = 0
- for _, subItem := range item.OtherDrugWarehouseInfo {
- if index == 0 {
- index = index + 1
- if subItem.RetailPrice > 0 {
- item.MinPrice = subItem.RetailPrice
- }
- }
- }
- }
- }
-
- manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
- drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
- efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
- doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
- //获取所有科室信息
- department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
- //获取诊断信息
- sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
- diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
- additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "drugs": drugs,
- "advices_template": advices,
- "drugways": drugways,
- "efs": efs,
- "doctors": doctors,
- "department": department,
- "sick": sick,
- "additions": additions,
- "diagnose": diagnose,
- "manufacturers": manufacturers,
- })
- }
- }
-
- func (c *HisApiController) CreateHisPrescription() {
- record_date := c.GetString("record_date")
- patient_id, _ := c.GetInt64("patient_id")
- reg_type, _ := c.GetInt64("reg_type")
- diagnose := c.GetString("diagnose")
- sick_type, _ := c.GetInt64("sick_type")
- sick_history := c.GetString("sick_history")
- doctor_id, _ := c.GetInt64("doctor", 0)
- department, _ := c.GetInt64("department", 0)
- his_patient_id, _ := c.GetInt64("his_patient_id")
-
- p_type, _ := c.GetInt64("p_type")
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adminInfo := c.GetAdminUserInfo()
- recordDateTime := theTime.Unix()
-
- //查询默认出库仓库库存
- storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
- role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
-
- if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
- lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
- if len(lists) == 1 {
- his_patient_id = lists[0].ID
- }
-
- }
-
- patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
-
- //保存处方出库
- _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
-
- //自动出库
- _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
-
- //耗材保存处方出库
- goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
-
- settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
-
- //已发药和已收费限制逻辑
- isMidicine := false
- isCharge := false
- if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
-
- prescriptions, _ := dataBody["prescriptions"].([]interface{})
- if len(prescriptions) > 0 {
- for _, item := range prescriptions {
- items := item.(map[string]interface{})
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- id := int64(items["id"].(float64))
- if id > 0 {
- new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
- if err != nil {
- if new_prescription.OrderStatus == 4 {
- isCharge = true
- }
- }
- }
-
- if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
- advices := items["advices"].([]interface{})
-
- if len(advices) > 0 {
- for _, advice := range advices {
-
- var adviceId int64
- if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
- adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
- }
- if adviceId > 0 {
- his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
-
- if err == nil {
- if his_advice_info.IsMedicine == 1 {
-
- isMidicine = true
- }
- }
- }
- }
- }
- }
- }
- }
- }
- if isMidicine == true {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
- return
- }
- if isCharge == true {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
- return
- }
- //已发药和已收费限制逻辑
-
- if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
- //校验库存总量
- if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
- prescriptions, _ := dataBody["prescriptions"].([]interface{})
- if len(prescriptions) > 0 {
- for _, item := range prescriptions {
- items := item.(map[string]interface{})
- if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
- advices := items["advices"].([]interface{})
- if len(advices) > 0 {
- for _, advice := range advices {
- var drug_id int64
- var prescribing_number float64
- var prescribingNumberUnit string
-
- var adviceId int64
- if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
- drug_id = int64(advice.(map[string]interface{})["id"].(float64))
- }
- if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
- prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
- prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
- }
-
- if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
- prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
- }
-
- if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
- adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
- }
-
- drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
- if drug.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- //查询药品的所有库存
- list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
-
- var total_count int64
- for _, it := range list {
- total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
- }
- totals := strconv.FormatInt(total_count, 10)
- //查询该药品是否存在开药记录
- advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
-
- //查询最新批次库存
- info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
- var batch_number_count int64
- batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
- batch_number_counts := strconv.FormatInt(batch_number_count, 10)
- //新增处方
- if advicelist.ID == 0 {
- all_count, _ := strconv.ParseFloat(totals, 64)
- batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
- if prescribingNumberUnit == drug.MinUnit {
-
- if drug.IsUse != 1 {
- if prescribing_number > all_count {
- c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
- return
- }
-
- if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
- if prescribing_number > batch_number_all_count {
- c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
- return
- }
- }
-
- }
-
- }
- if prescribingNumberUnit == drug.MaxUnit {
- num := prescribing_number * float64(drug.MinNumber)
- if drug.IsUse != 1 {
- if num > all_count {
- c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
- return
- }
- if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
- if num > batch_number_all_count {
- c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
- return
- }
- }
-
- }
- }
- }
-
- drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
- if drugOutConfig.IsOpen != 1 {
- //修改处方
- for _, advice := range advices {
- var drug_id int64
- var prescribing_number float64
- var prescribingNumberUnit string
- var prescribingNumber string
-
- var adviceId int64
- if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
- drug_id = int64(advice.(map[string]interface{})["id"].(float64))
- }
- if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
- prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
- prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
- prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
- }
-
- if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
- prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
- }
-
- if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
- adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
- }
-
- drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
- if drug.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- //查询药品的所有库存
- list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
- var total_count int64
- for _, it := range list {
- total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
- }
- totals := strconv.FormatInt(total_count, 10)
- //查询该药品是否存在开药记录
- advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
-
- //新增处方
- if advicelist.ID == 0 {
- //查询最新批次库存
- info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
- var batch_number_count int64
- batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
- batch_number_counts := strconv.FormatInt(batch_number_count, 10)
-
- all_count, _ := strconv.ParseFloat(totals, 64)
- if prescribingNumberUnit == drug.MinUnit {
- batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
- if drug.IsUse != 1 {
- if prescribing_number > all_count {
- c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
- return
- }
- if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
- if prescribing_number > batch_number_all_count {
- c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
- return
- }
- }
-
- }
-
- } else {
- if prescribingNumberUnit == drug.MaxUnit {
- batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
- num := prescribing_number * float64(drug.MinNumber)
- if drug.IsUse != 1 {
- if num > all_count {
- c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
- return
- }
- if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
- if prescribing_number > batch_number_all_count {
- c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
- return
- }
- }
-
- }
-
- }
- }
- }
- //修改处方
- if advicelist.ID > 0 {
-
- //查询最新批次库存
- info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
- var batch_number_count int64
- batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
-
- var device_number int64
-
- if advicelist.PrescribingNumberUnit == drug.MaxUnit {
- prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
- prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
- device_number = prescribingNumberInt * drug.MinNumber
- }
- if advicelist.PrescribingNumberUnit == drug.MinUnit {
- prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
- prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
- device_number = prescribingNumberInt
- }
-
- var number_count int64
- if prescribingNumberUnit == drug.MaxUnit {
- prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
- number_count = prescribingNumberInt * drug.MinNumber
- }
- if prescribingNumberUnit == drug.MinUnit {
- prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
- number_count = prescribingNumberInt
- }
-
- //如果修改的数量大于之前修改的数量
- if (number_count - device_number) > 0 {
- //如果修改的差数量 大于库存数量
- if drug.IsUse != 1 {
- if (number_count - device_number) > total_count {
- c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
- return
- }
-
- if (number_count - device_number) > batch_number_count {
- c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
- return
- }
- if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 9671 {
- // 查询该药品最后一次出库记录
- outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
-
- var out_count int64
- var in_count int64
- var stock_max_number int64
- var stock_min_number int64
- for _, it := range outInfo {
- if it.CountUnit == drug.MaxUnit {
- it.Count = it.Count * drug.MinNumber
- }
- out_count += it.Count
- warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
-
- stock_max_number = warehouseInfoList.StockMaxNumber
- stock_min_number = warehouseInfoList.StockMinNumber
- in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
-
- }
-
- if out_count > 0 {
- if (number_count - device_number) > in_count {
- c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
- return
- }
- }
- // 未出库
- if out_count == 0 {
- var sum_in_count int64
- warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
- sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
- fmt.Println("sum_in_count", sum_in_count)
- //如果修改的数量大于有库存的第一个批次
- if number_count > sum_in_count {
- c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
- return
- }
- }
- }
-
- }
-
- }
- pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
- fmt.Println("device_number2333233232323222323232323323322332", device_number)
- fmt.Println("number_count99999999999999999999999999999999999", number_count)
- if pharmacyConfig.IsOpen != 1 {
- if device_number != number_count {
-
- // 查询该药品最后一次出库记录
- druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
-
- //回退库存
- if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
-
- service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
-
- }
- if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
- var stock_max_number int64
- var stock_min_number int64
-
- if number_count >= drug.MinNumber {
-
- stock_max_number = device_number / drug.MinNumber
- service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
-
- stock_min_number = device_number % drug.MinNumber
- service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
-
- } else {
-
- service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
-
- }
- }
-
- if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
- service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
-
- }
- //删除记录
- service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
-
- //查询默认仓库剩余多少库存
- var sum_count int64
- stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
- for _, its := range stockInfo {
- if its.MaxUnit == drug.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
-
- service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
-
- }
- }
-
- }
- }
- }
-
- //保存处方开药
- if drugOutConfig.IsOpen == 1 {
- //修改处方
- for _, advice := range advices {
- var drug_id int64
- var prescribing_number float64
- var prescribingNumberUnit string
- var prescribingNumber string
-
- var adviceId int64
- if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
- drug_id = int64(advice.(map[string]interface{})["id"].(float64))
- }
- if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
- prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
- prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
- prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
- }
-
- if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
- prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
- }
-
- if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
- adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
- }
-
- drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
- if drug.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- //查询药品的所有库存
- list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
- var total_count int64
- for _, it := range list {
- total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
- }
- totals := strconv.FormatInt(total_count, 10)
- //查询该药品是否存在开药记录
- advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
-
- //新增处方
- if advicelist.ID == 0 {
- //查询最新批次库存
- info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
- var batch_number_count int64
- batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
- batch_number_counts := strconv.FormatInt(batch_number_count, 10)
- all_count, _ := strconv.ParseFloat(totals, 64)
- if prescribingNumberUnit == drug.MinUnit {
- batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
- if drug.IsUse != 1 {
- if prescribing_number > all_count {
- c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
- return
- }
- if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
- if prescribing_number > batch_number_all_count {
- c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
- return
- }
- }
-
- }
-
- } else {
- if prescribingNumberUnit == drug.MaxUnit {
- batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
- num := prescribing_number * float64(drug.MinNumber)
- if drug.IsUse != 1 {
- if num > all_count {
- c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
- return
- }
- if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
- if prescribing_number > batch_number_all_count {
- c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
- return
- }
- }
-
- }
-
- }
- }
- }
- //修改处方
- if advicelist.ID > 0 {
- //查询最新批次库存
- info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
- var batch_number_count int64
- batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
-
- var device_number int64
-
- if advicelist.PrescribingNumberUnit == drug.MaxUnit {
- prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
- prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
- device_number = prescribingNumberInt * drug.MinNumber
- }
- if advicelist.PrescribingNumberUnit == drug.MinUnit {
- prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
- prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
- device_number = prescribingNumberInt
- }
-
- var number_count int64
- if prescribingNumberUnit == drug.MaxUnit {
- prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
- number_count = prescribingNumberInt * drug.MinNumber
- }
- if prescribingNumberUnit == drug.MinUnit {
- prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
- number_count = prescribingNumberInt
- }
- //如果修改的数量大于之前修改的数量
- if (number_count - device_number) > 0 {
- //如果修改的差数量 大于库存数量
- if drug.IsUse != 1 {
- if (number_count - device_number) > total_count {
- c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
- return
- }
- if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
- if (number_count - device_number) > batch_number_count {
- c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
- return
- }
- }
-
- if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
- //查询历史出库数据总批次
- // 查询该药品最后一次出库记录
- outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
- var out_count int64
- var in_count int64
- var stock_max_number int64
- var stock_min_number int64
- for _, it := range outInfo {
- if it.CountUnit == drug.MaxUnit {
- it.Count = it.Count * drug.MinNumber
- }
- out_count += it.Count
- warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
- stock_max_number = warehouseInfoList.StockMaxNumber
- stock_min_number = warehouseInfoList.StockMinNumber
- in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
-
- }
-
- if out_count > 0 {
- if (number_count - device_number) > in_count {
- c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
- return
- }
- }
-
- // 未出库
- if out_count == 0 {
- var sum_in_count int64
- warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
- sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
-
- //如果修改的数量大于有库存的第一个批次
- if number_count > sum_in_count {
- c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
- return
- }
- }
- }
-
- }
- }
- }
- }
- }
-
- }
- }
- }
- }
- }
- }
- }
-
- //校验耗材库存
- if goodOutConfig.IsOpen == 1 {
-
- if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
- prescriptions, _ := dataBody["prescriptions"].([]interface{})
-
- if len(prescriptions) > 0 {
- for _, item := range prescriptions {
-
- items := item.(map[string]interface{})
- if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
- projects := items["project"].([]interface{})
- if len(projects) > 0 {
-
- for _, project := range projects {
- var project_id int64
- var project_type int64
- var totals float64
- var project_name string
- var parsetotal int64
- var id int64
- if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
- project_id = int64(project.(map[string]interface{})["project_id"].(float64))
- }
- if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
- project_type = int64(project.(map[string]interface{})["type"].(float64))
- }
- if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
- total, _ := project.(map[string]interface{})["total"].(string)
- totals, _ = strconv.ParseFloat(total, 64)
- }
-
- if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
- project_name = project.(map[string]interface{})["project_name"].(string)
-
- }
- if project_type == 3 {
-
- //查找该耗材的出库记录
- goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
-
- if len(goodWarehouseInfo) == 0 {
- //查询耗材库存
- list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
- var stock_count int64
- for _, it := range list {
- stock_count += it.StockCount
- }
- stock_counts := strconv.FormatInt(stock_count, 10)
- stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
- if totals > stock_total_count {
- c.ServeDynamicFailJsonSend(project_name + "库存不足")
- return
- }
- }
-
- if len(goodWarehouseInfo) > 0 {
- //查询该患者耗材的历史数据
- ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
- count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
- //数量发生改变
- if parsetotal != count {
- //如果现在的数量大于历史数量,就要看库存是否足够
- if parsetotal > count {
-
- //查询耗材所有库存
- list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
- var stock_count int64
- for _, it := range list {
- stock_count += it.StockCount
- }
-
- //库存不足
- if (parsetotal - count) > stock_count {
- c.ServeDynamicFailJsonSend(project_name + "库存不足")
- return
- }
- }
- }
- }
-
- }
-
- }
- }
- }
- }
- }
- }
- }
-
- //不使用耗材保存处方出库
- if goodOutConfig.IsOpen != 1 {
- if stockConfig.IsOpen == 1 {
- if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
- prescriptions, _ := dataBody["prescriptions"].([]interface{})
-
- if len(prescriptions) > 0 {
- for _, item := range prescriptions {
-
- items := item.(map[string]interface{})
- if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
- projects := items["project"].([]interface{})
- if len(projects) > 0 {
-
- for _, project := range projects {
-
- var project_id int64
- var project_type int64
- var totals float64
- var project_name string
- var parsetotal int64
- var id int64
-
- if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
- id = int64(project.(map[string]interface{})["id"].(float64))
- }
- if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
- project_id = int64(project.(map[string]interface{})["project_id"].(float64))
- }
- if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
- project_type = int64(project.(map[string]interface{})["type"].(float64))
- }
- if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
- total, _ := project.(map[string]interface{})["total"].(string)
- totals, _ = strconv.ParseFloat(total, 64)
- parsetotal, _ = strconv.ParseInt(total, 10, 64)
- }
-
- if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
- project_name = project.(map[string]interface{})["project_name"].(string)
-
- }
- if project_type == 3 {
-
- //查找该耗材的出库记录
- goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
-
- if len(goodWarehouseInfo) == 0 {
- //查询耗材库存
- list, _ := service.GetGoodWarehouseInfoSeven(project_id)
- var stock_count int64
- for _, it := range list {
- stock_count += it.StockCount
- }
- stock_counts := strconv.FormatInt(stock_count, 10)
- stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
- if totals > stock_total_count {
- c.ServeDynamicFailJsonSend(project_name + "库存不足")
- return
- }
- //查找今日该患者已经出库的所有耗材
- goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
-
- for _, item := range goodList {
-
- goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
- var flush_count int64
- for _, it := range goodListSix {
- flush_count += it.StockCount
- }
- errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
- creater := adminInfo.AdminUser.Id
- if errs != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: item.OrgId,
- Errcode: "手动出库更新剩余出库失败",
- GoodId: item.GoodId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creater,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
-
- }
- //删除记录
- service.DeleteAutoWarehouse(patient_id, recordDateTime)
-
- }
- if len(goodWarehouseInfo) > 0 {
- //查询该患者耗材的历史数据
- ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
-
- count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
-
- //数量发生改变
- if parsetotal != count {
- //查找今日该患者已经出库的所有耗材
- goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
-
- for _, item := range goodList {
-
- goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
- var flush_count int64
- for _, it := range goodListSix {
- flush_count += it.StockCount
- }
- errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
-
- //减少出库数量
- creater := adminInfo.AdminUser.Id
- if errs != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: item.OrgId,
- Errcode: "手动出库更新剩余出库失败",
- GoodId: item.GoodId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creater,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
- //查询默认仓库
- stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
- var total_count int64
- for _, it := range stockList {
- total_count += it.StockCount
- }
- //基础库插入数据
- service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
- }
-
- //删除记录
- service.DeleteAutoWarehouse(patient_id, recordDateTime)
-
- }
-
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
-
- info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
- var hpInfo models.HisPrescriptionInfo
- if info.ID == 0 {
- var randNum int
- randNum = rand.Intn(10000) + 1000
- timestamp := time.Now().Unix()
- tempTime := time.Unix(timestamp, 0)
- timeFormat := tempTime.Format("20060102150405")
- p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
-
- hpInfo = models.HisPrescriptionInfo{
- HisPatientId: his_patient_id,
- UserOrgId: adminInfo.CurrentOrgId,
- RecordDate: theTime.Unix(),
- PatientId: patient_id,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Creator: adminInfo.AdminUser.Id,
- Modifier: adminInfo.AdminUser.Id,
- Diagnosis: diagnose,
- SickHistory: sick_history,
- Departments: department,
- RegisterType: reg_type,
- PrescriptionNumber: p_number,
- PrescriptionStatus: 1,
- Doctor: role.UserName,
- DoctorId: doctor_id,
- SickType: sick_type,
- PType: p_type,
- }
- service.SavePatientPrescriptionInfo(hpInfo)
- redis := service.RedisClient()
- key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
- redis.Set(keyOne, "", time.Second)
- keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
- redis.Set(keySeven, "", time.Second)
- defer redis.Close()
- } else {
- hpInfo = models.HisPrescriptionInfo{
- ID: info.ID,
- UserOrgId: adminInfo.CurrentOrgId,
- RecordDate: info.RecordDate,
- PatientId: info.PatientId,
- Status: 1,
- Ctime: info.Ctime,
- Mtime: time.Now().Unix(),
- Creator: info.Creator,
- Modifier: adminInfo.AdminUser.Id,
- Diagnosis: diagnose,
- SickHistory: sick_history,
- Departments: department,
- RegisterType: reg_type,
- PrescriptionNumber: info.PrescriptionNumber,
- Doctor: role.UserName,
- PrescriptionStatus: info.PrescriptionStatus,
- DoctorId: doctor_id,
- SickType: sick_type,
- PType: info.PType,
- HisPatientId: info.HisPatientId,
- }
- service.SavePatientPrescriptionInfo(hpInfo)
- redis := service.RedisClient()
- key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
- redis.Set(keyOne, "", time.Second)
- keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
- redis.Set(keySeven, "", time.Second)
- defer redis.Close()
- }
-
- //定义切片
-
- var adviceList []models.HisDoctorAdviceInfo
- var projectList []models.HisPrescriptionProject
-
- if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
- prescriptions, _ := dataBody["prescriptions"].([]interface{})
-
- var tempPrescription *models.HisPrescription
-
- if len(prescriptions) > 0 {
- for _, item := range prescriptions {
- items := item.(map[string]interface{})
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- id := int64(items["id"].(float64))
-
- new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
- tempPrescription = &new_prescription
- if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
- utils.ErrorLog("type")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- types := int64(items["type"].(float64))
-
- if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
- utils.ErrorLog("med_type")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- med_type := strconv.Itoa(int(items["med_type"].(float64)))
-
- if med_type == "0" {
- med_type = "14"
- }
-
- //if order_status == 0 {
- // order_status = 1
- //}
-
- if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
- utils.ErrorLog("pre_time")
- }
- preTime, _ := items["pre_time"].(string)
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- pTime := theTime2.Unix()
-
- ctime := time.Now().Unix()
-
- if tempPrescription.ID == 0 {
- prescription := &models.HisPrescription{
- ID: 0,
- PatientId: patient_id,
- UserOrgId: adminInfo.CurrentOrgId,
- RecordDate: recordDateTime,
- Ctime: ctime,
- Mtime: ctime,
- Type: types,
- Modifier: adminInfo.AdminUser.Id,
- Creator: adminInfo.AdminUser.Id,
- Status: 1,
- Doctor: role.UserName,
- HisPatientId: his_patient_id,
- OrderStatus: 1,
- BatchNumber: "",
- PrescriptionNumber: hpInfo.PrescriptionNumber,
- PreTime: pTime,
- PType: p_type,
- MedType: med_type,
- }
- tempPrescription = prescription
- service.SaveHisPrescription(tempPrescription)
- redis := service.RedisClient()
- key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
- redis.Set(key, "", time.Second)
-
- keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
- redis.Set(keyOne, "", time.Second)
- keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
- redis.Set(keySeven, "", time.Second)
- defer redis.Close()
- } else {
- tempPrescription.ID = id
- tempPrescription.Type = types
- tempPrescription.Modifier = adminInfo.AdminUser.Id
- tempPrescription.Mtime = time.Now().Unix()
- tempPrescription.Doctor = role.UserName
- //tempPrescription.OrderStatus = order_status
- tempPrescription.PreTime = pTime
- tempPrescription.MedType = med_type
- service.SaveHisPrescription(tempPrescription)
- redis := service.RedisClient()
- key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
-
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
- redis.Set(keyOne, "", time.Second)
- keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
- redis.Set(keySeven, "", time.Second)
- defer redis.Close()
- }
- //service.SaveHisPrescription(prescription)
- //更改患者挂号状态
- _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
- fmt.Println("更改失败", err2)
-
- if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
- advices := items["advices"].([]interface{})
- //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
- groupNo := int64(0)
- ctime := time.Now().Unix()
- mtime := ctime
- if len(advices) > 0 {
- for _, advice := range advices {
- var s models.HisDoctorAdviceInfo
- s.PrescriptionId = tempPrescription.ID
- s.AdviceType = 2
- s.AdviceDoctor = doctor_id
- s.StopState = 2
- s.ExecutionState = 2
- s.AdviceDate = recordDateTime
- s.Status = 1
- s.UserOrgId = adminInfo.CurrentOrgId
- s.RecordDate = recordDateTime
- s.StartTime = tempPrescription.PreTime
- s.Groupno = groupNo
- s.CreatedTime = ctime
- s.UpdatedTime = mtime
- s.PatientId = patient_id
- s.HisPatientId = his_patient_id
- s.StartTime = pTime
- s.IsSettle = 2
- errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
- if errcode > 0 {
- c.ServeFailJSONWithSGJErrorCode(errcode)
- return
- }
-
- s.StartTime = pTime
- var total_count int64 //处方总库存
- //查询改药品信息
- medical, _ := service.GetBaseDrugMedical(s.DrugId)
- prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
- prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
-
- if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
- total_count += prescribingNumberSeven * medical.MinNumber
- }
-
- if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- total_count += prescribingNumberSeven
- }
-
- if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
- total_count += prescribingNumberSeven
- }
- service.CreateHisDoctorAdvice(&s)
-
- //存储切片中
- adviceList = append(adviceList, s)
-
- redis := service.RedisClient()
- key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
- redis.Set(keyOne, "", time.Second)
- keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
- redis.Set(keySeven, "", time.Second)
- var randNum int
- randNum = rand.Intn(10000) + 1000
- timestamp := time.Now().Unix()
- tempTime := time.Unix(timestamp, 0)
- timeFormat := tempTime.Format("20060102150405")
- s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
- service.CreateHisDoctorAdvice(&s)
- keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
- redis.Set(keySix, "", time.Second)
- keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
- redis.Set(keyFive, "", time.Second)
- keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
- redis.Set(keyEight, "", time.Second)
- defer redis.Close()
-
- }
- }
-
- }
- if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
- projects := items["project"].([]interface{})
- if len(projects) > 0 {
- for _, project := range projects {
-
- var p models.HisPrescriptionProject
- p.PrescriptionId = tempPrescription.ID
- p.Ctime = time.Now().Unix()
- p.Mtime = time.Now().Unix()
- p.PatientId = patient_id
- p.RecordDate = recordDateTime
- p.Doctor = doctor_id
- p.UserOrgId = adminInfo.CurrentOrgId
- p.HisPatientId = his_patient_id
- p.Status = 1
- p.StartTime = pTime
-
- errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
- if errcode > 0 {
- c.ServeFailJSONWithSGJErrorCode(errcode)
- return
- }
-
- if p.ID == 0 {
- p.IsOut = 2
- }
- if p.ID > 0 {
- projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
- p.IsOut = projectDetail.IsOut
- }
- service.CreateHisProjectTwo(&p)
- projectList = append(projectList, p)
- var randNum int
- randNum = rand.Intn(10000) + 1000
- timestamp := time.Now().Unix()
- tempTime := time.Unix(timestamp, 0)
- timeFormat := tempTime.Format("20060102150405")
- p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
-
- if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
- //新增或者编辑项目,修改对应的标签数据
- labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
- if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
- var label models.HisLabelPrintInfo
- project, _ := service.GetProjectDetail(p.ProjectId)
- if project.CostClassify == 3 { //类别为检验检查
- if p.TeamId > 0 { //检验检查组套
- tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
- if tempLabel.ID == 0 {
- team, _ := service.GetProjectTeamDetail(p.TeamId)
- label.Number = tempPrescription.PrescriptionNumber
- label.ProjectId = project.ID
- label.Status = 1
- label.IsPrint = 2
- label.DoctorId = info.DoctorId
- label.UserOrgId = p.UserOrgId
- label.PatientId = patient_id
- label.RecordDate = recordDateTime
- label.Ctime = time.Now().Unix()
- label.Mtime = time.Now().Unix()
- label.ItemId = p.TeamId
- label.FeedetlSn = p.FeedetlSn
- label.PProjectId = p.ID
- label.ProjectName = team.ProjectTeam
- label.PatientName = patient.Name
- service.CreateHisLabelRecord(&label)
- }
- } else { //单条检验检查项目
- label.Number = tempPrescription.PrescriptionNumber
- label.ProjectId = project.ID
- label.Status = 1
- label.DoctorId = info.DoctorId
- label.UserOrgId = p.UserOrgId
- label.PatientId = patient_id
- label.RecordDate = recordDateTime
- label.IsPrint = 2
- label.Ctime = time.Now().Unix()
- label.Mtime = time.Now().Unix()
- label.FeedetlSn = p.FeedetlSn
- label.PProjectId = p.ID
- label.ItemId = p.TeamId
- label.ProjectName = project.ProjectName
- label.PatientName = patient.Name
- service.CreateHisLabelRecord(&label)
- }
- }
- }
- }
-
- service.SaveHisProjectTwo(&p)
-
- }
- }
- }
- //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
- // addition := items["addition"].([]interface{})
- // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
- // ctime := time.Now().Unix()
- // mtime := ctime
- // if len(addition) > 0 {
- // for _, item := range addition {
- // var s models.HisAdditionalCharge
- // s.PrescriptionId = tempPrescription.ID
- // s.Status = 1
- // s.UserOrgId = adminInfo.CurrentOrgId
- // s.RecordDate = recordDateTime
- // s.CreatedTime = ctime
- // s.UpdatedTime = mtime
- // s.PatientId = patient_id
- // s.HisPatientId = his_patient_id
- // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
- // if errcode > 0 {
- // c.ServeFailJSONWithSGJErrorCode(errcode)
- // return
- // }
- // service.CreateAdditionalCharge(&s)
- // var randNum int
- // randNum = rand.Intn(10000) + 1000
- // timestamp := time.Now().Unix()
- // tempTime := time.Unix(timestamp, 0)
- // timeFormat := tempTime.Format("20060102150405")
- // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
- // service.CreateAdditionalCharge(&s)
- //
- // }
- // }
- //}
-
- }
-
- }
-
- //查询今日该患者开的药品处方
- hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
- drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
- //药品出库
- if drugOutConfig.IsOpen == 1 {
- for _, item := range hisdoctorlist {
- drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
- // 查询该药品最后一次出库记录
- druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
-
- if len(druginfo) > 0 {
- //回退库存
- for _, it := range druginfo {
-
- if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
-
- service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
-
- }
- if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
- service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
-
- }
- if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
-
- service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
-
- }
- }
- }
-
- //删除记录
- service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
- //查询最后一次数据
- if drugOutConfig.IsOpen == 1 {
- //出库
- if drug.IsUse == 2 {
- creater := adminInfo.AdminUser.Id
- service.HisDrugsDelivery(item.UserOrgId, creater, item)
- }
-
- //更新字典里面的库存
- stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
- var sum_count int64
- for _, its := range stockInfo {
- baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
- if its.MaxUnit == baseDrug.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
- //更新基础库存
- service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
- //剩余库存
- service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
- }
- }
- }
-
- //耗材保存处方出库
- if goodOutConfig.IsOpen == 1 {
-
- //查询今日耗材出库数量
- hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
-
- for _, item := range hisgoodlist {
- //查询耗材最后一次出库记录
- wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
- fmt.Println("hh23h232323o23o23o2o32o23o2o3o2o23o32o23o2o323o23o23o23o23o23o")
- //查询默认出库仓库库存
- storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
- if len(wareOut) > 0 {
-
- for _, it := range wareOut {
- //回退库存
- service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
- //删除出库记录
- service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
- //出库数量减少
- service.UpdateSumCount(it.OrgId, storeConfig.StorehouseOutInfo, it.ProjectId, it.Count)
- }
- }
-
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
-
- total = total + 1
- warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- number = number + total
- warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
-
- operation_time := time.Now().Unix()
- creater := c.GetAdminUserInfo().AdminUser.Id
-
- recordDateStr := time.Now().Format("2006-01-02")
- recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- nowtime := recordDate.Unix()
- warehouseOut := models.WarehouseOut{
- WarehouseOutOrderNumber: warehousing_out_order,
- OperationTime: operation_time,
- OrgId: adminInfo.CurrentOrgId,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- WarehouseOutTime: nowtime,
- Type: 1,
- StorehouseId: storeConfig.StorehouseOutInfo,
- IsCheck: 1,
- IsSys: 1,
- }
- //查询是否生成出库单
- out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
- if out.ID == 0 {
- service.AddSigleWarehouseOut(&warehouseOut)
- }
-
- lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
-
- goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
- houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
- parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
-
- dialyPrepareOne := models.DialysisBeforePrepare{
- GoodTypeId: goodObj.GoodTypeId,
- GoodId: item.ProjectId,
- PatientId: item.PatientId,
- RecordDate: item.RecordDate,
- UserOrgId: adminInfo.CurrentOrgId,
- Count: parseIntCount,
- Ctime: time.Now().Unix(),
- Creater: creater,
- Status: 1,
- StorehouseId: houseConfig.StorehouseOutInfo,
- ProjectId: item.ID,
- }
- goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
- if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
- service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
-
- //查询剩余库存
- goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
- var sum_count int64
- for _, item := range goodList {
- sum_count += item.StockCount
- }
-
- //更新剩余库存
- service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
-
- //耗材
- service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
- }
-
- }
- }
- }
-
- //redisClient := service.RedisClient()
- //defer redisClient.Close()
- //
- //list := models.HisList{
- // Patient_id: patient_id,
- // Advice_id:0,
- // Record_date: 0,
- // Advice: adviceList,
- // Project: nil,
- //}
- //hisLis = append(hisLis, list)
- //
- //advice_json, _ := json.Marshal(&hisLis)
- //redisClient.RPush("111", advice_json).Result()
- //result, _ := redisClient.RPop("111").Result()
- //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
- //
- //var dat []map[string]interface{}
- //json.Unmarshal([]byte(result), &dat)
- //fmt.Println("hhhh2332323232233223322332322323232323",dat)
- //
- //for k,v:=range dat{
- // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
- //}
- //project_json, _ := json.Marshal(&projectList)
- //redisClient.LPush("222", project_json).Result()
-
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "保存成功",
- })
- return
-
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
-
- }
- func (c *HisApiController) EditHisPrescription() {
- record_date := c.GetString("record_date")
- patient_id, _ := c.GetInt64("patient_id")
- reg_type, _ := c.GetInt64("reg_type")
- //diagnose, _ := c.GetInt64("diagnose", 0)
- diagnose := c.GetString("diagnose")
- sick_type, _ := c.GetInt64("sick_type")
- sick_history := c.GetString("sick_history")
- doctor_id, _ := c.GetInt64("doctor", 0)
- department, _ := c.GetInt64("department", 0)
- his_patient_id, _ := c.GetInt64("his_patient_id")
- p_type, _ := c.GetInt64("p_type")
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adminInfo := c.GetAdminUserInfo()
- recordDateTime := theTime.Unix()
-
- role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
-
- info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
- var hpInfo models.HisPrescriptionInfo
- if info.ID == 0 {
- var randNum int
- randNum = rand.Intn(10000) + 1000
- timestamp := time.Now().Unix()
- tempTime := time.Unix(timestamp, 0)
- timeFormat := tempTime.Format("20060102150405")
- p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
-
- hpInfo = models.HisPrescriptionInfo{
- UserOrgId: adminInfo.CurrentOrgId,
- RecordDate: theTime.Unix(),
- PatientId: patient_id,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Creator: adminInfo.AdminUser.Id,
- Modifier: adminInfo.AdminUser.Id,
- Diagnosis: diagnose,
- SickHistory: sick_history,
- Departments: department,
- RegisterType: reg_type,
- PrescriptionNumber: p_number,
- PrescriptionStatus: 1,
- Doctor: role.UserName,
- DoctorId: doctor_id,
- SickType: sick_type,
- PType: p_type,
- }
- service.SavePatientPrescriptionInfo(hpInfo)
-
- } else {
- hpInfo = models.HisPrescriptionInfo{
- ID: info.ID,
- UserOrgId: adminInfo.CurrentOrgId,
- RecordDate: info.RecordDate,
- PatientId: info.PatientId,
- Status: 1,
- Ctime: info.Ctime,
- Mtime: time.Now().Unix(),
- Creator: info.Creator,
- Modifier: adminInfo.AdminUser.Id,
- Diagnosis: diagnose,
- SickHistory: sick_history,
- Departments: department,
- RegisterType: reg_type,
- PrescriptionNumber: info.PrescriptionNumber,
- Doctor: role.UserName,
- PrescriptionStatus: info.PrescriptionStatus,
- DoctorId: doctor_id,
- SickType: sick_type,
- PType: info.PType,
- }
- service.SavePatientPrescriptionInfo(hpInfo)
- }
-
- if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
- prescriptions, _ := dataBody["prescriptions"].([]interface{})
-
- if len(prescriptions) > 0 {
- for _, item := range prescriptions {
- items := item.(map[string]interface{})
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- id := int64(items["id"].(float64))
-
- if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
- utils.ErrorLog("type")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- types := int64(items["type"].(float64))
-
- if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
- utils.ErrorLog("med_type")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- med_type := strconv.Itoa(int(items["med_type"].(float64)))
-
- historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
-
- ctime := time.Now().Unix()
-
- prescription := &models.HisPrescription{
- ID: id,
- PatientId: patient_id,
- UserOrgId: adminInfo.CurrentOrgId,
- RecordDate: recordDateTime,
- Ctime: ctime,
- Mtime: ctime,
- Type: types,
- Modifier: adminInfo.AdminUser.Id,
- Creator: adminInfo.AdminUser.Id,
- Status: 1,
- Doctor: role.UserName,
- HisPatientId: his_patient_id,
- OrderStatus: 1,
- BatchNumber: "",
- PrescriptionNumber: hpInfo.PrescriptionNumber,
- PType: hpInfo.PType,
- MedType: med_type,
- }
-
- if historyPrescription.ID > 0 {
- prescription.PreTime = historyPrescription.PreTime
-
- }
-
- service.SaveHisPrescription(prescription)
-
- if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
- advices := items["advices"].([]interface{})
- //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
- groupNo := int64(0)
- ctime := time.Now().Unix()
- mtime := ctime
- if len(advices) > 0 {
- for _, advice := range advices {
- var s models.HisDoctorAdviceInfo
- s.PrescriptionId = prescription.ID
- s.AdviceType = 2
- s.AdviceDoctor = adminInfo.AdminUser.Id
- s.StopState = 2
- s.ExecutionState = 2
- s.AdviceDate = recordDateTime
- s.Status = 1
- s.UserOrgId = adminInfo.CurrentOrgId
- s.RecordDate = recordDateTime
- s.StartTime = prescription.PreTime
- s.Groupno = groupNo
- s.CreatedTime = ctime
- s.UpdatedTime = mtime
- s.PatientId = patient_id
- s.HisPatientId = his_patient_id
- errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
- if errcode > 0 {
- c.ServeFailJSONWithSGJErrorCode(errcode)
- return
- }
- service.CreateHisDoctorAdvice(&s)
- redis := service.RedisClient()
- key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
- fmt.Println("keyOne", keyOne)
- redis.Set(keyOne, "", time.Second)
- keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
- redis.Set(keySeven, "", time.Second)
- redis.Close()
-
- }
- }
- }
- if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
- projects := items["project"].([]interface{})
- if len(projects) > 0 {
- for _, project := range projects {
- var p models.HisPrescriptionProject
- p.PrescriptionId = prescription.ID
- p.Ctime = time.Now().Unix()
- p.Mtime = time.Now().Unix()
- p.PatientId = patient_id
- p.RecordDate = recordDateTime
- p.UserOrgId = adminInfo.CurrentOrgId
- p.HisPatientId = his_patient_id
- p.Status = 1
- errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
- if errcode > 0 {
- c.ServeFailJSONWithSGJErrorCode(errcode)
- return
- }
- service.CreateHisProjectTwo(&p)
-
- }
- }
- }
- if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
- addition := items["addition"].([]interface{})
- //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
- ctime := time.Now().Unix()
- mtime := ctime
- if len(addition) > 0 {
- for _, item := range addition {
- var s models.HisAdditionalCharge
- s.PrescriptionId = prescription.ID
- s.Status = 1
- s.UserOrgId = adminInfo.CurrentOrgId
- s.RecordDate = recordDateTime
- s.CreatedTime = ctime
- s.UpdatedTime = mtime
- s.PatientId = patient_id
- s.HisPatientId = his_patient_id
- errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
- if errcode > 0 {
- c.ServeFailJSONWithSGJErrorCode(errcode)
- return
- }
- service.CreateAdditionalCharge(&s)
- }
- }
- }
-
- }
- }
- }
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "保存成功",
- })
- return
-
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
-
- func (c *HisApiController) DeletePrescription() {
- prescription_id, _ := c.GetInt64("id")
- projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
- advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
- //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
-
- _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
-
- drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
- //耗材保存处方出库
- goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
- //已收费和已发药限制逻辑
- isCharge := false
- isMedicine := false
- new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
- new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
-
- for _, item := range new_prescriptions {
- if item.IsMedicine == 1 {
- isMedicine = true
- }
- }
-
- for _, item := range new_prescriptions {
- if item.OrderStatus == 4 {
- isCharge = true
- }
- }
-
- if p_err != nil {
- if new_prescription.ID > 0 {
- if new_prescription.OrderStatus == 2 {
- isCharge = true
- }
- }
- }
- for _, item := range advices {
- if item.IsMedicine == 1 {
- isMedicine = true
- }
- }
- if isCharge {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
- return
- }
-
- if isMedicine {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
- return
- }
- //已收费和已发药限制逻辑
-
- if len(projects) > 0 {
- for _, item := range projects {
- service.DeletePrintInfo(item.ID) //删除打印信息
-
- if goodOutConfig.IsOpen != 1 {
- if stockConfig.IsOpen == 1 {
- if item.Type == 3 && item.IsOut == 1 {
- good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
- f_count, _ := strconv.ParseFloat(item.Count, 64)
- good.Total = good.Total + f_count
- service.UpdateGoodInfo(&good)
- operation_time := time.Now().Unix()
- creater := c.GetAdminUserInfo().AdminUser.Id
- //创建退库单
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
- total = total + 1
- orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
- houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
- cancelStock := models.CancelStock{
- OrderNumber: orderNumber,
- OperaTime: operation_time,
- OrgId: c.GetAdminUserInfo().CurrentOrgId,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- ReturnTime: item.RecordDate,
- Type: 1,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- }
- _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
- if msgerrkonde == gorm.ErrRecordNotFound {
- service.AddSigleCancelStock(&cancelStock)
- }
- cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
- floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
- prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
- //查询该耗材是否出库
- info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
- manufacturer, _ := service.GetManufactureById(info.Manufacturer)
- deaerler, _ := service.GetDealerById(info.Dealer)
-
- var total_count int64
- count, _ := strconv.ParseInt(item.Count, 10, 64)
- total_count += count
-
- goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
- var flush_count int64
- for _, it := range goodList {
- flush_count += it.StockCount
- }
- if info.ID > 0 {
- if info.Count >= total_count {
-
- //回退库存
- service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
- cancelStockInfo := models.CancelStockInfo{
- GoodId: item.ProjectId,
- CancelStockId: cancel.ID,
- GoodTypeId: good.GoodTypeId,
- Count: prescribingNumber,
- Price: info.Price,
- Total: 0,
- ProductDate: info.ProductDate,
- ExpiryDate: info.ExpiryDate,
- Ctime: time.Now().Unix(),
- Status: 1,
- OrgId: c.GetAdminUserInfo().CurrentOrgId,
- OrderNumber: cancel.OrderNumber,
- Type: 0,
- Dealer: deaerler.DealerName,
- Manufacturer: manufacturer.ManufacturerName,
- Number: info.Number,
- RegisterAccount: "",
- Remark: "",
- WarehouseInfoId: info.WarehouseInfotId,
- PatientId: info.PatientId,
- RecordDate: info.SysRecordTime,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- }
-
- service.CreateCancelStockInfoOne(&cancelStockInfo)
-
- cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
-
- flow := models.VmStockFlow{
- WarehousingId: info.WarehouseInfotId,
- GoodId: item.ProjectId,
- Number: info.Number,
- LicenseNumber: info.LicenseNumber,
- Count: prescribingNumber,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- PatientId: item.PatientId,
- SystemTime: info.SysRecordTime,
- ConsumableType: 7,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: info.WarehouseOutId,
- WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
- IsEdit: 0,
- CancelStockId: cancel.ID,
- CancelOrderNumber: cancel.OrderNumber,
- Manufacturer: manufacturer.ID,
- Dealer: 0,
- Creator: c.GetAdminUserInfo().CurrentOrgId,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: info.Price,
- WarehousingDetailId: info.WarehouseInfotId,
- WarehouseOutDetailId: info.ID,
- CancelOutDetailId: cancelInfo.ID,
- ProductDate: info.ProductDate,
- ExpireDate: info.ExpiryDate,
- StorehouseId: houseConfig.StorehouseOutInfo,
- OverCount: flush_count,
- }
- service.CreateStockFlowOne(flow)
-
- //退库数量增加
- service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
- //出库数量减少
- service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
- }
-
- if info.Count < total_count {
- //回退库存
- service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
- cancelStockInfo := models.CancelStockInfo{
- GoodId: item.ProjectId,
- CancelStockId: cancel.ID,
- GoodTypeId: good.GoodTypeId,
- Count: info.Count,
- Price: info.Price,
- Total: 0,
- ProductDate: info.ProductDate,
- ExpiryDate: info.ExpiryDate,
- Ctime: time.Now().Unix(),
- Status: 1,
- OrgId: c.GetAdminUserInfo().CurrentOrgId,
- OrderNumber: cancel.OrderNumber,
- Type: 0,
- Dealer: deaerler.DealerName,
- Manufacturer: manufacturer.ManufacturerName,
- Number: info.Number,
- RegisterAccount: "",
- Remark: "",
- WarehouseInfoId: info.WarehouseInfotId,
- PatientId: info.PatientId,
- RecordDate: info.SysRecordTime,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- }
-
- service.CreateCancelStockInfoOne(&cancelStockInfo)
-
- cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
-
- flow := models.VmStockFlow{
- WarehousingId: info.WarehouseInfotId,
- GoodId: item.ProjectId,
- Number: info.Number,
- LicenseNumber: info.LicenseNumber,
- Count: info.Count,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- PatientId: item.PatientId,
- SystemTime: info.SysRecordTime,
- ConsumableType: 7,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: info.WarehouseOutId,
- WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
- IsEdit: 0,
- CancelStockId: cancel.ID,
- CancelOrderNumber: cancel.OrderNumber,
- Manufacturer: manufacturer.ID,
- Dealer: 0,
- Creator: c.GetAdminUserInfo().CurrentOrgId,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: info.Price,
- WarehousingDetailId: info.WarehouseInfotId,
- WarehouseOutDetailId: info.ID,
- CancelOutDetailId: cancelInfo.ID,
- ProductDate: info.ProductDate,
- ExpireDate: info.ExpiryDate,
- StorehouseId: houseConfig.StorehouseOutInfo,
- OverCount: flush_count,
- }
- service.CreateStockFlowOne(flow)
-
- //退库数量增加
- service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
- //出库数量减少
- service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
- }
-
- //查询已出库数量
- dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
-
- if prescribingNumber < dialysisInfo.Count {
- //改变数量
- service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
- }
-
- if prescribingNumber >= dialysisInfo.Count {
- //删除出库表
- service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
- }
-
- //更新库存
- service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
-
- //更新基础库库存
- service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
- //查询今日该耗材退库数量
- //cancelInfoOne, _ := service.GetCancelStockInfoByPatientId(info.PatientId, item.ProjectId, info.SysRecordTime)
- //var cancel_Count int64
- //for _, items := range cancelInfoOne {
- // cancel_Count += items.Count
- //}
- //
- //cha_count = total_count - cancel_Count
- //
- //if total_count > cancel_Count {
- //
- // out, err := service.FindStockOutByIsSys(c.GetAdminUserInfo().CurrentOrgId, 1, info.SysRecordTime)
- // if err == gorm.ErrRecordNotFound {
- // //没有记录,则创建出库单
- // timeStr := time.Now().Format("2006-01-02")
- // timeArr := strings.Split(timeStr, "-")
- // total, _ := service.FindAllWarehouseOut(c.GetAdminUserInfo().CurrentOrgId)
- // total = total + 1
- // warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- // number = number + total
- // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
- // warehouseOut := models.WarehouseOut{
- // WarehouseOutOrderNumber: warehousing_out_order,
- // OperationTime: time.Now().Unix(),
- // OrgId: c.GetAdminUserInfo().CurrentOrgId,
- // Creater: creater,
- // Ctime: time.Now().Unix(),
- // Status: 1,
- // WarehouseOutTime: info.SysRecordTime,
- // Dealer: 0,
- // Manufacturer: 0,
- // Type: 1,
- // IsSys: 1,
- // StorehouseId: houseConfig.StorehouseOutInfo,
- // IsCheck: 1,
- // }
- // err := service.AddSigleWarehouseOut(&warehouseOut)
- // if err != nil {
- // utils.TraceLog("创建出库单失败 err = %v", err)
- // return
- // }
- // prepare := &models.DialysisBeforePrepare{
- // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- // PatientId: info.PatientId,
- // RecordDate: info.SysRecordTime,
- // GoodId: item.ProjectId,
- // GoodTypeId: info.GoodTypeId,
- // Count: cha_count,
- // StorehouseId: houseConfig.StorehouseOutInfo,
- // }
- // //出库
- // service.ConsumablesDelivery(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &warehouseOut, cha_count)
- // } else if err == nil {
- //
- // prepare := &models.DialysisBeforePrepare{
- // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- // PatientId: info.PatientId,
- // RecordDate: info.SysRecordTime,
- // GoodId: item.ProjectId,
- // GoodTypeId: info.GoodTypeId,
- // Count: cha_count,
- // StorehouseId: houseConfig.StorehouseOutInfo,
- // }
- // //出库
- // service.ConsumablesDelivery(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &out, cha_count)
- // }
- //
- //}
-
- }
-
- }
- }
- }
-
- //保存耗材出库
- if goodOutConfig.IsOpen == 1 {
-
- if item.Type == 3 {
- good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
- f_count, _ := strconv.ParseFloat(item.Count, 64)
- good.Total = good.Total + f_count
- service.UpdateGoodInfo(&good)
- operation_time := time.Now().Unix()
- creater := c.GetAdminUserInfo().AdminUser.Id
- //创建退库单
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
- total = total + 1
- orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
- houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
- cancelStock := models.CancelStock{
- OrderNumber: orderNumber,
- OperaTime: operation_time,
- OrgId: c.GetAdminUserInfo().CurrentOrgId,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- ReturnTime: item.RecordDate,
- Type: 1,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- }
- _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
- if msgerrkonde == gorm.ErrRecordNotFound {
- service.AddSigleCancelStock(&cancelStock)
- }
- cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
- floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
- prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
- //查询该耗材是否出库
- info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
- manufacturer, _ := service.GetManufactureById(info.Manufacturer)
- deaerler, _ := service.GetDealerById(info.Dealer)
-
- var total_count int64
- count, _ := strconv.ParseInt(item.Count, 10, 64)
- total_count += count
-
- goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
- var flush_count int64
- for _, it := range goodList {
- flush_count += it.StockCount
- }
- fmt.Println("历史出库数据", info.Count)
- fmt.Println("出库数量", total_count)
- if info.ID > 0 {
-
- //回退库存
- service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
- cancelStockInfo := models.CancelStockInfo{
- GoodId: item.ProjectId,
- CancelStockId: cancel.ID,
- GoodTypeId: good.GoodTypeId,
- Count: prescribingNumber,
- Price: info.Price,
- Total: 0,
- ProductDate: info.ProductDate,
- ExpiryDate: info.ExpiryDate,
- Ctime: time.Now().Unix(),
- Status: 1,
- OrgId: c.GetAdminUserInfo().CurrentOrgId,
- OrderNumber: cancel.OrderNumber,
- Type: 0,
- Dealer: deaerler.DealerName,
- Manufacturer: manufacturer.ManufacturerName,
- Number: info.Number,
- RegisterAccount: "",
- Remark: "",
- WarehouseInfoId: info.WarehouseInfotId,
- PatientId: info.PatientId,
- RecordDate: info.SysRecordTime,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- }
-
- service.CreateCancelStockInfoOne(&cancelStockInfo)
-
- cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
-
- flow := models.VmStockFlow{
- WarehousingId: info.WarehouseInfotId,
- GoodId: item.ProjectId,
- Number: info.Number,
- LicenseNumber: info.LicenseNumber,
- Count: prescribingNumber,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- PatientId: item.PatientId,
- SystemTime: info.SysRecordTime,
- ConsumableType: 7,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: info.WarehouseOutId,
- WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
- IsEdit: 0,
- CancelStockId: cancel.ID,
- CancelOrderNumber: cancel.OrderNumber,
- Manufacturer: manufacturer.ID,
- Dealer: 0,
- Creator: c.GetAdminUserInfo().CurrentOrgId,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: info.Price,
- WarehousingDetailId: info.WarehouseInfotId,
- WarehouseOutDetailId: info.ID,
- CancelOutDetailId: cancelInfo.ID,
- ProductDate: info.ProductDate,
- ExpireDate: info.ExpiryDate,
- StorehouseId: houseConfig.StorehouseOutInfo,
- OverCount: flush_count,
- }
- service.CreateStockFlowOne(flow)
-
- //退库数量增加
- service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
- //出库数量减少
- service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
-
- //if info.Count < total_count {
- // //回退库存
- // service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
- // cancelStockInfo := models.CancelStockInfo{
- // GoodId: item.ProjectId,
- // CancelStockId: cancel.ID,
- // GoodTypeId: good.GoodTypeId,
- // Count: info.Count,
- // Price: info.Price,
- // Total: 0,
- // ProductDate: info.ProductDate,
- // ExpiryDate: info.ExpiryDate,
- // Ctime: time.Now().Unix(),
- // Status: 1,
- // OrgId: c.GetAdminUserInfo().CurrentOrgId,
- // OrderNumber: cancel.OrderNumber,
- // Type: 0,
- // Dealer: deaerler.DealerName,
- // Manufacturer: manufacturer.ManufacturerName,
- // Number: info.Number,
- // RegisterAccount: "",
- // Remark: "",
- // WarehouseInfoId: info.WarehouseInfotId,
- // PatientId: info.PatientId,
- // RecordDate: info.SysRecordTime,
- // StorehouseId: houseConfig.StorehouseOutInfo,
- // IsCheck: 1,
- // }
- //
- // service.CreateCancelStockInfoOne(&cancelStockInfo)
- //
- // cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
- //
- // flow := models.VmStockFlow{
- // WarehousingId: info.WarehouseInfotId,
- // GoodId: item.ProjectId,
- // Number: info.Number,
- // LicenseNumber: info.LicenseNumber,
- // Count: info.Count,
- // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- // PatientId: item.PatientId,
- // SystemTime: info.SysRecordTime,
- // ConsumableType: 7,
- // IsSys: 0,
- // WarehousingOrder: "",
- // WarehouseOutId: info.WarehouseOutId,
- // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
- // IsEdit: 0,
- // CancelStockId: cancel.ID,
- // CancelOrderNumber: cancel.OrderNumber,
- // Manufacturer: manufacturer.ID,
- // Dealer: 0,
- // Creator: c.GetAdminUserInfo().CurrentOrgId,
- // UpdateCreator: 0,
- // Status: 1,
- // Ctime: time.Now().Unix(),
- // Mtime: 0,
- // Price: info.Price,
- // WarehousingDetailId: info.WarehouseInfotId,
- // WarehouseOutDetailId: info.ID,
- // CancelOutDetailId: cancelInfo.ID,
- // ProductDate: info.ProductDate,
- // ExpireDate: info.ExpiryDate,
- // StorehouseId: houseConfig.StorehouseOutInfo,
- // OverCount: flush_count,
- // }
- // service.CreateStockFlowOne(flow)
- //
- // //退库数量增加
- // service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
- // //出库数量减少
- // service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
- //
- //}
-
- //查询已出库数量
- dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
-
- if prescribingNumber < dialysisInfo.Count {
- //改变数量
- service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
- }
-
- if prescribingNumber >= dialysisInfo.Count {
- //删除出库表
- service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
- }
-
- goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
- var flush_count_one int64
- for _, it := range goodList {
- flush_count_one += it.StockCount
- }
-
- //更新库存
- msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
- fmt.Println("msgerrkonde23332323", msgerrkonde)
-
- //更新基础库库存
- service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
-
- }
- }
- }
- }
- err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
- fmt.Println(err)
- }
- err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
- fmt.Println(err)
- if len(advices) > 0 {
- for _, item := range advices {
- redis := service.RedisClient()
- keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keyFive, "", time.Second)
- keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyOne, "", time.Second)
- redis.Close()
-
- }
- }
- if c.GetAdminUserInfo().CurrentOrgId == 10387 {
-
- if len(advices) > 0 {
- for _, item := range advices {
- creater := c.GetAdminUserInfo().AdminUser.Id
- service.DrugAutoAddCancelInfo(item, creater)
- }
- }
-
- } else {
- if drugOutConfig.IsOpen == 1 {
- if len(advices) > 0 {
- for _, item := range advices {
- creater := c.GetAdminUserInfo().AdminUser.Id
- service.DrugAutoAddCancelInfo(item, creater)
- }
- }
- }
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- return
-
- }
-
- func (c *HisApiController) DeleteDoctorAdvice() {
- id, _ := c.GetInt64("id")
- advice, _ := service.GetHisDoctorAdvicesById(id)
-
- //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
-
- drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
-
- //已收费和已发药的限制逻辑
- isCharge := false
- isMedicine := false
- new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
-
- //获取今天该患者所有处方,判断是否发药或者收费
- new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
- for _, item := range new_prescriptions {
- if item.IsMedicine == 1 {
- isMedicine = true
- }
- }
- for _, item := range new_prescriptions {
- if item.OrderStatus == 4 {
- isCharge = true
- }
- }
-
- if isMedicine {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
- return
- }
-
- if isCharge {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
- return
- }
-
- advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
- for _, item := range advices {
- if item.IsMedicine == 1 {
- isMedicine = true
- }
- }
-
- if isMedicine {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
- return
- }
- if new_prescription.ID > 0 {
- if new_prescription.OrderStatus == 2 {
- isCharge = true
- }
- }
-
- if isCharge {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
- return
- }
- //已收费和已发药的限制逻辑
-
- err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
- redis := service.RedisClient()
- keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keyFive, "", time.Second)
- keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyOne, "", time.Second)
-
- defer redis.Close()
-
- if err == nil {
- if c.GetAdminUserInfo().CurrentOrgId == 10387 {
- //查询是否在处方中出库
- openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
-
- if openConfig.IsOpen != 1 {
-
- //判断该医嘱是否执行了
- if advice.ExecutionState == 1 {
- creater := c.GetAdminUserInfo().AdminUser.Id
- service.DrugAutoAddCancelInfo(&advice, creater)
- }
- }
-
- //开启保存处方扣减功能
- if openConfig.IsOpen == 1 {
- creater := c.GetAdminUserInfo().AdminUser.Id
- service.DrugAutoAddCancelInfo(&advice, creater)
- }
- } else {
-
- if drugOutConfig.IsOpen == 1 {
-
- //查询是否在处方中出库
- openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
-
- if openConfig.IsOpen != 1 {
-
- //判断该医嘱是否执行了
- if advice.ExecutionState == 1 {
- creater := c.GetAdminUserInfo().AdminUser.Id
- service.DrugAutoAddCancelInfo(&advice, creater)
-
- }
-
- }
-
- //开启保存处方扣减功能
- if openConfig.IsOpen == 1 {
- creater := c.GetAdminUserInfo().AdminUser.Id
- service.DrugAutoAddCancelInfo(&advice, creater)
-
- }
- }
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- return
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
-
- func (c *HisApiController) DeleteProject() {
- id, _ := c.GetInt64("id")
- adminInfo := c.GetAdminUserInfo()
- project, _ := service.GetHisProjectByID(id)
- // var consumable models.DialysisBeforePrepare
- _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
- //耗材保存处方出库
- goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
- isCharge := false
- isMedicine := false
- new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
- new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
- for _, item := range new_prescriptions {
- if item.IsMedicine == 1 {
- isMedicine = true
- }
- }
- for _, item := range new_prescriptions {
- if item.OrderStatus == 4 {
- isCharge = true
- }
- }
- if isMedicine {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
- return
- }
- if isCharge {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
- return
- }
-
- if new_prescription.ID > 0 {
- if new_prescription.OrderStatus == 2 {
- isCharge = true
- }
- }
-
- if isCharge {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
- return
- }
-
- service.DeletePrintInfo(id)
- label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
- label.Status = 0
- service.CreateHisLabelRecord(&label)
-
- if goodOutConfig.IsOpen != 1 {
- if stockConfig.IsOpen == 1 {
- if project.Type == 2 {
- err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
- fmt.Println(err)
- }
-
- if project.Type == 3 && project.IsOut == 1 {
- houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
- good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
- f_count, _ := strconv.ParseFloat(project.Count, 64)
-
- operation_time := time.Now().Unix()
- creater := adminInfo.AdminUser.Id
- //创建退库单
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
- total = total + 1
- orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
-
- cancelStock := models.CancelStock{
- OrderNumber: orderNumber,
- OperaTime: operation_time,
- OrgId: adminInfo.CurrentOrgId,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- ReturnTime: project.RecordDate,
- Type: 1,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- }
- _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
- if msgerrkonde == gorm.ErrRecordNotFound {
- service.AddSigleCancelStock(&cancelStock)
- }
- cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
- floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
- prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
- //获取出库数据
- info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
-
- manufacturer, _ := service.GetManufactureById(info.Manufacturer)
- deaerler, _ := service.GetDealerById(info.Dealer)
- if info.ID > 0 {
- cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
- if info.Count >= prescribingNumber {
- cancelStockInfo := models.CancelStockInfo{
- GoodId: project.ProjectId,
- CancelStockId: cancel.ID,
- GoodTypeId: good.GoodTypeId,
- Count: prescribingNumber,
- Price: info.Price,
- Total: 0,
- ProductDate: info.ProductDate,
- ExpiryDate: info.ExpiryDate,
- Ctime: time.Now().Unix(),
- Status: 1,
- OrgId: adminInfo.CurrentOrgId,
- OrderNumber: cancel.OrderNumber,
- Type: 0,
- Dealer: deaerler.DealerName,
- Manufacturer: manufacturer.ManufacturerName,
- Number: info.Number,
- RegisterAccount: "",
- Remark: "",
- WarehouseInfoId: info.WarehouseInfotId,
- PatientId: info.PatientId,
- RecordDate: info.SysRecordTime,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- }
-
- service.CreateCancelStockInfoOne(&cancelStockInfo)
- //回退库存
- service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
- //退库数量增加
- service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
- //出库数量减少
- service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
- }
- if info.Count < prescribingNumber {
- cancelStockInfo := models.CancelStockInfo{
- GoodId: project.ProjectId,
- CancelStockId: cancel.ID,
- GoodTypeId: good.GoodTypeId,
- Count: info.Count,
- Price: info.Price,
- Total: 0,
- ProductDate: info.ProductDate,
- ExpiryDate: info.ExpiryDate,
- Ctime: time.Now().Unix(),
- Status: 1,
- OrgId: adminInfo.CurrentOrgId,
- OrderNumber: cancel.OrderNumber,
- Type: 0,
- Dealer: deaerler.DealerName,
- Manufacturer: manufacturer.ManufacturerName,
- Number: info.Number,
- RegisterAccount: "",
- Remark: "",
- WarehouseInfoId: info.WarehouseInfotId,
- PatientId: info.PatientId,
- RecordDate: info.SysRecordTime,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- }
-
- service.CreateCancelStockInfoOne(&cancelStockInfo)
- //回退库存
- service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
- //退库数量增加
- service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
- //出库数量减少
- service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
- }
-
- goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
- var over_count int64
- for _, it := range goodList {
- over_count += it.StockCount
- }
- if info.Count >= prescribingNumber {
- flow := models.VmStockFlow{
- WarehousingId: info.WarehouseInfotId,
- GoodId: project.ProjectId,
- Number: info.Number,
- LicenseNumber: info.LicenseNumber,
- Count: prescribingNumber,
- UserOrgId: adminInfo.CurrentOrgId,
- PatientId: project.PatientId,
- SystemTime: info.SysRecordTime,
- ConsumableType: 7,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: info.WarehouseOutId,
- WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
- IsEdit: 0,
- CancelStockId: cancel.ID,
- CancelOrderNumber: cancel.OrderNumber,
- Manufacturer: manufacturer.ID,
- Dealer: 0,
- Creator: adminInfo.AdminUser.Id,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: info.Price,
- WarehousingDetailId: info.WarehouseInfotId,
- WarehouseOutDetailId: info.ID,
- CancelOutDetailId: cancelInfo.ID,
- ProductDate: info.ProductDate,
- ExpireDate: info.ExpiryDate,
- StorehouseId: houseConfig.StorehouseOutInfo,
- OverCount: over_count,
- }
- service.CreateStockFlowOne(flow)
- }
-
- if info.Count < prescribingNumber {
- flow := models.VmStockFlow{
- WarehousingId: info.WarehouseInfotId,
- GoodId: project.ProjectId,
- Number: info.Number,
- LicenseNumber: info.LicenseNumber,
- Count: info.Count,
- UserOrgId: adminInfo.CurrentOrgId,
- PatientId: project.PatientId,
- SystemTime: info.SysRecordTime,
- ConsumableType: 7,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: info.WarehouseOutId,
- WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
- IsEdit: 0,
- CancelStockId: cancel.ID,
- CancelOrderNumber: cancel.OrderNumber,
- Manufacturer: manufacturer.ID,
- Dealer: 0,
- Creator: adminInfo.AdminUser.Id,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: info.Price,
- WarehousingDetailId: info.WarehouseInfotId,
- WarehouseOutDetailId: info.ID,
- CancelOutDetailId: cancelInfo.ID,
- ProductDate: info.ProductDate,
- ExpireDate: info.ExpiryDate,
- StorehouseId: houseConfig.StorehouseOutInfo,
- OverCount: over_count,
- }
- service.CreateStockFlowOne(flow)
- }
-
- //查询已出库数量
- dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
-
- if prescribingNumber < dialysisInfo.Count {
- //改变数量
- service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
- }
-
- if prescribingNumber >= dialysisInfo.Count {
- //删除出库表
- service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
- }
-
- //更新剩余库存
- service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
-
- //查询今日该患者开了多少耗材
- //projectList, _ := service.GetHisPrepscritionByPatientId(info.PatientId, project.ProjectId, info.SysRecordTime)
- //
- //var total_count int64
- //var cha_count int64
- //for _, item := range projectList {
- // count, _ := strconv.ParseInt(item.Count, 10, 64)
- // total_count += count
- //}
- //
- ////查询今日该耗材退库数量
- //cancelInfoOne, _ := service.GetCancelStockInfoByPatientId(info.PatientId, project.ProjectId, info.SysRecordTime)
- //var cancel_count int64
- //for _, items := range cancelInfoOne {
- // cancel_count += items.Count
- //}
- //
- //cha_count = total_count - cancel_count
- //
- //if total_count > cancel_count {
- //
- // out, err := service.FindStockOutByIsSys(adminInfo.CurrentOrgId, 1, info.SysRecordTime)
- // if err == gorm.ErrRecordNotFound {
- // //没有记录,则创建出库单
- // timeStr := time.Now().Format("2006-01-02")
- // timeArr := strings.Split(timeStr, "-")
- // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
- // total = total + 1
- // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- // number = number + total
- // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
- // warehouseOut := models.WarehouseOut{
- // WarehouseOutOrderNumber: warehousing_out_order,
- // OperationTime: time.Now().Unix(),
- // OrgId: adminInfo.CurrentOrgId,
- // Creater: creater,
- // Ctime: time.Now().Unix(),
- // Status: 1,
- // WarehouseOutTime: info.SysRecordTime,
- // Dealer: 0,
- // Manufacturer: 0,
- // Type: 1,
- // IsSys: 1,
- // StorehouseId: houseConfig.StorehouseOutInfo,
- // }
- // err := service.AddSigleWarehouseOut(&warehouseOut)
- // if err != nil {
- // utils.TraceLog("创建出库单失败 err = %v", err)
- // return
- // }
- // prepare := &models.DialysisBeforePrepare{
- // UserOrgId: adminInfo.CurrentOrgId,
- // PatientId: info.PatientId,
- // RecordDate: info.SysRecordTime,
- // GoodId: project.ProjectId,
- // GoodTypeId: info.GoodTypeId,
- // Count: cha_count,
- // StorehouseId: houseConfig.StorehouseOutInfo,
- // }
- // //出库
- // service.ConsumablesDelivery(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &warehouseOut, cha_count)
- // } else if err == nil {
- // prepare := &models.DialysisBeforePrepare{
- // UserOrgId: adminInfo.CurrentOrgId,
- // PatientId: info.PatientId,
- // RecordDate: info.SysRecordTime,
- // GoodId: project.ProjectId,
- // GoodTypeId: info.GoodTypeId,
- // Count: cha_count,
- // StorehouseId: houseConfig.StorehouseOutInfo,
- // }
- // //出库
- // service.ConsumablesDelivery(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &out, cha_count)
- // }
- //
- //}
-
- stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
- var total_count_one int64
- for _, it := range stockList {
- total_count_one += it.StockCount
- }
- //基础库插入数据
- service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
-
- goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
- var flush_count int64
- for _, it := range goodListOne {
- flush_count += it.StockCount
- }
- errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
- if errs != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: project.UserOrgId,
- Errcode: "手动出库更新剩余出库失败",
- GoodId: project.ProjectId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creater,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
- }
- err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
- fmt.Println(err)
- } else {
- err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
- fmt.Println(err)
- }
-
- }
- }
-
- if goodOutConfig.IsOpen == 1 {
-
- if project.Type == 3 {
- houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
- good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
- f_count, _ := strconv.ParseFloat(project.Count, 64)
-
- operation_time := time.Now().Unix()
- creater := adminInfo.AdminUser.Id
- //创建退库单
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
- total = total + 1
- orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
-
- cancelStock := models.CancelStock{
- OrderNumber: orderNumber,
- OperaTime: operation_time,
- OrgId: adminInfo.CurrentOrgId,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- ReturnTime: project.RecordDate,
- Type: 1,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- }
- _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
- if msgerrkonde == gorm.ErrRecordNotFound {
- service.AddSigleCancelStock(&cancelStock)
- }
- cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
- floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
- prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
- //获取出库数据
- info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
-
- manufacturer, _ := service.GetManufactureById(info.Manufacturer)
- deaerler, _ := service.GetDealerById(info.Dealer)
- if info.ID > 0 {
- cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
- if info.Count >= prescribingNumber {
- cancelStockInfo := models.CancelStockInfo{
- GoodId: project.ProjectId,
- CancelStockId: cancel.ID,
- GoodTypeId: good.GoodTypeId,
- Count: prescribingNumber,
- Price: info.Price,
- Total: 0,
- ProductDate: info.ProductDate,
- ExpiryDate: info.ExpiryDate,
- Ctime: time.Now().Unix(),
- Status: 1,
- OrgId: adminInfo.CurrentOrgId,
- OrderNumber: cancel.OrderNumber,
- Type: 0,
- Dealer: deaerler.DealerName,
- Manufacturer: manufacturer.ManufacturerName,
- Number: info.Number,
- RegisterAccount: "",
- Remark: "",
- WarehouseInfoId: info.WarehouseInfotId,
- PatientId: info.PatientId,
- RecordDate: info.SysRecordTime,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- }
-
- service.CreateCancelStockInfoOne(&cancelStockInfo)
- //回退库存
- service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
- //退库数量增加
- service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
- //出库数量减少
- service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
- }
- if info.Count < prescribingNumber {
- cancelStockInfo := models.CancelStockInfo{
- GoodId: project.ProjectId,
- CancelStockId: cancel.ID,
- GoodTypeId: good.GoodTypeId,
- Count: info.Count,
- Price: info.Price,
- Total: 0,
- ProductDate: info.ProductDate,
- ExpiryDate: info.ExpiryDate,
- Ctime: time.Now().Unix(),
- Status: 1,
- OrgId: adminInfo.CurrentOrgId,
- OrderNumber: cancel.OrderNumber,
- Type: 0,
- Dealer: deaerler.DealerName,
- Manufacturer: manufacturer.ManufacturerName,
- Number: info.Number,
- RegisterAccount: "",
- Remark: "",
- WarehouseInfoId: info.WarehouseInfotId,
- PatientId: info.PatientId,
- RecordDate: info.SysRecordTime,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- }
-
- service.CreateCancelStockInfoOne(&cancelStockInfo)
- //回退库存
- service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
- //退库数量增加
- service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
- //出库数量减少
- service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
- }
-
- goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
- var over_count int64
- for _, it := range goodList {
- over_count += it.StockCount
- }
- if info.Count >= prescribingNumber {
- flow := models.VmStockFlow{
- WarehousingId: info.WarehouseInfotId,
- GoodId: project.ProjectId,
- Number: info.Number,
- LicenseNumber: info.LicenseNumber,
- Count: prescribingNumber,
- UserOrgId: adminInfo.CurrentOrgId,
- PatientId: project.PatientId,
- SystemTime: info.SysRecordTime,
- ConsumableType: 7,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: info.WarehouseOutId,
- WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
- IsEdit: 0,
- CancelStockId: cancel.ID,
- CancelOrderNumber: cancel.OrderNumber,
- Manufacturer: manufacturer.ID,
- Dealer: 0,
- Creator: adminInfo.AdminUser.Id,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: info.Price,
- WarehousingDetailId: info.WarehouseInfotId,
- WarehouseOutDetailId: info.ID,
- CancelOutDetailId: cancelInfo.ID,
- ProductDate: info.ProductDate,
- ExpireDate: info.ExpiryDate,
- StorehouseId: houseConfig.StorehouseOutInfo,
- OverCount: over_count,
- }
- service.CreateStockFlowOne(flow)
- }
-
- if info.Count < prescribingNumber {
- flow := models.VmStockFlow{
- WarehousingId: info.WarehouseInfotId,
- GoodId: project.ProjectId,
- Number: info.Number,
- LicenseNumber: info.LicenseNumber,
- Count: info.Count,
- UserOrgId: adminInfo.CurrentOrgId,
- PatientId: project.PatientId,
- SystemTime: info.SysRecordTime,
- ConsumableType: 7,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: info.WarehouseOutId,
- WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
- IsEdit: 0,
- CancelStockId: cancel.ID,
- CancelOrderNumber: cancel.OrderNumber,
- Manufacturer: manufacturer.ID,
- Dealer: 0,
- Creator: adminInfo.AdminUser.Id,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: info.Price,
- WarehousingDetailId: info.WarehouseInfotId,
- WarehouseOutDetailId: info.ID,
- CancelOutDetailId: cancelInfo.ID,
- ProductDate: info.ProductDate,
- ExpireDate: info.ExpiryDate,
- StorehouseId: houseConfig.StorehouseOutInfo,
- OverCount: over_count,
- }
- service.CreateStockFlowOne(flow)
- }
-
- //查询已出库数量
- dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
-
- if prescribingNumber < dialysisInfo.Count {
- //改变数量
- service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
- }
-
- if prescribingNumber >= dialysisInfo.Count {
- //删除出库表
- service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
- }
-
- //更新剩余库存
- service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
-
- stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
- var total_count_one int64
- for _, it := range stockList {
- total_count_one += it.StockCount
- }
- //基础库插入数据
- service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
-
- goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
- var flush_count int64
- for _, it := range goodListOne {
- flush_count += it.StockCount
- }
- errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
- if errs != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: project.UserOrgId,
- Errcode: "手动出库更新剩余出库失败",
- GoodId: project.ProjectId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creater,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
- }
- err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
- fmt.Println(err)
- } else {
- err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
- fmt.Println(err)
- }
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- return
-
- }
-
- func (c *HisApiController) CreateHisAdditionalCharge() {
- his_patient_id, _ := c.GetInt64("his_patient_id")
- patient_id, _ := c.GetInt64("patient_id")
- record_date := c.GetString("record_date")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adminInfo := c.GetAdminUserInfo()
- recordDateTime := theTime.Unix()
- dataBody := make(map[string]interface{}, 0)
- err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var additions []*models.HisAdditionalCharge
- if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
- additions, _ := dataBody["addition"].([]interface{})
- if len(additions) > 0 {
- for _, item := range additions {
- items := item.(map[string]interface{})
-
- if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
- utils.ErrorLog("item_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- item_id := int64(items["item_id"].(float64))
-
- if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
- utils.ErrorLog("item_name")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- item_name := items["item_name"].(string)
-
- if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
- utils.ErrorLog("price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- price, _ := strconv.ParseFloat(items["price"].(string), 64)
-
- ctime := time.Now().Unix()
- additional := &models.HisAdditionalCharge{
- PatientId: patient_id,
- HisPatientId: his_patient_id,
- UserOrgId: adminInfo.CurrentOrgId,
- RecordDate: recordDateTime,
- CreatedTime: ctime,
- UpdatedTime: ctime,
- Modifier: adminInfo.AdminUser.Id,
- Creator: adminInfo.AdminUser.Id,
- Price: price,
- ItemName: item_name,
- ItemId: item_id,
- Status: 1,
- }
- additions = append(additions, additional)
- }
- }
- }
- for _, item := range additions {
- service.CreateAddtionalCharge(item)
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "创建成功",
- })
- }
-
- func (c *HisApiController) CreateHisPatientCaseHistory() {
-
- blood_fat := c.GetString("blood_fat")
- bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
-
- blood_sugar := c.GetString("blood_sugar")
- bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
-
- chief_conplaint := c.GetString("chief_conplaint")
-
- dbp := c.GetString("dbp")
- dbpfloat, _ := strconv.ParseFloat(dbp, 64)
- delivery_way, _ := c.GetInt64("delivery_way")
- diagnostic := c.GetString("diagnostic")
-
- family_history := c.GetString("family_history")
-
- height := c.GetString("height")
- history_of_present_illness := c.GetString("history_of_present_illness")
- is_infect, _ := c.GetInt64("is_infect")
-
- past_history := c.GetString("past_history")
- patient_id, _ := c.GetInt64("patient_id")
- his_patient_id, _ := c.GetInt64("his_patient_id")
-
- personal_history := c.GetString("personal_history")
- pulse := c.GetString("pulse")
- pulsefloat, _ := strconv.ParseFloat(pulse, 64)
- sbp := c.GetString("sbp")
- sbpfloat, _ := strconv.ParseFloat(sbp, 64)
- heightfloat, _ := strconv.ParseFloat(height, 64)
- sicktype := c.GetString("sick_type")
-
- sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
- symptom := c.GetString("symptom")
- sick_date := c.GetString("sick_date")
- temperatures := c.GetString("temperature")
-
- temperature, _ := strconv.ParseFloat(temperatures, 64)
- record_date := c.GetString("record_date")
- breathing := c.GetString("breathing")
- doctor_advice := c.GetString("doctor_advice")
- remark := c.GetString("remark")
- breathingfloat, _ := strconv.ParseFloat(breathing, 64)
-
- sick, _ := c.GetInt64("sick")
- diagnose, _ := c.GetInt64("diagnose")
- //id, _ := c.GetInt64("id")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- allergic_history := c.GetString("allergic_history")
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDateTime := theTime.Unix()
-
- sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- sickTimes := sickTime.Unix()
- ctime := time.Now().Unix()
-
- primary_disease := c.GetString("primary_disease")
- confirm_failure_date := c.GetString("confirm_failure_date")
- confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
- drug_allergy_history := c.GetString("drug_allergy_history")
- physical_examination := c.GetString("physical_examination")
- special_inspection := c.GetString("special_inspection")
- lab_apparatus := c.GetString("lab_apparatus")
- caseHistory := models.HisPatientCaseHistory{
- HisPatientId: his_patient_id,
- PatientId: patient_id,
- Temperature: temperature,
- BloodSugar: bloodsugarfloat,
- Pulse: pulsefloat,
- Sbp: sbpfloat,
- Dbp: dbpfloat,
- Height: heightfloat,
- BloodFat: bloodfatfloat,
- SickType: sick_type,
- Symptom: symptom,
- SickDate: sickTimes,
- IsInfect: is_infect,
- HistoryOfPresentIllness: history_of_present_illness,
- PastHistory: past_history,
- Doctor: c.GetAdminUserInfo().AdminUser.Id,
- ChiefConplaint: chief_conplaint,
- PersonalHistory: personal_history,
- FamilyHistory: family_history,
- Diagnostic: diagnostic,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- Status: 1,
- Ctime: ctime,
- Mtime: ctime,
- RecordDate: recordDateTime,
- DeliveryWay: delivery_way,
- Breathing: breathingfloat,
- DoctorAdvice: doctor_advice,
- Remark: remark,
- Sick: sick,
- Diagnose: diagnose,
- AllergicHistory: allergic_history,
- PrimaryDisease: primary_disease,
- ConfirmFailureDate: confirm_failure_date_time.Unix(),
- DrugAllergyHistory: drug_allergy_history,
- PhysicalExamination: physical_examination,
- SpecialInspection: special_inspection,
- LabApparatus: lab_apparatus,
- }
- //查询该患者是否有病历
- _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
- if errcodes == gorm.ErrRecordNotFound {
- err = service.SaveHisPatientCaseHistory(&caseHistory)
- historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "caseHistory": caseHistory,
- "historyInfo": historyInfo,
- })
- return
- } else if errcodes == nil {
- err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
- historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "caseHistory": caseHistory,
- "historyInfo": historyInfo,
- })
- }
-
- //查询该患者是否有病历
- //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
- //if errcode == gorm.ErrRecordNotFound {
- // err = service.SaveHisPatientCaseHistory(caseHistory)
- // if err != nil {
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "保存成功",
- // })
- // }
- //} else if errcode == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
- // return
- //}
-
- }
- func (c *HisApiController) GetHisPatientCaseHistoryList() {
- patient_id, _ := c.GetInt64("patient_id", 0)
- adminUser := c.GetAdminUserInfo()
- caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": caseHistorys,
- })
-
- }
- func (c *HisApiController) GetHisPatientCaseHistory() {
- record_date, _ := c.GetInt64("record_date", 0)
- patient_id, _ := c.GetInt64("patient_id", 0)
- admin := c.GetAdminUserInfo()
- info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
- case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
- c.ServeSuccessJSON(map[string]interface{}{
- "info": info,
- "case_history": case_history,
- })
-
- }
- func (c *HisApiController) CreateCaseHistoryTemplate() {
- template_name := c.GetString("template_name")
- template_remark := c.GetString("template_remark")
- doctor := c.GetAdminUserInfo().AdminUser.Id
- diagnostic := c.GetString("diagnostic")
- chief_conplaint := c.GetString("chief_conplain")
- history_of_present_illness := c.GetString("history_of_present_illness")
- past_history := c.GetString("past_history")
- personal_history := c.GetString("personal_history")
- family_history := c.GetString("family_history")
- user_name := c.GetString("user_name")
- doctor_advice := c.GetString("doctor_advice")
- remark := c.GetString("remark")
- //record_date := c.GetString("record_date")
- //fmt.Println("record_date--------",record_date)
- //timeLayout := "2006-01-02"
- //loc, _ := time.LoadLocation("Local")
- //
- //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- //if err != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- //}
- //recordDateTime := theTime.Unix()
-
- ctime := time.Now().Unix()
-
- template := models.HisCaseHistoryTemplate{
- HistoryOfPresentIllness: history_of_present_illness,
- PastHistory: past_history,
- ChiefConplaint: chief_conplaint,
- PersonalHistory: personal_history,
- FamilyHistory: family_history,
- Diagnostic: diagnostic,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- Status: 1,
- Ctime: ctime,
- Mtime: ctime,
- RecordDate: time.Now().Unix(),
- TemplateName: template_name,
- TemplateRemark: template_remark,
- Creator: doctor,
- Modifier: doctor,
- UserName: user_name,
- DoctorAdvice: doctor_advice,
- Remark: remark,
- }
-
- err := service.SaveHisPatientCaseHistoryTemplate(template)
-
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "保存成功",
- })
-
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
-
- }
- func (c *HisApiController) GetCaseHistoryTemplate() {
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- keyword := c.GetString("keyword")
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- admin := c.GetAdminUserInfo()
- template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
- //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "template": template,
- //"history": history,
- })
-
- }
-
- func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
-
- if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
- utils.ErrorLog("drug_name")
- return enums.ErrorCodeParamWrong
- }
- adviceName, _ := json["drug_name"].(string)
- if len(adviceName) == 0 {
- utils.ErrorLog("len(advice_name) == 0")
- return enums.ErrorCodeParamWrong
- }
- advice.AdviceName = adviceName
- adviceDesc, _ := json["advice_desc"].(string)
- advice.AdviceDesc = adviceDesc
- if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
- drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
- advice.DrugSpec = drugSpec
- }
- if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
- remark, _ := json["remark"].(string)
- advice.Remark = remark
- }
- if json["id"] == nil {
- advice.DrugId = 0
- } else {
- if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
- drug_id := int64(json["id"].(float64))
- advice.DrugId = drug_id
- }
- }
- if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
- advice_id := int64(json["advice_id"].(float64))
- advice.ID = advice_id
- if advice.ID > 0 {
- hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
- if err == nil {
- if hisAdvice.ID > 0 {
- advice.ExecutionTime = hisAdvice.ExecutionTime
- advice.ExecutionStaff = hisAdvice.ExecutionStaff
- advice.ExecutionState = hisAdvice.ExecutionState
- advice.CheckTime = hisAdvice.CheckTime
- advice.Checker = hisAdvice.Checker
- advice.CheckState = hisAdvice.CheckState
- advice.StartTime = hisAdvice.StartTime
- advice.FeedetlSn = hisAdvice.FeedetlSn
-
- }
- }
- }
- }
-
- //
- //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
- // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
- // advice.ExecutionTime = execution_time
- //}
- //
- //
- //
- //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
- // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
- // advice.ExecutionStaff = execution_staff
- //}
- //
- //
- //
- //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
- // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
- // advice.ExecutionState = execution_state
- //}
- //
- //
- //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
- // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
- // advice.CheckTime = check_time
- //}
- //
- //
- //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
- // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
- // advice.CheckState = check_state
- //}
- //
- //
- //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
- // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
- // advice.Checker = checker
- //}
- //
- //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
- // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
- // advice.StartTime = start_time
- //}
-
- if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
- drugSpecUnit, _ := json["min_unit"].(string)
- advice.DrugSpecUnit = drugSpecUnit
- }
- if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
- singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
- advice.SingleDose = singleDose
- }
- if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
- singleDoseUnit, _ := json["single_dose_unit"].(string)
- advice.SingleDoseUnit = singleDoseUnit
- }
- if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
- prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
- advice.PrescribingNumber = prescribingNumber
- }
- if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
- prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
- advice.PrescribingNumberUnit = prescribingNumberUnit
- }
- if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
- deliveryWay, _ := json["delivery_way"].(string)
- advice.DeliveryWay = deliveryWay
- }
- if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
- executionFrequency, _ := json["execution_frequency"].(string)
- advice.ExecutionFrequency = executionFrequency
- }
-
- if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
- price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
- advice.Price = price
- }
- if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
- med_list_codg, _ := json["medical_insurance_number"].(string)
- advice.MedListCodg = med_list_codg
- }
- if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
- day := int64(json["day"].(float64))
- advice.Day = day
- }
- return 0
- }
-
- func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
- if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
- id := int64(json["id"].(float64))
- project.ID = id
- historyProject, _ := service.GetHisProjectByID(id)
- project.FeedetlSn = historyProject.FeedetlSn
-
- }
- if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
- project_id := int64(json["project_id"].(float64))
- project.ProjectId = project_id
-
- }
- // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
- // price := int64(json["price"].(float64))
- // formatInt_price := strconv.FormatInt(price, 10)
- // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
- // project.Price = float_price
- // }
- if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
- price, _ := strconv.ParseFloat(json["price"].(string), 64)
- project.Price = price
- }
-
- if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
- total, _ := json["total"].(string)
- project.Count = total
- }
-
- if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
- medical_code, _ := json["medical_code"].(string)
- project.MedListCodg = medical_code
- }
- if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
- single_dose, _ := json["single_dose"].(string)
- project.SingleDose = single_dose
- }
-
- if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
- delivery_way, _ := json["delivery_way"].(string)
- project.DeliveryWay = delivery_way
- }
- if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
- execution_frequency, _ := json["execution_frequency"].(string)
- project.ExecutionFrequency = execution_frequency
- }
- if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
- remark, _ := json["remark"].(string)
- project.Remark = remark
- }
- if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
- day, _ := json["number_days"].(string)
- project.Day = day
- }
-
- if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
- unit, _ := json["unit"].(string)
- project.Unit = unit
- }
- return 0
- }
-
- func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
- if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
- id := int64(json["id"].(float64))
- historyAddtions, _ := service.GetHisAdditionByID(id)
- additionalCharge.ID = id
- additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
- }
- if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
- item_id := int64(json["item_id"].(float64))
- additionalCharge.ItemId = item_id
- config, _ := service.GetAdditionChargeByID(org_id, item_id)
- if config.ID > 0 {
- if len(config.Code) > 0 {
- additionalCharge.MedListCodg = config.Code
- }
- }
- }
- // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
- // price := int64(json["price"].(float64))
- // formatInt_price := strconv.FormatInt(price, 10)
- // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
- // additionalCharge.Price = float_price
- // }
-
- //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
- // price := int64(json["price"].(float64))
- // formatInt_price := strconv.FormatInt(price, 10)
- // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
- // additionalCharge.Price = float_price
- //}
-
- if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
- price, _ := strconv.ParseFloat(json["price"].(string), 64)
- additionalCharge.Price = price
- }
- if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
- count, _ := json["count"].(string)
- counts, _ := strconv.ParseInt(count, 10, 64)
- additionalCharge.Count = counts
- }
- if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
- item_name, _ := json["item_name"].(string)
- additionalCharge.ItemName = item_name
- }
-
- return 0
- }
-
- func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
-
- if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
- utils.ErrorLog("drug_name")
- return enums.ErrorCodeParamWrong
- }
- adviceName, _ := json["drug_name"].(string)
- if len(adviceName) == 0 {
- utils.ErrorLog("len(advice_name) == 0")
- return enums.ErrorCodeParamWrong
- }
- advice.AdviceName = adviceName
- adviceDesc, _ := json["advice_desc"].(string)
- advice.AdviceDesc = adviceDesc
- if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
- drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
- advice.DrugSpec = drugSpec
- }
- if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
- remark, _ := json["remark"].(string)
- advice.Remark = remark
- }
- if json["id"] == nil {
- advice.DrugId = 0
- } else {
- if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
- drug_id := int64(json["id"].(float64))
- advice.DrugId = drug_id
- }
- }
-
- if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
- groupno := int64(json["groupno"].(float64))
- advice.Groupno = groupno
- }
-
- if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
- hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
- advice.HospApprFlag = hosp_appr_flag
- }
-
- if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
- prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
- advice.PrescribingNumber = prescribingNumber
- }
-
- //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
- // frequency_type := int64(json["frequency_type"].(float64))
- // advice.FrequencyType = frequency_type
- //}
- //
- //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
- // day_count := int64(json["day_count"].(float64))
- // advice.DayCount = day_count
- //}
- //
- //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
- // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
- // week_day, _ := json["week_day"].(string)
- // advice.WeekDay = week_day
- //}
-
- if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
- drugSpecUnit, _ := json["min_unit"].(string)
- advice.DrugSpecUnit = drugSpecUnit
- }
- if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
- singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
- advice.SingleDose = singleDose
- }
- if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
- singleDoseUnit, _ := json["single_dose_unit"].(string)
- advice.SingleDoseUnit = singleDoseUnit
- }
-
- if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
- deliveryWay, _ := json["delivery_way"].(string)
- advice.DeliveryWay = deliveryWay
- }
- if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
- executionFrequency, _ := json["execution_frequency"].(string)
- advice.ExecutionFrequency = executionFrequency
- }
-
- if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
- price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
- advice.Price = price
- }
- if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
- med_list_codg, _ := json["medical_insurance_number"].(string)
- advice.MedListCodg = med_list_codg
- }
- if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
- day := int64(json["day"].(float64))
- advice.Day = day
- }
-
- if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
- prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
- advice.PrescribingNumberUnit = prescribingNumberUnit
- }
-
- if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
- advice_id := int64(json["advice_id"].(float64))
- advice.ID = advice_id
- if advice.ID > 0 {
- hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
- if err == nil {
- if hisAdvice.ID > 0 {
-
- advice.ExecutionTime = hisAdvice.ExecutionTime
- advice.ExecutionStaff = hisAdvice.ExecutionStaff
- advice.ExecutionState = hisAdvice.ExecutionState
- advice.CheckTime = hisAdvice.CheckTime
- advice.Checker = hisAdvice.Checker
- advice.CheckState = hisAdvice.CheckState
- advice.StartTime = hisAdvice.StartTime
- advice.HospApprFlag = hisAdvice.HospApprFlag
- advice.IsMedicine = hisAdvice.IsMedicine
- if hisAdvice.UserOrgId == 10028 {
- if hisAdvice.DeliveryWay != advice.DeliveryWay || hisAdvice.ExecutionFrequency != advice.ExecutionFrequency || hisAdvice.Day != advice.Day || hisAdvice.PrescribingNumber != advice.PrescribingNumber || hisAdvice.Price != advice.Price || hisAdvice.Remark != advice.Remark || hisAdvice.PrescribingNumberUnit != advice.PrescribingNumberUnit {
- advice.ExecutionTime = 0
- advice.ExecutionStaff = 0
- advice.ExecutionState = 2
- advice.CheckTime = 0
- advice.Checker = 0
- advice.CheckState = 2
- }
- } else {
- if hisAdvice.SingleDose != advice.SingleDose || hisAdvice.DeliveryWay != advice.DeliveryWay || hisAdvice.ExecutionFrequency != advice.ExecutionFrequency || hisAdvice.Day != advice.Day || hisAdvice.PrescribingNumber != advice.PrescribingNumber || hisAdvice.Price != advice.Price || hisAdvice.Remark != advice.Remark || hisAdvice.PrescribingNumberUnit != advice.PrescribingNumberUnit {
- advice.ExecutionTime = 0
- advice.ExecutionStaff = 0
- advice.ExecutionState = 2
- advice.CheckTime = 0
- advice.Checker = 0
- advice.CheckState = 2
- }
- }
-
- //advice.Groupno = hisAdvice.Groupno
-
- }
- }
- }
- }
-
- //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
- //
- //if drugStockConfig.IsOpen == 1 {
- //
- // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
- // if advice.ID == 0 { //医嘱不存在
- // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
- // drug.Total = drug.Total - advice.PrescribingNumber
- // service.UpdateBaseDrugLib(&drug)
- //
- // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
- // num := advice.PrescribingNumber * float64(drug.MinNumber)
- // drug.Total = drug.Total - num
- // service.UpdateBaseDrugLib(&drug)
- // }
- //
- // } else if advice.ID > 0 { //医嘱存在
- // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
- // var num float64
- //
- // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
- // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
- // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
- // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
- // drug.Total = drug.Total + num
- // service.UpdateBaseDrugLib(&drug)
- // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
- // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
- // drug.Total = drug.Total - num
- // service.UpdateBaseDrugLib(&drug)
- // }
- // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
- // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
- // if num2 > advice.PrescribingNumber {
- // num = num2 - advice.PrescribingNumber
- // drug.Total = drug.Total + num
- // service.UpdateBaseDrugLib(&drug)
- // } else if num2 < advice.PrescribingNumber {
- // num = advice.PrescribingNumber - num2
- // drug.Total = drug.Total - num
- // service.UpdateBaseDrugLib(&drug)
- // }
- //
- // }
- //
- // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
- // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
- // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
- // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
- // if num1 > num2 {
- // num = num1 - num2
- // drug.Total = drug.Total + num
- // service.UpdateBaseDrugLib(&drug)
- // } else if num1 < num2 {
- // num = num2 - num1
- // drug.Total = drug.Total - num
- // service.UpdateBaseDrugLib(&drug)
- // }
- //
- // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
- // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
- // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
- // if hisAdvice.PrescribingNumber > num2 {
- // num = hisAdvice.PrescribingNumber - num2
- // drug.Total = drug.Total + num
- // service.UpdateBaseDrugLib(&drug)
- // } else if num2 < advice.PrescribingNumber {
- // num = num2 - hisAdvice.PrescribingNumber
- // drug.Total = drug.Total - num
- // service.UpdateBaseDrugLib(&drug)
- // }
- //
- // }
- // }
- // }
- //}
-
- //
- //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
- // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
- // advice.ExecutionTime = execution_time
- //}
- //
- //
- //
- //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
- // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
- // advice.ExecutionStaff = execution_staff
- //}
- //
- //
- //
- //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
- // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
- // advice.ExecutionState = execution_state
- //}
- //
- //
- //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
- // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
- // advice.CheckTime = check_time
- //}
- //
- //
- //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
- // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
- // advice.CheckState = check_state
- //}
- //
- //
- //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
- // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
- // advice.Checker = checker
- //}
- //
- //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
- // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
- // advice.StartTime = start_time
- //}
-
- return 0
- }
-
- func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
- project.ExecutionStaff = 0
- project.ExecutionState = 2
- project.ExecutionTime = 0
- project.Checker = 0
- project.CheckState = 2
- project.CheckTime = 0
- if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
- id := int64(json["id"].(float64))
- project.ID = id
- temp_project, _ := service.GetHisPrescriptionProjectByID(id)
- project.ExecutionStaff = temp_project.ExecutionStaff
- project.ExecutionState = temp_project.ExecutionState
- project.ExecutionTime = temp_project.ExecutionTime
- project.Checker = temp_project.Checker
- project.CheckState = temp_project.CheckState
- project.CheckTime = temp_project.CheckTime
- project.TeamId = temp_project.TeamId
- }
- if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
- types := int64(json["type"].(float64))
- project.Type = types
- }
- if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
- project_id := int64(json["project_id"].(float64))
- project.ProjectId = project_id
-
- }
-
- if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
- team_id := int64(json["team_id"].(float64))
- project.TeamId = team_id
-
- }
-
- if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
- price, _ := strconv.ParseFloat(json["price"].(string), 64)
- project.Price = price
- }
-
- if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
- total, _ := json["total"].(string)
- //totals, _ := strconv.ParseInt(total, 10, 64)
- project.Count = total
- }
-
- if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
- medical_code, _ := json["medical_code"].(string)
- project.MedListCodg = medical_code
- }
- if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
- single_dose, _ := json["single_dose"].(string)
- project.SingleDose = single_dose
- }
-
- if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
- delivery_way, _ := json["delivery_way"].(string)
- project.DeliveryWay = delivery_way
- }
- if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
- execution_frequency, _ := json["execution_frequency"].(string)
- project.ExecutionFrequency = execution_frequency
- }
- if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
- remark, _ := json["remark"].(string)
- project.Remark = remark
- }
- if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
- day, _ := json["number_days"].(string)
- project.Day = day
- }
-
- if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
- unit, _ := json["unit"].(string)
- project.Unit = unit
- }
-
- //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
- // frequency_type := int64(json["frequency_type"].(float64))
- // project.FrequencyType = frequency_type
- //}
- //
- //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
- // day_count := int64(json["day_count"].(float64))
- // project.DayCount = day_count
- //}
- //
- //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
- // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
- // week_day, _ := json["week_day"].(string)
- // project.WeekDay = week_day
- //}
-
- //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
- //
- //if project.ID == 0 {
- // if stockConfig.IsOpen == 1 {
- // if project.Type == 3 {
- // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
- // f_count, _ := strconv.ParseFloat(project.Count, 64)
- // good.Total = good.Total - f_count
- // service.UpdateGoodInfo(&good)
- // }
- // }
- //
- //} else {
- // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
- //
- // if stockConfig.IsOpen == 1 {
- // if project.Type == 3 {
- // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
- // if project.Count < temp_project.Count {
- // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
- // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
- //
- // other_count := f_count_two - f_count_one
- // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
- // good.Total = good.Total + other_count_two
- // service.UpdateGoodInfo(&good)
- // } else if project.Count > temp_project.Count {
- // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
- // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
- //
- // other_count := f_count_one - f_count_two
- // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
- // good.Total = good.Total - other_count_two
- // service.UpdateGoodInfo(&good)
- // }
- //
- // }
- // }
- //
- //}
-
- return 0
- }
-
- func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
- if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
- id := int64(json["id"].(float64))
- additionalCharge.ID = id
- }
-
- if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
- item_id := int64(json["item_id"].(float64))
- additionalCharge.ItemId = item_id
- config, _ := service.GetAdditionChargeByID(org_id, item_id)
- if config.ID > 0 {
- if len(config.Code) > 0 {
- additionalCharge.MedListCodg = config.Code
- }
- }
- }
- // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
- // price := int64(json["price"].(float64))
- // formatInt_price := strconv.FormatInt(price, 10)
- // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
- // additionalCharge.Price = float_price
- // }
-
- //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
- // price := int64(json["price"].(float64))
- // formatInt_price := strconv.FormatInt(price, 10)
- // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
- // additionalCharge.Price = float_price
- //}
-
- if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
- price, _ := strconv.ParseFloat(json["price"].(string), 64)
- additionalCharge.Price = price
- }
- if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
- count, _ := json["count"].(string)
- counts, _ := strconv.ParseInt(count, 10, 64)
- additionalCharge.Count = counts
- }
- if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
- item_name, _ := json["item_name"].(string)
- additionalCharge.ItemName = item_name
- }
-
- return 0
- }
-
- func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
-
- if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
- utils.ErrorLog("drug_name")
- return enums.ErrorCodeParamWrong
- }
- adviceName, _ := json["drug_name"].(string)
- if len(adviceName) == 0 {
- utils.ErrorLog("len(advice_name) == 0")
- return enums.ErrorCodeParamWrong
- }
- advice.AdviceName = adviceName
- adviceDesc, _ := json["advice_desc"].(string)
- advice.AdviceDesc = adviceDesc
- if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
- drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
- advice.DrugSpec = drugSpec
- }
- if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
- remark, _ := json["remark"].(string)
- advice.Remark = remark
- }
- if json["id"] == nil {
- advice.DrugId = 0
- } else {
- if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
- drug_id := int64(json["id"].(float64))
- advice.DrugId = drug_id
- }
- }
-
- if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
- drugSpecUnit, _ := json["min_unit"].(string)
- advice.DrugSpecUnit = drugSpecUnit
- }
- if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
- singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
- advice.SingleDose = singleDose
- }
- if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
- singleDoseUnit, _ := json["single_dose_unit"].(string)
- advice.SingleDoseUnit = singleDoseUnit
- }
- if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
- prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
- advice.PrescribingNumber = prescribingNumber
- }
- if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
- prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
- advice.PrescribingNumberUnit = prescribingNumberUnit
- }
- if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
- deliveryWay, _ := json["delivery_way"].(string)
- advice.DeliveryWay = deliveryWay
- }
- if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
- executionFrequency, _ := json["execution_frequency"].(string)
- advice.ExecutionFrequency = executionFrequency
- }
-
- if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
- price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
- advice.Price = price
- }
- if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
- med_list_codg, _ := json["medical_insurance_number"].(string)
- advice.MedListCodg = med_list_codg
- }
- if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
- day := int64(json["day"].(float64))
- advice.Day = day
- }
-
- return 0
- }
-
- func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
- if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
- types := int64(json["type"].(float64))
- project.Type = types
- }
- if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
- project_id := int64(json["project_id"].(float64))
- project.ProjectId = project_id
- }
-
- if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
- price, _ := strconv.ParseFloat(json["price"].(string), 64)
- project.Price = price
- }
-
- if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
- total, _ := json["total"].(string)
- //totals, _ := strconv.ParseInt(total, 10, 64)
- project.Count = total
- }
-
- if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
- medical_code, _ := json["medical_code"].(string)
- project.MedListCodg = medical_code
- }
- if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
- single_dose, _ := json["single_dose"].(string)
- project.SingleDose = single_dose
- }
-
- if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
- delivery_way, _ := json["delivery_way"].(string)
- project.DeliveryWay = delivery_way
- }
- if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
- execution_frequency, _ := json["execution_frequency"].(string)
- project.ExecutionFrequency = execution_frequency
- }
- if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
- remark, _ := json["remark"].(string)
- project.Remark = remark
- }
- if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
- day, _ := json["number_days"].(string)
- project.Day = day
- }
-
- if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
- unit, _ := json["unit"].(string)
- project.Unit = unit
- }
- return 0
- }
-
- func (c *HisApiController) GetHisOrderList() {
- page, _ := c.GetInt64("page", -1)
- limit, _ := c.GetInt64("limit", -1)
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- types, _ := c.GetInt64("type", 0)
- keywords := c.GetString("keywords")
- p_type, _ := c.GetInt64("p_type", 0)
- sort_type, _ := c.GetInt64("sort_type", 0)
- charge_type, _ := c.GetInt64("charge_type", 0)
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- //fmt.Println(err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- adminUser := c.GetAdminUserInfo()
- org_id := adminUser.CurrentOrgId
- order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time, charge_type)
-
- for _, item := range order {
- info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
- item.DoctorName = info.Doctor
- item.DepartmentName = info.XtHisDepartment.Name
- }
-
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "order": order,
- "total": total,
- })
-
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- }
-
- func (c *HisApiController) GetHisOrder() {
- patient_id, _ := c.GetInt64("patient_id", 0)
- number := c.GetString("number")
- adminInfo := c.GetAdminUserInfo()
- order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
- prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
-
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "order": order,
- "prescription": prescriptions,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- }
-
- func (c *HisApiController) GetHisPrescriptionList() {
- record_date := c.GetString("record_date")
- keywords := c.GetString("keywords")
- page, _ := c.GetInt64("page")
- limit, _ := c.GetInt64("limit")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDateTime := theTime.Unix()
- adminInfo := c.GetAdminUserInfo()
- prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit)
-
- //adminInfo := c.GetAdminUserInfo()
- //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
- //fmt.Println(prescriptionOrder)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "order": prescriptionOrder,
- "total": total,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- }
-
- func (c *HisApiController) GetHisPrescriptionInfo() {
- id, _ := c.GetInt64("id")
- adminInfo := c.GetAdminUserInfo()
- prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
- prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "order": prescriptionOrder,
- "prescription": prescription,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- }
-
- func (c *HisApiController) GetMedicalInsuranceConfig() {
- adminUser := c.GetAdminUserInfo()
- config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "config": config,
- })
-
- }
-
- type ResultTwo struct {
- ErrMsg interface{} `json:"err_msg"`
- InfRefmsgid string `json:"inf_refmsgid"`
- Infcode int64 `json:"infcode"`
- Output struct {
- Baseinfo struct {
- Age float64 `json:"age"`
- Brdy string `json:"brdy"`
- Certno string `json:"certno"`
- Gend string `json:"gend"`
- Naty string `json:"naty"`
- PsnCertType string `json:"psn_cert_type"`
- PsnName string `json:"psn_name"`
- PsnNo string `json:"psn_no"`
- } `json:"baseinfo"`
- Idetinfo []interface{} `json:"idetinfo"`
- Iinfo []struct {
- Balc float64 `json:"balc"`
- CvlservFlag string `json:"cvlserv_flag"`
- EmpName string `json:"emp_name"`
- InsuplcAdmdvs string `json:"insuplc_admdvs"`
- Insutype string `json:"insutype"`
- PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
- PausInsuDate interface{} `json:"paus_insu_date"`
- PsnInsuDate string `json:"psn_insu_date"`
- PsnInsuStas string `json:"psn_insu_stas"`
- PsnType string `json:"psn_type"`
- } `json:"insuinfo"`
- } `json:"output"`
- RefmsgTime string `json:"refmsg_time"`
- RespondTime string `json:"respond_time"`
- Signtype interface{} `json:"signtype"`
- WarnInfo interface{} `json:"warn_info"`
- }
- type ResultThree struct {
- Cainfo interface{} `json:"cainfo"`
- ErrMsg interface{} `json:"err_msg"`
- InfRefmsgid string `json:"inf_refmsgid"`
- Infcode int64 `json:"infcode"`
- Output struct {
- Data struct {
- IptOtpNo string `json:"ipt_otp_no"`
- MdtrtID string `json:"mdtrt_id"`
- PsnNo string `json:"psn_no"`
- } `json:"data"`
- } `json:"output"`
- RefmsgTime string `json:"refmsg_time"`
- RespondTime string `json:"respond_time"`
- Signtype interface{} `json:"signtype"`
- WarnMsg interface{} `json:"warn_msg"`
- }
- type ResultFour struct {
- Cainfo string `json:"cainfo"`
- ErrMsg string `json:"err_msg"`
- InfRefmsgid string `json:"inf_refmsgid"`
- Infcode int64 `json:"infcode"`
- Output struct {
- Result []struct {
- BasMednFlag string `json:"bas_medn_flag"`
- ChldMedcFlag string `json:"chld_medc_flag"`
- ChrgitmLv string `json:"chrgitm_lv"`
- Cnt float64 `json:"cnt"`
- DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
- DrtReimFlag string `json:"drt_reim_flag"`
- FeedetlSn string `json:"feedetl_sn"`
- FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
- HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
- InscpScpAmt float64 `json:"inscp_scp_amt"`
- ListSpItemFlag string `json:"list_sp_item_flag"`
- LmtUsedFlag string `json:"lmt_used_flag"`
- MedChrgitmType string `json:"med_chrgitm_type"`
- Memo string `json:"memo"`
- OverlmtAmt float64 `json:"overlmt_amt"`
- PreselfpayAmt float64 `json:"preselfpay_amt"`
- Pric float64 `json:"pric"`
- PricUplmtAmt float64 `json:"pric_uplmt_amt"`
- SelfpayProp float64 `json:"selfpay_prop"`
- } `json:"result"`
- } `json:"output"`
- RefmsgTime string `json:"refmsg_time"`
- RespondTime string `json:"respond_time"`
- Signtype string `json:"signtype"`
- WarnMsg string `json:"warn_msg"`
- }
- type ResultFive struct {
- Insutype string `json:"insutype"`
- }
- type ResultSix struct {
- Cainfo interface{} `json:"cainfo"`
- ErrMsg interface{} `json:"err_msg"`
- InfRefmsgid string `json:"inf_refmsgid"`
- Infcode int64 `json:"infcode"`
- Output struct {
- } `json:"output"`
- RefmsgTime string `json:"refmsg_time"`
- RespondTime string `json:"respond_time"`
- Signtype interface{} `json:"signtype"`
- WarnMsg interface{} `json:"warn_msg"`
- }
- type ResultSeven struct {
- Cainfo string `json:"cainfo"`
- ErrMsg string `json:"err_msg"`
- InfRefmsgid string `json:"inf_refmsgid"`
- Infcode int64 `json:"infcode"`
- Output struct {
- Setldetail []interface{} `json:"setldetail"`
- Setlinfo struct {
- AcctMulaidPay float64 `json:"acct_mulaid_pay"`
- AcctPay float64 `json:"acct_pay"`
- ActPayDedc float64 `json:"act_pay_dedc"`
- Age float64 `json:"age"`
- Balc float64 `json:"balc"`
- Brdy string `json:"brdy"`
- Certno string `json:"certno"`
- ClrOptins string `json:"clr_optins"`
- ClrType string `json:"clr_type"`
- ClrWay string `json:"clr_way"`
- CvlservFlag string `json:"cvlserv_flag"`
- CvlservPay float64 `json:"cvlserv_pay"`
- FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
- FundPaySumamt float64 `json:"fund_pay_sumamt"`
- Gend string `json:"gend"`
- HifesPay float64 `json:"hifes_pay"`
- HifmiPay float64 `json:"hifmi_pay"`
- HifobPay float64 `json:"hifob_pay"`
- HifpPay float64 `json:"hifp_pay"`
- HospPartAmt float64 `json:"hosp_part_amt"`
- InscpScpAmt float64 `json:"inscp_scp_amt"`
- Insutype string `json:"insutype"`
- MafPay float64 `json:"maf_pay"`
- MdtrtCertType string `json:"mdtrt_cert_type"`
- MdtrtID string `json:"mdtrt_id"`
- MedType string `json:"med_type"`
- MedfeeSumamt float64 `json:"medfee_sumamt"`
- MedinsSetlID string `json:"medins_setl_id"`
- Naty string `json:"naty"`
- OthPay float64 `json:"oth_pay"`
- OverlmtSelfpay float64 `json:"overlmt_selfpay"`
- PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
- PreselfpayAmt float64 `json:"preselfpay_amt"`
- PsnCashPay float64 `json:"psn_cash_pay"`
- PsnCertType string `json:"psn_cert_type"`
- PsnName string `json:"psn_name"`
- PsnNo string `json:"psn_no"`
- PsnPartAmt float64 `json:"psn_part_amt"`
- PsnType string `json:"psn_type"`
- SetlID string `json:"setl_id"`
- SetlTime string `json:"setl_time"`
- } `json:"setlinfo"`
- } `json:"output"`
- RefmsgTime string `json:"refmsg_time"`
- RespondTime string `json:"respond_time"`
- Signtype interface{} `json:"signtype"`
- WarnMsg interface{} `json:"warn_msg"`
- }
-
- type ResultEight struct {
- Cainfo string `json:"cainfo"`
- ErrMsg string `json:"err_msg"`
- InfRefmsgid string `json:"inf_refmsgid"`
- Infcode int64 `json:"infcode"`
- Output struct {
- Stmtinfo struct {
- SetlOptins string `json:"setl_optins"`
- StmtRslt string `json:"stmt_rslt"`
- StmtRsltDscr string `json:"stmt_rslt_dscr"`
- } `json:"stmtinfo"`
- } `json:"output"`
- RefmsgTime string `json:"refmsg_time"`
- RespondTime string `json:"respond_time"`
- Signtype interface{} `json:"signtype"`
- WarnMsg interface{} `json:"warn_msg"`
- }
-
- type ResultNine struct {
- Cainfo string `json:"cainfo"`
- ErrMsg string `json:"err_msg"`
- InfRefmsgid string `json:"inf_refmsgid"`
- Infcode int64 `json:"infcode"`
- Output struct {
- FileQuryNo string `json:"file_qury_no"`
- } `json:"output"`
- RefmsgTime string `json:"refmsg_time"`
- RespondTime string `json:"respond_time"`
- Signtype interface{} `json:"signtype"`
- WarnMsg interface{} `json:"warn_msg"`
- }
-
- type ResultTen struct {
- Cainfo string `json:"cainfo"`
- ErrMsg string `json:"err_msg"`
- InfRefmsgid string `json:"inf_refmsgid"`
- Infcode int64 `json:"infcode"`
- Output struct {
- DldEndtime string `json:"dld_endtime"`
- FileQuryNo string `json:"file_qury_no"`
- Filename string `json:"filename"`
- } `json:"output"`
- RefmsgTime string `json:"refmsg_time"`
- RespondTime string `json:"respond_time"`
- Signtype interface{} `json:"signtype"`
- WarnMsg interface{} `json:"warn_msg"`
- }
-
- type ResultEleven struct {
- Cainfo string `json:"cainfo"`
- ErrMsg string `json:"err_msg"`
- InfRefmsgid string `json:"inf_refmsgid"`
- Infcode int64 `json:"infcode"`
- Output struct {
- Setlinfo struct {
- FixmedinsName string `json:"fixmedins_name"`
- FixmedinsCode string `json:"fixmedins_code"`
- PsnNo string `json:"psn_no"`
- PsnName string `json:"psn_name"`
- HifobPay float64 `json:"hifob_pay"`
- Gend string `json:"gend"`
- Brdy string `json:"brdy"`
- PsnCertType string `json:"psn_cert_type"`
- PsnType string `json:"psn_type"`
- EmpName string `json:"emp_name"`
- Certno string `json:"certno"`
- Insutype string `json:"insutype"`
- MedfeeSumamt float64 `json:"medfee_sumamt"`
- FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
- OverlmtSelfpay float64 `json:"overlmt_selfpay"`
- PreselfpayAmt float64 `json:"preselfpay_amt"`
- InscpScpAmt float64 `json:"inscp_scp_amt"`
- ActPayDedc float64 `json:"act_pay_dedc"`
- HifpPay float64 `json:"hifp_pay"`
- PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
- CvlservPay float64 `json:"cvlserv_pay"`
- HifesPay float64 `json:"hifes_pay"`
- HifmiPay float64 `json:"hifmi_pay"`
- MafPay float64 `json:"maf_pay"`
- OthPay float64 `json:"oth_pay"`
- FundPaySumamt float64 `json:"fund_pay_sumamt"`
- PsnPay float64 `json:"psn_pay"`
- AcctPay float64 `json:"acct_pay"`
- CashPayamt float64 `json:"cash_payamt"`
- Balc float64 `json:"balc"`
- AcctMulaidPay float64 `json:"acct_mulaid_pay"`
- MedinsSetlId string `json:"medins_setl_id"`
- RefdSetlFlag string `json:"refd_setl_flag"`
- SetlTime string `json:"setl_time"`
- MedType string `json:"med_type"`
- } `json:"setlinfo"`
- } `json:"output"`
- RefmsgTime string `json:"refmsg_time"`
- RespondTime string `json:"respond_time"`
- Signtype interface{} `json:"signtype"`
- WarnMsg interface{} `json:"warn_msg"`
- }
-
- type Custom struct {
- DetItemFeeSumamt string
- Cut string
- FeedetlSn string
- Price string
- MedListCodg string
- Type int64
- AdviceId int64
- ProjectId int64
- ItemId int64
- }
-
- //获取个人信息----挂号-----上传就诊信息
- func (c *HisApiController) GetRegisterInfo() {
- id, _ := c.GetInt64("id")
- record_time := c.GetString("record_time")
- settlementValue, _ := c.GetInt64("settlement_value")
- medical_insurance_card := c.GetString("medical_insurance_card")
- name := c.GetString("name")
- id_card_type, _ := c.GetInt64("id_card_type")
- certificates, _ := c.GetInt64("certificates")
- medical_care, _ := c.GetInt64("medical_care")
- birthday := c.GetString("birthday")
- age, _ := c.GetInt64("age")
- id_card := c.GetString("id_card")
- register_type, _ := c.GetInt64("register")
- doctor, _ := c.GetInt64("doctor")
- department, _ := c.GetInt64("department")
- gender, _ := c.GetInt64("sex")
- phone := c.GetString("phone")
- registration_fee, _ := c.GetFloat("registration_fee")
- medical_expenses, _ := c.GetFloat("medical_expenses")
- social_type, _ := c.GetInt64("social_type")
-
- //diagnosis_id, _ := c.GetInt64("diagnosis")
-
- diagnosis_ids := c.GetString("diagnosis")
-
- sick_type, _ := c.GetInt64("sick_type")
- reg_type := c.GetString("p_type")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
- birthUnix := birthdays.Unix()
-
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDateTime := theTime.Unix()
-
- adminInfo := c.GetAdminUserInfo()
- tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
- if tempPatient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
- return
- }
- var patient service.Patients
- if id == 0 {
- patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
-
- } else {
- patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
-
- }
-
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
- if len(patient.IdCardNo) == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
- return
- }
-
- his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
- if len(his) >= 1 {
- order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
- if len(his) >= 1 && order.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
- return
- }
- }
-
- timeStr := time.Now().Format("2006-01-02 15:04:05")
- fmt.Println(timeStr)
- timeArr := strings.Split(timeStr, " ")
- fmt.Println(timeArr)
-
- timeArrTwo := strings.Split(timeArr[0], "-")
- timeArrThree := strings.Split(timeArr[1], ":")
- var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
-
- lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
-
- if len(lists) == 0 {
- var hisPatient models.XtHisPatient
- hisPatient = models.XtHisPatient{
- Name: name,
- Age: age,
- Gender: gender,
- Birthday: birthUnix,
- Phone: phone,
- MedicalTreatmentType: medical_care,
- IdType: certificates,
- IdCardNo: id_card,
- BalanceAccountsType: settlementValue,
- SocialType: social_type,
- MedicalInsuranceNumber: medical_insurance_card,
- RegisterType: register_type,
- RegisterCost: registration_fee,
- TreatmentCost: medical_expenses,
- AdminUserId: adminInfo.AdminUser.Id,
- UserOrgId: adminInfo.CurrentOrgId,
- Status: 1,
- RecordDate: recordDateTime,
- IsReturn: 1,
- PatientId: patient.ID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Number: str,
- IdCardType: id_card_type,
- Departments: department,
- Doctor: doctor,
- PType: reg_type,
- Diagnosis: diagnosis_ids,
- SickType: sick_type,
- }
- service.CreateHisPatient(&hisPatient)
-
- service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "his_info": hisPatient,
- })
- } else {
- //chrgBchno := rand.Intn(1000000) + 10000
- var hisPatient models.XtHisPatient
- hisPatient = models.XtHisPatient{
- Name: name,
- Age: age,
- Gender: gender,
- Birthday: birthUnix,
- Phone: phone,
- MedicalTreatmentType: medical_care,
- IdType: certificates,
- IdCardNo: id_card,
- BalanceAccountsType: settlementValue,
- SocialType: social_type,
- MedicalInsuranceNumber: medical_insurance_card,
- RegisterType: register_type,
- RegisterCost: registration_fee,
- TreatmentCost: medical_expenses,
- AdminUserId: adminInfo.AdminUser.Id,
- UserOrgId: adminInfo.CurrentOrgId,
- Status: 1,
- RecordDate: recordDateTime,
- IsReturn: 1,
- PatientId: patient.ID,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Number: str,
- IdCardType: id_card_type,
- Departments: department,
- Doctor: doctor,
- PType: reg_type,
- Diagnosis: diagnosis_ids,
- SickType: sick_type,
- }
- service.CreateHisPatient(&hisPatient)
-
- service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "his_info": hisPatient,
- })
-
- }
-
- }
-
- //上传明细----结算
- func (c *HisApiController) GetUploadInfo() {
- id, _ := c.GetInt64("id")
- record_time := c.GetString("record_time")
- his_patient_id, _ := c.GetInt64("his_patient_id")
-
- pay_way, _ := c.GetInt64("pay_way")
- pay_price, _ := c.GetFloat("pay_price")
- pay_card_no := c.GetString("pay_card_no")
- discount_price, _ := c.GetFloat("discount_price")
- preferential_price, _ := c.GetFloat("preferential_price")
- reality_price, _ := c.GetFloat("reality_price")
- found_price, _ := c.GetFloat("found_price")
- medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
- private_price, _ := c.GetFloat("private_price")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
-
- fapiao_code := c.GetString("fapiao_code")
- fapiao_number := c.GetString("fapiao_number")
-
- diagnosis_id := c.GetString("diagnosis")
- sick_type, _ := c.GetInt64("sick_type")
- reg_type, _ := c.GetInt64("p_type")
- order_id, _ := c.GetInt64("order_id")
-
- dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
- tmp_decimal := c.GetString("tmp_decimal")
- var decimal float64 //本次使用的押金
- var errmsg error
- tx := service.XTWriteDB().Begin() //开了事务
- //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
- defer func() {
- if errmsg != nil {
- utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
- tx.Rollback()
- } else {
- tx.Commit()
- }
- }()
- fmt.Println("dec_way", dec_way)
- if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
- return
- }
- if len(tmp_decimal) > 0 {
- if tmp_decimal[0] == 45 {
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
- return
- }
- }
- tt, errs := strconv.ParseFloat(tmp_decimal, 64)
- fmt.Println(errs)
- //if errs != nil {
- // c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金金额错误")
- // return
- //}
- decimal = tt
-
- his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
-
- tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
-
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDateTime := theTime.Unix()
- adminUser := c.GetAdminUserInfo()
- var prescriptions []*models.HisPrescription
-
- var prescriptionsOne []*models.HisPrescription
-
- var start_time int64
- var end_time int64
-
- ids_str := c.GetString("ids")
- ids_arr := strings.Split(ids_str, ",")
- if tempOrder.ID == 0 {
- if settle_accounts_type == 1 { //日结
- fmt.Println(reg_type)
-
- if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
-
- prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
-
- prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
- } else {
- prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
-
- prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
- }
- } else { //月结
-
- start_time_str := c.GetString("start_time")
- end_time_str := c.GetString("end_time")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordStartTime := theStartTime.Unix()
- start_time = recordStartTime
- theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordEndTime := theEndTime.Unix()
- end_time = recordEndTime
- prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
-
- prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
- }
-
- var goods []*models.DialysisBeforePrepareGoods
- var newGoods []*models.NewDialysisBeforePrepareGoods
- var oldGoods []*models.OldDialysisBeforePrepareGoods
- var infos []*models.HisDoctorAdviceInfo
- var infoList []*models.HisDoctorAdviceInfo
- var hisAdvice []*models.HisDoctorAdviceInfo
- var newGoodOne []*models.NewDialysisBeforePrepareGoods
- houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
-
- //判断库存不足
- //结算出库开关
- settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
- if settConfig.IsOpen == 1 {
- //判断库存的地方
- for _, info := range prescriptions {
- if info.Type == 1 {
- infos = append(infos, info.HisDoctorAdviceInfo...)
-
- }
- if info.Type == 2 {
- for _, sumItem := range info.HisPrescriptionProject {
- if sumItem.Type == 3 {
- var good models.DialysisBeforePrepareGoods
- var newGood models.NewDialysisBeforePrepareGoods
- good.GoodId = sumItem.GoodInfo.ID
- good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
- count, _ := strconv.Atoi(sumItem.Count)
- good.Count = int64(count)
- good.StorehouseId = houseConfig.StorehouseOutInfo
- good.ProjectId = sumItem.ID
- goods = append(goods, &good)
-
- newGood.GoodId = sumItem.GoodInfo.ID
- newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
- count2, _ := strconv.Atoi(sumItem.Count)
- newGood.Count = int64(count2)
- newGood.StorehouseId = houseConfig.StorehouseOutInfo
- newGood.ProjectId = sumItem.ID
- newGoods = append(newGoods, &newGood)
- }
- }
- }
- }
-
- for _, info := range prescriptionsOne {
-
- if info.Type == 1 {
- hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
- }
-
- if info.Type == 2 {
- for _, sumItem := range info.HisPrescriptionProject {
- if sumItem.Type == 3 {
- var newGood models.NewDialysisBeforePrepareGoods
-
- newGood.GoodId = sumItem.GoodInfo.ID
- newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
- count2, _ := strconv.Atoi(sumItem.Count)
- newGood.Count = int64(count2)
- newGood.StorehouseId = houseConfig.StorehouseOutInfo
- newGood.ProjectId = sumItem.ID
- newGoodOne = append(newGoodOne, &newGood)
- }
- }
- }
- }
-
- //判断
- for _, itemOne := range infos {
-
- for _, itemTwo := range hisAdvice {
- if itemOne.DrugId == itemTwo.DrugId {
- itemTwo.Child = append(itemTwo.Child, itemOne)
- }
- }
- }
-
- for _, itemTwo := range hisAdvice {
- medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
- var sum_out_count int64
- for _, itemThree := range itemTwo.Child {
- var prescribing_number int64
- stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
- parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
- if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
- prescribing_number = parseIntPrescribingNumber * medical.MinNumber
- }
- if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- prescribing_number = parseIntPrescribingNumber
- }
- if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
- prescribing_number = parseIntPrescribingNumber
- }
-
- sum_out_count += prescribing_number
- }
- drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
-
- fmt.Println("sum_out_count233232323232wo", sum_out_count)
- fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
- if sum_out_count > drugStockOut.FlushCount {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "2",
- "drug": medical,
- })
- return
- }
- }
- fmt.Println("newGoods99999988882os", newGoods)
- for _, itemOne := range newGoods {
- for _, item := range newGoodOne {
- if itemOne.GoodId == item.GoodId {
- item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
- }
- }
- }
-
- for _, item := range newGoodOne {
- var sum_out_count_one int64
- good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
- for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
- sum_out_count_one += itemOne.Count
- }
- list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
- fmt.Println("sum_out_count_one", sum_out_count_one)
- fmt.Println("list.FlushCount", list.FlushCount)
- if sum_out_count_one > list.FlushCount {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "3",
- "good": good,
- })
- return
- }
- }
- }
-
- timestamp := time.Now().Unix()
- tempTime := time.Unix(timestamp, 0)
- timeFormat := tempTime.Format("20060102150405")
- chrgBchno := rand.Intn(100000) + 10000
- chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
- strconv.FormatInt(his.PatientId, 10)
-
- var ids []int64
-
- for _, item := range prescriptions {
- ids = append(ids, item.ID)
- }
- var total float64
-
- for _, item := range prescriptions {
- fmt.Println(item)
- if item.Type == 1 { //药品
- for _, subItem := range item.HisDoctorAdviceInfo {
- total = total + (subItem.Price * subItem.PrescribingNumber)
- }
- }
- if item.Type == 2 { //项目
- for _, subItem := range item.HisPrescriptionProject {
- cnt, _ := strconv.ParseFloat(subItem.Count, 64)
- total = total + (subItem.Price * cnt)
- }
- }
-
- for _, subItem := range item.HisAdditionalCharge {
- total = total + (subItem.Price * float64(subItem.Count))
- }
- }
-
- if reg_type == 1111 || reg_type == 1112 {
- reg_type = 11
- }
-
- tm := time.Unix(time.Now().Unix(), 0)
-
- allTotal := fmt.Sprintf("%.4f", total)
- totals, _ := strconv.ParseFloat(allTotal, 64)
- order := &models.HisOrder{
- UserOrgId: adminUser.CurrentOrgId,
- HisPatientId: his.ID,
- PatientId: id,
- SettleAccountsDate: recordDateTime,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- OrderStatus: 2,
- MdtrtId: his.Number,
- Number: chrg_bchno,
- MedfeeSumamt: totals,
- PayWay: pay_way,
- PayPrice: pay_price,
- MedType: strconv.Itoa(int(reg_type)),
- PayCardNo: pay_card_no,
- DiscountPrice: discount_price,
- PreferentialPrice: preferential_price,
- RealityPrice: reality_price,
- FoundPrice: found_price,
- MedicalInsurancePrice: medical_insurance_price,
- PrivatePrice: private_price,
- SettleEndTime: end_time,
- SettleStartTime: start_time,
- PsnPartAmt: totals,
- PsnCashPay: totals,
- SettleType: settle_accounts_type,
- FaPiaoCode: fapiao_code,
- FaPiaoNumber: fapiao_number,
- Diagnosis: diagnosis_id,
- PType: 2,
- SetlTime: tm.Format("2006-01-02 15:04:05"),
- Decimal: decimal,
- }
- err = service.CreateOrderTX(order, tx)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
- return
- }
-
- var customs []*Custom
- for _, item := range prescriptions {
- if item.Type == 1 { //药品a
- for _, subItem := range item.HisDoctorAdviceInfo {
- cus := &Custom{
- AdviceId: subItem.ID,
- ProjectId: 0,
- DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
- Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
- FeedetlSn: subItem.FeedetlSn,
- Price: fmt.Sprintf("%.4f", subItem.Price),
- MedListCodg: subItem.MedListCodg,
- Type: 1,
- }
- customs = append(customs, cus)
- }
- }
- if item.Type == 2 { //项目
- for _, subItem := range item.HisPrescriptionProject {
- cnt, _ := strconv.ParseFloat(subItem.Count, 64)
- cus := &Custom{
- AdviceId: 0,
- ProjectId: subItem.ID,
- DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
- Cut: fmt.Sprintf("%.4f", cnt),
- FeedetlSn: subItem.FeedetlSn,
- Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
- MedListCodg: subItem.MedListCodg,
- Type: 2,
- }
- customs = append(customs, cus)
- }
- }
- for _, item := range item.HisAdditionalCharge {
- cus := &Custom{
- ItemId: item.ID,
- AdviceId: 0,
- ProjectId: 0,
- DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
- Cut: fmt.Sprintf("%.4f", float64(item.Count)),
- FeedetlSn: item.FeedetlSn,
- Price: fmt.Sprintf("%.4f", float64(item.Price)),
- MedListCodg: item.XtHisAddtionConfig.Code,
- Type: 3,
- }
- customs = append(customs, cus)
- }
- }
-
- for _, item := range customs {
- var advice_id int64 = 0
- var project_id int64 = 0
- var item_id int64 = 0
-
- var types int64 = 0
-
- if item.Type == 1 {
- advice_id = item.AdviceId
- project_id = 0
- item_id = 0
- } else if item.Type == 2 {
- advice_id = 0
- item_id = 0
-
- project_id = item.ProjectId
- } else if item.Type == 3 {
- advice_id = 0
- item_id = item.ItemId
- project_id = 0
- }
- detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
- cut, _ := strconv.ParseFloat(item.Cut, 32)
- pric, _ := strconv.ParseFloat(item.Price, 32)
- info := &models.HisOrderInfo{
- OrderNumber: order.Number,
- UploadDate: time.Now().Unix(),
- AdviceId: advice_id,
- DetItemFeeSumamt: detItemFeeSumamt,
- Cnt: cut,
- Pric: pric,
- PatientId: id,
- Status: 1,
- Mtime: time.Now().Unix(),
- Ctime: time.Now().Unix(),
- UserOrgId: adminUser.CurrentOrgId,
- HisPatientId: his.ID,
- OrderId: order.ID,
- ProjectId: project_id,
- Type: types,
- ItemId: item_id,
- }
- service.CreateOrderInfoTX(info, tx)
- }
- his.Diagnosis = diagnosis_id
- his.SickType = sick_type
- his.RegisterType = reg_type
- his.MedicalTreatmentType = reg_type
- service.UpdataHisPateintTX(&his, tx)
- err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
- err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
- err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
- //判断是否使用了押金
- if dec_way == "true" {
-
- tmpstring := strconv.FormatInt(order.ID, 10)
-
- //扣押金
- errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
- order.Decimal = decimal
- service.UpDateOrderTwo(order)
- if errmsg != nil {
- c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
- //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
- return
- }
- }
-
- if err == nil {
- for _, info := range prescriptions {
- if info.Type == 1 {
- infoList = append(infoList, info.HisDoctorAdviceInfo...)
- }
- if info.Type == 2 {
- for _, sumItem := range info.HisPrescriptionProject {
- if sumItem.Type == 3 {
- var good models.DialysisBeforePrepareGoods
- var newGood models.NewDialysisBeforePrepareGoods
- var oldGood models.OldDialysisBeforePrepareGoods
- good.GoodId = sumItem.GoodInfo.ID
- good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
- count, _ := strconv.Atoi(sumItem.Count)
- good.Count = int64(count)
- good.StorehouseId = houseConfig.StorehouseOutInfo
- good.ProjectId = sumItem.ID
- good.PatientId = sumItem.PatientId
- goods = append(goods, &good)
-
- newGood.GoodId = sumItem.GoodInfo.ID
- newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
- count2, _ := strconv.Atoi(sumItem.Count)
- newGood.Count = int64(count2)
- newGood.StorehouseId = houseConfig.StorehouseOutInfo
- newGood.ProjectId = sumItem.ID
- newGood.PatientId = sumItem.HisPatientId
- newGoods = append(newGoods, &newGood)
-
- oldGood.GoodId = sumItem.GoodInfo.ID
- oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
- count3, _ := strconv.Atoi(sumItem.Count)
- oldGood.Count = int64(count3)
- oldGood.StorehouseId = houseConfig.StorehouseOutInfo
- oldGood.ProjectId = sumItem.ID
- oldGood.RecordDate = sumItem.RecordDate
- oldGood.PatientId = sumItem.HisPatientId
-
- oldGoods = append(oldGoods, &oldGood)
- }
-
- }
-
- }
- }
- if settConfig.IsOpen == 1 {
-
- for _, item := range infoList {
- medical, _ := service.GetBaseDrugMedical(item.DrugId)
- if medical.IsUse == 2 {
- //药品出库
- service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
- //查询默认仓库
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
- //查询默认仓库剩余多少库存
- var sum_count int64
- stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
- for _, its := range stockInfo {
- if its.MaxUnit == medical.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
- service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
- service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
- }
- }
- orgId := c.GetAdminUserInfo().CurrentOrgId
-
- if len(oldGoods) > 0 {
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllWarehouseOut(orgId)
-
- total = total + 1
- warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- number = number + total
- warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
-
- operation_time := time.Now().Unix()
- creater := c.GetAdminUserInfo().AdminUser.Id
- //查询默认出库仓库库存
- storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
- recordDateStr := time.Now().Format("2006-01-02")
- recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- nowtime := recordDate.Unix()
- warehouseOut := models.WarehouseOut{
- WarehouseOutOrderNumber: warehousing_out_order,
- OperationTime: operation_time,
- OrgId: orgId,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- WarehouseOutTime: nowtime,
- Type: 1,
- StorehouseId: storeConfig.StorehouseOutInfo,
- IsCheck: 1,
- OrderId: order.ID,
- IsSys: 5,
- }
- //查询是否生成出库单
- out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
- if out.ID == 0 {
- service.AddSigleWarehouseOut(&warehouseOut)
- }
-
- lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
-
- for _, item := range oldGoods {
- dialyPrepareOne := models.DialysisBeforePrepare{
- GoodTypeId: item.GoodTypeId,
- GoodId: item.GoodId,
- PatientId: his.PatientId,
- RecordDate: item.RecordDate,
- UserOrgId: adminUser.CurrentOrgId,
- Count: item.Count,
- Ctime: time.Now().Unix(),
- Creater: adminUser.AdminUser.Id,
- CommdityCode: item.CommdityCode,
- Status: 1,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
- goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
- //非零用
- if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
- service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
- //查询剩余库存
- goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
- var sum_count int64
- for _, item := range goodList {
- sum_count += item.StockCount
- }
- service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
-
- //耗材
- service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
- }
-
- }
- }
-
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "结算成功",
- })
-
- }
- } else {
- if tempOrder.IsPre > 0 {
- allTotal := fmt.Sprintf("%.2f", tempOrder.MedfeeSumamt)
- totals, _ := strconv.ParseFloat(allTotal, 64)
- tempOrder.OrderStatus = 2
- tempOrder.PayWay = pay_way
- tempOrder.PayPrice = pay_price
- tempOrder.PayCardNo = pay_card_no
- tempOrder.DiscountPrice = discount_price
- tempOrder.PreferentialPrice = preferential_price
- tempOrder.RealityPrice = reality_price
- tempOrder.FoundPrice = found_price
- tempOrder.MedicalInsurancePrice = medical_insurance_price
- tempOrder.PrivatePrice = private_price
- tempOrder.FaPiaoCode = fapiao_code
- tempOrder.FaPiaoNumber = fapiao_number
- tempOrder.PType = 2
- tempOrder.MedfeeSumamt = totals
- tempOrder.Diagnosis = diagnosis_id
- err = service.SaveHisOrder(&tempOrder)
- err = service.UpdataOrderStatusTwo(tempOrder.Number, adminUser.CurrentOrgId)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
- return
- }
- if err == nil {
- houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
- var goods []*models.DialysisBeforePrepareGoods
- var newGoods []*models.NewDialysisBeforePrepareGoods
- var infos []*models.HisDoctorAdviceInfo
- var hisAdvice []*models.HisDoctorAdviceInfo
- var newGoodOne []*models.NewDialysisBeforePrepareGoods
- var infolist []*models.HisDoctorAdviceInfo
- var oldGoods []*models.OldDialysisBeforePrepareGoods
- for _, info := range prescriptions {
- if info.Type == 1 {
- infos = append(infos, info.HisDoctorAdviceInfo...)
- }
- if info.Type == 2 {
- for _, sumItem := range info.HisPrescriptionProject {
- if sumItem.Type == 3 {
- var good models.DialysisBeforePrepareGoods
- var newGood models.NewDialysisBeforePrepareGoods
- good.GoodId = sumItem.GoodInfo.ID
- good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
- count, _ := strconv.Atoi(sumItem.Count)
- good.Count = int64(count)
- good.StorehouseId = houseConfig.StorehouseOutInfo
- good.ProjectId = sumItem.ID
- goods = append(goods, &good)
-
- newGood.GoodId = sumItem.GoodInfo.ID
- newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
- count2, _ := strconv.Atoi(sumItem.Count)
- newGood.Count = int64(count2)
- newGood.StorehouseId = houseConfig.StorehouseOutInfo
- newGood.ProjectId = sumItem.ID
- newGoods = append(newGoods, &newGood)
- }
-
- }
-
- }
- }
-
- settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
- if settConfig.IsOpen == 1 {
-
- //判断库存的地方
- for _, info := range prescriptions {
- if info.Type == 1 {
- infolist = append(infolist, info.HisDoctorAdviceInfo...)
-
- }
- if info.Type == 2 {
- for _, sumItem := range info.HisPrescriptionProject {
- if sumItem.Type == 3 {
- var good models.DialysisBeforePrepareGoods
- var newGood models.NewDialysisBeforePrepareGoods
- var oldGood models.OldDialysisBeforePrepareGoods
- good.GoodId = sumItem.GoodInfo.ID
- good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
- count, _ := strconv.Atoi(sumItem.Count)
- good.Count = int64(count)
- good.StorehouseId = houseConfig.StorehouseOutInfo
- good.ProjectId = sumItem.ID
- goods = append(goods, &good)
-
- newGood.GoodId = sumItem.GoodInfo.ID
- newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
- count2, _ := strconv.Atoi(sumItem.Count)
- newGood.Count = int64(count2)
- newGood.StorehouseId = houseConfig.StorehouseOutInfo
- newGood.ProjectId = sumItem.ID
- newGoods = append(newGoods, &newGood)
-
- oldGood.GoodId = sumItem.GoodInfo.ID
- oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
- count3, _ := strconv.Atoi(sumItem.Count)
- oldGood.Count = int64(count3)
- oldGood.StorehouseId = houseConfig.StorehouseOutInfo
- oldGood.ProjectId = sumItem.ID
- oldGood.RecordDate = sumItem.RecordDate
-
- oldGoods = append(oldGoods, &oldGood)
- }
- }
- }
- }
-
- for _, info := range prescriptionsOne {
- if info.Type == 1 {
- hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
- }
-
- if info.Type == 2 {
- for _, sumItem := range info.HisPrescriptionProject {
- if sumItem.Type == 3 {
- var newGood models.NewDialysisBeforePrepareGoods
-
- newGood.GoodId = sumItem.GoodInfo.ID
- newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
- count2, _ := strconv.Atoi(sumItem.Count)
- newGood.Count = int64(count2)
- newGood.StorehouseId = houseConfig.StorehouseOutInfo
- newGood.ProjectId = sumItem.ID
- newGoodOne = append(newGoodOne, &newGood)
- }
- }
- }
- }
-
- //判断
- for _, itemOne := range infos {
- for _, itemTwo := range hisAdvice {
- if itemOne.DrugId == itemTwo.DrugId {
- itemTwo.Child = append(itemTwo.ChildDoctorAdvice, itemOne)
- }
- }
- }
-
- for _, itemTwo := range hisAdvice {
- medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
- var sum_out_count int64
- for _, itemThree := range itemTwo.Child {
- var prescribing_number int64
- stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
- parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
- if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
- prescribing_number = parseIntPrescribingNumber * medical.MinNumber
- }
- if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- prescribing_number = parseIntPrescribingNumber
- }
- if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
- prescribing_number = parseIntPrescribingNumber
- }
- sum_out_count += prescribing_number
- }
- houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
- drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
-
- if sum_out_count > drugStockOut.FlushCount {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "2",
- "drug": medical,
- })
- return
- }
- }
-
- for _, itemOne := range newGoods {
- for _, item := range newGoodOne {
- if itemOne.ProjectId == item.ProjectId {
- item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, item)
- }
- }
- }
-
- for _, item := range newGoodOne {
- var sum_out_count_one int64
- good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
-
- for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
- sum_out_count_one += itemOne.Count
- }
- list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
- fmt.Println("sum_out_count_one", sum_out_count_one)
- fmt.Println("list.FlushCount", list.FlushCount)
- if sum_out_count_one > list.FlushCount {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "3",
- "good": good,
- })
- return
- }
- }
- for _, item := range infolist {
- service.HisDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item)
- }
- for _, item := range oldGoods {
- dialyPrepareOne := models.DialysisBeforePrepare{
- GoodTypeId: item.GoodTypeId,
- GoodId: item.GoodId,
- PatientId: item.PatientId,
- RecordDate: item.RecordDate,
- UserOrgId: item.UserOrgId,
- Count: item.Count,
- Ctime: time.Now().Unix(),
- Creater: adminUser.AdminUser.Id,
- CommdityCode: item.CommdityCode,
- Status: 1,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
- err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
- }
-
- service.ConsumablesDeliveryTotal(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, goods, newGoods, adminUser.AdminUser.Id)
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "结算成功",
- })
- }
- }
- }
- }
-
- //退款
- func (c *HisApiController) Refund() {
- order_id, _ := c.GetInt64("order_id")
- order, _ := service.GetHisOrderByID(order_id)
- adminUser := c.GetAdminUserInfo()
- orgid := c.GetAdminUserInfo().CurrentOrgId
-
- err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- tmp := strconv.FormatInt(order.ID, 10)
- //当押金不为零时产生退费记录
- if order.Decimal != 0 {
- err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- }
-
- orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
- houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
- var goods []*models.DialysisBeforePrepareGoods
- var newGoods []*models.NewDialysisBeforePrepareGoods
- var infos []*models.HisDoctorAdviceInfo
-
- for _, info := range orders {
- if info.AdviceId > 0 && info.ProjectId == 0 {
- infos = append(infos, &info.HisDoctorAdviceInfo)
- }
- if info.ProjectId > 0 && info.AdviceId == 0 {
- if info.HisPrescriptionProject.Type == 3 {
- var good models.DialysisBeforePrepareGoods
- var newGood models.NewDialysisBeforePrepareGoods
- good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
- good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
- count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
- good.Count = int64(count)
- good.StorehouseId = houseConfig.StorehouseOutInfo
- good.ProjectId = info.HisPrescriptionProject.ID
- good.PatientId = info.PatientId
- good.OrderId = order_id
- goods = append(goods, &good)
-
- newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
- newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
- count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
- newGood.Count = int64(count2)
- newGood.StorehouseId = houseConfig.StorehouseOutInfo
- newGood.ProjectId = info.HisPrescriptionProject.ID
- newGood.RecordDate = order.SettleAccountsDate
- newGood.UserOrgId = order.UserOrgId
- newGood.PatientId = info.PatientId
- newGood.OrderId = order_id
- newGoods = append(newGoods, &newGood)
- }
- }
- }
- settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
- if settConfig.IsOpen == 1 {
- for _, item := range infos {
-
- service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
-
- }
-
- for _, item := range newGoods {
- service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
- }
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "退费成功",
- })
- }
-
- func (c *HisApiController) RefundNumber() {
- his_patient_id, _ := c.GetInt64("id")
- info, _ := service.GetNewHisPatientInfo(his_patient_id)
- info.Status = 0
- count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
- if count > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
- return
- }
-
- err := service.SaveHisPatient(info)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "退号成功",
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- }
-
- func (this *HisApiController) AdditionalCharge() {
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
- his_patient_id := int64(dataBody["his_patient_id"].(float64))
- patient_id := int64(dataBody["patient_id"].(float64))
- medicineData, _ := dataBody["medicineData"].([]interface{})
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- admin_user_id := adminUserInfo.AdminUser.Id
- timeStr := time.Now().Format("2006-01-02")
- timeLayout := "2006-01-02 15:04:05"
- timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
- timenow := timeStringToTime.Unix()
- var additionalCharges []*models.HisAdditionalCharge
- for _, item := range medicineData {
-
- var randNum int
- randNum = rand.Intn(10000) + 1000
- timestamp := time.Now().Unix()
- tempTime := time.Unix(timestamp, 0)
- timeFormat := tempTime.Format("20060102150405")
- p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
-
- items := item.(map[string]interface{})
- money := items["price"].(string)
- item_id_str := items["item_id"].(string)
- name := items["name"].(string)
- id_str := items["id"].(string)
- moneys, _ := strconv.ParseInt(money, 10, 64)
- monStr := strconv.FormatInt(moneys, 10)
- monneyStr, _ := strconv.ParseFloat(monStr, 64)
- item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
- id, _ := strconv.ParseInt(id_str, 10, 64)
- additionalCharge := &models.HisAdditionalCharge{
- ID: id,
- HisPatientId: his_patient_id,
- UserOrgId: orgId,
- PatientId: patient_id,
- RecordDate: timenow,
- Price: monneyStr,
- Status: 1,
- ItemName: name,
- ItemId: item_id,
- AdminUserId: admin_user_id,
- CreatedTime: time.Now().Unix(),
- OrderStatus: 0,
- PrescriptionNumber: "",
- BatchNumber: "",
- FeedetlSn: p_number,
- }
- service.CreateAdditionalCharge(additionalCharge)
-
- additionalCharges = append(additionalCharges, additionalCharge)
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "添加成功",
- "additional_charges": additionalCharges,
- })
- }
-
- func (this *HisApiController) DeleteAddition() {
- id, _ := this.GetInt64("id")
- //TODO 需要判断是否已经结算
- err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- return
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
-
- }
-
- func (this *HisApiController) GetAdminUsers() {
- adminUser := this.GetAdminUserInfo()
- doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "doctors": doctors,
- })
- }
-
- func (this *HisApiController) GetLastOrNextHisPrescription() {
- change_type, _ := this.GetInt64("type", 0)
- record_date := this.GetString("record_time")
- patient_id, _ := this.GetInt64("patient_id", 0)
- p_type, _ := this.GetInt64("p_type", 0)
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
- record_time := theAdviceRecordTime.Unix()
- adminUserInfo := this.GetAdminUserInfo()
- prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
- if err == nil {
- if len(prescriptions) == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
- return
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "prescriptions": prescriptions,
- })
- return
- }
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
-
- func (this *HisApiController) GetCallHisPrescription() {
- patient_id, _ := this.GetInt64("patient_id", 0)
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := this.GetString("start_time")
- startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- end_time := this.GetString("end_time")
- p_type, _ := this.GetInt64("p_type")
-
- endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- adminUserInfo := this.GetAdminUserInfo()
- prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "prescriptions": prescriptions,
- })
- return
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
-
- func (this *HisApiController) GetHisDayPrescription() {
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := this.GetString("start_time")
- patient_id, _ := this.GetInt64("patient_id", 0)
- startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- end_time := this.GetString("end_time")
- p_type, _ := this.GetInt64("p_type")
-
- order_status, _ := this.GetInt64("type")
-
- endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- adminUserInfo := this.GetAdminUserInfo()
-
- var dayHisPrescription []*models.HisPrescription
- var err error
- if order_status == 1 || order_status == 0 {
-
- dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
-
- } else if order_status == 2 {
- dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
-
- }
-
- var settle_total float64
- for _, item := range dayHisPrescription {
- if len(item.HisPrescriptionProject) > 0 {
- for _, subItem := range item.HisPrescriptionProject {
- count, _ := strconv.ParseFloat(subItem.Count, 64)
- total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
- settle_total = settle_total + total
- }
- }
- if len(item.HisDoctorAdviceInfo) > 0 {
- for _, subItem := range item.HisDoctorAdviceInfo {
- total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
- settle_total = settle_total + total
- }
- }
-
- }
- settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
-
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "day_prescription": dayHisPrescription,
- "settle_total": settle_total,
- })
- return
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
-
- func (c *HisApiController) GetHisChargePatientList() {
- record_date := c.GetString("record_date")
- order_status, _ := c.GetInt64("type")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDateTime := theTime.Unix()
- adminInfo := c.GetAdminUserInfo()
- var tempPatients []*service.NewTempPatients
- //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
- if order_status != 2 {
- tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
- } else {
- tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
- }
-
- var patients []*service.NewTempPatients
- var patients_two []*service.NewTempPatients
-
- for _, item := range tempPatients {
- //过滤掉没挂号的和没开处方的
- if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
- patients = append(patients, item)
- }
-
- //过滤掉没挂号的
- if len(item.HisPatient) > 0 {
- patients_two = append(patients_two, item)
- }
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "list": patients,
- "list_two": patients_two,
- })
- }
-
- func (c *HisApiController) GetHisUnRegisterPatientList() {
- record_date := c.GetString("record_date")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDateTime := theTime.Unix()
- adminUser := c.GetAdminUserInfo()
-
- tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
-
- var patients []*service.Patients
- for _, item := range tempPatients {
- if item.HisPatient.ID == 0 {
- patients = append(patients, item)
- }
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "list": patients,
- //"list_two": patients_two,
- })
-
- }
-
- func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
- newArr = make([]*service.Patients, 0)
- for i := 0; i < len(patient); i++ {
- repeat := false
- for j := i + 1; j < len(patient); j++ {
- if patient[i].ID == patient[j].ID {
- repeat = true
- break
- }
- }
- if !repeat {
- newArr = append(newArr, patient[i])
- }
- }
- return
- }
-
- func (c *HisApiController) GetHisChargePatientInfo() {
- patient_id, _ := c.GetInt64("patient_id")
- his_patient_id, _ := c.GetInt64("his_patient_id")
- record_date := c.GetString("record_date")
- //start_time := c.GetString("start_time")
- //end_time := c.GetString("end_time")
- order_status, _ := c.GetInt64("type", 0)
- p_type, _ := c.GetInt64("p_type", 0)
- order_id, _ := c.GetInt64("order_id", 0)
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDateTime := theTime.Unix()
-
- //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- //if err != nil {
- //
- //}
- //startRecordDateTime := startTime.Unix()
- //
- //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- //if err != nil {
- //
- //}
- //endRecordDateTime := endTime.Unix()
-
- admin := c.GetAdminUserInfo()
- his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
- xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
-
- var prescriptions []*models.HisPrescription
- //var unChargeMonthPrescriptions []*models.HisPrescription
-
- order, _ := service.GetHisOrderByID(order_id)
-
- if order_status == 1 || order_status == 0 {
- prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
- } else if order_status == 2 {
- prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
- //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
- }
-
- case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
- patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
-
- lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
-
- doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
- //获取所有科室信息
- department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "his_info": his_patient_info,
- "xt_info": xt_patient_info,
- "prescription": prescriptions,
- "case_history": case_history,
- "info": patientPrescriptionInfo,
- "last_info": lastPatientPrescriptionInfo,
- "order": order,
- "doctors": doctors,
- "department": department,
- })
- return
- }
-
- func (c *HisApiController) GetAllOrderDetail() {
- order_id, _ := c.GetInt64("id", 0)
- order, _ := service.GetHisOrderByID(order_id)
- if order.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
- return
- }
- record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
- org_id := c.GetAdminUserInfo().CurrentOrgId
- adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
- patient, _ := service.GetPatientByID(org_id, order.PatientId)
- order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
- c.ServeSuccessJSON(map[string]interface{}{
- "order": order,
- "order_info": order_info,
- "patient": patient,
- "admin_info": adminInfo,
- "hospital_record": record,
- })
- return
-
- }
-
- func (c *HisApiController) GetAllOrderDetailCollect() {
- order_id, _ := c.GetInt64("id", 0)
-
- order, _ := service.GetHisOrderByID(order_id)
- if order.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
- return
- }
-
- org_id := c.GetAdminUserInfo().CurrentOrgId
- adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
- order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
- patient, _ := service.GetPatientByID(org_id, order.PatientId)
-
- his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
- //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
- record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
-
- var bedCostTotal float64 = 0 //床位总费
- //var bedCostSelfTotal float64 = 0 //床位自费
-
- var operationCostTotal float64 = 0 //手术费
- //var operationCostSelfTotal float64 = 0 //手术费
-
- var otherCostTotal float64 = 0 //其他费用
- //var otherCostSelfTotal float64 = 0 //其他费用
-
- var materialCostTotal float64 = 0 //材料费
- //var materialCostSelfTotal float64 = 0 //材料费
-
- var westernMedicineCostTotal float64 = 0 //西药费
- //var westernMedicineCostSelfTotal float64 = 0 //西药费
-
- var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
- //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
-
- var checkCostTotal float64 = 0 //检查费
- //var checkCostSelfTotal float64 = 0 //检查费
-
- var laboratoryCostTotal float64 = 0 //化验费
- //var laboratoryCostSelfTotal float64 = 0 //化验费
-
- var treatCostTotal float64 = 0 //治疗费用
- //var treatCostSelfTotal float64 = 0 //治疗费用
-
- var zhenChaCostTotal float64 = 0 //其他费用
- //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
-
- decimal.DivisionPrecision = 2
- var BalanceAccountsType int64
- if his.ID > 0 {
- BalanceAccountsType = his.BalanceAccountsType
- } else {
- BalanceAccountsType = record.BalanceAccountsType
- }
- if BalanceAccountsType != 2 {
- for _, item := range order_info {
- if org_id == 10215 {
- if item.MedChrgitmType == "01" { //床位费
- bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
- if item.MedChrgitmType == "02" { //诊察费
- zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //zhenChaCostSelfTotal = zhenChaCostTotal
- }
- if item.MedChrgitmType == "03" { //检查费
- checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- //if item.MedChrgitmType == "02" { //检查费
- // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- //}
-
- if item.MedChrgitmType == "04" { //化验费
- laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
- treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "06" { //手术费
- operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "08" { //材料费
- materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "09" { //西药费
- westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "11" { //中成费
- chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
- otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- } else if org_id == 10188 || org_id == 10217 {
- if item.MedChrgitmType == "01" { //床位费
- bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
- if item.MedChrgitmType == "02" { //诊察费
- zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //zhenChaCostSelfTotal = zhenChaCostTotal
- }
- if item.MedChrgitmType == "03" { //检查费
- laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
-
- //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- //if item.MedChrgitmType == "02" { //检查费
- // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- //}
-
- if item.MedChrgitmType == "04" { //化验费
- laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
- treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "06" { //手术费
- operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "08" { //材料费
- materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "09" { //西药费
- westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "11" { //中成费
- chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
- otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- } else {
-
- if item.MedChrgitmType == "01" { //床位费
- bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
- //if item.MedChrgitmType == "02" { //诊察费
- // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- // //zhenChaCostSelfTotal = zhenChaCostTotal
- //}
-
- if item.MedChrgitmType == "03" { //检查费
- checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- //if item.MedChrgitmType == "02" { //检查费
- // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- //}
-
- if item.MedChrgitmType == "04" { //化验费
- laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
- treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "06" { //手术费
- operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "08" { //材料费
- materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "09" { //西药费
- westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "11" { //中成费
- chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
- otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- }
-
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "order": order,
- "order_info": order_info,
- "patient": patient,
- "admin_info": adminInfo,
- "his_hospital": record,
- "bedCostTotal": bedCostTotal,
- "operationCostTotal": operationCostTotal,
- "otherCostTotal": otherCostTotal,
- "materialCostTotal": materialCostTotal,
- "westernMedicineCostTotal": westernMedicineCostTotal,
- "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
- "checkCostTotal": checkCostTotal,
- "zhenChaCostTotal": zhenChaCostTotal,
- "laboratoryCostTotal": laboratoryCostTotal,
- "treatCostTotal": treatCostTotal,
- })
- } else {
- for _, item := range order_info {
- item.FulamtOwnpayAmt = item.DetItemFeeSumamt
- if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
- item.MedChrgitmType = "09"
- }
- if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
- if item.HisPrescriptionProject.Type == 2 {
- if c.GetAdminUserInfo().CurrentOrgId == 10215 {
- switch item.HisPrescriptionProject.VMHisProject.CostClassify {
- case 0:
- item.MedChrgitmType = "0"
- break
- case 1:
- item.MedChrgitmType = "14"
- break
- case 2:
- item.MedChrgitmType = "05"
-
- break
- case 3:
- item.MedChrgitmType = "03"
-
- break
- case 4:
- item.MedChrgitmType = "03"
-
- break
- case 5:
- item.MedChrgitmType = "08"
-
- break
- case 6:
- item.MedChrgitmType = "14"
-
- break
- case 7:
- item.MedChrgitmType = "14"
-
- break
- case 8:
- item.MedChrgitmType = "03"
- break
- case 9:
- item.MedChrgitmType = "14"
- break
- case 10:
- item.MedChrgitmType = "14"
- break
- case 11:
- item.MedChrgitmType = "06"
- break
- case 12:
- item.MedChrgitmType = "12"
- break
- case 13:
- item.MedChrgitmType = "01"
- break
- case 14:
- item.MedChrgitmType = "04"
- break
- case 15:
- item.MedChrgitmType = "14"
- break
-
- }
-
- } else {
- switch item.HisPrescriptionProject.VMHisProject.CostClassify {
-
- case 1:
- item.MedChrgitmType = "14"
- break
- case 2:
- item.MedChrgitmType = "05"
-
- break
- case 3:
- item.MedChrgitmType = "04"
-
- break
- case 4:
- item.MedChrgitmType = "14"
-
- break
- case 5:
- item.MedChrgitmType = "08"
-
- break
- case 6:
- item.MedChrgitmType = "14"
-
- break
- case 7:
- item.MedChrgitmType = "14"
-
- break
- case 8:
- item.MedChrgitmType = "03"
- break
- case 9:
- item.MedChrgitmType = "14"
- break
- }
- }
- } else if item.HisPrescriptionProject.Type == 3 {
- item.MedChrgitmType = "08"
- }
- }
- }
-
- for _, item := range order_info {
- if org_id == 10215 {
- if item.MedChrgitmType == "01" { //床位费
- bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
- if item.MedChrgitmType == "02" { //诊察费
- zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //zhenChaCostSelfTotal = zhenChaCostTotal
- }
-
- if item.MedChrgitmType == "03" { //检查费
- checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- //if item.MedChrgitmType == "02" { //检查费
- // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- //}
-
- if item.MedChrgitmType == "04" { //化验费
- laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
- treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "06" { //手术费
- operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "08" { //材料费
- materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "09" { //西药费
- westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "11" { //中成费
- chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
- otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- } else {
-
- if item.MedChrgitmType == "01" { //床位费
- bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
- //if item.MedChrgitmType == "02" { //诊察费
- // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- // //zhenChaCostSelfTotal = zhenChaCostTotal
- //}
-
- if item.MedChrgitmType == "03" { //检查费
- checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- //if item.MedChrgitmType == "02" { //检查费
- // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- //}
-
- if item.MedChrgitmType == "04" { //化验费
- laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
- treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "06" { //手术费
- operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "08" { //材料费
- materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "09" { //西药费
- westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "11" { //中成费
- chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
- otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- }
-
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "order": order,
- "order_info": order_info,
- "patient": patient,
- "admin_info": adminInfo,
- "his_hospital": record,
- "bedCostTotal": bedCostTotal,
- "operationCostTotal": operationCostTotal,
- "otherCostTotal": otherCostTotal,
- "materialCostTotal": materialCostTotal,
- "westernMedicineCostTotal": westernMedicineCostTotal,
- "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
- "checkCostTotal": checkCostTotal,
- "zhenChaCostTotal": zhenChaCostTotal,
- "laboratoryCostTotal": laboratoryCostTotal,
- "treatCostTotal": treatCostTotal,
- })
-
- }
- }
-
- func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
- page, _ := c.GetInt64("page")
- limit, _ := c.GetInt64("limit")
- keywords := c.GetString("keywords")
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- //clr_type := c.GetString("clr_type")
- insutype := c.GetString("insutype")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- var theStartTIme int64
- if len(start_time) > 0 {
- theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- theStartTIme = theTime.Unix()
- }
- var theEndtTIme int64
- if len(end_time) > 0 {
- theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- theEndtTIme = theTime.Unix()
- }
-
- if page <= 0 {
- page = 1
- }
- if limit <= 0 {
- limit = 10
- }
- list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
- c.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "list": list,
- })
- return
-
- }
-
- func (c *HisApiController) GetPutOnRecordList() {
- page, _ := c.GetInt64("page")
- limit, _ := c.GetInt64("limit")
- keywords := c.GetString("keywords")
- is_put_on_record, _ := c.GetInt64("is_put_on_record")
-
- if page <= 0 {
- page = 1
- }
- if limit <= 0 {
- limit = 10
- }
- list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
- c.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "list": list,
- })
- return
-
- }
-
- func (c *HisApiController) GetCompareData() {
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- insutype := c.GetString("insutype")
- clr_type := c.GetString("clr_type")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var theStartTIme int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- theStartTIme = 0
- }
- theStartTIme = theTime.Unix()
- }
- var theEndtTIme int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- theEndtTIme = 0
- }
- theEndtTIme = theTime.Unix()
- }
- formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
- fmt.Println(err)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "list": formData,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
-
- }
- }
-
- func (c *HisApiController) GetFaPiaoData() {
- order_id, _ := c.GetInt64("order_id")
- patient_id, _ := c.GetInt64("patient_id")
- number := c.GetString("number")
-
- adminUser := c.GetAdminUserInfo()
- order, _ := service.GetHisOrderByID(order_id)
- orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
-
- patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
-
- department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
-
- his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, number)
-
- his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
-
- patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
-
- var bedCostTotal float64 = 0 //床位总费
- var bedCostSelfTotal float64 = 0 //床位自费
- var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
-
- var operationCostTotal float64 = 0 //手术费
- var operationCostSelfTotal float64 = 0 //手术费
- var operationCostPartSelfTotal float64 = 0 //手术费
-
- var otherCostTotal float64 = 0 //其他费用
- var otherCostSelfTotal float64 = 0 //其他费用
- var otherCostPartSelfTotal float64 = 0 //其他费用
-
- var materialCostTotal float64 = 0 //材料费
- var materialCostSelfTotal float64 = 0 //材料费
- var materialCostPartSelfTotal float64 = 0 //材料费
-
- var westernMedicineCostTotal float64 = 0 //西药费
- var westernMedicineCostSelfTotal float64 = 0 //西药费
- var westernMedicineCostPartSelfTotal float64 = 0 //西药费
-
- var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
- var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
- var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
-
- var checkCostTotal float64 = 0 //检查费
- var checkCostSelfTotal float64 = 0 //检查费
- var checkCostPartSelfTotal float64 = 0 //检查费
-
- var laboratoryCostTotal float64 = 0 //化验费
- var laboratoryCostSelfTotal float64 = 0 //化验费
- var laboratoryCostPartSelfTotal float64 = 0 //化验费
-
- var treatCostTotal float64 = 0 //治疗费用
- var treatCostSelfTotal float64 = 0 //治疗费用
- var treatCostPartSelfTotal float64 = 0 //治疗费用
-
- var zhenChaCostTotal float64 = 0 //其他费用
- var zhenChaCostSelfTotal float64 = 0 //其他费用
- var zhenChaCostPartSelfTotal float64 = 0 //其他费用
-
- decimal.DivisionPrecision = 2
- orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
-
- var balanceAccountsType int64
- if his.ID > 0 {
-
- balanceAccountsType = his.BalanceAccountsType
- } else {
-
- balanceAccountsType = his_hospital_record.BalanceAccountsType
- }
-
- if balanceAccountsType == 2 {
- //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
- for _, item := range orderInfos_two {
- item.FulamtOwnpayAmt = item.DetItemFeeSumamt
- if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
- item.MedChrgitmType = "09"
- }
-
- if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
- if item.HisPrescriptionProject.Type == 2 {
- if c.GetAdminUserInfo().CurrentOrgId == 10215 {
- switch item.HisPrescriptionProject.VMHisProject.CostClassify {
- case 0:
- item.MedChrgitmType = "0"
- break
- case 1:
- item.MedChrgitmType = "14"
- break
- case 2:
- item.MedChrgitmType = "05"
-
- break
- case 3:
- item.MedChrgitmType = "03"
-
- break
- case 4:
- item.MedChrgitmType = "03"
-
- break
- case 5:
- item.MedChrgitmType = "08"
-
- break
- case 6:
- item.MedChrgitmType = "14"
-
- break
- case 7:
- item.MedChrgitmType = "14"
-
- break
- case 8:
- item.MedChrgitmType = "03"
- break
- case 9:
- item.MedChrgitmType = "14"
- break
- case 10:
- item.MedChrgitmType = "14"
- break
- case 11:
- item.MedChrgitmType = "06"
- break
- case 12:
- item.MedChrgitmType = "12"
- break
- case 13:
- item.MedChrgitmType = "01"
- break
- case 14:
- item.MedChrgitmType = "04"
- break
- case 15:
- item.MedChrgitmType = "02"
- break
-
- }
-
- } else {
- switch item.HisPrescriptionProject.VMHisProject.CostClassify {
-
- case 1:
- item.MedChrgitmType = "14"
- break
- case 2:
- item.MedChrgitmType = "05"
-
- break
- case 3:
- item.MedChrgitmType = "03"
-
- break
- case 4:
- item.MedChrgitmType = "03"
-
- break
- case 5:
- item.MedChrgitmType = "08"
-
- break
- case 6:
- item.MedChrgitmType = "14"
-
- break
- case 7:
- item.MedChrgitmType = "14"
-
- break
- case 8:
- item.MedChrgitmType = "03"
- break
- case 9:
- item.MedChrgitmType = "14"
- break
-
- }
-
- }
-
- } else if item.HisPrescriptionProject.Type == 3 {
- item.MedChrgitmType = "08"
- }
- }
- }
-
- for _, item := range orderInfos_two {
- fmt.Println(item.MedChrgitmType)
- if item.MedChrgitmType == "01" { //床位费
- bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- bedCostSelfTotal = bedCostTotal
- }
-
- if item.MedChrgitmType == "02" { //诊察费
- zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- zhenChaCostSelfTotal = zhenChaCostTotal
- }
-
- if item.MedChrgitmType == "03" { //检查费
- checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- checkCostSelfTotal = checkCostTotal
- }
-
- if item.MedChrgitmType == "04" { //化验费
- laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- laboratoryCostSelfTotal = laboratoryCostTotal
- }
-
- if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
- treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- treatCostSelfTotal = treatCostTotal
- }
-
- if item.MedChrgitmType == "06" { //手术费
- treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- operationCostSelfTotal = treatCostTotal
- }
-
- if item.MedChrgitmType == "08" { //材料费
- materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- materialCostSelfTotal = materialCostTotal
- }
-
- if item.MedChrgitmType == "09" { //西药费
- westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- westernMedicineCostSelfTotal = westernMedicineCostTotal
- }
-
- if item.MedChrgitmType == "11" { //中成费
- chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
- }
-
- if c.GetAdminUserInfo().CurrentOrgId == 10106 {
- if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
- otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- otherCostSelfTotal = otherCostTotal
- }
- } else {
- if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
- otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- otherCostSelfTotal = otherCostTotal
- }
-
- }
-
- }
-
- } else {
- for _, item := range orderInfos {
- if item.MedChrgitmType == "01" { //床位费
- bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "02" { //诊察费
- zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
- if item.MedChrgitmType == "03" { //检查费
- laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
-
- }
- } else {
- if item.MedChrgitmType == "03" { //检查费
- checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- }
-
- if item.MedChrgitmType == "04" { //化验费
- laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
-
- }
-
- if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
- treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
-
- }
-
- if item.MedChrgitmType == "06" { //手术费
- operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
- materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "09" { //西药费
- westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "11" { //中成费
- chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
- otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
- otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
- }
-
- }
-
- }
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
- if err != nil {
-
- }
- startRecordDateTime := startTime.Unix()
-
- endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
- if err != nil {
-
- }
- endRecordDateTime := endTime.Unix()
-
- pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
- sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
- admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "order_number": order.Number, //业务流水号
- "id_card_no": his.IdCardNo, //社会保障号
- "department_name": department.Name, //科室
- "number": his.Number, //门诊号
- "date": order.SettleAccountsDate, //结算日期
- "name": order.PsnName, //姓名
- "gender": patient.Gender, //性别
- "psn_cash_money": order.PsnCashPay, //个人支付
- "pay_way": "门诊", //结算方式
- "medfee_sumamt": order.MedfeeSumamt, //总费用
- "admin_user_name": admin.UserName, //收款员
- "order": order,
- "order_info": orderInfos_two,
- "his": his,
- "bedCostTotal": bedCostTotal,
- "bedCostSelfTotal": bedCostSelfTotal,
- "bedCostPartSelfTotal": bedCostPartSelfTotal,
- "operationCostTotal": operationCostTotal,
- "operationCostSelfTotal": operationCostSelfTotal,
- "operationCostPartSelfTotal": operationCostPartSelfTotal,
- "otherCostTotal": otherCostTotal,
- "otherCostSelfTotal": otherCostSelfTotal,
- "otherCostPartSelfTotal": otherCostPartSelfTotal,
- "materialCostTotal": materialCostTotal,
- "materialCostSelfTotal": materialCostSelfTotal,
- "materialCostPartSelfTotal": materialCostPartSelfTotal,
- "westernMedicineCostTotal": westernMedicineCostTotal,
- "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
- "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
- "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
- "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
- "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
- "checkCostTotal": checkCostTotal,
- "checkCostSelfTotal": checkCostSelfTotal,
- "checkCostPartSelfTotal": checkCostPartSelfTotal,
- "laboratoryCostTotal": laboratoryCostTotal,
- "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
- "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
- "treatCostTotal": treatCostTotal,
- "treatCostSelfTotal": treatCostSelfTotal,
- "treatCostPartSelfTotal": treatCostPartSelfTotal,
- "zhenChaCostTotal": zhenChaCostTotal,
- "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
- "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
- "his_hospital_record": his_hospital_record,
- "pre_pay_money": pre_pay_money,
- "refund_sum": sum,
- })
-
- }
-
- func (this *HisApiController) GetIncomeStatisticsData() {
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- key_words := this.GetString("key_words")
- limit, _ := this.GetInt64("limit")
- page, _ := this.GetInt64("page")
-
- if page <= 0 {
- page = 1
- }
- if limit <= 0 {
- limit = 10
- }
- statistics_type, _ := this.GetInt64("statistics_type")
- admin := this.GetAdminUserInfo()
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var theStartTIme int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- theStartTIme = 0
- }
- theStartTIme = theTime.Unix()
- }
- var theEndtTIme int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- theEndtTIme = 0
- }
- theEndtTIme = theTime.Unix()
- }
-
- if statistics_type == 1 {
- list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- })
- } else {
- list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- })
-
- }
-
- }
-
- func (c *HisApiController) PostProjectInformation() {
- adminUser := c.GetAdminUserInfo()
- orgId := adminUser.CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- return
- }
- utils.ErrorLog("%v", dataBody)
- var projectList []*models.HisProject
- var total_goods []interface{}
- tempProjects := dataBody["projects"].([]interface{})
-
- total_goods = tempProjects
- for index, projectMap := range tempProjects {
-
- projectM := projectMap.(map[string]interface{})
-
- var project models.HisProject
- if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
- utils.ErrorLog("project_name")
- return
- }
-
- project_name, _ := projectM["project_name"].(string)
- if len(project_name) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 6,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- project.ProjectName = project_name
-
- prices := projectM["price"].(string)
-
- price, _ := strconv.ParseFloat(prices, 64)
- if price <= 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 6,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- project.Price = price
-
- if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
- utils.ErrorLog("unit_id")
- return
- }
-
- unit := projectM["unit"].(string)
- if len(unit) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 6,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
- project.Unit = unit
-
- cost_classify := projectM["cost_classify"].(string)
- if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 6,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
- var costClassify = "费用类别"
- var cost_classify_id int64
-
- costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
-
- if len(cost_classify) != 0 {
- _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
- if errcode == gorm.ErrRecordNotFound {
- costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
- dataconfig := models.DictDataconfig{
- ParentId: costClassifyConfig.ID,
- Module: "system",
- OrgId: orgId,
- Name: cost_classify,
- FieldName: "",
- Value: costConfig.Value + 1,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUser.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
- }
-
- costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
-
- for _, it := range costClassList {
- if cost_classify == it.Name {
- cost_classify_id = int64(it.Value)
- }
- }
- project.CostClassify = cost_classify_id
-
- executive_section := projectM["executive_section"].(string)
- if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 6,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- if len(executive_section) != 0 {
- //查找科室是否有内容
- _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
- if errcodedepart == gorm.ErrRecordNotFound {
- department := models.XtHisDepartment{
- Name: executive_section,
- Status: 1,
- UserOrgId: adminUser.CurrentOrgId,
- CreatedTime: time.Now().Unix(),
- }
- service.CreateDePartment(&department)
- }
- }
- var executive_section_id int64
- departMentList, _ := service.GetAllDepartMent(orgId)
- for _, it := range departMentList {
- if executive_section == it.Name {
- executive_section_id = it.ID
- }
- }
- project.ExecutiveSection = executive_section_id
-
- medical_coverage := projectM["medical_coverage"].(string)
-
- if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 6,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- var medicalCoverage = "医保等级"
- var medical_coverage_id int64
-
- medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
- if len(medical_coverage) != 0 {
-
- _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
- if errormedicalcoverage == gorm.ErrRecordNotFound {
- medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
- dataconfig := models.DictDataconfig{
- ParentId: medicalCoverageConfig.ID,
- Module: "system",
- OrgId: orgId,
- Name: medical_coverage,
- FieldName: "",
- Value: medicalCoverageConfig.Value + 1,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUser.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
- }
- medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
- for _, it := range medicalCoverageList {
- if medical_coverage == it.Name {
- medical_coverage_id = int64(it.Value)
- }
- }
- project.MedicalCoverage = medical_coverage_id
-
- pinyin := projectM["pinyin"].(string)
- project.Pinyin = pinyin
-
- wubi := projectM["wubi"].(string)
-
- project.Wubi = wubi
-
- statistical_classification := projectM["statistical_classification"].(string)
-
- var statisticalClassification = "统计分类"
- var statistical_classification_id int64
- classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
- if len(statistical_classification) != 0 {
-
- _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
-
- if classificationerrcodes == gorm.ErrRecordNotFound {
- classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
- dataconfig := models.DictDataconfig{
- ParentId: classiFication.ID,
- Module: "system",
- OrgId: orgId,
- Name: statistical_classification,
- FieldName: "",
- Value: classiFicationConfig.Value + 1,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUser.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
-
- }
- classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
-
- for _, it := range classiFicationList {
- if statistical_classification == it.Name {
-
- statistical_classification_id = int64(it.Value)
- }
- }
-
- project.StatisticalClassification = statistical_classification_id
-
- disease_directory := int64(projectM["disease_directory"].(float64))
- project.DiseaseDirectory = disease_directory
-
- is_record := int64(projectM["is_record"].(float64))
- project.IsRecord = is_record
-
- medical_code := projectM["medical_code"].(string)
- project.MedicalCode = medical_code
-
- tube_color := projectM["tube_color"].(string)
-
- var tubeColor = "试管颜色"
- var tube_color_id int64
- tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
- if len(tube_color) != 0 {
- _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
- if errcodetube == gorm.ErrRecordNotFound {
- tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
- dataconfig := models.DictDataconfig{
- ParentId: tubeColorConfig.ID,
- Module: "system",
- OrgId: orgId,
- Name: tube_color,
- FieldName: "",
- Value: tubeConfig.Value + 1,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUser.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
-
- }
-
- tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
- for _, it := range tubeColorList {
- if tube_color == it.Name {
- tube_color_id = int64(it.Value)
- }
- }
-
- project.TubeColor = tube_color_id
-
- single_dose := projectM["single_dose"].(string)
- project.SingleDose = single_dose
- execution_frequency := projectM["execution_frequency"].(string)
- project.ExecutionFrequency = execution_frequency
-
- delivery_way := projectM["delivery_way"].(string)
- project.DeliveryWay = delivery_way
-
- number_days := projectM["number_days"].(string)
- project.NumberDays = number_days
-
- total := projectM["total"].(string)
- project.Total = total
-
- medical_status := int64(projectM["medical_status"].(float64))
- project.MedicalStatus = medical_status
-
- category := int64(projectM["category"].(float64))
- project.Category = category
-
- specail_project := int64(projectM["specail_project"].(float64))
- project.SpecailProject = specail_project
-
- social_security_directory_code := projectM["social_security_directory_code"].(string)
-
- project.SocialSecurityDirectoryCode = social_security_directory_code
-
- remark := projectM["remark"].(string)
- project.Remark = remark
-
- record_date := projectM["record_date"].(string)
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- project.RecordDate = theTime.Unix()
- projectList = append(projectList, &project)
- }
-
- export_time := time.Now().Unix()
-
- errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
- if len(projectList) > 0 {
- for _, item := range projectList {
- project := models.HisProject{
- ProjectName: item.ProjectName,
- Price: item.Price,
- Unit: item.Unit,
- CostClassify: item.CostClassify,
- ExecutiveSection: item.ExecutiveSection,
- MedicalCoverage: item.MedicalCoverage,
- UserOrgId: orgId,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- Pinyin: item.Pinyin,
- Wubi: item.Wubi,
- StatisticalClassification: item.StatisticalClassification,
- DiseaseDirectory: item.DiseaseDirectory,
- IsRecord: item.IsRecord,
- MedicalCode: item.MedicalCode,
- TubeColor: item.TubeColor,
- SingleDose: item.SingleDose,
- DeliveryWay: item.DeliveryWay,
- NumberDays: item.NumberDays,
- Total: item.Total,
- Category: item.Category,
- MedicalStatus: item.MedicalStatus,
- SpecailProject: item.SpecailProject,
- RecordDate: item.RecordDate,
- Remark: item.Remark,
- SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
- ExecutionFrequency: item.ExecutionFrequency,
- }
-
- _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
- if errcodeproject == gorm.ErrRecordNotFound {
- service.CreateProjectInfomation(&project)
- } else if errcodeproject == nil {
- service.UpdateProjectByName(&project, item.ProjectName, orgId)
- }
-
- log := models.ExportLog{
- LogType: 6,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_goods)),
- FailNum: int64(len(errLogs)),
- SuccessNum: int64(len(projectList)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "导入成功",
- "total_num": len(total_goods),
- "success_num": len(projectList),
- "fail_num": int64(len(errLogs)),
- })
- }
- } else {
- log := models.ExportLog{
- LogType: 6,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_goods)),
- FailNum: int64(len(errLogs)),
- SuccessNum: int64(len(projectList)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "导入成功",
- "total_num": len(total_goods),
- "success_num": len(projectList),
- "fail_num": int64(len(errLogs)),
- })
- }
- }
-
- //func (this *HisApiController) EditProjectInformation(){
- //
- // id, _ := this.GetInt64("id")
- // project_team := this.GetString("project_team")
- // price := this.GetString("price")
- // price_float, _ := strconv.ParseFloat(price, 64)
- // pinyin := this.GetString("pinyin")
- // wubi := this.GetString("wubi")
- // tube_color, _ := this.GetInt64("tube_color")
- // team_type, _ := this.GetInt64("team_type")
- // remark := this.GetString("remark")
- // ids := this.GetString("ids")
- // item_id := this.GetString("item_id")
- // projectTeam := models.XtHisProjectTeam{
- // ProjectTeam: project_team,
- // Price: price_float,
- // Pinyin: pinyin,
- // Wubi: wubi,
- // TubeColor: tube_color,
- // TeamType: team_type,
- // Remark: remark,
- // ProjectId: ids,
- // ItemId: item_id,
- // }
- //
- //
- // dataBody := make(map[string]interface{}, 0)
- // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- // if err != nil {
- // utils.ErrorLog(err.Error())
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- // }
- //
- // err = service.UpdatedProjectTeam(id, &projectTeam)
- //
- //
- // if err != nil {
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
- // return
- // }
- //
- // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
- // infos, _ := dataBody["info"].([]interface{})
- // if len(infos) > 0 {
- // var ids []string
- //
- // for _, item := range infos {
- // items := item.(map[string]interface{})
- // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- // utils.ErrorLog("id")
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- // }
- // id := int64(items["id"].(float64))
- //
- // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
- // utils.ErrorLog("type")
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- // }
- // types := int64(items["type"].(float64))
- //
- // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
- // utils.ErrorLog("number")
- // }
- //
- // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
- //
- // projectList := models.XtHisProjectList{
- // Number: number,
- // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- // ProjectId: id,
- // Status: 1,
- // CreatedTime: time.Now().Unix(),
- // UpdatedTime: time.Now().Unix(),
- // TeamId: projectTeam.ID,
- // Type: types,
- // }
- // list := projectList
- //
- // service.CreateProjectList(&list)
- //
- // ids = append(ids, strconv.FormatInt(list.ID, 10))
- //
- // }
- // ids_str := strings.Join(ids, ",")
- // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
- // service.SaveProjectTeam(&projectTeam)
- // this.ServeSuccessJSON(map[string]interface{}{
- // "projectTeam": projectTeam,
- // })
- // }
- // }
- //}
-
- func (c *HisApiController) CreateHisPrescriptionTemplate() {
- name := c.GetString("name")
- mode_id, _ := c.GetInt64("mode", 0)
- types, _ := c.GetInt64("type", 0)
- patient_id, _ := c.GetInt64("patient_id", 0)
- types = 1
- adminInfo := c.GetAdminUserInfo()
- template := &models.HisPrescriptionTemplate{
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- PatientId: patient_id,
- Type: types,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Name: name,
- Mode: mode_id,
- }
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- err = service.CreateHisPrescriptionTemplate(template)
- if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
- prescriptions, _ := dataBody["prescriptions"].([]interface{})
- if len(prescriptions) > 0 {
- for _, item := range prescriptions {
- items := item.(map[string]interface{})
- if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
- utils.ErrorLog("type")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- types := int64(items["type"].(float64))
-
- if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
- utils.ErrorLog("med_type")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- med_type := strconv.Itoa(int(items["med_type"].(float64)))
-
- ctime := time.Now().Unix()
- prescription := &models.HisPrescriptionInfoTemplate{
- PatientId: patient_id,
- UserOrgId: adminInfo.CurrentOrgId,
- Ctime: ctime,
- Mtime: ctime,
- Type: types,
- Modifier: adminInfo.AdminUser.Id,
- Creator: adminInfo.AdminUser.Id,
- Status: 1,
- PTemplateId: template.ID,
- MedType: med_type,
- }
- service.CreateHisPrescriptionInfoTemplate(prescription)
-
- if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
- advices := items["advices"].([]interface{})
- //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
- ctime := time.Now().Unix()
- mtime := ctime
- if len(advices) > 0 {
- for _, advice := range advices {
- var s models.HisPrescriptionAdviceTemplate
- s.PrescriptionId = prescription.ID
- s.AdviceType = 2
- s.StopState = 2
- s.ExecutionState = 2
- s.Status = 1
- s.UserOrgId = adminInfo.CurrentOrgId
- s.CreatedTime = ctime
- s.UpdatedTime = mtime
- s.PatientId = patient_id
- errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
- if errcode > 0 {
- c.ServeFailJSONWithSGJErrorCode(errcode)
- return
- }
-
- service.CreateHisPrescriptionAdviceTemplate(&s)
-
- }
- }
- }
- if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
- projects := items["project"].([]interface{})
- if len(projects) > 0 {
- for _, project := range projects {
- var p models.HisPrescriptionProjectTemplate
- p.PrescriptionId = prescription.ID
- p.Ctime = time.Now().Unix()
- p.Mtime = time.Now().Unix()
- p.PatientId = patient_id
- p.UserOrgId = adminInfo.CurrentOrgId
- p.Status = 1
- errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
- if errcode > 0 {
- c.ServeFailJSONWithSGJErrorCode(errcode)
- return
- }
- service.CreateHisPrescriptionProjectTemplate(&p)
-
- }
- }
- }
-
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "创建成功",
- })
- }
- }
-
- }
-
- func (c *HisApiController) PreSettle() {
- id, _ := c.GetInt64("id")
- record_time := c.GetString("record_time")
- his_patient_id, _ := c.GetInt64("his_patient_id")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
- diagnosis_id := c.GetString("diagnosis")
- sick_type, _ := c.GetInt64("sick_type")
- reg_type, _ := c.GetInt64("p_type")
-
- his, _ := service.GetHisPatientByIdThree(his_patient_id)
-
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDateTime := theTime.Unix()
- adminUser := c.GetAdminUserInfo()
- var prescriptions []*models.HisPrescription
- var start_time int64
- var end_time int64
-
- ids_str := c.GetString("ids")
- ids_arr := strings.Split(ids_str, ",")
-
- fmt.Println(reg_type)
-
- if settle_accounts_type == 1 { //日结
-
- if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
-
- prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
- } else {
- prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
- }
-
- fmt.Println(prescriptions)
- } else { //月结
- start_time_str := c.GetString("start_time")
- end_time_str := c.GetString("end_time")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordStartTime := theStartTime.Unix()
- start_time = recordStartTime
- theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordEndTime := theEndTime.Unix()
- end_time = recordEndTime
- prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
- }
-
- if reg_type == 1111 || reg_type == 1112 {
- reg_type = 11
- }
-
- timestamp := time.Now().Unix()
- tempTime := time.Unix(timestamp, 0)
- timeFormat := tempTime.Format("20060102150405")
- chrgBchno := rand.Intn(100000) + 10000
- chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
- strconv.FormatInt(his.PatientId, 10)
-
- var ids []int64
-
- for _, item := range prescriptions {
- ids = append(ids, item.ID)
- }
-
- fmt.Println(ids)
-
- var total float64
- for _, item := range prescriptions {
- fmt.Println(item)
- if item.Type == 1 { //药品
- for _, subItem := range item.HisDoctorAdviceInfo {
- total = total + (subItem.Price * subItem.PrescribingNumber)
- }
- }
- if item.Type == 2 { //项目
- for _, subItem := range item.HisPrescriptionProject {
- cnt, _ := strconv.ParseFloat(subItem.Count, 64)
- total = total + (subItem.Price * cnt)
- }
- }
-
- for _, subItem := range item.HisAdditionalCharge {
- total = total + (subItem.Price * float64(subItem.Count))
- }
- }
-
- allTotal := fmt.Sprintf("%.2f", total)
- totals, _ := strconv.ParseFloat(allTotal, 64)
- order := &models.HisOrder{
- UserOrgId: adminUser.CurrentOrgId,
- HisPatientId: his.ID,
- PatientId: id,
- SettleAccountsDate: recordDateTime,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- OrderStatus: 1,
- MdtrtId: his.Number,
- Number: chrg_bchno,
- MedfeeSumamt: totals,
- SettleEndTime: end_time,
- SettleStartTime: start_time,
- SettleType: settle_accounts_type,
- PsnPartAmt: totals,
- PsnCashPay: totals,
- PType: 2,
- IsPre: 1,
- MedType: strconv.Itoa(int(reg_type)),
- Diagnosis: diagnosis_id,
- }
- err = service.CreateOrder(order)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
- return
- }
-
- var customs []*Custom
- for _, item := range prescriptions {
- fmt.Println(item.Type)
- if item.Type == 1 { //药品
- for _, subItem := range item.HisDoctorAdviceInfo {
- cus := &Custom{
- AdviceId: subItem.ID,
- ProjectId: 0,
- DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
- Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
- FeedetlSn: subItem.FeedetlSn,
- Price: fmt.Sprintf("%.2f", subItem.Price),
- MedListCodg: subItem.MedListCodg,
- Type: 1,
- }
- customs = append(customs, cus)
- }
- }
-
- if item.Type == 2 { //项目
- for _, subItem := range item.HisPrescriptionProject {
- cnt, _ := strconv.ParseFloat(subItem.Count, 64)
- cus := &Custom{
- AdviceId: 0,
- ProjectId: subItem.ID,
- DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
- Cut: fmt.Sprintf("%.2f", cnt),
- FeedetlSn: subItem.FeedetlSn,
- Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
- MedListCodg: subItem.MedListCodg,
- Type: 2,
- }
-
- customs = append(customs, cus)
- }
- }
-
- for _, item := range item.HisAdditionalCharge {
- cus := &Custom{
- ItemId: item.ID,
- AdviceId: 0,
- ProjectId: 0,
- DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
- Cut: fmt.Sprintf("%.2f", float64(item.Count)),
- FeedetlSn: item.FeedetlSn,
- Price: fmt.Sprintf("%.2f", float64(item.Price)),
- MedListCodg: item.XtHisAddtionConfig.Code,
- Type: 3,
- }
-
- customs = append(customs, cus)
- }
-
- }
-
- fmt.Println(customs)
-
- for _, item := range customs {
- var advice_id int64 = 0
- var project_id int64 = 0
- var item_id int64 = 0
-
- var types int64 = 0
-
- if item.Type == 1 {
- advice_id = item.AdviceId
- project_id = 0
- item_id = 0
- } else if item.Type == 2 {
- advice_id = 0
- item_id = 0
-
- project_id = item.ProjectId
- } else if item.Type == 3 {
- advice_id = 0
- item_id = item.ItemId
- project_id = 0
- }
-
- detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
- cut, _ := strconv.ParseFloat(item.Cut, 32)
- pric, _ := strconv.ParseFloat(item.Price, 32)
-
- info := &models.HisOrderInfo{
- OrderNumber: order.Number,
- UploadDate: time.Now().Unix(),
- AdviceId: advice_id,
- DetItemFeeSumamt: detItemFeeSumamt,
- Cnt: cut,
- Pric: pric,
- PatientId: id,
- Status: 1,
- Mtime: time.Now().Unix(),
- Ctime: time.Now().Unix(),
- UserOrgId: adminUser.CurrentOrgId,
- HisPatientId: his.ID,
- OrderId: order.ID,
- ProjectId: project_id,
- Type: types,
- ItemId: item_id,
- }
- service.CreateOrderInfo(info)
- }
- his.SickType = sick_type
- service.UpdataHisPateint(&his)
- err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
- err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
- //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "结算成功",
- })
- }
- }
-
- type CustomOrderInfo struct {
- Name string
- Spec string
- Unit string
- Count float64
- Price float64
- Total float64
- }
-
- func (c *HisApiController) GetPrivateExpensesInfo() {
- order_id, _ := c.GetInt64("id", 0)
- his_patient_id, _ := c.GetInt64("his_patient_id", 0)
- order, _ := service.GetHisOrderByID(order_id)
- role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
- if order.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
- return
- }
- miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
- his, _ := service.GetHisPatientByIdThree(his_patient_id)
- org_id := c.GetAdminUserInfo().CurrentOrgId
- adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
- //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
-
- orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
- orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
- orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
-
- var orderInfos_four []*models.HisOrderInfoTwo
- for _, item := range orderInfos_three {
- if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
- item.HisPrescriptionProject.IsCheckTeam = 1
- orderInfos_four = append(orderInfos_four, item)
-
- }
- if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
- item.HisPrescriptionProject.IsCheckTeam = 2
- orderInfos_two = append(orderInfos_two, item)
- }
- }
-
- new_order_info := RemoveRepeatedTeam(orderInfos_four)
- var cus_slice []CustomOrderInfo
- for _, item := range new_order_info {
- var cus CustomOrderInfo
- cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
- cus.Unit = ""
- cus.Spec = ""
- var total float64
- for _, subItem := range orderInfos_four {
- if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
- total = total + subItem.DetItemFeeSumamt
- fmt.Println(subItem.DetItemFeeSumamt)
- }
- }
- cus.Count = 1
- cus.Total = total
- cus_slice = append(cus_slice, cus)
- }
-
- orderInfos = append(orderInfos, orderInfos_two...)
- if c.GetAdminUserInfo().CurrentOrgId != 10138 {
- orderInfos = append(orderInfos, orderInfos_three...)
-
- }
-
- patient, _ := service.GetPatientByID(org_id, order.PatientId)
- c.ServeSuccessJSON(map[string]interface{}{
- "order": order,
- "order_info": orderInfos,
- "patient": patient,
- "admin_info": adminInfo,
- "his": his,
- "current_admin": role,
- "org_config": miConfig,
- "new_order_info": cus_slice,
- })
-
- }
-
- func (this *HisApiController) ChangeMedType() {
- med_type := this.GetString("med_type")
- old_med_type := this.GetString("old_med_type")
- ids := this.GetString("ids")
- settle_type, _ := this.GetInt64("settle_type")
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- ids_arr := strings.Split(ids, ",")
- if settle_type == 1 { //日结
- id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
- prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
- prescription.MedType = med_type
- err := service.SaveHisPrescription(&prescription)
-
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "修改成功",
- })
-
- } else {
-
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
-
- }
-
- } else if settle_type == 2 {
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordStartTime := theStartTime.Unix()
- start_time_timestamp := recordStartTime
- theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordEndTime := theEndTime.Unix()
- end_time_timestamp := recordEndTime
- updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
- if updateErr == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "修改成功",
- })
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
-
- }
-
- func (c *HisApiController) GetHisMonthChargePatientInfo() {
- patient_id, _ := c.GetInt64("patient_id")
- his_patient_id, _ := c.GetInt64("his_patient_id")
- record_date := c.GetString("record_date")
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- order_status, _ := c.GetInt64("type", 0)
- p_type, _ := c.GetInt64("p_type", 0)
- order_id, _ := c.GetInt64("order_id", 0)
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDateTime := theTime.Unix()
-
- startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
-
- }
- startRecordDateTime := startTime.Unix()
-
- endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
-
- }
- endRecordDateTime := endTime.Unix()
-
- admin := c.GetAdminUserInfo()
- his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
- xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
-
- order, _ := service.GetHisOrderByID(order_id)
-
- var monthPrescriptions []*models.HisPrescription
- if order_status == 1 || order_status == 0 {
- monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
- } else if order_status == 2 {
- monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
- }
-
- var settle_total float64
- for _, item := range monthPrescriptions {
- if len(item.HisPrescriptionProject) > 0 {
- for _, subItem := range item.HisPrescriptionProject {
- count, _ := strconv.ParseFloat(subItem.Count, 64)
- total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
- settle_total = settle_total + total
- }
- }
- if len(item.HisDoctorAdviceInfo) > 0 {
- for _, subItem := range item.HisDoctorAdviceInfo {
- total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
- settle_total = settle_total + total
- }
- }
-
- }
- settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
-
- case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
- patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
-
- lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
-
- doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
- //获取所有科室信息
- department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "his_info": his_patient_info,
- "xt_info": xt_patient_info,
- "case_history": case_history,
- "info": patientPrescriptionInfo,
- "last_info": lastPatientPrescriptionInfo,
- "month_prescriptions": monthPrescriptions,
- "order": order,
- "doctors": doctors,
- "department": department,
- "settle_total": settle_total,
- })
- return
- }
-
- func (c *HisApiController) GetHisMonthPatientInfo() {
- patient_id, _ := c.GetInt64("patient_id")
- his_patient_id, _ := c.GetInt64("his_patient_id")
- record_date := c.GetString("record_date")
- number := c.GetString("number")
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- p_type, _ := c.GetInt64("p_type")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDateTime := theTime.Unix()
- startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
-
- }
- startRecordDateTime := startTime.Unix()
- endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
-
- }
- endRecordDateTime := endTime.Unix()
- admin := c.GetAdminUserInfo()
- his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
- xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
-
- count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
-
- monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
- var settle_total float64
- for _, item := range monthPrescriptions {
- if len(item.HisPrescriptionProject) > 0 {
- for _, subItem := range item.HisPrescriptionProject {
- count, _ := strconv.ParseFloat(subItem.Count, 64)
- total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
- settle_total = settle_total + total
- }
- }
- if len(item.HisDoctorAdviceInfo) > 0 {
- for _, subItem := range item.HisDoctorAdviceInfo {
- total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
- settle_total = settle_total + total
- }
- }
-
- }
- settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
-
- case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
- patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
- lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
-
- order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
- doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
-
- _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
- //获取所有科室信息
- department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "his_info": his_patient_info,
- "xt_info": xt_patient_info,
- "case_history": case_history,
- "info": patientPrescriptionInfo,
- "month_prescriptions": monthPrescriptions,
- "order": order,
- "doctors": doctors,
- "department": department,
- "count": count,
- "drugStockConfig": drugStockConfig,
- "last_info": lastPatientPrescriptionInfo,
- "settle_total": settle_total,
- })
- return
-
- }
-
- func (c *HisApiController) GetAllOrder() {
- org_id := c.GetAdminUserInfo().CurrentOrgId
- orders, _ := service.GetNewHisOrderList(org_id)
- c.ServeSuccessJSON(map[string]interface{}{
- "order": orders,
- })
- return
-
- }
-
- func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
- newArr = make([]*models.HisOrderInfoTwo, 0)
- for i := 0; i < len(arr); i++ {
- repeat := false
- for j := i + 1; j < len(arr); j++ {
- if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
- repeat = true
- break
- }
- }
- if !repeat {
- newArr = append(newArr, arr[i])
- }
- }
- return
- }
-
- //修改处方退库操作 参数传修改之前的处方数据
- func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
-
- if advice.ExecutionState == 1 {
- //查询该病人该药品是否有库存记录
- info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
- if errcode == gorm.ErrRecordNotFound {
-
- } else {
- //退库
- drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
- if advice.PrescribingNumberUnit == drug.MinUnit {
-
- floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
- prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
-
- //退库
- warehouseInfo := models.DrugWarehouseInfo{
- StockMinNumber: prescribingNumber,
- }
-
- service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
-
- operation_time := time.Now().Unix()
- creater := advice.AdviceDoctor
-
- ctime := time.Now().Unix()
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
- total = total + 1
- orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
-
- cancelStock := models.DrugCancelStock{
- OrderNumber: orderNumber,
- OperaTime: operation_time,
- OrgId: advice.UserOrgId,
- Creater: creater,
- Ctime: ctime,
- Status: 1,
- ReturnTime: advice.AdviceDate,
- Dealer: info.Dealer,
- Manufacturer: info.Manufacturer,
- Type: 1,
- }
- service.AddSigleDrugCancelStock(&cancelStock)
-
- manufactureName, _ := service.GetManufactureById(info.Manufacturer)
- dealer, _ := service.GetDealerById(info.Dealer)
- cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
- cancelStockInfo := models.DrugCancelStockInfo{
- OrderNumber: cancelInfo.OrderNumber,
- CancelStockId: cancelInfo.ID,
- DrugId: info.DrugId,
- Count: info.Count,
- Status: 1,
- Ctime: ctime,
- OrgId: advice.UserOrgId,
- Type: 1,
- Manufacturer: manufactureName.ManufacturerName,
- Dealer: dealer.DealerName,
- Total: 0,
- RetailPrice: info.RetailPrice,
- RetailTotalPrice: info.RetailTotalPrice,
- Price: info.Price,
- RegisterAccount: "",
- Remark: info.Remark,
- BatchNumber: info.BatchNumber,
- MaxUnit: info.CountUnit,
- ProductDate: info.ProductDate,
- ExpiryDate: info.ExpiryDate,
- BatchNumberId: info.WarehouseInfoId,
- }
-
- flow := models.DrugFlow{
- WarehousingId: 0,
- DrugId: info.DrugId,
- Number: "",
- BatchNumber: info.BatchNumber,
- Count: info.Count,
- UserOrgId: advice.UserOrgId,
- PatientId: 0,
- SystemTime: ctime,
- ConsumableType: 4,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: 0,
- WarehouseOutOrderNumber: "",
- IsEdit: 0,
- CancelStockId: cancelStock.ID,
- CancelOrderNumber: cancelStock.OrderNumber,
- Manufacturer: info.Manufacturer,
- Dealer: info.Dealer,
- Creator: advice.UserOrgId,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: info.Price,
- WarehousingDetailId: 0,
- WarehouseOutDetailId: 0,
- CancelOutDetailId: 0,
- ExpireDate: info.ExpiryDate,
- ProductDate: info.ProductDate,
- MaxUnit: info.CountUnit,
- MinUnit: "",
- }
- service.CreatedCancelStock(cancelStockInfo)
- service.CreateDrugFlowOne(flow)
- } else {
-
- floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
-
- prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
-
- if advice.PrescribingNumberUnit == drug.MaxUnit {
- warehouseInfo := models.DrugWarehouseInfo{
- StockMinNumber: prescribingNumber,
- }
- service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
-
- }
-
- operation_time := time.Now().Unix()
- creater := advice.AdviceDoctor
-
- ctime := time.Now().Unix()
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
- total = total + 1
- orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
-
- cancelStock := models.DrugCancelStock{
- OrderNumber: orderNumber,
- OperaTime: operation_time,
- OrgId: advice.UserOrgId,
- Creater: creater,
- Ctime: ctime,
- Status: 1,
- ReturnTime: advice.AdviceDate,
- Dealer: info.Dealer,
- Manufacturer: info.Manufacturer,
- Type: 1,
- }
- service.AddSigleDrugCancelStock(&cancelStock)
-
- manufactureName, _ := service.GetManufactureById(info.Manufacturer)
- dealer, _ := service.GetDealerById(info.Dealer)
- cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
- cancelStockInfo := models.DrugCancelStockInfo{
- OrderNumber: cancelInfo.OrderNumber,
- CancelStockId: cancelInfo.ID,
- DrugId: info.DrugId,
- Count: info.Count,
- Status: 1,
- Ctime: ctime,
- OrgId: advice.UserOrgId,
- Type: 1,
- Manufacturer: manufactureName.ManufacturerName,
- Dealer: dealer.DealerName,
- Total: 0,
- RetailPrice: info.RetailPrice,
- RetailTotalPrice: info.RetailTotalPrice,
- Price: info.Price,
- RegisterAccount: "",
- Remark: info.Remark,
- BatchNumber: info.BatchNumber,
- MaxUnit: info.CountUnit,
- ProductDate: info.ProductDate,
- ExpiryDate: info.ExpiryDate,
- BatchNumberId: info.WarehouseInfoId,
- }
-
- flow := models.DrugFlow{
- WarehousingId: 0,
- DrugId: info.DrugId,
- Number: "",
- BatchNumber: info.BatchNumber,
- Count: info.Count,
- UserOrgId: advice.UserOrgId,
- PatientId: 0,
- SystemTime: ctime,
- ConsumableType: 4,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: 0,
- WarehouseOutOrderNumber: "",
- IsEdit: 0,
- CancelStockId: cancelStock.ID,
- CancelOrderNumber: cancelStock.OrderNumber,
- Manufacturer: info.Manufacturer,
- Dealer: info.Dealer,
- Creator: advice.AdviceDoctor,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: info.Price,
- WarehousingDetailId: 0,
- WarehouseOutDetailId: 0,
- CancelOutDetailId: 0,
- ExpireDate: info.ExpiryDate,
- ProductDate: info.ProductDate,
- MaxUnit: info.CountUnit,
- MinUnit: "",
- }
- service.CreatedCancelStock(cancelStockInfo)
- service.CreateDrugFlowOne(flow)
- }
- }
- }
- return err
- }
-
- func (this *HisApiController) DeleteNCDS() {
- id, _ := this.GetInt64("id", 0)
- if id > 0 {
- service.DeletePsnNCDSRecordById(id)
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
- return
- }
-
- }
-
- func (c *HisApiController) GetHisDoctorAdviceInfo() {
-
- id, _ := c.GetInt64("id")
- advice, _ := service.GetHisDoctorAdviceInfo(id)
- c.ServeSuccessJSON(map[string]interface{}{
- "advice": advice,
- })
- return
- }
-
- func (c *HisApiController) GetHisMonthChargePatientList() {
- record_date := c.GetString("record_date")
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDateTime := theTime.Unix()
- startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
-
- }
- startRecordDateTime := startTime.Unix()
- endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
-
- }
- endRecordDateTime := endTime.Unix()
- adminInfo := c.GetAdminUserInfo()
- var tempMonthChargePatients []*service.MonthChargePatients
- tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
- for _, item := range tempPatients {
- //过滤没有处方的
- if len(item.HisPrescription) == 0 {
- tempMonthChargePatients = append(tempMonthChargePatients, item)
- }
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "list": tempMonthChargePatients,
- })
-
- }
|