his_api_controller.go 391KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "github.com/shopspring/decimal"
  12. "math/rand"
  13. "reflect"
  14. "strconv"
  15. "strings"
  16. "syscall"
  17. "time"
  18. "unsafe"
  19. )
  20. type HisApiController struct {
  21. BaseAuthAPIController
  22. }
  23. func HisManagerApiRegistRouters() {
  24. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  25. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  26. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  27. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  28. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  29. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  30. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  31. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  32. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  33. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  34. beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  35. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  36. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  37. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  40. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  41. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  42. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  43. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  44. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  45. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  46. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  47. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  48. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  49. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  50. //新增附加费用
  51. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  52. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  53. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  54. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  55. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  56. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  57. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  58. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  59. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  60. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  61. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  62. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  63. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  64. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  65. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  66. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  67. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. }
  84. func (c *HisApiController) GetTestOrder() {
  85. order_id, _ := c.GetInt64("order_id")
  86. admin_user_id, _ := c.GetInt64("admin_user_id")
  87. adminUser := c.GetAdminUserInfo()
  88. order, _ := service.GetHisOrderByID(order_id)
  89. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  90. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  91. orderInfos = append(orderInfos, orderInfos_two...)
  92. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  93. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  94. var dia_config []*models.HisXtDiagnoseConfig
  95. var name string
  96. var bedCostTotal float64 = 0 //床位总费
  97. var bedCostSelfTotal float64 = 0 //床位自费
  98. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  99. var bedSelfTotal float64 = 0 //床位部分项目自费
  100. var bedInscpTotal float64 = 0 //床位部分项目自费
  101. var operationCostTotal float64 = 0 //手术费
  102. var operationCostSelfTotal float64 = 0 //手术费
  103. var operationCostPartSelfTotal float64 = 0 //手术费
  104. var operationSelfTotal float64 = 0 //床位部分项目自费
  105. var operationInscpTotal float64 = 0 //床位部分项目自费
  106. var otherCostTotal float64 = 0 //其他费用
  107. var otherCostSelfTotal float64 = 0 //其他费用
  108. var otherCostPartSelfTotal float64 = 0 //其他费用
  109. var otherSelfTotal float64 = 0 //床位部分项目自费
  110. var otherInscpTotal float64 = 0 //床位部分项目自费
  111. var materialCostTotal float64 = 0 //材料费
  112. var materialCostSelfTotal float64 = 0 //材料费
  113. var materialCostPartSelfTotal float64 = 0 //材料费
  114. var materialSelfTotal float64 = 0 //床位部分项目自费
  115. var materialInscpTotal float64 = 0 //床位部分项目自费
  116. var westernMedicineCostTotal float64 = 0 //西药费
  117. var westernMedicineCostSelfTotal float64 = 0 //西药费
  118. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  119. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  120. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  121. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  122. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  123. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  124. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  125. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  126. var checkCostTotal float64 = 0 //检查费
  127. var checkCostSelfTotal float64 = 0 //检查费
  128. var checkCostPartSelfTotal float64 = 0 //检查费
  129. var checkSelfTotal float64 = 0 //床位部分项目自费
  130. var checkInscpTotal float64 = 0 //床位部分项目自费
  131. var laboratoryCostTotal float64 = 0 //化验费
  132. var laboratoryCostSelfTotal float64 = 0 //化验费
  133. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  134. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  135. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  136. var treatCostTotal float64 = 0 //治疗费用
  137. var treatCostSelfTotal float64 = 0 //治疗费用
  138. var treatCostPartSelfTotal float64 = 0 //治疗费用
  139. var treatSelfTotal float64 = 0 //床位部分项目自费
  140. var treatInscpTotal float64 = 0 //床位部分项目自费
  141. decimal.DivisionPrecision = 2
  142. for _, item := range orderInfos {
  143. if item.MedChrgitmType == "01" { //床位费
  144. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  145. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  146. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  147. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  148. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  149. }
  150. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  151. if item.MedChrgitmType == "03" { //检查费
  152. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  153. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  154. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  155. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  156. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  157. }
  158. } else {
  159. if item.MedChrgitmType == "03" { //检查费
  160. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  161. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  162. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  163. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  164. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  165. }
  166. }
  167. if item.MedChrgitmType == "04" { //化验费
  168. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  169. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  170. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  171. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  172. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  173. }
  174. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  175. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  176. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  177. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  178. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  179. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  180. }
  181. if item.MedChrgitmType == "06" { //手术费
  182. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  183. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  184. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  185. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  186. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  187. }
  188. if item.MedChrgitmType == "08" { //材料费
  189. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  190. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  191. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  192. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  193. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  194. }
  195. if item.MedChrgitmType == "09" { //西药费
  196. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  197. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  198. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  199. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  200. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  201. }
  202. if item.MedChrgitmType == "11" { //中成费
  203. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  204. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  205. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  206. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  207. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  208. }
  209. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  210. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  211. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  212. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  213. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  214. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  215. }
  216. }
  217. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  218. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  219. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  220. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  221. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  222. var doctor_name string
  223. if roles.ID == 0 {
  224. doctor_name = "管理员"
  225. } else {
  226. doctor_name = roles.UserName
  227. }
  228. yiliao_leibie := ""
  229. switch order.MedType {
  230. case "11":
  231. yiliao_leibie = "普通门诊"
  232. break
  233. case "12":
  234. yiliao_leibie = "门诊挂号"
  235. break
  236. case "13":
  237. yiliao_leibie = "急诊"
  238. break
  239. case "14":
  240. yiliao_leibie = "门诊特殊病"
  241. break
  242. case "15":
  243. yiliao_leibie = "门诊统筹"
  244. break
  245. case "16":
  246. yiliao_leibie = "门诊慢性病"
  247. break
  248. case "21":
  249. yiliao_leibie = "普通住院"
  250. break
  251. }
  252. c.ServeSuccessJSON(map[string]interface{}{
  253. "diagnosis": name,
  254. "order_infos": orderInfos,
  255. "number": order.MdtrtId,
  256. "date": order.SettleAccountsDate,
  257. "charge_admin": charge_admin,
  258. "printor_admin": printor_admin,
  259. "info": order,
  260. "order": order,
  261. "bedCostTotal": bedCostTotal,
  262. "bedCostSelfTotal": bedCostSelfTotal,
  263. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  264. "bedSelfTotal": bedSelfTotal,
  265. "bedInscpTotal": bedInscpTotal,
  266. "operationCostTotal": operationCostTotal,
  267. "operationCostSelfTotal": operationCostSelfTotal,
  268. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  269. "operationSelfTotal": operationSelfTotal,
  270. "operationInscpTotal": operationInscpTotal,
  271. "otherCostTotal": otherCostTotal,
  272. "otherCostSelfTotal": otherCostSelfTotal,
  273. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  274. "otherSelfTotal": otherSelfTotal,
  275. "otherInscpTotal": otherInscpTotal,
  276. "materialCostTotal": materialCostTotal,
  277. "materialCostSelfTotal": materialCostSelfTotal,
  278. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  279. "materialSelfTotal": materialSelfTotal,
  280. "materialInscpTotal": materialInscpTotal,
  281. "westernMedicineCostTotal": westernMedicineCostTotal,
  282. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  283. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  284. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  285. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  286. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  287. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  288. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  289. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  290. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  291. "checkCostTotal": checkCostTotal,
  292. "checkCostSelfTotal": checkCostSelfTotal,
  293. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  294. "checkSelfTotal": checkSelfTotal,
  295. "checkInscpTotal": checkInscpTotal,
  296. "laboratoryCostTotal": laboratoryCostTotal,
  297. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  298. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  299. "laboratorySelfTotal": laboratorySelfTotal,
  300. "laboratoryInscpTotal": laboratoryInscpTotal,
  301. "treatCostTotal": treatCostTotal,
  302. "treatCostSelfTotal": treatCostSelfTotal,
  303. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  304. "treatSelfTotal": treatSelfTotal,
  305. "treatInscpTotal": treatInscpTotal,
  306. "doctor_info": doctor_info,
  307. "doctor_name": doctor_name,
  308. "health_card_no": order.PsnNo,
  309. "yiliao_leibie": yiliao_leibie,
  310. "patient": patient,
  311. "org_name": miConfig.OrgName,
  312. "org_code": miConfig.Code,
  313. "order_number": order.Number,
  314. "his_hospital": his_hospital,
  315. "dia_config": dia_config,
  316. })
  317. }
  318. func (c *PublicApiController) GetBaiLinExportData() {
  319. data := service.GetBaiLinOrderData()
  320. fmt.Println(len(data))
  321. var new_data []*models.NewCustomHisOrder
  322. for _, item := range data {
  323. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  324. new_data = append(new_data, item)
  325. }
  326. }
  327. fmt.Println(len(new_data))
  328. c.ServeSuccessJSON(map[string]interface{}{
  329. "list": new_data,
  330. })
  331. }
  332. func (c *HisApiController) GetHisUnChargePatientList() {
  333. record_date := c.GetString("record_date")
  334. timeLayout := "2006-01-02"
  335. loc, _ := time.LoadLocation("Local")
  336. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  337. if err != nil {
  338. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  339. return
  340. }
  341. recordDateTime := theTime.Unix()
  342. adminInfo := c.GetAdminUserInfo()
  343. var tempPatients []*service.NewTempPatients
  344. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  345. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  346. var patients []*service.NewTempPatients
  347. var patients_two []*service.NewTempPatients
  348. for _, item := range tempPatients {
  349. //过滤掉没挂号的和没开处方的
  350. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  351. patients = append(patients, item)
  352. }
  353. //过滤掉没挂号的
  354. if len(item.HisPatient) > 0 {
  355. patients_two = append(patients_two, item)
  356. }
  357. }
  358. c.ServeSuccessJSON(map[string]interface{}{
  359. "list": patients,
  360. "list_two": patients_two,
  361. })
  362. }
  363. func (c *HisApiController) GetPrivateExpensesOrder() {
  364. //id, _ := c.GetInt64("id")
  365. //record_time := c.GetString("record_time")
  366. order_id, _ := c.GetInt64("order_id")
  367. admin_user_id, _ := c.GetInt64("admin_user_id")
  368. //timeLayout := "2006-01-02"
  369. //loc, _ := time.LoadLocation("Local")
  370. //
  371. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  372. //if err != nil {
  373. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  374. // return
  375. //}
  376. //recordDateTime := theTime.Unix()
  377. adminUser := c.GetAdminUserInfo()
  378. order, _ := service.GetHisOrderByID(order_id)
  379. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  380. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  381. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  382. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  383. //var config []*models.HisXtDiagnoseConfig
  384. var name string
  385. if order.PType == 1 {
  386. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  387. for _, item := range diagnosis_ids {
  388. id, _ := strconv.ParseInt(item, 10, 64)
  389. diagnosisConfig, _ := service.FindDiagnoseById(id)
  390. if len(name) == 0 {
  391. name = diagnosisConfig.ClassName
  392. } else {
  393. name = name + "," + diagnosisConfig.ClassName
  394. }
  395. }
  396. } else {
  397. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  398. for _, item := range diagnosis_ids {
  399. id, _ := strconv.ParseInt(item, 10, 64)
  400. diagnosisConfig, _ := service.FindDiagnoseById(id)
  401. if len(name) == 0 {
  402. name = diagnosisConfig.ClassName
  403. } else {
  404. name = name + "," + diagnosisConfig.ClassName
  405. }
  406. }
  407. }
  408. var bedCostTotal float64 = 0 //床位总费
  409. //var bedCostSelfTotal float64 = 0 //床位自费
  410. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  411. var operationCostTotal float64 = 0 //手术费
  412. //var operationCostSelfTotal float64 = 0 //手术费
  413. var operationCostPartSelfTotal float64 = 0 //手术费
  414. var otherCostTotal float64 = 0 //其他费用
  415. //var otherCostSelfTotal float64 = 0 //其他费用
  416. var otherCostPartSelfTotal float64 = 0 //其他费用
  417. var materialCostTotal float64 = 0 //材料费
  418. //var materialCostSelfTotal float64 = 0 //材料费
  419. var materialCostPartSelfTotal float64 = 0 //材料费
  420. var westernMedicineCostTotal float64 = 0 //西药费
  421. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  422. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  423. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  424. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  425. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  426. var checkCostTotal float64 = 0 //检查费
  427. //var checkCostSelfTotal float64 = 0 //检查费
  428. var checkCostPartSelfTotal float64 = 0 //检查费
  429. var laboratoryCostTotal float64 = 0 //化验费
  430. //var laboratoryCostSelfTotal float64 = 0 //化验费
  431. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  432. var treatCostTotal float64 = 0 //治疗费用
  433. //var treatCostSelfTotal float64 = 0 //治疗费用
  434. var treatCostPartSelfTotal float64 = 0 //治疗费用
  435. var zhenChaCostTotal float64 = 0 //其他费用
  436. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  437. decimal.DivisionPrecision = 2
  438. for _, item := range orderInfos {
  439. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  440. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  441. item.MedChrgitmType = "09"
  442. }
  443. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  444. if item.HisPrescriptionProject.Type == 2 {
  445. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  446. fmt.Println("CostClassify")
  447. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  448. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  449. case 0:
  450. item.MedChrgitmType = "0"
  451. break
  452. case 1:
  453. item.MedChrgitmType = "14"
  454. break
  455. case 2:
  456. item.MedChrgitmType = "05"
  457. break
  458. case 3:
  459. item.MedChrgitmType = "03"
  460. break
  461. case 4:
  462. item.MedChrgitmType = "03"
  463. break
  464. case 5:
  465. item.MedChrgitmType = "08"
  466. break
  467. case 6:
  468. item.MedChrgitmType = "14"
  469. break
  470. case 7:
  471. item.MedChrgitmType = "14"
  472. break
  473. case 8:
  474. item.MedChrgitmType = "03"
  475. break
  476. case 9:
  477. item.MedChrgitmType = "14"
  478. break
  479. case 10:
  480. item.MedChrgitmType = "14"
  481. break
  482. case 11:
  483. item.MedChrgitmType = "06"
  484. break
  485. case 12:
  486. item.MedChrgitmType = "12"
  487. break
  488. case 13:
  489. item.MedChrgitmType = "01"
  490. break
  491. case 14:
  492. item.MedChrgitmType = "04"
  493. break
  494. case 15:
  495. item.MedChrgitmType = "14"
  496. break
  497. }
  498. } else {
  499. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  500. case 1:
  501. item.MedChrgitmType = "14"
  502. break
  503. case 2:
  504. item.MedChrgitmType = "05"
  505. break
  506. case 3:
  507. item.MedChrgitmType = "04"
  508. break
  509. case 4:
  510. item.MedChrgitmType = "14"
  511. break
  512. case 5:
  513. item.MedChrgitmType = "08"
  514. break
  515. case 6:
  516. item.MedChrgitmType = "14"
  517. break
  518. case 7:
  519. item.MedChrgitmType = "14"
  520. break
  521. case 8:
  522. item.MedChrgitmType = "03"
  523. break
  524. case 9:
  525. item.MedChrgitmType = "14"
  526. break
  527. }
  528. }
  529. } else if item.HisPrescriptionProject.Type == 3 {
  530. item.MedChrgitmType = "08"
  531. }
  532. }
  533. }
  534. order.PsnCashPay = order.MedfeeSumamt
  535. for _, item := range orderInfos {
  536. if item.MedChrgitmType == "01" { //床位费
  537. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  538. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  539. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  540. }
  541. if item.MedChrgitmType == "02" { //诊察费
  542. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  543. //zhenChaCostSelfTotal = zhenChaCostTotal
  544. }
  545. if item.MedChrgitmType == "03" { //检查费
  546. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  547. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  548. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  549. }
  550. if item.MedChrgitmType == "02" { //检查费
  551. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  552. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  553. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  554. }
  555. if item.MedChrgitmType == "04" { //化验费
  556. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  557. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  558. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  559. }
  560. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  561. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  562. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  563. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  564. }
  565. if item.MedChrgitmType == "06" { //手术费
  566. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  567. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  568. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  569. }
  570. if item.MedChrgitmType == "08" { //材料费
  571. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  572. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  573. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  574. }
  575. if item.MedChrgitmType == "09" { //西药费
  576. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  577. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  578. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  579. }
  580. if item.MedChrgitmType == "11" { //中成费
  581. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  582. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  583. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  584. }
  585. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  586. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  587. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  588. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  589. }
  590. }
  591. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  592. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  593. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  594. patient, _ := service.GetPatientByID(order.UserOrgId, order.PatientId)
  595. c.ServeSuccessJSON(map[string]interface{}{
  596. "patient": patient,
  597. "order_infos": orderInfos,
  598. "diagnosis": name,
  599. "bedCostTotal": bedCostTotal,
  600. "bedCostSelfTotal": bedCostTotal,
  601. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  602. "operationCostTotal": operationCostTotal,
  603. "operationCostSelfTotal": operationCostTotal,
  604. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  605. "otherCostTotal": otherCostTotal,
  606. "otherCostSelfTotal": otherCostTotal,
  607. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  608. "materialCostTotal": materialCostTotal,
  609. "materialCostSelfTotal": materialCostTotal,
  610. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  611. "westernMedicineCostTotal": westernMedicineCostTotal,
  612. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  613. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  614. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  615. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  616. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  617. "checkCostTotal": checkCostTotal,
  618. "checkCostSelfTotal": checkCostTotal,
  619. "zhenChaCostTotal": zhenChaCostTotal,
  620. "zhenChaCostSelfTotal": zhenChaCostTotal,
  621. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  622. "laboratoryCostTotal": laboratoryCostTotal,
  623. "laboratoryCostSelfTotal": laboratoryCostTotal,
  624. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  625. "treatCostTotal": treatCostTotal,
  626. "treatCostSelfTotal": treatCostTotal,
  627. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  628. "charge_admin": charge_admin,
  629. "printor_admin": printor_admin,
  630. "org_name": org.OrgName,
  631. "org_code": miConfig.Code,
  632. "name": patient.Name,
  633. "number": order.MdtrtId,
  634. "date": order.SettleAccountsDate,
  635. "info": order,
  636. "his_hospital": his_hospital,
  637. "his": his,
  638. })
  639. }
  640. func (c *HisApiController) RefudDetail() {
  641. order_id, _ := c.GetInt64("order_id")
  642. order, _ := service.GetHisOrderByID(order_id)
  643. adminUser := c.GetAdminUserInfo()
  644. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  645. c.ServeSuccessJSON(map[string]interface{}{
  646. "msg": "撤销成功",
  647. })
  648. }
  649. func (c *HisApiController) Sscard() {
  650. //r := CardInit()
  651. //if r == 0 {
  652. // GetBaseInfo()
  653. //}
  654. //c.ServeSuccessJSON(map[string]interface{}{
  655. // "list": "11",
  656. //})
  657. }
  658. func GetBaseInfo() error {
  659. //handle := syscall.MustLoadDLL("SSCard.dll")
  660. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  661. //
  662. //str := make([]byte, 256)
  663. //str1 := make([]byte, 256)
  664. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  665. //if ferr != nil {
  666. // fmt.Println("ReadCardBas 报错", ferr.Error())
  667. // return ferr
  668. //}
  669. //
  670. //fmt.Println(string(str))
  671. //
  672. //fmt.Println(r)
  673. return nil
  674. }
  675. func CardInit() int {
  676. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  677. //add := DllTestDef.MustFindProc("Init")
  678. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  679. //if err != nil {
  680. // fmt.Println("SSCard的运算结果为:", ret)
  681. //}
  682. //result := int(ret)
  683. return 0
  684. }
  685. func IntPtr(n int) uintptr {
  686. return uintptr(n)
  687. }
  688. func StrPtr(s string) uintptr {
  689. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  690. }
  691. func (c *HisApiController) GetHisPatientList() {
  692. //types, _ := c.GetInt64("type", 0)
  693. record_date := c.GetString("record_date")
  694. sch_type, _ := c.GetInt64("sch_type")
  695. timeLayout := "2006-01-02"
  696. loc, _ := time.LoadLocation("Local")
  697. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  698. if err != nil {
  699. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  700. return
  701. }
  702. recordDateTime := theTime.Unix()
  703. adminInfo := c.GetAdminUserInfo()
  704. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  705. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  706. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  707. //获取当前用户的信息
  708. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  709. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  710. //获取所有科室信息
  711. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  712. c.ServeSuccessJSON(map[string]interface{}{
  713. "list": patients,
  714. "list_two": patients_two,
  715. "info": adminUserInfo,
  716. "doctors": doctors,
  717. "department": department,
  718. })
  719. }
  720. type CustomTemplate struct {
  721. ID int64 `gorm:"column:id" json:"id" form:"id"`
  722. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  723. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  724. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  725. Status int64 `gorm:"column:status" json:"status" form:"status"`
  726. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  727. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  728. Type int64 `gorm:"column:type" json:"type" form:"type"`
  729. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  730. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  731. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  732. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  733. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  734. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  735. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  736. }
  737. func (c *HisApiController) GetHisPatientInfo() {
  738. patient_id, _ := c.GetInt64("patient_id")
  739. his_patient_id, _ := c.GetInt64("his_patient_id")
  740. record_date := c.GetString("record_date")
  741. number := c.GetString("number")
  742. //start_time := c.GetString("start_time")
  743. //end_time := c.GetString("end_time")
  744. p_type, _ := c.GetInt64("p_type")
  745. timeLayout := "2006-01-02"
  746. loc, _ := time.LoadLocation("Local")
  747. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  748. if err != nil {
  749. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  750. return
  751. }
  752. recordDateTime := theTime.Unix()
  753. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  754. //if err != nil {
  755. //
  756. //}
  757. //startRecordDateTime := startTime.Unix()
  758. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  759. //if err != nil {
  760. //
  761. //}
  762. //endRecordDateTime := endTime.Unix()
  763. admin := c.GetAdminUserInfo()
  764. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  765. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  766. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  767. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  768. var prescriptions []*models.HisPrescription
  769. var last_prescriptions []*models.HisPrescription
  770. var sch_prescriptions []CustomTemplate
  771. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  772. if p_type == 1 { //住院
  773. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  774. for _, item := range prescriptions {
  775. for _, subItem := range item.HisDoctorAdviceInfo {
  776. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  777. if info.RetailPrice > 0 {
  778. subItem.Drug.MinPrice = info.RetailPrice
  779. }
  780. }
  781. }
  782. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  783. } else { //门诊
  784. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  785. for _, item := range prescriptions {
  786. for _, subItem := range item.HisDoctorAdviceInfo {
  787. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  788. if info.RetailPrice > 0 {
  789. subItem.Drug.MinPrice = info.RetailPrice
  790. }
  791. }
  792. }
  793. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  794. }
  795. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  796. if sch.ID > 0 {
  797. var week string
  798. t := time.Now()
  799. switch t.Weekday().String() {
  800. case "Monday":
  801. week = "周一"
  802. break
  803. case "Tuesday":
  804. week = "周二"
  805. break
  806. case "Wednesday":
  807. week = "周三"
  808. break
  809. case "Thursday":
  810. week = "周四"
  811. break
  812. case "Friday":
  813. week = "周五"
  814. break
  815. case "Saturday":
  816. week = "周六"
  817. break
  818. case "Sunday":
  819. week = "周日"
  820. break
  821. }
  822. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  823. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  824. //根据推送频率组装新的数组
  825. for _, item := range temp_sch_prescriptions {
  826. var cus CustomTemplate
  827. cus.ID = item.ID
  828. cus.UserOrgId = item.UserOrgId
  829. cus.PatientId = item.PatientId
  830. cus.MedType = item.MedType
  831. cus.RecordDate = item.RecordDate
  832. cus.Type = item.Type
  833. cus.PType = item.PType
  834. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  835. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  836. if subItem.FrequencyType == 1 { //每次必推
  837. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  838. }
  839. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  840. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  841. }
  842. if subItem.FrequencyType == 2 { //按照天数频率
  843. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  844. now := p.Unix()
  845. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  846. dayStr2 := "-" + dayStr
  847. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  848. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  849. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  850. if len(advices) == 0 {
  851. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  852. }
  853. }
  854. }
  855. }
  856. for _, subItem := range item.HisPrescriptionProjectTemplate {
  857. if subItem.Type == 2 {
  858. if subItem.XtHisProject.MedicalStatus != 1 {
  859. if subItem.FrequencyType == 1 {
  860. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  861. }
  862. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  863. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  864. }
  865. if subItem.FrequencyType == 2 {
  866. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  867. now := p.Unix()
  868. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  869. dayStr2 := "-" + dayStr
  870. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  871. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  872. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  873. if len(projects) == 0 {
  874. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  875. }
  876. }
  877. }
  878. } else if subItem.Type == 3 {
  879. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  880. if subItem.FrequencyType == 1 {
  881. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  882. }
  883. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  884. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  885. }
  886. if subItem.FrequencyType == 2 {
  887. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  888. now := p.Unix()
  889. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  890. dayStr2 := "-" + dayStr
  891. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  892. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  893. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  894. if len(projects) == 0 {
  895. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  896. }
  897. }
  898. }
  899. }
  900. }
  901. sch_prescriptions = append(sch_prescriptions, cus)
  902. }
  903. for _, item := range sch_prescriptions {
  904. if len(item.HisPrescriptionProjectTemplate) == 0 {
  905. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  906. }
  907. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  908. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  909. }
  910. }
  911. }
  912. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  913. if config.ID > 0 && config.IsOpen == 1 {
  914. for _, item := range sch_prescriptions {
  915. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  916. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  917. if info.RetailPrice > 0 {
  918. subItem.Drug.MinPrice = info.RetailPrice
  919. }
  920. }
  921. }
  922. }
  923. if config.ID > 0 && config.IsOpen == 1 {
  924. for _, item := range sch_prescriptions {
  925. for _, subItem := range item.HisPrescriptionProjectTemplate {
  926. if subItem.Type == 3 {
  927. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  928. if info.Price > 0 {
  929. subItem.GoodInfo.PackingPrice = info.Price
  930. }
  931. }
  932. }
  933. }
  934. }
  935. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  936. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  937. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  938. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  939. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  940. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  941. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  942. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  943. //获取所有科室信息
  944. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  945. c.ServeSuccessJSON(map[string]interface{}{
  946. "his_info": his_patient_info,
  947. "xt_info": xt_patient_info,
  948. "prescription": prescriptions,
  949. "case_history": case_history,
  950. "info": patientPrescriptionInfo,
  951. //"month_prescriptions": monthPrescriptions,
  952. "order": order,
  953. "doctors": doctors,
  954. "department": department,
  955. "sch_prescriptions": sch_prescriptions,
  956. "last_prescriptions": last_prescriptions,
  957. "schedule": sch,
  958. "count": count,
  959. "drugStockConfig": drugStockConfig,
  960. "last_info": lastPatientPrescriptionInfo,
  961. })
  962. return
  963. }
  964. func (c *HisApiController) GetHisPrescriptionConfig() {
  965. adminInfo := c.GetAdminUserInfo()
  966. //获取医嘱模版
  967. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  968. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  969. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  970. //获取所有基础药
  971. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  972. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  973. if config.ID > 0 && config.IsOpen == 1 {
  974. for _, item := range drugs {
  975. var index = 0
  976. for _, subItem := range item.OtherDrugWarehouseInfo {
  977. if index == 0 {
  978. index = index + 1
  979. if subItem.RetailPrice > 0 {
  980. item.MinPrice = subItem.RetailPrice
  981. }
  982. }
  983. }
  984. }
  985. }
  986. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  987. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  988. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  989. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  990. //获取所有科室信息
  991. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  992. //获取诊断信息
  993. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  994. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  995. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  996. //获取是否开启保存耗材出库的开关
  997. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  998. c.ServeSuccessJSON(map[string]interface{}{
  999. "drugs": drugs,
  1000. "advices_template": advices,
  1001. "drugways": drugways,
  1002. "efs": efs,
  1003. "doctors": doctors,
  1004. "department": department,
  1005. "sick": sick,
  1006. "additions": additions,
  1007. "diagnose": diagnose,
  1008. "manufacturers": manufacturers,
  1009. "goodOutOpen": goodOutOpen,
  1010. })
  1011. }
  1012. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1013. //获取所有基础药
  1014. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1015. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1016. if config.ID > 0 && config.IsOpen == 1 {
  1017. for _, item := range drugs {
  1018. var index = 0
  1019. for _, subItem := range item.OtherDrugWarehouseInfo {
  1020. if index == 0 {
  1021. index = index + 1
  1022. if subItem.RetailPrice > 0 {
  1023. item.MinPrice = subItem.RetailPrice
  1024. }
  1025. }
  1026. }
  1027. }
  1028. }
  1029. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1030. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1031. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1032. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1033. //获取所有科室信息
  1034. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1035. //获取诊断信息
  1036. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1037. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1038. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1039. //获取是否开启保存耗材出库的开关
  1040. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1041. c.ServeSuccessJSON(map[string]interface{}{
  1042. "drugs": drugs,
  1043. "advices_template": advices,
  1044. "drugways": drugways,
  1045. "efs": efs,
  1046. "doctors": doctors,
  1047. "department": department,
  1048. "sick": sick,
  1049. "additions": additions,
  1050. "diagnose": diagnose,
  1051. "manufacturers": manufacturers,
  1052. "goodOutOpen": goodOutOpen,
  1053. })
  1054. }
  1055. }
  1056. func (c *HisApiController) CreateHisPrescription() {
  1057. record_date := c.GetString("record_date")
  1058. patient_id, _ := c.GetInt64("patient_id")
  1059. reg_type, _ := c.GetInt64("reg_type")
  1060. diagnose := c.GetString("diagnose")
  1061. sick_type, _ := c.GetInt64("sick_type")
  1062. sick_history := c.GetString("sick_history")
  1063. doctor_id, _ := c.GetInt64("doctor", 0)
  1064. department, _ := c.GetInt64("department", 0)
  1065. his_patient_id, _ := c.GetInt64("his_patient_id")
  1066. p_type, _ := c.GetInt64("p_type")
  1067. dataBody := make(map[string]interface{}, 0)
  1068. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1069. if err != nil {
  1070. utils.ErrorLog(err.Error())
  1071. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1072. return
  1073. }
  1074. timeLayout := "2006-01-02"
  1075. loc, _ := time.LoadLocation("Local")
  1076. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1077. if err != nil {
  1078. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1079. return
  1080. }
  1081. adminInfo := c.GetAdminUserInfo()
  1082. recordDateTime := theTime.Unix()
  1083. //查询默认出库仓库库存
  1084. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1085. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1086. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1087. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1088. if len(lists) == 1 {
  1089. his_patient_id = lists[0].ID
  1090. }
  1091. }
  1092. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1093. //保存处方出库
  1094. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1095. //自动出库
  1096. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1097. //耗材保存处方出库
  1098. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1099. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1100. //已发药和已收费限制逻辑
  1101. isMidicine := false
  1102. isCharge := false
  1103. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1104. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1105. if len(prescriptions) > 0 {
  1106. for _, item := range prescriptions {
  1107. items := item.(map[string]interface{})
  1108. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1109. utils.ErrorLog("id")
  1110. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1111. return
  1112. }
  1113. id := int64(items["id"].(float64))
  1114. if id > 0 {
  1115. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1116. if err != nil {
  1117. if new_prescription.OrderStatus == 4 {
  1118. isCharge = true
  1119. }
  1120. }
  1121. }
  1122. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1123. advices := items["advices"].([]interface{})
  1124. if len(advices) > 0 {
  1125. for _, advice := range advices {
  1126. var adviceId int64
  1127. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1128. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1129. }
  1130. if adviceId > 0 {
  1131. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1132. if err == nil {
  1133. if his_advice_info.IsMedicine == 1 {
  1134. isMidicine = true
  1135. }
  1136. }
  1137. }
  1138. }
  1139. }
  1140. }
  1141. }
  1142. }
  1143. }
  1144. if isMidicine == true {
  1145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1146. return
  1147. }
  1148. if isCharge == true {
  1149. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1150. return
  1151. }
  1152. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1153. fmt.Println("0230032032032032032032023---------------", pharmacyConfig.IsOpen)
  1154. //药品发药出库
  1155. if pharmacyConfig.IsOpen == 1 {
  1156. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1157. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1158. if len(prescriptions) > 0 {
  1159. for _, item := range prescriptions {
  1160. items := item.(map[string]interface{})
  1161. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1162. advices := items["advices"].([]interface{})
  1163. if len(advices) > 0 {
  1164. for _, advice := range advices {
  1165. var drug_id int64
  1166. var prescribing_number float64
  1167. var prescribingNumberUnit string
  1168. var adviceId int64
  1169. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1170. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1171. }
  1172. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1173. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1174. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1175. }
  1176. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1177. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1178. }
  1179. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1180. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1181. }
  1182. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1183. if drug.ID == 0 {
  1184. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1185. return
  1186. }
  1187. //查询药品的所有库存
  1188. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1189. var total_count int64
  1190. for _, it := range list {
  1191. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1192. }
  1193. totals := strconv.FormatInt(total_count, 10)
  1194. //查询该药品是否存在开药记录
  1195. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1196. //新增处方
  1197. if advicelist.ID == 0 {
  1198. all_count, _ := strconv.ParseFloat(totals, 64)
  1199. if prescribingNumberUnit == drug.MinUnit {
  1200. if drug.IsUse != 1 {
  1201. if prescribing_number > all_count {
  1202. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1203. return
  1204. }
  1205. }
  1206. }
  1207. if prescribingNumberUnit == drug.MaxUnit {
  1208. num := prescribing_number * float64(drug.MinNumber)
  1209. if drug.IsUse != 1 {
  1210. if num > all_count {
  1211. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1212. return
  1213. }
  1214. }
  1215. }
  1216. }
  1217. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1218. if drugOutConfig.IsOpen != 1 {
  1219. //修改处方
  1220. for _, advice := range advices {
  1221. var drug_id int64
  1222. var prescribing_number float64
  1223. var prescribingNumberUnit string
  1224. var prescribingNumber string
  1225. var adviceId int64
  1226. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1227. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1228. }
  1229. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1230. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1231. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1232. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1233. }
  1234. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1235. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1236. }
  1237. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1238. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1239. }
  1240. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1241. if drug.ID == 0 {
  1242. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1243. return
  1244. }
  1245. //查询药品的所有库存
  1246. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1247. var total_count int64
  1248. for _, it := range list {
  1249. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1250. }
  1251. totals := strconv.FormatInt(total_count, 10)
  1252. //查询该药品是否存在开药记录
  1253. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1254. //新增处方
  1255. if advicelist.ID == 0 {
  1256. all_count, _ := strconv.ParseFloat(totals, 64)
  1257. if prescribingNumberUnit == drug.MinUnit {
  1258. if drug.IsUse != 1 {
  1259. if prescribing_number > all_count {
  1260. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1261. return
  1262. }
  1263. }
  1264. } else {
  1265. if prescribingNumberUnit == drug.MaxUnit {
  1266. num := prescribing_number * float64(drug.MinNumber)
  1267. if drug.IsUse != 1 {
  1268. if num > all_count {
  1269. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1270. return
  1271. }
  1272. }
  1273. }
  1274. }
  1275. }
  1276. //修改处方
  1277. if advicelist.ID > 0 {
  1278. var device_number int64
  1279. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1280. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1281. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1282. device_number = prescribingNumberInt * drug.MinNumber
  1283. }
  1284. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1285. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1286. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1287. device_number = prescribingNumberInt
  1288. }
  1289. var number_count int64
  1290. if prescribingNumberUnit == drug.MaxUnit {
  1291. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1292. number_count = prescribingNumberInt * drug.MinNumber
  1293. }
  1294. if prescribingNumberUnit == drug.MinUnit {
  1295. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1296. number_count = prescribingNumberInt
  1297. }
  1298. //如果修改的数量大于之前修改的数量
  1299. if (number_count - device_number) > 0 {
  1300. //如果修改的差数量 大于库存数量
  1301. if drug.IsUse != 1 {
  1302. if (number_count - device_number) > total_count {
  1303. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1304. return
  1305. }
  1306. }
  1307. }
  1308. }
  1309. }
  1310. }
  1311. }
  1312. }
  1313. }
  1314. }
  1315. }
  1316. }
  1317. }
  1318. //已发药和已收费限制逻辑
  1319. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1320. //校验库存总量
  1321. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1322. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1323. if len(prescriptions) > 0 {
  1324. for _, item := range prescriptions {
  1325. items := item.(map[string]interface{})
  1326. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1327. advices := items["advices"].([]interface{})
  1328. if len(advices) > 0 {
  1329. for _, advice := range advices {
  1330. var drug_id int64
  1331. var prescribing_number float64
  1332. var prescribingNumberUnit string
  1333. var adviceId int64
  1334. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1335. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1336. }
  1337. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1338. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1339. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1340. }
  1341. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1342. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1343. }
  1344. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1345. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1346. }
  1347. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1348. if drug.ID == 0 {
  1349. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1350. return
  1351. }
  1352. //查询药品的所有库存
  1353. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1354. var total_count int64
  1355. for _, it := range list {
  1356. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1357. }
  1358. totals := strconv.FormatInt(total_count, 10)
  1359. //查询该药品是否存在开药记录
  1360. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1361. //查询最新批次库存
  1362. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1363. var batch_number_count int64
  1364. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1365. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1366. //新增处方
  1367. if advicelist.ID == 0 {
  1368. all_count, _ := strconv.ParseFloat(totals, 64)
  1369. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1370. if prescribingNumberUnit == drug.MinUnit {
  1371. if drug.IsUse != 1 {
  1372. if prescribing_number > all_count {
  1373. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1374. return
  1375. }
  1376. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1377. if prescribing_number > batch_number_all_count {
  1378. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1379. return
  1380. }
  1381. }
  1382. }
  1383. }
  1384. if prescribingNumberUnit == drug.MaxUnit {
  1385. num := prescribing_number * float64(drug.MinNumber)
  1386. if drug.IsUse != 1 {
  1387. if num > all_count {
  1388. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1389. return
  1390. }
  1391. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1392. if num > batch_number_all_count {
  1393. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1394. return
  1395. }
  1396. }
  1397. }
  1398. }
  1399. }
  1400. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1401. if drugOutConfig.IsOpen != 1 {
  1402. //修改处方
  1403. for _, advice := range advices {
  1404. var drug_id int64
  1405. var prescribing_number float64
  1406. var prescribingNumberUnit string
  1407. var prescribingNumber string
  1408. var adviceId int64
  1409. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1410. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1411. }
  1412. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1413. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1414. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1415. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1416. }
  1417. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1418. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1419. }
  1420. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1421. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1422. }
  1423. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1424. if drug.ID == 0 {
  1425. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1426. return
  1427. }
  1428. //查询药品的所有库存
  1429. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1430. var total_count int64
  1431. for _, it := range list {
  1432. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1433. }
  1434. totals := strconv.FormatInt(total_count, 10)
  1435. //查询该药品是否存在开药记录
  1436. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1437. //新增处方
  1438. if advicelist.ID == 0 {
  1439. //查询最新批次库存
  1440. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1441. var batch_number_count int64
  1442. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1443. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1444. all_count, _ := strconv.ParseFloat(totals, 64)
  1445. if prescribingNumberUnit == drug.MinUnit {
  1446. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1447. if drug.IsUse != 1 {
  1448. if prescribing_number > all_count {
  1449. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1450. return
  1451. }
  1452. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1453. if prescribing_number > batch_number_all_count {
  1454. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1455. return
  1456. }
  1457. }
  1458. }
  1459. } else {
  1460. if prescribingNumberUnit == drug.MaxUnit {
  1461. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1462. num := prescribing_number * float64(drug.MinNumber)
  1463. if drug.IsUse != 1 {
  1464. if num > all_count {
  1465. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1466. return
  1467. }
  1468. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1469. if prescribing_number > batch_number_all_count {
  1470. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1471. return
  1472. }
  1473. }
  1474. }
  1475. }
  1476. }
  1477. }
  1478. //修改处方
  1479. if advicelist.ID > 0 {
  1480. //查询最新批次库存
  1481. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1482. var batch_number_count int64
  1483. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1484. var device_number int64
  1485. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1486. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1487. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1488. device_number = prescribingNumberInt * drug.MinNumber
  1489. }
  1490. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1491. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1492. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1493. device_number = prescribingNumberInt
  1494. }
  1495. var number_count int64
  1496. if prescribingNumberUnit == drug.MaxUnit {
  1497. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1498. number_count = prescribingNumberInt * drug.MinNumber
  1499. }
  1500. if prescribingNumberUnit == drug.MinUnit {
  1501. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1502. number_count = prescribingNumberInt
  1503. }
  1504. //如果修改的数量大于之前修改的数量
  1505. if (number_count - device_number) > 0 {
  1506. //如果修改的差数量 大于库存数量
  1507. if drug.IsUse != 1 {
  1508. if (number_count - device_number) > total_count {
  1509. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1510. return
  1511. }
  1512. if (number_count - device_number) > batch_number_count {
  1513. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1514. return
  1515. }
  1516. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1517. // 查询该药品最后一次出库记录
  1518. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1519. var out_count int64
  1520. var in_count int64
  1521. var stock_max_number int64
  1522. var stock_min_number int64
  1523. for _, it := range outInfo {
  1524. if it.CountUnit == drug.MaxUnit {
  1525. it.Count = it.Count * drug.MinNumber
  1526. }
  1527. out_count += it.Count
  1528. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1529. stock_max_number = warehouseInfoList.StockMaxNumber
  1530. stock_min_number = warehouseInfoList.StockMinNumber
  1531. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1532. }
  1533. if out_count > 0 {
  1534. if (number_count - device_number) > in_count {
  1535. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1536. return
  1537. }
  1538. }
  1539. // 未出库
  1540. if out_count == 0 {
  1541. var sum_in_count int64
  1542. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1543. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1544. fmt.Println("sum_in_count", sum_in_count)
  1545. //如果修改的数量大于有库存的第一个批次
  1546. if number_count > sum_in_count {
  1547. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  1548. return
  1549. }
  1550. }
  1551. }
  1552. }
  1553. }
  1554. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1555. fmt.Println("device_number2333233232323222323232323323322332", device_number)
  1556. fmt.Println("number_count99999999999999999999999999999999999", number_count)
  1557. if pharmacyConfig.IsOpen != 1 {
  1558. if device_number != number_count {
  1559. // 查询该药品最后一次出库记录
  1560. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  1561. //回退库存
  1562. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  1563. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  1564. }
  1565. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  1566. var stock_max_number int64
  1567. var stock_min_number int64
  1568. if number_count >= drug.MinNumber {
  1569. stock_max_number = device_number / drug.MinNumber
  1570. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  1571. stock_min_number = device_number % drug.MinNumber
  1572. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  1573. } else {
  1574. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  1575. }
  1576. }
  1577. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  1578. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  1579. }
  1580. //删除记录
  1581. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  1582. //查询默认仓库剩余多少库存
  1583. var sum_count int64
  1584. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  1585. for _, its := range stockInfo {
  1586. if its.MaxUnit == drug.MaxUnit {
  1587. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  1588. }
  1589. sum_count += its.StockMaxNumber + its.StockMinNumber
  1590. }
  1591. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  1592. }
  1593. }
  1594. }
  1595. }
  1596. }
  1597. //保存处方开药
  1598. if drugOutConfig.IsOpen == 1 {
  1599. //修改处方
  1600. for _, advice := range advices {
  1601. var drug_id int64
  1602. var prescribing_number float64
  1603. var prescribingNumberUnit string
  1604. var prescribingNumber string
  1605. var adviceId int64
  1606. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1607. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1608. }
  1609. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1610. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1611. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1612. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1613. }
  1614. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1615. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1616. }
  1617. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1618. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1619. }
  1620. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1621. if drug.ID == 0 {
  1622. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1623. return
  1624. }
  1625. //查询药品的所有库存
  1626. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1627. var total_count int64
  1628. for _, it := range list {
  1629. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1630. }
  1631. totals := strconv.FormatInt(total_count, 10)
  1632. //查询该药品是否存在开药记录
  1633. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1634. //新增处方
  1635. if advicelist.ID == 0 {
  1636. //查询最新批次库存
  1637. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1638. var batch_number_count int64
  1639. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1640. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1641. all_count, _ := strconv.ParseFloat(totals, 64)
  1642. if prescribingNumberUnit == drug.MinUnit {
  1643. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1644. if drug.IsUse != 1 {
  1645. if prescribing_number > all_count {
  1646. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1647. return
  1648. }
  1649. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1650. if prescribing_number > batch_number_all_count {
  1651. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1652. return
  1653. }
  1654. }
  1655. }
  1656. } else {
  1657. if prescribingNumberUnit == drug.MaxUnit {
  1658. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1659. num := prescribing_number * float64(drug.MinNumber)
  1660. if drug.IsUse != 1 {
  1661. if num > all_count {
  1662. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1663. return
  1664. }
  1665. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1666. if prescribing_number > batch_number_all_count {
  1667. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1668. return
  1669. }
  1670. }
  1671. }
  1672. }
  1673. }
  1674. }
  1675. //修改处方
  1676. if advicelist.ID > 0 {
  1677. //查询最新批次库存
  1678. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1679. var batch_number_count int64
  1680. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1681. var device_number int64
  1682. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1683. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1684. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1685. device_number = prescribingNumberInt * drug.MinNumber
  1686. }
  1687. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1688. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1689. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1690. device_number = prescribingNumberInt
  1691. }
  1692. var number_count int64
  1693. if prescribingNumberUnit == drug.MaxUnit {
  1694. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1695. number_count = prescribingNumberInt * drug.MinNumber
  1696. }
  1697. if prescribingNumberUnit == drug.MinUnit {
  1698. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1699. number_count = prescribingNumberInt
  1700. }
  1701. //如果修改的数量大于之前修改的数量
  1702. if (number_count - device_number) > 0 {
  1703. //如果修改的差数量 大于库存数量
  1704. if drug.IsUse != 1 {
  1705. if (number_count - device_number) > total_count {
  1706. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1707. return
  1708. }
  1709. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1710. if (number_count - device_number) > batch_number_count {
  1711. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1712. return
  1713. }
  1714. }
  1715. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1716. //查询历史出库数据总批次
  1717. // 查询该药品最后一次出库记录
  1718. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1719. var out_count int64
  1720. var in_count int64
  1721. var stock_max_number int64
  1722. var stock_min_number int64
  1723. for _, it := range outInfo {
  1724. if it.CountUnit == drug.MaxUnit {
  1725. it.Count = it.Count * drug.MinNumber
  1726. }
  1727. out_count += it.Count
  1728. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1729. stock_max_number = warehouseInfoList.StockMaxNumber
  1730. stock_min_number = warehouseInfoList.StockMinNumber
  1731. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1732. }
  1733. if out_count > 0 {
  1734. if (number_count - device_number) > in_count {
  1735. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1736. return
  1737. }
  1738. }
  1739. // 未出库
  1740. if out_count == 0 {
  1741. var sum_in_count int64
  1742. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1743. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1744. //如果修改的数量大于有库存的第一个批次
  1745. if number_count > sum_in_count {
  1746. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  1747. return
  1748. }
  1749. }
  1750. }
  1751. }
  1752. }
  1753. }
  1754. }
  1755. }
  1756. }
  1757. }
  1758. }
  1759. }
  1760. }
  1761. }
  1762. }
  1763. //校验耗材库存
  1764. if goodOutConfig.IsOpen == 1 {
  1765. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1766. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1767. if len(prescriptions) > 0 {
  1768. for _, item := range prescriptions {
  1769. items := item.(map[string]interface{})
  1770. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1771. projects := items["project"].([]interface{})
  1772. if len(projects) > 0 {
  1773. for _, project := range projects {
  1774. var project_id int64
  1775. var project_type int64
  1776. var totals float64
  1777. var project_name string
  1778. var parsetotal int64
  1779. var id int64
  1780. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  1781. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  1782. }
  1783. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  1784. project_type = int64(project.(map[string]interface{})["type"].(float64))
  1785. }
  1786. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  1787. total, _ := project.(map[string]interface{})["total"].(string)
  1788. totals, _ = strconv.ParseFloat(total, 64)
  1789. }
  1790. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  1791. project_name = project.(map[string]interface{})["project_name"].(string)
  1792. }
  1793. if project_type == 3 {
  1794. //查找该耗材的出库记录
  1795. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  1796. if len(goodWarehouseInfo) == 0 {
  1797. //查询耗材库存
  1798. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  1799. var stock_count int64
  1800. for _, it := range list {
  1801. stock_count += it.StockCount
  1802. }
  1803. stock_counts := strconv.FormatInt(stock_count, 10)
  1804. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  1805. if totals > stock_total_count {
  1806. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  1807. return
  1808. }
  1809. }
  1810. if len(goodWarehouseInfo) > 0 {
  1811. //查询该患者耗材的历史数据
  1812. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  1813. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  1814. //数量发生改变
  1815. if parsetotal != count {
  1816. //如果现在的数量大于历史数量,就要看库存是否足够
  1817. if parsetotal > count {
  1818. //查询耗材所有库存
  1819. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  1820. var stock_count int64
  1821. for _, it := range list {
  1822. stock_count += it.StockCount
  1823. }
  1824. //库存不足
  1825. if (parsetotal - count) > stock_count {
  1826. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  1827. return
  1828. }
  1829. }
  1830. }
  1831. }
  1832. }
  1833. }
  1834. }
  1835. }
  1836. }
  1837. }
  1838. }
  1839. }
  1840. //不使用耗材保存处方出库
  1841. if goodOutConfig.IsOpen != 1 {
  1842. if stockConfig.IsOpen == 1 {
  1843. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1844. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1845. if len(prescriptions) > 0 {
  1846. for _, item := range prescriptions {
  1847. items := item.(map[string]interface{})
  1848. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1849. projects := items["project"].([]interface{})
  1850. if len(projects) > 0 {
  1851. for _, project := range projects {
  1852. var project_id int64
  1853. var project_type int64
  1854. var totals float64
  1855. var project_name string
  1856. var parsetotal int64
  1857. var id int64
  1858. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  1859. id = int64(project.(map[string]interface{})["id"].(float64))
  1860. }
  1861. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  1862. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  1863. }
  1864. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  1865. project_type = int64(project.(map[string]interface{})["type"].(float64))
  1866. }
  1867. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  1868. total, _ := project.(map[string]interface{})["total"].(string)
  1869. totals, _ = strconv.ParseFloat(total, 64)
  1870. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  1871. }
  1872. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  1873. project_name = project.(map[string]interface{})["project_name"].(string)
  1874. }
  1875. if project_type == 3 {
  1876. //查找该耗材的出库记录
  1877. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  1878. //没有出库记录
  1879. if len(goodWarehouseInfo) == 0 {
  1880. //查询耗材库存
  1881. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  1882. var stock_count int64
  1883. for _, it := range list {
  1884. stock_count += it.StockCount
  1885. }
  1886. stock_counts := strconv.FormatInt(stock_count, 10)
  1887. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  1888. if totals > stock_total_count {
  1889. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  1890. return
  1891. }
  1892. //查找今日该患者已经出库的所有耗材
  1893. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  1894. for _, item := range goodList {
  1895. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  1896. var flush_count int64
  1897. for _, it := range goodListSix {
  1898. flush_count += it.StockCount
  1899. }
  1900. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  1901. creater := adminInfo.AdminUser.Id
  1902. if errs != nil {
  1903. goodErrcode := models.XtGoodErrcode{
  1904. UserOrgId: item.OrgId,
  1905. Errcode: "手动出库更新剩余出库失败",
  1906. GoodId: item.GoodId,
  1907. Status: 1,
  1908. Ctime: time.Now().Unix(),
  1909. Mtime: 0,
  1910. Count: 0,
  1911. StockCount: 0,
  1912. Creater: creater,
  1913. BatchNumberId: 0,
  1914. WarehouseOutId: 0,
  1915. }
  1916. service.CreateGoodErrcode(goodErrcode)
  1917. }
  1918. }
  1919. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  1920. }
  1921. //有出库记录
  1922. if len(goodWarehouseInfo) > 0 {
  1923. //查询该患者耗材的历史数据
  1924. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  1925. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  1926. //数量发生改变
  1927. if parsetotal != count {
  1928. //查找今日该患者已经出库的所有耗材
  1929. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  1930. for _, item := range goodList {
  1931. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  1932. var flush_count int64
  1933. for _, it := range goodListSix {
  1934. flush_count += it.StockCount
  1935. }
  1936. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  1937. //减少出库数量
  1938. creater := adminInfo.AdminUser.Id
  1939. if errs != nil {
  1940. goodErrcode := models.XtGoodErrcode{
  1941. UserOrgId: item.OrgId,
  1942. Errcode: "手动出库更新剩余出库失败",
  1943. GoodId: item.GoodId,
  1944. Status: 1,
  1945. Ctime: time.Now().Unix(),
  1946. Mtime: 0,
  1947. Count: 0,
  1948. StockCount: 0,
  1949. Creater: creater,
  1950. BatchNumberId: 0,
  1951. WarehouseOutId: 0,
  1952. }
  1953. service.CreateGoodErrcode(goodErrcode)
  1954. }
  1955. //查询默认仓库
  1956. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  1957. var total_count int64
  1958. for _, it := range stockList {
  1959. total_count += it.StockCount
  1960. }
  1961. //基础库插入数据
  1962. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  1963. }
  1964. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  1965. }
  1966. }
  1967. }
  1968. }
  1969. }
  1970. }
  1971. }
  1972. }
  1973. }
  1974. }
  1975. }
  1976. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1977. var hpInfo models.HisPrescriptionInfo
  1978. if info.ID == 0 {
  1979. var randNum int
  1980. randNum = rand.Intn(10000) + 1000
  1981. timestamp := time.Now().Unix()
  1982. tempTime := time.Unix(timestamp, 0)
  1983. timeFormat := tempTime.Format("20060102150405")
  1984. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  1985. hpInfo = models.HisPrescriptionInfo{
  1986. HisPatientId: his_patient_id,
  1987. UserOrgId: adminInfo.CurrentOrgId,
  1988. RecordDate: theTime.Unix(),
  1989. PatientId: patient_id,
  1990. Status: 1,
  1991. Ctime: time.Now().Unix(),
  1992. Mtime: time.Now().Unix(),
  1993. Creator: adminInfo.AdminUser.Id,
  1994. Modifier: adminInfo.AdminUser.Id,
  1995. Diagnosis: diagnose,
  1996. SickHistory: sick_history,
  1997. Departments: department,
  1998. RegisterType: reg_type,
  1999. PrescriptionNumber: p_number,
  2000. PrescriptionStatus: 1,
  2001. Doctor: role.UserName,
  2002. DoctorId: doctor_id,
  2003. SickType: sick_type,
  2004. PType: p_type,
  2005. }
  2006. service.SavePatientPrescriptionInfo(hpInfo)
  2007. redis := service.RedisClient()
  2008. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2009. redis.Set(key, "", time.Second)
  2010. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2011. redis.Set(keyOne, "", time.Second)
  2012. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2013. redis.Set(keySeven, "", time.Second)
  2014. defer redis.Close()
  2015. } else {
  2016. hpInfo = models.HisPrescriptionInfo{
  2017. ID: info.ID,
  2018. UserOrgId: adminInfo.CurrentOrgId,
  2019. RecordDate: info.RecordDate,
  2020. PatientId: info.PatientId,
  2021. Status: 1,
  2022. Ctime: info.Ctime,
  2023. Mtime: time.Now().Unix(),
  2024. Creator: info.Creator,
  2025. Modifier: adminInfo.AdminUser.Id,
  2026. Diagnosis: diagnose,
  2027. SickHistory: sick_history,
  2028. Departments: department,
  2029. RegisterType: reg_type,
  2030. PrescriptionNumber: info.PrescriptionNumber,
  2031. Doctor: role.UserName,
  2032. PrescriptionStatus: info.PrescriptionStatus,
  2033. DoctorId: doctor_id,
  2034. SickType: sick_type,
  2035. PType: info.PType,
  2036. HisPatientId: info.HisPatientId,
  2037. }
  2038. service.SavePatientPrescriptionInfo(hpInfo)
  2039. redis := service.RedisClient()
  2040. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2041. redis.Set(key, "", time.Second)
  2042. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2043. redis.Set(keyOne, "", time.Second)
  2044. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2045. redis.Set(keySeven, "", time.Second)
  2046. defer redis.Close()
  2047. }
  2048. //定义切片
  2049. var adviceList []models.HisDoctorAdviceInfo
  2050. var projectList []models.HisPrescriptionProject
  2051. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2052. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2053. var tempPrescription *models.HisPrescription
  2054. if len(prescriptions) > 0 {
  2055. for _, item := range prescriptions {
  2056. items := item.(map[string]interface{})
  2057. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2058. utils.ErrorLog("id")
  2059. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2060. return
  2061. }
  2062. id := int64(items["id"].(float64))
  2063. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2064. tempPrescription = &new_prescription
  2065. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2066. utils.ErrorLog("type")
  2067. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2068. return
  2069. }
  2070. types := int64(items["type"].(float64))
  2071. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2072. utils.ErrorLog("med_type")
  2073. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2074. return
  2075. }
  2076. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2077. if med_type == "0" {
  2078. med_type = "14"
  2079. }
  2080. //if order_status == 0 {
  2081. // order_status = 1
  2082. //}
  2083. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2084. utils.ErrorLog("pre_time")
  2085. }
  2086. preTime, _ := items["pre_time"].(string)
  2087. timeLayout := "2006-01-02"
  2088. loc, _ := time.LoadLocation("Local")
  2089. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2090. if err != nil {
  2091. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2092. return
  2093. }
  2094. pTime := theTime2.Unix()
  2095. ctime := time.Now().Unix()
  2096. if tempPrescription.ID == 0 {
  2097. prescription := &models.HisPrescription{
  2098. ID: 0,
  2099. PatientId: patient_id,
  2100. UserOrgId: adminInfo.CurrentOrgId,
  2101. RecordDate: recordDateTime,
  2102. Ctime: ctime,
  2103. Mtime: ctime,
  2104. Type: types,
  2105. Modifier: adminInfo.AdminUser.Id,
  2106. Creator: adminInfo.AdminUser.Id,
  2107. Status: 1,
  2108. Doctor: role.UserName,
  2109. HisPatientId: his_patient_id,
  2110. OrderStatus: 1,
  2111. BatchNumber: "",
  2112. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2113. PreTime: pTime,
  2114. PType: p_type,
  2115. MedType: med_type,
  2116. }
  2117. tempPrescription = prescription
  2118. service.SaveHisPrescription(tempPrescription)
  2119. redis := service.RedisClient()
  2120. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2121. redis.Set(key, "", time.Second)
  2122. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2123. redis.Set(keyOne, "", time.Second)
  2124. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2125. redis.Set(keySeven, "", time.Second)
  2126. defer redis.Close()
  2127. } else {
  2128. tempPrescription.ID = id
  2129. tempPrescription.Type = types
  2130. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2131. tempPrescription.Mtime = time.Now().Unix()
  2132. tempPrescription.Doctor = role.UserName
  2133. //tempPrescription.OrderStatus = order_status
  2134. tempPrescription.PreTime = pTime
  2135. tempPrescription.MedType = med_type
  2136. service.SaveHisPrescription(tempPrescription)
  2137. redis := service.RedisClient()
  2138. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2139. redis.Set(key, "", time.Second)
  2140. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2141. redis.Set(keyOne, "", time.Second)
  2142. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2143. redis.Set(keySeven, "", time.Second)
  2144. defer redis.Close()
  2145. }
  2146. //service.SaveHisPrescription(prescription)
  2147. //更改患者挂号状态
  2148. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2149. fmt.Println("更改失败", err2)
  2150. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2151. advices := items["advices"].([]interface{})
  2152. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2153. groupNo := int64(0)
  2154. ctime := time.Now().Unix()
  2155. mtime := ctime
  2156. if len(advices) > 0 {
  2157. for _, advice := range advices {
  2158. var s models.HisDoctorAdviceInfo
  2159. s.PrescriptionId = tempPrescription.ID
  2160. s.AdviceType = 2
  2161. s.AdviceDoctor = doctor_id
  2162. s.StopState = 2
  2163. s.ExecutionState = 2
  2164. s.AdviceDate = recordDateTime
  2165. s.Status = 1
  2166. s.UserOrgId = adminInfo.CurrentOrgId
  2167. s.RecordDate = recordDateTime
  2168. s.StartTime = tempPrescription.PreTime
  2169. s.Groupno = groupNo
  2170. s.CreatedTime = ctime
  2171. s.UpdatedTime = mtime
  2172. s.PatientId = patient_id
  2173. s.HisPatientId = his_patient_id
  2174. s.StartTime = pTime
  2175. s.IsSettle = 2
  2176. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2177. if errcode > 0 {
  2178. c.ServeFailJSONWithSGJErrorCode(errcode)
  2179. return
  2180. }
  2181. s.StartTime = pTime
  2182. var total_count int64 //处方总库存
  2183. //查询改药品信息
  2184. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2185. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2186. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2187. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2188. total_count += prescribingNumberSeven * medical.MinNumber
  2189. }
  2190. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2191. total_count += prescribingNumberSeven
  2192. }
  2193. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2194. total_count += prescribingNumberSeven
  2195. }
  2196. service.CreateHisDoctorAdvice(&s)
  2197. //存储切片中
  2198. adviceList = append(adviceList, s)
  2199. redis := service.RedisClient()
  2200. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2201. redis.Set(key, "", time.Second)
  2202. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2203. redis.Set(keyOne, "", time.Second)
  2204. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2205. redis.Set(keySeven, "", time.Second)
  2206. var randNum int
  2207. randNum = rand.Intn(10000) + 1000
  2208. timestamp := time.Now().Unix()
  2209. tempTime := time.Unix(timestamp, 0)
  2210. timeFormat := tempTime.Format("20060102150405")
  2211. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  2212. service.CreateHisDoctorAdvice(&s)
  2213. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2214. redis.Set(keySix, "", time.Second)
  2215. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2216. redis.Set(keyFive, "", time.Second)
  2217. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2218. redis.Set(keyEight, "", time.Second)
  2219. defer redis.Close()
  2220. }
  2221. }
  2222. }
  2223. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2224. projects := items["project"].([]interface{})
  2225. if len(projects) > 0 {
  2226. for _, project := range projects {
  2227. var p models.HisPrescriptionProject
  2228. p.PrescriptionId = tempPrescription.ID
  2229. p.Ctime = time.Now().Unix()
  2230. p.Mtime = time.Now().Unix()
  2231. p.PatientId = patient_id
  2232. p.RecordDate = recordDateTime
  2233. p.Doctor = doctor_id
  2234. p.UserOrgId = adminInfo.CurrentOrgId
  2235. p.HisPatientId = his_patient_id
  2236. p.Status = 1
  2237. p.StartTime = pTime
  2238. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  2239. if errcode > 0 {
  2240. c.ServeFailJSONWithSGJErrorCode(errcode)
  2241. return
  2242. }
  2243. if p.ID == 0 {
  2244. p.IsOut = 2
  2245. }
  2246. if p.ID > 0 {
  2247. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  2248. p.IsOut = projectDetail.IsOut
  2249. }
  2250. service.CreateHisProjectTwo(&p)
  2251. projectList = append(projectList, p)
  2252. var randNum int
  2253. randNum = rand.Intn(10000) + 1000
  2254. timestamp := time.Now().Unix()
  2255. tempTime := time.Unix(timestamp, 0)
  2256. timeFormat := tempTime.Format("20060102150405")
  2257. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  2258. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  2259. //新增或者编辑项目,修改对应的标签数据
  2260. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  2261. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  2262. var label models.HisLabelPrintInfo
  2263. project, _ := service.GetProjectDetail(p.ProjectId)
  2264. if project.CostClassify == 3 { //类别为检验检查
  2265. if p.TeamId > 0 { //检验检查组套
  2266. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  2267. if tempLabel.ID == 0 {
  2268. team, _ := service.GetProjectTeamDetail(p.TeamId)
  2269. label.Number = tempPrescription.PrescriptionNumber
  2270. label.ProjectId = project.ID
  2271. label.Status = 1
  2272. label.IsPrint = 2
  2273. label.DoctorId = info.DoctorId
  2274. label.UserOrgId = p.UserOrgId
  2275. label.PatientId = patient_id
  2276. label.RecordDate = recordDateTime
  2277. label.Ctime = time.Now().Unix()
  2278. label.Mtime = time.Now().Unix()
  2279. label.ItemId = p.TeamId
  2280. label.FeedetlSn = p.FeedetlSn
  2281. label.PProjectId = p.ID
  2282. label.ProjectName = team.ProjectTeam
  2283. label.PatientName = patient.Name
  2284. service.CreateHisLabelRecord(&label)
  2285. }
  2286. } else { //单条检验检查项目
  2287. label.Number = tempPrescription.PrescriptionNumber
  2288. label.ProjectId = project.ID
  2289. label.Status = 1
  2290. label.DoctorId = info.DoctorId
  2291. label.UserOrgId = p.UserOrgId
  2292. label.PatientId = patient_id
  2293. label.RecordDate = recordDateTime
  2294. label.IsPrint = 2
  2295. label.Ctime = time.Now().Unix()
  2296. label.Mtime = time.Now().Unix()
  2297. label.FeedetlSn = p.FeedetlSn
  2298. label.PProjectId = p.ID
  2299. label.ItemId = p.TeamId
  2300. label.ProjectName = project.ProjectName
  2301. label.PatientName = patient.Name
  2302. service.CreateHisLabelRecord(&label)
  2303. }
  2304. }
  2305. }
  2306. }
  2307. service.SaveHisProjectTwo(&p)
  2308. }
  2309. }
  2310. }
  2311. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2312. // addition := items["addition"].([]interface{})
  2313. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2314. // ctime := time.Now().Unix()
  2315. // mtime := ctime
  2316. // if len(addition) > 0 {
  2317. // for _, item := range addition {
  2318. // var s models.HisAdditionalCharge
  2319. // s.PrescriptionId = tempPrescription.ID
  2320. // s.Status = 1
  2321. // s.UserOrgId = adminInfo.CurrentOrgId
  2322. // s.RecordDate = recordDateTime
  2323. // s.CreatedTime = ctime
  2324. // s.UpdatedTime = mtime
  2325. // s.PatientId = patient_id
  2326. // s.HisPatientId = his_patient_id
  2327. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  2328. // if errcode > 0 {
  2329. // c.ServeFailJSONWithSGJErrorCode(errcode)
  2330. // return
  2331. // }
  2332. // service.CreateAdditionalCharge(&s)
  2333. // var randNum int
  2334. // randNum = rand.Intn(10000) + 1000
  2335. // timestamp := time.Now().Unix()
  2336. // tempTime := time.Unix(timestamp, 0)
  2337. // timeFormat := tempTime.Format("20060102150405")
  2338. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  2339. // service.CreateAdditionalCharge(&s)
  2340. //
  2341. // }
  2342. // }
  2343. //}
  2344. }
  2345. }
  2346. //查询今日该患者开的药品处方
  2347. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2348. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2349. //药品出库
  2350. if drugOutConfig.IsOpen == 1 {
  2351. for _, item := range hisdoctorlist {
  2352. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  2353. // 查询该药品最后一次出库记录
  2354. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  2355. if len(druginfo) > 0 {
  2356. //回退库存
  2357. for _, it := range druginfo {
  2358. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2359. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2360. }
  2361. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2362. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2363. }
  2364. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2365. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2366. }
  2367. }
  2368. }
  2369. //删除记录
  2370. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  2371. //查询最后一次数据
  2372. if drugOutConfig.IsOpen == 1 {
  2373. //出库
  2374. if drug.IsUse == 2 {
  2375. creater := adminInfo.AdminUser.Id
  2376. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  2377. }
  2378. //更新字典里面的库存
  2379. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2380. var sum_count int64
  2381. for _, its := range stockInfo {
  2382. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  2383. if its.MaxUnit == baseDrug.MaxUnit {
  2384. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  2385. }
  2386. sum_count += its.StockMaxNumber + its.StockMinNumber
  2387. }
  2388. //更新基础库存
  2389. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2390. //剩余库存
  2391. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  2392. }
  2393. }
  2394. }
  2395. //耗材保存处方出库
  2396. if goodOutConfig.IsOpen == 1 {
  2397. //查询今日耗材出库数量
  2398. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2399. for _, item := range hisgoodlist {
  2400. //查询历史出库数据
  2401. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2402. var out_count_five int64
  2403. for _, item := range flowGood {
  2404. out_count_five += item.Count
  2405. }
  2406. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  2407. if out_count_five != parseIntCount {
  2408. //查询耗材最后一次出库记录
  2409. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  2410. //查询默认出库仓库库存
  2411. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2412. if len(wareOut) > 0 {
  2413. for _, it := range wareOut {
  2414. //回退库存
  2415. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  2416. //删除出库记录
  2417. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  2418. }
  2419. }
  2420. timeStr := time.Now().Format("2006-01-02")
  2421. timeArr := strings.Split(timeStr, "-")
  2422. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  2423. total = total + 1
  2424. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2425. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2426. number = number + total
  2427. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2428. operation_time := time.Now().Unix()
  2429. creater := c.GetAdminUserInfo().AdminUser.Id
  2430. recordDateStr := time.Now().Format("2006-01-02")
  2431. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2432. nowtime := recordDate.Unix()
  2433. warehouseOut := models.WarehouseOut{
  2434. WarehouseOutOrderNumber: warehousing_out_order,
  2435. OperationTime: operation_time,
  2436. OrgId: adminInfo.CurrentOrgId,
  2437. Creater: creater,
  2438. Ctime: time.Now().Unix(),
  2439. Status: 1,
  2440. WarehouseOutTime: nowtime,
  2441. Type: 1,
  2442. StorehouseId: storeConfig.StorehouseOutInfo,
  2443. IsCheck: 1,
  2444. IsSys: 1,
  2445. }
  2446. //查询是否生成出库单
  2447. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2448. if out.ID == 0 {
  2449. service.AddSigleWarehouseOut(&warehouseOut)
  2450. }
  2451. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2452. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2453. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  2454. dialyPrepareOne := models.DialysisBeforePrepare{
  2455. GoodTypeId: goodObj.GoodTypeId,
  2456. GoodId: item.ProjectId,
  2457. PatientId: item.PatientId,
  2458. RecordDate: item.RecordDate,
  2459. UserOrgId: adminInfo.CurrentOrgId,
  2460. Count: parseIntCount,
  2461. Ctime: time.Now().Unix(),
  2462. Creater: creater,
  2463. Status: 1,
  2464. StorehouseId: houseConfig.StorehouseOutInfo,
  2465. ProjectId: item.ID,
  2466. }
  2467. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2468. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  2469. //查询历史出库数据
  2470. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2471. var out_count int64
  2472. for _, item := range flowGood {
  2473. out_count += item.Count
  2474. }
  2475. //如果历史数和当前数据不想等才进行退库出库
  2476. if out_count != parseIntCount {
  2477. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  2478. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2479. detail := models.AutomaticReduceDetail{
  2480. WarehouseOutId: 0,
  2481. WarehouseOutOrderNumber: "",
  2482. PatientId: item.PatientId,
  2483. Ctime: time.Now().Unix(),
  2484. Mtime: 0,
  2485. Status: 1,
  2486. RecordTime: item.RecordDate,
  2487. OrgId: item.UserOrgId,
  2488. GoodId: item.ProjectId,
  2489. GoodTypeId: 0,
  2490. Count: parseIntCount,
  2491. Type: 0,
  2492. ProjectId: item.ID,
  2493. StorehouseId: 0,
  2494. }
  2495. service.CreateAutoDetail(detail)
  2496. //查询剩余库存
  2497. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  2498. var sum_count int64
  2499. for _, item := range goodList {
  2500. sum_count += item.StockCount
  2501. }
  2502. //更新剩余库存
  2503. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  2504. //耗材
  2505. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  2506. }
  2507. }
  2508. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  2509. //查询历史出库数据
  2510. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2511. var out_count int64
  2512. for _, item := range flowGood {
  2513. out_count += item.Count
  2514. }
  2515. //如果历史数和当前数据不想等才进行退库出库
  2516. if out_count != parseIntCount {
  2517. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  2518. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2519. detail := models.AutomaticReduceDetail{
  2520. WarehouseOutId: 0,
  2521. WarehouseOutOrderNumber: "",
  2522. PatientId: item.PatientId,
  2523. Ctime: time.Now().Unix(),
  2524. Mtime: 0,
  2525. Status: 1,
  2526. RecordTime: item.RecordDate,
  2527. OrgId: item.UserOrgId,
  2528. GoodId: item.ProjectId,
  2529. GoodTypeId: 0,
  2530. Count: parseIntCount,
  2531. Type: 0,
  2532. ProjectId: item.ID,
  2533. StorehouseId: 0,
  2534. }
  2535. service.CreateAutoDetail(detail)
  2536. //查询剩余库存
  2537. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  2538. var sum_count int64
  2539. for _, item := range goodList {
  2540. sum_count += item.StockCount
  2541. }
  2542. //更新剩余库存
  2543. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  2544. //耗材
  2545. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  2546. }
  2547. }
  2548. }
  2549. }
  2550. }
  2551. }
  2552. //redisClient := service.RedisClient()
  2553. //defer redisClient.Close()
  2554. //
  2555. //list := models.HisList{
  2556. // Patient_id: patient_id,
  2557. // Advice_id:0,
  2558. // Record_date: 0,
  2559. // Advice: adviceList,
  2560. // Project: nil,
  2561. //}
  2562. //hisLis = append(hisLis, list)
  2563. //
  2564. //advice_json, _ := json.Marshal(&hisLis)
  2565. //redisClient.RPush("111", advice_json).Result()
  2566. //result, _ := redisClient.RPop("111").Result()
  2567. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  2568. //
  2569. //var dat []map[string]interface{}
  2570. //json.Unmarshal([]byte(result), &dat)
  2571. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  2572. //
  2573. //for k,v:=range dat{
  2574. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  2575. //}
  2576. //project_json, _ := json.Marshal(&projectList)
  2577. //redisClient.LPush("222", project_json).Result()
  2578. if err == nil {
  2579. c.ServeSuccessJSON(map[string]interface{}{
  2580. "msg": "保存成功",
  2581. })
  2582. return
  2583. } else {
  2584. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2585. return
  2586. }
  2587. }
  2588. func (c *HisApiController) EditHisPrescription() {
  2589. record_date := c.GetString("record_date")
  2590. patient_id, _ := c.GetInt64("patient_id")
  2591. reg_type, _ := c.GetInt64("reg_type")
  2592. //diagnose, _ := c.GetInt64("diagnose", 0)
  2593. diagnose := c.GetString("diagnose")
  2594. sick_type, _ := c.GetInt64("sick_type")
  2595. sick_history := c.GetString("sick_history")
  2596. doctor_id, _ := c.GetInt64("doctor", 0)
  2597. department, _ := c.GetInt64("department", 0)
  2598. his_patient_id, _ := c.GetInt64("his_patient_id")
  2599. p_type, _ := c.GetInt64("p_type")
  2600. dataBody := make(map[string]interface{}, 0)
  2601. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2602. if err != nil {
  2603. utils.ErrorLog(err.Error())
  2604. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2605. return
  2606. }
  2607. timeLayout := "2006-01-02"
  2608. loc, _ := time.LoadLocation("Local")
  2609. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2610. if err != nil {
  2611. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2612. return
  2613. }
  2614. adminInfo := c.GetAdminUserInfo()
  2615. recordDateTime := theTime.Unix()
  2616. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  2617. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2618. var hpInfo models.HisPrescriptionInfo
  2619. if info.ID == 0 {
  2620. var randNum int
  2621. randNum = rand.Intn(10000) + 1000
  2622. timestamp := time.Now().Unix()
  2623. tempTime := time.Unix(timestamp, 0)
  2624. timeFormat := tempTime.Format("20060102150405")
  2625. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2626. hpInfo = models.HisPrescriptionInfo{
  2627. UserOrgId: adminInfo.CurrentOrgId,
  2628. RecordDate: theTime.Unix(),
  2629. PatientId: patient_id,
  2630. Status: 1,
  2631. Ctime: time.Now().Unix(),
  2632. Mtime: time.Now().Unix(),
  2633. Creator: adminInfo.AdminUser.Id,
  2634. Modifier: adminInfo.AdminUser.Id,
  2635. Diagnosis: diagnose,
  2636. SickHistory: sick_history,
  2637. Departments: department,
  2638. RegisterType: reg_type,
  2639. PrescriptionNumber: p_number,
  2640. PrescriptionStatus: 1,
  2641. Doctor: role.UserName,
  2642. DoctorId: doctor_id,
  2643. SickType: sick_type,
  2644. PType: p_type,
  2645. }
  2646. service.SavePatientPrescriptionInfo(hpInfo)
  2647. } else {
  2648. hpInfo = models.HisPrescriptionInfo{
  2649. ID: info.ID,
  2650. UserOrgId: adminInfo.CurrentOrgId,
  2651. RecordDate: info.RecordDate,
  2652. PatientId: info.PatientId,
  2653. Status: 1,
  2654. Ctime: info.Ctime,
  2655. Mtime: time.Now().Unix(),
  2656. Creator: info.Creator,
  2657. Modifier: adminInfo.AdminUser.Id,
  2658. Diagnosis: diagnose,
  2659. SickHistory: sick_history,
  2660. Departments: department,
  2661. RegisterType: reg_type,
  2662. PrescriptionNumber: info.PrescriptionNumber,
  2663. Doctor: role.UserName,
  2664. PrescriptionStatus: info.PrescriptionStatus,
  2665. DoctorId: doctor_id,
  2666. SickType: sick_type,
  2667. PType: info.PType,
  2668. }
  2669. service.SavePatientPrescriptionInfo(hpInfo)
  2670. }
  2671. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2672. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2673. if len(prescriptions) > 0 {
  2674. for _, item := range prescriptions {
  2675. items := item.(map[string]interface{})
  2676. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2677. utils.ErrorLog("id")
  2678. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2679. return
  2680. }
  2681. id := int64(items["id"].(float64))
  2682. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2683. utils.ErrorLog("type")
  2684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2685. return
  2686. }
  2687. types := int64(items["type"].(float64))
  2688. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2689. utils.ErrorLog("med_type")
  2690. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2691. return
  2692. }
  2693. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2694. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  2695. ctime := time.Now().Unix()
  2696. prescription := &models.HisPrescription{
  2697. ID: id,
  2698. PatientId: patient_id,
  2699. UserOrgId: adminInfo.CurrentOrgId,
  2700. RecordDate: recordDateTime,
  2701. Ctime: ctime,
  2702. Mtime: ctime,
  2703. Type: types,
  2704. Modifier: adminInfo.AdminUser.Id,
  2705. Creator: adminInfo.AdminUser.Id,
  2706. Status: 1,
  2707. Doctor: role.UserName,
  2708. HisPatientId: his_patient_id,
  2709. OrderStatus: 1,
  2710. BatchNumber: "",
  2711. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2712. PType: hpInfo.PType,
  2713. MedType: med_type,
  2714. }
  2715. if historyPrescription.ID > 0 {
  2716. prescription.PreTime = historyPrescription.PreTime
  2717. }
  2718. service.SaveHisPrescription(prescription)
  2719. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2720. advices := items["advices"].([]interface{})
  2721. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2722. groupNo := int64(0)
  2723. ctime := time.Now().Unix()
  2724. mtime := ctime
  2725. if len(advices) > 0 {
  2726. for _, advice := range advices {
  2727. var s models.HisDoctorAdviceInfo
  2728. s.PrescriptionId = prescription.ID
  2729. s.AdviceType = 2
  2730. s.AdviceDoctor = adminInfo.AdminUser.Id
  2731. s.StopState = 2
  2732. s.ExecutionState = 2
  2733. s.AdviceDate = recordDateTime
  2734. s.Status = 1
  2735. s.UserOrgId = adminInfo.CurrentOrgId
  2736. s.RecordDate = recordDateTime
  2737. s.StartTime = prescription.PreTime
  2738. s.Groupno = groupNo
  2739. s.CreatedTime = ctime
  2740. s.UpdatedTime = mtime
  2741. s.PatientId = patient_id
  2742. s.HisPatientId = his_patient_id
  2743. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  2744. if errcode > 0 {
  2745. c.ServeFailJSONWithSGJErrorCode(errcode)
  2746. return
  2747. }
  2748. service.CreateHisDoctorAdvice(&s)
  2749. redis := service.RedisClient()
  2750. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2751. redis.Set(key, "", time.Second)
  2752. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2753. fmt.Println("keyOne", keyOne)
  2754. redis.Set(keyOne, "", time.Second)
  2755. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2756. redis.Set(keySeven, "", time.Second)
  2757. redis.Close()
  2758. }
  2759. }
  2760. }
  2761. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2762. projects := items["project"].([]interface{})
  2763. if len(projects) > 0 {
  2764. for _, project := range projects {
  2765. var p models.HisPrescriptionProject
  2766. p.PrescriptionId = prescription.ID
  2767. p.Ctime = time.Now().Unix()
  2768. p.Mtime = time.Now().Unix()
  2769. p.PatientId = patient_id
  2770. p.RecordDate = recordDateTime
  2771. p.UserOrgId = adminInfo.CurrentOrgId
  2772. p.HisPatientId = his_patient_id
  2773. p.Status = 1
  2774. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  2775. if errcode > 0 {
  2776. c.ServeFailJSONWithSGJErrorCode(errcode)
  2777. return
  2778. }
  2779. service.CreateHisProjectTwo(&p)
  2780. }
  2781. }
  2782. }
  2783. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2784. addition := items["addition"].([]interface{})
  2785. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2786. ctime := time.Now().Unix()
  2787. mtime := ctime
  2788. if len(addition) > 0 {
  2789. for _, item := range addition {
  2790. var s models.HisAdditionalCharge
  2791. s.PrescriptionId = prescription.ID
  2792. s.Status = 1
  2793. s.UserOrgId = adminInfo.CurrentOrgId
  2794. s.RecordDate = recordDateTime
  2795. s.CreatedTime = ctime
  2796. s.UpdatedTime = mtime
  2797. s.PatientId = patient_id
  2798. s.HisPatientId = his_patient_id
  2799. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  2800. if errcode > 0 {
  2801. c.ServeFailJSONWithSGJErrorCode(errcode)
  2802. return
  2803. }
  2804. service.CreateAdditionalCharge(&s)
  2805. }
  2806. }
  2807. }
  2808. }
  2809. }
  2810. }
  2811. if err == nil {
  2812. c.ServeSuccessJSON(map[string]interface{}{
  2813. "msg": "保存成功",
  2814. })
  2815. return
  2816. } else {
  2817. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2818. return
  2819. }
  2820. }
  2821. func (c *HisApiController) DeletePrescription() {
  2822. prescription_id, _ := c.GetInt64("id")
  2823. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  2824. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  2825. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2826. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2827. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  2828. //耗材保存处方出库
  2829. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  2830. //已收费和已发药限制逻辑
  2831. isCharge := false
  2832. isMedicine := false
  2833. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  2834. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  2835. for _, item := range new_prescriptions {
  2836. if item.IsMedicine == 1 {
  2837. isMedicine = true
  2838. }
  2839. }
  2840. for _, item := range new_prescriptions {
  2841. if item.OrderStatus == 4 {
  2842. isCharge = true
  2843. }
  2844. }
  2845. if p_err != nil {
  2846. if new_prescription.ID > 0 {
  2847. if new_prescription.OrderStatus == 2 {
  2848. isCharge = true
  2849. }
  2850. }
  2851. }
  2852. for _, item := range advices {
  2853. if item.IsMedicine == 1 {
  2854. isMedicine = true
  2855. }
  2856. }
  2857. if isCharge {
  2858. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  2859. return
  2860. }
  2861. if isMedicine {
  2862. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  2863. return
  2864. }
  2865. //已收费和已发药限制逻辑
  2866. if len(projects) > 0 {
  2867. for _, item := range projects {
  2868. service.DeletePrintInfo(item.ID) //删除打印信息
  2869. if goodOutConfig.IsOpen != 1 {
  2870. if stockConfig.IsOpen == 1 {
  2871. if item.Type == 3 && item.IsOut == 1 {
  2872. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  2873. f_count, _ := strconv.ParseFloat(item.Count, 64)
  2874. good.Total = good.Total + f_count
  2875. service.UpdateGoodInfo(&good)
  2876. operation_time := time.Now().Unix()
  2877. creater := c.GetAdminUserInfo().AdminUser.Id
  2878. //创建退库单
  2879. timeStr := time.Now().Format("2006-01-02")
  2880. timeArr := strings.Split(timeStr, "-")
  2881. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  2882. total = total + 1
  2883. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2884. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  2885. cancelStock := models.CancelStock{
  2886. OrderNumber: orderNumber,
  2887. OperaTime: operation_time,
  2888. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2889. Creater: creater,
  2890. Ctime: time.Now().Unix(),
  2891. Status: 1,
  2892. ReturnTime: item.RecordDate,
  2893. Type: 1,
  2894. StorehouseId: houseConfig.StorehouseOutInfo,
  2895. IsCheck: 1,
  2896. }
  2897. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  2898. if msgerrkonde == gorm.ErrRecordNotFound {
  2899. service.AddSigleCancelStock(&cancelStock)
  2900. }
  2901. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  2902. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  2903. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2904. //查询该耗材是否出库
  2905. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  2906. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  2907. deaerler, _ := service.GetDealerById(info.Dealer)
  2908. var total_count int64
  2909. count, _ := strconv.ParseInt(item.Count, 10, 64)
  2910. total_count += count
  2911. if info.ID > 0 {
  2912. if info.Count >= total_count {
  2913. //回退库存
  2914. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  2915. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  2916. var flush_count int64
  2917. for _, it := range goodList {
  2918. flush_count += it.StockCount
  2919. }
  2920. cancelStockInfo := models.CancelStockInfo{
  2921. GoodId: item.ProjectId,
  2922. CancelStockId: cancel.ID,
  2923. GoodTypeId: good.GoodTypeId,
  2924. Count: prescribingNumber,
  2925. Price: info.Price,
  2926. Total: 0,
  2927. ProductDate: info.ProductDate,
  2928. ExpiryDate: info.ExpiryDate,
  2929. Ctime: time.Now().Unix(),
  2930. Status: 1,
  2931. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2932. OrderNumber: cancel.OrderNumber,
  2933. Type: 0,
  2934. Dealer: deaerler.DealerName,
  2935. Manufacturer: manufacturer.ManufacturerName,
  2936. Number: info.Number,
  2937. RegisterAccount: "",
  2938. Remark: "",
  2939. WarehouseInfoId: info.WarehouseInfotId,
  2940. PatientId: info.PatientId,
  2941. RecordDate: info.SysRecordTime,
  2942. StorehouseId: houseConfig.StorehouseOutInfo,
  2943. IsCheck: 1,
  2944. }
  2945. service.CreateCancelStockInfoOne(&cancelStockInfo)
  2946. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  2947. flow := models.VmStockFlow{
  2948. WarehousingId: info.WarehouseInfotId,
  2949. GoodId: item.ProjectId,
  2950. Number: info.Number,
  2951. LicenseNumber: info.LicenseNumber,
  2952. Count: prescribingNumber,
  2953. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2954. PatientId: item.PatientId,
  2955. SystemTime: info.SysRecordTime,
  2956. ConsumableType: 7,
  2957. IsSys: 0,
  2958. WarehousingOrder: "",
  2959. WarehouseOutId: info.WarehouseOutId,
  2960. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2961. IsEdit: 0,
  2962. CancelStockId: cancel.ID,
  2963. CancelOrderNumber: cancel.OrderNumber,
  2964. Manufacturer: manufacturer.ID,
  2965. Dealer: 0,
  2966. Creator: c.GetAdminUserInfo().CurrentOrgId,
  2967. UpdateCreator: 0,
  2968. Status: 1,
  2969. Ctime: time.Now().Unix(),
  2970. Mtime: 0,
  2971. Price: info.Price,
  2972. WarehousingDetailId: info.WarehouseInfotId,
  2973. WarehouseOutDetailId: info.ID,
  2974. CancelOutDetailId: cancelInfo.ID,
  2975. ProductDate: info.ProductDate,
  2976. ExpireDate: info.ExpiryDate,
  2977. StorehouseId: houseConfig.StorehouseOutInfo,
  2978. OverCount: flush_count,
  2979. }
  2980. service.CreateStockFlowOne(flow)
  2981. //退库数量增加
  2982. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  2983. //出库数量减少
  2984. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  2985. }
  2986. if info.Count < total_count {
  2987. //回退库存
  2988. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  2989. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  2990. var flush_count int64
  2991. for _, it := range goodList {
  2992. flush_count += it.StockCount
  2993. }
  2994. cancelStockInfo := models.CancelStockInfo{
  2995. GoodId: item.ProjectId,
  2996. CancelStockId: cancel.ID,
  2997. GoodTypeId: good.GoodTypeId,
  2998. Count: info.Count,
  2999. Price: info.Price,
  3000. Total: 0,
  3001. ProductDate: info.ProductDate,
  3002. ExpiryDate: info.ExpiryDate,
  3003. Ctime: time.Now().Unix(),
  3004. Status: 1,
  3005. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3006. OrderNumber: cancel.OrderNumber,
  3007. Type: 0,
  3008. Dealer: deaerler.DealerName,
  3009. Manufacturer: manufacturer.ManufacturerName,
  3010. Number: info.Number,
  3011. RegisterAccount: "",
  3012. Remark: "",
  3013. WarehouseInfoId: info.WarehouseInfotId,
  3014. PatientId: info.PatientId,
  3015. RecordDate: info.SysRecordTime,
  3016. StorehouseId: houseConfig.StorehouseOutInfo,
  3017. IsCheck: 1,
  3018. }
  3019. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3020. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3021. flow := models.VmStockFlow{
  3022. WarehousingId: info.WarehouseInfotId,
  3023. GoodId: item.ProjectId,
  3024. Number: info.Number,
  3025. LicenseNumber: info.LicenseNumber,
  3026. Count: info.Count,
  3027. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3028. PatientId: item.PatientId,
  3029. SystemTime: info.SysRecordTime,
  3030. ConsumableType: 7,
  3031. IsSys: 0,
  3032. WarehousingOrder: "",
  3033. WarehouseOutId: info.WarehouseOutId,
  3034. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3035. IsEdit: 0,
  3036. CancelStockId: cancel.ID,
  3037. CancelOrderNumber: cancel.OrderNumber,
  3038. Manufacturer: manufacturer.ID,
  3039. Dealer: 0,
  3040. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3041. UpdateCreator: 0,
  3042. Status: 1,
  3043. Ctime: time.Now().Unix(),
  3044. Mtime: 0,
  3045. Price: info.Price,
  3046. WarehousingDetailId: info.WarehouseInfotId,
  3047. WarehouseOutDetailId: info.ID,
  3048. CancelOutDetailId: cancelInfo.ID,
  3049. ProductDate: info.ProductDate,
  3050. ExpireDate: info.ExpiryDate,
  3051. StorehouseId: houseConfig.StorehouseOutInfo,
  3052. OverCount: flush_count,
  3053. }
  3054. service.CreateStockFlowOne(flow)
  3055. //退库数量增加
  3056. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3057. //出库数量减少
  3058. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  3059. }
  3060. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3061. var flush_count int64
  3062. for _, it := range goodList {
  3063. flush_count += it.StockCount
  3064. }
  3065. //查询已出库数量
  3066. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3067. if prescribingNumber < dialysisInfo.Count {
  3068. //改变数量
  3069. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3070. }
  3071. if prescribingNumber >= dialysisInfo.Count {
  3072. //删除出库表
  3073. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3074. }
  3075. //更新库存
  3076. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  3077. //更新基础库库存
  3078. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  3079. }
  3080. }
  3081. }
  3082. }
  3083. //保存耗材出库
  3084. if goodOutConfig.IsOpen == 1 {
  3085. if item.Type == 3 {
  3086. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3087. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3088. good.Total = good.Total + f_count
  3089. service.UpdateGoodInfo(&good)
  3090. operation_time := time.Now().Unix()
  3091. creater := c.GetAdminUserInfo().AdminUser.Id
  3092. //创建退库单
  3093. timeStr := time.Now().Format("2006-01-02")
  3094. timeArr := strings.Split(timeStr, "-")
  3095. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3096. total = total + 1
  3097. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3098. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3099. cancelStock := models.CancelStock{
  3100. OrderNumber: orderNumber,
  3101. OperaTime: operation_time,
  3102. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3103. Creater: creater,
  3104. Ctime: time.Now().Unix(),
  3105. Status: 1,
  3106. ReturnTime: item.RecordDate,
  3107. Type: 1,
  3108. StorehouseId: houseConfig.StorehouseOutInfo,
  3109. IsCheck: 1,
  3110. }
  3111. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3112. if msgerrkonde == gorm.ErrRecordNotFound {
  3113. service.AddSigleCancelStock(&cancelStock)
  3114. }
  3115. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3116. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3117. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3118. //查询该耗材是否出库
  3119. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3120. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3121. deaerler, _ := service.GetDealerById(info.Dealer)
  3122. var total_count int64
  3123. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3124. total_count += count
  3125. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3126. var flush_count int64
  3127. for _, it := range goodList {
  3128. flush_count += it.StockCount
  3129. }
  3130. fmt.Println("历史出库数据", info.Count)
  3131. fmt.Println("出库数量", total_count)
  3132. if info.ID > 0 {
  3133. cancelStockInfo := models.CancelStockInfo{
  3134. GoodId: item.ProjectId,
  3135. CancelStockId: cancel.ID,
  3136. GoodTypeId: good.GoodTypeId,
  3137. Count: prescribingNumber,
  3138. Price: info.Price,
  3139. Total: 0,
  3140. ProductDate: info.ProductDate,
  3141. ExpiryDate: info.ExpiryDate,
  3142. Ctime: time.Now().Unix(),
  3143. Status: 1,
  3144. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3145. OrderNumber: cancel.OrderNumber,
  3146. Type: 0,
  3147. Dealer: deaerler.DealerName,
  3148. Manufacturer: manufacturer.ManufacturerName,
  3149. Number: info.Number,
  3150. RegisterAccount: "",
  3151. Remark: "",
  3152. WarehouseInfoId: info.WarehouseInfotId,
  3153. PatientId: info.PatientId,
  3154. RecordDate: info.SysRecordTime,
  3155. StorehouseId: houseConfig.StorehouseOutInfo,
  3156. IsCheck: 1,
  3157. }
  3158. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3159. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3160. //查询出库数量
  3161. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  3162. //出库数据 大于 退库数量
  3163. if len(list) > 0 {
  3164. for _, it := range list {
  3165. //回退库存
  3166. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  3167. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3168. var flush_count_one int64
  3169. for _, it := range goodList {
  3170. flush_count_one += it.StockCount
  3171. }
  3172. //查询该批次是否有退库数据
  3173. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  3174. creater := c.GetAdminUserInfo().AdminUser.Id
  3175. flow := models.VmStockFlow{
  3176. WarehousingId: it.WarehouseInfotId,
  3177. GoodId: it.GoodId,
  3178. Number: it.Number,
  3179. LicenseNumber: it.LicenseNumber,
  3180. Count: it.Count,
  3181. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3182. PatientId: it.PatientId,
  3183. SystemTime: it.SysRecordTime,
  3184. ConsumableType: 7,
  3185. IsSys: 0,
  3186. WarehousingOrder: "",
  3187. WarehouseOutId: it.WarehouseOutId,
  3188. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  3189. IsEdit: 0,
  3190. CancelStockId: cancel.ID,
  3191. CancelOrderNumber: cancel.OrderNumber,
  3192. Manufacturer: manufacturer.ID,
  3193. Dealer: 0,
  3194. Creator: creater,
  3195. UpdateCreator: 0,
  3196. Status: 1,
  3197. Ctime: time.Now().Unix(),
  3198. Mtime: 0,
  3199. Price: it.Price,
  3200. WarehousingDetailId: it.WarehouseInfotId,
  3201. WarehouseOutDetailId: it.ID,
  3202. CancelOutDetailId: cancelInfo.ID,
  3203. ProductDate: it.ProductDate,
  3204. ExpireDate: it.ExpiryDate,
  3205. StorehouseId: houseConfig.StorehouseOutInfo,
  3206. OverCount: flush_count_one,
  3207. }
  3208. service.CreateStockFlowOne(flow)
  3209. //if flow.ID > 0 {
  3210. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  3211. //}
  3212. }
  3213. }
  3214. //flow := models.VmStockFlow{
  3215. // WarehousingId: info.WarehouseInfotId,
  3216. // GoodId: item.ProjectId,
  3217. // Number: info.Number,
  3218. // LicenseNumber: info.LicenseNumber,
  3219. // Count: prescribingNumber,
  3220. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3221. // PatientId: item.PatientId,
  3222. // SystemTime: info.SysRecordTime,
  3223. // ConsumableType: 7,
  3224. // IsSys: 0,
  3225. // WarehousingOrder: "",
  3226. // WarehouseOutId: info.WarehouseOutId,
  3227. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3228. // IsEdit: 0,
  3229. // CancelStockId: cancel.ID,
  3230. // CancelOrderNumber: cancel.OrderNumber,
  3231. // Manufacturer: manufacturer.ID,
  3232. // Dealer: 0,
  3233. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  3234. // UpdateCreator: 0,
  3235. // Status: 1,
  3236. // Ctime: time.Now().Unix(),
  3237. // Mtime: 0,
  3238. // Price: info.Price,
  3239. // WarehousingDetailId: info.WarehouseInfotId,
  3240. // WarehouseOutDetailId: info.ID,
  3241. // CancelOutDetailId: cancelInfo.ID,
  3242. // ProductDate: info.ProductDate,
  3243. // ExpireDate: info.ExpiryDate,
  3244. // StorehouseId: houseConfig.StorehouseOutInfo,
  3245. // OverCount: flush_count,
  3246. //}
  3247. //service.CreateStockFlowOne(flow)
  3248. //退库数量增加
  3249. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3250. //出库数量减少
  3251. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3252. //查询已出库数量
  3253. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3254. if prescribingNumber < dialysisInfo.Count {
  3255. //改变数量
  3256. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3257. }
  3258. if prescribingNumber >= dialysisInfo.Count {
  3259. //删除出库表
  3260. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3261. }
  3262. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3263. var flush_count_one int64
  3264. for _, it := range goodList {
  3265. flush_count_one += it.StockCount
  3266. }
  3267. //更新库存
  3268. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  3269. fmt.Println("msgerrkonde23332323", msgerrkonde)
  3270. //更新基础库库存
  3271. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  3272. }
  3273. }
  3274. }
  3275. }
  3276. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3277. fmt.Println(err)
  3278. }
  3279. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3280. fmt.Println(err)
  3281. if len(advices) > 0 {
  3282. for _, item := range advices {
  3283. redis := service.RedisClient()
  3284. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  3285. redis.Set(keyFive, "", time.Second)
  3286. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  3287. redis.Set(keyOne, "", time.Second)
  3288. redis.Close()
  3289. }
  3290. }
  3291. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3292. if len(advices) > 0 {
  3293. for _, item := range advices {
  3294. creater := c.GetAdminUserInfo().AdminUser.Id
  3295. service.DrugAutoAddCancelInfo(item, creater)
  3296. }
  3297. }
  3298. } else {
  3299. if drugOutConfig.IsOpen == 1 {
  3300. if len(advices) > 0 {
  3301. for _, item := range advices {
  3302. creater := c.GetAdminUserInfo().AdminUser.Id
  3303. service.DrugAutoAddCancelInfo(item, creater)
  3304. }
  3305. }
  3306. } else {
  3307. if len(advices) > 0 {
  3308. for _, item := range advices {
  3309. creater := c.GetAdminUserInfo().AdminUser.Id
  3310. service.DrugAutoAddCancelInfo(item, creater)
  3311. }
  3312. }
  3313. }
  3314. }
  3315. c.ServeSuccessJSON(map[string]interface{}{
  3316. "msg": "删除成功",
  3317. })
  3318. return
  3319. }
  3320. func (c *HisApiController) DeleteDoctorAdvice() {
  3321. id, _ := c.GetInt64("id")
  3322. advice, _ := service.GetHisDoctorAdvicesById(id)
  3323. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3324. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3325. //已收费和已发药的限制逻辑
  3326. isCharge := false
  3327. isMedicine := false
  3328. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3329. //获取今天该患者所有处方,判断是否发药或者收费
  3330. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3331. for _, item := range new_prescriptions {
  3332. if item.IsMedicine == 1 {
  3333. isMedicine = true
  3334. }
  3335. }
  3336. for _, item := range new_prescriptions {
  3337. if item.OrderStatus == 4 {
  3338. isCharge = true
  3339. }
  3340. }
  3341. if isMedicine {
  3342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3343. return
  3344. }
  3345. if isCharge {
  3346. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3347. return
  3348. }
  3349. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  3350. for _, item := range advices {
  3351. if item.IsMedicine == 1 {
  3352. isMedicine = true
  3353. }
  3354. }
  3355. if isMedicine {
  3356. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  3357. return
  3358. }
  3359. if new_prescription.ID > 0 {
  3360. if new_prescription.OrderStatus == 2 {
  3361. isCharge = true
  3362. }
  3363. }
  3364. if isCharge {
  3365. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3366. return
  3367. }
  3368. //已收费和已发药的限制逻辑
  3369. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  3370. redis := service.RedisClient()
  3371. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  3372. redis.Set(keyFive, "", time.Second)
  3373. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  3374. redis.Set(keyOne, "", time.Second)
  3375. defer redis.Close()
  3376. if err == nil {
  3377. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3378. //查询是否在处方中出库
  3379. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3380. if openConfig.IsOpen != 1 {
  3381. //判断该医嘱是否执行了
  3382. if advice.ExecutionState == 1 {
  3383. creater := c.GetAdminUserInfo().AdminUser.Id
  3384. service.DrugAutoAddCancelInfo(&advice, creater)
  3385. }
  3386. }
  3387. //开启保存处方扣减功能
  3388. if openConfig.IsOpen == 1 {
  3389. creater := c.GetAdminUserInfo().AdminUser.Id
  3390. service.DrugAutoAddCancelInfo(&advice, creater)
  3391. }
  3392. } else {
  3393. if drugOutConfig.IsOpen == 1 {
  3394. //查询是否在处方中出库
  3395. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3396. if openConfig.IsOpen != 1 {
  3397. //判断该医嘱是否执行了
  3398. if advice.ExecutionState == 1 {
  3399. creater := c.GetAdminUserInfo().AdminUser.Id
  3400. service.DrugAutoAddCancelInfo(&advice, creater)
  3401. }
  3402. }
  3403. //开启保存处方扣减功能
  3404. if openConfig.IsOpen == 1 {
  3405. creater := c.GetAdminUserInfo().AdminUser.Id
  3406. service.DrugAutoAddCancelInfo(&advice, creater)
  3407. }
  3408. } else {
  3409. //判断该医嘱是否执行了
  3410. if advice.ExecutionState == 1 {
  3411. creater := c.GetAdminUserInfo().AdminUser.Id
  3412. service.DrugAutoAddCancelInfo(&advice, creater)
  3413. }
  3414. }
  3415. }
  3416. c.ServeSuccessJSON(map[string]interface{}{
  3417. "msg": "删除成功",
  3418. })
  3419. return
  3420. } else {
  3421. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3422. return
  3423. }
  3424. }
  3425. func (c *HisApiController) DeleteProject() {
  3426. id, _ := c.GetInt64("id")
  3427. adminInfo := c.GetAdminUserInfo()
  3428. project, _ := service.GetHisProjectByID(id)
  3429. // var consumable models.DialysisBeforePrepare
  3430. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3431. //耗材保存处方出库
  3432. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3433. isCharge := false
  3434. isMedicine := false
  3435. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3436. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3437. for _, item := range new_prescriptions {
  3438. if item.IsMedicine == 1 {
  3439. isMedicine = true
  3440. }
  3441. }
  3442. for _, item := range new_prescriptions {
  3443. if item.OrderStatus == 4 {
  3444. isCharge = true
  3445. }
  3446. }
  3447. if isMedicine {
  3448. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3449. return
  3450. }
  3451. if isCharge {
  3452. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3453. return
  3454. }
  3455. if new_prescription.ID > 0 {
  3456. if new_prescription.OrderStatus == 2 {
  3457. isCharge = true
  3458. }
  3459. }
  3460. if isCharge {
  3461. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3462. return
  3463. }
  3464. service.DeletePrintInfo(id)
  3465. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  3466. label.Status = 0
  3467. service.CreateHisLabelRecord(&label)
  3468. if goodOutConfig.IsOpen != 1 {
  3469. if stockConfig.IsOpen == 1 {
  3470. if project.Type == 2 {
  3471. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3472. fmt.Println(err)
  3473. }
  3474. if project.Type == 3 && project.IsOut == 1 {
  3475. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3476. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3477. f_count, _ := strconv.ParseFloat(project.Count, 64)
  3478. operation_time := time.Now().Unix()
  3479. creater := adminInfo.AdminUser.Id
  3480. //创建退库单
  3481. timeStr := time.Now().Format("2006-01-02")
  3482. timeArr := strings.Split(timeStr, "-")
  3483. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  3484. total = total + 1
  3485. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3486. cancelStock := models.CancelStock{
  3487. OrderNumber: orderNumber,
  3488. OperaTime: operation_time,
  3489. OrgId: adminInfo.CurrentOrgId,
  3490. Creater: creater,
  3491. Ctime: time.Now().Unix(),
  3492. Status: 1,
  3493. ReturnTime: project.RecordDate,
  3494. Type: 1,
  3495. StorehouseId: houseConfig.StorehouseOutInfo,
  3496. IsCheck: 1,
  3497. }
  3498. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  3499. if msgerrkonde == gorm.ErrRecordNotFound {
  3500. service.AddSigleCancelStock(&cancelStock)
  3501. }
  3502. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  3503. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3504. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3505. //查询是否有出库
  3506. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  3507. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3508. deaerler, _ := service.GetDealerById(info.Dealer)
  3509. if info.ID > 0 {
  3510. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  3511. if info.Count >= prescribingNumber {
  3512. cancelStockInfo := models.CancelStockInfo{
  3513. GoodId: project.ProjectId,
  3514. CancelStockId: cancel.ID,
  3515. GoodTypeId: good.GoodTypeId,
  3516. Count: prescribingNumber,
  3517. Price: info.Price,
  3518. Total: 0,
  3519. ProductDate: info.ProductDate,
  3520. ExpiryDate: info.ExpiryDate,
  3521. Ctime: time.Now().Unix(),
  3522. Status: 1,
  3523. OrgId: adminInfo.CurrentOrgId,
  3524. OrderNumber: cancel.OrderNumber,
  3525. Type: 0,
  3526. Dealer: deaerler.DealerName,
  3527. Manufacturer: manufacturer.ManufacturerName,
  3528. Number: info.Number,
  3529. RegisterAccount: "",
  3530. Remark: "",
  3531. WarehouseInfoId: info.WarehouseInfotId,
  3532. PatientId: info.PatientId,
  3533. RecordDate: info.SysRecordTime,
  3534. StorehouseId: houseConfig.StorehouseOutInfo,
  3535. IsCheck: 1,
  3536. }
  3537. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3538. //回退库存
  3539. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  3540. //退库数量增加
  3541. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  3542. //出库数量减少
  3543. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  3544. }
  3545. if info.Count < prescribingNumber {
  3546. cancelStockInfo := models.CancelStockInfo{
  3547. GoodId: project.ProjectId,
  3548. CancelStockId: cancel.ID,
  3549. GoodTypeId: good.GoodTypeId,
  3550. Count: info.Count,
  3551. Price: info.Price,
  3552. Total: 0,
  3553. ProductDate: info.ProductDate,
  3554. ExpiryDate: info.ExpiryDate,
  3555. Ctime: time.Now().Unix(),
  3556. Status: 1,
  3557. OrgId: adminInfo.CurrentOrgId,
  3558. OrderNumber: cancel.OrderNumber,
  3559. Type: 0,
  3560. Dealer: deaerler.DealerName,
  3561. Manufacturer: manufacturer.ManufacturerName,
  3562. Number: info.Number,
  3563. RegisterAccount: "",
  3564. Remark: "",
  3565. WarehouseInfoId: info.WarehouseInfotId,
  3566. PatientId: info.PatientId,
  3567. RecordDate: info.SysRecordTime,
  3568. StorehouseId: houseConfig.StorehouseOutInfo,
  3569. IsCheck: 1,
  3570. }
  3571. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3572. //回退库存
  3573. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  3574. //退库数量增加
  3575. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3576. //出库数量减少
  3577. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  3578. }
  3579. //查询剩余库存
  3580. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3581. var over_count int64
  3582. for _, it := range goodList {
  3583. over_count += it.StockCount
  3584. }
  3585. //出库数据 大于 退库数量
  3586. if info.Count >= prescribingNumber {
  3587. flow := models.VmStockFlow{
  3588. WarehousingId: info.WarehouseInfotId,
  3589. GoodId: project.ProjectId,
  3590. Number: info.Number,
  3591. LicenseNumber: info.LicenseNumber,
  3592. Count: prescribingNumber,
  3593. UserOrgId: adminInfo.CurrentOrgId,
  3594. PatientId: project.PatientId,
  3595. SystemTime: info.SysRecordTime,
  3596. ConsumableType: 7,
  3597. IsSys: 0,
  3598. WarehousingOrder: "",
  3599. WarehouseOutId: info.WarehouseOutId,
  3600. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3601. IsEdit: 0,
  3602. CancelStockId: cancel.ID,
  3603. CancelOrderNumber: cancel.OrderNumber,
  3604. Manufacturer: manufacturer.ID,
  3605. Dealer: 0,
  3606. Creator: adminInfo.AdminUser.Id,
  3607. UpdateCreator: 0,
  3608. Status: 1,
  3609. Ctime: time.Now().Unix(),
  3610. Mtime: 0,
  3611. Price: info.Price,
  3612. WarehousingDetailId: info.WarehouseInfotId,
  3613. WarehouseOutDetailId: info.ID,
  3614. CancelOutDetailId: cancelInfo.ID,
  3615. ProductDate: info.ProductDate,
  3616. ExpireDate: info.ExpiryDate,
  3617. StorehouseId: houseConfig.StorehouseOutInfo,
  3618. OverCount: over_count,
  3619. }
  3620. service.CreateStockFlowOne(flow)
  3621. }
  3622. //出库数据小于退库数据
  3623. if info.Count < prescribingNumber {
  3624. flow := models.VmStockFlow{
  3625. WarehousingId: info.WarehouseInfotId,
  3626. GoodId: project.ProjectId,
  3627. Number: info.Number,
  3628. LicenseNumber: info.LicenseNumber,
  3629. Count: info.Count,
  3630. UserOrgId: adminInfo.CurrentOrgId,
  3631. PatientId: project.PatientId,
  3632. SystemTime: info.SysRecordTime,
  3633. ConsumableType: 7,
  3634. IsSys: 0,
  3635. WarehousingOrder: "",
  3636. WarehouseOutId: info.WarehouseOutId,
  3637. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3638. IsEdit: 0,
  3639. CancelStockId: cancel.ID,
  3640. CancelOrderNumber: cancel.OrderNumber,
  3641. Manufacturer: manufacturer.ID,
  3642. Dealer: 0,
  3643. Creator: adminInfo.AdminUser.Id,
  3644. UpdateCreator: 0,
  3645. Status: 1,
  3646. Ctime: time.Now().Unix(),
  3647. Mtime: 0,
  3648. Price: info.Price,
  3649. WarehousingDetailId: info.WarehouseInfotId,
  3650. WarehouseOutDetailId: info.ID,
  3651. CancelOutDetailId: cancelInfo.ID,
  3652. ProductDate: info.ProductDate,
  3653. ExpireDate: info.ExpiryDate,
  3654. StorehouseId: houseConfig.StorehouseOutInfo,
  3655. OverCount: over_count,
  3656. }
  3657. service.CreateStockFlowOne(flow)
  3658. }
  3659. //查询已出库数量
  3660. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  3661. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  3662. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  3663. if prescribingNumber < dialysisInfo.Count {
  3664. //改变数量
  3665. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  3666. }
  3667. if prescribingNumber >= dialysisInfo.Count {
  3668. //删除出库表
  3669. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  3670. }
  3671. //更新剩余库存
  3672. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  3673. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  3674. var total_count_one int64
  3675. for _, it := range stockList {
  3676. total_count_one += it.StockCount
  3677. }
  3678. //基础库插入数据
  3679. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  3680. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3681. var flush_count int64
  3682. for _, it := range goodListOne {
  3683. flush_count += it.StockCount
  3684. }
  3685. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  3686. if errs != nil {
  3687. goodErrcode := models.XtGoodErrcode{
  3688. UserOrgId: project.UserOrgId,
  3689. Errcode: "手动出库更新剩余出库失败",
  3690. GoodId: project.ProjectId,
  3691. Status: 1,
  3692. Ctime: time.Now().Unix(),
  3693. Mtime: 0,
  3694. Count: 0,
  3695. StockCount: 0,
  3696. Creater: creater,
  3697. BatchNumberId: 0,
  3698. WarehouseOutId: 0,
  3699. }
  3700. service.CreateGoodErrcode(goodErrcode)
  3701. }
  3702. }
  3703. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3704. fmt.Println(err)
  3705. } else {
  3706. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3707. fmt.Println(err)
  3708. }
  3709. }
  3710. }
  3711. //保存处方出库
  3712. if goodOutConfig.IsOpen == 1 {
  3713. if project.Type == 3 {
  3714. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3715. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3716. f_count, _ := strconv.ParseFloat(project.Count, 64)
  3717. operation_time := time.Now().Unix()
  3718. creater := adminInfo.AdminUser.Id
  3719. //创建退库单
  3720. timeStr := time.Now().Format("2006-01-02")
  3721. timeArr := strings.Split(timeStr, "-")
  3722. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  3723. total = total + 1
  3724. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3725. cancelStock := models.CancelStock{
  3726. OrderNumber: orderNumber,
  3727. OperaTime: operation_time,
  3728. OrgId: adminInfo.CurrentOrgId,
  3729. Creater: creater,
  3730. Ctime: time.Now().Unix(),
  3731. Status: 1,
  3732. ReturnTime: project.RecordDate,
  3733. Type: 1,
  3734. StorehouseId: houseConfig.StorehouseOutInfo,
  3735. IsCheck: 1,
  3736. }
  3737. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  3738. if msgerrkonde == gorm.ErrRecordNotFound {
  3739. service.AddSigleCancelStock(&cancelStock)
  3740. }
  3741. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  3742. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3743. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3744. //获取出库数据
  3745. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  3746. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3747. deaerler, _ := service.GetDealerById(info.Dealer)
  3748. if info.ID > 0 {
  3749. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  3750. if info.Count >= prescribingNumber {
  3751. cancelStockInfo := models.CancelStockInfo{
  3752. GoodId: project.ProjectId,
  3753. CancelStockId: cancel.ID,
  3754. GoodTypeId: good.GoodTypeId,
  3755. Count: prescribingNumber,
  3756. Price: info.Price,
  3757. Total: 0,
  3758. ProductDate: info.ProductDate,
  3759. ExpiryDate: info.ExpiryDate,
  3760. Ctime: time.Now().Unix(),
  3761. Status: 1,
  3762. OrgId: adminInfo.CurrentOrgId,
  3763. OrderNumber: cancel.OrderNumber,
  3764. Type: 0,
  3765. Dealer: deaerler.DealerName,
  3766. Manufacturer: manufacturer.ManufacturerName,
  3767. Number: info.Number,
  3768. RegisterAccount: "",
  3769. Remark: "",
  3770. WarehouseInfoId: info.WarehouseInfotId,
  3771. PatientId: info.PatientId,
  3772. RecordDate: info.SysRecordTime,
  3773. StorehouseId: houseConfig.StorehouseOutInfo,
  3774. IsCheck: 1,
  3775. }
  3776. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3777. //退库数量增加
  3778. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  3779. //出库数量减少
  3780. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  3781. }
  3782. if info.Count < prescribingNumber {
  3783. cancelStockInfo := models.CancelStockInfo{
  3784. GoodId: project.ProjectId,
  3785. CancelStockId: cancel.ID,
  3786. GoodTypeId: good.GoodTypeId,
  3787. Count: prescribingNumber,
  3788. Price: info.Price,
  3789. Total: 0,
  3790. ProductDate: info.ProductDate,
  3791. ExpiryDate: info.ExpiryDate,
  3792. Ctime: time.Now().Unix(),
  3793. Status: 1,
  3794. OrgId: adminInfo.CurrentOrgId,
  3795. OrderNumber: cancel.OrderNumber,
  3796. Type: 0,
  3797. Dealer: deaerler.DealerName,
  3798. Manufacturer: manufacturer.ManufacturerName,
  3799. Number: info.Number,
  3800. RegisterAccount: "",
  3801. Remark: "",
  3802. WarehouseInfoId: info.WarehouseInfotId,
  3803. PatientId: info.PatientId,
  3804. RecordDate: info.SysRecordTime,
  3805. StorehouseId: houseConfig.StorehouseOutInfo,
  3806. IsCheck: 1,
  3807. }
  3808. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3809. //回退库存
  3810. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  3811. }
  3812. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3813. var over_count int64
  3814. for _, it := range goodList {
  3815. over_count += it.StockCount
  3816. }
  3817. //查询出库数量
  3818. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  3819. //出库数据 大于 退库数量
  3820. if len(list) > 0 {
  3821. for _, it := range list {
  3822. //回退库存
  3823. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  3824. //退库数量增加
  3825. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  3826. //出库数量减少
  3827. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  3828. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3829. var over_count_one int64
  3830. for _, it := range goodList {
  3831. over_count_one += it.StockCount
  3832. }
  3833. //查询该批次是否有退库数据
  3834. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  3835. flow := models.VmStockFlow{
  3836. WarehousingId: it.WarehouseInfotId,
  3837. GoodId: it.GoodId,
  3838. Number: it.Number,
  3839. LicenseNumber: it.LicenseNumber,
  3840. Count: it.Count,
  3841. UserOrgId: adminInfo.CurrentOrgId,
  3842. PatientId: it.PatientId,
  3843. SystemTime: it.SysRecordTime,
  3844. ConsumableType: 7,
  3845. IsSys: 0,
  3846. WarehousingOrder: "",
  3847. WarehouseOutId: it.WarehouseOutId,
  3848. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  3849. IsEdit: 0,
  3850. CancelStockId: cancel.ID,
  3851. CancelOrderNumber: cancel.OrderNumber,
  3852. Manufacturer: manufacturer.ID,
  3853. Dealer: 0,
  3854. Creator: adminInfo.AdminUser.Id,
  3855. UpdateCreator: 0,
  3856. Status: 1,
  3857. Ctime: time.Now().Unix(),
  3858. Mtime: 0,
  3859. Price: it.Price,
  3860. WarehousingDetailId: it.WarehouseInfotId,
  3861. WarehouseOutDetailId: it.ID,
  3862. CancelOutDetailId: cancelInfo.ID,
  3863. ProductDate: it.ProductDate,
  3864. ExpireDate: it.ExpiryDate,
  3865. StorehouseId: houseConfig.StorehouseOutInfo,
  3866. OverCount: over_count_one,
  3867. }
  3868. service.CreateStockFlowOne(flow)
  3869. }
  3870. }
  3871. //查询已出库数量
  3872. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  3873. if prescribingNumber < dialysisInfo.Count {
  3874. //改变数量
  3875. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  3876. }
  3877. if prescribingNumber >= dialysisInfo.Count {
  3878. //删除出库表
  3879. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  3880. }
  3881. //更新剩余库存
  3882. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  3883. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  3884. var total_count_one int64
  3885. for _, it := range stockList {
  3886. total_count_one += it.StockCount
  3887. }
  3888. //基础库插入数据
  3889. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  3890. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3891. var flush_count int64
  3892. for _, it := range goodListOne {
  3893. flush_count += it.StockCount
  3894. }
  3895. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  3896. if errs != nil {
  3897. goodErrcode := models.XtGoodErrcode{
  3898. UserOrgId: project.UserOrgId,
  3899. Errcode: "手动出库更新剩余出库失败",
  3900. GoodId: project.ProjectId,
  3901. Status: 1,
  3902. Ctime: time.Now().Unix(),
  3903. Mtime: 0,
  3904. Count: 0,
  3905. StockCount: 0,
  3906. Creater: creater,
  3907. BatchNumberId: 0,
  3908. WarehouseOutId: 0,
  3909. }
  3910. service.CreateGoodErrcode(goodErrcode)
  3911. }
  3912. }
  3913. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3914. fmt.Println(err)
  3915. } else {
  3916. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3917. fmt.Println(err)
  3918. }
  3919. }
  3920. c.ServeSuccessJSON(map[string]interface{}{
  3921. "msg": "删除成功",
  3922. })
  3923. return
  3924. }
  3925. func (c *HisApiController) CreateHisAdditionalCharge() {
  3926. his_patient_id, _ := c.GetInt64("his_patient_id")
  3927. patient_id, _ := c.GetInt64("patient_id")
  3928. record_date := c.GetString("record_date")
  3929. timeLayout := "2006-01-02"
  3930. loc, _ := time.LoadLocation("Local")
  3931. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3932. if err != nil {
  3933. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3934. return
  3935. }
  3936. adminInfo := c.GetAdminUserInfo()
  3937. recordDateTime := theTime.Unix()
  3938. dataBody := make(map[string]interface{}, 0)
  3939. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3940. if err != nil {
  3941. utils.ErrorLog(err.Error())
  3942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3943. return
  3944. }
  3945. var additions []*models.HisAdditionalCharge
  3946. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  3947. additions, _ := dataBody["addition"].([]interface{})
  3948. if len(additions) > 0 {
  3949. for _, item := range additions {
  3950. items := item.(map[string]interface{})
  3951. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  3952. utils.ErrorLog("item_id")
  3953. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3954. return
  3955. }
  3956. item_id := int64(items["item_id"].(float64))
  3957. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  3958. utils.ErrorLog("item_name")
  3959. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3960. return
  3961. }
  3962. item_name := items["item_name"].(string)
  3963. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  3964. utils.ErrorLog("price")
  3965. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3966. return
  3967. }
  3968. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  3969. ctime := time.Now().Unix()
  3970. additional := &models.HisAdditionalCharge{
  3971. PatientId: patient_id,
  3972. HisPatientId: his_patient_id,
  3973. UserOrgId: adminInfo.CurrentOrgId,
  3974. RecordDate: recordDateTime,
  3975. CreatedTime: ctime,
  3976. UpdatedTime: ctime,
  3977. Modifier: adminInfo.AdminUser.Id,
  3978. Creator: adminInfo.AdminUser.Id,
  3979. Price: price,
  3980. ItemName: item_name,
  3981. ItemId: item_id,
  3982. Status: 1,
  3983. }
  3984. additions = append(additions, additional)
  3985. }
  3986. }
  3987. }
  3988. for _, item := range additions {
  3989. service.CreateAddtionalCharge(item)
  3990. }
  3991. c.ServeSuccessJSON(map[string]interface{}{
  3992. "msg": "创建成功",
  3993. })
  3994. }
  3995. func (c *HisApiController) CreateHisPatientCaseHistory() {
  3996. blood_fat := c.GetString("blood_fat")
  3997. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  3998. blood_sugar := c.GetString("blood_sugar")
  3999. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  4000. chief_conplaint := c.GetString("chief_conplaint")
  4001. dbp := c.GetString("dbp")
  4002. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  4003. delivery_way, _ := c.GetInt64("delivery_way")
  4004. diagnostic := c.GetString("diagnostic")
  4005. family_history := c.GetString("family_history")
  4006. height := c.GetString("height")
  4007. history_of_present_illness := c.GetString("history_of_present_illness")
  4008. is_infect, _ := c.GetInt64("is_infect")
  4009. past_history := c.GetString("past_history")
  4010. patient_id, _ := c.GetInt64("patient_id")
  4011. his_patient_id, _ := c.GetInt64("his_patient_id")
  4012. personal_history := c.GetString("personal_history")
  4013. pulse := c.GetString("pulse")
  4014. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  4015. sbp := c.GetString("sbp")
  4016. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  4017. heightfloat, _ := strconv.ParseFloat(height, 64)
  4018. sicktype := c.GetString("sick_type")
  4019. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  4020. symptom := c.GetString("symptom")
  4021. sick_date := c.GetString("sick_date")
  4022. temperatures := c.GetString("temperature")
  4023. temperature, _ := strconv.ParseFloat(temperatures, 64)
  4024. record_date := c.GetString("record_date")
  4025. breathing := c.GetString("breathing")
  4026. doctor_advice := c.GetString("doctor_advice")
  4027. remark := c.GetString("remark")
  4028. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  4029. sick, _ := c.GetInt64("sick")
  4030. diagnose, _ := c.GetInt64("diagnose")
  4031. //id, _ := c.GetInt64("id")
  4032. timeLayout := "2006-01-02"
  4033. loc, _ := time.LoadLocation("Local")
  4034. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4035. allergic_history := c.GetString("allergic_history")
  4036. if err != nil {
  4037. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4038. return
  4039. }
  4040. recordDateTime := theTime.Unix()
  4041. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  4042. if err != nil {
  4043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4044. return
  4045. }
  4046. sickTimes := sickTime.Unix()
  4047. ctime := time.Now().Unix()
  4048. primary_disease := c.GetString("primary_disease")
  4049. confirm_failure_date := c.GetString("confirm_failure_date")
  4050. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  4051. drug_allergy_history := c.GetString("drug_allergy_history")
  4052. physical_examination := c.GetString("physical_examination")
  4053. special_inspection := c.GetString("special_inspection")
  4054. lab_apparatus := c.GetString("lab_apparatus")
  4055. caseHistory := models.HisPatientCaseHistory{
  4056. HisPatientId: his_patient_id,
  4057. PatientId: patient_id,
  4058. Temperature: temperature,
  4059. BloodSugar: bloodsugarfloat,
  4060. Pulse: pulsefloat,
  4061. Sbp: sbpfloat,
  4062. Dbp: dbpfloat,
  4063. Height: heightfloat,
  4064. BloodFat: bloodfatfloat,
  4065. SickType: sick_type,
  4066. Symptom: symptom,
  4067. SickDate: sickTimes,
  4068. IsInfect: is_infect,
  4069. HistoryOfPresentIllness: history_of_present_illness,
  4070. PastHistory: past_history,
  4071. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  4072. ChiefConplaint: chief_conplaint,
  4073. PersonalHistory: personal_history,
  4074. FamilyHistory: family_history,
  4075. Diagnostic: diagnostic,
  4076. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4077. Status: 1,
  4078. Ctime: ctime,
  4079. Mtime: ctime,
  4080. RecordDate: recordDateTime,
  4081. DeliveryWay: delivery_way,
  4082. Breathing: breathingfloat,
  4083. DoctorAdvice: doctor_advice,
  4084. Remark: remark,
  4085. Sick: sick,
  4086. Diagnose: diagnose,
  4087. AllergicHistory: allergic_history,
  4088. PrimaryDisease: primary_disease,
  4089. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  4090. DrugAllergyHistory: drug_allergy_history,
  4091. PhysicalExamination: physical_examination,
  4092. SpecialInspection: special_inspection,
  4093. LabApparatus: lab_apparatus,
  4094. }
  4095. //查询该患者是否有病历
  4096. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  4097. if errcodes == gorm.ErrRecordNotFound {
  4098. err = service.SaveHisPatientCaseHistory(&caseHistory)
  4099. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4100. if err != nil {
  4101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4102. return
  4103. }
  4104. c.ServeSuccessJSON(map[string]interface{}{
  4105. "caseHistory": caseHistory,
  4106. "historyInfo": historyInfo,
  4107. })
  4108. return
  4109. } else if errcodes == nil {
  4110. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  4111. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4112. if err != nil {
  4113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4114. return
  4115. }
  4116. c.ServeSuccessJSON(map[string]interface{}{
  4117. "caseHistory": caseHistory,
  4118. "historyInfo": historyInfo,
  4119. })
  4120. }
  4121. //查询该患者是否有病历
  4122. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  4123. //if errcode == gorm.ErrRecordNotFound {
  4124. // err = service.SaveHisPatientCaseHistory(caseHistory)
  4125. // if err != nil {
  4126. // c.ServeSuccessJSON(map[string]interface{}{
  4127. // "msg": "保存成功",
  4128. // })
  4129. // }
  4130. //} else if errcode == nil {
  4131. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4132. // return
  4133. //}
  4134. }
  4135. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  4136. patient_id, _ := c.GetInt64("patient_id", 0)
  4137. adminUser := c.GetAdminUserInfo()
  4138. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  4139. c.ServeSuccessJSON(map[string]interface{}{
  4140. "list": caseHistorys,
  4141. })
  4142. }
  4143. func (c *HisApiController) GetHisPatientCaseHistory() {
  4144. record_date, _ := c.GetInt64("record_date", 0)
  4145. patient_id, _ := c.GetInt64("patient_id", 0)
  4146. admin := c.GetAdminUserInfo()
  4147. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  4148. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  4149. c.ServeSuccessJSON(map[string]interface{}{
  4150. "info": info,
  4151. "case_history": case_history,
  4152. })
  4153. }
  4154. func (c *HisApiController) CreateCaseHistoryTemplate() {
  4155. template_name := c.GetString("template_name")
  4156. template_remark := c.GetString("template_remark")
  4157. doctor := c.GetAdminUserInfo().AdminUser.Id
  4158. diagnostic := c.GetString("diagnostic")
  4159. chief_conplaint := c.GetString("chief_conplain")
  4160. history_of_present_illness := c.GetString("history_of_present_illness")
  4161. past_history := c.GetString("past_history")
  4162. personal_history := c.GetString("personal_history")
  4163. family_history := c.GetString("family_history")
  4164. user_name := c.GetString("user_name")
  4165. doctor_advice := c.GetString("doctor_advice")
  4166. remark := c.GetString("remark")
  4167. //record_date := c.GetString("record_date")
  4168. //fmt.Println("record_date--------",record_date)
  4169. //timeLayout := "2006-01-02"
  4170. //loc, _ := time.LoadLocation("Local")
  4171. //
  4172. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4173. //if err != nil {
  4174. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4175. // return
  4176. //}
  4177. //recordDateTime := theTime.Unix()
  4178. ctime := time.Now().Unix()
  4179. template := models.HisCaseHistoryTemplate{
  4180. HistoryOfPresentIllness: history_of_present_illness,
  4181. PastHistory: past_history,
  4182. ChiefConplaint: chief_conplaint,
  4183. PersonalHistory: personal_history,
  4184. FamilyHistory: family_history,
  4185. Diagnostic: diagnostic,
  4186. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4187. Status: 1,
  4188. Ctime: ctime,
  4189. Mtime: ctime,
  4190. RecordDate: time.Now().Unix(),
  4191. TemplateName: template_name,
  4192. TemplateRemark: template_remark,
  4193. Creator: doctor,
  4194. Modifier: doctor,
  4195. UserName: user_name,
  4196. DoctorAdvice: doctor_advice,
  4197. Remark: remark,
  4198. }
  4199. err := service.SaveHisPatientCaseHistoryTemplate(template)
  4200. if err == nil {
  4201. c.ServeSuccessJSON(map[string]interface{}{
  4202. "msg": "保存成功",
  4203. })
  4204. } else {
  4205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4206. return
  4207. }
  4208. }
  4209. func (c *HisApiController) GetCaseHistoryTemplate() {
  4210. timeLayout := "2006-01-02"
  4211. loc, _ := time.LoadLocation("Local")
  4212. keyword := c.GetString("keyword")
  4213. start_time := c.GetString("start_time")
  4214. end_time := c.GetString("end_time")
  4215. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4216. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4217. admin := c.GetAdminUserInfo()
  4218. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  4219. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  4220. c.ServeSuccessJSON(map[string]interface{}{
  4221. "template": template,
  4222. //"history": history,
  4223. })
  4224. }
  4225. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4226. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4227. utils.ErrorLog("drug_name")
  4228. return enums.ErrorCodeParamWrong
  4229. }
  4230. adviceName, _ := json["drug_name"].(string)
  4231. if len(adviceName) == 0 {
  4232. utils.ErrorLog("len(advice_name) == 0")
  4233. return enums.ErrorCodeParamWrong
  4234. }
  4235. advice.AdviceName = adviceName
  4236. adviceDesc, _ := json["advice_desc"].(string)
  4237. advice.AdviceDesc = adviceDesc
  4238. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4239. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4240. advice.DrugSpec = drugSpec
  4241. }
  4242. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4243. remark, _ := json["remark"].(string)
  4244. advice.Remark = remark
  4245. }
  4246. if json["id"] == nil {
  4247. advice.DrugId = 0
  4248. } else {
  4249. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4250. drug_id := int64(json["id"].(float64))
  4251. advice.DrugId = drug_id
  4252. }
  4253. }
  4254. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4255. advice_id := int64(json["advice_id"].(float64))
  4256. advice.ID = advice_id
  4257. if advice.ID > 0 {
  4258. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4259. if err == nil {
  4260. if hisAdvice.ID > 0 {
  4261. advice.ExecutionTime = hisAdvice.ExecutionTime
  4262. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4263. advice.ExecutionState = hisAdvice.ExecutionState
  4264. advice.CheckTime = hisAdvice.CheckTime
  4265. advice.Checker = hisAdvice.Checker
  4266. advice.CheckState = hisAdvice.CheckState
  4267. advice.StartTime = hisAdvice.StartTime
  4268. advice.FeedetlSn = hisAdvice.FeedetlSn
  4269. }
  4270. }
  4271. }
  4272. }
  4273. //
  4274. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4275. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4276. // advice.ExecutionTime = execution_time
  4277. //}
  4278. //
  4279. //
  4280. //
  4281. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  4282. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  4283. // advice.ExecutionStaff = execution_staff
  4284. //}
  4285. //
  4286. //
  4287. //
  4288. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  4289. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  4290. // advice.ExecutionState = execution_state
  4291. //}
  4292. //
  4293. //
  4294. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  4295. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  4296. // advice.CheckTime = check_time
  4297. //}
  4298. //
  4299. //
  4300. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  4301. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  4302. // advice.CheckState = check_state
  4303. //}
  4304. //
  4305. //
  4306. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  4307. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  4308. // advice.Checker = checker
  4309. //}
  4310. //
  4311. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  4312. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  4313. // advice.StartTime = start_time
  4314. //}
  4315. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4316. drugSpecUnit, _ := json["min_unit"].(string)
  4317. advice.DrugSpecUnit = drugSpecUnit
  4318. }
  4319. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4320. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4321. advice.SingleDose = singleDose
  4322. }
  4323. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4324. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4325. advice.SingleDoseUnit = singleDoseUnit
  4326. }
  4327. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4328. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4329. advice.PrescribingNumber = prescribingNumber
  4330. }
  4331. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4332. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4333. advice.PrescribingNumberUnit = prescribingNumberUnit
  4334. }
  4335. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4336. deliveryWay, _ := json["delivery_way"].(string)
  4337. advice.DeliveryWay = deliveryWay
  4338. }
  4339. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4340. executionFrequency, _ := json["execution_frequency"].(string)
  4341. advice.ExecutionFrequency = executionFrequency
  4342. }
  4343. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4344. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4345. advice.Price = price
  4346. }
  4347. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4348. med_list_codg, _ := json["medical_insurance_number"].(string)
  4349. advice.MedListCodg = med_list_codg
  4350. }
  4351. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4352. day := int64(json["day"].(float64))
  4353. advice.Day = day
  4354. }
  4355. return 0
  4356. }
  4357. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  4358. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4359. id := int64(json["id"].(float64))
  4360. project.ID = id
  4361. historyProject, _ := service.GetHisProjectByID(id)
  4362. project.FeedetlSn = historyProject.FeedetlSn
  4363. }
  4364. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4365. project_id := int64(json["project_id"].(float64))
  4366. project.ProjectId = project_id
  4367. }
  4368. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4369. // price := int64(json["price"].(float64))
  4370. // formatInt_price := strconv.FormatInt(price, 10)
  4371. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4372. // project.Price = float_price
  4373. // }
  4374. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4375. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4376. project.Price = price
  4377. }
  4378. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  4379. total, _ := json["total"].(string)
  4380. project.Count = total
  4381. }
  4382. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  4383. medical_code, _ := json["medical_code"].(string)
  4384. project.MedListCodg = medical_code
  4385. }
  4386. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4387. single_dose, _ := json["single_dose"].(string)
  4388. project.SingleDose = single_dose
  4389. }
  4390. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4391. delivery_way, _ := json["delivery_way"].(string)
  4392. project.DeliveryWay = delivery_way
  4393. }
  4394. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4395. execution_frequency, _ := json["execution_frequency"].(string)
  4396. project.ExecutionFrequency = execution_frequency
  4397. }
  4398. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4399. remark, _ := json["remark"].(string)
  4400. project.Remark = remark
  4401. }
  4402. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  4403. day, _ := json["number_days"].(string)
  4404. project.Day = day
  4405. }
  4406. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  4407. unit, _ := json["unit"].(string)
  4408. project.Unit = unit
  4409. }
  4410. return 0
  4411. }
  4412. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  4413. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4414. id := int64(json["id"].(float64))
  4415. historyAddtions, _ := service.GetHisAdditionByID(id)
  4416. additionalCharge.ID = id
  4417. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  4418. }
  4419. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  4420. item_id := int64(json["item_id"].(float64))
  4421. additionalCharge.ItemId = item_id
  4422. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  4423. if config.ID > 0 {
  4424. if len(config.Code) > 0 {
  4425. additionalCharge.MedListCodg = config.Code
  4426. }
  4427. }
  4428. }
  4429. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4430. // price := int64(json["price"].(float64))
  4431. // formatInt_price := strconv.FormatInt(price, 10)
  4432. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4433. // additionalCharge.Price = float_price
  4434. // }
  4435. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4436. // price := int64(json["price"].(float64))
  4437. // formatInt_price := strconv.FormatInt(price, 10)
  4438. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4439. // additionalCharge.Price = float_price
  4440. //}
  4441. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4442. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4443. additionalCharge.Price = price
  4444. }
  4445. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  4446. count, _ := json["count"].(string)
  4447. counts, _ := strconv.ParseInt(count, 10, 64)
  4448. additionalCharge.Count = counts
  4449. }
  4450. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  4451. item_name, _ := json["item_name"].(string)
  4452. additionalCharge.ItemName = item_name
  4453. }
  4454. return 0
  4455. }
  4456. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4457. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4458. utils.ErrorLog("drug_name")
  4459. return enums.ErrorCodeParamWrong
  4460. }
  4461. adviceName, _ := json["drug_name"].(string)
  4462. if len(adviceName) == 0 {
  4463. utils.ErrorLog("len(advice_name) == 0")
  4464. return enums.ErrorCodeParamWrong
  4465. }
  4466. advice.AdviceName = adviceName
  4467. adviceDesc, _ := json["advice_desc"].(string)
  4468. advice.AdviceDesc = adviceDesc
  4469. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4470. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4471. advice.DrugSpec = drugSpec
  4472. }
  4473. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4474. remark, _ := json["remark"].(string)
  4475. advice.Remark = remark
  4476. }
  4477. if json["id"] == nil {
  4478. advice.DrugId = 0
  4479. } else {
  4480. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4481. drug_id := int64(json["id"].(float64))
  4482. advice.DrugId = drug_id
  4483. }
  4484. }
  4485. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  4486. groupno := int64(json["groupno"].(float64))
  4487. advice.Groupno = groupno
  4488. }
  4489. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  4490. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  4491. advice.HospApprFlag = hosp_appr_flag
  4492. }
  4493. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4494. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4495. advice.PrescribingNumber = prescribingNumber
  4496. }
  4497. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  4498. // frequency_type := int64(json["frequency_type"].(float64))
  4499. // advice.FrequencyType = frequency_type
  4500. //}
  4501. //
  4502. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  4503. // day_count := int64(json["day_count"].(float64))
  4504. // advice.DayCount = day_count
  4505. //}
  4506. //
  4507. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  4508. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  4509. // week_day, _ := json["week_day"].(string)
  4510. // advice.WeekDay = week_day
  4511. //}
  4512. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4513. drugSpecUnit, _ := json["min_unit"].(string)
  4514. advice.DrugSpecUnit = drugSpecUnit
  4515. }
  4516. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4517. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4518. advice.SingleDose = singleDose
  4519. }
  4520. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4521. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4522. advice.SingleDoseUnit = singleDoseUnit
  4523. }
  4524. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4525. deliveryWay, _ := json["delivery_way"].(string)
  4526. advice.DeliveryWay = deliveryWay
  4527. }
  4528. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4529. executionFrequency, _ := json["execution_frequency"].(string)
  4530. advice.ExecutionFrequency = executionFrequency
  4531. }
  4532. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4533. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4534. advice.Price = price
  4535. }
  4536. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4537. med_list_codg, _ := json["medical_insurance_number"].(string)
  4538. advice.MedListCodg = med_list_codg
  4539. }
  4540. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4541. day := int64(json["day"].(float64))
  4542. advice.Day = day
  4543. }
  4544. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4545. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4546. advice.PrescribingNumberUnit = prescribingNumberUnit
  4547. }
  4548. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4549. advice_id := int64(json["advice_id"].(float64))
  4550. advice.ID = advice_id
  4551. if advice.ID > 0 {
  4552. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4553. if err == nil {
  4554. if hisAdvice.ID > 0 {
  4555. advice.ExecutionTime = hisAdvice.ExecutionTime
  4556. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4557. advice.ExecutionState = hisAdvice.ExecutionState
  4558. advice.CheckTime = hisAdvice.CheckTime
  4559. advice.Checker = hisAdvice.Checker
  4560. advice.CheckState = hisAdvice.CheckState
  4561. advice.StartTime = hisAdvice.StartTime
  4562. advice.HospApprFlag = hisAdvice.HospApprFlag
  4563. advice.IsMedicine = hisAdvice.IsMedicine
  4564. if hisAdvice.UserOrgId == 10028 {
  4565. 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 {
  4566. advice.ExecutionTime = 0
  4567. advice.ExecutionStaff = 0
  4568. advice.ExecutionState = 2
  4569. advice.CheckTime = 0
  4570. advice.Checker = 0
  4571. advice.CheckState = 2
  4572. }
  4573. } else {
  4574. 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 {
  4575. advice.ExecutionTime = 0
  4576. advice.ExecutionStaff = 0
  4577. advice.ExecutionState = 2
  4578. advice.CheckTime = 0
  4579. advice.Checker = 0
  4580. advice.CheckState = 2
  4581. }
  4582. }
  4583. //advice.Groupno = hisAdvice.Groupno
  4584. }
  4585. }
  4586. }
  4587. }
  4588. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  4589. //
  4590. //if drugStockConfig.IsOpen == 1 {
  4591. //
  4592. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  4593. // if advice.ID == 0 { //医嘱不存在
  4594. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  4595. // drug.Total = drug.Total - advice.PrescribingNumber
  4596. // service.UpdateBaseDrugLib(&drug)
  4597. //
  4598. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  4599. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  4600. // drug.Total = drug.Total - num
  4601. // service.UpdateBaseDrugLib(&drug)
  4602. // }
  4603. //
  4604. // } else if advice.ID > 0 { //医嘱存在
  4605. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  4606. // var num float64
  4607. //
  4608. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  4609. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  4610. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  4611. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  4612. // drug.Total = drug.Total + num
  4613. // service.UpdateBaseDrugLib(&drug)
  4614. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  4615. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  4616. // drug.Total = drug.Total - num
  4617. // service.UpdateBaseDrugLib(&drug)
  4618. // }
  4619. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  4620. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  4621. // if num2 > advice.PrescribingNumber {
  4622. // num = num2 - advice.PrescribingNumber
  4623. // drug.Total = drug.Total + num
  4624. // service.UpdateBaseDrugLib(&drug)
  4625. // } else if num2 < advice.PrescribingNumber {
  4626. // num = advice.PrescribingNumber - num2
  4627. // drug.Total = drug.Total - num
  4628. // service.UpdateBaseDrugLib(&drug)
  4629. // }
  4630. //
  4631. // }
  4632. //
  4633. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  4634. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  4635. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  4636. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  4637. // if num1 > num2 {
  4638. // num = num1 - num2
  4639. // drug.Total = drug.Total + num
  4640. // service.UpdateBaseDrugLib(&drug)
  4641. // } else if num1 < num2 {
  4642. // num = num2 - num1
  4643. // drug.Total = drug.Total - num
  4644. // service.UpdateBaseDrugLib(&drug)
  4645. // }
  4646. //
  4647. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  4648. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  4649. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  4650. // if hisAdvice.PrescribingNumber > num2 {
  4651. // num = hisAdvice.PrescribingNumber - num2
  4652. // drug.Total = drug.Total + num
  4653. // service.UpdateBaseDrugLib(&drug)
  4654. // } else if num2 < advice.PrescribingNumber {
  4655. // num = num2 - hisAdvice.PrescribingNumber
  4656. // drug.Total = drug.Total - num
  4657. // service.UpdateBaseDrugLib(&drug)
  4658. // }
  4659. //
  4660. // }
  4661. // }
  4662. // }
  4663. //}
  4664. //
  4665. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4666. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4667. // advice.ExecutionTime = execution_time
  4668. //}
  4669. //
  4670. //
  4671. //
  4672. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  4673. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  4674. // advice.ExecutionStaff = execution_staff
  4675. //}
  4676. //
  4677. //
  4678. //
  4679. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  4680. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  4681. // advice.ExecutionState = execution_state
  4682. //}
  4683. //
  4684. //
  4685. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  4686. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  4687. // advice.CheckTime = check_time
  4688. //}
  4689. //
  4690. //
  4691. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  4692. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  4693. // advice.CheckState = check_state
  4694. //}
  4695. //
  4696. //
  4697. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  4698. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  4699. // advice.Checker = checker
  4700. //}
  4701. //
  4702. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  4703. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  4704. // advice.StartTime = start_time
  4705. //}
  4706. return 0
  4707. }
  4708. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  4709. project.ExecutionStaff = 0
  4710. project.ExecutionState = 2
  4711. project.ExecutionTime = 0
  4712. project.Checker = 0
  4713. project.CheckState = 2
  4714. project.CheckTime = 0
  4715. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4716. id := int64(json["id"].(float64))
  4717. project.ID = id
  4718. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  4719. project.ExecutionStaff = temp_project.ExecutionStaff
  4720. project.ExecutionState = temp_project.ExecutionState
  4721. project.ExecutionTime = temp_project.ExecutionTime
  4722. project.Checker = temp_project.Checker
  4723. project.CheckState = temp_project.CheckState
  4724. project.CheckTime = temp_project.CheckTime
  4725. project.TeamId = temp_project.TeamId
  4726. }
  4727. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  4728. types := int64(json["type"].(float64))
  4729. project.Type = types
  4730. }
  4731. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4732. project_id := int64(json["project_id"].(float64))
  4733. project.ProjectId = project_id
  4734. }
  4735. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  4736. team_id := int64(json["team_id"].(float64))
  4737. project.TeamId = team_id
  4738. }
  4739. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4740. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4741. project.Price = price
  4742. }
  4743. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  4744. total, _ := json["total"].(string)
  4745. //totals, _ := strconv.ParseInt(total, 10, 64)
  4746. project.Count = total
  4747. }
  4748. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  4749. medical_code, _ := json["medical_code"].(string)
  4750. project.MedListCodg = medical_code
  4751. }
  4752. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4753. single_dose, _ := json["single_dose"].(string)
  4754. project.SingleDose = single_dose
  4755. }
  4756. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4757. delivery_way, _ := json["delivery_way"].(string)
  4758. project.DeliveryWay = delivery_way
  4759. }
  4760. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4761. execution_frequency, _ := json["execution_frequency"].(string)
  4762. project.ExecutionFrequency = execution_frequency
  4763. }
  4764. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4765. remark, _ := json["remark"].(string)
  4766. project.Remark = remark
  4767. }
  4768. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  4769. day, _ := json["number_days"].(string)
  4770. project.Day = day
  4771. }
  4772. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  4773. unit, _ := json["unit"].(string)
  4774. project.Unit = unit
  4775. }
  4776. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  4777. // frequency_type := int64(json["frequency_type"].(float64))
  4778. // project.FrequencyType = frequency_type
  4779. //}
  4780. //
  4781. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  4782. // day_count := int64(json["day_count"].(float64))
  4783. // project.DayCount = day_count
  4784. //}
  4785. //
  4786. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  4787. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  4788. // week_day, _ := json["week_day"].(string)
  4789. // project.WeekDay = week_day
  4790. //}
  4791. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  4792. //
  4793. //if project.ID == 0 {
  4794. // if stockConfig.IsOpen == 1 {
  4795. // if project.Type == 3 {
  4796. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4797. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  4798. // good.Total = good.Total - f_count
  4799. // service.UpdateGoodInfo(&good)
  4800. // }
  4801. // }
  4802. //
  4803. //} else {
  4804. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  4805. //
  4806. // if stockConfig.IsOpen == 1 {
  4807. // if project.Type == 3 {
  4808. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4809. // if project.Count < temp_project.Count {
  4810. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  4811. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  4812. //
  4813. // other_count := f_count_two - f_count_one
  4814. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  4815. // good.Total = good.Total + other_count_two
  4816. // service.UpdateGoodInfo(&good)
  4817. // } else if project.Count > temp_project.Count {
  4818. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  4819. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  4820. //
  4821. // other_count := f_count_one - f_count_two
  4822. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  4823. // good.Total = good.Total - other_count_two
  4824. // service.UpdateGoodInfo(&good)
  4825. // }
  4826. //
  4827. // }
  4828. // }
  4829. //
  4830. //}
  4831. return 0
  4832. }
  4833. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  4834. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4835. id := int64(json["id"].(float64))
  4836. additionalCharge.ID = id
  4837. }
  4838. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  4839. item_id := int64(json["item_id"].(float64))
  4840. additionalCharge.ItemId = item_id
  4841. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  4842. if config.ID > 0 {
  4843. if len(config.Code) > 0 {
  4844. additionalCharge.MedListCodg = config.Code
  4845. }
  4846. }
  4847. }
  4848. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4849. // price := int64(json["price"].(float64))
  4850. // formatInt_price := strconv.FormatInt(price, 10)
  4851. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4852. // additionalCharge.Price = float_price
  4853. // }
  4854. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4855. // price := int64(json["price"].(float64))
  4856. // formatInt_price := strconv.FormatInt(price, 10)
  4857. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4858. // additionalCharge.Price = float_price
  4859. //}
  4860. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4861. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4862. additionalCharge.Price = price
  4863. }
  4864. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  4865. count, _ := json["count"].(string)
  4866. counts, _ := strconv.ParseInt(count, 10, 64)
  4867. additionalCharge.Count = counts
  4868. }
  4869. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  4870. item_name, _ := json["item_name"].(string)
  4871. additionalCharge.ItemName = item_name
  4872. }
  4873. return 0
  4874. }
  4875. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  4876. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4877. utils.ErrorLog("drug_name")
  4878. return enums.ErrorCodeParamWrong
  4879. }
  4880. adviceName, _ := json["drug_name"].(string)
  4881. if len(adviceName) == 0 {
  4882. utils.ErrorLog("len(advice_name) == 0")
  4883. return enums.ErrorCodeParamWrong
  4884. }
  4885. advice.AdviceName = adviceName
  4886. adviceDesc, _ := json["advice_desc"].(string)
  4887. advice.AdviceDesc = adviceDesc
  4888. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4889. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4890. advice.DrugSpec = drugSpec
  4891. }
  4892. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4893. remark, _ := json["remark"].(string)
  4894. advice.Remark = remark
  4895. }
  4896. if json["id"] == nil {
  4897. advice.DrugId = 0
  4898. } else {
  4899. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4900. drug_id := int64(json["id"].(float64))
  4901. advice.DrugId = drug_id
  4902. }
  4903. }
  4904. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4905. drugSpecUnit, _ := json["min_unit"].(string)
  4906. advice.DrugSpecUnit = drugSpecUnit
  4907. }
  4908. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4909. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4910. advice.SingleDose = singleDose
  4911. }
  4912. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4913. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4914. advice.SingleDoseUnit = singleDoseUnit
  4915. }
  4916. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4917. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4918. advice.PrescribingNumber = prescribingNumber
  4919. }
  4920. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4921. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4922. advice.PrescribingNumberUnit = prescribingNumberUnit
  4923. }
  4924. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4925. deliveryWay, _ := json["delivery_way"].(string)
  4926. advice.DeliveryWay = deliveryWay
  4927. }
  4928. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4929. executionFrequency, _ := json["execution_frequency"].(string)
  4930. advice.ExecutionFrequency = executionFrequency
  4931. }
  4932. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4933. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4934. advice.Price = price
  4935. }
  4936. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4937. med_list_codg, _ := json["medical_insurance_number"].(string)
  4938. advice.MedListCodg = med_list_codg
  4939. }
  4940. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4941. day := int64(json["day"].(float64))
  4942. advice.Day = day
  4943. }
  4944. return 0
  4945. }
  4946. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  4947. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  4948. types := int64(json["type"].(float64))
  4949. project.Type = types
  4950. }
  4951. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4952. project_id := int64(json["project_id"].(float64))
  4953. project.ProjectId = project_id
  4954. }
  4955. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4956. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4957. project.Price = price
  4958. }
  4959. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  4960. total, _ := json["total"].(string)
  4961. //totals, _ := strconv.ParseInt(total, 10, 64)
  4962. project.Count = total
  4963. }
  4964. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  4965. medical_code, _ := json["medical_code"].(string)
  4966. project.MedListCodg = medical_code
  4967. }
  4968. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4969. single_dose, _ := json["single_dose"].(string)
  4970. project.SingleDose = single_dose
  4971. }
  4972. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4973. delivery_way, _ := json["delivery_way"].(string)
  4974. project.DeliveryWay = delivery_way
  4975. }
  4976. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4977. execution_frequency, _ := json["execution_frequency"].(string)
  4978. project.ExecutionFrequency = execution_frequency
  4979. }
  4980. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4981. remark, _ := json["remark"].(string)
  4982. project.Remark = remark
  4983. }
  4984. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  4985. day, _ := json["number_days"].(string)
  4986. project.Day = day
  4987. }
  4988. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  4989. unit, _ := json["unit"].(string)
  4990. project.Unit = unit
  4991. }
  4992. return 0
  4993. }
  4994. func (c *HisApiController) GetHisOrderList() {
  4995. page, _ := c.GetInt64("page", -1)
  4996. limit, _ := c.GetInt64("limit", -1)
  4997. start_time := c.GetString("start_time")
  4998. end_time := c.GetString("end_time")
  4999. types, _ := c.GetInt64("type", 0)
  5000. keywords := c.GetString("keywords")
  5001. p_type, _ := c.GetInt64("p_type", 0)
  5002. sort_type, _ := c.GetInt64("sort_type", 0)
  5003. charge_type, _ := c.GetInt64("charge_type", 0)
  5004. timeLayout := "2006-01-02"
  5005. loc, _ := time.LoadLocation("Local")
  5006. var startTime int64
  5007. if len(start_time) > 0 {
  5008. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5009. if err != nil {
  5010. //fmt.Println(err)
  5011. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5012. return
  5013. }
  5014. startTime = theTime.Unix()
  5015. }
  5016. var endTime int64
  5017. if len(end_time) > 0 {
  5018. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5019. if err != nil {
  5020. utils.ErrorLog(err.Error())
  5021. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5022. return
  5023. }
  5024. endTime = theTime.Unix()
  5025. }
  5026. adminUser := c.GetAdminUserInfo()
  5027. org_id := adminUser.CurrentOrgId
  5028. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time, charge_type)
  5029. for _, item := range order {
  5030. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  5031. item.DoctorName = info.Doctor
  5032. item.DepartmentName = info.XtHisDepartment.Name
  5033. }
  5034. if err == nil {
  5035. c.ServeSuccessJSON(map[string]interface{}{
  5036. "order": order,
  5037. "total": total,
  5038. })
  5039. } else {
  5040. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5041. return
  5042. }
  5043. }
  5044. func (c *HisApiController) GetHisOrder() {
  5045. patient_id, _ := c.GetInt64("patient_id", 0)
  5046. number := c.GetString("number")
  5047. adminInfo := c.GetAdminUserInfo()
  5048. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  5049. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  5050. if err == nil {
  5051. c.ServeSuccessJSON(map[string]interface{}{
  5052. "order": order,
  5053. "prescription": prescriptions,
  5054. })
  5055. } else {
  5056. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5057. return
  5058. }
  5059. }
  5060. func (c *HisApiController) GetHisPrescriptionList() {
  5061. record_date := c.GetString("record_date")
  5062. keywords := c.GetString("keywords")
  5063. page, _ := c.GetInt64("page")
  5064. limit, _ := c.GetInt64("limit")
  5065. sch_type, _ := c.GetInt64("sch_type")
  5066. timeLayout := "2006-01-02"
  5067. loc, _ := time.LoadLocation("Local")
  5068. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5069. if err != nil {
  5070. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5071. return
  5072. }
  5073. recordDateTime := theTime.Unix()
  5074. adminInfo := c.GetAdminUserInfo()
  5075. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  5076. //adminInfo := c.GetAdminUserInfo()
  5077. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  5078. //fmt.Println(prescriptionOrder)
  5079. if err == nil {
  5080. c.ServeSuccessJSON(map[string]interface{}{
  5081. "order": prescriptionOrder,
  5082. "total": total,
  5083. })
  5084. } else {
  5085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5086. return
  5087. }
  5088. }
  5089. func (c *HisApiController) GetHisPrescriptionInfo() {
  5090. id, _ := c.GetInt64("id")
  5091. adminInfo := c.GetAdminUserInfo()
  5092. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  5093. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  5094. if err == nil {
  5095. c.ServeSuccessJSON(map[string]interface{}{
  5096. "order": prescriptionOrder,
  5097. "prescription": prescription,
  5098. })
  5099. } else {
  5100. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5101. return
  5102. }
  5103. }
  5104. func (c *HisApiController) GetMedicalInsuranceConfig() {
  5105. adminUser := c.GetAdminUserInfo()
  5106. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5107. c.ServeSuccessJSON(map[string]interface{}{
  5108. "config": config,
  5109. })
  5110. }
  5111. type ResultTwo struct {
  5112. ErrMsg interface{} `json:"err_msg"`
  5113. InfRefmsgid string `json:"inf_refmsgid"`
  5114. Infcode int64 `json:"infcode"`
  5115. Output struct {
  5116. Baseinfo struct {
  5117. Age float64 `json:"age"`
  5118. Brdy string `json:"brdy"`
  5119. Certno string `json:"certno"`
  5120. Gend string `json:"gend"`
  5121. Naty string `json:"naty"`
  5122. PsnCertType string `json:"psn_cert_type"`
  5123. PsnName string `json:"psn_name"`
  5124. PsnNo string `json:"psn_no"`
  5125. } `json:"baseinfo"`
  5126. Idetinfo []interface{} `json:"idetinfo"`
  5127. Iinfo []struct {
  5128. Balc float64 `json:"balc"`
  5129. CvlservFlag string `json:"cvlserv_flag"`
  5130. EmpName string `json:"emp_name"`
  5131. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  5132. Insutype string `json:"insutype"`
  5133. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  5134. PausInsuDate interface{} `json:"paus_insu_date"`
  5135. PsnInsuDate string `json:"psn_insu_date"`
  5136. PsnInsuStas string `json:"psn_insu_stas"`
  5137. PsnType string `json:"psn_type"`
  5138. } `json:"insuinfo"`
  5139. } `json:"output"`
  5140. RefmsgTime string `json:"refmsg_time"`
  5141. RespondTime string `json:"respond_time"`
  5142. Signtype interface{} `json:"signtype"`
  5143. WarnInfo interface{} `json:"warn_info"`
  5144. }
  5145. type ResultThree struct {
  5146. Cainfo interface{} `json:"cainfo"`
  5147. ErrMsg interface{} `json:"err_msg"`
  5148. InfRefmsgid string `json:"inf_refmsgid"`
  5149. Infcode int64 `json:"infcode"`
  5150. Output struct {
  5151. Data struct {
  5152. IptOtpNo string `json:"ipt_otp_no"`
  5153. MdtrtID string `json:"mdtrt_id"`
  5154. PsnNo string `json:"psn_no"`
  5155. } `json:"data"`
  5156. } `json:"output"`
  5157. RefmsgTime string `json:"refmsg_time"`
  5158. RespondTime string `json:"respond_time"`
  5159. Signtype interface{} `json:"signtype"`
  5160. WarnMsg interface{} `json:"warn_msg"`
  5161. }
  5162. type ResultFour struct {
  5163. Cainfo string `json:"cainfo"`
  5164. ErrMsg string `json:"err_msg"`
  5165. InfRefmsgid string `json:"inf_refmsgid"`
  5166. Infcode int64 `json:"infcode"`
  5167. Output struct {
  5168. Result []struct {
  5169. BasMednFlag string `json:"bas_medn_flag"`
  5170. ChldMedcFlag string `json:"chld_medc_flag"`
  5171. ChrgitmLv string `json:"chrgitm_lv"`
  5172. Cnt float64 `json:"cnt"`
  5173. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  5174. DrtReimFlag string `json:"drt_reim_flag"`
  5175. FeedetlSn string `json:"feedetl_sn"`
  5176. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5177. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  5178. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5179. ListSpItemFlag string `json:"list_sp_item_flag"`
  5180. LmtUsedFlag string `json:"lmt_used_flag"`
  5181. MedChrgitmType string `json:"med_chrgitm_type"`
  5182. Memo string `json:"memo"`
  5183. OverlmtAmt float64 `json:"overlmt_amt"`
  5184. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5185. Pric float64 `json:"pric"`
  5186. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  5187. SelfpayProp float64 `json:"selfpay_prop"`
  5188. } `json:"result"`
  5189. } `json:"output"`
  5190. RefmsgTime string `json:"refmsg_time"`
  5191. RespondTime string `json:"respond_time"`
  5192. Signtype string `json:"signtype"`
  5193. WarnMsg string `json:"warn_msg"`
  5194. }
  5195. type ResultFive struct {
  5196. Insutype string `json:"insutype"`
  5197. }
  5198. type ResultSix struct {
  5199. Cainfo interface{} `json:"cainfo"`
  5200. ErrMsg interface{} `json:"err_msg"`
  5201. InfRefmsgid string `json:"inf_refmsgid"`
  5202. Infcode int64 `json:"infcode"`
  5203. Output struct {
  5204. } `json:"output"`
  5205. RefmsgTime string `json:"refmsg_time"`
  5206. RespondTime string `json:"respond_time"`
  5207. Signtype interface{} `json:"signtype"`
  5208. WarnMsg interface{} `json:"warn_msg"`
  5209. }
  5210. type ResultSeven struct {
  5211. Cainfo string `json:"cainfo"`
  5212. ErrMsg string `json:"err_msg"`
  5213. InfRefmsgid string `json:"inf_refmsgid"`
  5214. Infcode int64 `json:"infcode"`
  5215. Output struct {
  5216. Setldetail []interface{} `json:"setldetail"`
  5217. Setlinfo struct {
  5218. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5219. AcctPay float64 `json:"acct_pay"`
  5220. ActPayDedc float64 `json:"act_pay_dedc"`
  5221. Age float64 `json:"age"`
  5222. Balc float64 `json:"balc"`
  5223. Brdy string `json:"brdy"`
  5224. Certno string `json:"certno"`
  5225. ClrOptins string `json:"clr_optins"`
  5226. ClrType string `json:"clr_type"`
  5227. ClrWay string `json:"clr_way"`
  5228. CvlservFlag string `json:"cvlserv_flag"`
  5229. CvlservPay float64 `json:"cvlserv_pay"`
  5230. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5231. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5232. Gend string `json:"gend"`
  5233. HifesPay float64 `json:"hifes_pay"`
  5234. HifmiPay float64 `json:"hifmi_pay"`
  5235. HifobPay float64 `json:"hifob_pay"`
  5236. HifpPay float64 `json:"hifp_pay"`
  5237. HospPartAmt float64 `json:"hosp_part_amt"`
  5238. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5239. Insutype string `json:"insutype"`
  5240. MafPay float64 `json:"maf_pay"`
  5241. MdtrtCertType string `json:"mdtrt_cert_type"`
  5242. MdtrtID string `json:"mdtrt_id"`
  5243. MedType string `json:"med_type"`
  5244. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5245. MedinsSetlID string `json:"medins_setl_id"`
  5246. Naty string `json:"naty"`
  5247. OthPay float64 `json:"oth_pay"`
  5248. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5249. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5250. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5251. PsnCashPay float64 `json:"psn_cash_pay"`
  5252. PsnCertType string `json:"psn_cert_type"`
  5253. PsnName string `json:"psn_name"`
  5254. PsnNo string `json:"psn_no"`
  5255. PsnPartAmt float64 `json:"psn_part_amt"`
  5256. PsnType string `json:"psn_type"`
  5257. SetlID string `json:"setl_id"`
  5258. SetlTime string `json:"setl_time"`
  5259. } `json:"setlinfo"`
  5260. } `json:"output"`
  5261. RefmsgTime string `json:"refmsg_time"`
  5262. RespondTime string `json:"respond_time"`
  5263. Signtype interface{} `json:"signtype"`
  5264. WarnMsg interface{} `json:"warn_msg"`
  5265. }
  5266. type ResultEight struct {
  5267. Cainfo string `json:"cainfo"`
  5268. ErrMsg string `json:"err_msg"`
  5269. InfRefmsgid string `json:"inf_refmsgid"`
  5270. Infcode int64 `json:"infcode"`
  5271. Output struct {
  5272. Stmtinfo struct {
  5273. SetlOptins string `json:"setl_optins"`
  5274. StmtRslt string `json:"stmt_rslt"`
  5275. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  5276. } `json:"stmtinfo"`
  5277. } `json:"output"`
  5278. RefmsgTime string `json:"refmsg_time"`
  5279. RespondTime string `json:"respond_time"`
  5280. Signtype interface{} `json:"signtype"`
  5281. WarnMsg interface{} `json:"warn_msg"`
  5282. }
  5283. type ResultNine struct {
  5284. Cainfo string `json:"cainfo"`
  5285. ErrMsg string `json:"err_msg"`
  5286. InfRefmsgid string `json:"inf_refmsgid"`
  5287. Infcode int64 `json:"infcode"`
  5288. Output struct {
  5289. FileQuryNo string `json:"file_qury_no"`
  5290. } `json:"output"`
  5291. RefmsgTime string `json:"refmsg_time"`
  5292. RespondTime string `json:"respond_time"`
  5293. Signtype interface{} `json:"signtype"`
  5294. WarnMsg interface{} `json:"warn_msg"`
  5295. }
  5296. type ResultTen struct {
  5297. Cainfo string `json:"cainfo"`
  5298. ErrMsg string `json:"err_msg"`
  5299. InfRefmsgid string `json:"inf_refmsgid"`
  5300. Infcode int64 `json:"infcode"`
  5301. Output struct {
  5302. DldEndtime string `json:"dld_endtime"`
  5303. FileQuryNo string `json:"file_qury_no"`
  5304. Filename string `json:"filename"`
  5305. } `json:"output"`
  5306. RefmsgTime string `json:"refmsg_time"`
  5307. RespondTime string `json:"respond_time"`
  5308. Signtype interface{} `json:"signtype"`
  5309. WarnMsg interface{} `json:"warn_msg"`
  5310. }
  5311. type ResultEleven struct {
  5312. Cainfo string `json:"cainfo"`
  5313. ErrMsg string `json:"err_msg"`
  5314. InfRefmsgid string `json:"inf_refmsgid"`
  5315. Infcode int64 `json:"infcode"`
  5316. Output struct {
  5317. Setlinfo struct {
  5318. FixmedinsName string `json:"fixmedins_name"`
  5319. FixmedinsCode string `json:"fixmedins_code"`
  5320. PsnNo string `json:"psn_no"`
  5321. PsnName string `json:"psn_name"`
  5322. HifobPay float64 `json:"hifob_pay"`
  5323. Gend string `json:"gend"`
  5324. Brdy string `json:"brdy"`
  5325. PsnCertType string `json:"psn_cert_type"`
  5326. PsnType string `json:"psn_type"`
  5327. EmpName string `json:"emp_name"`
  5328. Certno string `json:"certno"`
  5329. Insutype string `json:"insutype"`
  5330. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5331. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5332. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5333. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5334. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5335. ActPayDedc float64 `json:"act_pay_dedc"`
  5336. HifpPay float64 `json:"hifp_pay"`
  5337. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5338. CvlservPay float64 `json:"cvlserv_pay"`
  5339. HifesPay float64 `json:"hifes_pay"`
  5340. HifmiPay float64 `json:"hifmi_pay"`
  5341. MafPay float64 `json:"maf_pay"`
  5342. OthPay float64 `json:"oth_pay"`
  5343. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5344. PsnPay float64 `json:"psn_pay"`
  5345. AcctPay float64 `json:"acct_pay"`
  5346. CashPayamt float64 `json:"cash_payamt"`
  5347. Balc float64 `json:"balc"`
  5348. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5349. MedinsSetlId string `json:"medins_setl_id"`
  5350. RefdSetlFlag string `json:"refd_setl_flag"`
  5351. SetlTime string `json:"setl_time"`
  5352. MedType string `json:"med_type"`
  5353. } `json:"setlinfo"`
  5354. } `json:"output"`
  5355. RefmsgTime string `json:"refmsg_time"`
  5356. RespondTime string `json:"respond_time"`
  5357. Signtype interface{} `json:"signtype"`
  5358. WarnMsg interface{} `json:"warn_msg"`
  5359. }
  5360. type Custom struct {
  5361. DetItemFeeSumamt string
  5362. Cut string
  5363. FeedetlSn string
  5364. Price string
  5365. MedListCodg string
  5366. Type int64
  5367. AdviceId int64
  5368. ProjectId int64
  5369. ItemId int64
  5370. }
  5371. // 获取个人信息----挂号-----上传就诊信息
  5372. func (c *HisApiController) GetRegisterInfo() {
  5373. id, _ := c.GetInt64("id")
  5374. record_time := c.GetString("record_time")
  5375. settlementValue, _ := c.GetInt64("settlement_value")
  5376. medical_insurance_card := c.GetString("medical_insurance_card")
  5377. name := c.GetString("name")
  5378. id_card_type, _ := c.GetInt64("id_card_type")
  5379. certificates, _ := c.GetInt64("certificates")
  5380. medical_care, _ := c.GetInt64("medical_care")
  5381. birthday := c.GetString("birthday")
  5382. age, _ := c.GetInt64("age")
  5383. id_card := c.GetString("id_card")
  5384. register_type, _ := c.GetInt64("register")
  5385. doctor, _ := c.GetInt64("doctor")
  5386. department, _ := c.GetInt64("department")
  5387. gender, _ := c.GetInt64("sex")
  5388. phone := c.GetString("phone")
  5389. registration_fee, _ := c.GetFloat("registration_fee")
  5390. medical_expenses, _ := c.GetFloat("medical_expenses")
  5391. social_type, _ := c.GetInt64("social_type")
  5392. //diagnosis_id, _ := c.GetInt64("diagnosis")
  5393. diagnosis_ids := c.GetString("diagnosis")
  5394. sick_type, _ := c.GetInt64("sick_type")
  5395. reg_type := c.GetString("p_type")
  5396. timeLayout := "2006-01-02"
  5397. loc, _ := time.LoadLocation("Local")
  5398. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  5399. birthUnix := birthdays.Unix()
  5400. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5401. if err != nil {
  5402. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5403. return
  5404. }
  5405. recordDateTime := theTime.Unix()
  5406. adminInfo := c.GetAdminUserInfo()
  5407. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  5408. if tempPatient.ID == 0 {
  5409. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  5410. return
  5411. }
  5412. var patient service.Patients
  5413. if id == 0 {
  5414. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  5415. } else {
  5416. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  5417. }
  5418. if patient.ID == 0 {
  5419. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  5420. return
  5421. }
  5422. if len(patient.IdCardNo) == 0 {
  5423. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  5424. return
  5425. }
  5426. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5427. if len(his) >= 1 {
  5428. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  5429. if len(his) >= 1 && order.ID == 0 {
  5430. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  5431. return
  5432. }
  5433. }
  5434. timeStr := time.Now().Format("2006-01-02 15:04:05")
  5435. fmt.Println(timeStr)
  5436. timeArr := strings.Split(timeStr, " ")
  5437. fmt.Println(timeArr)
  5438. timeArrTwo := strings.Split(timeArr[0], "-")
  5439. timeArrThree := strings.Split(timeArr[1], ":")
  5440. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  5441. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5442. if len(lists) == 0 {
  5443. var hisPatient models.XtHisPatient
  5444. hisPatient = models.XtHisPatient{
  5445. Name: name,
  5446. Age: age,
  5447. Gender: gender,
  5448. Birthday: birthUnix,
  5449. Phone: phone,
  5450. MedicalTreatmentType: medical_care,
  5451. IdType: certificates,
  5452. IdCardNo: id_card,
  5453. BalanceAccountsType: settlementValue,
  5454. SocialType: social_type,
  5455. MedicalInsuranceNumber: medical_insurance_card,
  5456. RegisterType: register_type,
  5457. RegisterCost: registration_fee,
  5458. TreatmentCost: medical_expenses,
  5459. AdminUserId: adminInfo.AdminUser.Id,
  5460. UserOrgId: adminInfo.CurrentOrgId,
  5461. Status: 1,
  5462. RecordDate: recordDateTime,
  5463. IsReturn: 1,
  5464. PatientId: patient.ID,
  5465. Ctime: time.Now().Unix(),
  5466. Mtime: time.Now().Unix(),
  5467. Number: str,
  5468. IdCardType: id_card_type,
  5469. Departments: department,
  5470. Doctor: doctor,
  5471. PType: reg_type,
  5472. Diagnosis: diagnosis_ids,
  5473. SickType: sick_type,
  5474. }
  5475. service.CreateHisPatient(&hisPatient)
  5476. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  5477. c.ServeSuccessJSON(map[string]interface{}{
  5478. "his_info": hisPatient,
  5479. })
  5480. } else {
  5481. //chrgBchno := rand.Intn(1000000) + 10000
  5482. var hisPatient models.XtHisPatient
  5483. hisPatient = models.XtHisPatient{
  5484. Name: name,
  5485. Age: age,
  5486. Gender: gender,
  5487. Birthday: birthUnix,
  5488. Phone: phone,
  5489. MedicalTreatmentType: medical_care,
  5490. IdType: certificates,
  5491. IdCardNo: id_card,
  5492. BalanceAccountsType: settlementValue,
  5493. SocialType: social_type,
  5494. MedicalInsuranceNumber: medical_insurance_card,
  5495. RegisterType: register_type,
  5496. RegisterCost: registration_fee,
  5497. TreatmentCost: medical_expenses,
  5498. AdminUserId: adminInfo.AdminUser.Id,
  5499. UserOrgId: adminInfo.CurrentOrgId,
  5500. Status: 1,
  5501. RecordDate: recordDateTime,
  5502. IsReturn: 1,
  5503. PatientId: patient.ID,
  5504. Ctime: time.Now().Unix(),
  5505. Mtime: time.Now().Unix(),
  5506. Number: str,
  5507. IdCardType: id_card_type,
  5508. Departments: department,
  5509. Doctor: doctor,
  5510. PType: reg_type,
  5511. Diagnosis: diagnosis_ids,
  5512. SickType: sick_type,
  5513. }
  5514. service.CreateHisPatient(&hisPatient)
  5515. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  5516. c.ServeSuccessJSON(map[string]interface{}{
  5517. "his_info": hisPatient,
  5518. })
  5519. }
  5520. }
  5521. // 上传明细----结算
  5522. func (c *HisApiController) GetUploadInfo() {
  5523. id, _ := c.GetInt64("id")
  5524. record_time := c.GetString("record_time")
  5525. his_patient_id, _ := c.GetInt64("his_patient_id")
  5526. oth_desc := c.GetString("oth_desc")
  5527. pay_way, _ := c.GetInt64("pay_way")
  5528. pay_ways := c.GetString("pay_ways")
  5529. cash_pay := c.GetString("cash_pay")
  5530. band_card_pay := c.GetString("band_card_pay")
  5531. wechat_pay := c.GetString("wechat_pay")
  5532. ali_pay := c.GetString("ali_pay")
  5533. jifen_pay := c.GetString("jifen_pay")
  5534. pay_price, _ := c.GetFloat("pay_price")
  5535. pay_card_no := c.GetString("pay_card_no")
  5536. discount_price, _ := c.GetFloat("discount_price")
  5537. preferential_price, _ := c.GetFloat("preferential_price")
  5538. reality_price, _ := c.GetFloat("reality_price")
  5539. found_price, _ := c.GetFloat("found_price")
  5540. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  5541. private_price, _ := c.GetFloat("private_price")
  5542. timeLayout := "2006-01-02"
  5543. loc, _ := time.LoadLocation("Local")
  5544. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  5545. fapiao_code := c.GetString("fapiao_code")
  5546. fapiao_number := c.GetString("fapiao_number")
  5547. diagnosis_id := c.GetString("diagnosis")
  5548. sick_type, _ := c.GetInt64("sick_type")
  5549. reg_type, _ := c.GetInt64("p_type")
  5550. order_id, _ := c.GetInt64("order_id")
  5551. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  5552. tmp_decimal := c.GetString("tmp_decimal")
  5553. var decimal float64 //本次使用的押金
  5554. var errmsg error
  5555. tx := service.XTWriteDB().Begin() //开了事务
  5556. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  5557. defer func() {
  5558. if errmsg != nil {
  5559. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  5560. tx.Rollback()
  5561. } else {
  5562. tx.Commit()
  5563. }
  5564. }()
  5565. fmt.Println("dec_way", dec_way)
  5566. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  5567. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  5568. return
  5569. }
  5570. if len(tmp_decimal) > 0 {
  5571. if tmp_decimal[0] == 45 {
  5572. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  5573. return
  5574. }
  5575. }
  5576. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  5577. fmt.Println(errs)
  5578. //if errs != nil {
  5579. // c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金金额错误")
  5580. // return
  5581. //}
  5582. decimal = tt
  5583. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  5584. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  5585. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5586. if err != nil {
  5587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5588. return
  5589. }
  5590. recordDateTime := theTime.Unix()
  5591. adminUser := c.GetAdminUserInfo()
  5592. var prescriptions []*models.HisPrescription
  5593. var prescriptionsOne []*models.HisPrescription
  5594. var start_time int64
  5595. var end_time int64
  5596. ids_str := c.GetString("ids")
  5597. ids_arr := strings.Split(ids_str, ",")
  5598. if tempOrder.ID == 0 {
  5599. if settle_accounts_type == 1 { //日结
  5600. fmt.Println(reg_type)
  5601. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  5602. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  5603. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  5604. } else {
  5605. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5606. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5607. }
  5608. } else { //月结
  5609. start_time_str := c.GetString("start_time")
  5610. end_time_str := c.GetString("end_time")
  5611. timeLayout := "2006-01-02"
  5612. loc, _ := time.LoadLocation("Local")
  5613. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  5614. if err != nil {
  5615. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5616. return
  5617. }
  5618. recordStartTime := theStartTime.Unix()
  5619. start_time = recordStartTime
  5620. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  5621. if err != nil {
  5622. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5623. return
  5624. }
  5625. recordEndTime := theEndTime.Unix()
  5626. end_time = recordEndTime
  5627. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  5628. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5629. }
  5630. var goods []*models.DialysisBeforePrepareGoods
  5631. var newGoods []*models.NewDialysisBeforePrepareGoods
  5632. var oldGoods []*models.OldDialysisBeforePrepareGoods
  5633. var infos []*models.HisDoctorAdviceInfo
  5634. var infoList []*models.HisDoctorAdviceInfo
  5635. var hisAdvice []*models.HisDoctorAdviceInfo
  5636. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  5637. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  5638. //判断库存不足
  5639. //结算出库开关
  5640. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  5641. if settConfig.IsOpen == 1 {
  5642. //判断库存的地方
  5643. for _, info := range prescriptions {
  5644. if info.Type == 1 {
  5645. infos = append(infos, info.HisDoctorAdviceInfo...)
  5646. }
  5647. if info.Type == 2 {
  5648. for _, sumItem := range info.HisPrescriptionProject {
  5649. if sumItem.Type == 3 {
  5650. var good models.DialysisBeforePrepareGoods
  5651. var newGood models.NewDialysisBeforePrepareGoods
  5652. good.GoodId = sumItem.GoodInfo.ID
  5653. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5654. count, _ := strconv.Atoi(sumItem.Count)
  5655. good.Count = int64(count)
  5656. good.StorehouseId = houseConfig.StorehouseOutInfo
  5657. good.ProjectId = sumItem.ID
  5658. goods = append(goods, &good)
  5659. newGood.GoodId = sumItem.GoodInfo.ID
  5660. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5661. count2, _ := strconv.Atoi(sumItem.Count)
  5662. newGood.Count = int64(count2)
  5663. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5664. newGood.ProjectId = sumItem.ID
  5665. newGoods = append(newGoods, &newGood)
  5666. }
  5667. }
  5668. }
  5669. }
  5670. for _, info := range prescriptionsOne {
  5671. if info.Type == 1 {
  5672. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  5673. }
  5674. if info.Type == 2 {
  5675. for _, sumItem := range info.HisPrescriptionProject {
  5676. if sumItem.Type == 3 {
  5677. var newGood models.NewDialysisBeforePrepareGoods
  5678. newGood.GoodId = sumItem.GoodInfo.ID
  5679. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5680. count2, _ := strconv.Atoi(sumItem.Count)
  5681. newGood.Count = int64(count2)
  5682. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5683. newGood.ProjectId = sumItem.ID
  5684. newGoodOne = append(newGoodOne, &newGood)
  5685. }
  5686. }
  5687. }
  5688. }
  5689. //判断
  5690. for _, itemOne := range infos {
  5691. for _, itemTwo := range hisAdvice {
  5692. if itemOne.DrugId == itemTwo.DrugId {
  5693. itemTwo.Child = append(itemTwo.Child, itemOne)
  5694. }
  5695. }
  5696. }
  5697. for _, itemTwo := range hisAdvice {
  5698. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  5699. var sum_out_count int64
  5700. for _, itemThree := range itemTwo.Child {
  5701. var prescribing_number int64
  5702. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  5703. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5704. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5705. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5706. }
  5707. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5708. prescribing_number = parseIntPrescribingNumber
  5709. }
  5710. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5711. prescribing_number = parseIntPrescribingNumber
  5712. }
  5713. sum_out_count += prescribing_number
  5714. }
  5715. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  5716. fmt.Println("sum_out_count233232323232wo", sum_out_count)
  5717. fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
  5718. if sum_out_count > drugStockOut.FlushCount {
  5719. c.ServeSuccessJSON(map[string]interface{}{
  5720. "msg": "2",
  5721. "drug": medical,
  5722. })
  5723. return
  5724. }
  5725. }
  5726. fmt.Println("newGoods99999988882os", newGoods)
  5727. for _, itemOne := range newGoods {
  5728. for _, item := range newGoodOne {
  5729. if itemOne.GoodId == item.GoodId {
  5730. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  5731. }
  5732. }
  5733. }
  5734. for _, item := range newGoodOne {
  5735. var sum_out_count_one int64
  5736. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  5737. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  5738. sum_out_count_one += itemOne.Count
  5739. }
  5740. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5741. fmt.Println("sum_out_count_one", sum_out_count_one)
  5742. fmt.Println("list.FlushCount", list.FlushCount)
  5743. if sum_out_count_one > list.FlushCount {
  5744. c.ServeSuccessJSON(map[string]interface{}{
  5745. "msg": "3",
  5746. "good": good,
  5747. })
  5748. return
  5749. }
  5750. }
  5751. }
  5752. timestamp := time.Now().Unix()
  5753. tempTime := time.Unix(timestamp, 0)
  5754. timeFormat := tempTime.Format("20060102150405")
  5755. chrgBchno := rand.Intn(100000) + 10000
  5756. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  5757. strconv.FormatInt(his.PatientId, 10)
  5758. var ids []int64
  5759. for _, item := range prescriptions {
  5760. ids = append(ids, item.ID)
  5761. }
  5762. var total float64
  5763. for _, item := range prescriptions {
  5764. fmt.Println(item)
  5765. if item.Type == 1 { //药品
  5766. for _, subItem := range item.HisDoctorAdviceInfo {
  5767. total = total + (subItem.Price * subItem.PrescribingNumber)
  5768. }
  5769. }
  5770. if item.Type == 2 { //项目
  5771. for _, subItem := range item.HisPrescriptionProject {
  5772. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  5773. total = total + (subItem.Price * cnt)
  5774. }
  5775. }
  5776. for _, subItem := range item.HisAdditionalCharge {
  5777. total = total + (subItem.Price * float64(subItem.Count))
  5778. }
  5779. }
  5780. if reg_type == 1111 || reg_type == 1112 {
  5781. reg_type = 11
  5782. }
  5783. tm := time.Unix(time.Now().Unix(), 0)
  5784. allTotal := fmt.Sprintf("%.4f", total)
  5785. totals, _ := strconv.ParseFloat(allTotal, 64)
  5786. order := &models.HisOrder{
  5787. UserOrgId: adminUser.CurrentOrgId,
  5788. HisPatientId: his.ID,
  5789. PatientId: id,
  5790. SettleAccountsDate: recordDateTime,
  5791. Ctime: time.Now().Unix(),
  5792. Mtime: time.Now().Unix(),
  5793. Status: 1,
  5794. OrderStatus: 2,
  5795. MdtrtId: his.Number,
  5796. Number: chrg_bchno,
  5797. MedfeeSumamt: totals,
  5798. PayWay: pay_way,
  5799. PayWays: pay_ways,
  5800. PayPrice: pay_price,
  5801. MedType: strconv.Itoa(int(reg_type)),
  5802. PayCardNo: pay_card_no,
  5803. DiscountPrice: discount_price,
  5804. PreferentialPrice: preferential_price,
  5805. RealityPrice: reality_price,
  5806. FoundPrice: found_price,
  5807. MedicalInsurancePrice: medical_insurance_price,
  5808. PrivatePrice: private_price,
  5809. SettleEndTime: end_time,
  5810. SettleStartTime: start_time,
  5811. PsnPartAmt: totals,
  5812. PsnCashPay: totals,
  5813. SettleType: settle_accounts_type,
  5814. FaPiaoCode: fapiao_code,
  5815. FaPiaoNumber: fapiao_number,
  5816. Diagnosis: diagnosis_id,
  5817. PType: 2,
  5818. SetlTime: tm.Format("2006-01-02 15:04:05"),
  5819. Decimal: decimal,
  5820. OthDesc: oth_desc,
  5821. CashPay: cash_pay,
  5822. WechatPay: wechat_pay,
  5823. AliPay: ali_pay,
  5824. JifenPay: jifen_pay,
  5825. BandCardPay: band_card_pay,
  5826. }
  5827. err = service.CreateOrderTX(order, tx)
  5828. if err != nil {
  5829. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  5830. return
  5831. }
  5832. var customs []*Custom
  5833. for _, item := range prescriptions {
  5834. if item.Type == 1 { //药品a
  5835. for _, subItem := range item.HisDoctorAdviceInfo {
  5836. cus := &Custom{
  5837. AdviceId: subItem.ID,
  5838. ProjectId: 0,
  5839. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  5840. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  5841. FeedetlSn: subItem.FeedetlSn,
  5842. Price: fmt.Sprintf("%.4f", subItem.Price),
  5843. MedListCodg: subItem.MedListCodg,
  5844. Type: 1,
  5845. }
  5846. customs = append(customs, cus)
  5847. }
  5848. }
  5849. if item.Type == 2 { //项目
  5850. for _, subItem := range item.HisPrescriptionProject {
  5851. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  5852. cus := &Custom{
  5853. AdviceId: 0,
  5854. ProjectId: subItem.ID,
  5855. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  5856. Cut: fmt.Sprintf("%.4f", cnt),
  5857. FeedetlSn: subItem.FeedetlSn,
  5858. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  5859. MedListCodg: subItem.MedListCodg,
  5860. Type: 2,
  5861. }
  5862. customs = append(customs, cus)
  5863. }
  5864. }
  5865. for _, item := range item.HisAdditionalCharge {
  5866. cus := &Custom{
  5867. ItemId: item.ID,
  5868. AdviceId: 0,
  5869. ProjectId: 0,
  5870. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  5871. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  5872. FeedetlSn: item.FeedetlSn,
  5873. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  5874. MedListCodg: item.XtHisAddtionConfig.Code,
  5875. Type: 3,
  5876. }
  5877. customs = append(customs, cus)
  5878. }
  5879. }
  5880. for _, item := range customs {
  5881. var advice_id int64 = 0
  5882. var project_id int64 = 0
  5883. var item_id int64 = 0
  5884. var types int64 = 0
  5885. if item.Type == 1 {
  5886. advice_id = item.AdviceId
  5887. project_id = 0
  5888. item_id = 0
  5889. } else if item.Type == 2 {
  5890. advice_id = 0
  5891. item_id = 0
  5892. project_id = item.ProjectId
  5893. } else if item.Type == 3 {
  5894. advice_id = 0
  5895. item_id = item.ItemId
  5896. project_id = 0
  5897. }
  5898. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  5899. cut, _ := strconv.ParseFloat(item.Cut, 32)
  5900. pric, _ := strconv.ParseFloat(item.Price, 32)
  5901. info := &models.HisOrderInfo{
  5902. OrderNumber: order.Number,
  5903. UploadDate: time.Now().Unix(),
  5904. AdviceId: advice_id,
  5905. DetItemFeeSumamt: detItemFeeSumamt,
  5906. Cnt: cut,
  5907. Pric: pric,
  5908. PatientId: id,
  5909. Status: 1,
  5910. Mtime: time.Now().Unix(),
  5911. Ctime: time.Now().Unix(),
  5912. UserOrgId: adminUser.CurrentOrgId,
  5913. HisPatientId: his.ID,
  5914. OrderId: order.ID,
  5915. ProjectId: project_id,
  5916. Type: types,
  5917. ItemId: item_id,
  5918. }
  5919. service.CreateOrderInfoTX(info, tx)
  5920. }
  5921. his.Diagnosis = diagnosis_id
  5922. his.SickType = sick_type
  5923. his.RegisterType = reg_type
  5924. his.MedicalTreatmentType = reg_type
  5925. service.UpdataHisPateintTX(&his, tx)
  5926. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  5927. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  5928. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  5929. //判断是否使用了押金
  5930. if dec_way == "true" {
  5931. tmpstring := strconv.FormatInt(order.ID, 10)
  5932. //扣押金
  5933. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  5934. order.Decimal = decimal
  5935. service.UpDateOrderTwo(order)
  5936. if errmsg != nil {
  5937. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  5938. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  5939. return
  5940. }
  5941. }
  5942. if err == nil {
  5943. for _, info := range prescriptions {
  5944. if info.Type == 1 {
  5945. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  5946. }
  5947. if info.Type == 2 {
  5948. for _, sumItem := range info.HisPrescriptionProject {
  5949. if sumItem.Type == 3 {
  5950. var good models.DialysisBeforePrepareGoods
  5951. var newGood models.NewDialysisBeforePrepareGoods
  5952. var oldGood models.OldDialysisBeforePrepareGoods
  5953. good.GoodId = sumItem.GoodInfo.ID
  5954. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5955. count, _ := strconv.Atoi(sumItem.Count)
  5956. good.Count = int64(count)
  5957. good.StorehouseId = houseConfig.StorehouseOutInfo
  5958. good.ProjectId = sumItem.ID
  5959. good.PatientId = sumItem.PatientId
  5960. goods = append(goods, &good)
  5961. newGood.GoodId = sumItem.GoodInfo.ID
  5962. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5963. count2, _ := strconv.Atoi(sumItem.Count)
  5964. newGood.Count = int64(count2)
  5965. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5966. newGood.ProjectId = sumItem.ID
  5967. newGood.PatientId = sumItem.HisPatientId
  5968. newGoods = append(newGoods, &newGood)
  5969. oldGood.GoodId = sumItem.GoodInfo.ID
  5970. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5971. count3, _ := strconv.Atoi(sumItem.Count)
  5972. oldGood.Count = int64(count3)
  5973. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  5974. oldGood.ProjectId = sumItem.ID
  5975. oldGood.RecordDate = sumItem.RecordDate
  5976. oldGood.PatientId = sumItem.HisPatientId
  5977. oldGoods = append(oldGoods, &oldGood)
  5978. }
  5979. }
  5980. }
  5981. }
  5982. if settConfig.IsOpen == 1 {
  5983. for _, item := range infoList {
  5984. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  5985. if medical.IsUse == 2 {
  5986. //药品出库
  5987. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  5988. //查询默认仓库
  5989. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  5990. //查询默认仓库剩余多少库存
  5991. var sum_count int64
  5992. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  5993. for _, its := range stockInfo {
  5994. if its.MaxUnit == medical.MaxUnit {
  5995. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5996. }
  5997. sum_count += its.StockMaxNumber + its.StockMinNumber
  5998. }
  5999. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6000. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6001. }
  6002. }
  6003. orgId := c.GetAdminUserInfo().CurrentOrgId
  6004. if len(oldGoods) > 0 {
  6005. timeStr := time.Now().Format("2006-01-02")
  6006. timeArr := strings.Split(timeStr, "-")
  6007. total, _ := service.FindAllWarehouseOut(orgId)
  6008. total = total + 1
  6009. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6010. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6011. number = number + total
  6012. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6013. operation_time := time.Now().Unix()
  6014. creater := c.GetAdminUserInfo().AdminUser.Id
  6015. //查询默认出库仓库库存
  6016. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6017. recordDateStr := time.Now().Format("2006-01-02")
  6018. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6019. nowtime := recordDate.Unix()
  6020. warehouseOut := models.WarehouseOut{
  6021. WarehouseOutOrderNumber: warehousing_out_order,
  6022. OperationTime: operation_time,
  6023. OrgId: orgId,
  6024. Creater: creater,
  6025. Ctime: time.Now().Unix(),
  6026. Status: 1,
  6027. WarehouseOutTime: nowtime,
  6028. Type: 1,
  6029. StorehouseId: storeConfig.StorehouseOutInfo,
  6030. IsCheck: 1,
  6031. OrderId: order.ID,
  6032. IsSys: 5,
  6033. }
  6034. //查询是否生成出库单
  6035. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6036. if out.ID == 0 {
  6037. service.AddSigleWarehouseOut(&warehouseOut)
  6038. }
  6039. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6040. for _, item := range oldGoods {
  6041. dialyPrepareOne := models.DialysisBeforePrepare{
  6042. GoodTypeId: item.GoodTypeId,
  6043. GoodId: item.GoodId,
  6044. PatientId: his.PatientId,
  6045. RecordDate: item.RecordDate,
  6046. UserOrgId: adminUser.CurrentOrgId,
  6047. Count: item.Count,
  6048. Ctime: time.Now().Unix(),
  6049. Creater: adminUser.AdminUser.Id,
  6050. CommdityCode: item.CommdityCode,
  6051. Status: 1,
  6052. StorehouseId: houseConfig.StorehouseOutInfo,
  6053. }
  6054. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  6055. //非零用
  6056. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  6057. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6058. //查询剩余库存
  6059. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6060. var sum_count int64
  6061. for _, item := range goodList {
  6062. sum_count += item.StockCount
  6063. }
  6064. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6065. //耗材
  6066. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6067. }
  6068. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  6069. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6070. //查询剩余库存
  6071. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6072. var sum_count int64
  6073. for _, item := range goodList {
  6074. sum_count += item.StockCount
  6075. }
  6076. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6077. //耗材
  6078. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6079. }
  6080. }
  6081. }
  6082. }
  6083. c.ServeSuccessJSON(map[string]interface{}{
  6084. "msg": "结算成功",
  6085. })
  6086. }
  6087. } else {
  6088. if tempOrder.IsPre > 0 {
  6089. allTotal := fmt.Sprintf("%.2f", tempOrder.MedfeeSumamt)
  6090. totals, _ := strconv.ParseFloat(allTotal, 64)
  6091. tempOrder.OrderStatus = 2
  6092. tempOrder.PayWay = pay_way
  6093. tempOrder.PayPrice = pay_price
  6094. tempOrder.PayCardNo = pay_card_no
  6095. tempOrder.DiscountPrice = discount_price
  6096. tempOrder.PreferentialPrice = preferential_price
  6097. tempOrder.RealityPrice = reality_price
  6098. tempOrder.FoundPrice = found_price
  6099. tempOrder.MedicalInsurancePrice = medical_insurance_price
  6100. tempOrder.PrivatePrice = private_price
  6101. tempOrder.FaPiaoCode = fapiao_code
  6102. tempOrder.FaPiaoNumber = fapiao_number
  6103. tempOrder.PType = 2
  6104. tempOrder.MedfeeSumamt = totals
  6105. tempOrder.Diagnosis = diagnosis_id
  6106. err = service.SaveHisOrder(&tempOrder)
  6107. err = service.UpdataOrderStatusTwo(tempOrder.Number, adminUser.CurrentOrgId)
  6108. if err != nil {
  6109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6110. return
  6111. }
  6112. if err == nil {
  6113. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  6114. var goods []*models.DialysisBeforePrepareGoods
  6115. var newGoods []*models.NewDialysisBeforePrepareGoods
  6116. var infos []*models.HisDoctorAdviceInfo
  6117. var hisAdvice []*models.HisDoctorAdviceInfo
  6118. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  6119. var infolist []*models.HisDoctorAdviceInfo
  6120. var oldGoods []*models.OldDialysisBeforePrepareGoods
  6121. for _, info := range prescriptions {
  6122. if info.Type == 1 {
  6123. infos = append(infos, info.HisDoctorAdviceInfo...)
  6124. }
  6125. if info.Type == 2 {
  6126. for _, sumItem := range info.HisPrescriptionProject {
  6127. if sumItem.Type == 3 {
  6128. var good models.DialysisBeforePrepareGoods
  6129. var newGood models.NewDialysisBeforePrepareGoods
  6130. good.GoodId = sumItem.GoodInfo.ID
  6131. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6132. count, _ := strconv.Atoi(sumItem.Count)
  6133. good.Count = int64(count)
  6134. good.StorehouseId = houseConfig.StorehouseOutInfo
  6135. good.ProjectId = sumItem.ID
  6136. goods = append(goods, &good)
  6137. newGood.GoodId = sumItem.GoodInfo.ID
  6138. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6139. count2, _ := strconv.Atoi(sumItem.Count)
  6140. newGood.Count = int64(count2)
  6141. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6142. newGood.ProjectId = sumItem.ID
  6143. newGoods = append(newGoods, &newGood)
  6144. }
  6145. }
  6146. }
  6147. }
  6148. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6149. if settConfig.IsOpen == 1 {
  6150. //判断库存的地方
  6151. for _, info := range prescriptions {
  6152. if info.Type == 1 {
  6153. infolist = append(infolist, info.HisDoctorAdviceInfo...)
  6154. }
  6155. if info.Type == 2 {
  6156. for _, sumItem := range info.HisPrescriptionProject {
  6157. if sumItem.Type == 3 {
  6158. var good models.DialysisBeforePrepareGoods
  6159. var newGood models.NewDialysisBeforePrepareGoods
  6160. var oldGood models.OldDialysisBeforePrepareGoods
  6161. good.GoodId = sumItem.GoodInfo.ID
  6162. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6163. count, _ := strconv.Atoi(sumItem.Count)
  6164. good.Count = int64(count)
  6165. good.StorehouseId = houseConfig.StorehouseOutInfo
  6166. good.ProjectId = sumItem.ID
  6167. goods = append(goods, &good)
  6168. newGood.GoodId = sumItem.GoodInfo.ID
  6169. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6170. count2, _ := strconv.Atoi(sumItem.Count)
  6171. newGood.Count = int64(count2)
  6172. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6173. newGood.ProjectId = sumItem.ID
  6174. newGoods = append(newGoods, &newGood)
  6175. oldGood.GoodId = sumItem.GoodInfo.ID
  6176. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6177. count3, _ := strconv.Atoi(sumItem.Count)
  6178. oldGood.Count = int64(count3)
  6179. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  6180. oldGood.ProjectId = sumItem.ID
  6181. oldGood.RecordDate = sumItem.RecordDate
  6182. oldGoods = append(oldGoods, &oldGood)
  6183. }
  6184. }
  6185. }
  6186. }
  6187. for _, info := range prescriptionsOne {
  6188. if info.Type == 1 {
  6189. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  6190. }
  6191. if info.Type == 2 {
  6192. for _, sumItem := range info.HisPrescriptionProject {
  6193. if sumItem.Type == 3 {
  6194. var newGood models.NewDialysisBeforePrepareGoods
  6195. newGood.GoodId = sumItem.GoodInfo.ID
  6196. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6197. count2, _ := strconv.Atoi(sumItem.Count)
  6198. newGood.Count = int64(count2)
  6199. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6200. newGood.ProjectId = sumItem.ID
  6201. newGoodOne = append(newGoodOne, &newGood)
  6202. }
  6203. }
  6204. }
  6205. }
  6206. //判断
  6207. for _, itemOne := range infos {
  6208. for _, itemTwo := range hisAdvice {
  6209. if itemOne.DrugId == itemTwo.DrugId {
  6210. itemTwo.Child = append(itemTwo.ChildDoctorAdvice, itemOne)
  6211. }
  6212. }
  6213. }
  6214. for _, itemTwo := range hisAdvice {
  6215. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  6216. var sum_out_count int64
  6217. for _, itemThree := range itemTwo.Child {
  6218. var prescribing_number int64
  6219. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6220. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6221. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6222. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6223. }
  6224. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6225. prescribing_number = parseIntPrescribingNumber
  6226. }
  6227. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6228. prescribing_number = parseIntPrescribingNumber
  6229. }
  6230. sum_out_count += prescribing_number
  6231. }
  6232. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  6233. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  6234. if sum_out_count > drugStockOut.FlushCount {
  6235. c.ServeSuccessJSON(map[string]interface{}{
  6236. "msg": "2",
  6237. "drug": medical,
  6238. })
  6239. return
  6240. }
  6241. }
  6242. for _, itemOne := range newGoods {
  6243. for _, item := range newGoodOne {
  6244. if itemOne.ProjectId == item.ProjectId {
  6245. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, item)
  6246. }
  6247. }
  6248. }
  6249. for _, item := range newGoodOne {
  6250. var sum_out_count_one int64
  6251. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  6252. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  6253. sum_out_count_one += itemOne.Count
  6254. }
  6255. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6256. fmt.Println("sum_out_count_one", sum_out_count_one)
  6257. fmt.Println("list.FlushCount", list.FlushCount)
  6258. if sum_out_count_one > list.FlushCount {
  6259. c.ServeSuccessJSON(map[string]interface{}{
  6260. "msg": "3",
  6261. "good": good,
  6262. })
  6263. return
  6264. }
  6265. }
  6266. for _, item := range infolist {
  6267. service.HisDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item)
  6268. }
  6269. for _, item := range oldGoods {
  6270. dialyPrepareOne := models.DialysisBeforePrepare{
  6271. GoodTypeId: item.GoodTypeId,
  6272. GoodId: item.GoodId,
  6273. PatientId: item.PatientId,
  6274. RecordDate: item.RecordDate,
  6275. UserOrgId: item.UserOrgId,
  6276. Count: item.Count,
  6277. Ctime: time.Now().Unix(),
  6278. Creater: adminUser.AdminUser.Id,
  6279. CommdityCode: item.CommdityCode,
  6280. Status: 1,
  6281. StorehouseId: houseConfig.StorehouseOutInfo,
  6282. }
  6283. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  6284. }
  6285. service.ConsumablesDeliveryTotal(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, goods, newGoods, adminUser.AdminUser.Id)
  6286. }
  6287. c.ServeSuccessJSON(map[string]interface{}{
  6288. "msg": "结算成功",
  6289. })
  6290. }
  6291. }
  6292. }
  6293. }
  6294. // 退款
  6295. func (c *HisApiController) Refund() {
  6296. order_id, _ := c.GetInt64("order_id")
  6297. order, _ := service.GetHisOrderByID(order_id)
  6298. adminUser := c.GetAdminUserInfo()
  6299. orgid := c.GetAdminUserInfo().CurrentOrgId
  6300. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  6301. if err != nil {
  6302. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6303. return
  6304. }
  6305. tmp := strconv.FormatInt(order.ID, 10)
  6306. //当押金不为零时产生退费记录
  6307. if order.Decimal != 0 {
  6308. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  6309. if err != nil {
  6310. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6311. return
  6312. }
  6313. }
  6314. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  6315. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  6316. var goods []*models.DialysisBeforePrepareGoods
  6317. var newGoods []*models.NewDialysisBeforePrepareGoods
  6318. var infos []*models.HisDoctorAdviceInfo
  6319. for _, info := range orders {
  6320. if info.AdviceId > 0 && info.ProjectId == 0 {
  6321. infos = append(infos, &info.HisDoctorAdviceInfo)
  6322. }
  6323. if info.ProjectId > 0 && info.AdviceId == 0 {
  6324. if info.HisPrescriptionProject.Type == 3 {
  6325. var good models.DialysisBeforePrepareGoods
  6326. var newGood models.NewDialysisBeforePrepareGoods
  6327. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6328. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6329. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6330. good.Count = int64(count)
  6331. good.StorehouseId = houseConfig.StorehouseOutInfo
  6332. good.ProjectId = info.HisPrescriptionProject.ID
  6333. good.PatientId = info.PatientId
  6334. good.OrderId = order_id
  6335. goods = append(goods, &good)
  6336. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6337. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6338. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6339. newGood.Count = int64(count2)
  6340. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6341. newGood.ProjectId = info.HisPrescriptionProject.ID
  6342. newGood.RecordDate = order.SettleAccountsDate
  6343. newGood.UserOrgId = order.UserOrgId
  6344. newGood.PatientId = info.PatientId
  6345. newGood.OrderId = order_id
  6346. newGoods = append(newGoods, &newGood)
  6347. }
  6348. }
  6349. }
  6350. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6351. if settConfig.IsOpen == 1 {
  6352. for _, item := range infos {
  6353. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6354. }
  6355. for _, item := range newGoods {
  6356. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6357. }
  6358. }
  6359. c.ServeSuccessJSON(map[string]interface{}{
  6360. "msg": "退费成功",
  6361. })
  6362. }
  6363. func (c *HisApiController) RefundNumber() {
  6364. his_patient_id, _ := c.GetInt64("id")
  6365. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6366. info.Status = 0
  6367. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  6368. if count > 0 {
  6369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  6370. return
  6371. }
  6372. err := service.SaveHisPatient(info)
  6373. if err == nil {
  6374. c.ServeSuccessJSON(map[string]interface{}{
  6375. "msg": "退号成功",
  6376. })
  6377. } else {
  6378. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6379. return
  6380. }
  6381. }
  6382. func (this *HisApiController) AdditionalCharge() {
  6383. dataBody := make(map[string]interface{}, 0)
  6384. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6385. fmt.Println(err)
  6386. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  6387. patient_id := int64(dataBody["patient_id"].(float64))
  6388. medicineData, _ := dataBody["medicineData"].([]interface{})
  6389. adminUserInfo := this.GetAdminUserInfo()
  6390. orgId := adminUserInfo.CurrentOrgId
  6391. admin_user_id := adminUserInfo.AdminUser.Id
  6392. timeStr := time.Now().Format("2006-01-02")
  6393. timeLayout := "2006-01-02 15:04:05"
  6394. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  6395. timenow := timeStringToTime.Unix()
  6396. var additionalCharges []*models.HisAdditionalCharge
  6397. for _, item := range medicineData {
  6398. var randNum int
  6399. randNum = rand.Intn(10000) + 1000
  6400. timestamp := time.Now().Unix()
  6401. tempTime := time.Unix(timestamp, 0)
  6402. timeFormat := tempTime.Format("20060102150405")
  6403. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  6404. items := item.(map[string]interface{})
  6405. money := items["price"].(string)
  6406. item_id_str := items["item_id"].(string)
  6407. name := items["name"].(string)
  6408. id_str := items["id"].(string)
  6409. moneys, _ := strconv.ParseInt(money, 10, 64)
  6410. monStr := strconv.FormatInt(moneys, 10)
  6411. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  6412. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  6413. id, _ := strconv.ParseInt(id_str, 10, 64)
  6414. additionalCharge := &models.HisAdditionalCharge{
  6415. ID: id,
  6416. HisPatientId: his_patient_id,
  6417. UserOrgId: orgId,
  6418. PatientId: patient_id,
  6419. RecordDate: timenow,
  6420. Price: monneyStr,
  6421. Status: 1,
  6422. ItemName: name,
  6423. ItemId: item_id,
  6424. AdminUserId: admin_user_id,
  6425. CreatedTime: time.Now().Unix(),
  6426. OrderStatus: 0,
  6427. PrescriptionNumber: "",
  6428. BatchNumber: "",
  6429. FeedetlSn: p_number,
  6430. }
  6431. service.CreateAdditionalCharge(additionalCharge)
  6432. additionalCharges = append(additionalCharges, additionalCharge)
  6433. }
  6434. this.ServeSuccessJSON(map[string]interface{}{
  6435. "msg": "添加成功",
  6436. "additional_charges": additionalCharges,
  6437. })
  6438. }
  6439. func (this *HisApiController) DeleteAddition() {
  6440. id, _ := this.GetInt64("id")
  6441. //TODO 需要判断是否已经结算
  6442. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  6443. if err == nil {
  6444. this.ServeSuccessJSON(map[string]interface{}{
  6445. "msg": "删除成功",
  6446. })
  6447. return
  6448. } else {
  6449. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6450. return
  6451. }
  6452. }
  6453. func (this *HisApiController) GetAdminUsers() {
  6454. adminUser := this.GetAdminUserInfo()
  6455. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  6456. this.ServeSuccessJSON(map[string]interface{}{
  6457. "doctors": doctors,
  6458. })
  6459. }
  6460. func (this *HisApiController) GetLastOrNextHisPrescription() {
  6461. change_type, _ := this.GetInt64("type", 0)
  6462. record_date := this.GetString("record_time")
  6463. patient_id, _ := this.GetInt64("patient_id", 0)
  6464. p_type, _ := this.GetInt64("p_type", 0)
  6465. timeLayout := "2006-01-02"
  6466. loc, _ := time.LoadLocation("Local")
  6467. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6468. record_time := theAdviceRecordTime.Unix()
  6469. adminUserInfo := this.GetAdminUserInfo()
  6470. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  6471. if err == nil {
  6472. if len(prescriptions) == 0 {
  6473. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  6474. return
  6475. } else {
  6476. this.ServeSuccessJSON(map[string]interface{}{
  6477. "prescriptions": prescriptions,
  6478. })
  6479. return
  6480. }
  6481. } else {
  6482. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6483. return
  6484. }
  6485. }
  6486. func (this *HisApiController) GetCallHisPrescription() {
  6487. patient_id, _ := this.GetInt64("patient_id", 0)
  6488. timeLayout := "2006-01-02"
  6489. loc, _ := time.LoadLocation("Local")
  6490. start_time := this.GetString("start_time")
  6491. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6492. end_time := this.GetString("end_time")
  6493. p_type, _ := this.GetInt64("p_type")
  6494. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6495. adminUserInfo := this.GetAdminUserInfo()
  6496. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  6497. if err == nil {
  6498. this.ServeSuccessJSON(map[string]interface{}{
  6499. "prescriptions": prescriptions,
  6500. })
  6501. return
  6502. } else {
  6503. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6504. return
  6505. }
  6506. }
  6507. func (this *HisApiController) GetHisDayPrescription() {
  6508. timeLayout := "2006-01-02"
  6509. loc, _ := time.LoadLocation("Local")
  6510. start_time := this.GetString("start_time")
  6511. patient_id, _ := this.GetInt64("patient_id", 0)
  6512. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6513. end_time := this.GetString("end_time")
  6514. p_type, _ := this.GetInt64("p_type")
  6515. order_status, _ := this.GetInt64("type")
  6516. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6517. adminUserInfo := this.GetAdminUserInfo()
  6518. var dayHisPrescription []*models.HisPrescription
  6519. var err error
  6520. if order_status == 1 || order_status == 0 {
  6521. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6522. } else if order_status == 2 {
  6523. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6524. }
  6525. var settle_total float64
  6526. for _, item := range dayHisPrescription {
  6527. if len(item.HisPrescriptionProject) > 0 {
  6528. for _, subItem := range item.HisPrescriptionProject {
  6529. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6530. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6531. settle_total = settle_total + total
  6532. }
  6533. }
  6534. if len(item.HisDoctorAdviceInfo) > 0 {
  6535. for _, subItem := range item.HisDoctorAdviceInfo {
  6536. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6537. settle_total = settle_total + total
  6538. }
  6539. }
  6540. }
  6541. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6542. if err == nil {
  6543. this.ServeSuccessJSON(map[string]interface{}{
  6544. "day_prescription": dayHisPrescription,
  6545. "settle_total": settle_total,
  6546. })
  6547. return
  6548. } else {
  6549. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6550. return
  6551. }
  6552. }
  6553. func (c *HisApiController) GetHisChargePatientList() {
  6554. record_date := c.GetString("record_date")
  6555. order_status, _ := c.GetInt64("type")
  6556. timeLayout := "2006-01-02"
  6557. loc, _ := time.LoadLocation("Local")
  6558. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6559. if err != nil {
  6560. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6561. return
  6562. }
  6563. recordDateTime := theTime.Unix()
  6564. adminInfo := c.GetAdminUserInfo()
  6565. var tempPatients []*service.NewTempPatients
  6566. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6567. if order_status != 2 {
  6568. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6569. } else {
  6570. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6571. }
  6572. var patients []*service.NewTempPatients
  6573. var patients_two []*service.NewTempPatients
  6574. for _, item := range tempPatients {
  6575. //过滤掉没挂号的和没开处方的
  6576. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  6577. patients = append(patients, item)
  6578. }
  6579. //过滤掉没挂号的
  6580. if len(item.HisPatient) > 0 {
  6581. patients_two = append(patients_two, item)
  6582. }
  6583. }
  6584. c.ServeSuccessJSON(map[string]interface{}{
  6585. "list": patients,
  6586. "list_two": patients_two,
  6587. })
  6588. }
  6589. func (c *HisApiController) GetHisUnRegisterPatientList() {
  6590. record_date := c.GetString("record_date")
  6591. timeLayout := "2006-01-02"
  6592. loc, _ := time.LoadLocation("Local")
  6593. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6594. if err != nil {
  6595. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6596. return
  6597. }
  6598. recordDateTime := theTime.Unix()
  6599. adminUser := c.GetAdminUserInfo()
  6600. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  6601. var patients []*service.Patients
  6602. for _, item := range tempPatients {
  6603. if item.HisPatient.ID == 0 {
  6604. patients = append(patients, item)
  6605. }
  6606. }
  6607. c.ServeSuccessJSON(map[string]interface{}{
  6608. "list": patients,
  6609. //"list_two": patients_two,
  6610. })
  6611. }
  6612. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  6613. newArr = make([]*service.Patients, 0)
  6614. for i := 0; i < len(patient); i++ {
  6615. repeat := false
  6616. for j := i + 1; j < len(patient); j++ {
  6617. if patient[i].ID == patient[j].ID {
  6618. repeat = true
  6619. break
  6620. }
  6621. }
  6622. if !repeat {
  6623. newArr = append(newArr, patient[i])
  6624. }
  6625. }
  6626. return
  6627. }
  6628. func (c *HisApiController) GetHisChargePatientInfo() {
  6629. patient_id, _ := c.GetInt64("patient_id")
  6630. his_patient_id, _ := c.GetInt64("his_patient_id")
  6631. record_date := c.GetString("record_date")
  6632. //start_time := c.GetString("start_time")
  6633. //end_time := c.GetString("end_time")
  6634. order_status, _ := c.GetInt64("type", 0)
  6635. p_type, _ := c.GetInt64("p_type", 0)
  6636. order_id, _ := c.GetInt64("order_id", 0)
  6637. timeLayout := "2006-01-02"
  6638. loc, _ := time.LoadLocation("Local")
  6639. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6640. if err != nil {
  6641. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6642. return
  6643. }
  6644. recordDateTime := theTime.Unix()
  6645. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6646. //if err != nil {
  6647. //
  6648. //}
  6649. //startRecordDateTime := startTime.Unix()
  6650. //
  6651. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6652. //if err != nil {
  6653. //
  6654. //}
  6655. //endRecordDateTime := endTime.Unix()
  6656. admin := c.GetAdminUserInfo()
  6657. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6658. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6659. var prescriptions []*models.HisPrescription
  6660. //var unChargeMonthPrescriptions []*models.HisPrescription
  6661. order, _ := service.GetHisOrderByID(order_id)
  6662. if order_status == 1 || order_status == 0 {
  6663. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  6664. } else if order_status == 2 {
  6665. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  6666. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6667. }
  6668. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6669. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6670. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6671. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6672. //获取所有科室信息
  6673. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6674. c.ServeSuccessJSON(map[string]interface{}{
  6675. "his_info": his_patient_info,
  6676. "xt_info": xt_patient_info,
  6677. "prescription": prescriptions,
  6678. "case_history": case_history,
  6679. "info": patientPrescriptionInfo,
  6680. "last_info": lastPatientPrescriptionInfo,
  6681. "order": order,
  6682. "doctors": doctors,
  6683. "department": department,
  6684. })
  6685. return
  6686. }
  6687. func (c *HisApiController) GetAllOrderDetail() {
  6688. order_id, _ := c.GetInt64("id", 0)
  6689. order, _ := service.GetHisOrderByID(order_id)
  6690. if order.ID == 0 {
  6691. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6692. return
  6693. }
  6694. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6695. org_id := c.GetAdminUserInfo().CurrentOrgId
  6696. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6697. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  6698. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6699. c.ServeSuccessJSON(map[string]interface{}{
  6700. "order": order,
  6701. "order_info": order_info,
  6702. "patient": patient,
  6703. "admin_info": adminInfo,
  6704. "hospital_record": record,
  6705. })
  6706. return
  6707. }
  6708. func (c *HisApiController) GetAllOrderDetailCollect() {
  6709. order_id, _ := c.GetInt64("id", 0)
  6710. order, _ := service.GetHisOrderByID(order_id)
  6711. if order.ID == 0 {
  6712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6713. return
  6714. }
  6715. org_id := c.GetAdminUserInfo().CurrentOrgId
  6716. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6717. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6718. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  6719. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  6720. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  6721. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6722. var bedCostTotal float64 = 0 //床位总费
  6723. //var bedCostSelfTotal float64 = 0 //床位自费
  6724. var operationCostTotal float64 = 0 //手术费
  6725. //var operationCostSelfTotal float64 = 0 //手术费
  6726. var otherCostTotal float64 = 0 //其他费用
  6727. //var otherCostSelfTotal float64 = 0 //其他费用
  6728. var materialCostTotal float64 = 0 //材料费
  6729. //var materialCostSelfTotal float64 = 0 //材料费
  6730. var westernMedicineCostTotal float64 = 0 //西药费
  6731. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  6732. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  6733. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  6734. var checkCostTotal float64 = 0 //检查费
  6735. //var checkCostSelfTotal float64 = 0 //检查费
  6736. var laboratoryCostTotal float64 = 0 //化验费
  6737. //var laboratoryCostSelfTotal float64 = 0 //化验费
  6738. var treatCostTotal float64 = 0 //治疗费用
  6739. //var treatCostSelfTotal float64 = 0 //治疗费用
  6740. var zhenChaCostTotal float64 = 0 //其他费用
  6741. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  6742. decimal.DivisionPrecision = 2
  6743. var BalanceAccountsType int64
  6744. if his.ID > 0 {
  6745. BalanceAccountsType = his.BalanceAccountsType
  6746. } else {
  6747. BalanceAccountsType = record.BalanceAccountsType
  6748. }
  6749. if BalanceAccountsType != 2 {
  6750. for _, item := range order_info {
  6751. if org_id == 10215 {
  6752. if item.MedChrgitmType == "01" { //床位费
  6753. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6754. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6755. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6756. }
  6757. if item.MedChrgitmType == "02" { //诊察费
  6758. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6759. //zhenChaCostSelfTotal = zhenChaCostTotal
  6760. }
  6761. if item.MedChrgitmType == "03" { //检查费
  6762. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6763. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6764. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6765. }
  6766. //if item.MedChrgitmType == "02" { //检查费
  6767. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6768. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6769. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6770. //}
  6771. if item.MedChrgitmType == "04" { //化验费
  6772. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6773. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6774. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6775. }
  6776. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6777. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6778. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6779. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6780. }
  6781. if item.MedChrgitmType == "06" { //手术费
  6782. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6783. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6784. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6785. }
  6786. if item.MedChrgitmType == "08" { //材料费
  6787. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6788. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6789. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6790. }
  6791. if item.MedChrgitmType == "09" { //西药费
  6792. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6793. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6794. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6795. }
  6796. if item.MedChrgitmType == "11" { //中成费
  6797. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6798. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6799. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6800. }
  6801. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  6802. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6803. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6804. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6805. }
  6806. } else if org_id == 10188 || org_id == 10217 {
  6807. if item.MedChrgitmType == "01" { //床位费
  6808. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6809. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6810. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6811. }
  6812. if item.MedChrgitmType == "02" { //诊察费
  6813. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6814. //zhenChaCostSelfTotal = zhenChaCostTotal
  6815. }
  6816. if item.MedChrgitmType == "03" { //检查费
  6817. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6818. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6819. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6820. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6821. }
  6822. //if item.MedChrgitmType == "02" { //检查费
  6823. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6824. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6825. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6826. //}
  6827. if item.MedChrgitmType == "04" { //化验费
  6828. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6829. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6830. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6831. }
  6832. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6833. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6834. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6835. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6836. }
  6837. if item.MedChrgitmType == "06" { //手术费
  6838. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6839. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6840. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6841. }
  6842. if item.MedChrgitmType == "08" { //材料费
  6843. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6844. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6845. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6846. }
  6847. if item.MedChrgitmType == "09" { //西药费
  6848. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6849. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6850. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6851. }
  6852. if item.MedChrgitmType == "11" { //中成费
  6853. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6854. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6855. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6856. }
  6857. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  6858. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6859. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6860. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6861. }
  6862. } else {
  6863. if item.MedChrgitmType == "01" { //床位费
  6864. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6865. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6866. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6867. }
  6868. //if item.MedChrgitmType == "02" { //诊察费
  6869. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6870. // //zhenChaCostSelfTotal = zhenChaCostTotal
  6871. //}
  6872. if item.MedChrgitmType == "03" { //检查费
  6873. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6874. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6875. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6876. }
  6877. //if item.MedChrgitmType == "02" { //检查费
  6878. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6879. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6880. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6881. //}
  6882. if item.MedChrgitmType == "04" { //化验费
  6883. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6884. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6885. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6886. }
  6887. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6888. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6889. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6890. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6891. }
  6892. if item.MedChrgitmType == "06" { //手术费
  6893. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6894. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6895. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6896. }
  6897. if item.MedChrgitmType == "08" { //材料费
  6898. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6899. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6900. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6901. }
  6902. if item.MedChrgitmType == "09" { //西药费
  6903. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6904. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6905. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6906. }
  6907. if item.MedChrgitmType == "11" { //中成费
  6908. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6909. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6910. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6911. }
  6912. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  6913. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6914. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6915. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6916. }
  6917. }
  6918. }
  6919. c.ServeSuccessJSON(map[string]interface{}{
  6920. "order": order,
  6921. "order_info": order_info,
  6922. "patient": patient,
  6923. "admin_info": adminInfo,
  6924. "his_hospital": record,
  6925. "bedCostTotal": bedCostTotal,
  6926. "operationCostTotal": operationCostTotal,
  6927. "otherCostTotal": otherCostTotal,
  6928. "materialCostTotal": materialCostTotal,
  6929. "westernMedicineCostTotal": westernMedicineCostTotal,
  6930. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  6931. "checkCostTotal": checkCostTotal,
  6932. "zhenChaCostTotal": zhenChaCostTotal,
  6933. "laboratoryCostTotal": laboratoryCostTotal,
  6934. "treatCostTotal": treatCostTotal,
  6935. })
  6936. } else {
  6937. for _, item := range order_info {
  6938. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  6939. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  6940. item.MedChrgitmType = "09"
  6941. }
  6942. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  6943. if item.HisPrescriptionProject.Type == 2 {
  6944. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  6945. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  6946. case 0:
  6947. item.MedChrgitmType = "0"
  6948. break
  6949. case 1:
  6950. item.MedChrgitmType = "14"
  6951. break
  6952. case 2:
  6953. item.MedChrgitmType = "05"
  6954. break
  6955. case 3:
  6956. item.MedChrgitmType = "03"
  6957. break
  6958. case 4:
  6959. item.MedChrgitmType = "03"
  6960. break
  6961. case 5:
  6962. item.MedChrgitmType = "08"
  6963. break
  6964. case 6:
  6965. item.MedChrgitmType = "14"
  6966. break
  6967. case 7:
  6968. item.MedChrgitmType = "14"
  6969. break
  6970. case 8:
  6971. item.MedChrgitmType = "03"
  6972. break
  6973. case 9:
  6974. item.MedChrgitmType = "14"
  6975. break
  6976. case 10:
  6977. item.MedChrgitmType = "14"
  6978. break
  6979. case 11:
  6980. item.MedChrgitmType = "06"
  6981. break
  6982. case 12:
  6983. item.MedChrgitmType = "12"
  6984. break
  6985. case 13:
  6986. item.MedChrgitmType = "01"
  6987. break
  6988. case 14:
  6989. item.MedChrgitmType = "04"
  6990. break
  6991. case 15:
  6992. item.MedChrgitmType = "14"
  6993. break
  6994. }
  6995. } else {
  6996. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  6997. case 1:
  6998. item.MedChrgitmType = "14"
  6999. break
  7000. case 2:
  7001. item.MedChrgitmType = "05"
  7002. break
  7003. case 3:
  7004. item.MedChrgitmType = "04"
  7005. break
  7006. case 4:
  7007. item.MedChrgitmType = "14"
  7008. break
  7009. case 5:
  7010. item.MedChrgitmType = "08"
  7011. break
  7012. case 6:
  7013. item.MedChrgitmType = "14"
  7014. break
  7015. case 7:
  7016. item.MedChrgitmType = "14"
  7017. break
  7018. case 8:
  7019. item.MedChrgitmType = "03"
  7020. break
  7021. case 9:
  7022. item.MedChrgitmType = "14"
  7023. break
  7024. }
  7025. }
  7026. } else if item.HisPrescriptionProject.Type == 3 {
  7027. item.MedChrgitmType = "08"
  7028. }
  7029. }
  7030. }
  7031. for _, item := range order_info {
  7032. if org_id == 10215 {
  7033. if item.MedChrgitmType == "01" { //床位费
  7034. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7035. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7036. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7037. }
  7038. if item.MedChrgitmType == "02" { //诊察费
  7039. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7040. //zhenChaCostSelfTotal = zhenChaCostTotal
  7041. }
  7042. if item.MedChrgitmType == "03" { //检查费
  7043. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7044. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7045. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7046. }
  7047. //if item.MedChrgitmType == "02" { //检查费
  7048. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7049. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7050. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7051. //}
  7052. if item.MedChrgitmType == "04" { //化验费
  7053. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7054. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7055. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7056. }
  7057. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7058. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7059. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7060. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7061. }
  7062. if item.MedChrgitmType == "06" { //手术费
  7063. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7064. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7065. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7066. }
  7067. if item.MedChrgitmType == "08" { //材料费
  7068. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7069. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7070. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7071. }
  7072. if item.MedChrgitmType == "09" { //西药费
  7073. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7074. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7075. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7076. }
  7077. if item.MedChrgitmType == "11" { //中成费
  7078. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7079. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7080. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7081. }
  7082. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7083. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7084. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7085. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7086. }
  7087. } else {
  7088. if item.MedChrgitmType == "01" { //床位费
  7089. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7090. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7091. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7092. }
  7093. //if item.MedChrgitmType == "02" { //诊察费
  7094. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7095. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7096. //}
  7097. if item.MedChrgitmType == "03" { //检查费
  7098. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7099. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7100. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7101. }
  7102. //if item.MedChrgitmType == "02" { //检查费
  7103. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7104. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7105. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7106. //}
  7107. if item.MedChrgitmType == "04" { //化验费
  7108. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7109. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7110. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7111. }
  7112. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7113. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7114. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7115. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7116. }
  7117. if item.MedChrgitmType == "06" { //手术费
  7118. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7119. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7120. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7121. }
  7122. if item.MedChrgitmType == "08" { //材料费
  7123. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7124. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7125. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7126. }
  7127. if item.MedChrgitmType == "09" { //西药费
  7128. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7129. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7130. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7131. }
  7132. if item.MedChrgitmType == "11" { //中成费
  7133. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7134. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7135. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7136. }
  7137. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7138. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7139. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7140. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7141. }
  7142. }
  7143. }
  7144. c.ServeSuccessJSON(map[string]interface{}{
  7145. "order": order,
  7146. "order_info": order_info,
  7147. "patient": patient,
  7148. "admin_info": adminInfo,
  7149. "his_hospital": record,
  7150. "bedCostTotal": bedCostTotal,
  7151. "operationCostTotal": operationCostTotal,
  7152. "otherCostTotal": otherCostTotal,
  7153. "materialCostTotal": materialCostTotal,
  7154. "westernMedicineCostTotal": westernMedicineCostTotal,
  7155. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7156. "checkCostTotal": checkCostTotal,
  7157. "zhenChaCostTotal": zhenChaCostTotal,
  7158. "laboratoryCostTotal": laboratoryCostTotal,
  7159. "treatCostTotal": treatCostTotal,
  7160. })
  7161. }
  7162. }
  7163. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  7164. page, _ := c.GetInt64("page")
  7165. limit, _ := c.GetInt64("limit")
  7166. keywords := c.GetString("keywords")
  7167. start_time := c.GetString("start_time")
  7168. end_time := c.GetString("end_time")
  7169. //clr_type := c.GetString("clr_type")
  7170. insutype := c.GetString("insutype")
  7171. timeLayout := "2006-01-02"
  7172. loc, _ := time.LoadLocation("Local")
  7173. var theStartTIme int64
  7174. if len(start_time) > 0 {
  7175. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7176. theStartTIme = theTime.Unix()
  7177. }
  7178. var theEndtTIme int64
  7179. if len(end_time) > 0 {
  7180. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7181. theEndtTIme = theTime.Unix()
  7182. }
  7183. if page <= 0 {
  7184. page = 1
  7185. }
  7186. if limit <= 0 {
  7187. limit = 10
  7188. }
  7189. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  7190. c.ServeSuccessJSON(map[string]interface{}{
  7191. "total": total,
  7192. "list": list,
  7193. })
  7194. return
  7195. }
  7196. func (c *HisApiController) GetPutOnRecordList() {
  7197. page, _ := c.GetInt64("page")
  7198. limit, _ := c.GetInt64("limit")
  7199. keywords := c.GetString("keywords")
  7200. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  7201. if page <= 0 {
  7202. page = 1
  7203. }
  7204. if limit <= 0 {
  7205. limit = 10
  7206. }
  7207. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  7208. c.ServeSuccessJSON(map[string]interface{}{
  7209. "total": total,
  7210. "list": list,
  7211. })
  7212. return
  7213. }
  7214. func (c *HisApiController) GetCompareData() {
  7215. start_time := c.GetString("start_time")
  7216. end_time := c.GetString("end_time")
  7217. insutype := c.GetString("insutype")
  7218. clr_type := c.GetString("clr_type")
  7219. timeLayout := "2006-01-02"
  7220. loc, _ := time.LoadLocation("Local")
  7221. var theStartTIme int64
  7222. if len(start_time) > 0 {
  7223. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7224. if err != nil {
  7225. theStartTIme = 0
  7226. }
  7227. theStartTIme = theTime.Unix()
  7228. }
  7229. var theEndtTIme int64
  7230. if len(end_time) > 0 {
  7231. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7232. if err != nil {
  7233. theEndtTIme = 0
  7234. }
  7235. theEndtTIme = theTime.Unix()
  7236. }
  7237. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  7238. fmt.Println(err)
  7239. if err == nil {
  7240. c.ServeSuccessJSON(map[string]interface{}{
  7241. "list": formData,
  7242. })
  7243. } else {
  7244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7245. return
  7246. }
  7247. }
  7248. func (c *HisApiController) GetFaPiaoData() {
  7249. order_id, _ := c.GetInt64("order_id")
  7250. patient_id, _ := c.GetInt64("patient_id")
  7251. number := c.GetString("number")
  7252. adminUser := c.GetAdminUserInfo()
  7253. order, _ := service.GetHisOrderByID(order_id)
  7254. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  7255. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  7256. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  7257. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, number)
  7258. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7259. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  7260. var bedCostTotal float64 = 0 //床位总费
  7261. var bedCostSelfTotal float64 = 0 //床位自费
  7262. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  7263. var operationCostTotal float64 = 0 //手术费
  7264. var operationCostSelfTotal float64 = 0 //手术费
  7265. var operationCostPartSelfTotal float64 = 0 //手术费
  7266. var otherCostTotal float64 = 0 //其他费用
  7267. var otherCostSelfTotal float64 = 0 //其他费用
  7268. var otherCostPartSelfTotal float64 = 0 //其他费用
  7269. var materialCostTotal float64 = 0 //材料费
  7270. var materialCostSelfTotal float64 = 0 //材料费
  7271. var materialCostPartSelfTotal float64 = 0 //材料费
  7272. var westernMedicineCostTotal float64 = 0 //西药费
  7273. var westernMedicineCostSelfTotal float64 = 0 //西药费
  7274. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  7275. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7276. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7277. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  7278. var checkCostTotal float64 = 0 //检查费
  7279. var checkCostSelfTotal float64 = 0 //检查费
  7280. var checkCostPartSelfTotal float64 = 0 //检查费
  7281. var laboratoryCostTotal float64 = 0 //化验费
  7282. var laboratoryCostSelfTotal float64 = 0 //化验费
  7283. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  7284. var treatCostTotal float64 = 0 //治疗费用
  7285. var treatCostSelfTotal float64 = 0 //治疗费用
  7286. var treatCostPartSelfTotal float64 = 0 //治疗费用
  7287. var zhenChaCostTotal float64 = 0 //其他费用
  7288. var zhenChaCostSelfTotal float64 = 0 //其他费用
  7289. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7290. decimal.DivisionPrecision = 2
  7291. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7292. var balanceAccountsType int64
  7293. if his.ID > 0 {
  7294. balanceAccountsType = his.BalanceAccountsType
  7295. } else {
  7296. balanceAccountsType = his_hospital_record.BalanceAccountsType
  7297. }
  7298. if balanceAccountsType == 2 {
  7299. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7300. for _, item := range orderInfos_two {
  7301. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7302. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7303. item.MedChrgitmType = "09"
  7304. }
  7305. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7306. if item.HisPrescriptionProject.Type == 2 {
  7307. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7308. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7309. case 0:
  7310. item.MedChrgitmType = "0"
  7311. break
  7312. case 1:
  7313. item.MedChrgitmType = "14"
  7314. break
  7315. case 2:
  7316. item.MedChrgitmType = "05"
  7317. break
  7318. case 3:
  7319. item.MedChrgitmType = "03"
  7320. break
  7321. case 4:
  7322. item.MedChrgitmType = "03"
  7323. break
  7324. case 5:
  7325. item.MedChrgitmType = "08"
  7326. break
  7327. case 6:
  7328. item.MedChrgitmType = "14"
  7329. break
  7330. case 7:
  7331. item.MedChrgitmType = "14"
  7332. break
  7333. case 8:
  7334. item.MedChrgitmType = "03"
  7335. break
  7336. case 9:
  7337. item.MedChrgitmType = "14"
  7338. break
  7339. case 10:
  7340. item.MedChrgitmType = "14"
  7341. break
  7342. case 11:
  7343. item.MedChrgitmType = "06"
  7344. break
  7345. case 12:
  7346. item.MedChrgitmType = "12"
  7347. break
  7348. case 13:
  7349. item.MedChrgitmType = "01"
  7350. break
  7351. case 14:
  7352. item.MedChrgitmType = "04"
  7353. break
  7354. case 15:
  7355. item.MedChrgitmType = "02"
  7356. break
  7357. }
  7358. } else {
  7359. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7360. case 1:
  7361. item.MedChrgitmType = "14"
  7362. break
  7363. case 2:
  7364. item.MedChrgitmType = "05"
  7365. break
  7366. case 3:
  7367. item.MedChrgitmType = "03"
  7368. break
  7369. case 4:
  7370. item.MedChrgitmType = "03"
  7371. break
  7372. case 5:
  7373. item.MedChrgitmType = "08"
  7374. break
  7375. case 6:
  7376. item.MedChrgitmType = "14"
  7377. break
  7378. case 7:
  7379. item.MedChrgitmType = "14"
  7380. break
  7381. case 8:
  7382. item.MedChrgitmType = "03"
  7383. break
  7384. case 9:
  7385. item.MedChrgitmType = "14"
  7386. break
  7387. }
  7388. }
  7389. } else if item.HisPrescriptionProject.Type == 3 {
  7390. item.MedChrgitmType = "08"
  7391. }
  7392. }
  7393. }
  7394. for _, item := range orderInfos_two {
  7395. fmt.Println(item.MedChrgitmType)
  7396. if item.MedChrgitmType == "01" { //床位费
  7397. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7398. bedCostSelfTotal = bedCostTotal
  7399. }
  7400. if item.MedChrgitmType == "02" { //诊察费
  7401. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7402. zhenChaCostSelfTotal = zhenChaCostTotal
  7403. }
  7404. if item.MedChrgitmType == "03" { //检查费
  7405. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7406. checkCostSelfTotal = checkCostTotal
  7407. }
  7408. if item.MedChrgitmType == "04" { //化验费
  7409. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7410. laboratoryCostSelfTotal = laboratoryCostTotal
  7411. }
  7412. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  7413. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7414. treatCostSelfTotal = treatCostTotal
  7415. }
  7416. if item.MedChrgitmType == "06" { //手术费
  7417. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7418. operationCostSelfTotal = treatCostTotal
  7419. }
  7420. if item.MedChrgitmType == "08" { //材料费
  7421. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7422. materialCostSelfTotal = materialCostTotal
  7423. }
  7424. if item.MedChrgitmType == "09" { //西药费
  7425. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7426. westernMedicineCostSelfTotal = westernMedicineCostTotal
  7427. }
  7428. if item.MedChrgitmType == "11" { //中成费
  7429. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7430. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  7431. }
  7432. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  7433. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7434. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7435. otherCostSelfTotal = otherCostTotal
  7436. }
  7437. } else {
  7438. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7439. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7440. otherCostSelfTotal = otherCostTotal
  7441. }
  7442. }
  7443. }
  7444. } else {
  7445. for _, item := range orderInfos {
  7446. if item.MedChrgitmType == "01" { //床位费
  7447. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7448. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7449. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7450. }
  7451. if item.MedChrgitmType == "02" { //诊察费
  7452. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7453. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7454. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7455. }
  7456. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  7457. if item.MedChrgitmType == "03" { //检查费
  7458. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7459. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7460. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7461. }
  7462. } else {
  7463. if item.MedChrgitmType == "03" { //检查费
  7464. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7465. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7466. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7467. }
  7468. }
  7469. if item.MedChrgitmType == "04" { //化验费
  7470. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7471. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7472. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7473. }
  7474. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7475. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7476. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7477. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7478. }
  7479. if item.MedChrgitmType == "06" { //手术费
  7480. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7481. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7482. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7483. }
  7484. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  7485. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7486. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7487. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7488. }
  7489. if item.MedChrgitmType == "09" { //西药费
  7490. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7491. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7492. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7493. }
  7494. if item.MedChrgitmType == "11" { //中成费
  7495. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7496. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7497. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7498. }
  7499. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7500. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7501. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7502. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7503. }
  7504. }
  7505. }
  7506. timeLayout := "2006-01-02"
  7507. loc, _ := time.LoadLocation("Local")
  7508. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  7509. if err != nil {
  7510. }
  7511. startRecordDateTime := startTime.Unix()
  7512. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  7513. if err != nil {
  7514. }
  7515. endRecordDateTime := endTime.Unix()
  7516. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  7517. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  7518. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  7519. c.ServeSuccessJSON(map[string]interface{}{
  7520. "order_number": order.Number, //业务流水号
  7521. "id_card_no": his.IdCardNo, //社会保障号
  7522. "department_name": department.Name, //科室
  7523. "number": his.Number, //门诊号
  7524. "date": order.SettleAccountsDate, //结算日期
  7525. "name": order.PsnName, //姓名
  7526. "gender": patient.Gender, //性别
  7527. "psn_cash_money": order.PsnCashPay, //个人支付
  7528. "pay_way": "门诊", //结算方式
  7529. "medfee_sumamt": order.MedfeeSumamt, //总费用
  7530. "admin_user_name": admin.UserName, //收款员
  7531. "order": order,
  7532. "order_info": orderInfos_two,
  7533. "his": his,
  7534. "bedCostTotal": bedCostTotal,
  7535. "bedCostSelfTotal": bedCostSelfTotal,
  7536. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  7537. "operationCostTotal": operationCostTotal,
  7538. "operationCostSelfTotal": operationCostSelfTotal,
  7539. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  7540. "otherCostTotal": otherCostTotal,
  7541. "otherCostSelfTotal": otherCostSelfTotal,
  7542. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  7543. "materialCostTotal": materialCostTotal,
  7544. "materialCostSelfTotal": materialCostSelfTotal,
  7545. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  7546. "westernMedicineCostTotal": westernMedicineCostTotal,
  7547. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  7548. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  7549. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7550. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  7551. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  7552. "checkCostTotal": checkCostTotal,
  7553. "checkCostSelfTotal": checkCostSelfTotal,
  7554. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  7555. "laboratoryCostTotal": laboratoryCostTotal,
  7556. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  7557. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  7558. "treatCostTotal": treatCostTotal,
  7559. "treatCostSelfTotal": treatCostSelfTotal,
  7560. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  7561. "zhenChaCostTotal": zhenChaCostTotal,
  7562. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  7563. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  7564. "his_hospital_record": his_hospital_record,
  7565. "pre_pay_money": pre_pay_money,
  7566. "refund_sum": sum,
  7567. })
  7568. }
  7569. func (this *HisApiController) GetIncomeStatisticsData() {
  7570. start_time := this.GetString("start_time")
  7571. end_time := this.GetString("end_time")
  7572. key_words := this.GetString("key_words")
  7573. limit, _ := this.GetInt64("limit")
  7574. page, _ := this.GetInt64("page")
  7575. if page <= 0 {
  7576. page = 1
  7577. }
  7578. if limit <= 0 {
  7579. limit = 10
  7580. }
  7581. statistics_type, _ := this.GetInt64("statistics_type")
  7582. admin := this.GetAdminUserInfo()
  7583. timeLayout := "2006-01-02"
  7584. loc, _ := time.LoadLocation("Local")
  7585. var theStartTIme int64
  7586. if len(start_time) > 0 {
  7587. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7588. if err != nil {
  7589. theStartTIme = 0
  7590. }
  7591. theStartTIme = theTime.Unix()
  7592. }
  7593. var theEndtTIme int64
  7594. if len(end_time) > 0 {
  7595. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7596. if err != nil {
  7597. theEndtTIme = 0
  7598. }
  7599. theEndtTIme = theTime.Unix()
  7600. }
  7601. if statistics_type == 1 {
  7602. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  7603. this.ServeSuccessJSON(map[string]interface{}{
  7604. "list": list,
  7605. "total": total,
  7606. })
  7607. } else {
  7608. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  7609. this.ServeSuccessJSON(map[string]interface{}{
  7610. "list": list,
  7611. "total": total,
  7612. })
  7613. }
  7614. }
  7615. func (c *HisApiController) PostProjectInformation() {
  7616. adminUser := c.GetAdminUserInfo()
  7617. orgId := adminUser.CurrentOrgId
  7618. dataBody := make(map[string]interface{}, 0)
  7619. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7620. if err != nil {
  7621. utils.ErrorLog(err.Error())
  7622. return
  7623. }
  7624. utils.ErrorLog("%v", dataBody)
  7625. var projectList []*models.HisProject
  7626. var total_goods []interface{}
  7627. tempProjects := dataBody["projects"].([]interface{})
  7628. total_goods = tempProjects
  7629. for index, projectMap := range tempProjects {
  7630. projectM := projectMap.(map[string]interface{})
  7631. var project models.HisProject
  7632. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  7633. utils.ErrorLog("project_name")
  7634. return
  7635. }
  7636. project_name, _ := projectM["project_name"].(string)
  7637. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  7638. err_log := models.ExportErrLog{
  7639. LogType: 6,
  7640. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7641. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  7642. Status: 1,
  7643. CreateTime: time.Now().Unix(),
  7644. UpdateTime: time.Now().Unix(),
  7645. ExportTime: time.Now().Unix(),
  7646. }
  7647. service.CreateExportErrLog(&err_log)
  7648. continue
  7649. }
  7650. project.ProjectName = project_name
  7651. prices := projectM["price"].(string)
  7652. price, _ := strconv.ParseFloat(prices, 64)
  7653. if price <= 0 { //名字为空则生成一条导入错误日志
  7654. err_log := models.ExportErrLog{
  7655. LogType: 6,
  7656. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7657. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  7658. Status: 1,
  7659. CreateTime: time.Now().Unix(),
  7660. UpdateTime: time.Now().Unix(),
  7661. ExportTime: time.Now().Unix(),
  7662. }
  7663. service.CreateExportErrLog(&err_log)
  7664. continue
  7665. }
  7666. project.Price = price
  7667. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  7668. utils.ErrorLog("unit_id")
  7669. return
  7670. }
  7671. unit := projectM["unit"].(string)
  7672. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  7673. err_log := models.ExportErrLog{
  7674. LogType: 6,
  7675. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7676. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  7677. Status: 1,
  7678. CreateTime: time.Now().Unix(),
  7679. UpdateTime: time.Now().Unix(),
  7680. ExportTime: time.Now().Unix(),
  7681. }
  7682. service.CreateExportErrLog(&err_log)
  7683. continue
  7684. }
  7685. project.Unit = unit
  7686. cost_classify := projectM["cost_classify"].(string)
  7687. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  7688. err_log := models.ExportErrLog{
  7689. LogType: 6,
  7690. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7691. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  7692. Status: 1,
  7693. CreateTime: time.Now().Unix(),
  7694. UpdateTime: time.Now().Unix(),
  7695. ExportTime: time.Now().Unix(),
  7696. }
  7697. service.CreateExportErrLog(&err_log)
  7698. continue
  7699. }
  7700. var costClassify = "费用类别"
  7701. var cost_classify_id int64
  7702. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  7703. if len(cost_classify) != 0 {
  7704. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  7705. if errcode == gorm.ErrRecordNotFound {
  7706. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  7707. dataconfig := models.DictDataconfig{
  7708. ParentId: costClassifyConfig.ID,
  7709. Module: "system",
  7710. OrgId: orgId,
  7711. Name: cost_classify,
  7712. FieldName: "",
  7713. Value: costConfig.Value + 1,
  7714. CreatedTime: "",
  7715. UpdatedTime: "",
  7716. CreateUserId: adminUser.AdminUser.Id,
  7717. Status: 1,
  7718. Remark: "",
  7719. DeleteIdSystem: 0,
  7720. Title: "",
  7721. Content: "",
  7722. Order: 0,
  7723. Code: "",
  7724. }
  7725. service.CreatedDicConfig(&dataconfig)
  7726. }
  7727. }
  7728. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  7729. for _, it := range costClassList {
  7730. if cost_classify == it.Name {
  7731. cost_classify_id = int64(it.Value)
  7732. }
  7733. }
  7734. project.CostClassify = cost_classify_id
  7735. executive_section := projectM["executive_section"].(string)
  7736. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  7737. err_log := models.ExportErrLog{
  7738. LogType: 6,
  7739. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7740. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  7741. Status: 1,
  7742. CreateTime: time.Now().Unix(),
  7743. UpdateTime: time.Now().Unix(),
  7744. ExportTime: time.Now().Unix(),
  7745. }
  7746. service.CreateExportErrLog(&err_log)
  7747. continue
  7748. }
  7749. if len(executive_section) != 0 {
  7750. //查找科室是否有内容
  7751. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  7752. if errcodedepart == gorm.ErrRecordNotFound {
  7753. department := models.XtHisDepartment{
  7754. Name: executive_section,
  7755. Status: 1,
  7756. UserOrgId: adminUser.CurrentOrgId,
  7757. CreatedTime: time.Now().Unix(),
  7758. }
  7759. service.CreateDePartment(&department)
  7760. }
  7761. }
  7762. var executive_section_id int64
  7763. departMentList, _ := service.GetAllDepartMent(orgId)
  7764. for _, it := range departMentList {
  7765. if executive_section == it.Name {
  7766. executive_section_id = it.ID
  7767. }
  7768. }
  7769. project.ExecutiveSection = executive_section_id
  7770. medical_coverage := projectM["medical_coverage"].(string)
  7771. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  7772. err_log := models.ExportErrLog{
  7773. LogType: 6,
  7774. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7775. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  7776. Status: 1,
  7777. CreateTime: time.Now().Unix(),
  7778. UpdateTime: time.Now().Unix(),
  7779. ExportTime: time.Now().Unix(),
  7780. }
  7781. service.CreateExportErrLog(&err_log)
  7782. continue
  7783. }
  7784. var medicalCoverage = "医保等级"
  7785. var medical_coverage_id int64
  7786. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  7787. if len(medical_coverage) != 0 {
  7788. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  7789. if errormedicalcoverage == gorm.ErrRecordNotFound {
  7790. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  7791. dataconfig := models.DictDataconfig{
  7792. ParentId: medicalCoverageConfig.ID,
  7793. Module: "system",
  7794. OrgId: orgId,
  7795. Name: medical_coverage,
  7796. FieldName: "",
  7797. Value: medicalCoverageConfig.Value + 1,
  7798. CreatedTime: "",
  7799. UpdatedTime: "",
  7800. CreateUserId: adminUser.AdminUser.Id,
  7801. Status: 1,
  7802. Remark: "",
  7803. DeleteIdSystem: 0,
  7804. Title: "",
  7805. Content: "",
  7806. Order: 0,
  7807. Code: "",
  7808. }
  7809. service.CreatedDicConfig(&dataconfig)
  7810. }
  7811. }
  7812. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  7813. for _, it := range medicalCoverageList {
  7814. if medical_coverage == it.Name {
  7815. medical_coverage_id = int64(it.Value)
  7816. }
  7817. }
  7818. project.MedicalCoverage = medical_coverage_id
  7819. pinyin := projectM["pinyin"].(string)
  7820. project.Pinyin = pinyin
  7821. wubi := projectM["wubi"].(string)
  7822. project.Wubi = wubi
  7823. statistical_classification := projectM["statistical_classification"].(string)
  7824. var statisticalClassification = "统计分类"
  7825. var statistical_classification_id int64
  7826. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  7827. if len(statistical_classification) != 0 {
  7828. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  7829. if classificationerrcodes == gorm.ErrRecordNotFound {
  7830. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  7831. dataconfig := models.DictDataconfig{
  7832. ParentId: classiFication.ID,
  7833. Module: "system",
  7834. OrgId: orgId,
  7835. Name: statistical_classification,
  7836. FieldName: "",
  7837. Value: classiFicationConfig.Value + 1,
  7838. CreatedTime: "",
  7839. UpdatedTime: "",
  7840. CreateUserId: adminUser.AdminUser.Id,
  7841. Status: 1,
  7842. Remark: "",
  7843. DeleteIdSystem: 0,
  7844. Title: "",
  7845. Content: "",
  7846. Order: 0,
  7847. Code: "",
  7848. }
  7849. service.CreatedDicConfig(&dataconfig)
  7850. }
  7851. }
  7852. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  7853. for _, it := range classiFicationList {
  7854. if statistical_classification == it.Name {
  7855. statistical_classification_id = int64(it.Value)
  7856. }
  7857. }
  7858. project.StatisticalClassification = statistical_classification_id
  7859. disease_directory := int64(projectM["disease_directory"].(float64))
  7860. project.DiseaseDirectory = disease_directory
  7861. is_record := int64(projectM["is_record"].(float64))
  7862. project.IsRecord = is_record
  7863. medical_code := projectM["medical_code"].(string)
  7864. project.MedicalCode = medical_code
  7865. tube_color := projectM["tube_color"].(string)
  7866. var tubeColor = "试管颜色"
  7867. var tube_color_id int64
  7868. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  7869. if len(tube_color) != 0 {
  7870. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  7871. if errcodetube == gorm.ErrRecordNotFound {
  7872. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  7873. dataconfig := models.DictDataconfig{
  7874. ParentId: tubeColorConfig.ID,
  7875. Module: "system",
  7876. OrgId: orgId,
  7877. Name: tube_color,
  7878. FieldName: "",
  7879. Value: tubeConfig.Value + 1,
  7880. CreatedTime: "",
  7881. UpdatedTime: "",
  7882. CreateUserId: adminUser.AdminUser.Id,
  7883. Status: 1,
  7884. Remark: "",
  7885. DeleteIdSystem: 0,
  7886. Title: "",
  7887. Content: "",
  7888. Order: 0,
  7889. Code: "",
  7890. }
  7891. service.CreatedDicConfig(&dataconfig)
  7892. }
  7893. }
  7894. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  7895. for _, it := range tubeColorList {
  7896. if tube_color == it.Name {
  7897. tube_color_id = int64(it.Value)
  7898. }
  7899. }
  7900. project.TubeColor = tube_color_id
  7901. single_dose := projectM["single_dose"].(string)
  7902. project.SingleDose = single_dose
  7903. execution_frequency := projectM["execution_frequency"].(string)
  7904. project.ExecutionFrequency = execution_frequency
  7905. delivery_way := projectM["delivery_way"].(string)
  7906. project.DeliveryWay = delivery_way
  7907. number_days := projectM["number_days"].(string)
  7908. project.NumberDays = number_days
  7909. total := projectM["total"].(string)
  7910. project.Total = total
  7911. medical_status := int64(projectM["medical_status"].(float64))
  7912. project.MedicalStatus = medical_status
  7913. category := int64(projectM["category"].(float64))
  7914. project.Category = category
  7915. specail_project := int64(projectM["specail_project"].(float64))
  7916. project.SpecailProject = specail_project
  7917. social_security_directory_code := projectM["social_security_directory_code"].(string)
  7918. project.SocialSecurityDirectoryCode = social_security_directory_code
  7919. remark := projectM["remark"].(string)
  7920. project.Remark = remark
  7921. record_date := projectM["record_date"].(string)
  7922. timeLayout := "2006-01-02"
  7923. loc, _ := time.LoadLocation("Local")
  7924. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7925. project.RecordDate = theTime.Unix()
  7926. projectList = append(projectList, &project)
  7927. }
  7928. export_time := time.Now().Unix()
  7929. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  7930. if len(projectList) > 0 {
  7931. for _, item := range projectList {
  7932. project := models.HisProject{
  7933. ProjectName: item.ProjectName,
  7934. Price: item.Price,
  7935. Unit: item.Unit,
  7936. CostClassify: item.CostClassify,
  7937. ExecutiveSection: item.ExecutiveSection,
  7938. MedicalCoverage: item.MedicalCoverage,
  7939. UserOrgId: orgId,
  7940. Status: 1,
  7941. CreatedTime: time.Now().Unix(),
  7942. Pinyin: item.Pinyin,
  7943. Wubi: item.Wubi,
  7944. StatisticalClassification: item.StatisticalClassification,
  7945. DiseaseDirectory: item.DiseaseDirectory,
  7946. IsRecord: item.IsRecord,
  7947. MedicalCode: item.MedicalCode,
  7948. TubeColor: item.TubeColor,
  7949. SingleDose: item.SingleDose,
  7950. DeliveryWay: item.DeliveryWay,
  7951. NumberDays: item.NumberDays,
  7952. Total: item.Total,
  7953. Category: item.Category,
  7954. MedicalStatus: item.MedicalStatus,
  7955. SpecailProject: item.SpecailProject,
  7956. RecordDate: item.RecordDate,
  7957. Remark: item.Remark,
  7958. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  7959. ExecutionFrequency: item.ExecutionFrequency,
  7960. }
  7961. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  7962. if errcodeproject == gorm.ErrRecordNotFound {
  7963. service.CreateProjectInfomation(&project)
  7964. } else if errcodeproject == nil {
  7965. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  7966. }
  7967. log := models.ExportLog{
  7968. LogType: 6,
  7969. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7970. TotalNum: int64(len(total_goods)),
  7971. FailNum: int64(len(errLogs)),
  7972. SuccessNum: int64(len(projectList)),
  7973. CreateTime: time.Now().Unix(),
  7974. UpdateTime: time.Now().Unix(),
  7975. ExportTime: export_time,
  7976. Status: 1,
  7977. }
  7978. service.CreateExportLog(&log)
  7979. c.ServeSuccessJSON(map[string]interface{}{
  7980. "msg": "导入成功",
  7981. "total_num": len(total_goods),
  7982. "success_num": len(projectList),
  7983. "fail_num": int64(len(errLogs)),
  7984. })
  7985. }
  7986. } else {
  7987. log := models.ExportLog{
  7988. LogType: 6,
  7989. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7990. TotalNum: int64(len(total_goods)),
  7991. FailNum: int64(len(errLogs)),
  7992. SuccessNum: int64(len(projectList)),
  7993. CreateTime: time.Now().Unix(),
  7994. UpdateTime: time.Now().Unix(),
  7995. ExportTime: export_time,
  7996. Status: 1,
  7997. }
  7998. service.CreateExportLog(&log)
  7999. c.ServeSuccessJSON(map[string]interface{}{
  8000. "msg": "导入成功",
  8001. "total_num": len(total_goods),
  8002. "success_num": len(projectList),
  8003. "fail_num": int64(len(errLogs)),
  8004. })
  8005. }
  8006. }
  8007. //func (this *HisApiController) EditProjectInformation(){
  8008. //
  8009. // id, _ := this.GetInt64("id")
  8010. // project_team := this.GetString("project_team")
  8011. // price := this.GetString("price")
  8012. // price_float, _ := strconv.ParseFloat(price, 64)
  8013. // pinyin := this.GetString("pinyin")
  8014. // wubi := this.GetString("wubi")
  8015. // tube_color, _ := this.GetInt64("tube_color")
  8016. // team_type, _ := this.GetInt64("team_type")
  8017. // remark := this.GetString("remark")
  8018. // ids := this.GetString("ids")
  8019. // item_id := this.GetString("item_id")
  8020. // projectTeam := models.XtHisProjectTeam{
  8021. // ProjectTeam: project_team,
  8022. // Price: price_float,
  8023. // Pinyin: pinyin,
  8024. // Wubi: wubi,
  8025. // TubeColor: tube_color,
  8026. // TeamType: team_type,
  8027. // Remark: remark,
  8028. // ProjectId: ids,
  8029. // ItemId: item_id,
  8030. // }
  8031. //
  8032. //
  8033. // dataBody := make(map[string]interface{}, 0)
  8034. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8035. // if err != nil {
  8036. // utils.ErrorLog(err.Error())
  8037. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8038. // return
  8039. // }
  8040. //
  8041. // err = service.UpdatedProjectTeam(id, &projectTeam)
  8042. //
  8043. //
  8044. // if err != nil {
  8045. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  8046. // return
  8047. // }
  8048. //
  8049. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  8050. // infos, _ := dataBody["info"].([]interface{})
  8051. // if len(infos) > 0 {
  8052. // var ids []string
  8053. //
  8054. // for _, item := range infos {
  8055. // items := item.(map[string]interface{})
  8056. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  8057. // utils.ErrorLog("id")
  8058. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8059. // return
  8060. // }
  8061. // id := int64(items["id"].(float64))
  8062. //
  8063. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8064. // utils.ErrorLog("type")
  8065. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8066. // return
  8067. // }
  8068. // types := int64(items["type"].(float64))
  8069. //
  8070. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  8071. // utils.ErrorLog("number")
  8072. // }
  8073. //
  8074. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  8075. //
  8076. // projectList := models.XtHisProjectList{
  8077. // Number: number,
  8078. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  8079. // ProjectId: id,
  8080. // Status: 1,
  8081. // CreatedTime: time.Now().Unix(),
  8082. // UpdatedTime: time.Now().Unix(),
  8083. // TeamId: projectTeam.ID,
  8084. // Type: types,
  8085. // }
  8086. // list := projectList
  8087. //
  8088. // service.CreateProjectList(&list)
  8089. //
  8090. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  8091. //
  8092. // }
  8093. // ids_str := strings.Join(ids, ",")
  8094. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  8095. // service.SaveProjectTeam(&projectTeam)
  8096. // this.ServeSuccessJSON(map[string]interface{}{
  8097. // "projectTeam": projectTeam,
  8098. // })
  8099. // }
  8100. // }
  8101. //}
  8102. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  8103. name := c.GetString("name")
  8104. mode_id, _ := c.GetInt64("mode", 0)
  8105. types, _ := c.GetInt64("type", 0)
  8106. patient_id, _ := c.GetInt64("patient_id", 0)
  8107. types = 1
  8108. adminInfo := c.GetAdminUserInfo()
  8109. template := &models.HisPrescriptionTemplate{
  8110. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8111. PatientId: patient_id,
  8112. Type: types,
  8113. Status: 1,
  8114. Ctime: time.Now().Unix(),
  8115. Mtime: time.Now().Unix(),
  8116. Name: name,
  8117. Mode: mode_id,
  8118. }
  8119. dataBody := make(map[string]interface{}, 0)
  8120. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8121. if err != nil {
  8122. utils.ErrorLog(err.Error())
  8123. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8124. return
  8125. }
  8126. err = service.CreateHisPrescriptionTemplate(template)
  8127. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  8128. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  8129. if len(prescriptions) > 0 {
  8130. for _, item := range prescriptions {
  8131. items := item.(map[string]interface{})
  8132. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8133. utils.ErrorLog("type")
  8134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8135. return
  8136. }
  8137. types := int64(items["type"].(float64))
  8138. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  8139. utils.ErrorLog("med_type")
  8140. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8141. return
  8142. }
  8143. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  8144. ctime := time.Now().Unix()
  8145. prescription := &models.HisPrescriptionInfoTemplate{
  8146. PatientId: patient_id,
  8147. UserOrgId: adminInfo.CurrentOrgId,
  8148. Ctime: ctime,
  8149. Mtime: ctime,
  8150. Type: types,
  8151. Modifier: adminInfo.AdminUser.Id,
  8152. Creator: adminInfo.AdminUser.Id,
  8153. Status: 1,
  8154. PTemplateId: template.ID,
  8155. MedType: med_type,
  8156. }
  8157. service.CreateHisPrescriptionInfoTemplate(prescription)
  8158. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  8159. advices := items["advices"].([]interface{})
  8160. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  8161. ctime := time.Now().Unix()
  8162. mtime := ctime
  8163. if len(advices) > 0 {
  8164. for _, advice := range advices {
  8165. var s models.HisPrescriptionAdviceTemplate
  8166. s.PrescriptionId = prescription.ID
  8167. s.AdviceType = 2
  8168. s.StopState = 2
  8169. s.ExecutionState = 2
  8170. s.Status = 1
  8171. s.UserOrgId = adminInfo.CurrentOrgId
  8172. s.CreatedTime = ctime
  8173. s.UpdatedTime = mtime
  8174. s.PatientId = patient_id
  8175. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  8176. if errcode > 0 {
  8177. c.ServeFailJSONWithSGJErrorCode(errcode)
  8178. return
  8179. }
  8180. service.CreateHisPrescriptionAdviceTemplate(&s)
  8181. }
  8182. }
  8183. }
  8184. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  8185. projects := items["project"].([]interface{})
  8186. if len(projects) > 0 {
  8187. for _, project := range projects {
  8188. var p models.HisPrescriptionProjectTemplate
  8189. p.PrescriptionId = prescription.ID
  8190. p.Ctime = time.Now().Unix()
  8191. p.Mtime = time.Now().Unix()
  8192. p.PatientId = patient_id
  8193. p.UserOrgId = adminInfo.CurrentOrgId
  8194. p.Status = 1
  8195. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  8196. if errcode > 0 {
  8197. c.ServeFailJSONWithSGJErrorCode(errcode)
  8198. return
  8199. }
  8200. service.CreateHisPrescriptionProjectTemplate(&p)
  8201. }
  8202. }
  8203. }
  8204. }
  8205. c.ServeSuccessJSON(map[string]interface{}{
  8206. "msg": "创建成功",
  8207. })
  8208. }
  8209. }
  8210. }
  8211. func (c *HisApiController) PreSettle() {
  8212. id, _ := c.GetInt64("id")
  8213. record_time := c.GetString("record_time")
  8214. his_patient_id, _ := c.GetInt64("his_patient_id")
  8215. timeLayout := "2006-01-02"
  8216. loc, _ := time.LoadLocation("Local")
  8217. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  8218. diagnosis_id := c.GetString("diagnosis")
  8219. sick_type, _ := c.GetInt64("sick_type")
  8220. reg_type, _ := c.GetInt64("p_type")
  8221. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  8222. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8223. if err != nil {
  8224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8225. return
  8226. }
  8227. recordDateTime := theTime.Unix()
  8228. adminUser := c.GetAdminUserInfo()
  8229. var prescriptions []*models.HisPrescription
  8230. var start_time int64
  8231. var end_time int64
  8232. ids_str := c.GetString("ids")
  8233. ids_arr := strings.Split(ids_str, ",")
  8234. fmt.Println(reg_type)
  8235. if settle_accounts_type == 1 { //日结
  8236. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  8237. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  8238. } else {
  8239. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  8240. }
  8241. fmt.Println(prescriptions)
  8242. } else { //月结
  8243. start_time_str := c.GetString("start_time")
  8244. end_time_str := c.GetString("end_time")
  8245. timeLayout := "2006-01-02"
  8246. loc, _ := time.LoadLocation("Local")
  8247. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  8248. if err != nil {
  8249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8250. return
  8251. }
  8252. recordStartTime := theStartTime.Unix()
  8253. start_time = recordStartTime
  8254. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  8255. if err != nil {
  8256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8257. return
  8258. }
  8259. recordEndTime := theEndTime.Unix()
  8260. end_time = recordEndTime
  8261. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  8262. }
  8263. if reg_type == 1111 || reg_type == 1112 {
  8264. reg_type = 11
  8265. }
  8266. timestamp := time.Now().Unix()
  8267. tempTime := time.Unix(timestamp, 0)
  8268. timeFormat := tempTime.Format("20060102150405")
  8269. chrgBchno := rand.Intn(100000) + 10000
  8270. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  8271. strconv.FormatInt(his.PatientId, 10)
  8272. var ids []int64
  8273. for _, item := range prescriptions {
  8274. ids = append(ids, item.ID)
  8275. }
  8276. fmt.Println(ids)
  8277. var total float64
  8278. for _, item := range prescriptions {
  8279. fmt.Println(item)
  8280. if item.Type == 1 { //药品
  8281. for _, subItem := range item.HisDoctorAdviceInfo {
  8282. total = total + (subItem.Price * subItem.PrescribingNumber)
  8283. }
  8284. }
  8285. if item.Type == 2 { //项目
  8286. for _, subItem := range item.HisPrescriptionProject {
  8287. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8288. total = total + (subItem.Price * cnt)
  8289. }
  8290. }
  8291. for _, subItem := range item.HisAdditionalCharge {
  8292. total = total + (subItem.Price * float64(subItem.Count))
  8293. }
  8294. }
  8295. allTotal := fmt.Sprintf("%.2f", total)
  8296. totals, _ := strconv.ParseFloat(allTotal, 64)
  8297. order := &models.HisOrder{
  8298. UserOrgId: adminUser.CurrentOrgId,
  8299. HisPatientId: his.ID,
  8300. PatientId: id,
  8301. SettleAccountsDate: recordDateTime,
  8302. Ctime: time.Now().Unix(),
  8303. Mtime: time.Now().Unix(),
  8304. Status: 1,
  8305. OrderStatus: 1,
  8306. MdtrtId: his.Number,
  8307. Number: chrg_bchno,
  8308. MedfeeSumamt: totals,
  8309. SettleEndTime: end_time,
  8310. SettleStartTime: start_time,
  8311. SettleType: settle_accounts_type,
  8312. PsnPartAmt: totals,
  8313. PsnCashPay: totals,
  8314. PType: 2,
  8315. IsPre: 1,
  8316. MedType: strconv.Itoa(int(reg_type)),
  8317. Diagnosis: diagnosis_id,
  8318. }
  8319. err = service.CreateOrder(order)
  8320. if err != nil {
  8321. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8322. return
  8323. }
  8324. var customs []*Custom
  8325. for _, item := range prescriptions {
  8326. fmt.Println(item.Type)
  8327. if item.Type == 1 { //药品
  8328. for _, subItem := range item.HisDoctorAdviceInfo {
  8329. cus := &Custom{
  8330. AdviceId: subItem.ID,
  8331. ProjectId: 0,
  8332. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  8333. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  8334. FeedetlSn: subItem.FeedetlSn,
  8335. Price: fmt.Sprintf("%.2f", subItem.Price),
  8336. MedListCodg: subItem.MedListCodg,
  8337. Type: 1,
  8338. }
  8339. customs = append(customs, cus)
  8340. }
  8341. }
  8342. if item.Type == 2 { //项目
  8343. for _, subItem := range item.HisPrescriptionProject {
  8344. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8345. cus := &Custom{
  8346. AdviceId: 0,
  8347. ProjectId: subItem.ID,
  8348. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  8349. Cut: fmt.Sprintf("%.2f", cnt),
  8350. FeedetlSn: subItem.FeedetlSn,
  8351. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  8352. MedListCodg: subItem.MedListCodg,
  8353. Type: 2,
  8354. }
  8355. customs = append(customs, cus)
  8356. }
  8357. }
  8358. for _, item := range item.HisAdditionalCharge {
  8359. cus := &Custom{
  8360. ItemId: item.ID,
  8361. AdviceId: 0,
  8362. ProjectId: 0,
  8363. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  8364. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  8365. FeedetlSn: item.FeedetlSn,
  8366. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  8367. MedListCodg: item.XtHisAddtionConfig.Code,
  8368. Type: 3,
  8369. }
  8370. customs = append(customs, cus)
  8371. }
  8372. }
  8373. fmt.Println(customs)
  8374. for _, item := range customs {
  8375. var advice_id int64 = 0
  8376. var project_id int64 = 0
  8377. var item_id int64 = 0
  8378. var types int64 = 0
  8379. if item.Type == 1 {
  8380. advice_id = item.AdviceId
  8381. project_id = 0
  8382. item_id = 0
  8383. } else if item.Type == 2 {
  8384. advice_id = 0
  8385. item_id = 0
  8386. project_id = item.ProjectId
  8387. } else if item.Type == 3 {
  8388. advice_id = 0
  8389. item_id = item.ItemId
  8390. project_id = 0
  8391. }
  8392. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8393. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8394. pric, _ := strconv.ParseFloat(item.Price, 32)
  8395. info := &models.HisOrderInfo{
  8396. OrderNumber: order.Number,
  8397. UploadDate: time.Now().Unix(),
  8398. AdviceId: advice_id,
  8399. DetItemFeeSumamt: detItemFeeSumamt,
  8400. Cnt: cut,
  8401. Pric: pric,
  8402. PatientId: id,
  8403. Status: 1,
  8404. Mtime: time.Now().Unix(),
  8405. Ctime: time.Now().Unix(),
  8406. UserOrgId: adminUser.CurrentOrgId,
  8407. HisPatientId: his.ID,
  8408. OrderId: order.ID,
  8409. ProjectId: project_id,
  8410. Type: types,
  8411. ItemId: item_id,
  8412. }
  8413. service.CreateOrderInfo(info)
  8414. }
  8415. his.SickType = sick_type
  8416. service.UpdataHisPateint(&his)
  8417. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  8418. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  8419. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  8420. if err == nil {
  8421. c.ServeSuccessJSON(map[string]interface{}{
  8422. "msg": "结算成功",
  8423. })
  8424. }
  8425. }
  8426. type CustomOrderInfo struct {
  8427. Name string
  8428. Spec string
  8429. Unit string
  8430. Count float64
  8431. Price float64
  8432. Total float64
  8433. }
  8434. func (c *HisApiController) GetPrivateExpensesInfo() {
  8435. order_id, _ := c.GetInt64("id", 0)
  8436. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  8437. order, _ := service.GetHisOrderByID(order_id)
  8438. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  8439. if order.ID == 0 {
  8440. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8441. return
  8442. }
  8443. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  8444. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  8445. org_id := c.GetAdminUserInfo().CurrentOrgId
  8446. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8447. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8448. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  8449. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  8450. orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  8451. var orderInfos_four []*models.HisOrderInfoTwo
  8452. for _, item := range orderInfos_three {
  8453. if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  8454. item.HisPrescriptionProject.IsCheckTeam = 1
  8455. orderInfos_four = append(orderInfos_four, item)
  8456. }
  8457. if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  8458. item.HisPrescriptionProject.IsCheckTeam = 2
  8459. orderInfos_two = append(orderInfos_two, item)
  8460. }
  8461. }
  8462. new_order_info := RemoveRepeatedTeam(orderInfos_four)
  8463. var cus_slice []CustomOrderInfo
  8464. for _, item := range new_order_info {
  8465. var cus CustomOrderInfo
  8466. cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  8467. cus.Unit = ""
  8468. cus.Spec = ""
  8469. var total float64
  8470. for _, subItem := range orderInfos_four {
  8471. if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  8472. total = total + subItem.DetItemFeeSumamt
  8473. fmt.Println(subItem.DetItemFeeSumamt)
  8474. }
  8475. }
  8476. cus.Count = 1
  8477. cus.Total = total
  8478. cus_slice = append(cus_slice, cus)
  8479. }
  8480. orderInfos = append(orderInfos, orderInfos_two...)
  8481. if c.GetAdminUserInfo().CurrentOrgId != 10138 {
  8482. orderInfos = append(orderInfos, orderInfos_three...)
  8483. }
  8484. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  8485. c.ServeSuccessJSON(map[string]interface{}{
  8486. "order": order,
  8487. "order_info": orderInfos,
  8488. "patient": patient,
  8489. "admin_info": adminInfo,
  8490. "his": his,
  8491. "current_admin": role,
  8492. "org_config": miConfig,
  8493. "new_order_info": cus_slice,
  8494. })
  8495. }
  8496. func (this *HisApiController) ChangeMedType() {
  8497. med_type := this.GetString("med_type")
  8498. old_med_type := this.GetString("old_med_type")
  8499. ids := this.GetString("ids")
  8500. settle_type, _ := this.GetInt64("settle_type")
  8501. start_time := this.GetString("start_time")
  8502. end_time := this.GetString("end_time")
  8503. ids_arr := strings.Split(ids, ",")
  8504. if settle_type == 1 { //日结
  8505. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  8506. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  8507. prescription.MedType = med_type
  8508. err := service.SaveHisPrescription(&prescription)
  8509. if err == nil {
  8510. this.ServeSuccessJSON(map[string]interface{}{
  8511. "msg": "修改成功",
  8512. })
  8513. } else {
  8514. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8515. return
  8516. }
  8517. } else if settle_type == 2 {
  8518. timeLayout := "2006-01-02"
  8519. loc, _ := time.LoadLocation("Local")
  8520. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8521. if err != nil {
  8522. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8523. return
  8524. }
  8525. recordStartTime := theStartTime.Unix()
  8526. start_time_timestamp := recordStartTime
  8527. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8528. if err != nil {
  8529. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8530. return
  8531. }
  8532. recordEndTime := theEndTime.Unix()
  8533. end_time_timestamp := recordEndTime
  8534. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  8535. if updateErr == nil {
  8536. this.ServeSuccessJSON(map[string]interface{}{
  8537. "msg": "修改成功",
  8538. })
  8539. } else {
  8540. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8541. return
  8542. }
  8543. }
  8544. }
  8545. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  8546. patient_id, _ := c.GetInt64("patient_id")
  8547. his_patient_id, _ := c.GetInt64("his_patient_id")
  8548. record_date := c.GetString("record_date")
  8549. start_time := c.GetString("start_time")
  8550. end_time := c.GetString("end_time")
  8551. order_status, _ := c.GetInt64("type", 0)
  8552. p_type, _ := c.GetInt64("p_type", 0)
  8553. order_id, _ := c.GetInt64("order_id", 0)
  8554. timeLayout := "2006-01-02"
  8555. loc, _ := time.LoadLocation("Local")
  8556. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8557. if err != nil {
  8558. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8559. return
  8560. }
  8561. recordDateTime := theTime.Unix()
  8562. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8563. if err != nil {
  8564. }
  8565. startRecordDateTime := startTime.Unix()
  8566. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8567. if err != nil {
  8568. }
  8569. endRecordDateTime := endTime.Unix()
  8570. admin := c.GetAdminUserInfo()
  8571. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8572. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8573. order, _ := service.GetHisOrderByID(order_id)
  8574. var monthPrescriptions []*models.HisPrescription
  8575. if order_status == 1 || order_status == 0 {
  8576. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8577. } else if order_status == 2 {
  8578. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  8579. }
  8580. var settle_total float64
  8581. for _, item := range monthPrescriptions {
  8582. if len(item.HisPrescriptionProject) > 0 {
  8583. for _, subItem := range item.HisPrescriptionProject {
  8584. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8585. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8586. settle_total = settle_total + total
  8587. }
  8588. }
  8589. if len(item.HisDoctorAdviceInfo) > 0 {
  8590. for _, subItem := range item.HisDoctorAdviceInfo {
  8591. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8592. settle_total = settle_total + total
  8593. }
  8594. }
  8595. }
  8596. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8597. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8598. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8599. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8600. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8601. //获取所有科室信息
  8602. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8603. c.ServeSuccessJSON(map[string]interface{}{
  8604. "his_info": his_patient_info,
  8605. "xt_info": xt_patient_info,
  8606. "case_history": case_history,
  8607. "info": patientPrescriptionInfo,
  8608. "last_info": lastPatientPrescriptionInfo,
  8609. "month_prescriptions": monthPrescriptions,
  8610. "order": order,
  8611. "doctors": doctors,
  8612. "department": department,
  8613. "settle_total": settle_total,
  8614. })
  8615. return
  8616. }
  8617. func (c *HisApiController) GetHisMonthPatientInfo() {
  8618. patient_id, _ := c.GetInt64("patient_id")
  8619. his_patient_id, _ := c.GetInt64("his_patient_id")
  8620. record_date := c.GetString("record_date")
  8621. number := c.GetString("number")
  8622. start_time := c.GetString("start_time")
  8623. end_time := c.GetString("end_time")
  8624. p_type, _ := c.GetInt64("p_type")
  8625. timeLayout := "2006-01-02"
  8626. loc, _ := time.LoadLocation("Local")
  8627. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8628. if err != nil {
  8629. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8630. return
  8631. }
  8632. recordDateTime := theTime.Unix()
  8633. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8634. if err != nil {
  8635. }
  8636. startRecordDateTime := startTime.Unix()
  8637. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8638. if err != nil {
  8639. }
  8640. endRecordDateTime := endTime.Unix()
  8641. admin := c.GetAdminUserInfo()
  8642. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  8643. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8644. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  8645. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8646. var settle_total float64
  8647. for _, item := range monthPrescriptions {
  8648. if len(item.HisPrescriptionProject) > 0 {
  8649. for _, subItem := range item.HisPrescriptionProject {
  8650. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8651. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8652. settle_total = settle_total + total
  8653. }
  8654. }
  8655. if len(item.HisDoctorAdviceInfo) > 0 {
  8656. for _, subItem := range item.HisDoctorAdviceInfo {
  8657. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8658. settle_total = settle_total + total
  8659. }
  8660. }
  8661. }
  8662. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8663. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8664. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8665. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8666. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  8667. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8668. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  8669. //获取所有科室信息
  8670. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8671. c.ServeSuccessJSON(map[string]interface{}{
  8672. "his_info": his_patient_info,
  8673. "xt_info": xt_patient_info,
  8674. "case_history": case_history,
  8675. "info": patientPrescriptionInfo,
  8676. "month_prescriptions": monthPrescriptions,
  8677. "order": order,
  8678. "doctors": doctors,
  8679. "department": department,
  8680. "count": count,
  8681. "drugStockConfig": drugStockConfig,
  8682. "last_info": lastPatientPrescriptionInfo,
  8683. "settle_total": settle_total,
  8684. })
  8685. return
  8686. }
  8687. func (c *HisApiController) GetAllOrder() {
  8688. org_id := c.GetAdminUserInfo().CurrentOrgId
  8689. orders, _ := service.GetNewHisOrderList(org_id)
  8690. c.ServeSuccessJSON(map[string]interface{}{
  8691. "order": orders,
  8692. })
  8693. return
  8694. }
  8695. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  8696. newArr = make([]*models.HisOrderInfoTwo, 0)
  8697. for i := 0; i < len(arr); i++ {
  8698. repeat := false
  8699. for j := i + 1; j < len(arr); j++ {
  8700. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  8701. repeat = true
  8702. break
  8703. }
  8704. }
  8705. if !repeat {
  8706. newArr = append(newArr, arr[i])
  8707. }
  8708. }
  8709. return
  8710. }
  8711. // 修改处方退库操作 参数传修改之前的处方数据
  8712. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  8713. if advice.ExecutionState == 1 {
  8714. //查询该病人该药品是否有库存记录
  8715. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  8716. if errcode == gorm.ErrRecordNotFound {
  8717. } else {
  8718. //退库
  8719. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8720. if advice.PrescribingNumberUnit == drug.MinUnit {
  8721. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  8722. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  8723. //退库
  8724. warehouseInfo := models.DrugWarehouseInfo{
  8725. StockMinNumber: prescribingNumber,
  8726. }
  8727. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  8728. operation_time := time.Now().Unix()
  8729. creater := advice.AdviceDoctor
  8730. ctime := time.Now().Unix()
  8731. timeStr := time.Now().Format("2006-01-02")
  8732. timeArr := strings.Split(timeStr, "-")
  8733. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  8734. total = total + 1
  8735. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8736. cancelStock := models.DrugCancelStock{
  8737. OrderNumber: orderNumber,
  8738. OperaTime: operation_time,
  8739. OrgId: advice.UserOrgId,
  8740. Creater: creater,
  8741. Ctime: ctime,
  8742. Status: 1,
  8743. ReturnTime: advice.AdviceDate,
  8744. Dealer: info.Dealer,
  8745. Manufacturer: info.Manufacturer,
  8746. Type: 1,
  8747. }
  8748. service.AddSigleDrugCancelStock(&cancelStock)
  8749. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  8750. dealer, _ := service.GetDealerById(info.Dealer)
  8751. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  8752. cancelStockInfo := models.DrugCancelStockInfo{
  8753. OrderNumber: cancelInfo.OrderNumber,
  8754. CancelStockId: cancelInfo.ID,
  8755. DrugId: info.DrugId,
  8756. Count: info.Count,
  8757. Status: 1,
  8758. Ctime: ctime,
  8759. OrgId: advice.UserOrgId,
  8760. Type: 1,
  8761. Manufacturer: manufactureName.ManufacturerName,
  8762. Dealer: dealer.DealerName,
  8763. Total: 0,
  8764. RetailPrice: info.RetailPrice,
  8765. RetailTotalPrice: info.RetailTotalPrice,
  8766. Price: info.Price,
  8767. RegisterAccount: "",
  8768. Remark: info.Remark,
  8769. BatchNumber: info.BatchNumber,
  8770. MaxUnit: info.CountUnit,
  8771. ProductDate: info.ProductDate,
  8772. ExpiryDate: info.ExpiryDate,
  8773. BatchNumberId: info.WarehouseInfoId,
  8774. }
  8775. flow := models.DrugFlow{
  8776. WarehousingId: 0,
  8777. DrugId: info.DrugId,
  8778. Number: "",
  8779. BatchNumber: info.BatchNumber,
  8780. Count: info.Count,
  8781. UserOrgId: advice.UserOrgId,
  8782. PatientId: 0,
  8783. SystemTime: ctime,
  8784. ConsumableType: 4,
  8785. IsSys: 0,
  8786. WarehousingOrder: "",
  8787. WarehouseOutId: 0,
  8788. WarehouseOutOrderNumber: "",
  8789. IsEdit: 0,
  8790. CancelStockId: cancelStock.ID,
  8791. CancelOrderNumber: cancelStock.OrderNumber,
  8792. Manufacturer: info.Manufacturer,
  8793. Dealer: info.Dealer,
  8794. Creator: advice.UserOrgId,
  8795. UpdateCreator: 0,
  8796. Status: 1,
  8797. Ctime: time.Now().Unix(),
  8798. Mtime: 0,
  8799. Price: info.Price,
  8800. WarehousingDetailId: 0,
  8801. WarehouseOutDetailId: 0,
  8802. CancelOutDetailId: 0,
  8803. ExpireDate: info.ExpiryDate,
  8804. ProductDate: info.ProductDate,
  8805. MaxUnit: info.CountUnit,
  8806. MinUnit: "",
  8807. }
  8808. service.CreatedCancelStock(cancelStockInfo)
  8809. service.CreateDrugFlowOne(flow)
  8810. } else {
  8811. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  8812. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  8813. if advice.PrescribingNumberUnit == drug.MaxUnit {
  8814. warehouseInfo := models.DrugWarehouseInfo{
  8815. StockMinNumber: prescribingNumber,
  8816. }
  8817. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  8818. }
  8819. operation_time := time.Now().Unix()
  8820. creater := advice.AdviceDoctor
  8821. ctime := time.Now().Unix()
  8822. timeStr := time.Now().Format("2006-01-02")
  8823. timeArr := strings.Split(timeStr, "-")
  8824. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  8825. total = total + 1
  8826. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8827. cancelStock := models.DrugCancelStock{
  8828. OrderNumber: orderNumber,
  8829. OperaTime: operation_time,
  8830. OrgId: advice.UserOrgId,
  8831. Creater: creater,
  8832. Ctime: ctime,
  8833. Status: 1,
  8834. ReturnTime: advice.AdviceDate,
  8835. Dealer: info.Dealer,
  8836. Manufacturer: info.Manufacturer,
  8837. Type: 1,
  8838. }
  8839. service.AddSigleDrugCancelStock(&cancelStock)
  8840. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  8841. dealer, _ := service.GetDealerById(info.Dealer)
  8842. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  8843. cancelStockInfo := models.DrugCancelStockInfo{
  8844. OrderNumber: cancelInfo.OrderNumber,
  8845. CancelStockId: cancelInfo.ID,
  8846. DrugId: info.DrugId,
  8847. Count: info.Count,
  8848. Status: 1,
  8849. Ctime: ctime,
  8850. OrgId: advice.UserOrgId,
  8851. Type: 1,
  8852. Manufacturer: manufactureName.ManufacturerName,
  8853. Dealer: dealer.DealerName,
  8854. Total: 0,
  8855. RetailPrice: info.RetailPrice,
  8856. RetailTotalPrice: info.RetailTotalPrice,
  8857. Price: info.Price,
  8858. RegisterAccount: "",
  8859. Remark: info.Remark,
  8860. BatchNumber: info.BatchNumber,
  8861. MaxUnit: info.CountUnit,
  8862. ProductDate: info.ProductDate,
  8863. ExpiryDate: info.ExpiryDate,
  8864. BatchNumberId: info.WarehouseInfoId,
  8865. }
  8866. flow := models.DrugFlow{
  8867. WarehousingId: 0,
  8868. DrugId: info.DrugId,
  8869. Number: "",
  8870. BatchNumber: info.BatchNumber,
  8871. Count: info.Count,
  8872. UserOrgId: advice.UserOrgId,
  8873. PatientId: 0,
  8874. SystemTime: ctime,
  8875. ConsumableType: 4,
  8876. IsSys: 0,
  8877. WarehousingOrder: "",
  8878. WarehouseOutId: 0,
  8879. WarehouseOutOrderNumber: "",
  8880. IsEdit: 0,
  8881. CancelStockId: cancelStock.ID,
  8882. CancelOrderNumber: cancelStock.OrderNumber,
  8883. Manufacturer: info.Manufacturer,
  8884. Dealer: info.Dealer,
  8885. Creator: advice.AdviceDoctor,
  8886. UpdateCreator: 0,
  8887. Status: 1,
  8888. Ctime: time.Now().Unix(),
  8889. Mtime: 0,
  8890. Price: info.Price,
  8891. WarehousingDetailId: 0,
  8892. WarehouseOutDetailId: 0,
  8893. CancelOutDetailId: 0,
  8894. ExpireDate: info.ExpiryDate,
  8895. ProductDate: info.ProductDate,
  8896. MaxUnit: info.CountUnit,
  8897. MinUnit: "",
  8898. }
  8899. service.CreatedCancelStock(cancelStockInfo)
  8900. service.CreateDrugFlowOne(flow)
  8901. }
  8902. }
  8903. }
  8904. return err
  8905. }
  8906. func (this *HisApiController) DeleteNCDS() {
  8907. id, _ := this.GetInt64("id", 0)
  8908. if id > 0 {
  8909. service.DeletePsnNCDSRecordById(id)
  8910. this.ServeSuccessJSON(map[string]interface{}{
  8911. "msg": "删除成功",
  8912. })
  8913. } else {
  8914. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  8915. return
  8916. }
  8917. }
  8918. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  8919. id, _ := c.GetInt64("id")
  8920. advice, _ := service.GetHisDoctorAdviceInfo(id)
  8921. c.ServeSuccessJSON(map[string]interface{}{
  8922. "advice": advice,
  8923. })
  8924. return
  8925. }
  8926. func (c *HisApiController) GetHisMonthChargePatientList() {
  8927. record_date := c.GetString("record_date")
  8928. start_time := c.GetString("start_time")
  8929. end_time := c.GetString("end_time")
  8930. timeLayout := "2006-01-02"
  8931. loc, _ := time.LoadLocation("Local")
  8932. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8933. if err != nil {
  8934. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8935. return
  8936. }
  8937. if err != nil {
  8938. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8939. return
  8940. }
  8941. recordDateTime := theTime.Unix()
  8942. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8943. if err != nil {
  8944. }
  8945. startRecordDateTime := startTime.Unix()
  8946. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8947. if err != nil {
  8948. }
  8949. endRecordDateTime := endTime.Unix()
  8950. adminInfo := c.GetAdminUserInfo()
  8951. var tempMonthChargePatients []*service.MonthChargePatients
  8952. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  8953. for _, item := range tempPatients {
  8954. //过滤没有处方的
  8955. if len(item.HisPrescription) == 0 {
  8956. tempMonthChargePatients = append(tempMonthChargePatients, item)
  8957. }
  8958. }
  8959. c.ServeSuccessJSON(map[string]interface{}{
  8960. "list": tempMonthChargePatients,
  8961. })
  8962. }