his_api_controller.go 391KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128
  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. pay_way, _ := c.GetInt64("pay_way")
  5527. pay_price, _ := c.GetFloat("pay_price")
  5528. pay_card_no := c.GetString("pay_card_no")
  5529. discount_price, _ := c.GetFloat("discount_price")
  5530. preferential_price, _ := c.GetFloat("preferential_price")
  5531. reality_price, _ := c.GetFloat("reality_price")
  5532. found_price, _ := c.GetFloat("found_price")
  5533. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  5534. private_price, _ := c.GetFloat("private_price")
  5535. timeLayout := "2006-01-02"
  5536. loc, _ := time.LoadLocation("Local")
  5537. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  5538. fapiao_code := c.GetString("fapiao_code")
  5539. fapiao_number := c.GetString("fapiao_number")
  5540. diagnosis_id := c.GetString("diagnosis")
  5541. sick_type, _ := c.GetInt64("sick_type")
  5542. reg_type, _ := c.GetInt64("p_type")
  5543. order_id, _ := c.GetInt64("order_id")
  5544. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  5545. tmp_decimal := c.GetString("tmp_decimal")
  5546. var decimal float64 //本次使用的押金
  5547. var errmsg error
  5548. tx := service.XTWriteDB().Begin() //开了事务
  5549. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  5550. defer func() {
  5551. if errmsg != nil {
  5552. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  5553. tx.Rollback()
  5554. } else {
  5555. tx.Commit()
  5556. }
  5557. }()
  5558. fmt.Println("dec_way", dec_way)
  5559. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  5560. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  5561. return
  5562. }
  5563. if len(tmp_decimal) > 0 {
  5564. if tmp_decimal[0] == 45 {
  5565. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  5566. return
  5567. }
  5568. }
  5569. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  5570. fmt.Println(errs)
  5571. //if errs != nil {
  5572. // c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金金额错误")
  5573. // return
  5574. //}
  5575. decimal = tt
  5576. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  5577. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  5578. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5579. if err != nil {
  5580. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5581. return
  5582. }
  5583. recordDateTime := theTime.Unix()
  5584. adminUser := c.GetAdminUserInfo()
  5585. var prescriptions []*models.HisPrescription
  5586. var prescriptionsOne []*models.HisPrescription
  5587. var start_time int64
  5588. var end_time int64
  5589. ids_str := c.GetString("ids")
  5590. ids_arr := strings.Split(ids_str, ",")
  5591. if tempOrder.ID == 0 {
  5592. if settle_accounts_type == 1 { //日结
  5593. fmt.Println(reg_type)
  5594. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  5595. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  5596. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  5597. } else {
  5598. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5599. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5600. }
  5601. } else { //月结
  5602. start_time_str := c.GetString("start_time")
  5603. end_time_str := c.GetString("end_time")
  5604. timeLayout := "2006-01-02"
  5605. loc, _ := time.LoadLocation("Local")
  5606. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  5607. if err != nil {
  5608. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5609. return
  5610. }
  5611. recordStartTime := theStartTime.Unix()
  5612. start_time = recordStartTime
  5613. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  5614. if err != nil {
  5615. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5616. return
  5617. }
  5618. recordEndTime := theEndTime.Unix()
  5619. end_time = recordEndTime
  5620. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  5621. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5622. }
  5623. var goods []*models.DialysisBeforePrepareGoods
  5624. var newGoods []*models.NewDialysisBeforePrepareGoods
  5625. var oldGoods []*models.OldDialysisBeforePrepareGoods
  5626. var infos []*models.HisDoctorAdviceInfo
  5627. var infoList []*models.HisDoctorAdviceInfo
  5628. var hisAdvice []*models.HisDoctorAdviceInfo
  5629. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  5630. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  5631. //判断库存不足
  5632. //结算出库开关
  5633. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  5634. if settConfig.IsOpen == 1 {
  5635. //判断库存的地方
  5636. for _, info := range prescriptions {
  5637. if info.Type == 1 {
  5638. infos = append(infos, info.HisDoctorAdviceInfo...)
  5639. }
  5640. if info.Type == 2 {
  5641. for _, sumItem := range info.HisPrescriptionProject {
  5642. if sumItem.Type == 3 {
  5643. var good models.DialysisBeforePrepareGoods
  5644. var newGood models.NewDialysisBeforePrepareGoods
  5645. good.GoodId = sumItem.GoodInfo.ID
  5646. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5647. count, _ := strconv.Atoi(sumItem.Count)
  5648. good.Count = int64(count)
  5649. good.StorehouseId = houseConfig.StorehouseOutInfo
  5650. good.ProjectId = sumItem.ID
  5651. goods = append(goods, &good)
  5652. newGood.GoodId = sumItem.GoodInfo.ID
  5653. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5654. count2, _ := strconv.Atoi(sumItem.Count)
  5655. newGood.Count = int64(count2)
  5656. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5657. newGood.ProjectId = sumItem.ID
  5658. newGoods = append(newGoods, &newGood)
  5659. }
  5660. }
  5661. }
  5662. }
  5663. for _, info := range prescriptionsOne {
  5664. if info.Type == 1 {
  5665. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  5666. }
  5667. if info.Type == 2 {
  5668. for _, sumItem := range info.HisPrescriptionProject {
  5669. if sumItem.Type == 3 {
  5670. var newGood models.NewDialysisBeforePrepareGoods
  5671. newGood.GoodId = sumItem.GoodInfo.ID
  5672. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5673. count2, _ := strconv.Atoi(sumItem.Count)
  5674. newGood.Count = int64(count2)
  5675. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5676. newGood.ProjectId = sumItem.ID
  5677. newGoodOne = append(newGoodOne, &newGood)
  5678. }
  5679. }
  5680. }
  5681. }
  5682. //判断
  5683. for _, itemOne := range infos {
  5684. for _, itemTwo := range hisAdvice {
  5685. if itemOne.DrugId == itemTwo.DrugId {
  5686. itemTwo.Child = append(itemTwo.Child, itemOne)
  5687. }
  5688. }
  5689. }
  5690. for _, itemTwo := range hisAdvice {
  5691. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  5692. var sum_out_count int64
  5693. for _, itemThree := range itemTwo.Child {
  5694. var prescribing_number int64
  5695. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  5696. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5697. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5698. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5699. }
  5700. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5701. prescribing_number = parseIntPrescribingNumber
  5702. }
  5703. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5704. prescribing_number = parseIntPrescribingNumber
  5705. }
  5706. sum_out_count += prescribing_number
  5707. }
  5708. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  5709. fmt.Println("sum_out_count233232323232wo", sum_out_count)
  5710. fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
  5711. if sum_out_count > drugStockOut.FlushCount {
  5712. c.ServeSuccessJSON(map[string]interface{}{
  5713. "msg": "2",
  5714. "drug": medical,
  5715. })
  5716. return
  5717. }
  5718. }
  5719. fmt.Println("newGoods99999988882os", newGoods)
  5720. for _, itemOne := range newGoods {
  5721. for _, item := range newGoodOne {
  5722. if itemOne.GoodId == item.GoodId {
  5723. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  5724. }
  5725. }
  5726. }
  5727. for _, item := range newGoodOne {
  5728. var sum_out_count_one int64
  5729. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  5730. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  5731. sum_out_count_one += itemOne.Count
  5732. }
  5733. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5734. fmt.Println("sum_out_count_one", sum_out_count_one)
  5735. fmt.Println("list.FlushCount", list.FlushCount)
  5736. if sum_out_count_one > list.FlushCount {
  5737. c.ServeSuccessJSON(map[string]interface{}{
  5738. "msg": "3",
  5739. "good": good,
  5740. })
  5741. return
  5742. }
  5743. }
  5744. }
  5745. timestamp := time.Now().Unix()
  5746. tempTime := time.Unix(timestamp, 0)
  5747. timeFormat := tempTime.Format("20060102150405")
  5748. chrgBchno := rand.Intn(100000) + 10000
  5749. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  5750. strconv.FormatInt(his.PatientId, 10)
  5751. var ids []int64
  5752. for _, item := range prescriptions {
  5753. ids = append(ids, item.ID)
  5754. }
  5755. var total float64
  5756. for _, item := range prescriptions {
  5757. fmt.Println(item)
  5758. if item.Type == 1 { //药品
  5759. for _, subItem := range item.HisDoctorAdviceInfo {
  5760. total = total + (subItem.Price * subItem.PrescribingNumber)
  5761. }
  5762. }
  5763. if item.Type == 2 { //项目
  5764. for _, subItem := range item.HisPrescriptionProject {
  5765. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  5766. total = total + (subItem.Price * cnt)
  5767. }
  5768. }
  5769. for _, subItem := range item.HisAdditionalCharge {
  5770. total = total + (subItem.Price * float64(subItem.Count))
  5771. }
  5772. }
  5773. if reg_type == 1111 || reg_type == 1112 {
  5774. reg_type = 11
  5775. }
  5776. tm := time.Unix(time.Now().Unix(), 0)
  5777. allTotal := fmt.Sprintf("%.4f", total)
  5778. totals, _ := strconv.ParseFloat(allTotal, 64)
  5779. order := &models.HisOrder{
  5780. UserOrgId: adminUser.CurrentOrgId,
  5781. HisPatientId: his.ID,
  5782. PatientId: id,
  5783. SettleAccountsDate: recordDateTime,
  5784. Ctime: time.Now().Unix(),
  5785. Mtime: time.Now().Unix(),
  5786. Status: 1,
  5787. OrderStatus: 2,
  5788. MdtrtId: his.Number,
  5789. Number: chrg_bchno,
  5790. MedfeeSumamt: totals,
  5791. PayWay: pay_way,
  5792. PayPrice: pay_price,
  5793. MedType: strconv.Itoa(int(reg_type)),
  5794. PayCardNo: pay_card_no,
  5795. DiscountPrice: discount_price,
  5796. PreferentialPrice: preferential_price,
  5797. RealityPrice: reality_price,
  5798. FoundPrice: found_price,
  5799. MedicalInsurancePrice: medical_insurance_price,
  5800. PrivatePrice: private_price,
  5801. SettleEndTime: end_time,
  5802. SettleStartTime: start_time,
  5803. PsnPartAmt: totals,
  5804. PsnCashPay: totals,
  5805. SettleType: settle_accounts_type,
  5806. FaPiaoCode: fapiao_code,
  5807. FaPiaoNumber: fapiao_number,
  5808. Diagnosis: diagnosis_id,
  5809. PType: 2,
  5810. SetlTime: tm.Format("2006-01-02 15:04:05"),
  5811. Decimal: decimal,
  5812. }
  5813. err = service.CreateOrderTX(order, tx)
  5814. if err != nil {
  5815. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  5816. return
  5817. }
  5818. var customs []*Custom
  5819. for _, item := range prescriptions {
  5820. if item.Type == 1 { //药品a
  5821. for _, subItem := range item.HisDoctorAdviceInfo {
  5822. cus := &Custom{
  5823. AdviceId: subItem.ID,
  5824. ProjectId: 0,
  5825. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  5826. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  5827. FeedetlSn: subItem.FeedetlSn,
  5828. Price: fmt.Sprintf("%.4f", subItem.Price),
  5829. MedListCodg: subItem.MedListCodg,
  5830. Type: 1,
  5831. }
  5832. customs = append(customs, cus)
  5833. }
  5834. }
  5835. if item.Type == 2 { //项目
  5836. for _, subItem := range item.HisPrescriptionProject {
  5837. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  5838. cus := &Custom{
  5839. AdviceId: 0,
  5840. ProjectId: subItem.ID,
  5841. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  5842. Cut: fmt.Sprintf("%.4f", cnt),
  5843. FeedetlSn: subItem.FeedetlSn,
  5844. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  5845. MedListCodg: subItem.MedListCodg,
  5846. Type: 2,
  5847. }
  5848. customs = append(customs, cus)
  5849. }
  5850. }
  5851. for _, item := range item.HisAdditionalCharge {
  5852. cus := &Custom{
  5853. ItemId: item.ID,
  5854. AdviceId: 0,
  5855. ProjectId: 0,
  5856. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  5857. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  5858. FeedetlSn: item.FeedetlSn,
  5859. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  5860. MedListCodg: item.XtHisAddtionConfig.Code,
  5861. Type: 3,
  5862. }
  5863. customs = append(customs, cus)
  5864. }
  5865. }
  5866. for _, item := range customs {
  5867. var advice_id int64 = 0
  5868. var project_id int64 = 0
  5869. var item_id int64 = 0
  5870. var types int64 = 0
  5871. if item.Type == 1 {
  5872. advice_id = item.AdviceId
  5873. project_id = 0
  5874. item_id = 0
  5875. } else if item.Type == 2 {
  5876. advice_id = 0
  5877. item_id = 0
  5878. project_id = item.ProjectId
  5879. } else if item.Type == 3 {
  5880. advice_id = 0
  5881. item_id = item.ItemId
  5882. project_id = 0
  5883. }
  5884. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  5885. cut, _ := strconv.ParseFloat(item.Cut, 32)
  5886. pric, _ := strconv.ParseFloat(item.Price, 32)
  5887. info := &models.HisOrderInfo{
  5888. OrderNumber: order.Number,
  5889. UploadDate: time.Now().Unix(),
  5890. AdviceId: advice_id,
  5891. DetItemFeeSumamt: detItemFeeSumamt,
  5892. Cnt: cut,
  5893. Pric: pric,
  5894. PatientId: id,
  5895. Status: 1,
  5896. Mtime: time.Now().Unix(),
  5897. Ctime: time.Now().Unix(),
  5898. UserOrgId: adminUser.CurrentOrgId,
  5899. HisPatientId: his.ID,
  5900. OrderId: order.ID,
  5901. ProjectId: project_id,
  5902. Type: types,
  5903. ItemId: item_id,
  5904. }
  5905. service.CreateOrderInfoTX(info, tx)
  5906. }
  5907. his.Diagnosis = diagnosis_id
  5908. his.SickType = sick_type
  5909. his.RegisterType = reg_type
  5910. his.MedicalTreatmentType = reg_type
  5911. service.UpdataHisPateintTX(&his, tx)
  5912. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  5913. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  5914. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  5915. //判断是否使用了押金
  5916. if dec_way == "true" {
  5917. tmpstring := strconv.FormatInt(order.ID, 10)
  5918. //扣押金
  5919. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  5920. order.Decimal = decimal
  5921. service.UpDateOrderTwo(order)
  5922. if errmsg != nil {
  5923. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  5924. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  5925. return
  5926. }
  5927. }
  5928. if err == nil {
  5929. for _, info := range prescriptions {
  5930. if info.Type == 1 {
  5931. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  5932. }
  5933. if info.Type == 2 {
  5934. for _, sumItem := range info.HisPrescriptionProject {
  5935. if sumItem.Type == 3 {
  5936. var good models.DialysisBeforePrepareGoods
  5937. var newGood models.NewDialysisBeforePrepareGoods
  5938. var oldGood models.OldDialysisBeforePrepareGoods
  5939. good.GoodId = sumItem.GoodInfo.ID
  5940. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5941. count, _ := strconv.Atoi(sumItem.Count)
  5942. good.Count = int64(count)
  5943. good.StorehouseId = houseConfig.StorehouseOutInfo
  5944. good.ProjectId = sumItem.ID
  5945. good.PatientId = sumItem.PatientId
  5946. goods = append(goods, &good)
  5947. newGood.GoodId = sumItem.GoodInfo.ID
  5948. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5949. count2, _ := strconv.Atoi(sumItem.Count)
  5950. newGood.Count = int64(count2)
  5951. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5952. newGood.ProjectId = sumItem.ID
  5953. newGood.PatientId = sumItem.HisPatientId
  5954. newGoods = append(newGoods, &newGood)
  5955. oldGood.GoodId = sumItem.GoodInfo.ID
  5956. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5957. count3, _ := strconv.Atoi(sumItem.Count)
  5958. oldGood.Count = int64(count3)
  5959. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  5960. oldGood.ProjectId = sumItem.ID
  5961. oldGood.RecordDate = sumItem.RecordDate
  5962. oldGood.PatientId = sumItem.HisPatientId
  5963. oldGoods = append(oldGoods, &oldGood)
  5964. }
  5965. }
  5966. }
  5967. }
  5968. if settConfig.IsOpen == 1 {
  5969. for _, item := range infoList {
  5970. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  5971. if medical.IsUse == 2 {
  5972. //药品出库
  5973. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  5974. //查询默认仓库
  5975. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  5976. //查询默认仓库剩余多少库存
  5977. var sum_count int64
  5978. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  5979. for _, its := range stockInfo {
  5980. if its.MaxUnit == medical.MaxUnit {
  5981. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5982. }
  5983. sum_count += its.StockMaxNumber + its.StockMinNumber
  5984. }
  5985. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  5986. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  5987. }
  5988. }
  5989. orgId := c.GetAdminUserInfo().CurrentOrgId
  5990. if len(oldGoods) > 0 {
  5991. timeStr := time.Now().Format("2006-01-02")
  5992. timeArr := strings.Split(timeStr, "-")
  5993. total, _ := service.FindAllWarehouseOut(orgId)
  5994. total = total + 1
  5995. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5996. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5997. number = number + total
  5998. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5999. operation_time := time.Now().Unix()
  6000. creater := c.GetAdminUserInfo().AdminUser.Id
  6001. //查询默认出库仓库库存
  6002. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6003. recordDateStr := time.Now().Format("2006-01-02")
  6004. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6005. nowtime := recordDate.Unix()
  6006. warehouseOut := models.WarehouseOut{
  6007. WarehouseOutOrderNumber: warehousing_out_order,
  6008. OperationTime: operation_time,
  6009. OrgId: orgId,
  6010. Creater: creater,
  6011. Ctime: time.Now().Unix(),
  6012. Status: 1,
  6013. WarehouseOutTime: nowtime,
  6014. Type: 1,
  6015. StorehouseId: storeConfig.StorehouseOutInfo,
  6016. IsCheck: 1,
  6017. OrderId: order.ID,
  6018. IsSys: 5,
  6019. }
  6020. //查询是否生成出库单
  6021. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6022. if out.ID == 0 {
  6023. service.AddSigleWarehouseOut(&warehouseOut)
  6024. }
  6025. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6026. for _, item := range oldGoods {
  6027. dialyPrepareOne := models.DialysisBeforePrepare{
  6028. GoodTypeId: item.GoodTypeId,
  6029. GoodId: item.GoodId,
  6030. PatientId: his.PatientId,
  6031. RecordDate: item.RecordDate,
  6032. UserOrgId: adminUser.CurrentOrgId,
  6033. Count: item.Count,
  6034. Ctime: time.Now().Unix(),
  6035. Creater: adminUser.AdminUser.Id,
  6036. CommdityCode: item.CommdityCode,
  6037. Status: 1,
  6038. StorehouseId: houseConfig.StorehouseOutInfo,
  6039. }
  6040. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  6041. //非零用
  6042. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  6043. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6044. //查询剩余库存
  6045. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6046. var sum_count int64
  6047. for _, item := range goodList {
  6048. sum_count += item.StockCount
  6049. }
  6050. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6051. //耗材
  6052. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6053. }
  6054. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  6055. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6056. //查询剩余库存
  6057. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6058. var sum_count int64
  6059. for _, item := range goodList {
  6060. sum_count += item.StockCount
  6061. }
  6062. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6063. //耗材
  6064. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6065. }
  6066. }
  6067. }
  6068. }
  6069. c.ServeSuccessJSON(map[string]interface{}{
  6070. "msg": "结算成功",
  6071. })
  6072. }
  6073. } else {
  6074. if tempOrder.IsPre > 0 {
  6075. allTotal := fmt.Sprintf("%.2f", tempOrder.MedfeeSumamt)
  6076. totals, _ := strconv.ParseFloat(allTotal, 64)
  6077. tempOrder.OrderStatus = 2
  6078. tempOrder.PayWay = pay_way
  6079. tempOrder.PayPrice = pay_price
  6080. tempOrder.PayCardNo = pay_card_no
  6081. tempOrder.DiscountPrice = discount_price
  6082. tempOrder.PreferentialPrice = preferential_price
  6083. tempOrder.RealityPrice = reality_price
  6084. tempOrder.FoundPrice = found_price
  6085. tempOrder.MedicalInsurancePrice = medical_insurance_price
  6086. tempOrder.PrivatePrice = private_price
  6087. tempOrder.FaPiaoCode = fapiao_code
  6088. tempOrder.FaPiaoNumber = fapiao_number
  6089. tempOrder.PType = 2
  6090. tempOrder.MedfeeSumamt = totals
  6091. tempOrder.Diagnosis = diagnosis_id
  6092. err = service.SaveHisOrder(&tempOrder)
  6093. err = service.UpdataOrderStatusTwo(tempOrder.Number, adminUser.CurrentOrgId)
  6094. if err != nil {
  6095. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6096. return
  6097. }
  6098. if err == nil {
  6099. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  6100. var goods []*models.DialysisBeforePrepareGoods
  6101. var newGoods []*models.NewDialysisBeforePrepareGoods
  6102. var infos []*models.HisDoctorAdviceInfo
  6103. var hisAdvice []*models.HisDoctorAdviceInfo
  6104. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  6105. var infolist []*models.HisDoctorAdviceInfo
  6106. var oldGoods []*models.OldDialysisBeforePrepareGoods
  6107. for _, info := range prescriptions {
  6108. if info.Type == 1 {
  6109. infos = append(infos, info.HisDoctorAdviceInfo...)
  6110. }
  6111. if info.Type == 2 {
  6112. for _, sumItem := range info.HisPrescriptionProject {
  6113. if sumItem.Type == 3 {
  6114. var good models.DialysisBeforePrepareGoods
  6115. var newGood models.NewDialysisBeforePrepareGoods
  6116. good.GoodId = sumItem.GoodInfo.ID
  6117. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6118. count, _ := strconv.Atoi(sumItem.Count)
  6119. good.Count = int64(count)
  6120. good.StorehouseId = houseConfig.StorehouseOutInfo
  6121. good.ProjectId = sumItem.ID
  6122. goods = append(goods, &good)
  6123. newGood.GoodId = sumItem.GoodInfo.ID
  6124. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6125. count2, _ := strconv.Atoi(sumItem.Count)
  6126. newGood.Count = int64(count2)
  6127. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6128. newGood.ProjectId = sumItem.ID
  6129. newGoods = append(newGoods, &newGood)
  6130. }
  6131. }
  6132. }
  6133. }
  6134. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6135. if settConfig.IsOpen == 1 {
  6136. //判断库存的地方
  6137. for _, info := range prescriptions {
  6138. if info.Type == 1 {
  6139. infolist = append(infolist, info.HisDoctorAdviceInfo...)
  6140. }
  6141. if info.Type == 2 {
  6142. for _, sumItem := range info.HisPrescriptionProject {
  6143. if sumItem.Type == 3 {
  6144. var good models.DialysisBeforePrepareGoods
  6145. var newGood models.NewDialysisBeforePrepareGoods
  6146. var oldGood models.OldDialysisBeforePrepareGoods
  6147. good.GoodId = sumItem.GoodInfo.ID
  6148. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6149. count, _ := strconv.Atoi(sumItem.Count)
  6150. good.Count = int64(count)
  6151. good.StorehouseId = houseConfig.StorehouseOutInfo
  6152. good.ProjectId = sumItem.ID
  6153. goods = append(goods, &good)
  6154. newGood.GoodId = sumItem.GoodInfo.ID
  6155. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6156. count2, _ := strconv.Atoi(sumItem.Count)
  6157. newGood.Count = int64(count2)
  6158. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6159. newGood.ProjectId = sumItem.ID
  6160. newGoods = append(newGoods, &newGood)
  6161. oldGood.GoodId = sumItem.GoodInfo.ID
  6162. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6163. count3, _ := strconv.Atoi(sumItem.Count)
  6164. oldGood.Count = int64(count3)
  6165. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  6166. oldGood.ProjectId = sumItem.ID
  6167. oldGood.RecordDate = sumItem.RecordDate
  6168. oldGoods = append(oldGoods, &oldGood)
  6169. }
  6170. }
  6171. }
  6172. }
  6173. for _, info := range prescriptionsOne {
  6174. if info.Type == 1 {
  6175. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  6176. }
  6177. if info.Type == 2 {
  6178. for _, sumItem := range info.HisPrescriptionProject {
  6179. if sumItem.Type == 3 {
  6180. var newGood models.NewDialysisBeforePrepareGoods
  6181. newGood.GoodId = sumItem.GoodInfo.ID
  6182. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6183. count2, _ := strconv.Atoi(sumItem.Count)
  6184. newGood.Count = int64(count2)
  6185. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6186. newGood.ProjectId = sumItem.ID
  6187. newGoodOne = append(newGoodOne, &newGood)
  6188. }
  6189. }
  6190. }
  6191. }
  6192. //判断
  6193. for _, itemOne := range infos {
  6194. for _, itemTwo := range hisAdvice {
  6195. if itemOne.DrugId == itemTwo.DrugId {
  6196. itemTwo.Child = append(itemTwo.ChildDoctorAdvice, itemOne)
  6197. }
  6198. }
  6199. }
  6200. for _, itemTwo := range hisAdvice {
  6201. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  6202. var sum_out_count int64
  6203. for _, itemThree := range itemTwo.Child {
  6204. var prescribing_number int64
  6205. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6206. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6207. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6208. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6209. }
  6210. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6211. prescribing_number = parseIntPrescribingNumber
  6212. }
  6213. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6214. prescribing_number = parseIntPrescribingNumber
  6215. }
  6216. sum_out_count += prescribing_number
  6217. }
  6218. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  6219. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  6220. if sum_out_count > drugStockOut.FlushCount {
  6221. c.ServeSuccessJSON(map[string]interface{}{
  6222. "msg": "2",
  6223. "drug": medical,
  6224. })
  6225. return
  6226. }
  6227. }
  6228. for _, itemOne := range newGoods {
  6229. for _, item := range newGoodOne {
  6230. if itemOne.ProjectId == item.ProjectId {
  6231. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, item)
  6232. }
  6233. }
  6234. }
  6235. for _, item := range newGoodOne {
  6236. var sum_out_count_one int64
  6237. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  6238. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  6239. sum_out_count_one += itemOne.Count
  6240. }
  6241. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6242. fmt.Println("sum_out_count_one", sum_out_count_one)
  6243. fmt.Println("list.FlushCount", list.FlushCount)
  6244. if sum_out_count_one > list.FlushCount {
  6245. c.ServeSuccessJSON(map[string]interface{}{
  6246. "msg": "3",
  6247. "good": good,
  6248. })
  6249. return
  6250. }
  6251. }
  6252. for _, item := range infolist {
  6253. service.HisDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item)
  6254. }
  6255. for _, item := range oldGoods {
  6256. dialyPrepareOne := models.DialysisBeforePrepare{
  6257. GoodTypeId: item.GoodTypeId,
  6258. GoodId: item.GoodId,
  6259. PatientId: item.PatientId,
  6260. RecordDate: item.RecordDate,
  6261. UserOrgId: item.UserOrgId,
  6262. Count: item.Count,
  6263. Ctime: time.Now().Unix(),
  6264. Creater: adminUser.AdminUser.Id,
  6265. CommdityCode: item.CommdityCode,
  6266. Status: 1,
  6267. StorehouseId: houseConfig.StorehouseOutInfo,
  6268. }
  6269. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  6270. }
  6271. service.ConsumablesDeliveryTotal(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, goods, newGoods, adminUser.AdminUser.Id)
  6272. }
  6273. c.ServeSuccessJSON(map[string]interface{}{
  6274. "msg": "结算成功",
  6275. })
  6276. }
  6277. }
  6278. }
  6279. }
  6280. // 退款
  6281. func (c *HisApiController) Refund() {
  6282. order_id, _ := c.GetInt64("order_id")
  6283. order, _ := service.GetHisOrderByID(order_id)
  6284. adminUser := c.GetAdminUserInfo()
  6285. orgid := c.GetAdminUserInfo().CurrentOrgId
  6286. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  6287. if err != nil {
  6288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6289. return
  6290. }
  6291. tmp := strconv.FormatInt(order.ID, 10)
  6292. //当押金不为零时产生退费记录
  6293. if order.Decimal != 0 {
  6294. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  6295. if err != nil {
  6296. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6297. return
  6298. }
  6299. }
  6300. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  6301. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  6302. var goods []*models.DialysisBeforePrepareGoods
  6303. var newGoods []*models.NewDialysisBeforePrepareGoods
  6304. var infos []*models.HisDoctorAdviceInfo
  6305. for _, info := range orders {
  6306. if info.AdviceId > 0 && info.ProjectId == 0 {
  6307. infos = append(infos, &info.HisDoctorAdviceInfo)
  6308. }
  6309. if info.ProjectId > 0 && info.AdviceId == 0 {
  6310. if info.HisPrescriptionProject.Type == 3 {
  6311. var good models.DialysisBeforePrepareGoods
  6312. var newGood models.NewDialysisBeforePrepareGoods
  6313. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6314. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6315. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6316. good.Count = int64(count)
  6317. good.StorehouseId = houseConfig.StorehouseOutInfo
  6318. good.ProjectId = info.HisPrescriptionProject.ID
  6319. good.PatientId = info.PatientId
  6320. good.OrderId = order_id
  6321. goods = append(goods, &good)
  6322. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6323. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6324. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6325. newGood.Count = int64(count2)
  6326. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6327. newGood.ProjectId = info.HisPrescriptionProject.ID
  6328. newGood.RecordDate = order.SettleAccountsDate
  6329. newGood.UserOrgId = order.UserOrgId
  6330. newGood.PatientId = info.PatientId
  6331. newGood.OrderId = order_id
  6332. newGoods = append(newGoods, &newGood)
  6333. }
  6334. }
  6335. }
  6336. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6337. if settConfig.IsOpen == 1 {
  6338. for _, item := range infos {
  6339. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6340. }
  6341. for _, item := range newGoods {
  6342. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6343. }
  6344. }
  6345. c.ServeSuccessJSON(map[string]interface{}{
  6346. "msg": "退费成功",
  6347. })
  6348. }
  6349. func (c *HisApiController) RefundNumber() {
  6350. his_patient_id, _ := c.GetInt64("id")
  6351. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6352. info.Status = 0
  6353. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  6354. if count > 0 {
  6355. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  6356. return
  6357. }
  6358. err := service.SaveHisPatient(info)
  6359. if err == nil {
  6360. c.ServeSuccessJSON(map[string]interface{}{
  6361. "msg": "退号成功",
  6362. })
  6363. } else {
  6364. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6365. return
  6366. }
  6367. }
  6368. func (this *HisApiController) AdditionalCharge() {
  6369. dataBody := make(map[string]interface{}, 0)
  6370. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6371. fmt.Println(err)
  6372. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  6373. patient_id := int64(dataBody["patient_id"].(float64))
  6374. medicineData, _ := dataBody["medicineData"].([]interface{})
  6375. adminUserInfo := this.GetAdminUserInfo()
  6376. orgId := adminUserInfo.CurrentOrgId
  6377. admin_user_id := adminUserInfo.AdminUser.Id
  6378. timeStr := time.Now().Format("2006-01-02")
  6379. timeLayout := "2006-01-02 15:04:05"
  6380. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  6381. timenow := timeStringToTime.Unix()
  6382. var additionalCharges []*models.HisAdditionalCharge
  6383. for _, item := range medicineData {
  6384. var randNum int
  6385. randNum = rand.Intn(10000) + 1000
  6386. timestamp := time.Now().Unix()
  6387. tempTime := time.Unix(timestamp, 0)
  6388. timeFormat := tempTime.Format("20060102150405")
  6389. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  6390. items := item.(map[string]interface{})
  6391. money := items["price"].(string)
  6392. item_id_str := items["item_id"].(string)
  6393. name := items["name"].(string)
  6394. id_str := items["id"].(string)
  6395. moneys, _ := strconv.ParseInt(money, 10, 64)
  6396. monStr := strconv.FormatInt(moneys, 10)
  6397. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  6398. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  6399. id, _ := strconv.ParseInt(id_str, 10, 64)
  6400. additionalCharge := &models.HisAdditionalCharge{
  6401. ID: id,
  6402. HisPatientId: his_patient_id,
  6403. UserOrgId: orgId,
  6404. PatientId: patient_id,
  6405. RecordDate: timenow,
  6406. Price: monneyStr,
  6407. Status: 1,
  6408. ItemName: name,
  6409. ItemId: item_id,
  6410. AdminUserId: admin_user_id,
  6411. CreatedTime: time.Now().Unix(),
  6412. OrderStatus: 0,
  6413. PrescriptionNumber: "",
  6414. BatchNumber: "",
  6415. FeedetlSn: p_number,
  6416. }
  6417. service.CreateAdditionalCharge(additionalCharge)
  6418. additionalCharges = append(additionalCharges, additionalCharge)
  6419. }
  6420. this.ServeSuccessJSON(map[string]interface{}{
  6421. "msg": "添加成功",
  6422. "additional_charges": additionalCharges,
  6423. })
  6424. }
  6425. func (this *HisApiController) DeleteAddition() {
  6426. id, _ := this.GetInt64("id")
  6427. //TODO 需要判断是否已经结算
  6428. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  6429. if err == nil {
  6430. this.ServeSuccessJSON(map[string]interface{}{
  6431. "msg": "删除成功",
  6432. })
  6433. return
  6434. } else {
  6435. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6436. return
  6437. }
  6438. }
  6439. func (this *HisApiController) GetAdminUsers() {
  6440. adminUser := this.GetAdminUserInfo()
  6441. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  6442. this.ServeSuccessJSON(map[string]interface{}{
  6443. "doctors": doctors,
  6444. })
  6445. }
  6446. func (this *HisApiController) GetLastOrNextHisPrescription() {
  6447. change_type, _ := this.GetInt64("type", 0)
  6448. record_date := this.GetString("record_time")
  6449. patient_id, _ := this.GetInt64("patient_id", 0)
  6450. p_type, _ := this.GetInt64("p_type", 0)
  6451. timeLayout := "2006-01-02"
  6452. loc, _ := time.LoadLocation("Local")
  6453. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6454. record_time := theAdviceRecordTime.Unix()
  6455. adminUserInfo := this.GetAdminUserInfo()
  6456. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  6457. if err == nil {
  6458. if len(prescriptions) == 0 {
  6459. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  6460. return
  6461. } else {
  6462. this.ServeSuccessJSON(map[string]interface{}{
  6463. "prescriptions": prescriptions,
  6464. })
  6465. return
  6466. }
  6467. } else {
  6468. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6469. return
  6470. }
  6471. }
  6472. func (this *HisApiController) GetCallHisPrescription() {
  6473. patient_id, _ := this.GetInt64("patient_id", 0)
  6474. timeLayout := "2006-01-02"
  6475. loc, _ := time.LoadLocation("Local")
  6476. start_time := this.GetString("start_time")
  6477. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6478. end_time := this.GetString("end_time")
  6479. p_type, _ := this.GetInt64("p_type")
  6480. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6481. adminUserInfo := this.GetAdminUserInfo()
  6482. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  6483. if err == nil {
  6484. this.ServeSuccessJSON(map[string]interface{}{
  6485. "prescriptions": prescriptions,
  6486. })
  6487. return
  6488. } else {
  6489. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6490. return
  6491. }
  6492. }
  6493. func (this *HisApiController) GetHisDayPrescription() {
  6494. timeLayout := "2006-01-02"
  6495. loc, _ := time.LoadLocation("Local")
  6496. start_time := this.GetString("start_time")
  6497. patient_id, _ := this.GetInt64("patient_id", 0)
  6498. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6499. end_time := this.GetString("end_time")
  6500. p_type, _ := this.GetInt64("p_type")
  6501. order_status, _ := this.GetInt64("type")
  6502. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6503. adminUserInfo := this.GetAdminUserInfo()
  6504. var dayHisPrescription []*models.HisPrescription
  6505. var err error
  6506. if order_status == 1 || order_status == 0 {
  6507. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6508. } else if order_status == 2 {
  6509. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6510. }
  6511. var settle_total float64
  6512. for _, item := range dayHisPrescription {
  6513. if len(item.HisPrescriptionProject) > 0 {
  6514. for _, subItem := range item.HisPrescriptionProject {
  6515. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6516. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6517. settle_total = settle_total + total
  6518. }
  6519. }
  6520. if len(item.HisDoctorAdviceInfo) > 0 {
  6521. for _, subItem := range item.HisDoctorAdviceInfo {
  6522. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6523. settle_total = settle_total + total
  6524. }
  6525. }
  6526. }
  6527. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6528. if err == nil {
  6529. this.ServeSuccessJSON(map[string]interface{}{
  6530. "day_prescription": dayHisPrescription,
  6531. "settle_total": settle_total,
  6532. })
  6533. return
  6534. } else {
  6535. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6536. return
  6537. }
  6538. }
  6539. func (c *HisApiController) GetHisChargePatientList() {
  6540. record_date := c.GetString("record_date")
  6541. order_status, _ := c.GetInt64("type")
  6542. timeLayout := "2006-01-02"
  6543. loc, _ := time.LoadLocation("Local")
  6544. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6545. if err != nil {
  6546. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6547. return
  6548. }
  6549. recordDateTime := theTime.Unix()
  6550. adminInfo := c.GetAdminUserInfo()
  6551. var tempPatients []*service.NewTempPatients
  6552. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6553. if order_status != 2 {
  6554. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6555. } else {
  6556. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6557. }
  6558. var patients []*service.NewTempPatients
  6559. var patients_two []*service.NewTempPatients
  6560. for _, item := range tempPatients {
  6561. //过滤掉没挂号的和没开处方的
  6562. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  6563. patients = append(patients, item)
  6564. }
  6565. //过滤掉没挂号的
  6566. if len(item.HisPatient) > 0 {
  6567. patients_two = append(patients_two, item)
  6568. }
  6569. }
  6570. c.ServeSuccessJSON(map[string]interface{}{
  6571. "list": patients,
  6572. "list_two": patients_two,
  6573. })
  6574. }
  6575. func (c *HisApiController) GetHisUnRegisterPatientList() {
  6576. record_date := c.GetString("record_date")
  6577. timeLayout := "2006-01-02"
  6578. loc, _ := time.LoadLocation("Local")
  6579. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6580. if err != nil {
  6581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6582. return
  6583. }
  6584. recordDateTime := theTime.Unix()
  6585. adminUser := c.GetAdminUserInfo()
  6586. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  6587. var patients []*service.Patients
  6588. for _, item := range tempPatients {
  6589. if item.HisPatient.ID == 0 {
  6590. patients = append(patients, item)
  6591. }
  6592. }
  6593. c.ServeSuccessJSON(map[string]interface{}{
  6594. "list": patients,
  6595. //"list_two": patients_two,
  6596. })
  6597. }
  6598. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  6599. newArr = make([]*service.Patients, 0)
  6600. for i := 0; i < len(patient); i++ {
  6601. repeat := false
  6602. for j := i + 1; j < len(patient); j++ {
  6603. if patient[i].ID == patient[j].ID {
  6604. repeat = true
  6605. break
  6606. }
  6607. }
  6608. if !repeat {
  6609. newArr = append(newArr, patient[i])
  6610. }
  6611. }
  6612. return
  6613. }
  6614. func (c *HisApiController) GetHisChargePatientInfo() {
  6615. patient_id, _ := c.GetInt64("patient_id")
  6616. his_patient_id, _ := c.GetInt64("his_patient_id")
  6617. record_date := c.GetString("record_date")
  6618. //start_time := c.GetString("start_time")
  6619. //end_time := c.GetString("end_time")
  6620. order_status, _ := c.GetInt64("type", 0)
  6621. p_type, _ := c.GetInt64("p_type", 0)
  6622. order_id, _ := c.GetInt64("order_id", 0)
  6623. timeLayout := "2006-01-02"
  6624. loc, _ := time.LoadLocation("Local")
  6625. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6626. if err != nil {
  6627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6628. return
  6629. }
  6630. recordDateTime := theTime.Unix()
  6631. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6632. //if err != nil {
  6633. //
  6634. //}
  6635. //startRecordDateTime := startTime.Unix()
  6636. //
  6637. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6638. //if err != nil {
  6639. //
  6640. //}
  6641. //endRecordDateTime := endTime.Unix()
  6642. admin := c.GetAdminUserInfo()
  6643. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6644. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6645. var prescriptions []*models.HisPrescription
  6646. //var unChargeMonthPrescriptions []*models.HisPrescription
  6647. order, _ := service.GetHisOrderByID(order_id)
  6648. if order_status == 1 || order_status == 0 {
  6649. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  6650. } else if order_status == 2 {
  6651. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  6652. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6653. }
  6654. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6655. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6656. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6657. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6658. //获取所有科室信息
  6659. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6660. c.ServeSuccessJSON(map[string]interface{}{
  6661. "his_info": his_patient_info,
  6662. "xt_info": xt_patient_info,
  6663. "prescription": prescriptions,
  6664. "case_history": case_history,
  6665. "info": patientPrescriptionInfo,
  6666. "last_info": lastPatientPrescriptionInfo,
  6667. "order": order,
  6668. "doctors": doctors,
  6669. "department": department,
  6670. })
  6671. return
  6672. }
  6673. func (c *HisApiController) GetAllOrderDetail() {
  6674. order_id, _ := c.GetInt64("id", 0)
  6675. order, _ := service.GetHisOrderByID(order_id)
  6676. if order.ID == 0 {
  6677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6678. return
  6679. }
  6680. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6681. org_id := c.GetAdminUserInfo().CurrentOrgId
  6682. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6683. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  6684. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6685. c.ServeSuccessJSON(map[string]interface{}{
  6686. "order": order,
  6687. "order_info": order_info,
  6688. "patient": patient,
  6689. "admin_info": adminInfo,
  6690. "hospital_record": record,
  6691. })
  6692. return
  6693. }
  6694. func (c *HisApiController) GetAllOrderDetailCollect() {
  6695. order_id, _ := c.GetInt64("id", 0)
  6696. order, _ := service.GetHisOrderByID(order_id)
  6697. if order.ID == 0 {
  6698. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6699. return
  6700. }
  6701. org_id := c.GetAdminUserInfo().CurrentOrgId
  6702. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6703. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6704. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  6705. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  6706. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  6707. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6708. var bedCostTotal float64 = 0 //床位总费
  6709. //var bedCostSelfTotal float64 = 0 //床位自费
  6710. var operationCostTotal float64 = 0 //手术费
  6711. //var operationCostSelfTotal float64 = 0 //手术费
  6712. var otherCostTotal float64 = 0 //其他费用
  6713. //var otherCostSelfTotal float64 = 0 //其他费用
  6714. var materialCostTotal float64 = 0 //材料费
  6715. //var materialCostSelfTotal float64 = 0 //材料费
  6716. var westernMedicineCostTotal float64 = 0 //西药费
  6717. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  6718. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  6719. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  6720. var checkCostTotal float64 = 0 //检查费
  6721. //var checkCostSelfTotal float64 = 0 //检查费
  6722. var laboratoryCostTotal float64 = 0 //化验费
  6723. //var laboratoryCostSelfTotal float64 = 0 //化验费
  6724. var treatCostTotal float64 = 0 //治疗费用
  6725. //var treatCostSelfTotal float64 = 0 //治疗费用
  6726. var zhenChaCostTotal float64 = 0 //其他费用
  6727. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  6728. decimal.DivisionPrecision = 2
  6729. var BalanceAccountsType int64
  6730. if his.ID > 0 {
  6731. BalanceAccountsType = his.BalanceAccountsType
  6732. } else {
  6733. BalanceAccountsType = record.BalanceAccountsType
  6734. }
  6735. if BalanceAccountsType != 2 {
  6736. for _, item := range order_info {
  6737. if org_id == 10215 {
  6738. if item.MedChrgitmType == "01" { //床位费
  6739. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6740. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6741. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6742. }
  6743. if item.MedChrgitmType == "02" { //诊察费
  6744. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6745. //zhenChaCostSelfTotal = zhenChaCostTotal
  6746. }
  6747. if item.MedChrgitmType == "03" { //检查费
  6748. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6749. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6750. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6751. }
  6752. //if item.MedChrgitmType == "02" { //检查费
  6753. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6754. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6755. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6756. //}
  6757. if item.MedChrgitmType == "04" { //化验费
  6758. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6759. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6760. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6761. }
  6762. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6763. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6764. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6765. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6766. }
  6767. if item.MedChrgitmType == "06" { //手术费
  6768. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6769. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6770. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6771. }
  6772. if item.MedChrgitmType == "08" { //材料费
  6773. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6774. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6775. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6776. }
  6777. if item.MedChrgitmType == "09" { //西药费
  6778. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6779. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6780. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6781. }
  6782. if item.MedChrgitmType == "11" { //中成费
  6783. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6784. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6785. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6786. }
  6787. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  6788. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6789. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6790. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6791. }
  6792. } else if org_id == 10188 || org_id == 10217 {
  6793. if item.MedChrgitmType == "01" { //床位费
  6794. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6795. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6796. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6797. }
  6798. if item.MedChrgitmType == "02" { //诊察费
  6799. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6800. //zhenChaCostSelfTotal = zhenChaCostTotal
  6801. }
  6802. if item.MedChrgitmType == "03" { //检查费
  6803. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6804. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6805. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6806. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6807. }
  6808. //if item.MedChrgitmType == "02" { //检查费
  6809. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6810. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6811. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6812. //}
  6813. if item.MedChrgitmType == "04" { //化验费
  6814. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6815. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6816. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6817. }
  6818. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6819. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6820. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6821. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6822. }
  6823. if item.MedChrgitmType == "06" { //手术费
  6824. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6825. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6826. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6827. }
  6828. if item.MedChrgitmType == "08" { //材料费
  6829. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6830. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6831. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6832. }
  6833. if item.MedChrgitmType == "09" { //西药费
  6834. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6835. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6836. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6837. }
  6838. if item.MedChrgitmType == "11" { //中成费
  6839. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6840. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6841. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6842. }
  6843. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  6844. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6845. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6846. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6847. }
  6848. } else {
  6849. if item.MedChrgitmType == "01" { //床位费
  6850. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6851. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6852. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6853. }
  6854. //if item.MedChrgitmType == "02" { //诊察费
  6855. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6856. // //zhenChaCostSelfTotal = zhenChaCostTotal
  6857. //}
  6858. if item.MedChrgitmType == "03" { //检查费
  6859. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6860. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6861. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6862. }
  6863. //if item.MedChrgitmType == "02" { //检查费
  6864. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6865. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6866. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6867. //}
  6868. if item.MedChrgitmType == "04" { //化验费
  6869. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6870. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6871. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6872. }
  6873. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6874. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6875. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6876. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6877. }
  6878. if item.MedChrgitmType == "06" { //手术费
  6879. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6880. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6881. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6882. }
  6883. if item.MedChrgitmType == "08" { //材料费
  6884. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6885. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6886. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6887. }
  6888. if item.MedChrgitmType == "09" { //西药费
  6889. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6890. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6891. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6892. }
  6893. if item.MedChrgitmType == "11" { //中成费
  6894. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6895. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6896. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6897. }
  6898. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  6899. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6900. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6901. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6902. }
  6903. }
  6904. }
  6905. c.ServeSuccessJSON(map[string]interface{}{
  6906. "order": order,
  6907. "order_info": order_info,
  6908. "patient": patient,
  6909. "admin_info": adminInfo,
  6910. "his_hospital": record,
  6911. "bedCostTotal": bedCostTotal,
  6912. "operationCostTotal": operationCostTotal,
  6913. "otherCostTotal": otherCostTotal,
  6914. "materialCostTotal": materialCostTotal,
  6915. "westernMedicineCostTotal": westernMedicineCostTotal,
  6916. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  6917. "checkCostTotal": checkCostTotal,
  6918. "zhenChaCostTotal": zhenChaCostTotal,
  6919. "laboratoryCostTotal": laboratoryCostTotal,
  6920. "treatCostTotal": treatCostTotal,
  6921. })
  6922. } else {
  6923. for _, item := range order_info {
  6924. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  6925. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  6926. item.MedChrgitmType = "09"
  6927. }
  6928. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  6929. if item.HisPrescriptionProject.Type == 2 {
  6930. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  6931. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  6932. case 0:
  6933. item.MedChrgitmType = "0"
  6934. break
  6935. case 1:
  6936. item.MedChrgitmType = "14"
  6937. break
  6938. case 2:
  6939. item.MedChrgitmType = "05"
  6940. break
  6941. case 3:
  6942. item.MedChrgitmType = "03"
  6943. break
  6944. case 4:
  6945. item.MedChrgitmType = "03"
  6946. break
  6947. case 5:
  6948. item.MedChrgitmType = "08"
  6949. break
  6950. case 6:
  6951. item.MedChrgitmType = "14"
  6952. break
  6953. case 7:
  6954. item.MedChrgitmType = "14"
  6955. break
  6956. case 8:
  6957. item.MedChrgitmType = "03"
  6958. break
  6959. case 9:
  6960. item.MedChrgitmType = "14"
  6961. break
  6962. case 10:
  6963. item.MedChrgitmType = "14"
  6964. break
  6965. case 11:
  6966. item.MedChrgitmType = "06"
  6967. break
  6968. case 12:
  6969. item.MedChrgitmType = "12"
  6970. break
  6971. case 13:
  6972. item.MedChrgitmType = "01"
  6973. break
  6974. case 14:
  6975. item.MedChrgitmType = "04"
  6976. break
  6977. case 15:
  6978. item.MedChrgitmType = "14"
  6979. break
  6980. }
  6981. } else {
  6982. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  6983. case 1:
  6984. item.MedChrgitmType = "14"
  6985. break
  6986. case 2:
  6987. item.MedChrgitmType = "05"
  6988. break
  6989. case 3:
  6990. item.MedChrgitmType = "04"
  6991. break
  6992. case 4:
  6993. item.MedChrgitmType = "14"
  6994. break
  6995. case 5:
  6996. item.MedChrgitmType = "08"
  6997. break
  6998. case 6:
  6999. item.MedChrgitmType = "14"
  7000. break
  7001. case 7:
  7002. item.MedChrgitmType = "14"
  7003. break
  7004. case 8:
  7005. item.MedChrgitmType = "03"
  7006. break
  7007. case 9:
  7008. item.MedChrgitmType = "14"
  7009. break
  7010. }
  7011. }
  7012. } else if item.HisPrescriptionProject.Type == 3 {
  7013. item.MedChrgitmType = "08"
  7014. }
  7015. }
  7016. }
  7017. for _, item := range order_info {
  7018. if org_id == 10215 {
  7019. if item.MedChrgitmType == "01" { //床位费
  7020. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7021. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7022. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7023. }
  7024. if item.MedChrgitmType == "02" { //诊察费
  7025. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7026. //zhenChaCostSelfTotal = zhenChaCostTotal
  7027. }
  7028. if item.MedChrgitmType == "03" { //检查费
  7029. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7030. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7031. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7032. }
  7033. //if item.MedChrgitmType == "02" { //检查费
  7034. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7035. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7036. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7037. //}
  7038. if item.MedChrgitmType == "04" { //化验费
  7039. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7040. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7041. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7042. }
  7043. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7044. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7045. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7046. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7047. }
  7048. if item.MedChrgitmType == "06" { //手术费
  7049. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7050. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7051. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7052. }
  7053. if item.MedChrgitmType == "08" { //材料费
  7054. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7055. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7056. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7057. }
  7058. if item.MedChrgitmType == "09" { //西药费
  7059. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7060. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7061. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7062. }
  7063. if item.MedChrgitmType == "11" { //中成费
  7064. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7065. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7066. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7067. }
  7068. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7069. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7070. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7071. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7072. }
  7073. } else {
  7074. if item.MedChrgitmType == "01" { //床位费
  7075. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7076. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7077. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7078. }
  7079. //if item.MedChrgitmType == "02" { //诊察费
  7080. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7081. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7082. //}
  7083. if item.MedChrgitmType == "03" { //检查费
  7084. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7085. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7086. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7087. }
  7088. //if item.MedChrgitmType == "02" { //检查费
  7089. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7090. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7091. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7092. //}
  7093. if item.MedChrgitmType == "04" { //化验费
  7094. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7095. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7096. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7097. }
  7098. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7099. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7100. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7101. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7102. }
  7103. if item.MedChrgitmType == "06" { //手术费
  7104. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7105. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7106. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7107. }
  7108. if item.MedChrgitmType == "08" { //材料费
  7109. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7110. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7111. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7112. }
  7113. if item.MedChrgitmType == "09" { //西药费
  7114. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7115. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7116. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7117. }
  7118. if item.MedChrgitmType == "11" { //中成费
  7119. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7120. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7121. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7122. }
  7123. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7124. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7125. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7126. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7127. }
  7128. }
  7129. }
  7130. c.ServeSuccessJSON(map[string]interface{}{
  7131. "order": order,
  7132. "order_info": order_info,
  7133. "patient": patient,
  7134. "admin_info": adminInfo,
  7135. "his_hospital": record,
  7136. "bedCostTotal": bedCostTotal,
  7137. "operationCostTotal": operationCostTotal,
  7138. "otherCostTotal": otherCostTotal,
  7139. "materialCostTotal": materialCostTotal,
  7140. "westernMedicineCostTotal": westernMedicineCostTotal,
  7141. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7142. "checkCostTotal": checkCostTotal,
  7143. "zhenChaCostTotal": zhenChaCostTotal,
  7144. "laboratoryCostTotal": laboratoryCostTotal,
  7145. "treatCostTotal": treatCostTotal,
  7146. })
  7147. }
  7148. }
  7149. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  7150. page, _ := c.GetInt64("page")
  7151. limit, _ := c.GetInt64("limit")
  7152. keywords := c.GetString("keywords")
  7153. start_time := c.GetString("start_time")
  7154. end_time := c.GetString("end_time")
  7155. //clr_type := c.GetString("clr_type")
  7156. insutype := c.GetString("insutype")
  7157. timeLayout := "2006-01-02"
  7158. loc, _ := time.LoadLocation("Local")
  7159. var theStartTIme int64
  7160. if len(start_time) > 0 {
  7161. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7162. theStartTIme = theTime.Unix()
  7163. }
  7164. var theEndtTIme int64
  7165. if len(end_time) > 0 {
  7166. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7167. theEndtTIme = theTime.Unix()
  7168. }
  7169. if page <= 0 {
  7170. page = 1
  7171. }
  7172. if limit <= 0 {
  7173. limit = 10
  7174. }
  7175. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  7176. c.ServeSuccessJSON(map[string]interface{}{
  7177. "total": total,
  7178. "list": list,
  7179. })
  7180. return
  7181. }
  7182. func (c *HisApiController) GetPutOnRecordList() {
  7183. page, _ := c.GetInt64("page")
  7184. limit, _ := c.GetInt64("limit")
  7185. keywords := c.GetString("keywords")
  7186. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  7187. if page <= 0 {
  7188. page = 1
  7189. }
  7190. if limit <= 0 {
  7191. limit = 10
  7192. }
  7193. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  7194. c.ServeSuccessJSON(map[string]interface{}{
  7195. "total": total,
  7196. "list": list,
  7197. })
  7198. return
  7199. }
  7200. func (c *HisApiController) GetCompareData() {
  7201. start_time := c.GetString("start_time")
  7202. end_time := c.GetString("end_time")
  7203. insutype := c.GetString("insutype")
  7204. clr_type := c.GetString("clr_type")
  7205. timeLayout := "2006-01-02"
  7206. loc, _ := time.LoadLocation("Local")
  7207. var theStartTIme int64
  7208. if len(start_time) > 0 {
  7209. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7210. if err != nil {
  7211. theStartTIme = 0
  7212. }
  7213. theStartTIme = theTime.Unix()
  7214. }
  7215. var theEndtTIme int64
  7216. if len(end_time) > 0 {
  7217. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7218. if err != nil {
  7219. theEndtTIme = 0
  7220. }
  7221. theEndtTIme = theTime.Unix()
  7222. }
  7223. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  7224. fmt.Println(err)
  7225. if err == nil {
  7226. c.ServeSuccessJSON(map[string]interface{}{
  7227. "list": formData,
  7228. })
  7229. } else {
  7230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7231. return
  7232. }
  7233. }
  7234. func (c *HisApiController) GetFaPiaoData() {
  7235. order_id, _ := c.GetInt64("order_id")
  7236. patient_id, _ := c.GetInt64("patient_id")
  7237. number := c.GetString("number")
  7238. adminUser := c.GetAdminUserInfo()
  7239. order, _ := service.GetHisOrderByID(order_id)
  7240. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  7241. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  7242. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  7243. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, number)
  7244. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7245. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  7246. var bedCostTotal float64 = 0 //床位总费
  7247. var bedCostSelfTotal float64 = 0 //床位自费
  7248. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  7249. var operationCostTotal float64 = 0 //手术费
  7250. var operationCostSelfTotal float64 = 0 //手术费
  7251. var operationCostPartSelfTotal float64 = 0 //手术费
  7252. var otherCostTotal float64 = 0 //其他费用
  7253. var otherCostSelfTotal float64 = 0 //其他费用
  7254. var otherCostPartSelfTotal float64 = 0 //其他费用
  7255. var materialCostTotal float64 = 0 //材料费
  7256. var materialCostSelfTotal float64 = 0 //材料费
  7257. var materialCostPartSelfTotal float64 = 0 //材料费
  7258. var westernMedicineCostTotal float64 = 0 //西药费
  7259. var westernMedicineCostSelfTotal float64 = 0 //西药费
  7260. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  7261. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7262. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7263. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  7264. var checkCostTotal float64 = 0 //检查费
  7265. var checkCostSelfTotal float64 = 0 //检查费
  7266. var checkCostPartSelfTotal float64 = 0 //检查费
  7267. var laboratoryCostTotal float64 = 0 //化验费
  7268. var laboratoryCostSelfTotal float64 = 0 //化验费
  7269. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  7270. var treatCostTotal float64 = 0 //治疗费用
  7271. var treatCostSelfTotal float64 = 0 //治疗费用
  7272. var treatCostPartSelfTotal float64 = 0 //治疗费用
  7273. var zhenChaCostTotal float64 = 0 //其他费用
  7274. var zhenChaCostSelfTotal float64 = 0 //其他费用
  7275. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7276. decimal.DivisionPrecision = 2
  7277. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7278. var balanceAccountsType int64
  7279. if his.ID > 0 {
  7280. balanceAccountsType = his.BalanceAccountsType
  7281. } else {
  7282. balanceAccountsType = his_hospital_record.BalanceAccountsType
  7283. }
  7284. if balanceAccountsType == 2 {
  7285. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7286. for _, item := range orderInfos_two {
  7287. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7288. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7289. item.MedChrgitmType = "09"
  7290. }
  7291. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7292. if item.HisPrescriptionProject.Type == 2 {
  7293. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7294. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7295. case 0:
  7296. item.MedChrgitmType = "0"
  7297. break
  7298. case 1:
  7299. item.MedChrgitmType = "14"
  7300. break
  7301. case 2:
  7302. item.MedChrgitmType = "05"
  7303. break
  7304. case 3:
  7305. item.MedChrgitmType = "03"
  7306. break
  7307. case 4:
  7308. item.MedChrgitmType = "03"
  7309. break
  7310. case 5:
  7311. item.MedChrgitmType = "08"
  7312. break
  7313. case 6:
  7314. item.MedChrgitmType = "14"
  7315. break
  7316. case 7:
  7317. item.MedChrgitmType = "14"
  7318. break
  7319. case 8:
  7320. item.MedChrgitmType = "03"
  7321. break
  7322. case 9:
  7323. item.MedChrgitmType = "14"
  7324. break
  7325. case 10:
  7326. item.MedChrgitmType = "14"
  7327. break
  7328. case 11:
  7329. item.MedChrgitmType = "06"
  7330. break
  7331. case 12:
  7332. item.MedChrgitmType = "12"
  7333. break
  7334. case 13:
  7335. item.MedChrgitmType = "01"
  7336. break
  7337. case 14:
  7338. item.MedChrgitmType = "04"
  7339. break
  7340. case 15:
  7341. item.MedChrgitmType = "02"
  7342. break
  7343. }
  7344. } else {
  7345. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7346. case 1:
  7347. item.MedChrgitmType = "14"
  7348. break
  7349. case 2:
  7350. item.MedChrgitmType = "05"
  7351. break
  7352. case 3:
  7353. item.MedChrgitmType = "03"
  7354. break
  7355. case 4:
  7356. item.MedChrgitmType = "03"
  7357. break
  7358. case 5:
  7359. item.MedChrgitmType = "08"
  7360. break
  7361. case 6:
  7362. item.MedChrgitmType = "14"
  7363. break
  7364. case 7:
  7365. item.MedChrgitmType = "14"
  7366. break
  7367. case 8:
  7368. item.MedChrgitmType = "03"
  7369. break
  7370. case 9:
  7371. item.MedChrgitmType = "14"
  7372. break
  7373. }
  7374. }
  7375. } else if item.HisPrescriptionProject.Type == 3 {
  7376. item.MedChrgitmType = "08"
  7377. }
  7378. }
  7379. }
  7380. for _, item := range orderInfos_two {
  7381. fmt.Println(item.MedChrgitmType)
  7382. if item.MedChrgitmType == "01" { //床位费
  7383. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7384. bedCostSelfTotal = bedCostTotal
  7385. }
  7386. if item.MedChrgitmType == "02" { //诊察费
  7387. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7388. zhenChaCostSelfTotal = zhenChaCostTotal
  7389. }
  7390. if item.MedChrgitmType == "03" { //检查费
  7391. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7392. checkCostSelfTotal = checkCostTotal
  7393. }
  7394. if item.MedChrgitmType == "04" { //化验费
  7395. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7396. laboratoryCostSelfTotal = laboratoryCostTotal
  7397. }
  7398. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  7399. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7400. treatCostSelfTotal = treatCostTotal
  7401. }
  7402. if item.MedChrgitmType == "06" { //手术费
  7403. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7404. operationCostSelfTotal = treatCostTotal
  7405. }
  7406. if item.MedChrgitmType == "08" { //材料费
  7407. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7408. materialCostSelfTotal = materialCostTotal
  7409. }
  7410. if item.MedChrgitmType == "09" { //西药费
  7411. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7412. westernMedicineCostSelfTotal = westernMedicineCostTotal
  7413. }
  7414. if item.MedChrgitmType == "11" { //中成费
  7415. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7416. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  7417. }
  7418. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  7419. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7420. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7421. otherCostSelfTotal = otherCostTotal
  7422. }
  7423. } else {
  7424. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7425. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7426. otherCostSelfTotal = otherCostTotal
  7427. }
  7428. }
  7429. }
  7430. } else {
  7431. for _, item := range orderInfos {
  7432. if item.MedChrgitmType == "01" { //床位费
  7433. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7434. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7435. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7436. }
  7437. if item.MedChrgitmType == "02" { //诊察费
  7438. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7439. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7440. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7441. }
  7442. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  7443. if item.MedChrgitmType == "03" { //检查费
  7444. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7445. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7446. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7447. }
  7448. } else {
  7449. if item.MedChrgitmType == "03" { //检查费
  7450. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7451. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7452. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7453. }
  7454. }
  7455. if item.MedChrgitmType == "04" { //化验费
  7456. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7457. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7458. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7459. }
  7460. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7461. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7462. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7463. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7464. }
  7465. if item.MedChrgitmType == "06" { //手术费
  7466. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7467. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7468. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7469. }
  7470. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  7471. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7472. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7473. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7474. }
  7475. if item.MedChrgitmType == "09" { //西药费
  7476. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7477. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7478. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7479. }
  7480. if item.MedChrgitmType == "11" { //中成费
  7481. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7482. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7483. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7484. }
  7485. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7486. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7487. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7488. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7489. }
  7490. }
  7491. }
  7492. timeLayout := "2006-01-02"
  7493. loc, _ := time.LoadLocation("Local")
  7494. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  7495. if err != nil {
  7496. }
  7497. startRecordDateTime := startTime.Unix()
  7498. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  7499. if err != nil {
  7500. }
  7501. endRecordDateTime := endTime.Unix()
  7502. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  7503. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  7504. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  7505. c.ServeSuccessJSON(map[string]interface{}{
  7506. "order_number": order.Number, //业务流水号
  7507. "id_card_no": his.IdCardNo, //社会保障号
  7508. "department_name": department.Name, //科室
  7509. "number": his.Number, //门诊号
  7510. "date": order.SettleAccountsDate, //结算日期
  7511. "name": order.PsnName, //姓名
  7512. "gender": patient.Gender, //性别
  7513. "psn_cash_money": order.PsnCashPay, //个人支付
  7514. "pay_way": "门诊", //结算方式
  7515. "medfee_sumamt": order.MedfeeSumamt, //总费用
  7516. "admin_user_name": admin.UserName, //收款员
  7517. "order": order,
  7518. "order_info": orderInfos_two,
  7519. "his": his,
  7520. "bedCostTotal": bedCostTotal,
  7521. "bedCostSelfTotal": bedCostSelfTotal,
  7522. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  7523. "operationCostTotal": operationCostTotal,
  7524. "operationCostSelfTotal": operationCostSelfTotal,
  7525. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  7526. "otherCostTotal": otherCostTotal,
  7527. "otherCostSelfTotal": otherCostSelfTotal,
  7528. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  7529. "materialCostTotal": materialCostTotal,
  7530. "materialCostSelfTotal": materialCostSelfTotal,
  7531. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  7532. "westernMedicineCostTotal": westernMedicineCostTotal,
  7533. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  7534. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  7535. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7536. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  7537. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  7538. "checkCostTotal": checkCostTotal,
  7539. "checkCostSelfTotal": checkCostSelfTotal,
  7540. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  7541. "laboratoryCostTotal": laboratoryCostTotal,
  7542. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  7543. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  7544. "treatCostTotal": treatCostTotal,
  7545. "treatCostSelfTotal": treatCostSelfTotal,
  7546. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  7547. "zhenChaCostTotal": zhenChaCostTotal,
  7548. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  7549. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  7550. "his_hospital_record": his_hospital_record,
  7551. "pre_pay_money": pre_pay_money,
  7552. "refund_sum": sum,
  7553. })
  7554. }
  7555. func (this *HisApiController) GetIncomeStatisticsData() {
  7556. start_time := this.GetString("start_time")
  7557. end_time := this.GetString("end_time")
  7558. key_words := this.GetString("key_words")
  7559. limit, _ := this.GetInt64("limit")
  7560. page, _ := this.GetInt64("page")
  7561. if page <= 0 {
  7562. page = 1
  7563. }
  7564. if limit <= 0 {
  7565. limit = 10
  7566. }
  7567. statistics_type, _ := this.GetInt64("statistics_type")
  7568. admin := this.GetAdminUserInfo()
  7569. timeLayout := "2006-01-02"
  7570. loc, _ := time.LoadLocation("Local")
  7571. var theStartTIme int64
  7572. if len(start_time) > 0 {
  7573. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7574. if err != nil {
  7575. theStartTIme = 0
  7576. }
  7577. theStartTIme = theTime.Unix()
  7578. }
  7579. var theEndtTIme int64
  7580. if len(end_time) > 0 {
  7581. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7582. if err != nil {
  7583. theEndtTIme = 0
  7584. }
  7585. theEndtTIme = theTime.Unix()
  7586. }
  7587. if statistics_type == 1 {
  7588. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  7589. this.ServeSuccessJSON(map[string]interface{}{
  7590. "list": list,
  7591. "total": total,
  7592. })
  7593. } else {
  7594. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  7595. this.ServeSuccessJSON(map[string]interface{}{
  7596. "list": list,
  7597. "total": total,
  7598. })
  7599. }
  7600. }
  7601. func (c *HisApiController) PostProjectInformation() {
  7602. adminUser := c.GetAdminUserInfo()
  7603. orgId := adminUser.CurrentOrgId
  7604. dataBody := make(map[string]interface{}, 0)
  7605. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7606. if err != nil {
  7607. utils.ErrorLog(err.Error())
  7608. return
  7609. }
  7610. utils.ErrorLog("%v", dataBody)
  7611. var projectList []*models.HisProject
  7612. var total_goods []interface{}
  7613. tempProjects := dataBody["projects"].([]interface{})
  7614. total_goods = tempProjects
  7615. for index, projectMap := range tempProjects {
  7616. projectM := projectMap.(map[string]interface{})
  7617. var project models.HisProject
  7618. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  7619. utils.ErrorLog("project_name")
  7620. return
  7621. }
  7622. project_name, _ := projectM["project_name"].(string)
  7623. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  7624. err_log := models.ExportErrLog{
  7625. LogType: 6,
  7626. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7627. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  7628. Status: 1,
  7629. CreateTime: time.Now().Unix(),
  7630. UpdateTime: time.Now().Unix(),
  7631. ExportTime: time.Now().Unix(),
  7632. }
  7633. service.CreateExportErrLog(&err_log)
  7634. continue
  7635. }
  7636. project.ProjectName = project_name
  7637. prices := projectM["price"].(string)
  7638. price, _ := strconv.ParseFloat(prices, 64)
  7639. if price <= 0 { //名字为空则生成一条导入错误日志
  7640. err_log := models.ExportErrLog{
  7641. LogType: 6,
  7642. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7643. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  7644. Status: 1,
  7645. CreateTime: time.Now().Unix(),
  7646. UpdateTime: time.Now().Unix(),
  7647. ExportTime: time.Now().Unix(),
  7648. }
  7649. service.CreateExportErrLog(&err_log)
  7650. continue
  7651. }
  7652. project.Price = price
  7653. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  7654. utils.ErrorLog("unit_id")
  7655. return
  7656. }
  7657. unit := projectM["unit"].(string)
  7658. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  7659. err_log := models.ExportErrLog{
  7660. LogType: 6,
  7661. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7662. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  7663. Status: 1,
  7664. CreateTime: time.Now().Unix(),
  7665. UpdateTime: time.Now().Unix(),
  7666. ExportTime: time.Now().Unix(),
  7667. }
  7668. service.CreateExportErrLog(&err_log)
  7669. continue
  7670. }
  7671. project.Unit = unit
  7672. cost_classify := projectM["cost_classify"].(string)
  7673. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  7674. err_log := models.ExportErrLog{
  7675. LogType: 6,
  7676. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7677. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  7678. Status: 1,
  7679. CreateTime: time.Now().Unix(),
  7680. UpdateTime: time.Now().Unix(),
  7681. ExportTime: time.Now().Unix(),
  7682. }
  7683. service.CreateExportErrLog(&err_log)
  7684. continue
  7685. }
  7686. var costClassify = "费用类别"
  7687. var cost_classify_id int64
  7688. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  7689. if len(cost_classify) != 0 {
  7690. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  7691. if errcode == gorm.ErrRecordNotFound {
  7692. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  7693. dataconfig := models.DictDataconfig{
  7694. ParentId: costClassifyConfig.ID,
  7695. Module: "system",
  7696. OrgId: orgId,
  7697. Name: cost_classify,
  7698. FieldName: "",
  7699. Value: costConfig.Value + 1,
  7700. CreatedTime: "",
  7701. UpdatedTime: "",
  7702. CreateUserId: adminUser.AdminUser.Id,
  7703. Status: 1,
  7704. Remark: "",
  7705. DeleteIdSystem: 0,
  7706. Title: "",
  7707. Content: "",
  7708. Order: 0,
  7709. Code: "",
  7710. }
  7711. service.CreatedDicConfig(&dataconfig)
  7712. }
  7713. }
  7714. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  7715. for _, it := range costClassList {
  7716. if cost_classify == it.Name {
  7717. cost_classify_id = int64(it.Value)
  7718. }
  7719. }
  7720. project.CostClassify = cost_classify_id
  7721. executive_section := projectM["executive_section"].(string)
  7722. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  7723. err_log := models.ExportErrLog{
  7724. LogType: 6,
  7725. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7726. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  7727. Status: 1,
  7728. CreateTime: time.Now().Unix(),
  7729. UpdateTime: time.Now().Unix(),
  7730. ExportTime: time.Now().Unix(),
  7731. }
  7732. service.CreateExportErrLog(&err_log)
  7733. continue
  7734. }
  7735. if len(executive_section) != 0 {
  7736. //查找科室是否有内容
  7737. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  7738. if errcodedepart == gorm.ErrRecordNotFound {
  7739. department := models.XtHisDepartment{
  7740. Name: executive_section,
  7741. Status: 1,
  7742. UserOrgId: adminUser.CurrentOrgId,
  7743. CreatedTime: time.Now().Unix(),
  7744. }
  7745. service.CreateDePartment(&department)
  7746. }
  7747. }
  7748. var executive_section_id int64
  7749. departMentList, _ := service.GetAllDepartMent(orgId)
  7750. for _, it := range departMentList {
  7751. if executive_section == it.Name {
  7752. executive_section_id = it.ID
  7753. }
  7754. }
  7755. project.ExecutiveSection = executive_section_id
  7756. medical_coverage := projectM["medical_coverage"].(string)
  7757. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  7758. err_log := models.ExportErrLog{
  7759. LogType: 6,
  7760. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7761. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  7762. Status: 1,
  7763. CreateTime: time.Now().Unix(),
  7764. UpdateTime: time.Now().Unix(),
  7765. ExportTime: time.Now().Unix(),
  7766. }
  7767. service.CreateExportErrLog(&err_log)
  7768. continue
  7769. }
  7770. var medicalCoverage = "医保等级"
  7771. var medical_coverage_id int64
  7772. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  7773. if len(medical_coverage) != 0 {
  7774. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  7775. if errormedicalcoverage == gorm.ErrRecordNotFound {
  7776. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  7777. dataconfig := models.DictDataconfig{
  7778. ParentId: medicalCoverageConfig.ID,
  7779. Module: "system",
  7780. OrgId: orgId,
  7781. Name: medical_coverage,
  7782. FieldName: "",
  7783. Value: medicalCoverageConfig.Value + 1,
  7784. CreatedTime: "",
  7785. UpdatedTime: "",
  7786. CreateUserId: adminUser.AdminUser.Id,
  7787. Status: 1,
  7788. Remark: "",
  7789. DeleteIdSystem: 0,
  7790. Title: "",
  7791. Content: "",
  7792. Order: 0,
  7793. Code: "",
  7794. }
  7795. service.CreatedDicConfig(&dataconfig)
  7796. }
  7797. }
  7798. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  7799. for _, it := range medicalCoverageList {
  7800. if medical_coverage == it.Name {
  7801. medical_coverage_id = int64(it.Value)
  7802. }
  7803. }
  7804. project.MedicalCoverage = medical_coverage_id
  7805. pinyin := projectM["pinyin"].(string)
  7806. project.Pinyin = pinyin
  7807. wubi := projectM["wubi"].(string)
  7808. project.Wubi = wubi
  7809. statistical_classification := projectM["statistical_classification"].(string)
  7810. var statisticalClassification = "统计分类"
  7811. var statistical_classification_id int64
  7812. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  7813. if len(statistical_classification) != 0 {
  7814. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  7815. if classificationerrcodes == gorm.ErrRecordNotFound {
  7816. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  7817. dataconfig := models.DictDataconfig{
  7818. ParentId: classiFication.ID,
  7819. Module: "system",
  7820. OrgId: orgId,
  7821. Name: statistical_classification,
  7822. FieldName: "",
  7823. Value: classiFicationConfig.Value + 1,
  7824. CreatedTime: "",
  7825. UpdatedTime: "",
  7826. CreateUserId: adminUser.AdminUser.Id,
  7827. Status: 1,
  7828. Remark: "",
  7829. DeleteIdSystem: 0,
  7830. Title: "",
  7831. Content: "",
  7832. Order: 0,
  7833. Code: "",
  7834. }
  7835. service.CreatedDicConfig(&dataconfig)
  7836. }
  7837. }
  7838. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  7839. for _, it := range classiFicationList {
  7840. if statistical_classification == it.Name {
  7841. statistical_classification_id = int64(it.Value)
  7842. }
  7843. }
  7844. project.StatisticalClassification = statistical_classification_id
  7845. disease_directory := int64(projectM["disease_directory"].(float64))
  7846. project.DiseaseDirectory = disease_directory
  7847. is_record := int64(projectM["is_record"].(float64))
  7848. project.IsRecord = is_record
  7849. medical_code := projectM["medical_code"].(string)
  7850. project.MedicalCode = medical_code
  7851. tube_color := projectM["tube_color"].(string)
  7852. var tubeColor = "试管颜色"
  7853. var tube_color_id int64
  7854. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  7855. if len(tube_color) != 0 {
  7856. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  7857. if errcodetube == gorm.ErrRecordNotFound {
  7858. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  7859. dataconfig := models.DictDataconfig{
  7860. ParentId: tubeColorConfig.ID,
  7861. Module: "system",
  7862. OrgId: orgId,
  7863. Name: tube_color,
  7864. FieldName: "",
  7865. Value: tubeConfig.Value + 1,
  7866. CreatedTime: "",
  7867. UpdatedTime: "",
  7868. CreateUserId: adminUser.AdminUser.Id,
  7869. Status: 1,
  7870. Remark: "",
  7871. DeleteIdSystem: 0,
  7872. Title: "",
  7873. Content: "",
  7874. Order: 0,
  7875. Code: "",
  7876. }
  7877. service.CreatedDicConfig(&dataconfig)
  7878. }
  7879. }
  7880. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  7881. for _, it := range tubeColorList {
  7882. if tube_color == it.Name {
  7883. tube_color_id = int64(it.Value)
  7884. }
  7885. }
  7886. project.TubeColor = tube_color_id
  7887. single_dose := projectM["single_dose"].(string)
  7888. project.SingleDose = single_dose
  7889. execution_frequency := projectM["execution_frequency"].(string)
  7890. project.ExecutionFrequency = execution_frequency
  7891. delivery_way := projectM["delivery_way"].(string)
  7892. project.DeliveryWay = delivery_way
  7893. number_days := projectM["number_days"].(string)
  7894. project.NumberDays = number_days
  7895. total := projectM["total"].(string)
  7896. project.Total = total
  7897. medical_status := int64(projectM["medical_status"].(float64))
  7898. project.MedicalStatus = medical_status
  7899. category := int64(projectM["category"].(float64))
  7900. project.Category = category
  7901. specail_project := int64(projectM["specail_project"].(float64))
  7902. project.SpecailProject = specail_project
  7903. social_security_directory_code := projectM["social_security_directory_code"].(string)
  7904. project.SocialSecurityDirectoryCode = social_security_directory_code
  7905. remark := projectM["remark"].(string)
  7906. project.Remark = remark
  7907. record_date := projectM["record_date"].(string)
  7908. timeLayout := "2006-01-02"
  7909. loc, _ := time.LoadLocation("Local")
  7910. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7911. project.RecordDate = theTime.Unix()
  7912. projectList = append(projectList, &project)
  7913. }
  7914. export_time := time.Now().Unix()
  7915. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  7916. if len(projectList) > 0 {
  7917. for _, item := range projectList {
  7918. project := models.HisProject{
  7919. ProjectName: item.ProjectName,
  7920. Price: item.Price,
  7921. Unit: item.Unit,
  7922. CostClassify: item.CostClassify,
  7923. ExecutiveSection: item.ExecutiveSection,
  7924. MedicalCoverage: item.MedicalCoverage,
  7925. UserOrgId: orgId,
  7926. Status: 1,
  7927. CreatedTime: time.Now().Unix(),
  7928. Pinyin: item.Pinyin,
  7929. Wubi: item.Wubi,
  7930. StatisticalClassification: item.StatisticalClassification,
  7931. DiseaseDirectory: item.DiseaseDirectory,
  7932. IsRecord: item.IsRecord,
  7933. MedicalCode: item.MedicalCode,
  7934. TubeColor: item.TubeColor,
  7935. SingleDose: item.SingleDose,
  7936. DeliveryWay: item.DeliveryWay,
  7937. NumberDays: item.NumberDays,
  7938. Total: item.Total,
  7939. Category: item.Category,
  7940. MedicalStatus: item.MedicalStatus,
  7941. SpecailProject: item.SpecailProject,
  7942. RecordDate: item.RecordDate,
  7943. Remark: item.Remark,
  7944. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  7945. ExecutionFrequency: item.ExecutionFrequency,
  7946. }
  7947. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  7948. if errcodeproject == gorm.ErrRecordNotFound {
  7949. service.CreateProjectInfomation(&project)
  7950. } else if errcodeproject == nil {
  7951. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  7952. }
  7953. log := models.ExportLog{
  7954. LogType: 6,
  7955. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7956. TotalNum: int64(len(total_goods)),
  7957. FailNum: int64(len(errLogs)),
  7958. SuccessNum: int64(len(projectList)),
  7959. CreateTime: time.Now().Unix(),
  7960. UpdateTime: time.Now().Unix(),
  7961. ExportTime: export_time,
  7962. Status: 1,
  7963. }
  7964. service.CreateExportLog(&log)
  7965. c.ServeSuccessJSON(map[string]interface{}{
  7966. "msg": "导入成功",
  7967. "total_num": len(total_goods),
  7968. "success_num": len(projectList),
  7969. "fail_num": int64(len(errLogs)),
  7970. })
  7971. }
  7972. } else {
  7973. log := models.ExportLog{
  7974. LogType: 6,
  7975. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7976. TotalNum: int64(len(total_goods)),
  7977. FailNum: int64(len(errLogs)),
  7978. SuccessNum: int64(len(projectList)),
  7979. CreateTime: time.Now().Unix(),
  7980. UpdateTime: time.Now().Unix(),
  7981. ExportTime: export_time,
  7982. Status: 1,
  7983. }
  7984. service.CreateExportLog(&log)
  7985. c.ServeSuccessJSON(map[string]interface{}{
  7986. "msg": "导入成功",
  7987. "total_num": len(total_goods),
  7988. "success_num": len(projectList),
  7989. "fail_num": int64(len(errLogs)),
  7990. })
  7991. }
  7992. }
  7993. //func (this *HisApiController) EditProjectInformation(){
  7994. //
  7995. // id, _ := this.GetInt64("id")
  7996. // project_team := this.GetString("project_team")
  7997. // price := this.GetString("price")
  7998. // price_float, _ := strconv.ParseFloat(price, 64)
  7999. // pinyin := this.GetString("pinyin")
  8000. // wubi := this.GetString("wubi")
  8001. // tube_color, _ := this.GetInt64("tube_color")
  8002. // team_type, _ := this.GetInt64("team_type")
  8003. // remark := this.GetString("remark")
  8004. // ids := this.GetString("ids")
  8005. // item_id := this.GetString("item_id")
  8006. // projectTeam := models.XtHisProjectTeam{
  8007. // ProjectTeam: project_team,
  8008. // Price: price_float,
  8009. // Pinyin: pinyin,
  8010. // Wubi: wubi,
  8011. // TubeColor: tube_color,
  8012. // TeamType: team_type,
  8013. // Remark: remark,
  8014. // ProjectId: ids,
  8015. // ItemId: item_id,
  8016. // }
  8017. //
  8018. //
  8019. // dataBody := make(map[string]interface{}, 0)
  8020. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8021. // if err != nil {
  8022. // utils.ErrorLog(err.Error())
  8023. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8024. // return
  8025. // }
  8026. //
  8027. // err = service.UpdatedProjectTeam(id, &projectTeam)
  8028. //
  8029. //
  8030. // if err != nil {
  8031. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  8032. // return
  8033. // }
  8034. //
  8035. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  8036. // infos, _ := dataBody["info"].([]interface{})
  8037. // if len(infos) > 0 {
  8038. // var ids []string
  8039. //
  8040. // for _, item := range infos {
  8041. // items := item.(map[string]interface{})
  8042. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  8043. // utils.ErrorLog("id")
  8044. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8045. // return
  8046. // }
  8047. // id := int64(items["id"].(float64))
  8048. //
  8049. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8050. // utils.ErrorLog("type")
  8051. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8052. // return
  8053. // }
  8054. // types := int64(items["type"].(float64))
  8055. //
  8056. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  8057. // utils.ErrorLog("number")
  8058. // }
  8059. //
  8060. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  8061. //
  8062. // projectList := models.XtHisProjectList{
  8063. // Number: number,
  8064. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  8065. // ProjectId: id,
  8066. // Status: 1,
  8067. // CreatedTime: time.Now().Unix(),
  8068. // UpdatedTime: time.Now().Unix(),
  8069. // TeamId: projectTeam.ID,
  8070. // Type: types,
  8071. // }
  8072. // list := projectList
  8073. //
  8074. // service.CreateProjectList(&list)
  8075. //
  8076. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  8077. //
  8078. // }
  8079. // ids_str := strings.Join(ids, ",")
  8080. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  8081. // service.SaveProjectTeam(&projectTeam)
  8082. // this.ServeSuccessJSON(map[string]interface{}{
  8083. // "projectTeam": projectTeam,
  8084. // })
  8085. // }
  8086. // }
  8087. //}
  8088. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  8089. name := c.GetString("name")
  8090. mode_id, _ := c.GetInt64("mode", 0)
  8091. types, _ := c.GetInt64("type", 0)
  8092. patient_id, _ := c.GetInt64("patient_id", 0)
  8093. types = 1
  8094. adminInfo := c.GetAdminUserInfo()
  8095. template := &models.HisPrescriptionTemplate{
  8096. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8097. PatientId: patient_id,
  8098. Type: types,
  8099. Status: 1,
  8100. Ctime: time.Now().Unix(),
  8101. Mtime: time.Now().Unix(),
  8102. Name: name,
  8103. Mode: mode_id,
  8104. }
  8105. dataBody := make(map[string]interface{}, 0)
  8106. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8107. if err != nil {
  8108. utils.ErrorLog(err.Error())
  8109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8110. return
  8111. }
  8112. err = service.CreateHisPrescriptionTemplate(template)
  8113. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  8114. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  8115. if len(prescriptions) > 0 {
  8116. for _, item := range prescriptions {
  8117. items := item.(map[string]interface{})
  8118. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8119. utils.ErrorLog("type")
  8120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8121. return
  8122. }
  8123. types := int64(items["type"].(float64))
  8124. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  8125. utils.ErrorLog("med_type")
  8126. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8127. return
  8128. }
  8129. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  8130. ctime := time.Now().Unix()
  8131. prescription := &models.HisPrescriptionInfoTemplate{
  8132. PatientId: patient_id,
  8133. UserOrgId: adminInfo.CurrentOrgId,
  8134. Ctime: ctime,
  8135. Mtime: ctime,
  8136. Type: types,
  8137. Modifier: adminInfo.AdminUser.Id,
  8138. Creator: adminInfo.AdminUser.Id,
  8139. Status: 1,
  8140. PTemplateId: template.ID,
  8141. MedType: med_type,
  8142. }
  8143. service.CreateHisPrescriptionInfoTemplate(prescription)
  8144. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  8145. advices := items["advices"].([]interface{})
  8146. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  8147. ctime := time.Now().Unix()
  8148. mtime := ctime
  8149. if len(advices) > 0 {
  8150. for _, advice := range advices {
  8151. var s models.HisPrescriptionAdviceTemplate
  8152. s.PrescriptionId = prescription.ID
  8153. s.AdviceType = 2
  8154. s.StopState = 2
  8155. s.ExecutionState = 2
  8156. s.Status = 1
  8157. s.UserOrgId = adminInfo.CurrentOrgId
  8158. s.CreatedTime = ctime
  8159. s.UpdatedTime = mtime
  8160. s.PatientId = patient_id
  8161. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  8162. if errcode > 0 {
  8163. c.ServeFailJSONWithSGJErrorCode(errcode)
  8164. return
  8165. }
  8166. service.CreateHisPrescriptionAdviceTemplate(&s)
  8167. }
  8168. }
  8169. }
  8170. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  8171. projects := items["project"].([]interface{})
  8172. if len(projects) > 0 {
  8173. for _, project := range projects {
  8174. var p models.HisPrescriptionProjectTemplate
  8175. p.PrescriptionId = prescription.ID
  8176. p.Ctime = time.Now().Unix()
  8177. p.Mtime = time.Now().Unix()
  8178. p.PatientId = patient_id
  8179. p.UserOrgId = adminInfo.CurrentOrgId
  8180. p.Status = 1
  8181. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  8182. if errcode > 0 {
  8183. c.ServeFailJSONWithSGJErrorCode(errcode)
  8184. return
  8185. }
  8186. service.CreateHisPrescriptionProjectTemplate(&p)
  8187. }
  8188. }
  8189. }
  8190. }
  8191. c.ServeSuccessJSON(map[string]interface{}{
  8192. "msg": "创建成功",
  8193. })
  8194. }
  8195. }
  8196. }
  8197. func (c *HisApiController) PreSettle() {
  8198. id, _ := c.GetInt64("id")
  8199. record_time := c.GetString("record_time")
  8200. his_patient_id, _ := c.GetInt64("his_patient_id")
  8201. timeLayout := "2006-01-02"
  8202. loc, _ := time.LoadLocation("Local")
  8203. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  8204. diagnosis_id := c.GetString("diagnosis")
  8205. sick_type, _ := c.GetInt64("sick_type")
  8206. reg_type, _ := c.GetInt64("p_type")
  8207. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  8208. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8209. if err != nil {
  8210. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8211. return
  8212. }
  8213. recordDateTime := theTime.Unix()
  8214. adminUser := c.GetAdminUserInfo()
  8215. var prescriptions []*models.HisPrescription
  8216. var start_time int64
  8217. var end_time int64
  8218. ids_str := c.GetString("ids")
  8219. ids_arr := strings.Split(ids_str, ",")
  8220. fmt.Println(reg_type)
  8221. if settle_accounts_type == 1 { //日结
  8222. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  8223. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  8224. } else {
  8225. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  8226. }
  8227. fmt.Println(prescriptions)
  8228. } else { //月结
  8229. start_time_str := c.GetString("start_time")
  8230. end_time_str := c.GetString("end_time")
  8231. timeLayout := "2006-01-02"
  8232. loc, _ := time.LoadLocation("Local")
  8233. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  8234. if err != nil {
  8235. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8236. return
  8237. }
  8238. recordStartTime := theStartTime.Unix()
  8239. start_time = recordStartTime
  8240. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  8241. if err != nil {
  8242. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8243. return
  8244. }
  8245. recordEndTime := theEndTime.Unix()
  8246. end_time = recordEndTime
  8247. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  8248. }
  8249. if reg_type == 1111 || reg_type == 1112 {
  8250. reg_type = 11
  8251. }
  8252. timestamp := time.Now().Unix()
  8253. tempTime := time.Unix(timestamp, 0)
  8254. timeFormat := tempTime.Format("20060102150405")
  8255. chrgBchno := rand.Intn(100000) + 10000
  8256. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  8257. strconv.FormatInt(his.PatientId, 10)
  8258. var ids []int64
  8259. for _, item := range prescriptions {
  8260. ids = append(ids, item.ID)
  8261. }
  8262. fmt.Println(ids)
  8263. var total float64
  8264. for _, item := range prescriptions {
  8265. fmt.Println(item)
  8266. if item.Type == 1 { //药品
  8267. for _, subItem := range item.HisDoctorAdviceInfo {
  8268. total = total + (subItem.Price * subItem.PrescribingNumber)
  8269. }
  8270. }
  8271. if item.Type == 2 { //项目
  8272. for _, subItem := range item.HisPrescriptionProject {
  8273. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8274. total = total + (subItem.Price * cnt)
  8275. }
  8276. }
  8277. for _, subItem := range item.HisAdditionalCharge {
  8278. total = total + (subItem.Price * float64(subItem.Count))
  8279. }
  8280. }
  8281. allTotal := fmt.Sprintf("%.2f", total)
  8282. totals, _ := strconv.ParseFloat(allTotal, 64)
  8283. order := &models.HisOrder{
  8284. UserOrgId: adminUser.CurrentOrgId,
  8285. HisPatientId: his.ID,
  8286. PatientId: id,
  8287. SettleAccountsDate: recordDateTime,
  8288. Ctime: time.Now().Unix(),
  8289. Mtime: time.Now().Unix(),
  8290. Status: 1,
  8291. OrderStatus: 1,
  8292. MdtrtId: his.Number,
  8293. Number: chrg_bchno,
  8294. MedfeeSumamt: totals,
  8295. SettleEndTime: end_time,
  8296. SettleStartTime: start_time,
  8297. SettleType: settle_accounts_type,
  8298. PsnPartAmt: totals,
  8299. PsnCashPay: totals,
  8300. PType: 2,
  8301. IsPre: 1,
  8302. MedType: strconv.Itoa(int(reg_type)),
  8303. Diagnosis: diagnosis_id,
  8304. }
  8305. err = service.CreateOrder(order)
  8306. if err != nil {
  8307. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8308. return
  8309. }
  8310. var customs []*Custom
  8311. for _, item := range prescriptions {
  8312. fmt.Println(item.Type)
  8313. if item.Type == 1 { //药品
  8314. for _, subItem := range item.HisDoctorAdviceInfo {
  8315. cus := &Custom{
  8316. AdviceId: subItem.ID,
  8317. ProjectId: 0,
  8318. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  8319. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  8320. FeedetlSn: subItem.FeedetlSn,
  8321. Price: fmt.Sprintf("%.2f", subItem.Price),
  8322. MedListCodg: subItem.MedListCodg,
  8323. Type: 1,
  8324. }
  8325. customs = append(customs, cus)
  8326. }
  8327. }
  8328. if item.Type == 2 { //项目
  8329. for _, subItem := range item.HisPrescriptionProject {
  8330. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8331. cus := &Custom{
  8332. AdviceId: 0,
  8333. ProjectId: subItem.ID,
  8334. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  8335. Cut: fmt.Sprintf("%.2f", cnt),
  8336. FeedetlSn: subItem.FeedetlSn,
  8337. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  8338. MedListCodg: subItem.MedListCodg,
  8339. Type: 2,
  8340. }
  8341. customs = append(customs, cus)
  8342. }
  8343. }
  8344. for _, item := range item.HisAdditionalCharge {
  8345. cus := &Custom{
  8346. ItemId: item.ID,
  8347. AdviceId: 0,
  8348. ProjectId: 0,
  8349. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  8350. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  8351. FeedetlSn: item.FeedetlSn,
  8352. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  8353. MedListCodg: item.XtHisAddtionConfig.Code,
  8354. Type: 3,
  8355. }
  8356. customs = append(customs, cus)
  8357. }
  8358. }
  8359. fmt.Println(customs)
  8360. for _, item := range customs {
  8361. var advice_id int64 = 0
  8362. var project_id int64 = 0
  8363. var item_id int64 = 0
  8364. var types int64 = 0
  8365. if item.Type == 1 {
  8366. advice_id = item.AdviceId
  8367. project_id = 0
  8368. item_id = 0
  8369. } else if item.Type == 2 {
  8370. advice_id = 0
  8371. item_id = 0
  8372. project_id = item.ProjectId
  8373. } else if item.Type == 3 {
  8374. advice_id = 0
  8375. item_id = item.ItemId
  8376. project_id = 0
  8377. }
  8378. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8379. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8380. pric, _ := strconv.ParseFloat(item.Price, 32)
  8381. info := &models.HisOrderInfo{
  8382. OrderNumber: order.Number,
  8383. UploadDate: time.Now().Unix(),
  8384. AdviceId: advice_id,
  8385. DetItemFeeSumamt: detItemFeeSumamt,
  8386. Cnt: cut,
  8387. Pric: pric,
  8388. PatientId: id,
  8389. Status: 1,
  8390. Mtime: time.Now().Unix(),
  8391. Ctime: time.Now().Unix(),
  8392. UserOrgId: adminUser.CurrentOrgId,
  8393. HisPatientId: his.ID,
  8394. OrderId: order.ID,
  8395. ProjectId: project_id,
  8396. Type: types,
  8397. ItemId: item_id,
  8398. }
  8399. service.CreateOrderInfo(info)
  8400. }
  8401. his.SickType = sick_type
  8402. service.UpdataHisPateint(&his)
  8403. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  8404. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  8405. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  8406. if err == nil {
  8407. c.ServeSuccessJSON(map[string]interface{}{
  8408. "msg": "结算成功",
  8409. })
  8410. }
  8411. }
  8412. type CustomOrderInfo struct {
  8413. Name string
  8414. Spec string
  8415. Unit string
  8416. Count float64
  8417. Price float64
  8418. Total float64
  8419. }
  8420. func (c *HisApiController) GetPrivateExpensesInfo() {
  8421. order_id, _ := c.GetInt64("id", 0)
  8422. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  8423. order, _ := service.GetHisOrderByID(order_id)
  8424. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  8425. if order.ID == 0 {
  8426. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8427. return
  8428. }
  8429. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  8430. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  8431. org_id := c.GetAdminUserInfo().CurrentOrgId
  8432. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8433. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8434. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  8435. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  8436. orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  8437. var orderInfos_four []*models.HisOrderInfoTwo
  8438. for _, item := range orderInfos_three {
  8439. if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  8440. item.HisPrescriptionProject.IsCheckTeam = 1
  8441. orderInfos_four = append(orderInfos_four, item)
  8442. }
  8443. if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  8444. item.HisPrescriptionProject.IsCheckTeam = 2
  8445. orderInfos_two = append(orderInfos_two, item)
  8446. }
  8447. }
  8448. new_order_info := RemoveRepeatedTeam(orderInfos_four)
  8449. var cus_slice []CustomOrderInfo
  8450. for _, item := range new_order_info {
  8451. var cus CustomOrderInfo
  8452. cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  8453. cus.Unit = ""
  8454. cus.Spec = ""
  8455. var total float64
  8456. for _, subItem := range orderInfos_four {
  8457. if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  8458. total = total + subItem.DetItemFeeSumamt
  8459. fmt.Println(subItem.DetItemFeeSumamt)
  8460. }
  8461. }
  8462. cus.Count = 1
  8463. cus.Total = total
  8464. cus_slice = append(cus_slice, cus)
  8465. }
  8466. orderInfos = append(orderInfos, orderInfos_two...)
  8467. if c.GetAdminUserInfo().CurrentOrgId != 10138 {
  8468. orderInfos = append(orderInfos, orderInfos_three...)
  8469. }
  8470. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  8471. c.ServeSuccessJSON(map[string]interface{}{
  8472. "order": order,
  8473. "order_info": orderInfos,
  8474. "patient": patient,
  8475. "admin_info": adminInfo,
  8476. "his": his,
  8477. "current_admin": role,
  8478. "org_config": miConfig,
  8479. "new_order_info": cus_slice,
  8480. })
  8481. }
  8482. func (this *HisApiController) ChangeMedType() {
  8483. med_type := this.GetString("med_type")
  8484. old_med_type := this.GetString("old_med_type")
  8485. ids := this.GetString("ids")
  8486. settle_type, _ := this.GetInt64("settle_type")
  8487. start_time := this.GetString("start_time")
  8488. end_time := this.GetString("end_time")
  8489. ids_arr := strings.Split(ids, ",")
  8490. if settle_type == 1 { //日结
  8491. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  8492. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  8493. prescription.MedType = med_type
  8494. err := service.SaveHisPrescription(&prescription)
  8495. if err == nil {
  8496. this.ServeSuccessJSON(map[string]interface{}{
  8497. "msg": "修改成功",
  8498. })
  8499. } else {
  8500. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8501. return
  8502. }
  8503. } else if settle_type == 2 {
  8504. timeLayout := "2006-01-02"
  8505. loc, _ := time.LoadLocation("Local")
  8506. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8507. if err != nil {
  8508. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8509. return
  8510. }
  8511. recordStartTime := theStartTime.Unix()
  8512. start_time_timestamp := recordStartTime
  8513. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8514. if err != nil {
  8515. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8516. return
  8517. }
  8518. recordEndTime := theEndTime.Unix()
  8519. end_time_timestamp := recordEndTime
  8520. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  8521. if updateErr == nil {
  8522. this.ServeSuccessJSON(map[string]interface{}{
  8523. "msg": "修改成功",
  8524. })
  8525. } else {
  8526. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8527. return
  8528. }
  8529. }
  8530. }
  8531. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  8532. patient_id, _ := c.GetInt64("patient_id")
  8533. his_patient_id, _ := c.GetInt64("his_patient_id")
  8534. record_date := c.GetString("record_date")
  8535. start_time := c.GetString("start_time")
  8536. end_time := c.GetString("end_time")
  8537. order_status, _ := c.GetInt64("type", 0)
  8538. p_type, _ := c.GetInt64("p_type", 0)
  8539. order_id, _ := c.GetInt64("order_id", 0)
  8540. timeLayout := "2006-01-02"
  8541. loc, _ := time.LoadLocation("Local")
  8542. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8543. if err != nil {
  8544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8545. return
  8546. }
  8547. recordDateTime := theTime.Unix()
  8548. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8549. if err != nil {
  8550. }
  8551. startRecordDateTime := startTime.Unix()
  8552. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8553. if err != nil {
  8554. }
  8555. endRecordDateTime := endTime.Unix()
  8556. admin := c.GetAdminUserInfo()
  8557. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8558. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8559. order, _ := service.GetHisOrderByID(order_id)
  8560. var monthPrescriptions []*models.HisPrescription
  8561. if order_status == 1 || order_status == 0 {
  8562. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8563. } else if order_status == 2 {
  8564. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  8565. }
  8566. var settle_total float64
  8567. for _, item := range monthPrescriptions {
  8568. if len(item.HisPrescriptionProject) > 0 {
  8569. for _, subItem := range item.HisPrescriptionProject {
  8570. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8571. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8572. settle_total = settle_total + total
  8573. }
  8574. }
  8575. if len(item.HisDoctorAdviceInfo) > 0 {
  8576. for _, subItem := range item.HisDoctorAdviceInfo {
  8577. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8578. settle_total = settle_total + total
  8579. }
  8580. }
  8581. }
  8582. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8583. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8584. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8585. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8586. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8587. //获取所有科室信息
  8588. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8589. c.ServeSuccessJSON(map[string]interface{}{
  8590. "his_info": his_patient_info,
  8591. "xt_info": xt_patient_info,
  8592. "case_history": case_history,
  8593. "info": patientPrescriptionInfo,
  8594. "last_info": lastPatientPrescriptionInfo,
  8595. "month_prescriptions": monthPrescriptions,
  8596. "order": order,
  8597. "doctors": doctors,
  8598. "department": department,
  8599. "settle_total": settle_total,
  8600. })
  8601. return
  8602. }
  8603. func (c *HisApiController) GetHisMonthPatientInfo() {
  8604. patient_id, _ := c.GetInt64("patient_id")
  8605. his_patient_id, _ := c.GetInt64("his_patient_id")
  8606. record_date := c.GetString("record_date")
  8607. number := c.GetString("number")
  8608. start_time := c.GetString("start_time")
  8609. end_time := c.GetString("end_time")
  8610. p_type, _ := c.GetInt64("p_type")
  8611. timeLayout := "2006-01-02"
  8612. loc, _ := time.LoadLocation("Local")
  8613. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8614. if err != nil {
  8615. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8616. return
  8617. }
  8618. recordDateTime := theTime.Unix()
  8619. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8620. if err != nil {
  8621. }
  8622. startRecordDateTime := startTime.Unix()
  8623. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8624. if err != nil {
  8625. }
  8626. endRecordDateTime := endTime.Unix()
  8627. admin := c.GetAdminUserInfo()
  8628. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  8629. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8630. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  8631. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8632. var settle_total float64
  8633. for _, item := range monthPrescriptions {
  8634. if len(item.HisPrescriptionProject) > 0 {
  8635. for _, subItem := range item.HisPrescriptionProject {
  8636. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8637. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8638. settle_total = settle_total + total
  8639. }
  8640. }
  8641. if len(item.HisDoctorAdviceInfo) > 0 {
  8642. for _, subItem := range item.HisDoctorAdviceInfo {
  8643. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8644. settle_total = settle_total + total
  8645. }
  8646. }
  8647. }
  8648. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8649. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8650. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8651. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8652. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  8653. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8654. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  8655. //获取所有科室信息
  8656. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8657. c.ServeSuccessJSON(map[string]interface{}{
  8658. "his_info": his_patient_info,
  8659. "xt_info": xt_patient_info,
  8660. "case_history": case_history,
  8661. "info": patientPrescriptionInfo,
  8662. "month_prescriptions": monthPrescriptions,
  8663. "order": order,
  8664. "doctors": doctors,
  8665. "department": department,
  8666. "count": count,
  8667. "drugStockConfig": drugStockConfig,
  8668. "last_info": lastPatientPrescriptionInfo,
  8669. "settle_total": settle_total,
  8670. })
  8671. return
  8672. }
  8673. func (c *HisApiController) GetAllOrder() {
  8674. org_id := c.GetAdminUserInfo().CurrentOrgId
  8675. orders, _ := service.GetNewHisOrderList(org_id)
  8676. c.ServeSuccessJSON(map[string]interface{}{
  8677. "order": orders,
  8678. })
  8679. return
  8680. }
  8681. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  8682. newArr = make([]*models.HisOrderInfoTwo, 0)
  8683. for i := 0; i < len(arr); i++ {
  8684. repeat := false
  8685. for j := i + 1; j < len(arr); j++ {
  8686. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  8687. repeat = true
  8688. break
  8689. }
  8690. }
  8691. if !repeat {
  8692. newArr = append(newArr, arr[i])
  8693. }
  8694. }
  8695. return
  8696. }
  8697. // 修改处方退库操作 参数传修改之前的处方数据
  8698. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  8699. if advice.ExecutionState == 1 {
  8700. //查询该病人该药品是否有库存记录
  8701. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  8702. if errcode == gorm.ErrRecordNotFound {
  8703. } else {
  8704. //退库
  8705. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8706. if advice.PrescribingNumberUnit == drug.MinUnit {
  8707. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  8708. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  8709. //退库
  8710. warehouseInfo := models.DrugWarehouseInfo{
  8711. StockMinNumber: prescribingNumber,
  8712. }
  8713. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  8714. operation_time := time.Now().Unix()
  8715. creater := advice.AdviceDoctor
  8716. ctime := time.Now().Unix()
  8717. timeStr := time.Now().Format("2006-01-02")
  8718. timeArr := strings.Split(timeStr, "-")
  8719. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  8720. total = total + 1
  8721. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8722. cancelStock := models.DrugCancelStock{
  8723. OrderNumber: orderNumber,
  8724. OperaTime: operation_time,
  8725. OrgId: advice.UserOrgId,
  8726. Creater: creater,
  8727. Ctime: ctime,
  8728. Status: 1,
  8729. ReturnTime: advice.AdviceDate,
  8730. Dealer: info.Dealer,
  8731. Manufacturer: info.Manufacturer,
  8732. Type: 1,
  8733. }
  8734. service.AddSigleDrugCancelStock(&cancelStock)
  8735. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  8736. dealer, _ := service.GetDealerById(info.Dealer)
  8737. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  8738. cancelStockInfo := models.DrugCancelStockInfo{
  8739. OrderNumber: cancelInfo.OrderNumber,
  8740. CancelStockId: cancelInfo.ID,
  8741. DrugId: info.DrugId,
  8742. Count: info.Count,
  8743. Status: 1,
  8744. Ctime: ctime,
  8745. OrgId: advice.UserOrgId,
  8746. Type: 1,
  8747. Manufacturer: manufactureName.ManufacturerName,
  8748. Dealer: dealer.DealerName,
  8749. Total: 0,
  8750. RetailPrice: info.RetailPrice,
  8751. RetailTotalPrice: info.RetailTotalPrice,
  8752. Price: info.Price,
  8753. RegisterAccount: "",
  8754. Remark: info.Remark,
  8755. BatchNumber: info.BatchNumber,
  8756. MaxUnit: info.CountUnit,
  8757. ProductDate: info.ProductDate,
  8758. ExpiryDate: info.ExpiryDate,
  8759. BatchNumberId: info.WarehouseInfoId,
  8760. }
  8761. flow := models.DrugFlow{
  8762. WarehousingId: 0,
  8763. DrugId: info.DrugId,
  8764. Number: "",
  8765. BatchNumber: info.BatchNumber,
  8766. Count: info.Count,
  8767. UserOrgId: advice.UserOrgId,
  8768. PatientId: 0,
  8769. SystemTime: ctime,
  8770. ConsumableType: 4,
  8771. IsSys: 0,
  8772. WarehousingOrder: "",
  8773. WarehouseOutId: 0,
  8774. WarehouseOutOrderNumber: "",
  8775. IsEdit: 0,
  8776. CancelStockId: cancelStock.ID,
  8777. CancelOrderNumber: cancelStock.OrderNumber,
  8778. Manufacturer: info.Manufacturer,
  8779. Dealer: info.Dealer,
  8780. Creator: advice.UserOrgId,
  8781. UpdateCreator: 0,
  8782. Status: 1,
  8783. Ctime: time.Now().Unix(),
  8784. Mtime: 0,
  8785. Price: info.Price,
  8786. WarehousingDetailId: 0,
  8787. WarehouseOutDetailId: 0,
  8788. CancelOutDetailId: 0,
  8789. ExpireDate: info.ExpiryDate,
  8790. ProductDate: info.ProductDate,
  8791. MaxUnit: info.CountUnit,
  8792. MinUnit: "",
  8793. }
  8794. service.CreatedCancelStock(cancelStockInfo)
  8795. service.CreateDrugFlowOne(flow)
  8796. } else {
  8797. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  8798. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  8799. if advice.PrescribingNumberUnit == drug.MaxUnit {
  8800. warehouseInfo := models.DrugWarehouseInfo{
  8801. StockMinNumber: prescribingNumber,
  8802. }
  8803. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  8804. }
  8805. operation_time := time.Now().Unix()
  8806. creater := advice.AdviceDoctor
  8807. ctime := time.Now().Unix()
  8808. timeStr := time.Now().Format("2006-01-02")
  8809. timeArr := strings.Split(timeStr, "-")
  8810. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  8811. total = total + 1
  8812. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8813. cancelStock := models.DrugCancelStock{
  8814. OrderNumber: orderNumber,
  8815. OperaTime: operation_time,
  8816. OrgId: advice.UserOrgId,
  8817. Creater: creater,
  8818. Ctime: ctime,
  8819. Status: 1,
  8820. ReturnTime: advice.AdviceDate,
  8821. Dealer: info.Dealer,
  8822. Manufacturer: info.Manufacturer,
  8823. Type: 1,
  8824. }
  8825. service.AddSigleDrugCancelStock(&cancelStock)
  8826. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  8827. dealer, _ := service.GetDealerById(info.Dealer)
  8828. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  8829. cancelStockInfo := models.DrugCancelStockInfo{
  8830. OrderNumber: cancelInfo.OrderNumber,
  8831. CancelStockId: cancelInfo.ID,
  8832. DrugId: info.DrugId,
  8833. Count: info.Count,
  8834. Status: 1,
  8835. Ctime: ctime,
  8836. OrgId: advice.UserOrgId,
  8837. Type: 1,
  8838. Manufacturer: manufactureName.ManufacturerName,
  8839. Dealer: dealer.DealerName,
  8840. Total: 0,
  8841. RetailPrice: info.RetailPrice,
  8842. RetailTotalPrice: info.RetailTotalPrice,
  8843. Price: info.Price,
  8844. RegisterAccount: "",
  8845. Remark: info.Remark,
  8846. BatchNumber: info.BatchNumber,
  8847. MaxUnit: info.CountUnit,
  8848. ProductDate: info.ProductDate,
  8849. ExpiryDate: info.ExpiryDate,
  8850. BatchNumberId: info.WarehouseInfoId,
  8851. }
  8852. flow := models.DrugFlow{
  8853. WarehousingId: 0,
  8854. DrugId: info.DrugId,
  8855. Number: "",
  8856. BatchNumber: info.BatchNumber,
  8857. Count: info.Count,
  8858. UserOrgId: advice.UserOrgId,
  8859. PatientId: 0,
  8860. SystemTime: ctime,
  8861. ConsumableType: 4,
  8862. IsSys: 0,
  8863. WarehousingOrder: "",
  8864. WarehouseOutId: 0,
  8865. WarehouseOutOrderNumber: "",
  8866. IsEdit: 0,
  8867. CancelStockId: cancelStock.ID,
  8868. CancelOrderNumber: cancelStock.OrderNumber,
  8869. Manufacturer: info.Manufacturer,
  8870. Dealer: info.Dealer,
  8871. Creator: advice.AdviceDoctor,
  8872. UpdateCreator: 0,
  8873. Status: 1,
  8874. Ctime: time.Now().Unix(),
  8875. Mtime: 0,
  8876. Price: info.Price,
  8877. WarehousingDetailId: 0,
  8878. WarehouseOutDetailId: 0,
  8879. CancelOutDetailId: 0,
  8880. ExpireDate: info.ExpiryDate,
  8881. ProductDate: info.ProductDate,
  8882. MaxUnit: info.CountUnit,
  8883. MinUnit: "",
  8884. }
  8885. service.CreatedCancelStock(cancelStockInfo)
  8886. service.CreateDrugFlowOne(flow)
  8887. }
  8888. }
  8889. }
  8890. return err
  8891. }
  8892. func (this *HisApiController) DeleteNCDS() {
  8893. id, _ := this.GetInt64("id", 0)
  8894. if id > 0 {
  8895. service.DeletePsnNCDSRecordById(id)
  8896. this.ServeSuccessJSON(map[string]interface{}{
  8897. "msg": "删除成功",
  8898. })
  8899. } else {
  8900. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  8901. return
  8902. }
  8903. }
  8904. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  8905. id, _ := c.GetInt64("id")
  8906. advice, _ := service.GetHisDoctorAdviceInfo(id)
  8907. c.ServeSuccessJSON(map[string]interface{}{
  8908. "advice": advice,
  8909. })
  8910. return
  8911. }
  8912. func (c *HisApiController) GetHisMonthChargePatientList() {
  8913. record_date := c.GetString("record_date")
  8914. start_time := c.GetString("start_time")
  8915. end_time := c.GetString("end_time")
  8916. timeLayout := "2006-01-02"
  8917. loc, _ := time.LoadLocation("Local")
  8918. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8919. if err != nil {
  8920. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8921. return
  8922. }
  8923. if err != nil {
  8924. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8925. return
  8926. }
  8927. recordDateTime := theTime.Unix()
  8928. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8929. if err != nil {
  8930. }
  8931. startRecordDateTime := startTime.Unix()
  8932. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8933. if err != nil {
  8934. }
  8935. endRecordDateTime := endTime.Unix()
  8936. adminInfo := c.GetAdminUserInfo()
  8937. var tempMonthChargePatients []*service.MonthChargePatients
  8938. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  8939. for _, item := range tempPatients {
  8940. //过滤没有处方的
  8941. if len(item.HisPrescription) == 0 {
  8942. tempMonthChargePatients = append(tempMonthChargePatients, item)
  8943. }
  8944. }
  8945. c.ServeSuccessJSON(map[string]interface{}{
  8946. "list": tempMonthChargePatients,
  8947. })
  8948. }