his_api_controller.go 403KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347
  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. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. }
  85. func (c *HisApiController) GetBatchSettleAccounts() {
  86. order_ids := c.GetString("order_ids")
  87. admin_user_id, _ := c.GetInt64("admin_user_id")
  88. adminUser := c.GetAdminUserInfo()
  89. orders := strings.Split(order_ids, ",")
  90. var newOrders []models.Orders
  91. for _, item := range orders {
  92. order, _ := service.GetHisOrderByIDTenOne(item)
  93. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  94. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  95. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  96. orderInfos = append(orderInfos, orderInfos_two...)
  97. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  98. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  99. var diagnosis_ids []string
  100. if his.ID > 0 {
  101. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  102. } else {
  103. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  104. }
  105. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  106. var dia_config []*models.HisXtDiagnoseConfig
  107. var name string
  108. for _, item := range diagnosis_ids {
  109. id, _ := strconv.ParseInt(item, 10, 64)
  110. diagnosisConfig, _ := service.FindDiagnoseById(id)
  111. dia_config = append(dia_config, diagnosisConfig)
  112. if len(name) == 0 {
  113. name = diagnosisConfig.ClassName
  114. } else {
  115. name = name + "," + diagnosisConfig.ClassName
  116. }
  117. }
  118. var bedCostTotal float64 = 0 //床位总费
  119. var bedCostSelfTotal float64 = 0 //床位自费
  120. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  121. var bedSelfTotal float64 = 0 //床位部分项目自费
  122. var bedInscpTotal float64 = 0 //床位部分项目自费
  123. var operationCostTotal float64 = 0 //手术费
  124. var operationCostSelfTotal float64 = 0 //手术费
  125. var operationCostPartSelfTotal float64 = 0 //手术费
  126. var operationSelfTotal float64 = 0 //床位部分项目自费
  127. var operationInscpTotal float64 = 0 //床位部分项目自费
  128. var otherCostTotal float64 = 0 //其他费用
  129. var otherCostSelfTotal float64 = 0 //其他费用
  130. var otherCostPartSelfTotal float64 = 0 //其他费用
  131. var otherSelfTotal float64 = 0 //床位部分项目自费
  132. var otherInscpTotal float64 = 0 //床位部分项目自费
  133. var materialCostTotal float64 = 0 //材料费
  134. var materialCostSelfTotal float64 = 0 //材料费
  135. var materialCostPartSelfTotal float64 = 0 //材料费
  136. var materialSelfTotal float64 = 0 //床位部分项目自费
  137. var materialInscpTotal float64 = 0 //床位部分项目自费
  138. var westernMedicineCostTotal float64 = 0 //西药费
  139. var westernMedicineCostSelfTotal float64 = 0 //西药费
  140. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  141. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  142. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  143. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  144. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  145. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  146. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  147. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  148. var checkCostTotal float64 = 0 //检查费
  149. var checkCostSelfTotal float64 = 0 //检查费
  150. var checkCostPartSelfTotal float64 = 0 //检查费
  151. var checkSelfTotal float64 = 0 //床位部分项目自费
  152. var checkInscpTotal float64 = 0 //床位部分项目自费
  153. var laboratoryCostTotal float64 = 0 //化验费
  154. var laboratoryCostSelfTotal float64 = 0 //化验费
  155. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  156. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  157. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  158. var treatCostTotal float64 = 0 //治疗费用
  159. var treatCostSelfTotal float64 = 0 //治疗费用
  160. var treatCostPartSelfTotal float64 = 0 //治疗费用
  161. var treatSelfTotal float64 = 0 //床位部分项目自费
  162. var treatInscpTotal float64 = 0 //床位部分项目自费
  163. decimal.DivisionPrecision = 2
  164. for _, item := range orderInfos {
  165. if item.MedChrgitmType == "01" { //床位费
  166. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  167. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  168. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  169. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  170. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  171. }
  172. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  173. if item.MedChrgitmType == "03" { //检查费
  174. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  175. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  176. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  177. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  178. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  179. }
  180. } else {
  181. if item.MedChrgitmType == "03" { //检查费
  182. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  183. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  184. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  185. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  186. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  187. }
  188. }
  189. if item.MedChrgitmType == "04" { //化验费
  190. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  191. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  192. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  193. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  194. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  195. }
  196. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  197. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  198. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  199. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  200. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  201. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  202. }
  203. if item.MedChrgitmType == "06" { //手术费
  204. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  205. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  206. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  207. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  208. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  209. }
  210. if item.MedChrgitmType == "08" { //材料费
  211. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  212. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  213. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  214. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  215. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  216. }
  217. if item.MedChrgitmType == "09" { //西药费
  218. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  219. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  220. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  221. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  222. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  223. }
  224. if item.MedChrgitmType == "11" { //中成费
  225. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  226. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  227. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  228. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  229. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  230. }
  231. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  232. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  233. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  234. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  235. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  236. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  237. }
  238. }
  239. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  240. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  241. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  242. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  243. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  244. var doctor_name string
  245. if roles.ID == 0 {
  246. doctor_name = "管理员"
  247. } else {
  248. doctor_name = roles.UserName
  249. }
  250. yiliao_leibie := ""
  251. switch order.MedType {
  252. case "11":
  253. yiliao_leibie = "普通门诊"
  254. break
  255. case "12":
  256. yiliao_leibie = "门诊挂号"
  257. break
  258. case "13":
  259. yiliao_leibie = "急诊"
  260. break
  261. case "14":
  262. yiliao_leibie = "门诊特殊病"
  263. break
  264. case "15":
  265. yiliao_leibie = "门诊统筹"
  266. break
  267. case "16":
  268. yiliao_leibie = "门诊慢性病"
  269. break
  270. case "21":
  271. yiliao_leibie = "普通住院"
  272. break
  273. }
  274. var newOrder models.Orders
  275. newOrder.Diagnosis = name
  276. newOrder.OrderInfos = orderInfos
  277. newOrder.Number = order.MdtrtId
  278. newOrder.Date = order.SettleAccountsDate
  279. newOrder.ChargeAdmin = charge_admin
  280. newOrder.PrintorAdmin = printor_admin
  281. newOrder.Order = order
  282. newOrder.BedCostTotal = bedCostTotal
  283. newOrder.BedCostSelfTotal = bedCostSelfTotal
  284. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  285. newOrder.BedSelfTotal = bedSelfTotal
  286. newOrder.BedInscpTotal = bedInscpTotal
  287. newOrder.OperationCostTotal = operationCostTotal
  288. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  289. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  290. newOrder.OperationSelfTotal = operationSelfTotal
  291. newOrder.OperationInscpTotal = operationInscpTotal
  292. newOrder.OtherCostTotal = otherCostTotal
  293. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  294. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  295. newOrder.OtherSelfTotal = otherSelfTotal
  296. newOrder.OtherInscpTotal = otherInscpTotal
  297. newOrder.MaterialCostTotal = materialCostTotal
  298. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  299. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  300. newOrder.MaterialSelfTotal = materialSelfTotal
  301. newOrder.MaterialInscpTotal = materialInscpTotal
  302. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  303. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  304. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  305. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  306. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  307. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  308. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  309. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  310. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  311. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  312. newOrder.CheckCostTotal = checkCostTotal
  313. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  314. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  315. newOrder.CheckSelfTotal = checkSelfTotal
  316. newOrder.CheckInscpTotal = checkInscpTotal
  317. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  318. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  319. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  320. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  321. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  322. newOrder.TreatCostTotal = treatCostTotal
  323. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  324. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  325. newOrder.TreatSelfTotal = treatSelfTotal
  326. newOrder.TreatInscpTotal = treatInscpTotal
  327. newOrder.DoctorInfo = doctor_info
  328. newOrder.DoctorName = doctor_name
  329. newOrder.HealthCardNo = order.PsnNo
  330. newOrder.YiliaoLeibie = yiliao_leibie
  331. newOrder.Patient = patient
  332. newOrder.OrgName = miConfig.OrgName
  333. newOrder.OrgCode = miConfig.Code
  334. newOrder.OrderNumber = order.Number
  335. newOrder.HisPatient = his
  336. newOrder.DiaConfig = dia_config
  337. newOrders = append(newOrders, newOrder)
  338. }
  339. c.ServeSuccessJSON(map[string]interface{}{
  340. "orders": newOrders,
  341. })
  342. }
  343. func (c *HisApiController) GetTestOrder() {
  344. order_id, _ := c.GetInt64("order_id")
  345. admin_user_id, _ := c.GetInt64("admin_user_id")
  346. adminUser := c.GetAdminUserInfo()
  347. order, _ := service.GetHisOrderByID(order_id)
  348. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  349. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  350. orderInfos = append(orderInfos, orderInfos_two...)
  351. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  352. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  353. var dia_config []*models.HisXtDiagnoseConfig
  354. var name string
  355. var bedCostTotal float64 = 0 //床位总费
  356. var bedCostSelfTotal float64 = 0 //床位自费
  357. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  358. var bedSelfTotal float64 = 0 //床位部分项目自费
  359. var bedInscpTotal float64 = 0 //床位部分项目自费
  360. var operationCostTotal float64 = 0 //手术费
  361. var operationCostSelfTotal float64 = 0 //手术费
  362. var operationCostPartSelfTotal float64 = 0 //手术费
  363. var operationSelfTotal float64 = 0 //床位部分项目自费
  364. var operationInscpTotal float64 = 0 //床位部分项目自费
  365. var otherCostTotal float64 = 0 //其他费用
  366. var otherCostSelfTotal float64 = 0 //其他费用
  367. var otherCostPartSelfTotal float64 = 0 //其他费用
  368. var otherSelfTotal float64 = 0 //床位部分项目自费
  369. var otherInscpTotal float64 = 0 //床位部分项目自费
  370. var materialCostTotal float64 = 0 //材料费
  371. var materialCostSelfTotal float64 = 0 //材料费
  372. var materialCostPartSelfTotal float64 = 0 //材料费
  373. var materialSelfTotal float64 = 0 //床位部分项目自费
  374. var materialInscpTotal float64 = 0 //床位部分项目自费
  375. var westernMedicineCostTotal float64 = 0 //西药费
  376. var westernMedicineCostSelfTotal float64 = 0 //西药费
  377. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  378. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  379. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  380. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  381. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  382. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  383. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  384. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  385. var checkCostTotal float64 = 0 //检查费
  386. var checkCostSelfTotal float64 = 0 //检查费
  387. var checkCostPartSelfTotal float64 = 0 //检查费
  388. var checkSelfTotal float64 = 0 //床位部分项目自费
  389. var checkInscpTotal float64 = 0 //床位部分项目自费
  390. var laboratoryCostTotal float64 = 0 //化验费
  391. var laboratoryCostSelfTotal float64 = 0 //化验费
  392. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  393. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  394. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  395. var treatCostTotal float64 = 0 //治疗费用
  396. var treatCostSelfTotal float64 = 0 //治疗费用
  397. var treatCostPartSelfTotal float64 = 0 //治疗费用
  398. var treatSelfTotal float64 = 0 //床位部分项目自费
  399. var treatInscpTotal float64 = 0 //床位部分项目自费
  400. decimal.DivisionPrecision = 2
  401. for _, item := range orderInfos {
  402. if item.MedChrgitmType == "01" { //床位费
  403. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  404. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  405. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  406. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  407. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  408. }
  409. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  410. if item.MedChrgitmType == "03" { //检查费
  411. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  412. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  413. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  414. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  415. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  416. }
  417. } else {
  418. if item.MedChrgitmType == "03" { //检查费
  419. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  420. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  421. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  422. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  423. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  424. }
  425. }
  426. if item.MedChrgitmType == "04" { //化验费
  427. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  428. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  429. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  430. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  431. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  432. }
  433. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  434. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  435. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  436. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  437. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  438. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  439. }
  440. if item.MedChrgitmType == "06" { //手术费
  441. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  442. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  443. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  444. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  445. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  446. }
  447. if item.MedChrgitmType == "08" { //材料费
  448. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  449. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  450. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  451. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  452. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  453. }
  454. if item.MedChrgitmType == "09" { //西药费
  455. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  456. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  457. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  458. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  459. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  460. }
  461. if item.MedChrgitmType == "11" { //中成费
  462. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  463. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  464. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  465. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  466. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  467. }
  468. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  469. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  470. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  471. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  472. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  473. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  474. }
  475. }
  476. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  477. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  478. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  479. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  480. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  481. var doctor_name string
  482. if roles.ID == 0 {
  483. doctor_name = "管理员"
  484. } else {
  485. doctor_name = roles.UserName
  486. }
  487. yiliao_leibie := ""
  488. switch order.MedType {
  489. case "11":
  490. yiliao_leibie = "普通门诊"
  491. break
  492. case "12":
  493. yiliao_leibie = "门诊挂号"
  494. break
  495. case "13":
  496. yiliao_leibie = "急诊"
  497. break
  498. case "14":
  499. yiliao_leibie = "门诊特殊病"
  500. break
  501. case "15":
  502. yiliao_leibie = "门诊统筹"
  503. break
  504. case "16":
  505. yiliao_leibie = "门诊慢性病"
  506. break
  507. case "21":
  508. yiliao_leibie = "普通住院"
  509. break
  510. }
  511. c.ServeSuccessJSON(map[string]interface{}{
  512. "diagnosis": name,
  513. "order_infos": orderInfos,
  514. "number": order.MdtrtId,
  515. "date": order.SettleAccountsDate,
  516. "charge_admin": charge_admin,
  517. "printor_admin": printor_admin,
  518. "info": order,
  519. "order": order,
  520. "bedCostTotal": bedCostTotal,
  521. "bedCostSelfTotal": bedCostSelfTotal,
  522. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  523. "bedSelfTotal": bedSelfTotal,
  524. "bedInscpTotal": bedInscpTotal,
  525. "operationCostTotal": operationCostTotal,
  526. "operationCostSelfTotal": operationCostSelfTotal,
  527. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  528. "operationSelfTotal": operationSelfTotal,
  529. "operationInscpTotal": operationInscpTotal,
  530. "otherCostTotal": otherCostTotal,
  531. "otherCostSelfTotal": otherCostSelfTotal,
  532. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  533. "otherSelfTotal": otherSelfTotal,
  534. "otherInscpTotal": otherInscpTotal,
  535. "materialCostTotal": materialCostTotal,
  536. "materialCostSelfTotal": materialCostSelfTotal,
  537. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  538. "materialSelfTotal": materialSelfTotal,
  539. "materialInscpTotal": materialInscpTotal,
  540. "westernMedicineCostTotal": westernMedicineCostTotal,
  541. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  542. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  543. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  544. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  545. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  546. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  547. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  548. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  549. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  550. "checkCostTotal": checkCostTotal,
  551. "checkCostSelfTotal": checkCostSelfTotal,
  552. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  553. "checkSelfTotal": checkSelfTotal,
  554. "checkInscpTotal": checkInscpTotal,
  555. "laboratoryCostTotal": laboratoryCostTotal,
  556. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  557. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  558. "laboratorySelfTotal": laboratorySelfTotal,
  559. "laboratoryInscpTotal": laboratoryInscpTotal,
  560. "treatCostTotal": treatCostTotal,
  561. "treatCostSelfTotal": treatCostSelfTotal,
  562. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  563. "treatSelfTotal": treatSelfTotal,
  564. "treatInscpTotal": treatInscpTotal,
  565. "doctor_info": doctor_info,
  566. "doctor_name": doctor_name,
  567. "health_card_no": order.PsnNo,
  568. "yiliao_leibie": yiliao_leibie,
  569. "patient": patient,
  570. "org_name": miConfig.OrgName,
  571. "org_code": miConfig.Code,
  572. "order_number": order.Number,
  573. "his_hospital": his_hospital,
  574. "dia_config": dia_config,
  575. })
  576. }
  577. func (c *PublicApiController) GetBaiLinExportData() {
  578. data := service.GetBaiLinOrderData()
  579. fmt.Println(len(data))
  580. var new_data []*models.NewCustomHisOrder
  581. for _, item := range data {
  582. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  583. new_data = append(new_data, item)
  584. }
  585. }
  586. fmt.Println(len(new_data))
  587. c.ServeSuccessJSON(map[string]interface{}{
  588. "list": new_data,
  589. })
  590. }
  591. func (c *HisApiController) GetHisUnChargePatientList() {
  592. record_date := c.GetString("record_date")
  593. timeLayout := "2006-01-02"
  594. loc, _ := time.LoadLocation("Local")
  595. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  596. if err != nil {
  597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  598. return
  599. }
  600. recordDateTime := theTime.Unix()
  601. adminInfo := c.GetAdminUserInfo()
  602. var tempPatients []*service.NewTempPatients
  603. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  604. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  605. var patients []*service.NewTempPatients
  606. var patients_two []*service.NewTempPatients
  607. for _, item := range tempPatients {
  608. //过滤掉没挂号的和没开处方的
  609. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  610. patients = append(patients, item)
  611. }
  612. //过滤掉没挂号的
  613. if len(item.HisPatient) > 0 {
  614. patients_two = append(patients_two, item)
  615. }
  616. }
  617. c.ServeSuccessJSON(map[string]interface{}{
  618. "list": patients,
  619. "list_two": patients_two,
  620. })
  621. }
  622. func (c *HisApiController) GetPrivateExpensesOrder() {
  623. //id, _ := c.GetInt64("id")
  624. //record_time := c.GetString("record_time")
  625. order_id, _ := c.GetInt64("order_id")
  626. admin_user_id, _ := c.GetInt64("admin_user_id")
  627. //timeLayout := "2006-01-02"
  628. //loc, _ := time.LoadLocation("Local")
  629. //
  630. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  631. //if err != nil {
  632. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  633. // return
  634. //}
  635. //recordDateTime := theTime.Unix()
  636. adminUser := c.GetAdminUserInfo()
  637. order, _ := service.GetHisOrderByID(order_id)
  638. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  639. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  640. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  641. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  642. //var config []*models.HisXtDiagnoseConfig
  643. var name string
  644. if order.PType == 1 {
  645. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  646. for _, item := range diagnosis_ids {
  647. id, _ := strconv.ParseInt(item, 10, 64)
  648. diagnosisConfig, _ := service.FindDiagnoseById(id)
  649. if len(name) == 0 {
  650. name = diagnosisConfig.ClassName
  651. } else {
  652. name = name + "," + diagnosisConfig.ClassName
  653. }
  654. }
  655. } else {
  656. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  657. for _, item := range diagnosis_ids {
  658. id, _ := strconv.ParseInt(item, 10, 64)
  659. diagnosisConfig, _ := service.FindDiagnoseById(id)
  660. if len(name) == 0 {
  661. name = diagnosisConfig.ClassName
  662. } else {
  663. name = name + "," + diagnosisConfig.ClassName
  664. }
  665. }
  666. }
  667. var bedCostTotal float64 = 0 //床位总费
  668. //var bedCostSelfTotal float64 = 0 //床位自费
  669. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  670. var operationCostTotal float64 = 0 //手术费
  671. //var operationCostSelfTotal float64 = 0 //手术费
  672. var operationCostPartSelfTotal float64 = 0 //手术费
  673. var otherCostTotal float64 = 0 //其他费用
  674. //var otherCostSelfTotal float64 = 0 //其他费用
  675. var otherCostPartSelfTotal float64 = 0 //其他费用
  676. var materialCostTotal float64 = 0 //材料费
  677. //var materialCostSelfTotal float64 = 0 //材料费
  678. var materialCostPartSelfTotal float64 = 0 //材料费
  679. var westernMedicineCostTotal float64 = 0 //西药费
  680. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  681. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  682. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  683. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  684. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  685. var checkCostTotal float64 = 0 //检查费
  686. //var checkCostSelfTotal float64 = 0 //检查费
  687. var checkCostPartSelfTotal float64 = 0 //检查费
  688. var laboratoryCostTotal float64 = 0 //化验费
  689. //var laboratoryCostSelfTotal float64 = 0 //化验费
  690. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  691. var treatCostTotal float64 = 0 //治疗费用
  692. //var treatCostSelfTotal float64 = 0 //治疗费用
  693. var treatCostPartSelfTotal float64 = 0 //治疗费用
  694. var zhenChaCostTotal float64 = 0 //其他费用
  695. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  696. decimal.DivisionPrecision = 2
  697. for _, item := range orderInfos {
  698. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  699. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  700. item.MedChrgitmType = "09"
  701. }
  702. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  703. if item.HisPrescriptionProject.Type == 2 {
  704. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  705. fmt.Println("CostClassify")
  706. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  707. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  708. case 0:
  709. item.MedChrgitmType = "0"
  710. break
  711. case 1:
  712. item.MedChrgitmType = "14"
  713. break
  714. case 2:
  715. item.MedChrgitmType = "05"
  716. break
  717. case 3:
  718. item.MedChrgitmType = "03"
  719. break
  720. case 4:
  721. item.MedChrgitmType = "03"
  722. break
  723. case 5:
  724. item.MedChrgitmType = "08"
  725. break
  726. case 6:
  727. item.MedChrgitmType = "14"
  728. break
  729. case 7:
  730. item.MedChrgitmType = "14"
  731. break
  732. case 8:
  733. item.MedChrgitmType = "03"
  734. break
  735. case 9:
  736. item.MedChrgitmType = "14"
  737. break
  738. case 10:
  739. item.MedChrgitmType = "14"
  740. break
  741. case 11:
  742. item.MedChrgitmType = "06"
  743. break
  744. case 12:
  745. item.MedChrgitmType = "12"
  746. break
  747. case 13:
  748. item.MedChrgitmType = "01"
  749. break
  750. case 14:
  751. item.MedChrgitmType = "04"
  752. break
  753. case 15:
  754. item.MedChrgitmType = "14"
  755. break
  756. }
  757. } else {
  758. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  759. case 1:
  760. item.MedChrgitmType = "14"
  761. break
  762. case 2:
  763. item.MedChrgitmType = "05"
  764. break
  765. case 3:
  766. item.MedChrgitmType = "04"
  767. break
  768. case 4:
  769. item.MedChrgitmType = "14"
  770. break
  771. case 5:
  772. item.MedChrgitmType = "08"
  773. break
  774. case 6:
  775. item.MedChrgitmType = "14"
  776. break
  777. case 7:
  778. item.MedChrgitmType = "14"
  779. break
  780. case 8:
  781. item.MedChrgitmType = "03"
  782. break
  783. case 9:
  784. item.MedChrgitmType = "14"
  785. break
  786. }
  787. }
  788. } else if item.HisPrescriptionProject.Type == 3 {
  789. item.MedChrgitmType = "08"
  790. }
  791. }
  792. }
  793. order.PsnCashPay = order.MedfeeSumamt
  794. for _, item := range orderInfos {
  795. if item.MedChrgitmType == "01" { //床位费
  796. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  797. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  798. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  799. }
  800. if item.MedChrgitmType == "02" { //诊察费
  801. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  802. //zhenChaCostSelfTotal = zhenChaCostTotal
  803. }
  804. if item.MedChrgitmType == "03" { //检查费
  805. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  806. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  807. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  808. }
  809. if item.MedChrgitmType == "02" { //检查费
  810. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  811. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  812. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  813. }
  814. if item.MedChrgitmType == "04" { //化验费
  815. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  816. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  817. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  818. }
  819. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  820. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  821. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  822. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  823. }
  824. if item.MedChrgitmType == "06" { //手术费
  825. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  826. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  827. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  828. }
  829. if item.MedChrgitmType == "08" { //材料费
  830. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  831. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  832. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  833. }
  834. if item.MedChrgitmType == "09" { //西药费
  835. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  836. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  837. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  838. }
  839. if item.MedChrgitmType == "11" { //中成费
  840. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  841. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  842. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  843. }
  844. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  845. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  846. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  847. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  848. }
  849. }
  850. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  851. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  852. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  853. patient, _ := service.GetPatientByID(order.UserOrgId, order.PatientId)
  854. c.ServeSuccessJSON(map[string]interface{}{
  855. "patient": patient,
  856. "order_infos": orderInfos,
  857. "diagnosis": name,
  858. "bedCostTotal": bedCostTotal,
  859. "bedCostSelfTotal": bedCostTotal,
  860. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  861. "operationCostTotal": operationCostTotal,
  862. "operationCostSelfTotal": operationCostTotal,
  863. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  864. "otherCostTotal": otherCostTotal,
  865. "otherCostSelfTotal": otherCostTotal,
  866. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  867. "materialCostTotal": materialCostTotal,
  868. "materialCostSelfTotal": materialCostTotal,
  869. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  870. "westernMedicineCostTotal": westernMedicineCostTotal,
  871. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  872. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  873. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  874. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  875. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  876. "checkCostTotal": checkCostTotal,
  877. "checkCostSelfTotal": checkCostTotal,
  878. "zhenChaCostTotal": zhenChaCostTotal,
  879. "zhenChaCostSelfTotal": zhenChaCostTotal,
  880. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  881. "laboratoryCostTotal": laboratoryCostTotal,
  882. "laboratoryCostSelfTotal": laboratoryCostTotal,
  883. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  884. "treatCostTotal": treatCostTotal,
  885. "treatCostSelfTotal": treatCostTotal,
  886. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  887. "charge_admin": charge_admin,
  888. "printor_admin": printor_admin,
  889. "org_name": org.OrgName,
  890. "org_code": miConfig.Code,
  891. "name": patient.Name,
  892. "number": order.MdtrtId,
  893. "date": order.SettleAccountsDate,
  894. "info": order,
  895. "his_hospital": his_hospital,
  896. "his": his,
  897. })
  898. }
  899. func (c *HisApiController) RefudDetail() {
  900. order_id, _ := c.GetInt64("order_id")
  901. order, _ := service.GetHisOrderByID(order_id)
  902. adminUser := c.GetAdminUserInfo()
  903. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  904. c.ServeSuccessJSON(map[string]interface{}{
  905. "msg": "撤销成功",
  906. })
  907. }
  908. func (c *HisApiController) Sscard() {
  909. //r := CardInit()
  910. //if r == 0 {
  911. // GetBaseInfo()
  912. //}
  913. //c.ServeSuccessJSON(map[string]interface{}{
  914. // "list": "11",
  915. //})
  916. }
  917. func GetBaseInfo() error {
  918. //handle := syscall.MustLoadDLL("SSCard.dll")
  919. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  920. //
  921. //str := make([]byte, 256)
  922. //str1 := make([]byte, 256)
  923. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  924. //if ferr != nil {
  925. // fmt.Println("ReadCardBas 报错", ferr.Error())
  926. // return ferr
  927. //}
  928. //
  929. //fmt.Println(string(str))
  930. //
  931. //fmt.Println(r)
  932. return nil
  933. }
  934. func CardInit() int {
  935. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  936. //add := DllTestDef.MustFindProc("Init")
  937. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  938. //if err != nil {
  939. // fmt.Println("SSCard的运算结果为:", ret)
  940. //}
  941. //result := int(ret)
  942. return 0
  943. }
  944. func IntPtr(n int) uintptr {
  945. return uintptr(n)
  946. }
  947. func StrPtr(s string) uintptr {
  948. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  949. }
  950. func (c *HisApiController) GetHisPatientList() {
  951. //types, _ := c.GetInt64("type", 0)
  952. record_date := c.GetString("record_date")
  953. sch_type, _ := c.GetInt64("sch_type")
  954. timeLayout := "2006-01-02"
  955. loc, _ := time.LoadLocation("Local")
  956. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  957. if err != nil {
  958. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  959. return
  960. }
  961. recordDateTime := theTime.Unix()
  962. adminInfo := c.GetAdminUserInfo()
  963. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  964. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  965. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  966. //获取当前用户的信息
  967. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  968. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  969. //获取所有科室信息
  970. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  971. c.ServeSuccessJSON(map[string]interface{}{
  972. "list": patients,
  973. "list_two": patients_two,
  974. "info": adminUserInfo,
  975. "doctors": doctors,
  976. "department": department,
  977. })
  978. }
  979. type CustomTemplate struct {
  980. ID int64 `gorm:"column:id" json:"id" form:"id"`
  981. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  982. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  983. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  984. Status int64 `gorm:"column:status" json:"status" form:"status"`
  985. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  986. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  987. Type int64 `gorm:"column:type" json:"type" form:"type"`
  988. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  989. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  990. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  991. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  992. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  993. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  994. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  995. }
  996. func (c *HisApiController) GetHisPatientInfo() {
  997. patient_id, _ := c.GetInt64("patient_id")
  998. his_patient_id, _ := c.GetInt64("his_patient_id")
  999. record_date := c.GetString("record_date")
  1000. number := c.GetString("number")
  1001. //start_time := c.GetString("start_time")
  1002. //end_time := c.GetString("end_time")
  1003. p_type, _ := c.GetInt64("p_type")
  1004. timeLayout := "2006-01-02"
  1005. loc, _ := time.LoadLocation("Local")
  1006. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1007. if err != nil {
  1008. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1009. return
  1010. }
  1011. recordDateTime := theTime.Unix()
  1012. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1013. //if err != nil {
  1014. //
  1015. //}
  1016. //startRecordDateTime := startTime.Unix()
  1017. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1018. //if err != nil {
  1019. //
  1020. //}
  1021. //endRecordDateTime := endTime.Unix()
  1022. admin := c.GetAdminUserInfo()
  1023. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1024. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1025. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1026. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1027. var prescriptions []*models.HisPrescription
  1028. var last_prescriptions []*models.HisPrescription
  1029. var sch_prescriptions []CustomTemplate
  1030. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1031. if p_type == 1 { //住院
  1032. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1033. for _, item := range prescriptions {
  1034. for _, subItem := range item.HisDoctorAdviceInfo {
  1035. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1036. if info.RetailPrice > 0 {
  1037. subItem.Drug.MinPrice = info.RetailPrice
  1038. }
  1039. }
  1040. }
  1041. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1042. } else { //门诊
  1043. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1044. for _, item := range prescriptions {
  1045. for _, subItem := range item.HisDoctorAdviceInfo {
  1046. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1047. if info.RetailPrice > 0 {
  1048. subItem.Drug.MinPrice = info.RetailPrice
  1049. }
  1050. }
  1051. }
  1052. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1053. }
  1054. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1055. if sch.ID > 0 {
  1056. var week string
  1057. t := time.Now()
  1058. switch t.Weekday().String() {
  1059. case "Monday":
  1060. week = "周一"
  1061. break
  1062. case "Tuesday":
  1063. week = "周二"
  1064. break
  1065. case "Wednesday":
  1066. week = "周三"
  1067. break
  1068. case "Thursday":
  1069. week = "周四"
  1070. break
  1071. case "Friday":
  1072. week = "周五"
  1073. break
  1074. case "Saturday":
  1075. week = "周六"
  1076. break
  1077. case "Sunday":
  1078. week = "周日"
  1079. break
  1080. }
  1081. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1082. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1083. //根据推送频率组装新的数组
  1084. for _, item := range temp_sch_prescriptions {
  1085. var cus CustomTemplate
  1086. cus.ID = item.ID
  1087. cus.UserOrgId = item.UserOrgId
  1088. cus.PatientId = item.PatientId
  1089. cus.MedType = item.MedType
  1090. cus.RecordDate = item.RecordDate
  1091. cus.Type = item.Type
  1092. cus.PType = item.PType
  1093. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1094. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1095. if subItem.FrequencyType == 1 { //每次必推
  1096. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1097. }
  1098. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1099. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1100. }
  1101. if subItem.FrequencyType == 2 { //按照天数频率
  1102. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1103. now := p.Unix()
  1104. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1105. dayStr2 := "-" + dayStr
  1106. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1107. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1108. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1109. if len(advices) == 0 {
  1110. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1111. }
  1112. }
  1113. }
  1114. }
  1115. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1116. if subItem.Type == 2 {
  1117. if subItem.XtHisProject.MedicalStatus != 1 {
  1118. if subItem.FrequencyType == 1 {
  1119. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1120. }
  1121. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1122. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1123. }
  1124. if subItem.FrequencyType == 2 {
  1125. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1126. now := p.Unix()
  1127. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1128. dayStr2 := "-" + dayStr
  1129. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1130. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1131. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1132. if len(projects) == 0 {
  1133. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1134. }
  1135. }
  1136. }
  1137. } else if subItem.Type == 3 {
  1138. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1139. if subItem.FrequencyType == 1 {
  1140. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1141. }
  1142. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1143. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1144. }
  1145. if subItem.FrequencyType == 2 {
  1146. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1147. now := p.Unix()
  1148. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1149. dayStr2 := "-" + dayStr
  1150. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1151. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1152. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1153. if len(projects) == 0 {
  1154. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1155. }
  1156. }
  1157. }
  1158. }
  1159. }
  1160. sch_prescriptions = append(sch_prescriptions, cus)
  1161. }
  1162. for _, item := range sch_prescriptions {
  1163. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1164. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1165. }
  1166. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1167. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1168. }
  1169. }
  1170. }
  1171. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1172. if config.ID > 0 && config.IsOpen == 1 {
  1173. for _, item := range sch_prescriptions {
  1174. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1175. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1176. if info.RetailPrice > 0 {
  1177. subItem.Drug.MinPrice = info.RetailPrice
  1178. }
  1179. }
  1180. }
  1181. }
  1182. if config.ID > 0 && config.IsOpen == 1 {
  1183. for _, item := range sch_prescriptions {
  1184. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1185. if subItem.Type == 3 {
  1186. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1187. if info.Price > 0 {
  1188. subItem.GoodInfo.PackingPrice = info.Price
  1189. }
  1190. }
  1191. }
  1192. }
  1193. }
  1194. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1195. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1196. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1197. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1198. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1199. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1200. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1201. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1202. //获取所有科室信息
  1203. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1204. c.ServeSuccessJSON(map[string]interface{}{
  1205. "his_info": his_patient_info,
  1206. "xt_info": xt_patient_info,
  1207. "prescription": prescriptions,
  1208. "case_history": case_history,
  1209. "info": patientPrescriptionInfo,
  1210. //"month_prescriptions": monthPrescriptions,
  1211. "order": order,
  1212. "doctors": doctors,
  1213. "department": department,
  1214. "sch_prescriptions": sch_prescriptions,
  1215. "last_prescriptions": last_prescriptions,
  1216. "schedule": sch,
  1217. "count": count,
  1218. "drugStockConfig": drugStockConfig,
  1219. "last_info": lastPatientPrescriptionInfo,
  1220. })
  1221. return
  1222. }
  1223. func (c *HisApiController) GetHisPrescriptionConfig() {
  1224. adminInfo := c.GetAdminUserInfo()
  1225. //获取医嘱模版
  1226. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1227. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1228. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1229. //获取所有基础药
  1230. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1231. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1232. if config.ID > 0 && config.IsOpen == 1 {
  1233. for _, item := range drugs {
  1234. var index = 0
  1235. for _, subItem := range item.OtherDrugWarehouseInfo {
  1236. if index == 0 {
  1237. index = index + 1
  1238. if subItem.RetailPrice > 0 {
  1239. item.MinPrice = subItem.RetailPrice
  1240. }
  1241. }
  1242. }
  1243. }
  1244. }
  1245. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1246. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1247. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1248. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1249. //获取所有科室信息
  1250. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1251. //获取诊断信息
  1252. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1253. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1254. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1255. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1256. //获取是否开启保存耗材出库的开关
  1257. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1258. c.ServeSuccessJSON(map[string]interface{}{
  1259. "drugs": drugs,
  1260. "advices_template": advices,
  1261. "drugways": drugways,
  1262. "efs": efs,
  1263. "doctors": doctors,
  1264. "department": department,
  1265. "sick": sick,
  1266. "additions": additions,
  1267. "diagnose": diagnose,
  1268. "manufacturers": manufacturers,
  1269. "goodOutOpen": goodOutOpen,
  1270. "patientDiagnose": patientDiagnose,
  1271. })
  1272. }
  1273. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1274. //获取所有基础药
  1275. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1276. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1277. if config.ID > 0 && config.IsOpen == 1 {
  1278. for _, item := range drugs {
  1279. var index = 0
  1280. for _, subItem := range item.OtherDrugWarehouseInfo {
  1281. if index == 0 {
  1282. index = index + 1
  1283. if subItem.RetailPrice > 0 {
  1284. item.MinPrice = subItem.RetailPrice
  1285. }
  1286. }
  1287. }
  1288. }
  1289. }
  1290. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1291. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1292. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1293. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1294. //获取所有科室信息
  1295. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1296. //获取诊断信息
  1297. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1298. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1299. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1300. //获取是否开启保存耗材出库的开关
  1301. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1302. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1303. c.ServeSuccessJSON(map[string]interface{}{
  1304. "drugs": drugs,
  1305. "advices_template": advices,
  1306. "drugways": drugways,
  1307. "efs": efs,
  1308. "doctors": doctors,
  1309. "department": department,
  1310. "sick": sick,
  1311. "additions": additions,
  1312. "diagnose": diagnose,
  1313. "manufacturers": manufacturers,
  1314. "goodOutOpen": goodOutOpen,
  1315. "patientDiagnose": patientDiagnose,
  1316. })
  1317. }
  1318. }
  1319. func (c *HisApiController) CreateHisPrescription() {
  1320. record_date := c.GetString("record_date")
  1321. patient_id, _ := c.GetInt64("patient_id")
  1322. reg_type, _ := c.GetInt64("reg_type")
  1323. diagnose := c.GetString("diagnose")
  1324. sick_type, _ := c.GetInt64("sick_type")
  1325. sick_history := c.GetString("sick_history")
  1326. doctor_id, _ := c.GetInt64("doctor", 0)
  1327. department, _ := c.GetInt64("department", 0)
  1328. his_patient_id, _ := c.GetInt64("his_patient_id")
  1329. p_type, _ := c.GetInt64("p_type")
  1330. patient_diagnose := c.GetString("patient_diagnose")
  1331. dataBody := make(map[string]interface{}, 0)
  1332. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1333. if err != nil {
  1334. utils.ErrorLog(err.Error())
  1335. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1336. return
  1337. }
  1338. timeLayout := "2006-01-02"
  1339. loc, _ := time.LoadLocation("Local")
  1340. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1341. if err != nil {
  1342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1343. return
  1344. }
  1345. adminInfo := c.GetAdminUserInfo()
  1346. recordDateTime := theTime.Unix()
  1347. //查询默认出库仓库库存
  1348. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1349. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1350. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1351. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1352. if len(lists) == 1 {
  1353. his_patient_id = lists[0].ID
  1354. }
  1355. }
  1356. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1357. //保存处方出库
  1358. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1359. //自动出库
  1360. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1361. //耗材保存处方出库
  1362. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1363. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1364. //已发药和已收费限制逻辑
  1365. isMidicine := false
  1366. isCharge := false
  1367. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1368. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1369. if len(prescriptions) > 0 {
  1370. for _, item := range prescriptions {
  1371. items := item.(map[string]interface{})
  1372. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1373. utils.ErrorLog("id")
  1374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1375. return
  1376. }
  1377. id := int64(items["id"].(float64))
  1378. if id > 0 {
  1379. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1380. if err != nil {
  1381. if new_prescription.OrderStatus == 4 {
  1382. isCharge = true
  1383. }
  1384. }
  1385. }
  1386. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1387. advices := items["advices"].([]interface{})
  1388. if len(advices) > 0 {
  1389. for _, advice := range advices {
  1390. var adviceId int64
  1391. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1392. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1393. }
  1394. if adviceId > 0 {
  1395. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1396. if err == nil {
  1397. if his_advice_info.IsMedicine == 1 {
  1398. isMidicine = true
  1399. }
  1400. }
  1401. }
  1402. }
  1403. }
  1404. }
  1405. }
  1406. }
  1407. }
  1408. if isMidicine == true {
  1409. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1410. return
  1411. }
  1412. if isCharge == true {
  1413. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1414. return
  1415. }
  1416. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1417. //药品发药出库
  1418. if pharmacyConfig.IsOpen == 1 {
  1419. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1420. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1421. if len(prescriptions) > 0 {
  1422. for _, item := range prescriptions {
  1423. items := item.(map[string]interface{})
  1424. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1425. advices := items["advices"].([]interface{})
  1426. if len(advices) > 0 {
  1427. for _, advice := range advices {
  1428. var drug_id int64
  1429. var prescribing_number float64
  1430. var prescribingNumberUnit string
  1431. var adviceId int64
  1432. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1433. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1434. }
  1435. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1436. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1437. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1438. }
  1439. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1440. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1441. }
  1442. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1443. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1444. }
  1445. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1446. if drug.ID == 0 {
  1447. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1448. return
  1449. }
  1450. //查询药品的所有库存
  1451. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1452. var total_count int64
  1453. for _, it := range list {
  1454. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1455. }
  1456. totals := strconv.FormatInt(total_count, 10)
  1457. //查询该药品是否存在开药记录
  1458. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1459. //新增处方
  1460. if advicelist.ID == 0 {
  1461. all_count, _ := strconv.ParseFloat(totals, 64)
  1462. if prescribingNumberUnit == drug.MinUnit {
  1463. if drug.IsUse != 1 {
  1464. if prescribing_number > all_count {
  1465. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1466. return
  1467. }
  1468. }
  1469. }
  1470. if prescribingNumberUnit == drug.MaxUnit {
  1471. num := prescribing_number * float64(drug.MinNumber)
  1472. if drug.IsUse != 1 {
  1473. if num > all_count {
  1474. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1475. return
  1476. }
  1477. }
  1478. }
  1479. }
  1480. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1481. if drugOutConfig.IsOpen != 1 {
  1482. //修改处方
  1483. for _, advice := range advices {
  1484. var drug_id int64
  1485. var prescribing_number float64
  1486. var prescribingNumberUnit string
  1487. var prescribingNumber string
  1488. var adviceId int64
  1489. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1490. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1491. }
  1492. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1493. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1494. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1495. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1496. }
  1497. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1498. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1499. }
  1500. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1501. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1502. }
  1503. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1504. if drug.ID == 0 {
  1505. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1506. return
  1507. }
  1508. //查询药品的所有库存
  1509. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1510. var total_count int64
  1511. for _, it := range list {
  1512. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1513. }
  1514. totals := strconv.FormatInt(total_count, 10)
  1515. //查询该药品是否存在开药记录
  1516. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1517. //新增处方
  1518. if advicelist.ID == 0 {
  1519. all_count, _ := strconv.ParseFloat(totals, 64)
  1520. if prescribingNumberUnit == drug.MinUnit {
  1521. if drug.IsUse != 1 {
  1522. if prescribing_number > all_count {
  1523. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1524. return
  1525. }
  1526. }
  1527. } else {
  1528. if prescribingNumberUnit == drug.MaxUnit {
  1529. num := prescribing_number * float64(drug.MinNumber)
  1530. if drug.IsUse != 1 {
  1531. if num > all_count {
  1532. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1533. return
  1534. }
  1535. }
  1536. }
  1537. }
  1538. }
  1539. //修改处方
  1540. if advicelist.ID > 0 {
  1541. var device_number int64
  1542. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1543. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1544. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1545. device_number = prescribingNumberInt * drug.MinNumber
  1546. }
  1547. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1548. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1549. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1550. device_number = prescribingNumberInt
  1551. }
  1552. var number_count int64
  1553. if prescribingNumberUnit == drug.MaxUnit {
  1554. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1555. number_count = prescribingNumberInt * drug.MinNumber
  1556. }
  1557. if prescribingNumberUnit == drug.MinUnit {
  1558. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1559. number_count = prescribingNumberInt
  1560. }
  1561. //如果修改的数量大于之前修改的数量
  1562. if (number_count - device_number) > 0 {
  1563. //如果修改的差数量 大于库存数量
  1564. if drug.IsUse != 1 {
  1565. if (number_count - device_number) > total_count {
  1566. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1567. return
  1568. }
  1569. }
  1570. }
  1571. }
  1572. }
  1573. }
  1574. }
  1575. }
  1576. }
  1577. }
  1578. }
  1579. }
  1580. }
  1581. //已发药和已收费限制逻辑
  1582. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1583. //校验库存总量
  1584. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1585. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1586. if len(prescriptions) > 0 {
  1587. for _, item := range prescriptions {
  1588. items := item.(map[string]interface{})
  1589. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1590. advices := items["advices"].([]interface{})
  1591. if len(advices) > 0 {
  1592. for _, advice := range advices {
  1593. var drug_id int64
  1594. var prescribing_number float64
  1595. var prescribingNumberUnit string
  1596. var adviceId int64
  1597. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1598. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1599. }
  1600. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1601. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1602. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1603. }
  1604. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1605. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1606. }
  1607. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1608. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1609. }
  1610. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1611. if drug.ID == 0 {
  1612. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1613. return
  1614. }
  1615. //查询药品的所有库存
  1616. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1617. var total_count int64
  1618. for _, it := range list {
  1619. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1620. }
  1621. totals := strconv.FormatInt(total_count, 10)
  1622. //查询该药品是否存在开药记录
  1623. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1624. //查询最新批次库存
  1625. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1626. var batch_number_count int64
  1627. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1628. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1629. //新增处方
  1630. if advicelist.ID == 0 {
  1631. all_count, _ := strconv.ParseFloat(totals, 64)
  1632. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1633. if prescribingNumberUnit == drug.MinUnit {
  1634. if drug.IsUse != 1 {
  1635. if prescribing_number > all_count {
  1636. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1637. return
  1638. }
  1639. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1640. if prescribing_number > batch_number_all_count {
  1641. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1642. return
  1643. }
  1644. }
  1645. }
  1646. }
  1647. if prescribingNumberUnit == drug.MaxUnit {
  1648. num := prescribing_number * float64(drug.MinNumber)
  1649. if drug.IsUse != 1 {
  1650. if num > all_count {
  1651. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1652. return
  1653. }
  1654. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1655. if num > batch_number_all_count {
  1656. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1657. return
  1658. }
  1659. }
  1660. }
  1661. }
  1662. }
  1663. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1664. if drugOutConfig.IsOpen != 1 {
  1665. //修改处方
  1666. for _, advice := range advices {
  1667. var drug_id int64
  1668. var prescribing_number float64
  1669. var prescribingNumberUnit string
  1670. var prescribingNumber string
  1671. var adviceId int64
  1672. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1673. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1674. }
  1675. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1676. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1677. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1678. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1679. }
  1680. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1681. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1682. }
  1683. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1684. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1685. }
  1686. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1687. if drug.ID == 0 {
  1688. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1689. return
  1690. }
  1691. //查询药品的所有库存
  1692. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1693. var total_count int64
  1694. for _, it := range list {
  1695. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1696. }
  1697. totals := strconv.FormatInt(total_count, 10)
  1698. //查询该药品是否存在开药记录
  1699. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1700. //新增处方
  1701. if advicelist.ID == 0 {
  1702. //查询最新批次库存
  1703. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1704. var batch_number_count int64
  1705. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1706. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1707. all_count, _ := strconv.ParseFloat(totals, 64)
  1708. if prescribingNumberUnit == drug.MinUnit {
  1709. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1710. if drug.IsUse != 1 {
  1711. if prescribing_number > all_count {
  1712. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1713. return
  1714. }
  1715. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1716. if prescribing_number > batch_number_all_count {
  1717. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1718. return
  1719. }
  1720. }
  1721. }
  1722. } else {
  1723. if prescribingNumberUnit == drug.MaxUnit {
  1724. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1725. num := prescribing_number * float64(drug.MinNumber)
  1726. if drug.IsUse != 1 {
  1727. if num > all_count {
  1728. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1729. return
  1730. }
  1731. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1732. if prescribing_number > batch_number_all_count {
  1733. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1734. return
  1735. }
  1736. }
  1737. }
  1738. }
  1739. }
  1740. }
  1741. //修改处方
  1742. if advicelist.ID > 0 {
  1743. //查询最新批次库存
  1744. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1745. var batch_number_count int64
  1746. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1747. var device_number int64
  1748. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1749. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1750. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1751. device_number = prescribingNumberInt * drug.MinNumber
  1752. }
  1753. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1754. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1755. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1756. device_number = prescribingNumberInt
  1757. }
  1758. var number_count int64
  1759. if prescribingNumberUnit == drug.MaxUnit {
  1760. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1761. number_count = prescribingNumberInt * drug.MinNumber
  1762. }
  1763. if prescribingNumberUnit == drug.MinUnit {
  1764. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1765. number_count = prescribingNumberInt
  1766. }
  1767. //如果修改的数量大于之前修改的数量
  1768. if (number_count - device_number) > 0 {
  1769. //如果修改的差数量 大于库存数量
  1770. if drug.IsUse != 1 {
  1771. if (number_count - device_number) > total_count {
  1772. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1773. return
  1774. }
  1775. if (number_count - device_number) > batch_number_count {
  1776. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1777. return
  1778. }
  1779. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1780. // 查询该药品最后一次出库记录
  1781. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1782. var out_count int64
  1783. var in_count int64
  1784. var stock_max_number int64
  1785. var stock_min_number int64
  1786. for _, it := range outInfo {
  1787. if it.CountUnit == drug.MaxUnit {
  1788. it.Count = it.Count * drug.MinNumber
  1789. }
  1790. out_count += it.Count
  1791. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1792. stock_max_number = warehouseInfoList.StockMaxNumber
  1793. stock_min_number = warehouseInfoList.StockMinNumber
  1794. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1795. }
  1796. if out_count > 0 {
  1797. if (number_count - device_number) > in_count {
  1798. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1799. return
  1800. }
  1801. }
  1802. // 未出库
  1803. if out_count == 0 {
  1804. var sum_in_count int64
  1805. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1806. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1807. fmt.Println("sum_in_count", sum_in_count)
  1808. //如果修改的数量大于有库存的第一个批次
  1809. if number_count > sum_in_count {
  1810. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  1811. return
  1812. }
  1813. }
  1814. }
  1815. }
  1816. }
  1817. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1818. fmt.Println("device_number2333233232323222323232323323322332", device_number)
  1819. fmt.Println("number_count99999999999999999999999999999999999", number_count)
  1820. if pharmacyConfig.IsOpen != 1 {
  1821. if device_number != number_count {
  1822. // 查询该药品最后一次出库记录
  1823. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  1824. //回退库存
  1825. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  1826. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  1827. }
  1828. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  1829. var stock_max_number int64
  1830. var stock_min_number int64
  1831. if number_count >= drug.MinNumber {
  1832. stock_max_number = device_number / drug.MinNumber
  1833. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  1834. stock_min_number = device_number % drug.MinNumber
  1835. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  1836. } else {
  1837. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  1838. }
  1839. }
  1840. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  1841. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  1842. }
  1843. //删除记录
  1844. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  1845. //查询默认仓库剩余多少库存
  1846. var sum_count int64
  1847. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  1848. for _, its := range stockInfo {
  1849. if its.MaxUnit == drug.MaxUnit {
  1850. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  1851. }
  1852. sum_count += its.StockMaxNumber + its.StockMinNumber
  1853. }
  1854. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  1855. }
  1856. }
  1857. }
  1858. }
  1859. }
  1860. //保存处方开药
  1861. if drugOutConfig.IsOpen == 1 {
  1862. //修改处方
  1863. for _, advice := range advices {
  1864. var drug_id int64
  1865. var prescribing_number float64
  1866. var prescribingNumberUnit string
  1867. var prescribingNumber string
  1868. var adviceId int64
  1869. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1870. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1871. }
  1872. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1873. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1874. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1875. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1876. }
  1877. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1878. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1879. }
  1880. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1881. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1882. }
  1883. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1884. if drug.ID == 0 {
  1885. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1886. return
  1887. }
  1888. //查询药品的所有库存
  1889. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1890. var total_count int64
  1891. for _, it := range list {
  1892. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1893. }
  1894. totals := strconv.FormatInt(total_count, 10)
  1895. //查询该药品是否存在开药记录
  1896. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1897. //新增处方
  1898. if advicelist.ID == 0 {
  1899. //查询最新批次库存
  1900. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1901. var batch_number_count int64
  1902. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1903. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1904. all_count, _ := strconv.ParseFloat(totals, 64)
  1905. if prescribingNumberUnit == drug.MinUnit {
  1906. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1907. if drug.IsUse != 1 {
  1908. if prescribing_number > all_count {
  1909. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1910. return
  1911. }
  1912. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1913. if prescribing_number > batch_number_all_count {
  1914. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1915. return
  1916. }
  1917. }
  1918. }
  1919. } else {
  1920. if prescribingNumberUnit == drug.MaxUnit {
  1921. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1922. num := prescribing_number * float64(drug.MinNumber)
  1923. if drug.IsUse != 1 {
  1924. if num > all_count {
  1925. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1926. return
  1927. }
  1928. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1929. if prescribing_number > batch_number_all_count {
  1930. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1931. return
  1932. }
  1933. }
  1934. }
  1935. }
  1936. }
  1937. }
  1938. //修改处方
  1939. if advicelist.ID > 0 {
  1940. //查询最新批次库存
  1941. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1942. var batch_number_count int64
  1943. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1944. var device_number int64
  1945. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1946. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1947. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1948. device_number = prescribingNumberInt * drug.MinNumber
  1949. }
  1950. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1951. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1952. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1953. device_number = prescribingNumberInt
  1954. }
  1955. var number_count int64
  1956. if prescribingNumberUnit == drug.MaxUnit {
  1957. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1958. number_count = prescribingNumberInt * drug.MinNumber
  1959. }
  1960. if prescribingNumberUnit == drug.MinUnit {
  1961. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1962. number_count = prescribingNumberInt
  1963. }
  1964. //如果修改的数量大于之前修改的数量
  1965. if (number_count - device_number) > 0 {
  1966. //如果修改的差数量 大于库存数量
  1967. if drug.IsUse != 1 {
  1968. if (number_count - device_number) > total_count {
  1969. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1970. return
  1971. }
  1972. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1973. if (number_count - device_number) > batch_number_count {
  1974. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1975. return
  1976. }
  1977. }
  1978. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1979. //查询历史出库数据总批次
  1980. // 查询该药品最后一次出库记录
  1981. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1982. var out_count int64
  1983. var in_count int64
  1984. var stock_max_number int64
  1985. var stock_min_number int64
  1986. for _, it := range outInfo {
  1987. if it.CountUnit == drug.MaxUnit {
  1988. it.Count = it.Count * drug.MinNumber
  1989. }
  1990. out_count += it.Count
  1991. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1992. stock_max_number = warehouseInfoList.StockMaxNumber
  1993. stock_min_number = warehouseInfoList.StockMinNumber
  1994. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1995. }
  1996. if out_count > 0 {
  1997. if (number_count - device_number) > in_count {
  1998. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1999. return
  2000. }
  2001. }
  2002. // 未出库
  2003. if out_count == 0 {
  2004. var sum_in_count int64
  2005. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2006. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2007. //如果修改的数量大于有库存的第一个批次
  2008. if number_count > sum_in_count {
  2009. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2010. return
  2011. }
  2012. }
  2013. }
  2014. }
  2015. }
  2016. }
  2017. }
  2018. }
  2019. }
  2020. }
  2021. }
  2022. }
  2023. }
  2024. }
  2025. }
  2026. //校验耗材库存
  2027. if goodOutConfig.IsOpen == 1 {
  2028. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2029. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2030. if len(prescriptions) > 0 {
  2031. for _, item := range prescriptions {
  2032. items := item.(map[string]interface{})
  2033. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2034. projects := items["project"].([]interface{})
  2035. if len(projects) > 0 {
  2036. for _, project := range projects {
  2037. var project_id int64
  2038. var project_type int64
  2039. var totals float64
  2040. var project_name string
  2041. var parsetotal int64
  2042. var id int64
  2043. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2044. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2045. }
  2046. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2047. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2048. }
  2049. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2050. total, _ := project.(map[string]interface{})["total"].(string)
  2051. totals, _ = strconv.ParseFloat(total, 64)
  2052. }
  2053. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2054. project_name = project.(map[string]interface{})["project_name"].(string)
  2055. }
  2056. if project_type == 3 {
  2057. //查找该耗材的出库记录
  2058. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2059. if len(goodWarehouseInfo) == 0 {
  2060. //查询耗材库存
  2061. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2062. var stock_count int64
  2063. for _, it := range list {
  2064. stock_count += it.StockCount
  2065. }
  2066. stock_counts := strconv.FormatInt(stock_count, 10)
  2067. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2068. if totals > stock_total_count {
  2069. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2070. return
  2071. }
  2072. }
  2073. if len(goodWarehouseInfo) > 0 {
  2074. //查询该患者耗材的历史数据
  2075. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2076. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2077. //数量发生改变
  2078. if parsetotal != count {
  2079. //如果现在的数量大于历史数量,就要看库存是否足够
  2080. if parsetotal > count {
  2081. //查询耗材所有库存
  2082. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2083. var stock_count int64
  2084. for _, it := range list {
  2085. stock_count += it.StockCount
  2086. }
  2087. //库存不足
  2088. if (parsetotal - count) > stock_count {
  2089. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2090. return
  2091. }
  2092. }
  2093. }
  2094. }
  2095. }
  2096. }
  2097. }
  2098. }
  2099. }
  2100. }
  2101. }
  2102. }
  2103. //不使用耗材保存处方出库
  2104. if goodOutConfig.IsOpen != 1 {
  2105. if stockConfig.IsOpen == 1 {
  2106. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2107. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2108. if len(prescriptions) > 0 {
  2109. for _, item := range prescriptions {
  2110. items := item.(map[string]interface{})
  2111. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2112. projects := items["project"].([]interface{})
  2113. if len(projects) > 0 {
  2114. for _, project := range projects {
  2115. var project_id int64
  2116. var project_type int64
  2117. var totals float64
  2118. var project_name string
  2119. var parsetotal int64
  2120. var id int64
  2121. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2122. id = int64(project.(map[string]interface{})["id"].(float64))
  2123. }
  2124. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2125. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2126. }
  2127. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2128. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2129. }
  2130. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2131. total, _ := project.(map[string]interface{})["total"].(string)
  2132. totals, _ = strconv.ParseFloat(total, 64)
  2133. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2134. }
  2135. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2136. project_name = project.(map[string]interface{})["project_name"].(string)
  2137. }
  2138. if project_type == 3 {
  2139. //查找该耗材的出库记录
  2140. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2141. //没有出库记录
  2142. if len(goodWarehouseInfo) == 0 {
  2143. //查询耗材库存
  2144. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2145. var stock_count int64
  2146. for _, it := range list {
  2147. stock_count += it.StockCount
  2148. }
  2149. stock_counts := strconv.FormatInt(stock_count, 10)
  2150. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2151. if totals > stock_total_count {
  2152. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2153. return
  2154. }
  2155. //查找今日该患者已经出库的所有耗材
  2156. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2157. for _, item := range goodList {
  2158. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2159. var flush_count int64
  2160. for _, it := range goodListSix {
  2161. flush_count += it.StockCount
  2162. }
  2163. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2164. creater := adminInfo.AdminUser.Id
  2165. if errs != nil {
  2166. goodErrcode := models.XtGoodErrcode{
  2167. UserOrgId: item.OrgId,
  2168. Errcode: "手动出库更新剩余出库失败",
  2169. GoodId: item.GoodId,
  2170. Status: 1,
  2171. Ctime: time.Now().Unix(),
  2172. Mtime: 0,
  2173. Count: 0,
  2174. StockCount: 0,
  2175. Creater: creater,
  2176. BatchNumberId: 0,
  2177. WarehouseOutId: 0,
  2178. }
  2179. service.CreateGoodErrcode(goodErrcode)
  2180. }
  2181. }
  2182. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2183. }
  2184. //有出库记录
  2185. if len(goodWarehouseInfo) > 0 {
  2186. //查询该患者耗材的历史数据
  2187. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2188. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2189. //数量发生改变
  2190. if parsetotal != count {
  2191. //查找今日该患者已经出库的所有耗材
  2192. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2193. for _, item := range goodList {
  2194. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2195. var flush_count int64
  2196. for _, it := range goodListSix {
  2197. flush_count += it.StockCount
  2198. }
  2199. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2200. //减少出库数量
  2201. creater := adminInfo.AdminUser.Id
  2202. if errs != nil {
  2203. goodErrcode := models.XtGoodErrcode{
  2204. UserOrgId: item.OrgId,
  2205. Errcode: "手动出库更新剩余出库失败",
  2206. GoodId: item.GoodId,
  2207. Status: 1,
  2208. Ctime: time.Now().Unix(),
  2209. Mtime: 0,
  2210. Count: 0,
  2211. StockCount: 0,
  2212. Creater: creater,
  2213. BatchNumberId: 0,
  2214. WarehouseOutId: 0,
  2215. }
  2216. service.CreateGoodErrcode(goodErrcode)
  2217. }
  2218. //查询默认仓库
  2219. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2220. var total_count int64
  2221. for _, it := range stockList {
  2222. total_count += it.StockCount
  2223. }
  2224. //基础库插入数据
  2225. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2226. }
  2227. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2228. }
  2229. }
  2230. }
  2231. }
  2232. }
  2233. }
  2234. }
  2235. }
  2236. }
  2237. }
  2238. }
  2239. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2240. var hpInfo models.HisPrescriptionInfo
  2241. if info.ID == 0 {
  2242. var randNum int
  2243. randNum = rand.Intn(10000) + 1000
  2244. timestamp := time.Now().Unix()
  2245. tempTime := time.Unix(timestamp, 0)
  2246. timeFormat := tempTime.Format("20060102150405")
  2247. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2248. hpInfo = models.HisPrescriptionInfo{
  2249. HisPatientId: his_patient_id,
  2250. UserOrgId: adminInfo.CurrentOrgId,
  2251. RecordDate: theTime.Unix(),
  2252. PatientId: patient_id,
  2253. Status: 1,
  2254. Ctime: time.Now().Unix(),
  2255. Mtime: time.Now().Unix(),
  2256. Creator: adminInfo.AdminUser.Id,
  2257. Modifier: adminInfo.AdminUser.Id,
  2258. Diagnosis: diagnose,
  2259. SickHistory: sick_history,
  2260. Departments: department,
  2261. RegisterType: reg_type,
  2262. PrescriptionNumber: p_number,
  2263. PrescriptionStatus: 1,
  2264. Doctor: role.UserName,
  2265. DoctorId: doctor_id,
  2266. SickType: sick_type,
  2267. PType: p_type,
  2268. PatientDiagnosis: patient_diagnose,
  2269. }
  2270. service.SavePatientPrescriptionInfo(hpInfo)
  2271. redis := service.RedisClient()
  2272. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2273. redis.Set(key, "", time.Second)
  2274. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2275. redis.Set(keyOne, "", time.Second)
  2276. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2277. redis.Set(keySeven, "", time.Second)
  2278. defer redis.Close()
  2279. } else {
  2280. hpInfo = models.HisPrescriptionInfo{
  2281. ID: info.ID,
  2282. UserOrgId: adminInfo.CurrentOrgId,
  2283. RecordDate: info.RecordDate,
  2284. PatientId: info.PatientId,
  2285. Status: 1,
  2286. Ctime: info.Ctime,
  2287. Mtime: time.Now().Unix(),
  2288. Creator: info.Creator,
  2289. Modifier: adminInfo.AdminUser.Id,
  2290. Diagnosis: diagnose,
  2291. SickHistory: sick_history,
  2292. Departments: department,
  2293. RegisterType: reg_type,
  2294. PrescriptionNumber: info.PrescriptionNumber,
  2295. Doctor: role.UserName,
  2296. PrescriptionStatus: info.PrescriptionStatus,
  2297. DoctorId: doctor_id,
  2298. SickType: sick_type,
  2299. PType: info.PType,
  2300. HisPatientId: info.HisPatientId,
  2301. PatientDiagnosis: patient_diagnose,
  2302. }
  2303. service.SavePatientPrescriptionInfo(hpInfo)
  2304. redis := service.RedisClient()
  2305. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2306. redis.Set(key, "", time.Second)
  2307. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2308. redis.Set(keyOne, "", time.Second)
  2309. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2310. redis.Set(keySeven, "", time.Second)
  2311. defer redis.Close()
  2312. }
  2313. //定义切片
  2314. var adviceList []models.HisDoctorAdviceInfo
  2315. var projectList []models.HisPrescriptionProject
  2316. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2317. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2318. var tempPrescription *models.HisPrescription
  2319. if len(prescriptions) > 0 {
  2320. for _, item := range prescriptions {
  2321. items := item.(map[string]interface{})
  2322. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2323. utils.ErrorLog("id")
  2324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2325. return
  2326. }
  2327. id := int64(items["id"].(float64))
  2328. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2329. tempPrescription = &new_prescription
  2330. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2331. utils.ErrorLog("type")
  2332. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2333. return
  2334. }
  2335. types := int64(items["type"].(float64))
  2336. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2337. utils.ErrorLog("med_type")
  2338. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2339. return
  2340. }
  2341. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2342. if med_type == "0" {
  2343. med_type = "14"
  2344. }
  2345. //if order_status == 0 {
  2346. // order_status = 1
  2347. //}
  2348. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2349. utils.ErrorLog("pre_time")
  2350. }
  2351. preTime, _ := items["pre_time"].(string)
  2352. timeLayout := "2006-01-02"
  2353. loc, _ := time.LoadLocation("Local")
  2354. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2355. if err != nil {
  2356. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2357. return
  2358. }
  2359. pTime := theTime2.Unix()
  2360. ctime := time.Now().Unix()
  2361. if tempPrescription.ID == 0 {
  2362. prescription := &models.HisPrescription{
  2363. ID: 0,
  2364. PatientId: patient_id,
  2365. UserOrgId: adminInfo.CurrentOrgId,
  2366. RecordDate: recordDateTime,
  2367. Ctime: ctime,
  2368. Mtime: ctime,
  2369. Type: types,
  2370. Modifier: adminInfo.AdminUser.Id,
  2371. Creator: adminInfo.AdminUser.Id,
  2372. Status: 1,
  2373. Doctor: role.UserName,
  2374. HisPatientId: his_patient_id,
  2375. OrderStatus: 1,
  2376. BatchNumber: "",
  2377. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2378. PreTime: pTime,
  2379. PType: p_type,
  2380. MedType: med_type,
  2381. }
  2382. tempPrescription = prescription
  2383. service.SaveHisPrescription(tempPrescription)
  2384. redis := service.RedisClient()
  2385. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2386. redis.Set(key, "", time.Second)
  2387. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2388. redis.Set(keyOne, "", time.Second)
  2389. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2390. redis.Set(keySeven, "", time.Second)
  2391. defer redis.Close()
  2392. } else {
  2393. tempPrescription.ID = id
  2394. tempPrescription.Type = types
  2395. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2396. tempPrescription.Mtime = time.Now().Unix()
  2397. tempPrescription.Doctor = role.UserName
  2398. //tempPrescription.OrderStatus = order_status
  2399. tempPrescription.PreTime = pTime
  2400. tempPrescription.MedType = med_type
  2401. service.SaveHisPrescription(tempPrescription)
  2402. redis := service.RedisClient()
  2403. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2404. redis.Set(key, "", time.Second)
  2405. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2406. redis.Set(keyOne, "", time.Second)
  2407. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2408. redis.Set(keySeven, "", time.Second)
  2409. defer redis.Close()
  2410. }
  2411. //service.SaveHisPrescription(prescription)
  2412. //更改患者挂号状态
  2413. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2414. fmt.Println("更改失败", err2)
  2415. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2416. advices := items["advices"].([]interface{})
  2417. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2418. groupNo := int64(0)
  2419. ctime := time.Now().Unix()
  2420. mtime := ctime
  2421. if len(advices) > 0 {
  2422. for _, advice := range advices {
  2423. var s models.HisDoctorAdviceInfo
  2424. s.PrescriptionId = tempPrescription.ID
  2425. s.AdviceType = 2
  2426. s.AdviceDoctor = doctor_id
  2427. s.StopState = 2
  2428. s.ExecutionState = 2
  2429. s.AdviceDate = recordDateTime
  2430. s.Status = 1
  2431. s.UserOrgId = adminInfo.CurrentOrgId
  2432. s.RecordDate = recordDateTime
  2433. s.StartTime = tempPrescription.PreTime
  2434. s.Groupno = groupNo
  2435. s.CreatedTime = ctime
  2436. s.UpdatedTime = mtime
  2437. s.PatientId = patient_id
  2438. s.HisPatientId = his_patient_id
  2439. s.StartTime = pTime
  2440. s.IsSettle = 2
  2441. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2442. if errcode > 0 {
  2443. c.ServeFailJSONWithSGJErrorCode(errcode)
  2444. return
  2445. }
  2446. s.StartTime = pTime
  2447. var total_count int64 //处方总库存
  2448. //查询改药品信息
  2449. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2450. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2451. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2452. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2453. total_count += prescribingNumberSeven * medical.MinNumber
  2454. }
  2455. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2456. total_count += prescribingNumberSeven
  2457. }
  2458. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2459. total_count += prescribingNumberSeven
  2460. }
  2461. service.CreateHisDoctorAdvice(&s)
  2462. //存储切片中
  2463. adviceList = append(adviceList, s)
  2464. redis := service.RedisClient()
  2465. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2466. redis.Set(key, "", time.Second)
  2467. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2468. redis.Set(keyOne, "", time.Second)
  2469. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2470. redis.Set(keySeven, "", time.Second)
  2471. var randNum int
  2472. randNum = rand.Intn(10000) + 1000
  2473. timestamp := time.Now().Unix()
  2474. tempTime := time.Unix(timestamp, 0)
  2475. timeFormat := tempTime.Format("20060102150405")
  2476. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  2477. service.CreateHisDoctorAdvice(&s)
  2478. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2479. redis.Set(keySix, "", time.Second)
  2480. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2481. redis.Set(keyFive, "", time.Second)
  2482. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2483. redis.Set(keyEight, "", time.Second)
  2484. defer redis.Close()
  2485. }
  2486. }
  2487. }
  2488. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2489. projects := items["project"].([]interface{})
  2490. if len(projects) > 0 {
  2491. for _, project := range projects {
  2492. var p models.HisPrescriptionProject
  2493. p.PrescriptionId = tempPrescription.ID
  2494. p.Ctime = time.Now().Unix()
  2495. p.Mtime = time.Now().Unix()
  2496. p.PatientId = patient_id
  2497. p.RecordDate = recordDateTime
  2498. p.Doctor = doctor_id
  2499. p.UserOrgId = adminInfo.CurrentOrgId
  2500. p.HisPatientId = his_patient_id
  2501. p.Status = 1
  2502. p.StartTime = pTime
  2503. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  2504. if errcode > 0 {
  2505. c.ServeFailJSONWithSGJErrorCode(errcode)
  2506. return
  2507. }
  2508. if p.ID == 0 {
  2509. p.IsOut = 2
  2510. }
  2511. if p.ID > 0 {
  2512. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  2513. p.IsOut = projectDetail.IsOut
  2514. }
  2515. service.CreateHisProjectTwo(&p)
  2516. projectList = append(projectList, p)
  2517. var randNum int
  2518. randNum = rand.Intn(10000) + 1000
  2519. timestamp := time.Now().Unix()
  2520. tempTime := time.Unix(timestamp, 0)
  2521. timeFormat := tempTime.Format("20060102150405")
  2522. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  2523. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  2524. //新增或者编辑项目,修改对应的标签数据
  2525. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  2526. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  2527. var label models.HisLabelPrintInfo
  2528. project, _ := service.GetProjectDetail(p.ProjectId)
  2529. if project.CostClassify == 3 { //类别为检验检查
  2530. if p.TeamId > 0 { //检验检查组套
  2531. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  2532. if tempLabel.ID == 0 {
  2533. team, _ := service.GetProjectTeamDetail(p.TeamId)
  2534. label.Number = tempPrescription.PrescriptionNumber
  2535. label.ProjectId = project.ID
  2536. label.Status = 1
  2537. label.IsPrint = 2
  2538. label.DoctorId = info.DoctorId
  2539. label.UserOrgId = p.UserOrgId
  2540. label.PatientId = patient_id
  2541. label.RecordDate = recordDateTime
  2542. label.Ctime = time.Now().Unix()
  2543. label.Mtime = time.Now().Unix()
  2544. label.ItemId = p.TeamId
  2545. label.FeedetlSn = p.FeedetlSn
  2546. label.PProjectId = p.ID
  2547. label.ProjectName = team.ProjectTeam
  2548. label.PatientName = patient.Name
  2549. service.CreateHisLabelRecord(&label)
  2550. }
  2551. } else { //单条检验检查项目
  2552. label.Number = tempPrescription.PrescriptionNumber
  2553. label.ProjectId = project.ID
  2554. label.Status = 1
  2555. label.DoctorId = info.DoctorId
  2556. label.UserOrgId = p.UserOrgId
  2557. label.PatientId = patient_id
  2558. label.RecordDate = recordDateTime
  2559. label.IsPrint = 2
  2560. label.Ctime = time.Now().Unix()
  2561. label.Mtime = time.Now().Unix()
  2562. label.FeedetlSn = p.FeedetlSn
  2563. label.PProjectId = p.ID
  2564. label.ItemId = p.TeamId
  2565. label.ProjectName = project.ProjectName
  2566. label.PatientName = patient.Name
  2567. service.CreateHisLabelRecord(&label)
  2568. }
  2569. }
  2570. }
  2571. }
  2572. service.SaveHisProjectTwo(&p)
  2573. }
  2574. }
  2575. }
  2576. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2577. // addition := items["addition"].([]interface{})
  2578. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2579. // ctime := time.Now().Unix()
  2580. // mtime := ctime
  2581. // if len(addition) > 0 {
  2582. // for _, item := range addition {
  2583. // var s models.HisAdditionalCharge
  2584. // s.PrescriptionId = tempPrescription.ID
  2585. // s.Status = 1
  2586. // s.UserOrgId = adminInfo.CurrentOrgId
  2587. // s.RecordDate = recordDateTime
  2588. // s.CreatedTime = ctime
  2589. // s.UpdatedTime = mtime
  2590. // s.PatientId = patient_id
  2591. // s.HisPatientId = his_patient_id
  2592. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  2593. // if errcode > 0 {
  2594. // c.ServeFailJSONWithSGJErrorCode(errcode)
  2595. // return
  2596. // }
  2597. // service.CreateAdditionalCharge(&s)
  2598. // var randNum int
  2599. // randNum = rand.Intn(10000) + 1000
  2600. // timestamp := time.Now().Unix()
  2601. // tempTime := time.Unix(timestamp, 0)
  2602. // timeFormat := tempTime.Format("20060102150405")
  2603. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  2604. // service.CreateAdditionalCharge(&s)
  2605. //
  2606. // }
  2607. // }
  2608. //}
  2609. }
  2610. }
  2611. //查询今日该患者开的药品处方
  2612. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2613. fmt.Println("今日出库2333333333333333333333333333333333333333")
  2614. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2615. //药品出库
  2616. if drugOutConfig.IsOpen == 1 {
  2617. for _, item := range hisdoctorlist {
  2618. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  2619. // 查询该药品最后一次出库记录
  2620. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  2621. fmt.Println("今日最后出库2333333333333333333333333333333333333333", druginfo)
  2622. if len(druginfo) > 0 {
  2623. //回退库存
  2624. for _, it := range druginfo {
  2625. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2626. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2627. }
  2628. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2629. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2630. }
  2631. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2632. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2633. }
  2634. }
  2635. }
  2636. //删除记录
  2637. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  2638. //查询最后一次数据
  2639. if drugOutConfig.IsOpen == 1 {
  2640. //出库
  2641. if drug.IsUse == 2 {
  2642. creater := adminInfo.AdminUser.Id
  2643. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  2644. }
  2645. //更新字典里面的库存
  2646. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2647. var sum_count int64
  2648. for _, its := range stockInfo {
  2649. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  2650. if its.MaxUnit == baseDrug.MaxUnit {
  2651. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  2652. }
  2653. sum_count += its.StockMaxNumber + its.StockMinNumber
  2654. }
  2655. //更新基础库存
  2656. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2657. //剩余库存
  2658. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  2659. }
  2660. }
  2661. }
  2662. //耗材保存处方出库
  2663. if goodOutConfig.IsOpen == 1 {
  2664. //查询今日耗材出库数量
  2665. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2666. for _, item := range hisgoodlist {
  2667. //查询历史出库数据
  2668. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2669. var out_count_five int64
  2670. for _, item := range flowGood {
  2671. out_count_five += item.Count
  2672. }
  2673. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  2674. if out_count_five != parseIntCount {
  2675. //查询耗材最后一次出库记录
  2676. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  2677. //查询默认出库仓库库存
  2678. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2679. if len(wareOut) > 0 {
  2680. for _, it := range wareOut {
  2681. //回退库存
  2682. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  2683. //删除出库记录
  2684. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  2685. }
  2686. }
  2687. timeStr := time.Now().Format("2006-01-02")
  2688. timeArr := strings.Split(timeStr, "-")
  2689. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  2690. total = total + 1
  2691. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2692. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2693. number = number + total
  2694. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2695. operation_time := time.Now().Unix()
  2696. creater := c.GetAdminUserInfo().AdminUser.Id
  2697. recordDateStr := time.Now().Format("2006-01-02")
  2698. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2699. nowtime := recordDate.Unix()
  2700. warehouseOut := models.WarehouseOut{
  2701. WarehouseOutOrderNumber: warehousing_out_order,
  2702. OperationTime: operation_time,
  2703. OrgId: adminInfo.CurrentOrgId,
  2704. Creater: creater,
  2705. Ctime: time.Now().Unix(),
  2706. Status: 1,
  2707. WarehouseOutTime: nowtime,
  2708. Type: 1,
  2709. StorehouseId: storeConfig.StorehouseOutInfo,
  2710. IsCheck: 1,
  2711. IsSys: 1,
  2712. }
  2713. //查询是否生成出库单
  2714. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2715. if out.ID == 0 {
  2716. service.AddSigleWarehouseOut(&warehouseOut)
  2717. }
  2718. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2719. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2720. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  2721. dialyPrepareOne := models.DialysisBeforePrepare{
  2722. GoodTypeId: goodObj.GoodTypeId,
  2723. GoodId: item.ProjectId,
  2724. PatientId: item.PatientId,
  2725. RecordDate: item.RecordDate,
  2726. UserOrgId: adminInfo.CurrentOrgId,
  2727. Count: parseIntCount,
  2728. Ctime: time.Now().Unix(),
  2729. Creater: creater,
  2730. Status: 1,
  2731. StorehouseId: houseConfig.StorehouseOutInfo,
  2732. ProjectId: item.ID,
  2733. }
  2734. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2735. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  2736. //查询历史出库数据
  2737. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2738. var out_count int64
  2739. for _, item := range flowGood {
  2740. out_count += item.Count
  2741. }
  2742. //如果历史数和当前数据不想等才进行退库出库
  2743. if out_count != parseIntCount {
  2744. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  2745. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2746. detail := models.AutomaticReduceDetail{
  2747. WarehouseOutId: 0,
  2748. WarehouseOutOrderNumber: "",
  2749. PatientId: item.PatientId,
  2750. Ctime: time.Now().Unix(),
  2751. Mtime: 0,
  2752. Status: 1,
  2753. RecordTime: item.RecordDate,
  2754. OrgId: item.UserOrgId,
  2755. GoodId: item.ProjectId,
  2756. GoodTypeId: 0,
  2757. Count: parseIntCount,
  2758. Type: 0,
  2759. ProjectId: item.ID,
  2760. StorehouseId: 0,
  2761. }
  2762. service.CreateAutoDetail(detail)
  2763. //查询剩余库存
  2764. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  2765. var sum_count int64
  2766. for _, item := range goodList {
  2767. sum_count += item.StockCount
  2768. }
  2769. //更新剩余库存
  2770. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  2771. //耗材
  2772. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  2773. }
  2774. }
  2775. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  2776. //查询历史出库数据
  2777. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2778. var out_count int64
  2779. for _, item := range flowGood {
  2780. out_count += item.Count
  2781. }
  2782. //如果历史数和当前数据不想等才进行退库出库
  2783. if out_count != parseIntCount {
  2784. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  2785. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2786. detail := models.AutomaticReduceDetail{
  2787. WarehouseOutId: 0,
  2788. WarehouseOutOrderNumber: "",
  2789. PatientId: item.PatientId,
  2790. Ctime: time.Now().Unix(),
  2791. Mtime: 0,
  2792. Status: 1,
  2793. RecordTime: item.RecordDate,
  2794. OrgId: item.UserOrgId,
  2795. GoodId: item.ProjectId,
  2796. GoodTypeId: 0,
  2797. Count: parseIntCount,
  2798. Type: 0,
  2799. ProjectId: item.ID,
  2800. StorehouseId: 0,
  2801. }
  2802. service.CreateAutoDetail(detail)
  2803. //查询剩余库存
  2804. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  2805. var sum_count int64
  2806. for _, item := range goodList {
  2807. sum_count += item.StockCount
  2808. }
  2809. //更新剩余库存
  2810. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  2811. //耗材
  2812. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  2813. }
  2814. }
  2815. }
  2816. }
  2817. }
  2818. }
  2819. //redisClient := service.RedisClient()
  2820. //defer redisClient.Close()
  2821. //
  2822. //list := models.HisList{
  2823. // Patient_id: patient_id,
  2824. // Advice_id:0,
  2825. // Record_date: 0,
  2826. // Advice: adviceList,
  2827. // Project: nil,
  2828. //}
  2829. //hisLis = append(hisLis, list)
  2830. //
  2831. //advice_json, _ := json.Marshal(&hisLis)
  2832. //redisClient.RPush("111", advice_json).Result()
  2833. //result, _ := redisClient.RPop("111").Result()
  2834. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  2835. //
  2836. //var dat []map[string]interface{}
  2837. //json.Unmarshal([]byte(result), &dat)
  2838. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  2839. //
  2840. //for k,v:=range dat{
  2841. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  2842. //}
  2843. //project_json, _ := json.Marshal(&projectList)
  2844. //redisClient.LPush("222", project_json).Result()
  2845. if err == nil {
  2846. c.ServeSuccessJSON(map[string]interface{}{
  2847. "msg": "保存成功",
  2848. })
  2849. return
  2850. } else {
  2851. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2852. return
  2853. }
  2854. }
  2855. func (c *HisApiController) EditHisPrescription() {
  2856. record_date := c.GetString("record_date")
  2857. patient_id, _ := c.GetInt64("patient_id")
  2858. reg_type, _ := c.GetInt64("reg_type")
  2859. //diagnose, _ := c.GetInt64("diagnose", 0)
  2860. diagnose := c.GetString("diagnose")
  2861. sick_type, _ := c.GetInt64("sick_type")
  2862. sick_history := c.GetString("sick_history")
  2863. doctor_id, _ := c.GetInt64("doctor", 0)
  2864. department, _ := c.GetInt64("department", 0)
  2865. his_patient_id, _ := c.GetInt64("his_patient_id")
  2866. p_type, _ := c.GetInt64("p_type")
  2867. dataBody := make(map[string]interface{}, 0)
  2868. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2869. if err != nil {
  2870. utils.ErrorLog(err.Error())
  2871. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2872. return
  2873. }
  2874. timeLayout := "2006-01-02"
  2875. loc, _ := time.LoadLocation("Local")
  2876. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2877. if err != nil {
  2878. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2879. return
  2880. }
  2881. adminInfo := c.GetAdminUserInfo()
  2882. recordDateTime := theTime.Unix()
  2883. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  2884. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2885. var hpInfo models.HisPrescriptionInfo
  2886. if info.ID == 0 {
  2887. var randNum int
  2888. randNum = rand.Intn(10000) + 1000
  2889. timestamp := time.Now().Unix()
  2890. tempTime := time.Unix(timestamp, 0)
  2891. timeFormat := tempTime.Format("20060102150405")
  2892. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2893. hpInfo = models.HisPrescriptionInfo{
  2894. UserOrgId: adminInfo.CurrentOrgId,
  2895. RecordDate: theTime.Unix(),
  2896. PatientId: patient_id,
  2897. Status: 1,
  2898. Ctime: time.Now().Unix(),
  2899. Mtime: time.Now().Unix(),
  2900. Creator: adminInfo.AdminUser.Id,
  2901. Modifier: adminInfo.AdminUser.Id,
  2902. Diagnosis: diagnose,
  2903. SickHistory: sick_history,
  2904. Departments: department,
  2905. RegisterType: reg_type,
  2906. PrescriptionNumber: p_number,
  2907. PrescriptionStatus: 1,
  2908. Doctor: role.UserName,
  2909. DoctorId: doctor_id,
  2910. SickType: sick_type,
  2911. PType: p_type,
  2912. }
  2913. service.SavePatientPrescriptionInfo(hpInfo)
  2914. } else {
  2915. hpInfo = models.HisPrescriptionInfo{
  2916. ID: info.ID,
  2917. UserOrgId: adminInfo.CurrentOrgId,
  2918. RecordDate: info.RecordDate,
  2919. PatientId: info.PatientId,
  2920. Status: 1,
  2921. Ctime: info.Ctime,
  2922. Mtime: time.Now().Unix(),
  2923. Creator: info.Creator,
  2924. Modifier: adminInfo.AdminUser.Id,
  2925. Diagnosis: diagnose,
  2926. SickHistory: sick_history,
  2927. Departments: department,
  2928. RegisterType: reg_type,
  2929. PrescriptionNumber: info.PrescriptionNumber,
  2930. Doctor: role.UserName,
  2931. PrescriptionStatus: info.PrescriptionStatus,
  2932. DoctorId: doctor_id,
  2933. SickType: sick_type,
  2934. PType: info.PType,
  2935. }
  2936. service.SavePatientPrescriptionInfo(hpInfo)
  2937. }
  2938. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2939. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2940. if len(prescriptions) > 0 {
  2941. for _, item := range prescriptions {
  2942. items := item.(map[string]interface{})
  2943. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2944. utils.ErrorLog("id")
  2945. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2946. return
  2947. }
  2948. id := int64(items["id"].(float64))
  2949. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2950. utils.ErrorLog("type")
  2951. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2952. return
  2953. }
  2954. types := int64(items["type"].(float64))
  2955. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2956. utils.ErrorLog("med_type")
  2957. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2958. return
  2959. }
  2960. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2961. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  2962. ctime := time.Now().Unix()
  2963. prescription := &models.HisPrescription{
  2964. ID: id,
  2965. PatientId: patient_id,
  2966. UserOrgId: adminInfo.CurrentOrgId,
  2967. RecordDate: recordDateTime,
  2968. Ctime: ctime,
  2969. Mtime: ctime,
  2970. Type: types,
  2971. Modifier: adminInfo.AdminUser.Id,
  2972. Creator: adminInfo.AdminUser.Id,
  2973. Status: 1,
  2974. Doctor: role.UserName,
  2975. HisPatientId: his_patient_id,
  2976. OrderStatus: 1,
  2977. BatchNumber: "",
  2978. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2979. PType: hpInfo.PType,
  2980. MedType: med_type,
  2981. }
  2982. if historyPrescription.ID > 0 {
  2983. prescription.PreTime = historyPrescription.PreTime
  2984. }
  2985. service.SaveHisPrescription(prescription)
  2986. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2987. advices := items["advices"].([]interface{})
  2988. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2989. groupNo := int64(0)
  2990. ctime := time.Now().Unix()
  2991. mtime := ctime
  2992. if len(advices) > 0 {
  2993. for _, advice := range advices {
  2994. var s models.HisDoctorAdviceInfo
  2995. s.PrescriptionId = prescription.ID
  2996. s.AdviceType = 2
  2997. s.AdviceDoctor = adminInfo.AdminUser.Id
  2998. s.StopState = 2
  2999. s.ExecutionState = 2
  3000. s.AdviceDate = recordDateTime
  3001. s.Status = 1
  3002. s.UserOrgId = adminInfo.CurrentOrgId
  3003. s.RecordDate = recordDateTime
  3004. s.StartTime = prescription.PreTime
  3005. s.Groupno = groupNo
  3006. s.CreatedTime = ctime
  3007. s.UpdatedTime = mtime
  3008. s.PatientId = patient_id
  3009. s.HisPatientId = his_patient_id
  3010. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  3011. if errcode > 0 {
  3012. c.ServeFailJSONWithSGJErrorCode(errcode)
  3013. return
  3014. }
  3015. service.CreateHisDoctorAdvice(&s)
  3016. redis := service.RedisClient()
  3017. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3018. redis.Set(key, "", time.Second)
  3019. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3020. fmt.Println("keyOne", keyOne)
  3021. redis.Set(keyOne, "", time.Second)
  3022. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3023. redis.Set(keySeven, "", time.Second)
  3024. redis.Close()
  3025. }
  3026. }
  3027. }
  3028. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3029. projects := items["project"].([]interface{})
  3030. if len(projects) > 0 {
  3031. for _, project := range projects {
  3032. var p models.HisPrescriptionProject
  3033. p.PrescriptionId = prescription.ID
  3034. p.Ctime = time.Now().Unix()
  3035. p.Mtime = time.Now().Unix()
  3036. p.PatientId = patient_id
  3037. p.RecordDate = recordDateTime
  3038. p.UserOrgId = adminInfo.CurrentOrgId
  3039. p.HisPatientId = his_patient_id
  3040. p.Status = 1
  3041. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  3042. if errcode > 0 {
  3043. c.ServeFailJSONWithSGJErrorCode(errcode)
  3044. return
  3045. }
  3046. service.CreateHisProjectTwo(&p)
  3047. }
  3048. }
  3049. }
  3050. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3051. addition := items["addition"].([]interface{})
  3052. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3053. ctime := time.Now().Unix()
  3054. mtime := ctime
  3055. if len(addition) > 0 {
  3056. for _, item := range addition {
  3057. var s models.HisAdditionalCharge
  3058. s.PrescriptionId = prescription.ID
  3059. s.Status = 1
  3060. s.UserOrgId = adminInfo.CurrentOrgId
  3061. s.RecordDate = recordDateTime
  3062. s.CreatedTime = ctime
  3063. s.UpdatedTime = mtime
  3064. s.PatientId = patient_id
  3065. s.HisPatientId = his_patient_id
  3066. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3067. if errcode > 0 {
  3068. c.ServeFailJSONWithSGJErrorCode(errcode)
  3069. return
  3070. }
  3071. service.CreateAdditionalCharge(&s)
  3072. }
  3073. }
  3074. }
  3075. }
  3076. }
  3077. }
  3078. if err == nil {
  3079. c.ServeSuccessJSON(map[string]interface{}{
  3080. "msg": "保存成功",
  3081. })
  3082. return
  3083. } else {
  3084. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3085. return
  3086. }
  3087. }
  3088. func (c *HisApiController) DeletePrescription() {
  3089. prescription_id, _ := c.GetInt64("id")
  3090. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  3091. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  3092. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3093. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3094. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3095. //耗材保存处方出库
  3096. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3097. //已收费和已发药限制逻辑
  3098. isCharge := false
  3099. isMedicine := false
  3100. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3101. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3102. for _, item := range new_prescriptions {
  3103. if item.IsMedicine == 1 {
  3104. isMedicine = true
  3105. }
  3106. }
  3107. for _, item := range new_prescriptions {
  3108. if item.OrderStatus == 4 {
  3109. isCharge = true
  3110. }
  3111. }
  3112. if p_err != nil {
  3113. if new_prescription.ID > 0 {
  3114. if new_prescription.OrderStatus == 2 {
  3115. isCharge = true
  3116. }
  3117. }
  3118. }
  3119. for _, item := range advices {
  3120. if item.IsMedicine == 1 {
  3121. isMedicine = true
  3122. }
  3123. }
  3124. if isCharge {
  3125. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3126. return
  3127. }
  3128. if isMedicine {
  3129. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3130. return
  3131. }
  3132. //已收费和已发药限制逻辑
  3133. if len(projects) > 0 {
  3134. for _, item := range projects {
  3135. service.DeletePrintInfo(item.ID) //删除打印信息
  3136. if goodOutConfig.IsOpen != 1 {
  3137. if stockConfig.IsOpen == 1 {
  3138. if item.Type == 3 && item.IsOut == 1 {
  3139. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3140. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3141. good.Total = good.Total + f_count
  3142. service.UpdateGoodInfo(&good)
  3143. operation_time := time.Now().Unix()
  3144. creater := c.GetAdminUserInfo().AdminUser.Id
  3145. //创建退库单
  3146. timeStr := time.Now().Format("2006-01-02")
  3147. timeArr := strings.Split(timeStr, "-")
  3148. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3149. total = total + 1
  3150. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3151. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3152. cancelStock := models.CancelStock{
  3153. OrderNumber: orderNumber,
  3154. OperaTime: operation_time,
  3155. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3156. Creater: creater,
  3157. Ctime: time.Now().Unix(),
  3158. Status: 1,
  3159. ReturnTime: item.RecordDate,
  3160. Type: 1,
  3161. StorehouseId: houseConfig.StorehouseOutInfo,
  3162. IsCheck: 1,
  3163. }
  3164. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3165. if msgerrkonde == gorm.ErrRecordNotFound {
  3166. service.AddSigleCancelStock(&cancelStock)
  3167. }
  3168. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3169. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3170. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3171. //查询该耗材是否出库
  3172. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3173. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3174. deaerler, _ := service.GetDealerById(info.Dealer)
  3175. var total_count int64
  3176. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3177. total_count += count
  3178. if info.ID > 0 {
  3179. if info.Count >= total_count {
  3180. //回退库存
  3181. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3182. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3183. var flush_count int64
  3184. for _, it := range goodList {
  3185. flush_count += it.StockCount
  3186. }
  3187. cancelStockInfo := models.CancelStockInfo{
  3188. GoodId: item.ProjectId,
  3189. CancelStockId: cancel.ID,
  3190. GoodTypeId: good.GoodTypeId,
  3191. Count: prescribingNumber,
  3192. Price: info.Price,
  3193. Total: 0,
  3194. ProductDate: info.ProductDate,
  3195. ExpiryDate: info.ExpiryDate,
  3196. Ctime: time.Now().Unix(),
  3197. Status: 1,
  3198. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3199. OrderNumber: cancel.OrderNumber,
  3200. Type: 0,
  3201. Dealer: deaerler.DealerName,
  3202. Manufacturer: manufacturer.ManufacturerName,
  3203. Number: info.Number,
  3204. RegisterAccount: "",
  3205. Remark: "",
  3206. WarehouseInfoId: info.WarehouseInfotId,
  3207. PatientId: info.PatientId,
  3208. RecordDate: info.SysRecordTime,
  3209. StorehouseId: houseConfig.StorehouseOutInfo,
  3210. IsCheck: 1,
  3211. }
  3212. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3213. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  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. if info.Count < total_count {
  3254. //回退库存
  3255. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3256. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3257. var flush_count int64
  3258. for _, it := range goodList {
  3259. flush_count += it.StockCount
  3260. }
  3261. cancelStockInfo := models.CancelStockInfo{
  3262. GoodId: item.ProjectId,
  3263. CancelStockId: cancel.ID,
  3264. GoodTypeId: good.GoodTypeId,
  3265. Count: info.Count,
  3266. Price: info.Price,
  3267. Total: 0,
  3268. ProductDate: info.ProductDate,
  3269. ExpiryDate: info.ExpiryDate,
  3270. Ctime: time.Now().Unix(),
  3271. Status: 1,
  3272. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3273. OrderNumber: cancel.OrderNumber,
  3274. Type: 0,
  3275. Dealer: deaerler.DealerName,
  3276. Manufacturer: manufacturer.ManufacturerName,
  3277. Number: info.Number,
  3278. RegisterAccount: "",
  3279. Remark: "",
  3280. WarehouseInfoId: info.WarehouseInfotId,
  3281. PatientId: info.PatientId,
  3282. RecordDate: info.SysRecordTime,
  3283. StorehouseId: houseConfig.StorehouseOutInfo,
  3284. IsCheck: 1,
  3285. }
  3286. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3287. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3288. flow := models.VmStockFlow{
  3289. WarehousingId: info.WarehouseInfotId,
  3290. GoodId: item.ProjectId,
  3291. Number: info.Number,
  3292. LicenseNumber: info.LicenseNumber,
  3293. Count: info.Count,
  3294. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3295. PatientId: item.PatientId,
  3296. SystemTime: info.SysRecordTime,
  3297. ConsumableType: 7,
  3298. IsSys: 0,
  3299. WarehousingOrder: "",
  3300. WarehouseOutId: info.WarehouseOutId,
  3301. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3302. IsEdit: 0,
  3303. CancelStockId: cancel.ID,
  3304. CancelOrderNumber: cancel.OrderNumber,
  3305. Manufacturer: manufacturer.ID,
  3306. Dealer: 0,
  3307. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3308. UpdateCreator: 0,
  3309. Status: 1,
  3310. Ctime: time.Now().Unix(),
  3311. Mtime: 0,
  3312. Price: info.Price,
  3313. WarehousingDetailId: info.WarehouseInfotId,
  3314. WarehouseOutDetailId: info.ID,
  3315. CancelOutDetailId: cancelInfo.ID,
  3316. ProductDate: info.ProductDate,
  3317. ExpireDate: info.ExpiryDate,
  3318. StorehouseId: houseConfig.StorehouseOutInfo,
  3319. OverCount: flush_count,
  3320. }
  3321. service.CreateStockFlowOne(flow)
  3322. //退库数量增加
  3323. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3324. //出库数量减少
  3325. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  3326. }
  3327. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3328. var flush_count int64
  3329. for _, it := range goodList {
  3330. flush_count += it.StockCount
  3331. }
  3332. //查询已出库数量
  3333. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3334. if prescribingNumber < dialysisInfo.Count {
  3335. //改变数量
  3336. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3337. }
  3338. if prescribingNumber >= dialysisInfo.Count {
  3339. //删除出库表
  3340. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3341. }
  3342. //更新库存
  3343. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  3344. //更新基础库库存
  3345. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  3346. }
  3347. }
  3348. }
  3349. }
  3350. //保存耗材出库
  3351. if goodOutConfig.IsOpen == 1 {
  3352. if item.Type == 3 {
  3353. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3354. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3355. good.Total = good.Total + f_count
  3356. service.UpdateGoodInfo(&good)
  3357. operation_time := time.Now().Unix()
  3358. creater := c.GetAdminUserInfo().AdminUser.Id
  3359. //创建退库单
  3360. timeStr := time.Now().Format("2006-01-02")
  3361. timeArr := strings.Split(timeStr, "-")
  3362. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3363. total = total + 1
  3364. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3365. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3366. cancelStock := models.CancelStock{
  3367. OrderNumber: orderNumber,
  3368. OperaTime: operation_time,
  3369. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3370. Creater: creater,
  3371. Ctime: time.Now().Unix(),
  3372. Status: 1,
  3373. ReturnTime: item.RecordDate,
  3374. Type: 1,
  3375. StorehouseId: houseConfig.StorehouseOutInfo,
  3376. IsCheck: 1,
  3377. }
  3378. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3379. if msgerrkonde == gorm.ErrRecordNotFound {
  3380. service.AddSigleCancelStock(&cancelStock)
  3381. }
  3382. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3383. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3384. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3385. //查询该耗材是否出库
  3386. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3387. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3388. deaerler, _ := service.GetDealerById(info.Dealer)
  3389. var total_count int64
  3390. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3391. total_count += count
  3392. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3393. var flush_count int64
  3394. for _, it := range goodList {
  3395. flush_count += it.StockCount
  3396. }
  3397. fmt.Println("历史出库数据", info.Count)
  3398. fmt.Println("出库数量", total_count)
  3399. if info.ID > 0 {
  3400. cancelStockInfo := models.CancelStockInfo{
  3401. GoodId: item.ProjectId,
  3402. CancelStockId: cancel.ID,
  3403. GoodTypeId: good.GoodTypeId,
  3404. Count: prescribingNumber,
  3405. Price: info.Price,
  3406. Total: 0,
  3407. ProductDate: info.ProductDate,
  3408. ExpiryDate: info.ExpiryDate,
  3409. Ctime: time.Now().Unix(),
  3410. Status: 1,
  3411. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3412. OrderNumber: cancel.OrderNumber,
  3413. Type: 0,
  3414. Dealer: deaerler.DealerName,
  3415. Manufacturer: manufacturer.ManufacturerName,
  3416. Number: info.Number,
  3417. RegisterAccount: "",
  3418. Remark: "",
  3419. WarehouseInfoId: info.WarehouseInfotId,
  3420. PatientId: info.PatientId,
  3421. RecordDate: info.SysRecordTime,
  3422. StorehouseId: houseConfig.StorehouseOutInfo,
  3423. IsCheck: 1,
  3424. }
  3425. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3426. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3427. //查询出库数量
  3428. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  3429. //出库数据 大于 退库数量
  3430. if len(list) > 0 {
  3431. for _, it := range list {
  3432. //回退库存
  3433. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  3434. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3435. var flush_count_one int64
  3436. for _, it := range goodList {
  3437. flush_count_one += it.StockCount
  3438. }
  3439. //查询该批次是否有退库数据
  3440. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  3441. creater := c.GetAdminUserInfo().AdminUser.Id
  3442. flow := models.VmStockFlow{
  3443. WarehousingId: it.WarehouseInfotId,
  3444. GoodId: it.GoodId,
  3445. Number: it.Number,
  3446. LicenseNumber: it.LicenseNumber,
  3447. Count: it.Count,
  3448. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3449. PatientId: it.PatientId,
  3450. SystemTime: it.SysRecordTime,
  3451. ConsumableType: 7,
  3452. IsSys: 0,
  3453. WarehousingOrder: "",
  3454. WarehouseOutId: it.WarehouseOutId,
  3455. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  3456. IsEdit: 0,
  3457. CancelStockId: cancel.ID,
  3458. CancelOrderNumber: cancel.OrderNumber,
  3459. Manufacturer: manufacturer.ID,
  3460. Dealer: 0,
  3461. Creator: creater,
  3462. UpdateCreator: 0,
  3463. Status: 1,
  3464. Ctime: time.Now().Unix(),
  3465. Mtime: 0,
  3466. Price: it.Price,
  3467. WarehousingDetailId: it.WarehouseInfotId,
  3468. WarehouseOutDetailId: it.ID,
  3469. CancelOutDetailId: cancelInfo.ID,
  3470. ProductDate: it.ProductDate,
  3471. ExpireDate: it.ExpiryDate,
  3472. StorehouseId: houseConfig.StorehouseOutInfo,
  3473. OverCount: flush_count_one,
  3474. }
  3475. service.CreateStockFlowOne(flow)
  3476. //if flow.ID > 0 {
  3477. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  3478. //}
  3479. }
  3480. }
  3481. //flow := models.VmStockFlow{
  3482. // WarehousingId: info.WarehouseInfotId,
  3483. // GoodId: item.ProjectId,
  3484. // Number: info.Number,
  3485. // LicenseNumber: info.LicenseNumber,
  3486. // Count: prescribingNumber,
  3487. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3488. // PatientId: item.PatientId,
  3489. // SystemTime: info.SysRecordTime,
  3490. // ConsumableType: 7,
  3491. // IsSys: 0,
  3492. // WarehousingOrder: "",
  3493. // WarehouseOutId: info.WarehouseOutId,
  3494. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3495. // IsEdit: 0,
  3496. // CancelStockId: cancel.ID,
  3497. // CancelOrderNumber: cancel.OrderNumber,
  3498. // Manufacturer: manufacturer.ID,
  3499. // Dealer: 0,
  3500. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  3501. // UpdateCreator: 0,
  3502. // Status: 1,
  3503. // Ctime: time.Now().Unix(),
  3504. // Mtime: 0,
  3505. // Price: info.Price,
  3506. // WarehousingDetailId: info.WarehouseInfotId,
  3507. // WarehouseOutDetailId: info.ID,
  3508. // CancelOutDetailId: cancelInfo.ID,
  3509. // ProductDate: info.ProductDate,
  3510. // ExpireDate: info.ExpiryDate,
  3511. // StorehouseId: houseConfig.StorehouseOutInfo,
  3512. // OverCount: flush_count,
  3513. //}
  3514. //service.CreateStockFlowOne(flow)
  3515. //退库数量增加
  3516. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3517. //出库数量减少
  3518. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3519. //查询已出库数量
  3520. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3521. if prescribingNumber < dialysisInfo.Count {
  3522. //改变数量
  3523. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3524. }
  3525. if prescribingNumber >= dialysisInfo.Count {
  3526. //删除出库表
  3527. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3528. }
  3529. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3530. var flush_count_one int64
  3531. for _, it := range goodList {
  3532. flush_count_one += it.StockCount
  3533. }
  3534. //更新库存
  3535. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  3536. fmt.Println("msgerrkonde23332323", msgerrkonde)
  3537. //更新基础库库存
  3538. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  3539. }
  3540. }
  3541. }
  3542. }
  3543. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3544. fmt.Println(err)
  3545. }
  3546. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3547. fmt.Println(err)
  3548. if len(advices) > 0 {
  3549. for _, item := range advices {
  3550. redis := service.RedisClient()
  3551. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  3552. redis.Set(keyFive, "", time.Second)
  3553. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  3554. redis.Set(keyOne, "", time.Second)
  3555. redis.Close()
  3556. }
  3557. }
  3558. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3559. if len(advices) > 0 {
  3560. for _, item := range advices {
  3561. creater := c.GetAdminUserInfo().AdminUser.Id
  3562. service.DrugAutoAddCancelInfo(item, creater)
  3563. }
  3564. }
  3565. } else {
  3566. if drugOutConfig.IsOpen == 1 {
  3567. if len(advices) > 0 {
  3568. for _, item := range advices {
  3569. creater := c.GetAdminUserInfo().AdminUser.Id
  3570. service.DrugAutoAddCancelInfo(item, creater)
  3571. }
  3572. }
  3573. } else {
  3574. if len(advices) > 0 {
  3575. for _, item := range advices {
  3576. creater := c.GetAdminUserInfo().AdminUser.Id
  3577. service.DrugAutoAddCancelInfo(item, creater)
  3578. }
  3579. }
  3580. }
  3581. }
  3582. c.ServeSuccessJSON(map[string]interface{}{
  3583. "msg": "删除成功",
  3584. })
  3585. return
  3586. }
  3587. func (c *HisApiController) DeleteDoctorAdvice() {
  3588. id, _ := c.GetInt64("id")
  3589. advice, _ := service.GetHisDoctorAdvicesById(id)
  3590. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3591. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3592. //已收费和已发药的限制逻辑
  3593. isCharge := false
  3594. isMedicine := false
  3595. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3596. //获取今天该患者所有处方,判断是否发药或者收费
  3597. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3598. for _, item := range new_prescriptions {
  3599. if item.IsMedicine == 1 {
  3600. isMedicine = true
  3601. }
  3602. }
  3603. for _, item := range new_prescriptions {
  3604. if item.OrderStatus == 4 {
  3605. isCharge = true
  3606. }
  3607. }
  3608. if isMedicine {
  3609. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3610. return
  3611. }
  3612. if isCharge {
  3613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3614. return
  3615. }
  3616. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  3617. for _, item := range advices {
  3618. if item.IsMedicine == 1 {
  3619. isMedicine = true
  3620. }
  3621. }
  3622. if isMedicine {
  3623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  3624. return
  3625. }
  3626. if new_prescription.ID > 0 {
  3627. if new_prescription.OrderStatus == 2 {
  3628. isCharge = true
  3629. }
  3630. }
  3631. if isCharge {
  3632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3633. return
  3634. }
  3635. //已收费和已发药的限制逻辑
  3636. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  3637. redis := service.RedisClient()
  3638. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  3639. redis.Set(keyFive, "", time.Second)
  3640. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  3641. redis.Set(keyOne, "", time.Second)
  3642. defer redis.Close()
  3643. if err == nil {
  3644. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3645. //查询是否在处方中出库
  3646. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3647. if openConfig.IsOpen != 1 {
  3648. //判断该医嘱是否执行了
  3649. if advice.ExecutionState == 1 {
  3650. creater := c.GetAdminUserInfo().AdminUser.Id
  3651. service.DrugAutoAddCancelInfo(&advice, creater)
  3652. }
  3653. }
  3654. //开启保存处方扣减功能
  3655. if openConfig.IsOpen == 1 {
  3656. creater := c.GetAdminUserInfo().AdminUser.Id
  3657. service.DrugAutoAddCancelInfo(&advice, creater)
  3658. }
  3659. } else {
  3660. if drugOutConfig.IsOpen == 1 {
  3661. //查询是否在处方中出库
  3662. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3663. if openConfig.IsOpen != 1 {
  3664. //判断该医嘱是否执行了
  3665. if advice.ExecutionState == 1 {
  3666. creater := c.GetAdminUserInfo().AdminUser.Id
  3667. service.DrugAutoAddCancelInfo(&advice, creater)
  3668. }
  3669. }
  3670. //开启保存处方扣减功能
  3671. if openConfig.IsOpen == 1 {
  3672. creater := c.GetAdminUserInfo().AdminUser.Id
  3673. service.DrugAutoAddCancelInfo(&advice, creater)
  3674. }
  3675. } else {
  3676. //判断该医嘱是否执行了
  3677. if advice.ExecutionState == 1 {
  3678. creater := c.GetAdminUserInfo().AdminUser.Id
  3679. service.DrugAutoAddCancelInfo(&advice, creater)
  3680. }
  3681. }
  3682. }
  3683. c.ServeSuccessJSON(map[string]interface{}{
  3684. "msg": "删除成功",
  3685. })
  3686. return
  3687. } else {
  3688. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3689. return
  3690. }
  3691. }
  3692. func (c *HisApiController) DeleteProject() {
  3693. id, _ := c.GetInt64("id")
  3694. adminInfo := c.GetAdminUserInfo()
  3695. project, _ := service.GetHisProjectByID(id)
  3696. // var consumable models.DialysisBeforePrepare
  3697. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3698. //耗材保存处方出库
  3699. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3700. isCharge := false
  3701. isMedicine := false
  3702. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3703. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3704. for _, item := range new_prescriptions {
  3705. if item.IsMedicine == 1 {
  3706. isMedicine = true
  3707. }
  3708. }
  3709. for _, item := range new_prescriptions {
  3710. if item.OrderStatus == 4 {
  3711. isCharge = true
  3712. }
  3713. }
  3714. if isMedicine {
  3715. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3716. return
  3717. }
  3718. if isCharge {
  3719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3720. return
  3721. }
  3722. if new_prescription.ID > 0 {
  3723. if new_prescription.OrderStatus == 2 {
  3724. isCharge = true
  3725. }
  3726. }
  3727. if isCharge {
  3728. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3729. return
  3730. }
  3731. service.DeletePrintInfo(id)
  3732. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  3733. label.Status = 0
  3734. service.CreateHisLabelRecord(&label)
  3735. fmt.Println(goodOutConfig.IsOpen)
  3736. if goodOutConfig.IsOpen != 1 {
  3737. if stockConfig.IsOpen == 1 {
  3738. if project.Type == 2 {
  3739. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3740. fmt.Println(err)
  3741. }
  3742. if project.Type == 3 && project.IsOut == 1 {
  3743. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3744. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3745. f_count, _ := strconv.ParseFloat(project.Count, 64)
  3746. operation_time := time.Now().Unix()
  3747. creater := adminInfo.AdminUser.Id
  3748. //创建退库单
  3749. timeStr := time.Now().Format("2006-01-02")
  3750. timeArr := strings.Split(timeStr, "-")
  3751. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  3752. total = total + 1
  3753. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3754. cancelStock := models.CancelStock{
  3755. OrderNumber: orderNumber,
  3756. OperaTime: operation_time,
  3757. OrgId: adminInfo.CurrentOrgId,
  3758. Creater: creater,
  3759. Ctime: time.Now().Unix(),
  3760. Status: 1,
  3761. ReturnTime: project.RecordDate,
  3762. Type: 1,
  3763. StorehouseId: houseConfig.StorehouseOutInfo,
  3764. IsCheck: 1,
  3765. }
  3766. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  3767. if msgerrkonde == gorm.ErrRecordNotFound {
  3768. service.AddSigleCancelStock(&cancelStock)
  3769. }
  3770. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  3771. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3772. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3773. //查询是否有出库
  3774. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  3775. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3776. deaerler, _ := service.GetDealerById(info.Dealer)
  3777. if info.ID > 0 {
  3778. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  3779. if info.Count >= prescribingNumber {
  3780. cancelStockInfo := models.CancelStockInfo{
  3781. GoodId: project.ProjectId,
  3782. CancelStockId: cancel.ID,
  3783. GoodTypeId: good.GoodTypeId,
  3784. Count: prescribingNumber,
  3785. Price: info.Price,
  3786. Total: 0,
  3787. ProductDate: info.ProductDate,
  3788. ExpiryDate: info.ExpiryDate,
  3789. Ctime: time.Now().Unix(),
  3790. Status: 1,
  3791. OrgId: adminInfo.CurrentOrgId,
  3792. OrderNumber: cancel.OrderNumber,
  3793. Type: 0,
  3794. Dealer: deaerler.DealerName,
  3795. Manufacturer: manufacturer.ManufacturerName,
  3796. Number: info.Number,
  3797. RegisterAccount: "",
  3798. Remark: "",
  3799. WarehouseInfoId: info.WarehouseInfotId,
  3800. PatientId: info.PatientId,
  3801. RecordDate: info.SysRecordTime,
  3802. StorehouseId: houseConfig.StorehouseOutInfo,
  3803. IsCheck: 1,
  3804. }
  3805. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3806. //回退库存
  3807. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  3808. //退库数量增加
  3809. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  3810. //出库数量减少
  3811. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  3812. }
  3813. if info.Count < prescribingNumber {
  3814. cancelStockInfo := models.CancelStockInfo{
  3815. GoodId: project.ProjectId,
  3816. CancelStockId: cancel.ID,
  3817. GoodTypeId: good.GoodTypeId,
  3818. Count: info.Count,
  3819. Price: info.Price,
  3820. Total: 0,
  3821. ProductDate: info.ProductDate,
  3822. ExpiryDate: info.ExpiryDate,
  3823. Ctime: time.Now().Unix(),
  3824. Status: 1,
  3825. OrgId: adminInfo.CurrentOrgId,
  3826. OrderNumber: cancel.OrderNumber,
  3827. Type: 0,
  3828. Dealer: deaerler.DealerName,
  3829. Manufacturer: manufacturer.ManufacturerName,
  3830. Number: info.Number,
  3831. RegisterAccount: "",
  3832. Remark: "",
  3833. WarehouseInfoId: info.WarehouseInfotId,
  3834. PatientId: info.PatientId,
  3835. RecordDate: info.SysRecordTime,
  3836. StorehouseId: houseConfig.StorehouseOutInfo,
  3837. IsCheck: 1,
  3838. }
  3839. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3840. //回退库存
  3841. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  3842. //退库数量增加
  3843. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3844. //出库数量减少
  3845. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  3846. }
  3847. //查询剩余库存
  3848. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3849. var over_count int64
  3850. for _, it := range goodList {
  3851. over_count += it.StockCount
  3852. }
  3853. //出库数据 大于 退库数量
  3854. if info.Count >= prescribingNumber {
  3855. flow := models.VmStockFlow{
  3856. WarehousingId: info.WarehouseInfotId,
  3857. GoodId: project.ProjectId,
  3858. Number: info.Number,
  3859. LicenseNumber: info.LicenseNumber,
  3860. Count: prescribingNumber,
  3861. UserOrgId: adminInfo.CurrentOrgId,
  3862. PatientId: project.PatientId,
  3863. SystemTime: info.SysRecordTime,
  3864. ConsumableType: 7,
  3865. IsSys: 0,
  3866. WarehousingOrder: "",
  3867. WarehouseOutId: info.WarehouseOutId,
  3868. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3869. IsEdit: 0,
  3870. CancelStockId: cancel.ID,
  3871. CancelOrderNumber: cancel.OrderNumber,
  3872. Manufacturer: manufacturer.ID,
  3873. Dealer: 0,
  3874. Creator: adminInfo.AdminUser.Id,
  3875. UpdateCreator: 0,
  3876. Status: 1,
  3877. Ctime: time.Now().Unix(),
  3878. Mtime: 0,
  3879. Price: info.Price,
  3880. WarehousingDetailId: info.WarehouseInfotId,
  3881. WarehouseOutDetailId: info.ID,
  3882. CancelOutDetailId: cancelInfo.ID,
  3883. ProductDate: info.ProductDate,
  3884. ExpireDate: info.ExpiryDate,
  3885. StorehouseId: houseConfig.StorehouseOutInfo,
  3886. OverCount: over_count,
  3887. }
  3888. service.CreateStockFlowOne(flow)
  3889. }
  3890. //出库数据小于退库数据
  3891. if info.Count < prescribingNumber {
  3892. flow := models.VmStockFlow{
  3893. WarehousingId: info.WarehouseInfotId,
  3894. GoodId: project.ProjectId,
  3895. Number: info.Number,
  3896. LicenseNumber: info.LicenseNumber,
  3897. Count: info.Count,
  3898. UserOrgId: adminInfo.CurrentOrgId,
  3899. PatientId: project.PatientId,
  3900. SystemTime: info.SysRecordTime,
  3901. ConsumableType: 7,
  3902. IsSys: 0,
  3903. WarehousingOrder: "",
  3904. WarehouseOutId: info.WarehouseOutId,
  3905. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3906. IsEdit: 0,
  3907. CancelStockId: cancel.ID,
  3908. CancelOrderNumber: cancel.OrderNumber,
  3909. Manufacturer: manufacturer.ID,
  3910. Dealer: 0,
  3911. Creator: adminInfo.AdminUser.Id,
  3912. UpdateCreator: 0,
  3913. Status: 1,
  3914. Ctime: time.Now().Unix(),
  3915. Mtime: 0,
  3916. Price: info.Price,
  3917. WarehousingDetailId: info.WarehouseInfotId,
  3918. WarehouseOutDetailId: info.ID,
  3919. CancelOutDetailId: cancelInfo.ID,
  3920. ProductDate: info.ProductDate,
  3921. ExpireDate: info.ExpiryDate,
  3922. StorehouseId: houseConfig.StorehouseOutInfo,
  3923. OverCount: over_count,
  3924. }
  3925. service.CreateStockFlowOne(flow)
  3926. }
  3927. //查询已出库数量
  3928. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  3929. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  3930. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  3931. if prescribingNumber < dialysisInfo.Count {
  3932. //改变数量
  3933. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  3934. }
  3935. if prescribingNumber >= dialysisInfo.Count {
  3936. //删除出库表
  3937. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  3938. }
  3939. //更新剩余库存
  3940. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  3941. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  3942. var total_count_one int64
  3943. for _, it := range stockList {
  3944. total_count_one += it.StockCount
  3945. }
  3946. //基础库插入数据
  3947. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  3948. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3949. var flush_count int64
  3950. for _, it := range goodListOne {
  3951. flush_count += it.StockCount
  3952. }
  3953. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  3954. if errs != nil {
  3955. goodErrcode := models.XtGoodErrcode{
  3956. UserOrgId: project.UserOrgId,
  3957. Errcode: "手动出库更新剩余出库失败",
  3958. GoodId: project.ProjectId,
  3959. Status: 1,
  3960. Ctime: time.Now().Unix(),
  3961. Mtime: 0,
  3962. Count: 0,
  3963. StockCount: 0,
  3964. Creater: creater,
  3965. BatchNumberId: 0,
  3966. WarehouseOutId: 0,
  3967. }
  3968. service.CreateGoodErrcode(goodErrcode)
  3969. }
  3970. }
  3971. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3972. fmt.Println(err)
  3973. } else {
  3974. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3975. fmt.Println(err)
  3976. }
  3977. } else {
  3978. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3979. fmt.Println(err)
  3980. }
  3981. }
  3982. //保存处方出库
  3983. if goodOutConfig.IsOpen == 1 {
  3984. if project.Type == 3 {
  3985. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3986. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3987. f_count, _ := strconv.ParseFloat(project.Count, 64)
  3988. operation_time := time.Now().Unix()
  3989. creater := adminInfo.AdminUser.Id
  3990. //创建退库单
  3991. timeStr := time.Now().Format("2006-01-02")
  3992. timeArr := strings.Split(timeStr, "-")
  3993. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  3994. total = total + 1
  3995. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3996. cancelStock := models.CancelStock{
  3997. OrderNumber: orderNumber,
  3998. OperaTime: operation_time,
  3999. OrgId: adminInfo.CurrentOrgId,
  4000. Creater: creater,
  4001. Ctime: time.Now().Unix(),
  4002. Status: 1,
  4003. ReturnTime: project.RecordDate,
  4004. Type: 1,
  4005. StorehouseId: houseConfig.StorehouseOutInfo,
  4006. IsCheck: 1,
  4007. }
  4008. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4009. if msgerrkonde == gorm.ErrRecordNotFound {
  4010. service.AddSigleCancelStock(&cancelStock)
  4011. }
  4012. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4013. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4014. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4015. //获取出库数据
  4016. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4017. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4018. deaerler, _ := service.GetDealerById(info.Dealer)
  4019. if info.ID > 0 {
  4020. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4021. if info.Count >= prescribingNumber {
  4022. cancelStockInfo := models.CancelStockInfo{
  4023. GoodId: project.ProjectId,
  4024. CancelStockId: cancel.ID,
  4025. GoodTypeId: good.GoodTypeId,
  4026. Count: prescribingNumber,
  4027. Price: info.Price,
  4028. Total: 0,
  4029. ProductDate: info.ProductDate,
  4030. ExpiryDate: info.ExpiryDate,
  4031. Ctime: time.Now().Unix(),
  4032. Status: 1,
  4033. OrgId: adminInfo.CurrentOrgId,
  4034. OrderNumber: cancel.OrderNumber,
  4035. Type: 0,
  4036. Dealer: deaerler.DealerName,
  4037. Manufacturer: manufacturer.ManufacturerName,
  4038. Number: info.Number,
  4039. RegisterAccount: "",
  4040. Remark: "",
  4041. WarehouseInfoId: info.WarehouseInfotId,
  4042. PatientId: info.PatientId,
  4043. RecordDate: info.SysRecordTime,
  4044. StorehouseId: houseConfig.StorehouseOutInfo,
  4045. IsCheck: 1,
  4046. }
  4047. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4048. //退库数量增加
  4049. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4050. //出库数量减少
  4051. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4052. }
  4053. if info.Count < prescribingNumber {
  4054. cancelStockInfo := models.CancelStockInfo{
  4055. GoodId: project.ProjectId,
  4056. CancelStockId: cancel.ID,
  4057. GoodTypeId: good.GoodTypeId,
  4058. Count: prescribingNumber,
  4059. Price: info.Price,
  4060. Total: 0,
  4061. ProductDate: info.ProductDate,
  4062. ExpiryDate: info.ExpiryDate,
  4063. Ctime: time.Now().Unix(),
  4064. Status: 1,
  4065. OrgId: adminInfo.CurrentOrgId,
  4066. OrderNumber: cancel.OrderNumber,
  4067. Type: 0,
  4068. Dealer: deaerler.DealerName,
  4069. Manufacturer: manufacturer.ManufacturerName,
  4070. Number: info.Number,
  4071. RegisterAccount: "",
  4072. Remark: "",
  4073. WarehouseInfoId: info.WarehouseInfotId,
  4074. PatientId: info.PatientId,
  4075. RecordDate: info.SysRecordTime,
  4076. StorehouseId: houseConfig.StorehouseOutInfo,
  4077. IsCheck: 1,
  4078. }
  4079. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4080. //回退库存
  4081. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4082. }
  4083. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4084. var over_count int64
  4085. for _, it := range goodList {
  4086. over_count += it.StockCount
  4087. }
  4088. //查询出库数量
  4089. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  4090. //出库数据 大于 退库数量
  4091. if len(list) > 0 {
  4092. for _, it := range list {
  4093. //回退库存
  4094. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4095. //退库数量增加
  4096. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  4097. //出库数量减少
  4098. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  4099. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4100. var over_count_one int64
  4101. for _, it := range goodList {
  4102. over_count_one += it.StockCount
  4103. }
  4104. //查询该批次是否有退库数据
  4105. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  4106. flow := models.VmStockFlow{
  4107. WarehousingId: it.WarehouseInfotId,
  4108. GoodId: it.GoodId,
  4109. Number: it.Number,
  4110. LicenseNumber: it.LicenseNumber,
  4111. Count: it.Count,
  4112. UserOrgId: adminInfo.CurrentOrgId,
  4113. PatientId: it.PatientId,
  4114. SystemTime: it.SysRecordTime,
  4115. ConsumableType: 7,
  4116. IsSys: 0,
  4117. WarehousingOrder: "",
  4118. WarehouseOutId: it.WarehouseOutId,
  4119. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4120. IsEdit: 0,
  4121. CancelStockId: cancel.ID,
  4122. CancelOrderNumber: cancel.OrderNumber,
  4123. Manufacturer: manufacturer.ID,
  4124. Dealer: 0,
  4125. Creator: adminInfo.AdminUser.Id,
  4126. UpdateCreator: 0,
  4127. Status: 1,
  4128. Ctime: time.Now().Unix(),
  4129. Mtime: 0,
  4130. Price: it.Price,
  4131. WarehousingDetailId: it.WarehouseInfotId,
  4132. WarehouseOutDetailId: it.ID,
  4133. CancelOutDetailId: cancelInfo.ID,
  4134. ProductDate: it.ProductDate,
  4135. ExpireDate: it.ExpiryDate,
  4136. StorehouseId: houseConfig.StorehouseOutInfo,
  4137. OverCount: over_count_one,
  4138. }
  4139. service.CreateStockFlowOne(flow)
  4140. }
  4141. }
  4142. //查询已出库数量
  4143. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4144. if prescribingNumber < dialysisInfo.Count {
  4145. //改变数量
  4146. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4147. }
  4148. if prescribingNumber >= dialysisInfo.Count {
  4149. //删除出库表
  4150. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4151. }
  4152. //更新剩余库存
  4153. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4154. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4155. var total_count_one int64
  4156. for _, it := range stockList {
  4157. total_count_one += it.StockCount
  4158. }
  4159. //基础库插入数据
  4160. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4161. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4162. var flush_count int64
  4163. for _, it := range goodListOne {
  4164. flush_count += it.StockCount
  4165. }
  4166. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4167. if errs != nil {
  4168. goodErrcode := models.XtGoodErrcode{
  4169. UserOrgId: project.UserOrgId,
  4170. Errcode: "手动出库更新剩余出库失败",
  4171. GoodId: project.ProjectId,
  4172. Status: 1,
  4173. Ctime: time.Now().Unix(),
  4174. Mtime: 0,
  4175. Count: 0,
  4176. StockCount: 0,
  4177. Creater: creater,
  4178. BatchNumberId: 0,
  4179. WarehouseOutId: 0,
  4180. }
  4181. service.CreateGoodErrcode(goodErrcode)
  4182. }
  4183. }
  4184. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4185. fmt.Println(err)
  4186. } else {
  4187. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4188. fmt.Println(err)
  4189. }
  4190. }
  4191. c.ServeSuccessJSON(map[string]interface{}{
  4192. "msg": "删除成功",
  4193. })
  4194. return
  4195. }
  4196. func (c *HisApiController) CreateHisAdditionalCharge() {
  4197. his_patient_id, _ := c.GetInt64("his_patient_id")
  4198. patient_id, _ := c.GetInt64("patient_id")
  4199. record_date := c.GetString("record_date")
  4200. timeLayout := "2006-01-02"
  4201. loc, _ := time.LoadLocation("Local")
  4202. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4203. if err != nil {
  4204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4205. return
  4206. }
  4207. adminInfo := c.GetAdminUserInfo()
  4208. recordDateTime := theTime.Unix()
  4209. dataBody := make(map[string]interface{}, 0)
  4210. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4211. if err != nil {
  4212. utils.ErrorLog(err.Error())
  4213. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4214. return
  4215. }
  4216. var additions []*models.HisAdditionalCharge
  4217. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  4218. additions, _ := dataBody["addition"].([]interface{})
  4219. if len(additions) > 0 {
  4220. for _, item := range additions {
  4221. items := item.(map[string]interface{})
  4222. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  4223. utils.ErrorLog("item_id")
  4224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4225. return
  4226. }
  4227. item_id := int64(items["item_id"].(float64))
  4228. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  4229. utils.ErrorLog("item_name")
  4230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4231. return
  4232. }
  4233. item_name := items["item_name"].(string)
  4234. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  4235. utils.ErrorLog("price")
  4236. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4237. return
  4238. }
  4239. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  4240. ctime := time.Now().Unix()
  4241. additional := &models.HisAdditionalCharge{
  4242. PatientId: patient_id,
  4243. HisPatientId: his_patient_id,
  4244. UserOrgId: adminInfo.CurrentOrgId,
  4245. RecordDate: recordDateTime,
  4246. CreatedTime: ctime,
  4247. UpdatedTime: ctime,
  4248. Modifier: adminInfo.AdminUser.Id,
  4249. Creator: adminInfo.AdminUser.Id,
  4250. Price: price,
  4251. ItemName: item_name,
  4252. ItemId: item_id,
  4253. Status: 1,
  4254. }
  4255. additions = append(additions, additional)
  4256. }
  4257. }
  4258. }
  4259. for _, item := range additions {
  4260. service.CreateAddtionalCharge(item)
  4261. }
  4262. c.ServeSuccessJSON(map[string]interface{}{
  4263. "msg": "创建成功",
  4264. })
  4265. }
  4266. func (c *HisApiController) CreateHisPatientCaseHistory() {
  4267. blood_fat := c.GetString("blood_fat")
  4268. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  4269. blood_sugar := c.GetString("blood_sugar")
  4270. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  4271. chief_conplaint := c.GetString("chief_conplaint")
  4272. dbp := c.GetString("dbp")
  4273. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  4274. delivery_way, _ := c.GetInt64("delivery_way")
  4275. diagnostic := c.GetString("diagnostic")
  4276. family_history := c.GetString("family_history")
  4277. height := c.GetString("height")
  4278. history_of_present_illness := c.GetString("history_of_present_illness")
  4279. is_infect, _ := c.GetInt64("is_infect")
  4280. past_history := c.GetString("past_history")
  4281. patient_id, _ := c.GetInt64("patient_id")
  4282. his_patient_id, _ := c.GetInt64("his_patient_id")
  4283. personal_history := c.GetString("personal_history")
  4284. pulse := c.GetString("pulse")
  4285. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  4286. sbp := c.GetString("sbp")
  4287. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  4288. heightfloat, _ := strconv.ParseFloat(height, 64)
  4289. sicktype := c.GetString("sick_type")
  4290. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  4291. symptom := c.GetString("symptom")
  4292. sick_date := c.GetString("sick_date")
  4293. temperatures := c.GetString("temperature")
  4294. temperature, _ := strconv.ParseFloat(temperatures, 64)
  4295. record_date := c.GetString("record_date")
  4296. breathing := c.GetString("breathing")
  4297. doctor_advice := c.GetString("doctor_advice")
  4298. remark := c.GetString("remark")
  4299. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  4300. sick, _ := c.GetInt64("sick")
  4301. diagnose, _ := c.GetInt64("diagnose")
  4302. //id, _ := c.GetInt64("id")
  4303. timeLayout := "2006-01-02"
  4304. loc, _ := time.LoadLocation("Local")
  4305. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4306. allergic_history := c.GetString("allergic_history")
  4307. if err != nil {
  4308. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4309. return
  4310. }
  4311. recordDateTime := theTime.Unix()
  4312. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  4313. if err != nil {
  4314. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4315. return
  4316. }
  4317. sickTimes := sickTime.Unix()
  4318. ctime := time.Now().Unix()
  4319. primary_disease := c.GetString("primary_disease")
  4320. confirm_failure_date := c.GetString("confirm_failure_date")
  4321. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  4322. drug_allergy_history := c.GetString("drug_allergy_history")
  4323. physical_examination := c.GetString("physical_examination")
  4324. special_inspection := c.GetString("special_inspection")
  4325. lab_apparatus := c.GetString("lab_apparatus")
  4326. caseHistory := models.HisPatientCaseHistory{
  4327. HisPatientId: his_patient_id,
  4328. PatientId: patient_id,
  4329. Temperature: temperature,
  4330. BloodSugar: bloodsugarfloat,
  4331. Pulse: pulsefloat,
  4332. Sbp: sbpfloat,
  4333. Dbp: dbpfloat,
  4334. Height: heightfloat,
  4335. BloodFat: bloodfatfloat,
  4336. SickType: sick_type,
  4337. Symptom: symptom,
  4338. SickDate: sickTimes,
  4339. IsInfect: is_infect,
  4340. HistoryOfPresentIllness: history_of_present_illness,
  4341. PastHistory: past_history,
  4342. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  4343. ChiefConplaint: chief_conplaint,
  4344. PersonalHistory: personal_history,
  4345. FamilyHistory: family_history,
  4346. Diagnostic: diagnostic,
  4347. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4348. Status: 1,
  4349. Ctime: ctime,
  4350. Mtime: ctime,
  4351. RecordDate: recordDateTime,
  4352. DeliveryWay: delivery_way,
  4353. Breathing: breathingfloat,
  4354. DoctorAdvice: doctor_advice,
  4355. Remark: remark,
  4356. Sick: sick,
  4357. Diagnose: diagnose,
  4358. AllergicHistory: allergic_history,
  4359. PrimaryDisease: primary_disease,
  4360. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  4361. DrugAllergyHistory: drug_allergy_history,
  4362. PhysicalExamination: physical_examination,
  4363. SpecialInspection: special_inspection,
  4364. LabApparatus: lab_apparatus,
  4365. }
  4366. //查询该患者是否有病历
  4367. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  4368. if errcodes == gorm.ErrRecordNotFound {
  4369. err = service.SaveHisPatientCaseHistory(&caseHistory)
  4370. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4371. if err != nil {
  4372. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4373. return
  4374. }
  4375. c.ServeSuccessJSON(map[string]interface{}{
  4376. "caseHistory": caseHistory,
  4377. "historyInfo": historyInfo,
  4378. })
  4379. return
  4380. } else if errcodes == nil {
  4381. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  4382. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4383. if err != nil {
  4384. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4385. return
  4386. }
  4387. c.ServeSuccessJSON(map[string]interface{}{
  4388. "caseHistory": caseHistory,
  4389. "historyInfo": historyInfo,
  4390. })
  4391. }
  4392. //查询该患者是否有病历
  4393. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  4394. //if errcode == gorm.ErrRecordNotFound {
  4395. // err = service.SaveHisPatientCaseHistory(caseHistory)
  4396. // if err != nil {
  4397. // c.ServeSuccessJSON(map[string]interface{}{
  4398. // "msg": "保存成功",
  4399. // })
  4400. // }
  4401. //} else if errcode == nil {
  4402. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4403. // return
  4404. //}
  4405. }
  4406. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  4407. patient_id, _ := c.GetInt64("patient_id", 0)
  4408. adminUser := c.GetAdminUserInfo()
  4409. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  4410. c.ServeSuccessJSON(map[string]interface{}{
  4411. "list": caseHistorys,
  4412. })
  4413. }
  4414. func (c *HisApiController) GetHisPatientCaseHistory() {
  4415. record_date, _ := c.GetInt64("record_date", 0)
  4416. patient_id, _ := c.GetInt64("patient_id", 0)
  4417. admin := c.GetAdminUserInfo()
  4418. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  4419. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  4420. c.ServeSuccessJSON(map[string]interface{}{
  4421. "info": info,
  4422. "case_history": case_history,
  4423. })
  4424. }
  4425. func (c *HisApiController) CreateCaseHistoryTemplate() {
  4426. template_name := c.GetString("template_name")
  4427. template_remark := c.GetString("template_remark")
  4428. doctor := c.GetAdminUserInfo().AdminUser.Id
  4429. diagnostic := c.GetString("diagnostic")
  4430. chief_conplaint := c.GetString("chief_conplain")
  4431. history_of_present_illness := c.GetString("history_of_present_illness")
  4432. past_history := c.GetString("past_history")
  4433. personal_history := c.GetString("personal_history")
  4434. family_history := c.GetString("family_history")
  4435. user_name := c.GetString("user_name")
  4436. doctor_advice := c.GetString("doctor_advice")
  4437. remark := c.GetString("remark")
  4438. //record_date := c.GetString("record_date")
  4439. //fmt.Println("record_date--------",record_date)
  4440. //timeLayout := "2006-01-02"
  4441. //loc, _ := time.LoadLocation("Local")
  4442. //
  4443. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4444. //if err != nil {
  4445. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4446. // return
  4447. //}
  4448. //recordDateTime := theTime.Unix()
  4449. ctime := time.Now().Unix()
  4450. template := models.HisCaseHistoryTemplate{
  4451. HistoryOfPresentIllness: history_of_present_illness,
  4452. PastHistory: past_history,
  4453. ChiefConplaint: chief_conplaint,
  4454. PersonalHistory: personal_history,
  4455. FamilyHistory: family_history,
  4456. Diagnostic: diagnostic,
  4457. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4458. Status: 1,
  4459. Ctime: ctime,
  4460. Mtime: ctime,
  4461. RecordDate: time.Now().Unix(),
  4462. TemplateName: template_name,
  4463. TemplateRemark: template_remark,
  4464. Creator: doctor,
  4465. Modifier: doctor,
  4466. UserName: user_name,
  4467. DoctorAdvice: doctor_advice,
  4468. Remark: remark,
  4469. }
  4470. err := service.SaveHisPatientCaseHistoryTemplate(template)
  4471. if err == nil {
  4472. c.ServeSuccessJSON(map[string]interface{}{
  4473. "msg": "保存成功",
  4474. })
  4475. } else {
  4476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4477. return
  4478. }
  4479. }
  4480. func (c *HisApiController) GetCaseHistoryTemplate() {
  4481. timeLayout := "2006-01-02"
  4482. loc, _ := time.LoadLocation("Local")
  4483. keyword := c.GetString("keyword")
  4484. start_time := c.GetString("start_time")
  4485. end_time := c.GetString("end_time")
  4486. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4487. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4488. admin := c.GetAdminUserInfo()
  4489. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  4490. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  4491. c.ServeSuccessJSON(map[string]interface{}{
  4492. "template": template,
  4493. //"history": history,
  4494. })
  4495. }
  4496. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4497. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4498. utils.ErrorLog("drug_name")
  4499. return enums.ErrorCodeParamWrong
  4500. }
  4501. adviceName, _ := json["drug_name"].(string)
  4502. if len(adviceName) == 0 {
  4503. utils.ErrorLog("len(advice_name) == 0")
  4504. return enums.ErrorCodeParamWrong
  4505. }
  4506. advice.AdviceName = adviceName
  4507. adviceDesc, _ := json["advice_desc"].(string)
  4508. advice.AdviceDesc = adviceDesc
  4509. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4510. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4511. advice.DrugSpec = drugSpec
  4512. }
  4513. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4514. remark, _ := json["remark"].(string)
  4515. advice.Remark = remark
  4516. }
  4517. if json["id"] == nil {
  4518. advice.DrugId = 0
  4519. } else {
  4520. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4521. drug_id := int64(json["id"].(float64))
  4522. advice.DrugId = drug_id
  4523. }
  4524. }
  4525. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4526. advice_id := int64(json["advice_id"].(float64))
  4527. advice.ID = advice_id
  4528. if advice.ID > 0 {
  4529. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4530. if err == nil {
  4531. if hisAdvice.ID > 0 {
  4532. advice.ExecutionTime = hisAdvice.ExecutionTime
  4533. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4534. advice.ExecutionState = hisAdvice.ExecutionState
  4535. advice.CheckTime = hisAdvice.CheckTime
  4536. advice.Checker = hisAdvice.Checker
  4537. advice.CheckState = hisAdvice.CheckState
  4538. advice.StartTime = hisAdvice.StartTime
  4539. advice.FeedetlSn = hisAdvice.FeedetlSn
  4540. }
  4541. }
  4542. }
  4543. }
  4544. //
  4545. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4546. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4547. // advice.ExecutionTime = execution_time
  4548. //}
  4549. //
  4550. //
  4551. //
  4552. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  4553. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  4554. // advice.ExecutionStaff = execution_staff
  4555. //}
  4556. //
  4557. //
  4558. //
  4559. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  4560. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  4561. // advice.ExecutionState = execution_state
  4562. //}
  4563. //
  4564. //
  4565. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  4566. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  4567. // advice.CheckTime = check_time
  4568. //}
  4569. //
  4570. //
  4571. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  4572. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  4573. // advice.CheckState = check_state
  4574. //}
  4575. //
  4576. //
  4577. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  4578. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  4579. // advice.Checker = checker
  4580. //}
  4581. //
  4582. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  4583. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  4584. // advice.StartTime = start_time
  4585. //}
  4586. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4587. drugSpecUnit, _ := json["min_unit"].(string)
  4588. advice.DrugSpecUnit = drugSpecUnit
  4589. }
  4590. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4591. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4592. advice.SingleDose = singleDose
  4593. }
  4594. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4595. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4596. advice.SingleDoseUnit = singleDoseUnit
  4597. }
  4598. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4599. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4600. advice.PrescribingNumber = prescribingNumber
  4601. }
  4602. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4603. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4604. advice.PrescribingNumberUnit = prescribingNumberUnit
  4605. }
  4606. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4607. deliveryWay, _ := json["delivery_way"].(string)
  4608. advice.DeliveryWay = deliveryWay
  4609. }
  4610. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4611. executionFrequency, _ := json["execution_frequency"].(string)
  4612. advice.ExecutionFrequency = executionFrequency
  4613. }
  4614. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4615. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4616. advice.Price = price
  4617. }
  4618. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4619. med_list_codg, _ := json["medical_insurance_number"].(string)
  4620. advice.MedListCodg = med_list_codg
  4621. }
  4622. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4623. day := int64(json["day"].(float64))
  4624. advice.Day = day
  4625. }
  4626. return 0
  4627. }
  4628. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  4629. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4630. id := int64(json["id"].(float64))
  4631. project.ID = id
  4632. historyProject, _ := service.GetHisProjectByID(id)
  4633. project.FeedetlSn = historyProject.FeedetlSn
  4634. }
  4635. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4636. project_id := int64(json["project_id"].(float64))
  4637. project.ProjectId = project_id
  4638. }
  4639. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4640. // price := int64(json["price"].(float64))
  4641. // formatInt_price := strconv.FormatInt(price, 10)
  4642. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4643. // project.Price = float_price
  4644. // }
  4645. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4646. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4647. project.Price = price
  4648. }
  4649. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  4650. total, _ := json["total"].(string)
  4651. project.Count = total
  4652. }
  4653. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  4654. medical_code, _ := json["medical_code"].(string)
  4655. project.MedListCodg = medical_code
  4656. }
  4657. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4658. single_dose, _ := json["single_dose"].(string)
  4659. project.SingleDose = single_dose
  4660. }
  4661. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4662. delivery_way, _ := json["delivery_way"].(string)
  4663. project.DeliveryWay = delivery_way
  4664. }
  4665. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4666. execution_frequency, _ := json["execution_frequency"].(string)
  4667. project.ExecutionFrequency = execution_frequency
  4668. }
  4669. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4670. remark, _ := json["remark"].(string)
  4671. project.Remark = remark
  4672. }
  4673. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  4674. day, _ := json["number_days"].(string)
  4675. project.Day = day
  4676. }
  4677. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  4678. unit, _ := json["unit"].(string)
  4679. project.Unit = unit
  4680. }
  4681. return 0
  4682. }
  4683. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  4684. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4685. id := int64(json["id"].(float64))
  4686. historyAddtions, _ := service.GetHisAdditionByID(id)
  4687. additionalCharge.ID = id
  4688. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  4689. }
  4690. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  4691. item_id := int64(json["item_id"].(float64))
  4692. additionalCharge.ItemId = item_id
  4693. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  4694. if config.ID > 0 {
  4695. if len(config.Code) > 0 {
  4696. additionalCharge.MedListCodg = config.Code
  4697. }
  4698. }
  4699. }
  4700. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4701. // price := int64(json["price"].(float64))
  4702. // formatInt_price := strconv.FormatInt(price, 10)
  4703. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4704. // additionalCharge.Price = float_price
  4705. // }
  4706. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4707. // price := int64(json["price"].(float64))
  4708. // formatInt_price := strconv.FormatInt(price, 10)
  4709. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4710. // additionalCharge.Price = float_price
  4711. //}
  4712. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4713. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4714. additionalCharge.Price = price
  4715. }
  4716. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  4717. count, _ := json["count"].(string)
  4718. counts, _ := strconv.ParseInt(count, 10, 64)
  4719. additionalCharge.Count = counts
  4720. }
  4721. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  4722. item_name, _ := json["item_name"].(string)
  4723. additionalCharge.ItemName = item_name
  4724. }
  4725. return 0
  4726. }
  4727. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4728. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4729. utils.ErrorLog("drug_name")
  4730. return enums.ErrorCodeParamWrong
  4731. }
  4732. adviceName, _ := json["drug_name"].(string)
  4733. if len(adviceName) == 0 {
  4734. utils.ErrorLog("len(advice_name) == 0")
  4735. return enums.ErrorCodeParamWrong
  4736. }
  4737. advice.AdviceName = adviceName
  4738. adviceDesc, _ := json["advice_desc"].(string)
  4739. advice.AdviceDesc = adviceDesc
  4740. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4741. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4742. advice.DrugSpec = drugSpec
  4743. }
  4744. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4745. remark, _ := json["remark"].(string)
  4746. advice.Remark = remark
  4747. }
  4748. if json["id"] == nil {
  4749. advice.DrugId = 0
  4750. } else {
  4751. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4752. drug_id := int64(json["id"].(float64))
  4753. advice.DrugId = drug_id
  4754. }
  4755. }
  4756. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  4757. groupno := int64(json["groupno"].(float64))
  4758. advice.Groupno = groupno
  4759. }
  4760. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  4761. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  4762. advice.HospApprFlag = hosp_appr_flag
  4763. }
  4764. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4765. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4766. advice.PrescribingNumber = prescribingNumber
  4767. }
  4768. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  4769. // frequency_type := int64(json["frequency_type"].(float64))
  4770. // advice.FrequencyType = frequency_type
  4771. //}
  4772. //
  4773. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  4774. // day_count := int64(json["day_count"].(float64))
  4775. // advice.DayCount = day_count
  4776. //}
  4777. //
  4778. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  4779. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  4780. // week_day, _ := json["week_day"].(string)
  4781. // advice.WeekDay = week_day
  4782. //}
  4783. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4784. drugSpecUnit, _ := json["min_unit"].(string)
  4785. advice.DrugSpecUnit = drugSpecUnit
  4786. }
  4787. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4788. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4789. advice.SingleDose = singleDose
  4790. }
  4791. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4792. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4793. advice.SingleDoseUnit = singleDoseUnit
  4794. }
  4795. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4796. deliveryWay, _ := json["delivery_way"].(string)
  4797. advice.DeliveryWay = deliveryWay
  4798. }
  4799. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4800. executionFrequency, _ := json["execution_frequency"].(string)
  4801. advice.ExecutionFrequency = executionFrequency
  4802. }
  4803. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4804. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4805. advice.Price = price
  4806. }
  4807. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4808. med_list_codg, _ := json["medical_insurance_number"].(string)
  4809. advice.MedListCodg = med_list_codg
  4810. }
  4811. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4812. day := int64(json["day"].(float64))
  4813. advice.Day = day
  4814. }
  4815. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4816. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4817. advice.PrescribingNumberUnit = prescribingNumberUnit
  4818. }
  4819. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4820. advice_id := int64(json["advice_id"].(float64))
  4821. advice.ID = advice_id
  4822. if advice.ID > 0 {
  4823. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4824. if err == nil {
  4825. if hisAdvice.ID > 0 {
  4826. advice.ExecutionTime = hisAdvice.ExecutionTime
  4827. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4828. advice.ExecutionState = hisAdvice.ExecutionState
  4829. advice.CheckTime = hisAdvice.CheckTime
  4830. advice.Checker = hisAdvice.Checker
  4831. advice.CheckState = hisAdvice.CheckState
  4832. advice.StartTime = hisAdvice.StartTime
  4833. advice.HospApprFlag = hisAdvice.HospApprFlag
  4834. advice.IsMedicine = hisAdvice.IsMedicine
  4835. if hisAdvice.UserOrgId == 10028 {
  4836. 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 {
  4837. advice.ExecutionTime = 0
  4838. advice.ExecutionStaff = 0
  4839. advice.ExecutionState = 2
  4840. advice.CheckTime = 0
  4841. advice.Checker = 0
  4842. advice.CheckState = 2
  4843. }
  4844. } else {
  4845. 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 {
  4846. advice.ExecutionTime = 0
  4847. advice.ExecutionStaff = 0
  4848. advice.ExecutionState = 2
  4849. advice.CheckTime = 0
  4850. advice.Checker = 0
  4851. advice.CheckState = 2
  4852. }
  4853. }
  4854. //advice.Groupno = hisAdvice.Groupno
  4855. }
  4856. }
  4857. }
  4858. }
  4859. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  4860. //
  4861. //if drugStockConfig.IsOpen == 1 {
  4862. //
  4863. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  4864. // if advice.ID == 0 { //医嘱不存在
  4865. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  4866. // drug.Total = drug.Total - advice.PrescribingNumber
  4867. // service.UpdateBaseDrugLib(&drug)
  4868. //
  4869. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  4870. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  4871. // drug.Total = drug.Total - num
  4872. // service.UpdateBaseDrugLib(&drug)
  4873. // }
  4874. //
  4875. // } else if advice.ID > 0 { //医嘱存在
  4876. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  4877. // var num float64
  4878. //
  4879. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  4880. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  4881. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  4882. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  4883. // drug.Total = drug.Total + num
  4884. // service.UpdateBaseDrugLib(&drug)
  4885. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  4886. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  4887. // drug.Total = drug.Total - num
  4888. // service.UpdateBaseDrugLib(&drug)
  4889. // }
  4890. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  4891. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  4892. // if num2 > advice.PrescribingNumber {
  4893. // num = num2 - advice.PrescribingNumber
  4894. // drug.Total = drug.Total + num
  4895. // service.UpdateBaseDrugLib(&drug)
  4896. // } else if num2 < advice.PrescribingNumber {
  4897. // num = advice.PrescribingNumber - num2
  4898. // drug.Total = drug.Total - num
  4899. // service.UpdateBaseDrugLib(&drug)
  4900. // }
  4901. //
  4902. // }
  4903. //
  4904. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  4905. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  4906. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  4907. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  4908. // if num1 > num2 {
  4909. // num = num1 - num2
  4910. // drug.Total = drug.Total + num
  4911. // service.UpdateBaseDrugLib(&drug)
  4912. // } else if num1 < num2 {
  4913. // num = num2 - num1
  4914. // drug.Total = drug.Total - num
  4915. // service.UpdateBaseDrugLib(&drug)
  4916. // }
  4917. //
  4918. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  4919. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  4920. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  4921. // if hisAdvice.PrescribingNumber > num2 {
  4922. // num = hisAdvice.PrescribingNumber - num2
  4923. // drug.Total = drug.Total + num
  4924. // service.UpdateBaseDrugLib(&drug)
  4925. // } else if num2 < advice.PrescribingNumber {
  4926. // num = num2 - hisAdvice.PrescribingNumber
  4927. // drug.Total = drug.Total - num
  4928. // service.UpdateBaseDrugLib(&drug)
  4929. // }
  4930. //
  4931. // }
  4932. // }
  4933. // }
  4934. //}
  4935. //
  4936. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4937. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4938. // advice.ExecutionTime = execution_time
  4939. //}
  4940. //
  4941. //
  4942. //
  4943. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  4944. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  4945. // advice.ExecutionStaff = execution_staff
  4946. //}
  4947. //
  4948. //
  4949. //
  4950. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  4951. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  4952. // advice.ExecutionState = execution_state
  4953. //}
  4954. //
  4955. //
  4956. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  4957. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  4958. // advice.CheckTime = check_time
  4959. //}
  4960. //
  4961. //
  4962. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  4963. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  4964. // advice.CheckState = check_state
  4965. //}
  4966. //
  4967. //
  4968. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  4969. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  4970. // advice.Checker = checker
  4971. //}
  4972. //
  4973. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  4974. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  4975. // advice.StartTime = start_time
  4976. //}
  4977. return 0
  4978. }
  4979. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  4980. project.ExecutionStaff = 0
  4981. project.ExecutionState = 2
  4982. project.ExecutionTime = 0
  4983. project.Checker = 0
  4984. project.CheckState = 2
  4985. project.CheckTime = 0
  4986. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4987. id := int64(json["id"].(float64))
  4988. project.ID = id
  4989. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  4990. project.ExecutionStaff = temp_project.ExecutionStaff
  4991. project.ExecutionState = temp_project.ExecutionState
  4992. project.ExecutionTime = temp_project.ExecutionTime
  4993. project.Checker = temp_project.Checker
  4994. project.CheckState = temp_project.CheckState
  4995. project.CheckTime = temp_project.CheckTime
  4996. project.TeamId = temp_project.TeamId
  4997. }
  4998. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  4999. types := int64(json["type"].(float64))
  5000. project.Type = types
  5001. }
  5002. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5003. project_id := int64(json["project_id"].(float64))
  5004. project.ProjectId = project_id
  5005. }
  5006. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  5007. team_id := int64(json["team_id"].(float64))
  5008. project.TeamId = team_id
  5009. }
  5010. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5011. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5012. project.Price = price
  5013. }
  5014. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5015. total, _ := json["total"].(string)
  5016. //totals, _ := strconv.ParseInt(total, 10, 64)
  5017. project.Count = total
  5018. }
  5019. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5020. medical_code, _ := json["medical_code"].(string)
  5021. project.MedListCodg = medical_code
  5022. }
  5023. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5024. single_dose, _ := json["single_dose"].(string)
  5025. project.SingleDose = single_dose
  5026. }
  5027. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5028. delivery_way, _ := json["delivery_way"].(string)
  5029. project.DeliveryWay = delivery_way
  5030. }
  5031. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5032. execution_frequency, _ := json["execution_frequency"].(string)
  5033. project.ExecutionFrequency = execution_frequency
  5034. }
  5035. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5036. remark, _ := json["remark"].(string)
  5037. project.Remark = remark
  5038. }
  5039. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5040. day, _ := json["number_days"].(string)
  5041. project.Day = day
  5042. }
  5043. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5044. unit, _ := json["unit"].(string)
  5045. project.Unit = unit
  5046. }
  5047. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5048. // frequency_type := int64(json["frequency_type"].(float64))
  5049. // project.FrequencyType = frequency_type
  5050. //}
  5051. //
  5052. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5053. // day_count := int64(json["day_count"].(float64))
  5054. // project.DayCount = day_count
  5055. //}
  5056. //
  5057. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5058. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5059. // week_day, _ := json["week_day"].(string)
  5060. // project.WeekDay = week_day
  5061. //}
  5062. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  5063. //
  5064. //if project.ID == 0 {
  5065. // if stockConfig.IsOpen == 1 {
  5066. // if project.Type == 3 {
  5067. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5068. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  5069. // good.Total = good.Total - f_count
  5070. // service.UpdateGoodInfo(&good)
  5071. // }
  5072. // }
  5073. //
  5074. //} else {
  5075. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  5076. //
  5077. // if stockConfig.IsOpen == 1 {
  5078. // if project.Type == 3 {
  5079. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5080. // if project.Count < temp_project.Count {
  5081. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5082. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5083. //
  5084. // other_count := f_count_two - f_count_one
  5085. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5086. // good.Total = good.Total + other_count_two
  5087. // service.UpdateGoodInfo(&good)
  5088. // } else if project.Count > temp_project.Count {
  5089. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5090. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5091. //
  5092. // other_count := f_count_one - f_count_two
  5093. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5094. // good.Total = good.Total - other_count_two
  5095. // service.UpdateGoodInfo(&good)
  5096. // }
  5097. //
  5098. // }
  5099. // }
  5100. //
  5101. //}
  5102. return 0
  5103. }
  5104. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5105. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5106. id := int64(json["id"].(float64))
  5107. additionalCharge.ID = id
  5108. }
  5109. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5110. item_id := int64(json["item_id"].(float64))
  5111. additionalCharge.ItemId = item_id
  5112. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5113. if config.ID > 0 {
  5114. if len(config.Code) > 0 {
  5115. additionalCharge.MedListCodg = config.Code
  5116. }
  5117. }
  5118. }
  5119. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5120. // price := int64(json["price"].(float64))
  5121. // formatInt_price := strconv.FormatInt(price, 10)
  5122. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5123. // additionalCharge.Price = float_price
  5124. // }
  5125. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5126. // price := int64(json["price"].(float64))
  5127. // formatInt_price := strconv.FormatInt(price, 10)
  5128. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5129. // additionalCharge.Price = float_price
  5130. //}
  5131. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5132. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5133. additionalCharge.Price = price
  5134. }
  5135. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5136. count, _ := json["count"].(string)
  5137. counts, _ := strconv.ParseInt(count, 10, 64)
  5138. additionalCharge.Count = counts
  5139. }
  5140. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5141. item_name, _ := json["item_name"].(string)
  5142. additionalCharge.ItemName = item_name
  5143. }
  5144. return 0
  5145. }
  5146. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  5147. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5148. utils.ErrorLog("drug_name")
  5149. return enums.ErrorCodeParamWrong
  5150. }
  5151. adviceName, _ := json["drug_name"].(string)
  5152. if len(adviceName) == 0 {
  5153. utils.ErrorLog("len(advice_name) == 0")
  5154. return enums.ErrorCodeParamWrong
  5155. }
  5156. advice.AdviceName = adviceName
  5157. adviceDesc, _ := json["advice_desc"].(string)
  5158. advice.AdviceDesc = adviceDesc
  5159. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5160. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5161. advice.DrugSpec = drugSpec
  5162. }
  5163. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5164. remark, _ := json["remark"].(string)
  5165. advice.Remark = remark
  5166. }
  5167. if json["id"] == nil {
  5168. advice.DrugId = 0
  5169. } else {
  5170. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5171. drug_id := int64(json["id"].(float64))
  5172. advice.DrugId = drug_id
  5173. }
  5174. }
  5175. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5176. drugSpecUnit, _ := json["min_unit"].(string)
  5177. advice.DrugSpecUnit = drugSpecUnit
  5178. }
  5179. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5180. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5181. advice.SingleDose = singleDose
  5182. }
  5183. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5184. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5185. advice.SingleDoseUnit = singleDoseUnit
  5186. }
  5187. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5188. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5189. advice.PrescribingNumber = prescribingNumber
  5190. }
  5191. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5192. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5193. advice.PrescribingNumberUnit = prescribingNumberUnit
  5194. }
  5195. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5196. deliveryWay, _ := json["delivery_way"].(string)
  5197. advice.DeliveryWay = deliveryWay
  5198. }
  5199. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5200. executionFrequency, _ := json["execution_frequency"].(string)
  5201. advice.ExecutionFrequency = executionFrequency
  5202. }
  5203. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5204. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5205. advice.Price = price
  5206. }
  5207. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5208. med_list_codg, _ := json["medical_insurance_number"].(string)
  5209. advice.MedListCodg = med_list_codg
  5210. }
  5211. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5212. day := int64(json["day"].(float64))
  5213. advice.Day = day
  5214. }
  5215. advice.FrequencyType = 1
  5216. return 0
  5217. }
  5218. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  5219. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5220. types := int64(json["type"].(float64))
  5221. project.Type = types
  5222. }
  5223. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5224. project_id := int64(json["project_id"].(float64))
  5225. project.ProjectId = project_id
  5226. }
  5227. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5228. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5229. project.Price = price
  5230. }
  5231. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5232. total, _ := json["total"].(string)
  5233. //totals, _ := strconv.ParseInt(total, 10, 64)
  5234. project.Count = total
  5235. }
  5236. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5237. medical_code, _ := json["medical_code"].(string)
  5238. project.MedListCodg = medical_code
  5239. }
  5240. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5241. single_dose, _ := json["single_dose"].(string)
  5242. project.SingleDose = single_dose
  5243. }
  5244. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5245. delivery_way, _ := json["delivery_way"].(string)
  5246. project.DeliveryWay = delivery_way
  5247. }
  5248. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5249. execution_frequency, _ := json["execution_frequency"].(string)
  5250. project.ExecutionFrequency = execution_frequency
  5251. }
  5252. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5253. remark, _ := json["remark"].(string)
  5254. project.Remark = remark
  5255. }
  5256. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5257. day, _ := json["number_days"].(string)
  5258. project.Day = day
  5259. }
  5260. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5261. unit, _ := json["unit"].(string)
  5262. project.Unit = unit
  5263. }
  5264. project.FrequencyType = 1
  5265. return 0
  5266. }
  5267. func (c *HisApiController) GetHisOrderList() {
  5268. page, _ := c.GetInt64("page", -1)
  5269. limit, _ := c.GetInt64("limit", -1)
  5270. start_time := c.GetString("start_time")
  5271. end_time := c.GetString("end_time")
  5272. types, _ := c.GetInt64("type", 0)
  5273. keywords := c.GetString("keywords")
  5274. p_type, _ := c.GetInt64("p_type", 0)
  5275. sort_type, _ := c.GetInt64("sort_type", 0)
  5276. charge_type, _ := c.GetInt64("charge_type", 0)
  5277. sch_type, _ := c.GetInt64("sch_type", 0)
  5278. zone_type, _ := c.GetInt64("zone_type", 0)
  5279. timeLayout := "2006-01-02"
  5280. loc, _ := time.LoadLocation("Local")
  5281. var startTime int64
  5282. if len(start_time) > 0 {
  5283. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5284. if err != nil {
  5285. //fmt.Println(err)
  5286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5287. return
  5288. }
  5289. startTime = theTime.Unix()
  5290. }
  5291. var endTime int64
  5292. if len(end_time) > 0 {
  5293. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5294. if err != nil {
  5295. utils.ErrorLog(err.Error())
  5296. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5297. return
  5298. }
  5299. endTime = theTime.Unix()
  5300. }
  5301. adminUser := c.GetAdminUserInfo()
  5302. org_id := adminUser.CurrentOrgId
  5303. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time, charge_type, sch_type, zone_type)
  5304. for _, item := range order {
  5305. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  5306. item.DoctorName = info.Doctor
  5307. item.DepartmentName = info.XtHisDepartment.Name
  5308. }
  5309. if err == nil {
  5310. c.ServeSuccessJSON(map[string]interface{}{
  5311. "order": order,
  5312. "total": total,
  5313. })
  5314. } else {
  5315. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5316. return
  5317. }
  5318. }
  5319. func (c *HisApiController) GetHisOrder() {
  5320. patient_id, _ := c.GetInt64("patient_id", 0)
  5321. number := c.GetString("number")
  5322. adminInfo := c.GetAdminUserInfo()
  5323. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  5324. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  5325. if err == nil {
  5326. c.ServeSuccessJSON(map[string]interface{}{
  5327. "order": order,
  5328. "prescription": prescriptions,
  5329. })
  5330. } else {
  5331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5332. return
  5333. }
  5334. }
  5335. func (c *HisApiController) GetHisPrescriptionList() {
  5336. record_date := c.GetString("record_date")
  5337. keywords := c.GetString("keywords")
  5338. page, _ := c.GetInt64("page")
  5339. limit, _ := c.GetInt64("limit")
  5340. sch_type, _ := c.GetInt64("sch_type")
  5341. timeLayout := "2006-01-02"
  5342. loc, _ := time.LoadLocation("Local")
  5343. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5344. if err != nil {
  5345. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5346. return
  5347. }
  5348. recordDateTime := theTime.Unix()
  5349. adminInfo := c.GetAdminUserInfo()
  5350. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  5351. //adminInfo := c.GetAdminUserInfo()
  5352. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  5353. //fmt.Println(prescriptionOrder)
  5354. if err == nil {
  5355. c.ServeSuccessJSON(map[string]interface{}{
  5356. "order": prescriptionOrder,
  5357. "total": total,
  5358. })
  5359. } else {
  5360. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5361. return
  5362. }
  5363. }
  5364. func (c *HisApiController) GetHisPrescriptionInfo() {
  5365. id, _ := c.GetInt64("id")
  5366. adminInfo := c.GetAdminUserInfo()
  5367. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  5368. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  5369. if err == nil {
  5370. c.ServeSuccessJSON(map[string]interface{}{
  5371. "order": prescriptionOrder,
  5372. "prescription": prescription,
  5373. })
  5374. } else {
  5375. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5376. return
  5377. }
  5378. }
  5379. func (c *HisApiController) GetMedicalInsuranceConfig() {
  5380. adminUser := c.GetAdminUserInfo()
  5381. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5382. c.ServeSuccessJSON(map[string]interface{}{
  5383. "config": config,
  5384. })
  5385. }
  5386. type ResultTwo struct {
  5387. ErrMsg interface{} `json:"err_msg"`
  5388. InfRefmsgid string `json:"inf_refmsgid"`
  5389. Infcode int64 `json:"infcode"`
  5390. Output struct {
  5391. Baseinfo struct {
  5392. Age float64 `json:"age"`
  5393. Brdy string `json:"brdy"`
  5394. Certno string `json:"certno"`
  5395. Gend string `json:"gend"`
  5396. Naty string `json:"naty"`
  5397. PsnCertType string `json:"psn_cert_type"`
  5398. PsnName string `json:"psn_name"`
  5399. PsnNo string `json:"psn_no"`
  5400. } `json:"baseinfo"`
  5401. Idetinfo []interface{} `json:"idetinfo"`
  5402. Iinfo []struct {
  5403. Balc float64 `json:"balc"`
  5404. CvlservFlag string `json:"cvlserv_flag"`
  5405. EmpName string `json:"emp_name"`
  5406. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  5407. Insutype string `json:"insutype"`
  5408. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  5409. PausInsuDate interface{} `json:"paus_insu_date"`
  5410. PsnInsuDate string `json:"psn_insu_date"`
  5411. PsnInsuStas string `json:"psn_insu_stas"`
  5412. PsnType string `json:"psn_type"`
  5413. } `json:"insuinfo"`
  5414. } `json:"output"`
  5415. RefmsgTime string `json:"refmsg_time"`
  5416. RespondTime string `json:"respond_time"`
  5417. Signtype interface{} `json:"signtype"`
  5418. WarnInfo interface{} `json:"warn_info"`
  5419. }
  5420. type ResultThree struct {
  5421. Cainfo interface{} `json:"cainfo"`
  5422. ErrMsg interface{} `json:"err_msg"`
  5423. InfRefmsgid string `json:"inf_refmsgid"`
  5424. Infcode int64 `json:"infcode"`
  5425. Output struct {
  5426. Data struct {
  5427. IptOtpNo string `json:"ipt_otp_no"`
  5428. MdtrtID string `json:"mdtrt_id"`
  5429. PsnNo string `json:"psn_no"`
  5430. } `json:"data"`
  5431. } `json:"output"`
  5432. RefmsgTime string `json:"refmsg_time"`
  5433. RespondTime string `json:"respond_time"`
  5434. Signtype interface{} `json:"signtype"`
  5435. WarnMsg interface{} `json:"warn_msg"`
  5436. }
  5437. type ResultFour struct {
  5438. Cainfo string `json:"cainfo"`
  5439. ErrMsg string `json:"err_msg"`
  5440. InfRefmsgid string `json:"inf_refmsgid"`
  5441. Infcode int64 `json:"infcode"`
  5442. Output struct {
  5443. Result []struct {
  5444. BasMednFlag string `json:"bas_medn_flag"`
  5445. ChldMedcFlag string `json:"chld_medc_flag"`
  5446. ChrgitmLv string `json:"chrgitm_lv"`
  5447. Cnt float64 `json:"cnt"`
  5448. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  5449. DrtReimFlag string `json:"drt_reim_flag"`
  5450. FeedetlSn string `json:"feedetl_sn"`
  5451. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5452. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  5453. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5454. ListSpItemFlag string `json:"list_sp_item_flag"`
  5455. LmtUsedFlag string `json:"lmt_used_flag"`
  5456. MedChrgitmType string `json:"med_chrgitm_type"`
  5457. Memo string `json:"memo"`
  5458. OverlmtAmt float64 `json:"overlmt_amt"`
  5459. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5460. Pric float64 `json:"pric"`
  5461. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  5462. SelfpayProp float64 `json:"selfpay_prop"`
  5463. } `json:"result"`
  5464. } `json:"output"`
  5465. RefmsgTime string `json:"refmsg_time"`
  5466. RespondTime string `json:"respond_time"`
  5467. Signtype string `json:"signtype"`
  5468. WarnMsg string `json:"warn_msg"`
  5469. }
  5470. type ResultFive struct {
  5471. Insutype string `json:"insutype"`
  5472. }
  5473. type ResultSix struct {
  5474. Cainfo interface{} `json:"cainfo"`
  5475. ErrMsg interface{} `json:"err_msg"`
  5476. InfRefmsgid string `json:"inf_refmsgid"`
  5477. Infcode int64 `json:"infcode"`
  5478. Output struct {
  5479. } `json:"output"`
  5480. RefmsgTime string `json:"refmsg_time"`
  5481. RespondTime string `json:"respond_time"`
  5482. Signtype interface{} `json:"signtype"`
  5483. WarnMsg interface{} `json:"warn_msg"`
  5484. }
  5485. type ResultSeven struct {
  5486. Cainfo string `json:"cainfo"`
  5487. ErrMsg string `json:"err_msg"`
  5488. InfRefmsgid string `json:"inf_refmsgid"`
  5489. Infcode int64 `json:"infcode"`
  5490. Output struct {
  5491. Setldetail []interface{} `json:"setldetail"`
  5492. Setlinfo struct {
  5493. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5494. AcctPay float64 `json:"acct_pay"`
  5495. ActPayDedc float64 `json:"act_pay_dedc"`
  5496. Age float64 `json:"age"`
  5497. Balc float64 `json:"balc"`
  5498. Brdy string `json:"brdy"`
  5499. Certno string `json:"certno"`
  5500. ClrOptins string `json:"clr_optins"`
  5501. ClrType string `json:"clr_type"`
  5502. ClrWay string `json:"clr_way"`
  5503. CvlservFlag string `json:"cvlserv_flag"`
  5504. CvlservPay float64 `json:"cvlserv_pay"`
  5505. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5506. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5507. Gend string `json:"gend"`
  5508. HifesPay float64 `json:"hifes_pay"`
  5509. HifmiPay float64 `json:"hifmi_pay"`
  5510. HifobPay float64 `json:"hifob_pay"`
  5511. HifpPay float64 `json:"hifp_pay"`
  5512. HospPartAmt float64 `json:"hosp_part_amt"`
  5513. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5514. Insutype string `json:"insutype"`
  5515. MafPay float64 `json:"maf_pay"`
  5516. MdtrtCertType string `json:"mdtrt_cert_type"`
  5517. MdtrtID string `json:"mdtrt_id"`
  5518. MedType string `json:"med_type"`
  5519. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5520. MedinsSetlID string `json:"medins_setl_id"`
  5521. Naty string `json:"naty"`
  5522. OthPay float64 `json:"oth_pay"`
  5523. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5524. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5525. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5526. PsnCashPay float64 `json:"psn_cash_pay"`
  5527. PsnCertType string `json:"psn_cert_type"`
  5528. PsnName string `json:"psn_name"`
  5529. PsnNo string `json:"psn_no"`
  5530. PsnPartAmt float64 `json:"psn_part_amt"`
  5531. PsnType string `json:"psn_type"`
  5532. SetlID string `json:"setl_id"`
  5533. SetlTime string `json:"setl_time"`
  5534. } `json:"setlinfo"`
  5535. } `json:"output"`
  5536. RefmsgTime string `json:"refmsg_time"`
  5537. RespondTime string `json:"respond_time"`
  5538. Signtype interface{} `json:"signtype"`
  5539. WarnMsg interface{} `json:"warn_msg"`
  5540. }
  5541. type ResultEight struct {
  5542. Cainfo string `json:"cainfo"`
  5543. ErrMsg string `json:"err_msg"`
  5544. InfRefmsgid string `json:"inf_refmsgid"`
  5545. Infcode int64 `json:"infcode"`
  5546. Output struct {
  5547. Stmtinfo struct {
  5548. SetlOptins string `json:"setl_optins"`
  5549. StmtRslt string `json:"stmt_rslt"`
  5550. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  5551. } `json:"stmtinfo"`
  5552. } `json:"output"`
  5553. RefmsgTime string `json:"refmsg_time"`
  5554. RespondTime string `json:"respond_time"`
  5555. Signtype interface{} `json:"signtype"`
  5556. WarnMsg interface{} `json:"warn_msg"`
  5557. }
  5558. type ResultNine struct {
  5559. Cainfo string `json:"cainfo"`
  5560. ErrMsg string `json:"err_msg"`
  5561. InfRefmsgid string `json:"inf_refmsgid"`
  5562. Infcode int64 `json:"infcode"`
  5563. Output struct {
  5564. FileQuryNo string `json:"file_qury_no"`
  5565. } `json:"output"`
  5566. RefmsgTime string `json:"refmsg_time"`
  5567. RespondTime string `json:"respond_time"`
  5568. Signtype interface{} `json:"signtype"`
  5569. WarnMsg interface{} `json:"warn_msg"`
  5570. }
  5571. type ResultTen struct {
  5572. Cainfo string `json:"cainfo"`
  5573. ErrMsg string `json:"err_msg"`
  5574. InfRefmsgid string `json:"inf_refmsgid"`
  5575. Infcode int64 `json:"infcode"`
  5576. Output struct {
  5577. DldEndtime string `json:"dld_endtime"`
  5578. FileQuryNo string `json:"file_qury_no"`
  5579. Filename string `json:"filename"`
  5580. } `json:"output"`
  5581. RefmsgTime string `json:"refmsg_time"`
  5582. RespondTime string `json:"respond_time"`
  5583. Signtype interface{} `json:"signtype"`
  5584. WarnMsg interface{} `json:"warn_msg"`
  5585. }
  5586. type ResultEleven struct {
  5587. Cainfo string `json:"cainfo"`
  5588. ErrMsg string `json:"err_msg"`
  5589. InfRefmsgid string `json:"inf_refmsgid"`
  5590. Infcode int64 `json:"infcode"`
  5591. Output struct {
  5592. Setlinfo struct {
  5593. FixmedinsName string `json:"fixmedins_name"`
  5594. FixmedinsCode string `json:"fixmedins_code"`
  5595. PsnNo string `json:"psn_no"`
  5596. PsnName string `json:"psn_name"`
  5597. HifobPay float64 `json:"hifob_pay"`
  5598. Gend string `json:"gend"`
  5599. Brdy string `json:"brdy"`
  5600. PsnCertType string `json:"psn_cert_type"`
  5601. PsnType string `json:"psn_type"`
  5602. EmpName string `json:"emp_name"`
  5603. Certno string `json:"certno"`
  5604. Insutype string `json:"insutype"`
  5605. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5606. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5607. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5608. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5609. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5610. ActPayDedc float64 `json:"act_pay_dedc"`
  5611. HifpPay float64 `json:"hifp_pay"`
  5612. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5613. CvlservPay float64 `json:"cvlserv_pay"`
  5614. HifesPay float64 `json:"hifes_pay"`
  5615. HifmiPay float64 `json:"hifmi_pay"`
  5616. MafPay float64 `json:"maf_pay"`
  5617. OthPay float64 `json:"oth_pay"`
  5618. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5619. PsnPay float64 `json:"psn_pay"`
  5620. AcctPay float64 `json:"acct_pay"`
  5621. CashPayamt float64 `json:"cash_payamt"`
  5622. Balc float64 `json:"balc"`
  5623. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5624. MedinsSetlId string `json:"medins_setl_id"`
  5625. RefdSetlFlag string `json:"refd_setl_flag"`
  5626. SetlTime string `json:"setl_time"`
  5627. MedType string `json:"med_type"`
  5628. } `json:"setlinfo"`
  5629. } `json:"output"`
  5630. RefmsgTime string `json:"refmsg_time"`
  5631. RespondTime string `json:"respond_time"`
  5632. Signtype interface{} `json:"signtype"`
  5633. WarnMsg interface{} `json:"warn_msg"`
  5634. }
  5635. type Custom struct {
  5636. DetItemFeeSumamt string
  5637. Cut string
  5638. FeedetlSn string
  5639. Price string
  5640. MedListCodg string
  5641. Type int64
  5642. AdviceId int64
  5643. ProjectId int64
  5644. ItemId int64
  5645. }
  5646. // 获取个人信息----挂号-----上传就诊信息
  5647. func (c *HisApiController) GetRegisterInfo() {
  5648. id, _ := c.GetInt64("id")
  5649. record_time := c.GetString("record_time")
  5650. settlementValue, _ := c.GetInt64("settlement_value")
  5651. medical_insurance_card := c.GetString("medical_insurance_card")
  5652. name := c.GetString("name")
  5653. id_card_type, _ := c.GetInt64("id_card_type")
  5654. certificates, _ := c.GetInt64("certificates")
  5655. medical_care, _ := c.GetInt64("medical_care")
  5656. birthday := c.GetString("birthday")
  5657. age, _ := c.GetInt64("age")
  5658. id_card := c.GetString("id_card")
  5659. register_type, _ := c.GetInt64("register")
  5660. doctor, _ := c.GetInt64("doctor")
  5661. department, _ := c.GetInt64("department")
  5662. gender, _ := c.GetInt64("sex")
  5663. phone := c.GetString("phone")
  5664. registration_fee, _ := c.GetFloat("registration_fee")
  5665. medical_expenses, _ := c.GetFloat("medical_expenses")
  5666. social_type, _ := c.GetInt64("social_type")
  5667. //diagnosis_id, _ := c.GetInt64("diagnosis")
  5668. diagnosis_ids := c.GetString("diagnosis")
  5669. sick_type, _ := c.GetInt64("sick_type")
  5670. reg_type := c.GetString("p_type")
  5671. timeLayout := "2006-01-02"
  5672. loc, _ := time.LoadLocation("Local")
  5673. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  5674. birthUnix := birthdays.Unix()
  5675. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5676. if err != nil {
  5677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5678. return
  5679. }
  5680. recordDateTime := theTime.Unix()
  5681. adminInfo := c.GetAdminUserInfo()
  5682. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  5683. if tempPatient.ID == 0 {
  5684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  5685. return
  5686. }
  5687. var patient service.Patients
  5688. if id == 0 {
  5689. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  5690. } else {
  5691. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  5692. }
  5693. if patient.ID == 0 {
  5694. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  5695. return
  5696. }
  5697. if len(patient.IdCardNo) == 0 {
  5698. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  5699. return
  5700. }
  5701. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5702. if len(his) >= 1 {
  5703. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  5704. if len(his) >= 1 && order.ID == 0 {
  5705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  5706. return
  5707. }
  5708. }
  5709. timeStr := time.Now().Format("2006-01-02 15:04:05")
  5710. fmt.Println(timeStr)
  5711. timeArr := strings.Split(timeStr, " ")
  5712. fmt.Println(timeArr)
  5713. timeArrTwo := strings.Split(timeArr[0], "-")
  5714. timeArrThree := strings.Split(timeArr[1], ":")
  5715. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  5716. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5717. if len(lists) == 0 {
  5718. var hisPatient models.XtHisPatient
  5719. hisPatient = models.XtHisPatient{
  5720. Name: name,
  5721. Age: age,
  5722. Gender: gender,
  5723. Birthday: birthUnix,
  5724. Phone: phone,
  5725. MedicalTreatmentType: medical_care,
  5726. IdType: certificates,
  5727. IdCardNo: id_card,
  5728. BalanceAccountsType: settlementValue,
  5729. SocialType: social_type,
  5730. MedicalInsuranceNumber: medical_insurance_card,
  5731. RegisterType: register_type,
  5732. RegisterCost: registration_fee,
  5733. TreatmentCost: medical_expenses,
  5734. AdminUserId: adminInfo.AdminUser.Id,
  5735. UserOrgId: adminInfo.CurrentOrgId,
  5736. Status: 1,
  5737. RecordDate: recordDateTime,
  5738. IsReturn: 1,
  5739. PatientId: patient.ID,
  5740. Ctime: time.Now().Unix(),
  5741. Mtime: time.Now().Unix(),
  5742. Number: str,
  5743. IdCardType: id_card_type,
  5744. Departments: department,
  5745. Doctor: doctor,
  5746. PType: reg_type,
  5747. Diagnosis: diagnosis_ids,
  5748. SickType: sick_type,
  5749. }
  5750. service.CreateHisPatient(&hisPatient)
  5751. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  5752. c.ServeSuccessJSON(map[string]interface{}{
  5753. "his_info": hisPatient,
  5754. })
  5755. } else {
  5756. //chrgBchno := rand.Intn(1000000) + 10000
  5757. var hisPatient models.XtHisPatient
  5758. hisPatient = models.XtHisPatient{
  5759. Name: name,
  5760. Age: age,
  5761. Gender: gender,
  5762. Birthday: birthUnix,
  5763. Phone: phone,
  5764. MedicalTreatmentType: medical_care,
  5765. IdType: certificates,
  5766. IdCardNo: id_card,
  5767. BalanceAccountsType: settlementValue,
  5768. SocialType: social_type,
  5769. MedicalInsuranceNumber: medical_insurance_card,
  5770. RegisterType: register_type,
  5771. RegisterCost: registration_fee,
  5772. TreatmentCost: medical_expenses,
  5773. AdminUserId: adminInfo.AdminUser.Id,
  5774. UserOrgId: adminInfo.CurrentOrgId,
  5775. Status: 1,
  5776. RecordDate: recordDateTime,
  5777. IsReturn: 1,
  5778. PatientId: patient.ID,
  5779. Ctime: time.Now().Unix(),
  5780. Mtime: time.Now().Unix(),
  5781. Number: str,
  5782. IdCardType: id_card_type,
  5783. Departments: department,
  5784. Doctor: doctor,
  5785. PType: reg_type,
  5786. Diagnosis: diagnosis_ids,
  5787. SickType: sick_type,
  5788. }
  5789. service.CreateHisPatient(&hisPatient)
  5790. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  5791. c.ServeSuccessJSON(map[string]interface{}{
  5792. "his_info": hisPatient,
  5793. })
  5794. }
  5795. }
  5796. // 上传明细----结算
  5797. func (c *HisApiController) GetUploadInfo() {
  5798. id, _ := c.GetInt64("id")
  5799. record_time := c.GetString("record_time")
  5800. his_patient_id, _ := c.GetInt64("his_patient_id")
  5801. oth_desc := c.GetString("oth_desc")
  5802. pay_way, _ := c.GetInt64("pay_way")
  5803. pay_ways := c.GetString("pay_ways")
  5804. pay_price, _ := c.GetFloat("pay_price")
  5805. pay_card_no := c.GetString("pay_card_no")
  5806. discount_price, _ := c.GetFloat("discount_price")
  5807. preferential_price, _ := c.GetFloat("preferential_price")
  5808. reality_price, _ := c.GetFloat("reality_price")
  5809. found_price, _ := c.GetFloat("found_price")
  5810. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  5811. private_price, _ := c.GetFloat("private_price")
  5812. timeLayout := "2006-01-02"
  5813. loc, _ := time.LoadLocation("Local")
  5814. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  5815. fapiao_code := c.GetString("fapiao_code")
  5816. fapiao_number := c.GetString("fapiao_number")
  5817. diagnosis_id := c.GetString("diagnosis")
  5818. sick_type, _ := c.GetInt64("sick_type")
  5819. reg_type, _ := c.GetInt64("p_type")
  5820. order_id, _ := c.GetInt64("order_id")
  5821. cash_pay := c.GetString("cash_pay")
  5822. wechat_pay := c.GetString("wechat_pay")
  5823. ali_pay := c.GetString("ali_pay")
  5824. jifen_pay := c.GetString("jifen_pay")
  5825. band_card_pay := c.GetString("band_card_pay")
  5826. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  5827. tmp_decimal := c.GetString("tmp_decimal")
  5828. var decimal float64 //本次使用的押金
  5829. var errmsg error
  5830. tx := service.XTWriteDB().Begin() //开了事务
  5831. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  5832. defer func() {
  5833. if errmsg != nil {
  5834. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  5835. tx.Rollback()
  5836. } else {
  5837. tx.Commit()
  5838. }
  5839. }()
  5840. fmt.Println("dec_way", dec_way)
  5841. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  5842. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  5843. return
  5844. }
  5845. if len(tmp_decimal) > 0 {
  5846. if tmp_decimal[0] == 45 {
  5847. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  5848. return
  5849. }
  5850. }
  5851. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  5852. fmt.Println(errs)
  5853. decimal = tt
  5854. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  5855. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  5856. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5857. if err != nil {
  5858. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5859. return
  5860. }
  5861. recordDateTime := theTime.Unix()
  5862. adminUser := c.GetAdminUserInfo()
  5863. var prescriptions []*models.HisPrescription
  5864. var prescriptionsOne []*models.HisPrescription
  5865. var start_time int64
  5866. var end_time int64
  5867. ids_str := c.GetString("ids")
  5868. ids_arr := strings.Split(ids_str, ",")
  5869. if tempOrder.ID == 0 {
  5870. if settle_accounts_type == 1 { //日结
  5871. fmt.Println(reg_type)
  5872. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  5873. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  5874. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  5875. } else {
  5876. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5877. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5878. }
  5879. } else { //月结
  5880. start_time_str := c.GetString("start_time")
  5881. end_time_str := c.GetString("end_time")
  5882. timeLayout := "2006-01-02"
  5883. loc, _ := time.LoadLocation("Local")
  5884. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  5885. if err != nil {
  5886. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5887. return
  5888. }
  5889. recordStartTime := theStartTime.Unix()
  5890. start_time = recordStartTime
  5891. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  5892. if err != nil {
  5893. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5894. return
  5895. }
  5896. recordEndTime := theEndTime.Unix()
  5897. end_time = recordEndTime
  5898. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  5899. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5900. }
  5901. var goods []*models.DialysisBeforePrepareGoods
  5902. var newGoods []*models.NewDialysisBeforePrepareGoods
  5903. var oldGoods []*models.OldDialysisBeforePrepareGoods
  5904. var infos []*models.HisDoctorAdviceInfo
  5905. var infoList []*models.HisDoctorAdviceInfo
  5906. var hisAdvice []*models.HisDoctorAdviceInfo
  5907. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  5908. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  5909. //判断库存不足
  5910. //结算出库开关
  5911. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  5912. if settConfig.IsOpen == 1 {
  5913. //判断库存的地方
  5914. for _, info := range prescriptions {
  5915. if info.Type == 1 {
  5916. infos = append(infos, info.HisDoctorAdviceInfo...)
  5917. }
  5918. if info.Type == 2 {
  5919. for _, sumItem := range info.HisPrescriptionProject {
  5920. if sumItem.Type == 3 {
  5921. var good models.DialysisBeforePrepareGoods
  5922. var newGood models.NewDialysisBeforePrepareGoods
  5923. good.GoodId = sumItem.GoodInfo.ID
  5924. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5925. count, _ := strconv.Atoi(sumItem.Count)
  5926. good.Count = int64(count)
  5927. good.StorehouseId = houseConfig.StorehouseOutInfo
  5928. good.ProjectId = sumItem.ID
  5929. goods = append(goods, &good)
  5930. newGood.GoodId = sumItem.GoodInfo.ID
  5931. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5932. count2, _ := strconv.Atoi(sumItem.Count)
  5933. newGood.Count = int64(count2)
  5934. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5935. newGood.ProjectId = sumItem.ID
  5936. newGoods = append(newGoods, &newGood)
  5937. }
  5938. }
  5939. }
  5940. }
  5941. for _, info := range prescriptionsOne {
  5942. if info.Type == 1 {
  5943. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  5944. }
  5945. if info.Type == 2 {
  5946. for _, sumItem := range info.HisPrescriptionProject {
  5947. if sumItem.Type == 3 {
  5948. var newGood models.NewDialysisBeforePrepareGoods
  5949. newGood.GoodId = sumItem.GoodInfo.ID
  5950. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5951. count2, _ := strconv.Atoi(sumItem.Count)
  5952. newGood.Count = int64(count2)
  5953. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5954. newGood.ProjectId = sumItem.ID
  5955. newGoodOne = append(newGoodOne, &newGood)
  5956. }
  5957. }
  5958. }
  5959. }
  5960. //判断
  5961. for _, itemOne := range infos {
  5962. for _, itemTwo := range hisAdvice {
  5963. if itemOne.DrugId == itemTwo.DrugId {
  5964. itemTwo.Child = append(itemTwo.Child, itemOne)
  5965. }
  5966. }
  5967. }
  5968. for _, itemTwo := range hisAdvice {
  5969. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  5970. var sum_out_count int64
  5971. for _, itemThree := range itemTwo.Child {
  5972. var prescribing_number int64
  5973. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  5974. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5975. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5976. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5977. }
  5978. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5979. prescribing_number = parseIntPrescribingNumber
  5980. }
  5981. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5982. prescribing_number = parseIntPrescribingNumber
  5983. }
  5984. sum_out_count += prescribing_number
  5985. }
  5986. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  5987. fmt.Println("sum_out_count233232323232wo", sum_out_count)
  5988. fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
  5989. if sum_out_count > drugStockOut.FlushCount {
  5990. c.ServeSuccessJSON(map[string]interface{}{
  5991. "msg": "2",
  5992. "drug": medical,
  5993. })
  5994. return
  5995. }
  5996. }
  5997. fmt.Println("newGoods99999988882os", newGoods)
  5998. for _, itemOne := range newGoods {
  5999. for _, item := range newGoodOne {
  6000. if itemOne.GoodId == item.GoodId {
  6001. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  6002. }
  6003. }
  6004. }
  6005. for _, item := range newGoodOne {
  6006. var sum_out_count_one int64
  6007. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  6008. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  6009. sum_out_count_one += itemOne.Count
  6010. }
  6011. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6012. fmt.Println("sum_out_count_one", sum_out_count_one)
  6013. fmt.Println("list.FlushCount", list.FlushCount)
  6014. if sum_out_count_one > list.FlushCount {
  6015. c.ServeSuccessJSON(map[string]interface{}{
  6016. "msg": "3",
  6017. "good": good,
  6018. })
  6019. return
  6020. }
  6021. }
  6022. }
  6023. timestamp := time.Now().Unix()
  6024. tempTime := time.Unix(timestamp, 0)
  6025. timeFormat := tempTime.Format("20060102150405")
  6026. chrgBchno := rand.Intn(100000) + 10000
  6027. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6028. strconv.FormatInt(his.PatientId, 10)
  6029. var ids []int64
  6030. for _, item := range prescriptions {
  6031. ids = append(ids, item.ID)
  6032. }
  6033. var total float64
  6034. for _, item := range prescriptions {
  6035. fmt.Println(item)
  6036. if item.Type == 1 { //药品
  6037. for _, subItem := range item.HisDoctorAdviceInfo {
  6038. total = total + (subItem.Price * subItem.PrescribingNumber)
  6039. }
  6040. }
  6041. if item.Type == 2 { //项目
  6042. for _, subItem := range item.HisPrescriptionProject {
  6043. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6044. total = total + (subItem.Price * cnt)
  6045. }
  6046. }
  6047. for _, subItem := range item.HisAdditionalCharge {
  6048. total = total + (subItem.Price * float64(subItem.Count))
  6049. }
  6050. }
  6051. if reg_type == 1111 || reg_type == 1112 {
  6052. reg_type = 11
  6053. }
  6054. tm := time.Unix(time.Now().Unix(), 0)
  6055. allTotal := fmt.Sprintf("%.4f", total)
  6056. totals, _ := strconv.ParseFloat(allTotal, 64)
  6057. order := &models.HisOrder{
  6058. UserOrgId: adminUser.CurrentOrgId,
  6059. HisPatientId: his.ID,
  6060. PatientId: id,
  6061. SettleAccountsDate: recordDateTime,
  6062. Ctime: time.Now().Unix(),
  6063. Mtime: time.Now().Unix(),
  6064. Status: 1,
  6065. OrderStatus: 2,
  6066. MdtrtId: his.Number,
  6067. Number: chrg_bchno,
  6068. MedfeeSumamt: totals,
  6069. PayWay: pay_way,
  6070. PayWays: pay_ways,
  6071. PayPrice: pay_price,
  6072. MedType: strconv.Itoa(int(reg_type)),
  6073. PayCardNo: pay_card_no,
  6074. DiscountPrice: discount_price,
  6075. PreferentialPrice: preferential_price,
  6076. RealityPrice: reality_price,
  6077. FoundPrice: found_price,
  6078. MedicalInsurancePrice: medical_insurance_price,
  6079. PrivatePrice: private_price,
  6080. SettleEndTime: end_time,
  6081. SettleStartTime: start_time,
  6082. PsnPartAmt: totals,
  6083. PsnCashPay: totals,
  6084. SettleType: settle_accounts_type,
  6085. FaPiaoCode: fapiao_code,
  6086. FaPiaoNumber: fapiao_number,
  6087. Diagnosis: diagnosis_id,
  6088. PType: 2,
  6089. SetlTime: tm.Format("2006-01-02 15:04:05"),
  6090. Decimal: decimal,
  6091. OthDesc: oth_desc,
  6092. CashPay: cash_pay,
  6093. WechatPay: wechat_pay,
  6094. AliPay: ali_pay,
  6095. JifenPay: jifen_pay,
  6096. BandCardPay: band_card_pay,
  6097. }
  6098. err = service.CreateOrderTX(order, tx)
  6099. if err != nil {
  6100. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6101. return
  6102. }
  6103. var customs []*Custom
  6104. for _, item := range prescriptions {
  6105. if item.Type == 1 { //药品a
  6106. for _, subItem := range item.HisDoctorAdviceInfo {
  6107. cus := &Custom{
  6108. AdviceId: subItem.ID,
  6109. ProjectId: 0,
  6110. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  6111. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  6112. FeedetlSn: subItem.FeedetlSn,
  6113. Price: fmt.Sprintf("%.4f", subItem.Price),
  6114. MedListCodg: subItem.MedListCodg,
  6115. Type: 1,
  6116. }
  6117. customs = append(customs, cus)
  6118. }
  6119. }
  6120. if item.Type == 2 { //项目
  6121. for _, subItem := range item.HisPrescriptionProject {
  6122. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6123. cus := &Custom{
  6124. AdviceId: 0,
  6125. ProjectId: subItem.ID,
  6126. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  6127. Cut: fmt.Sprintf("%.4f", cnt),
  6128. FeedetlSn: subItem.FeedetlSn,
  6129. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  6130. MedListCodg: subItem.MedListCodg,
  6131. Type: 2,
  6132. }
  6133. customs = append(customs, cus)
  6134. }
  6135. }
  6136. for _, item := range item.HisAdditionalCharge {
  6137. cus := &Custom{
  6138. ItemId: item.ID,
  6139. AdviceId: 0,
  6140. ProjectId: 0,
  6141. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  6142. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  6143. FeedetlSn: item.FeedetlSn,
  6144. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  6145. MedListCodg: item.XtHisAddtionConfig.Code,
  6146. Type: 3,
  6147. }
  6148. customs = append(customs, cus)
  6149. }
  6150. }
  6151. for _, item := range customs {
  6152. var advice_id int64 = 0
  6153. var project_id int64 = 0
  6154. var item_id int64 = 0
  6155. var types int64 = 0
  6156. if item.Type == 1 {
  6157. advice_id = item.AdviceId
  6158. project_id = 0
  6159. item_id = 0
  6160. } else if item.Type == 2 {
  6161. advice_id = 0
  6162. item_id = 0
  6163. project_id = item.ProjectId
  6164. } else if item.Type == 3 {
  6165. advice_id = 0
  6166. item_id = item.ItemId
  6167. project_id = 0
  6168. }
  6169. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  6170. cut, _ := strconv.ParseFloat(item.Cut, 32)
  6171. pric, _ := strconv.ParseFloat(item.Price, 32)
  6172. info := &models.HisOrderInfo{
  6173. OrderNumber: order.Number,
  6174. UploadDate: time.Now().Unix(),
  6175. AdviceId: advice_id,
  6176. DetItemFeeSumamt: detItemFeeSumamt,
  6177. Cnt: cut,
  6178. Pric: pric,
  6179. PatientId: id,
  6180. Status: 1,
  6181. Mtime: time.Now().Unix(),
  6182. Ctime: time.Now().Unix(),
  6183. UserOrgId: adminUser.CurrentOrgId,
  6184. HisPatientId: his.ID,
  6185. OrderId: order.ID,
  6186. ProjectId: project_id,
  6187. Type: types,
  6188. ItemId: item_id,
  6189. }
  6190. service.CreateOrderInfoTX(info, tx)
  6191. }
  6192. his.Diagnosis = diagnosis_id
  6193. his.SickType = sick_type
  6194. his.RegisterType = reg_type
  6195. his.MedicalTreatmentType = reg_type
  6196. service.UpdataHisPateintTX(&his, tx)
  6197. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  6198. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  6199. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  6200. //判断是否使用了押金
  6201. if dec_way == "true" {
  6202. tmpstring := strconv.FormatInt(order.ID, 10)
  6203. //扣押金
  6204. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  6205. order.Decimal = decimal
  6206. service.UpDateOrderTwo(order, tx)
  6207. if errmsg != nil {
  6208. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  6209. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6210. return
  6211. }
  6212. }
  6213. if err == nil {
  6214. for _, info := range prescriptions {
  6215. if info.Type == 1 {
  6216. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  6217. }
  6218. if info.Type == 2 {
  6219. for _, sumItem := range info.HisPrescriptionProject {
  6220. if sumItem.Type == 3 {
  6221. var good models.DialysisBeforePrepareGoods
  6222. var newGood models.NewDialysisBeforePrepareGoods
  6223. var oldGood models.OldDialysisBeforePrepareGoods
  6224. good.GoodId = sumItem.GoodInfo.ID
  6225. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6226. count, _ := strconv.Atoi(sumItem.Count)
  6227. good.Count = int64(count)
  6228. good.StorehouseId = houseConfig.StorehouseOutInfo
  6229. good.ProjectId = sumItem.ID
  6230. good.PatientId = sumItem.PatientId
  6231. goods = append(goods, &good)
  6232. newGood.GoodId = sumItem.GoodInfo.ID
  6233. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6234. count2, _ := strconv.Atoi(sumItem.Count)
  6235. newGood.Count = int64(count2)
  6236. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6237. newGood.ProjectId = sumItem.ID
  6238. newGood.PatientId = sumItem.HisPatientId
  6239. newGoods = append(newGoods, &newGood)
  6240. oldGood.GoodId = sumItem.GoodInfo.ID
  6241. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6242. count3, _ := strconv.Atoi(sumItem.Count)
  6243. oldGood.Count = int64(count3)
  6244. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  6245. oldGood.ProjectId = sumItem.ID
  6246. oldGood.RecordDate = sumItem.RecordDate
  6247. oldGood.PatientId = sumItem.HisPatientId
  6248. oldGoods = append(oldGoods, &oldGood)
  6249. }
  6250. }
  6251. }
  6252. }
  6253. if settConfig.IsOpen == 1 {
  6254. for _, item := range infoList {
  6255. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6256. if medical.IsUse == 2 {
  6257. //药品出库
  6258. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  6259. //查询默认仓库
  6260. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  6261. //查询默认仓库剩余多少库存
  6262. var sum_count int64
  6263. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6264. for _, its := range stockInfo {
  6265. if its.MaxUnit == medical.MaxUnit {
  6266. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6267. }
  6268. sum_count += its.StockMaxNumber + its.StockMinNumber
  6269. }
  6270. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6271. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6272. }
  6273. }
  6274. orgId := c.GetAdminUserInfo().CurrentOrgId
  6275. if len(oldGoods) > 0 {
  6276. timeStr := time.Now().Format("2006-01-02")
  6277. timeArr := strings.Split(timeStr, "-")
  6278. total, _ := service.FindAllWarehouseOut(orgId)
  6279. total = total + 1
  6280. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6281. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6282. number = number + total
  6283. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6284. operation_time := time.Now().Unix()
  6285. creater := c.GetAdminUserInfo().AdminUser.Id
  6286. //查询默认出库仓库库存
  6287. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6288. recordDateStr := time.Now().Format("2006-01-02")
  6289. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6290. nowtime := recordDate.Unix()
  6291. warehouseOut := models.WarehouseOut{
  6292. WarehouseOutOrderNumber: warehousing_out_order,
  6293. OperationTime: operation_time,
  6294. OrgId: orgId,
  6295. Creater: creater,
  6296. Ctime: time.Now().Unix(),
  6297. Status: 1,
  6298. WarehouseOutTime: nowtime,
  6299. Type: 1,
  6300. StorehouseId: storeConfig.StorehouseOutInfo,
  6301. IsCheck: 1,
  6302. OrderId: order.ID,
  6303. IsSys: 5,
  6304. }
  6305. //查询是否生成出库单
  6306. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6307. if out.ID == 0 {
  6308. service.AddSigleWarehouseOut(&warehouseOut)
  6309. }
  6310. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6311. for _, item := range oldGoods {
  6312. dialyPrepareOne := models.DialysisBeforePrepare{
  6313. GoodTypeId: item.GoodTypeId,
  6314. GoodId: item.GoodId,
  6315. PatientId: his.PatientId,
  6316. RecordDate: item.RecordDate,
  6317. UserOrgId: adminUser.CurrentOrgId,
  6318. Count: item.Count,
  6319. Ctime: time.Now().Unix(),
  6320. Creater: adminUser.AdminUser.Id,
  6321. CommdityCode: item.CommdityCode,
  6322. Status: 1,
  6323. StorehouseId: houseConfig.StorehouseOutInfo,
  6324. }
  6325. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  6326. //非零用
  6327. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  6328. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6329. //查询剩余库存
  6330. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6331. var sum_count int64
  6332. for _, item := range goodList {
  6333. sum_count += item.StockCount
  6334. }
  6335. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6336. //耗材
  6337. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6338. }
  6339. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  6340. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6341. //查询剩余库存
  6342. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6343. var sum_count int64
  6344. for _, item := range goodList {
  6345. sum_count += item.StockCount
  6346. }
  6347. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6348. //耗材
  6349. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6350. }
  6351. }
  6352. }
  6353. }
  6354. c.ServeSuccessJSON(map[string]interface{}{
  6355. "msg": "结算成功",
  6356. })
  6357. }
  6358. }
  6359. }
  6360. // 退款
  6361. func (c *HisApiController) Refund() {
  6362. order_id, _ := c.GetInt64("order_id")
  6363. order, _ := service.GetHisOrderByID(order_id)
  6364. adminUser := c.GetAdminUserInfo()
  6365. orgid := c.GetAdminUserInfo().CurrentOrgId
  6366. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  6367. if err != nil {
  6368. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6369. return
  6370. }
  6371. tmp := strconv.FormatInt(order.ID, 10)
  6372. //当押金不为零时产生退费记录
  6373. if order.Decimal != 0 {
  6374. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  6375. if err != nil {
  6376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6377. return
  6378. }
  6379. }
  6380. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  6381. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  6382. var goods []*models.DialysisBeforePrepareGoods
  6383. var newGoods []*models.NewDialysisBeforePrepareGoods
  6384. var infos []*models.HisDoctorAdviceInfo
  6385. for _, info := range orders {
  6386. if info.AdviceId > 0 && info.ProjectId == 0 {
  6387. infos = append(infos, &info.HisDoctorAdviceInfo)
  6388. }
  6389. if info.ProjectId > 0 && info.AdviceId == 0 {
  6390. if info.HisPrescriptionProject.Type == 3 {
  6391. var good models.DialysisBeforePrepareGoods
  6392. var newGood models.NewDialysisBeforePrepareGoods
  6393. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6394. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6395. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6396. good.Count = int64(count)
  6397. good.StorehouseId = houseConfig.StorehouseOutInfo
  6398. good.ProjectId = info.HisPrescriptionProject.ID
  6399. good.PatientId = info.PatientId
  6400. good.OrderId = order_id
  6401. goods = append(goods, &good)
  6402. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6403. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6404. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6405. newGood.Count = int64(count2)
  6406. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6407. newGood.ProjectId = info.HisPrescriptionProject.ID
  6408. newGood.RecordDate = order.SettleAccountsDate
  6409. newGood.UserOrgId = order.UserOrgId
  6410. newGood.PatientId = info.PatientId
  6411. newGood.OrderId = order_id
  6412. newGoods = append(newGoods, &newGood)
  6413. }
  6414. }
  6415. }
  6416. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6417. if settConfig.IsOpen == 1 {
  6418. for _, item := range infos {
  6419. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6420. }
  6421. for _, item := range newGoods {
  6422. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6423. }
  6424. }
  6425. c.ServeSuccessJSON(map[string]interface{}{
  6426. "msg": "退费成功",
  6427. })
  6428. }
  6429. func (c *HisApiController) RefundNumber() {
  6430. his_patient_id, _ := c.GetInt64("id")
  6431. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6432. info.Status = 0
  6433. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  6434. if count > 0 {
  6435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  6436. return
  6437. }
  6438. err := service.SaveHisPatient(info)
  6439. if err == nil {
  6440. c.ServeSuccessJSON(map[string]interface{}{
  6441. "msg": "退号成功",
  6442. })
  6443. } else {
  6444. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6445. return
  6446. }
  6447. }
  6448. func (this *HisApiController) AdditionalCharge() {
  6449. dataBody := make(map[string]interface{}, 0)
  6450. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6451. fmt.Println(err)
  6452. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  6453. patient_id := int64(dataBody["patient_id"].(float64))
  6454. medicineData, _ := dataBody["medicineData"].([]interface{})
  6455. adminUserInfo := this.GetAdminUserInfo()
  6456. orgId := adminUserInfo.CurrentOrgId
  6457. admin_user_id := adminUserInfo.AdminUser.Id
  6458. timeStr := time.Now().Format("2006-01-02")
  6459. timeLayout := "2006-01-02 15:04:05"
  6460. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  6461. timenow := timeStringToTime.Unix()
  6462. var additionalCharges []*models.HisAdditionalCharge
  6463. for _, item := range medicineData {
  6464. var randNum int
  6465. randNum = rand.Intn(10000) + 1000
  6466. timestamp := time.Now().Unix()
  6467. tempTime := time.Unix(timestamp, 0)
  6468. timeFormat := tempTime.Format("20060102150405")
  6469. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  6470. items := item.(map[string]interface{})
  6471. money := items["price"].(string)
  6472. item_id_str := items["item_id"].(string)
  6473. name := items["name"].(string)
  6474. id_str := items["id"].(string)
  6475. moneys, _ := strconv.ParseInt(money, 10, 64)
  6476. monStr := strconv.FormatInt(moneys, 10)
  6477. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  6478. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  6479. id, _ := strconv.ParseInt(id_str, 10, 64)
  6480. additionalCharge := &models.HisAdditionalCharge{
  6481. ID: id,
  6482. HisPatientId: his_patient_id,
  6483. UserOrgId: orgId,
  6484. PatientId: patient_id,
  6485. RecordDate: timenow,
  6486. Price: monneyStr,
  6487. Status: 1,
  6488. ItemName: name,
  6489. ItemId: item_id,
  6490. AdminUserId: admin_user_id,
  6491. CreatedTime: time.Now().Unix(),
  6492. OrderStatus: 0,
  6493. PrescriptionNumber: "",
  6494. BatchNumber: "",
  6495. FeedetlSn: p_number,
  6496. }
  6497. service.CreateAdditionalCharge(additionalCharge)
  6498. additionalCharges = append(additionalCharges, additionalCharge)
  6499. }
  6500. this.ServeSuccessJSON(map[string]interface{}{
  6501. "msg": "添加成功",
  6502. "additional_charges": additionalCharges,
  6503. })
  6504. }
  6505. func (this *HisApiController) DeleteAddition() {
  6506. id, _ := this.GetInt64("id")
  6507. //TODO 需要判断是否已经结算
  6508. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  6509. if err == nil {
  6510. this.ServeSuccessJSON(map[string]interface{}{
  6511. "msg": "删除成功",
  6512. })
  6513. return
  6514. } else {
  6515. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6516. return
  6517. }
  6518. }
  6519. func (this *HisApiController) GetAdminUsers() {
  6520. adminUser := this.GetAdminUserInfo()
  6521. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  6522. this.ServeSuccessJSON(map[string]interface{}{
  6523. "doctors": doctors,
  6524. })
  6525. }
  6526. func (this *HisApiController) GetLastOrNextHisPrescription() {
  6527. change_type, _ := this.GetInt64("type", 0)
  6528. record_date := this.GetString("record_time")
  6529. patient_id, _ := this.GetInt64("patient_id", 0)
  6530. p_type, _ := this.GetInt64("p_type", 0)
  6531. timeLayout := "2006-01-02"
  6532. loc, _ := time.LoadLocation("Local")
  6533. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6534. record_time := theAdviceRecordTime.Unix()
  6535. adminUserInfo := this.GetAdminUserInfo()
  6536. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  6537. if err == nil {
  6538. if len(prescriptions) == 0 {
  6539. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  6540. return
  6541. } else {
  6542. this.ServeSuccessJSON(map[string]interface{}{
  6543. "prescriptions": prescriptions,
  6544. })
  6545. return
  6546. }
  6547. } else {
  6548. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6549. return
  6550. }
  6551. }
  6552. func (this *HisApiController) GetCallHisPrescription() {
  6553. patient_id, _ := this.GetInt64("patient_id", 0)
  6554. timeLayout := "2006-01-02"
  6555. loc, _ := time.LoadLocation("Local")
  6556. start_time := this.GetString("start_time")
  6557. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6558. end_time := this.GetString("end_time")
  6559. p_type, _ := this.GetInt64("p_type")
  6560. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6561. adminUserInfo := this.GetAdminUserInfo()
  6562. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  6563. if err == nil {
  6564. this.ServeSuccessJSON(map[string]interface{}{
  6565. "prescriptions": prescriptions,
  6566. })
  6567. return
  6568. } else {
  6569. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6570. return
  6571. }
  6572. }
  6573. func (this *HisApiController) GetHisDayPrescription() {
  6574. timeLayout := "2006-01-02"
  6575. loc, _ := time.LoadLocation("Local")
  6576. start_time := this.GetString("start_time")
  6577. patient_id, _ := this.GetInt64("patient_id", 0)
  6578. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6579. end_time := this.GetString("end_time")
  6580. p_type, _ := this.GetInt64("p_type")
  6581. order_status, _ := this.GetInt64("type")
  6582. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6583. adminUserInfo := this.GetAdminUserInfo()
  6584. var dayHisPrescription []*models.HisPrescription
  6585. var err error
  6586. if order_status == 1 || order_status == 0 {
  6587. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6588. } else if order_status == 2 {
  6589. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6590. }
  6591. var settle_total float64
  6592. for _, item := range dayHisPrescription {
  6593. if len(item.HisPrescriptionProject) > 0 {
  6594. for _, subItem := range item.HisPrescriptionProject {
  6595. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6596. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6597. settle_total = settle_total + total
  6598. }
  6599. }
  6600. if len(item.HisDoctorAdviceInfo) > 0 {
  6601. for _, subItem := range item.HisDoctorAdviceInfo {
  6602. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6603. settle_total = settle_total + total
  6604. }
  6605. }
  6606. }
  6607. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6608. if err == nil {
  6609. this.ServeSuccessJSON(map[string]interface{}{
  6610. "day_prescription": dayHisPrescription,
  6611. "settle_total": settle_total,
  6612. })
  6613. return
  6614. } else {
  6615. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6616. return
  6617. }
  6618. }
  6619. func (c *HisApiController) GetHisChargePatientList() {
  6620. record_date := c.GetString("record_date")
  6621. order_status, _ := c.GetInt64("type")
  6622. timeLayout := "2006-01-02"
  6623. loc, _ := time.LoadLocation("Local")
  6624. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6625. if err != nil {
  6626. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6627. return
  6628. }
  6629. recordDateTime := theTime.Unix()
  6630. adminInfo := c.GetAdminUserInfo()
  6631. var tempPatients []*service.NewTempPatients
  6632. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6633. if order_status != 2 {
  6634. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6635. } else {
  6636. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6637. }
  6638. var patients []*service.NewTempPatients
  6639. var patients_two []*service.NewTempPatients
  6640. for _, item := range tempPatients {
  6641. //过滤掉没挂号的和没开处方的
  6642. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  6643. patients = append(patients, item)
  6644. }
  6645. //过滤掉没挂号的
  6646. if len(item.HisPatient) > 0 {
  6647. patients_two = append(patients_two, item)
  6648. }
  6649. }
  6650. c.ServeSuccessJSON(map[string]interface{}{
  6651. "list": patients,
  6652. "list_two": patients_two,
  6653. })
  6654. }
  6655. func (c *HisApiController) GetHisUnRegisterPatientList() {
  6656. record_date := c.GetString("record_date")
  6657. timeLayout := "2006-01-02"
  6658. loc, _ := time.LoadLocation("Local")
  6659. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6660. if err != nil {
  6661. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6662. return
  6663. }
  6664. recordDateTime := theTime.Unix()
  6665. adminUser := c.GetAdminUserInfo()
  6666. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  6667. var patients []*service.Patients
  6668. for _, item := range tempPatients {
  6669. if item.HisPatient.ID == 0 {
  6670. patients = append(patients, item)
  6671. }
  6672. }
  6673. c.ServeSuccessJSON(map[string]interface{}{
  6674. "list": patients,
  6675. //"list_two": patients_two,
  6676. })
  6677. }
  6678. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  6679. newArr = make([]*service.Patients, 0)
  6680. for i := 0; i < len(patient); i++ {
  6681. repeat := false
  6682. for j := i + 1; j < len(patient); j++ {
  6683. if patient[i].ID == patient[j].ID {
  6684. repeat = true
  6685. break
  6686. }
  6687. }
  6688. if !repeat {
  6689. newArr = append(newArr, patient[i])
  6690. }
  6691. }
  6692. return
  6693. }
  6694. func (c *HisApiController) GetHisChargePatientInfo() {
  6695. patient_id, _ := c.GetInt64("patient_id")
  6696. his_patient_id, _ := c.GetInt64("his_patient_id")
  6697. record_date := c.GetString("record_date")
  6698. //start_time := c.GetString("start_time")
  6699. //end_time := c.GetString("end_time")
  6700. order_status, _ := c.GetInt64("type", 0)
  6701. p_type, _ := c.GetInt64("p_type", 0)
  6702. order_id, _ := c.GetInt64("order_id", 0)
  6703. timeLayout := "2006-01-02"
  6704. loc, _ := time.LoadLocation("Local")
  6705. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6706. if err != nil {
  6707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6708. return
  6709. }
  6710. recordDateTime := theTime.Unix()
  6711. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6712. //if err != nil {
  6713. //
  6714. //}
  6715. //startRecordDateTime := startTime.Unix()
  6716. //
  6717. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6718. //if err != nil {
  6719. //
  6720. //}
  6721. //endRecordDateTime := endTime.Unix()
  6722. admin := c.GetAdminUserInfo()
  6723. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6724. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6725. var prescriptions []*models.HisPrescription
  6726. //var unChargeMonthPrescriptions []*models.HisPrescription
  6727. order, _ := service.GetHisOrderByID(order_id)
  6728. if order_status == 1 || order_status == 0 {
  6729. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  6730. } else if order_status == 2 {
  6731. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  6732. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6733. }
  6734. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6735. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6736. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6737. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6738. //获取所有科室信息
  6739. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6740. c.ServeSuccessJSON(map[string]interface{}{
  6741. "his_info": his_patient_info,
  6742. "xt_info": xt_patient_info,
  6743. "prescription": prescriptions,
  6744. "case_history": case_history,
  6745. "info": patientPrescriptionInfo,
  6746. "last_info": lastPatientPrescriptionInfo,
  6747. "order": order,
  6748. "doctors": doctors,
  6749. "department": department,
  6750. })
  6751. return
  6752. }
  6753. func (c *HisApiController) GetAllOrderDetail() {
  6754. order_id, _ := c.GetInt64("id", 0)
  6755. order, _ := service.GetHisOrderByID(order_id)
  6756. if order.ID == 0 {
  6757. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6758. return
  6759. }
  6760. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6761. org_id := c.GetAdminUserInfo().CurrentOrgId
  6762. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6763. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  6764. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6765. c.ServeSuccessJSON(map[string]interface{}{
  6766. "order": order,
  6767. "order_info": order_info,
  6768. "patient": patient,
  6769. "admin_info": adminInfo,
  6770. "hospital_record": record,
  6771. })
  6772. return
  6773. }
  6774. func (c *HisApiController) GetAllOrderDetailCollect() {
  6775. order_id, _ := c.GetInt64("id", 0)
  6776. order, _ := service.GetHisOrderByID(order_id)
  6777. if order.ID == 0 {
  6778. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6779. return
  6780. }
  6781. org_id := c.GetAdminUserInfo().CurrentOrgId
  6782. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6783. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6784. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  6785. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  6786. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  6787. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6788. var bedCostTotal float64 = 0 //床位总费
  6789. //var bedCostSelfTotal float64 = 0 //床位自费
  6790. var operationCostTotal float64 = 0 //手术费
  6791. //var operationCostSelfTotal float64 = 0 //手术费
  6792. var otherCostTotal float64 = 0 //其他费用
  6793. //var otherCostSelfTotal float64 = 0 //其他费用
  6794. var materialCostTotal float64 = 0 //材料费
  6795. //var materialCostSelfTotal float64 = 0 //材料费
  6796. var westernMedicineCostTotal float64 = 0 //西药费
  6797. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  6798. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  6799. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  6800. var checkCostTotal float64 = 0 //检查费
  6801. //var checkCostSelfTotal float64 = 0 //检查费
  6802. var laboratoryCostTotal float64 = 0 //化验费
  6803. //var laboratoryCostSelfTotal float64 = 0 //化验费
  6804. var treatCostTotal float64 = 0 //治疗费用
  6805. //var treatCostSelfTotal float64 = 0 //治疗费用
  6806. var zhenChaCostTotal float64 = 0 //其他费用
  6807. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  6808. decimal.DivisionPrecision = 2
  6809. var BalanceAccountsType int64
  6810. if his.ID > 0 {
  6811. BalanceAccountsType = his.BalanceAccountsType
  6812. } else {
  6813. BalanceAccountsType = record.BalanceAccountsType
  6814. }
  6815. if BalanceAccountsType != 2 {
  6816. for _, item := range order_info {
  6817. if org_id == 10215 {
  6818. if item.MedChrgitmType == "01" { //床位费
  6819. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6820. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6821. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6822. }
  6823. if item.MedChrgitmType == "02" { //诊察费
  6824. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6825. //zhenChaCostSelfTotal = zhenChaCostTotal
  6826. }
  6827. if item.MedChrgitmType == "03" { //检查费
  6828. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6829. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6830. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6831. }
  6832. //if item.MedChrgitmType == "02" { //检查费
  6833. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6834. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6835. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6836. //}
  6837. if item.MedChrgitmType == "04" { //化验费
  6838. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6839. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6840. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6841. }
  6842. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6843. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6844. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6845. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6846. }
  6847. if item.MedChrgitmType == "06" { //手术费
  6848. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6849. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6850. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6851. }
  6852. if item.MedChrgitmType == "08" { //材料费
  6853. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6854. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6855. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6856. }
  6857. if item.MedChrgitmType == "09" { //西药费
  6858. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6859. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6860. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6861. }
  6862. if item.MedChrgitmType == "11" { //中成费
  6863. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6864. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6865. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6866. }
  6867. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  6868. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6869. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6870. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6871. }
  6872. } else if org_id == 10188 || org_id == 10217 {
  6873. if item.MedChrgitmType == "01" { //床位费
  6874. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6875. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6876. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6877. }
  6878. if item.MedChrgitmType == "02" { //诊察费
  6879. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6880. //zhenChaCostSelfTotal = zhenChaCostTotal
  6881. }
  6882. if item.MedChrgitmType == "03" { //检查费
  6883. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6884. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6885. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6886. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6887. }
  6888. //if item.MedChrgitmType == "02" { //检查费
  6889. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6890. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6891. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6892. //}
  6893. if item.MedChrgitmType == "04" { //化验费
  6894. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6895. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6896. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6897. }
  6898. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6899. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6900. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6901. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6902. }
  6903. if item.MedChrgitmType == "06" { //手术费
  6904. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6905. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6906. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6907. }
  6908. if item.MedChrgitmType == "08" { //材料费
  6909. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6910. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6911. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6912. }
  6913. if item.MedChrgitmType == "09" { //西药费
  6914. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6915. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6916. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6917. }
  6918. if item.MedChrgitmType == "11" { //中成费
  6919. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6920. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6921. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6922. }
  6923. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  6924. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6925. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6926. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6927. }
  6928. } else {
  6929. if item.MedChrgitmType == "01" { //床位费
  6930. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6931. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6932. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6933. }
  6934. //if item.MedChrgitmType == "02" { //诊察费
  6935. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6936. // //zhenChaCostSelfTotal = zhenChaCostTotal
  6937. //}
  6938. if item.MedChrgitmType == "03" { //检查费
  6939. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6940. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6941. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6942. }
  6943. //if item.MedChrgitmType == "02" { //检查费
  6944. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6945. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6946. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6947. //}
  6948. if item.MedChrgitmType == "04" { //化验费
  6949. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6950. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6951. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6952. }
  6953. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6954. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6955. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6956. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6957. }
  6958. if item.MedChrgitmType == "06" { //手术费
  6959. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6960. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6961. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6962. }
  6963. if item.MedChrgitmType == "08" { //材料费
  6964. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6965. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6966. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6967. }
  6968. if item.MedChrgitmType == "09" { //西药费
  6969. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6970. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6971. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6972. }
  6973. if item.MedChrgitmType == "11" { //中成费
  6974. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6975. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6976. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6977. }
  6978. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  6979. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6980. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6981. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6982. }
  6983. }
  6984. }
  6985. c.ServeSuccessJSON(map[string]interface{}{
  6986. "order": order,
  6987. "order_info": order_info,
  6988. "patient": patient,
  6989. "admin_info": adminInfo,
  6990. "his_hospital": record,
  6991. "bedCostTotal": bedCostTotal,
  6992. "operationCostTotal": operationCostTotal,
  6993. "otherCostTotal": otherCostTotal,
  6994. "materialCostTotal": materialCostTotal,
  6995. "westernMedicineCostTotal": westernMedicineCostTotal,
  6996. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  6997. "checkCostTotal": checkCostTotal,
  6998. "zhenChaCostTotal": zhenChaCostTotal,
  6999. "laboratoryCostTotal": laboratoryCostTotal,
  7000. "treatCostTotal": treatCostTotal,
  7001. })
  7002. } else {
  7003. for _, item := range order_info {
  7004. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7005. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7006. item.MedChrgitmType = "09"
  7007. }
  7008. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7009. if item.HisPrescriptionProject.Type == 2 {
  7010. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7011. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7012. case 0:
  7013. item.MedChrgitmType = "0"
  7014. break
  7015. case 1:
  7016. item.MedChrgitmType = "14"
  7017. break
  7018. case 2:
  7019. item.MedChrgitmType = "05"
  7020. break
  7021. case 3:
  7022. item.MedChrgitmType = "03"
  7023. break
  7024. case 4:
  7025. item.MedChrgitmType = "03"
  7026. break
  7027. case 5:
  7028. item.MedChrgitmType = "08"
  7029. break
  7030. case 6:
  7031. item.MedChrgitmType = "14"
  7032. break
  7033. case 7:
  7034. item.MedChrgitmType = "14"
  7035. break
  7036. case 8:
  7037. item.MedChrgitmType = "03"
  7038. break
  7039. case 9:
  7040. item.MedChrgitmType = "14"
  7041. break
  7042. case 10:
  7043. item.MedChrgitmType = "14"
  7044. break
  7045. case 11:
  7046. item.MedChrgitmType = "06"
  7047. break
  7048. case 12:
  7049. item.MedChrgitmType = "12"
  7050. break
  7051. case 13:
  7052. item.MedChrgitmType = "01"
  7053. break
  7054. case 14:
  7055. item.MedChrgitmType = "04"
  7056. break
  7057. case 15:
  7058. item.MedChrgitmType = "14"
  7059. break
  7060. }
  7061. } else {
  7062. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7063. case 1:
  7064. item.MedChrgitmType = "14"
  7065. break
  7066. case 2:
  7067. item.MedChrgitmType = "05"
  7068. break
  7069. case 3:
  7070. item.MedChrgitmType = "04"
  7071. break
  7072. case 4:
  7073. item.MedChrgitmType = "14"
  7074. break
  7075. case 5:
  7076. item.MedChrgitmType = "08"
  7077. break
  7078. case 6:
  7079. item.MedChrgitmType = "14"
  7080. break
  7081. case 7:
  7082. item.MedChrgitmType = "14"
  7083. break
  7084. case 8:
  7085. item.MedChrgitmType = "03"
  7086. break
  7087. case 9:
  7088. item.MedChrgitmType = "14"
  7089. break
  7090. }
  7091. }
  7092. } else if item.HisPrescriptionProject.Type == 3 {
  7093. item.MedChrgitmType = "08"
  7094. }
  7095. }
  7096. }
  7097. for _, item := range order_info {
  7098. if org_id == 10215 {
  7099. if item.MedChrgitmType == "01" { //床位费
  7100. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7101. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7102. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7103. }
  7104. if item.MedChrgitmType == "02" { //诊察费
  7105. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7106. //zhenChaCostSelfTotal = zhenChaCostTotal
  7107. }
  7108. if item.MedChrgitmType == "03" { //检查费
  7109. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7110. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7111. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7112. }
  7113. //if item.MedChrgitmType == "02" { //检查费
  7114. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7115. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7116. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7117. //}
  7118. if item.MedChrgitmType == "04" { //化验费
  7119. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7120. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7121. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7122. }
  7123. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7124. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7125. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7126. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7127. }
  7128. if item.MedChrgitmType == "06" { //手术费
  7129. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7130. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7131. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7132. }
  7133. if item.MedChrgitmType == "08" { //材料费
  7134. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7135. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7136. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7137. }
  7138. if item.MedChrgitmType == "09" { //西药费
  7139. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7140. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7141. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7142. }
  7143. if item.MedChrgitmType == "11" { //中成费
  7144. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7145. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7146. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7147. }
  7148. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7149. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7150. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7151. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7152. }
  7153. } else {
  7154. if item.MedChrgitmType == "01" { //床位费
  7155. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7156. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7157. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7158. }
  7159. //if item.MedChrgitmType == "02" { //诊察费
  7160. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7161. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7162. //}
  7163. if item.MedChrgitmType == "03" { //检查费
  7164. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7165. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7166. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7167. }
  7168. //if item.MedChrgitmType == "02" { //检查费
  7169. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7170. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7171. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7172. //}
  7173. if item.MedChrgitmType == "04" { //化验费
  7174. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7175. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7176. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7177. }
  7178. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7179. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7180. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7181. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7182. }
  7183. if item.MedChrgitmType == "06" { //手术费
  7184. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7185. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7186. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7187. }
  7188. if item.MedChrgitmType == "08" { //材料费
  7189. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7190. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7191. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7192. }
  7193. if item.MedChrgitmType == "09" { //西药费
  7194. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7195. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7196. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7197. }
  7198. if item.MedChrgitmType == "11" { //中成费
  7199. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7200. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7201. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7202. }
  7203. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7204. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7205. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7206. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7207. }
  7208. }
  7209. }
  7210. c.ServeSuccessJSON(map[string]interface{}{
  7211. "order": order,
  7212. "order_info": order_info,
  7213. "patient": patient,
  7214. "admin_info": adminInfo,
  7215. "his_hospital": record,
  7216. "bedCostTotal": bedCostTotal,
  7217. "operationCostTotal": operationCostTotal,
  7218. "otherCostTotal": otherCostTotal,
  7219. "materialCostTotal": materialCostTotal,
  7220. "westernMedicineCostTotal": westernMedicineCostTotal,
  7221. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7222. "checkCostTotal": checkCostTotal,
  7223. "zhenChaCostTotal": zhenChaCostTotal,
  7224. "laboratoryCostTotal": laboratoryCostTotal,
  7225. "treatCostTotal": treatCostTotal,
  7226. })
  7227. }
  7228. }
  7229. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  7230. page, _ := c.GetInt64("page")
  7231. limit, _ := c.GetInt64("limit")
  7232. keywords := c.GetString("keywords")
  7233. start_time := c.GetString("start_time")
  7234. end_time := c.GetString("end_time")
  7235. //clr_type := c.GetString("clr_type")
  7236. insutype := c.GetString("insutype")
  7237. timeLayout := "2006-01-02"
  7238. loc, _ := time.LoadLocation("Local")
  7239. var theStartTIme int64
  7240. if len(start_time) > 0 {
  7241. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7242. theStartTIme = theTime.Unix()
  7243. }
  7244. var theEndtTIme int64
  7245. if len(end_time) > 0 {
  7246. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7247. theEndtTIme = theTime.Unix()
  7248. }
  7249. if page <= 0 {
  7250. page = 1
  7251. }
  7252. if limit <= 0 {
  7253. limit = 10
  7254. }
  7255. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  7256. c.ServeSuccessJSON(map[string]interface{}{
  7257. "total": total,
  7258. "list": list,
  7259. })
  7260. return
  7261. }
  7262. func (c *HisApiController) GetPutOnRecordList() {
  7263. page, _ := c.GetInt64("page")
  7264. limit, _ := c.GetInt64("limit")
  7265. keywords := c.GetString("keywords")
  7266. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  7267. if page <= 0 {
  7268. page = 1
  7269. }
  7270. if limit <= 0 {
  7271. limit = 10
  7272. }
  7273. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  7274. c.ServeSuccessJSON(map[string]interface{}{
  7275. "total": total,
  7276. "list": list,
  7277. })
  7278. return
  7279. }
  7280. func (c *HisApiController) GetCompareData() {
  7281. start_time := c.GetString("start_time")
  7282. end_time := c.GetString("end_time")
  7283. insutype := c.GetString("insutype")
  7284. clr_type := c.GetString("clr_type")
  7285. timeLayout := "2006-01-02"
  7286. loc, _ := time.LoadLocation("Local")
  7287. var theStartTIme int64
  7288. if len(start_time) > 0 {
  7289. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7290. if err != nil {
  7291. theStartTIme = 0
  7292. }
  7293. theStartTIme = theTime.Unix()
  7294. }
  7295. var theEndtTIme int64
  7296. if len(end_time) > 0 {
  7297. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7298. if err != nil {
  7299. theEndtTIme = 0
  7300. }
  7301. theEndtTIme = theTime.Unix()
  7302. }
  7303. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  7304. fmt.Println(err)
  7305. if err == nil {
  7306. c.ServeSuccessJSON(map[string]interface{}{
  7307. "list": formData,
  7308. })
  7309. } else {
  7310. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7311. return
  7312. }
  7313. }
  7314. func (c *HisApiController) GetFaPiaoData() {
  7315. order_id, _ := c.GetInt64("order_id")
  7316. patient_id, _ := c.GetInt64("patient_id")
  7317. number := c.GetString("number")
  7318. adminUser := c.GetAdminUserInfo()
  7319. order, _ := service.GetHisOrderByID(order_id)
  7320. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  7321. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  7322. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  7323. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, number)
  7324. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7325. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  7326. var bedCostTotal float64 = 0 //床位总费
  7327. var bedCostSelfTotal float64 = 0 //床位自费
  7328. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  7329. var operationCostTotal float64 = 0 //手术费
  7330. var operationCostSelfTotal float64 = 0 //手术费
  7331. var operationCostPartSelfTotal float64 = 0 //手术费
  7332. var otherCostTotal float64 = 0 //其他费用
  7333. var otherCostSelfTotal float64 = 0 //其他费用
  7334. var otherCostPartSelfTotal float64 = 0 //其他费用
  7335. var materialCostTotal float64 = 0 //材料费
  7336. var materialCostSelfTotal float64 = 0 //材料费
  7337. var materialCostPartSelfTotal float64 = 0 //材料费
  7338. var westernMedicineCostTotal float64 = 0 //西药费
  7339. var westernMedicineCostSelfTotal float64 = 0 //西药费
  7340. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  7341. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7342. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7343. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  7344. var checkCostTotal float64 = 0 //检查费
  7345. var checkCostSelfTotal float64 = 0 //检查费
  7346. var checkCostPartSelfTotal float64 = 0 //检查费
  7347. var laboratoryCostTotal float64 = 0 //化验费
  7348. var laboratoryCostSelfTotal float64 = 0 //化验费
  7349. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  7350. var treatCostTotal float64 = 0 //治疗费用
  7351. var treatCostSelfTotal float64 = 0 //治疗费用
  7352. var treatCostPartSelfTotal float64 = 0 //治疗费用
  7353. var zhenChaCostTotal float64 = 0 //其他费用
  7354. var zhenChaCostSelfTotal float64 = 0 //其他费用
  7355. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7356. decimal.DivisionPrecision = 2
  7357. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7358. var balanceAccountsType int64
  7359. if his.ID > 0 {
  7360. balanceAccountsType = his.BalanceAccountsType
  7361. } else {
  7362. balanceAccountsType = his_hospital_record.BalanceAccountsType
  7363. }
  7364. if balanceAccountsType == 2 {
  7365. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7366. for _, item := range orderInfos_two {
  7367. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7368. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7369. item.MedChrgitmType = "09"
  7370. }
  7371. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7372. if item.HisPrescriptionProject.Type == 2 {
  7373. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7374. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7375. case 0:
  7376. item.MedChrgitmType = "0"
  7377. break
  7378. case 1:
  7379. item.MedChrgitmType = "14"
  7380. break
  7381. case 2:
  7382. item.MedChrgitmType = "05"
  7383. break
  7384. case 3:
  7385. item.MedChrgitmType = "03"
  7386. break
  7387. case 4:
  7388. item.MedChrgitmType = "03"
  7389. break
  7390. case 5:
  7391. item.MedChrgitmType = "08"
  7392. break
  7393. case 6:
  7394. item.MedChrgitmType = "14"
  7395. break
  7396. case 7:
  7397. item.MedChrgitmType = "14"
  7398. break
  7399. case 8:
  7400. item.MedChrgitmType = "03"
  7401. break
  7402. case 9:
  7403. item.MedChrgitmType = "14"
  7404. break
  7405. case 10:
  7406. item.MedChrgitmType = "14"
  7407. break
  7408. case 11:
  7409. item.MedChrgitmType = "06"
  7410. break
  7411. case 12:
  7412. item.MedChrgitmType = "12"
  7413. break
  7414. case 13:
  7415. item.MedChrgitmType = "01"
  7416. break
  7417. case 14:
  7418. item.MedChrgitmType = "04"
  7419. break
  7420. case 15:
  7421. item.MedChrgitmType = "02"
  7422. break
  7423. }
  7424. } else {
  7425. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7426. case 1:
  7427. item.MedChrgitmType = "14"
  7428. break
  7429. case 2:
  7430. item.MedChrgitmType = "05"
  7431. break
  7432. case 3:
  7433. item.MedChrgitmType = "03"
  7434. break
  7435. case 4:
  7436. item.MedChrgitmType = "03"
  7437. break
  7438. case 5:
  7439. item.MedChrgitmType = "08"
  7440. break
  7441. case 6:
  7442. item.MedChrgitmType = "14"
  7443. break
  7444. case 7:
  7445. item.MedChrgitmType = "14"
  7446. break
  7447. case 8:
  7448. item.MedChrgitmType = "03"
  7449. break
  7450. case 9:
  7451. item.MedChrgitmType = "14"
  7452. break
  7453. }
  7454. }
  7455. } else if item.HisPrescriptionProject.Type == 3 {
  7456. item.MedChrgitmType = "08"
  7457. }
  7458. }
  7459. }
  7460. for _, item := range orderInfos_two {
  7461. fmt.Println(item.MedChrgitmType)
  7462. if item.MedChrgitmType == "01" { //床位费
  7463. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7464. bedCostSelfTotal = bedCostTotal
  7465. }
  7466. if item.MedChrgitmType == "02" { //诊察费
  7467. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7468. zhenChaCostSelfTotal = zhenChaCostTotal
  7469. }
  7470. if item.MedChrgitmType == "03" { //检查费
  7471. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7472. checkCostSelfTotal = checkCostTotal
  7473. }
  7474. if item.MedChrgitmType == "04" { //化验费
  7475. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7476. laboratoryCostSelfTotal = laboratoryCostTotal
  7477. }
  7478. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  7479. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7480. treatCostSelfTotal = treatCostTotal
  7481. }
  7482. if item.MedChrgitmType == "06" { //手术费
  7483. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7484. operationCostSelfTotal = treatCostTotal
  7485. }
  7486. if item.MedChrgitmType == "08" { //材料费
  7487. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7488. materialCostSelfTotal = materialCostTotal
  7489. }
  7490. if item.MedChrgitmType == "09" { //西药费
  7491. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7492. westernMedicineCostSelfTotal = westernMedicineCostTotal
  7493. }
  7494. if item.MedChrgitmType == "11" { //中成费
  7495. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7496. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  7497. }
  7498. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  7499. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7500. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7501. otherCostSelfTotal = otherCostTotal
  7502. }
  7503. } else {
  7504. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7505. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7506. otherCostSelfTotal = otherCostTotal
  7507. }
  7508. }
  7509. }
  7510. } else {
  7511. for _, item := range orderInfos {
  7512. if item.MedChrgitmType == "01" { //床位费
  7513. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7514. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7515. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7516. }
  7517. if item.MedChrgitmType == "02" { //诊察费
  7518. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7519. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7520. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7521. }
  7522. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  7523. if item.MedChrgitmType == "03" { //检查费
  7524. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7525. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7526. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7527. }
  7528. } else {
  7529. if item.MedChrgitmType == "03" { //检查费
  7530. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7531. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7532. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7533. }
  7534. }
  7535. if item.MedChrgitmType == "04" { //化验费
  7536. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7537. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7538. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7539. }
  7540. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7541. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7542. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7543. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7544. }
  7545. if item.MedChrgitmType == "06" { //手术费
  7546. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7547. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7548. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7549. }
  7550. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  7551. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7552. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7553. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7554. }
  7555. if item.MedChrgitmType == "09" { //西药费
  7556. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7557. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7558. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7559. }
  7560. if item.MedChrgitmType == "11" { //中成费
  7561. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7562. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7563. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7564. }
  7565. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7566. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7567. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7568. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7569. }
  7570. }
  7571. }
  7572. timeLayout := "2006-01-02"
  7573. loc, _ := time.LoadLocation("Local")
  7574. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  7575. if err != nil {
  7576. }
  7577. startRecordDateTime := startTime.Unix()
  7578. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  7579. if err != nil {
  7580. }
  7581. endRecordDateTime := endTime.Unix()
  7582. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  7583. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  7584. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  7585. c.ServeSuccessJSON(map[string]interface{}{
  7586. "order_number": order.Number, //业务流水号
  7587. "id_card_no": his.IdCardNo, //社会保障号
  7588. "department_name": department.Name, //科室
  7589. "number": his.Number, //门诊号
  7590. "date": order.SettleAccountsDate, //结算日期
  7591. "name": order.PsnName, //姓名
  7592. "gender": patient.Gender, //性别
  7593. "psn_cash_money": order.PsnCashPay, //个人支付
  7594. "pay_way": "门诊", //结算方式
  7595. "medfee_sumamt": order.MedfeeSumamt, //总费用
  7596. "admin_user_name": admin.UserName, //收款员
  7597. "order": order,
  7598. "order_info": orderInfos_two,
  7599. "his": his,
  7600. "bedCostTotal": bedCostTotal,
  7601. "bedCostSelfTotal": bedCostSelfTotal,
  7602. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  7603. "operationCostTotal": operationCostTotal,
  7604. "operationCostSelfTotal": operationCostSelfTotal,
  7605. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  7606. "otherCostTotal": otherCostTotal,
  7607. "otherCostSelfTotal": otherCostSelfTotal,
  7608. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  7609. "materialCostTotal": materialCostTotal,
  7610. "materialCostSelfTotal": materialCostSelfTotal,
  7611. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  7612. "westernMedicineCostTotal": westernMedicineCostTotal,
  7613. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  7614. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  7615. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7616. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  7617. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  7618. "checkCostTotal": checkCostTotal,
  7619. "checkCostSelfTotal": checkCostSelfTotal,
  7620. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  7621. "laboratoryCostTotal": laboratoryCostTotal,
  7622. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  7623. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  7624. "treatCostTotal": treatCostTotal,
  7625. "treatCostSelfTotal": treatCostSelfTotal,
  7626. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  7627. "zhenChaCostTotal": zhenChaCostTotal,
  7628. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  7629. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  7630. "his_hospital_record": his_hospital_record,
  7631. "pre_pay_money": pre_pay_money,
  7632. "refund_sum": sum,
  7633. })
  7634. }
  7635. func (this *HisApiController) GetIncomeStatisticsData() {
  7636. start_time := this.GetString("start_time")
  7637. end_time := this.GetString("end_time")
  7638. key_words := this.GetString("key_words")
  7639. limit, _ := this.GetInt64("limit")
  7640. page, _ := this.GetInt64("page")
  7641. if page <= 0 {
  7642. page = 1
  7643. }
  7644. if limit <= 0 {
  7645. limit = 10
  7646. }
  7647. statistics_type, _ := this.GetInt64("statistics_type")
  7648. admin := this.GetAdminUserInfo()
  7649. timeLayout := "2006-01-02"
  7650. loc, _ := time.LoadLocation("Local")
  7651. var theStartTIme int64
  7652. if len(start_time) > 0 {
  7653. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7654. if err != nil {
  7655. theStartTIme = 0
  7656. }
  7657. theStartTIme = theTime.Unix()
  7658. }
  7659. var theEndtTIme int64
  7660. if len(end_time) > 0 {
  7661. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7662. if err != nil {
  7663. theEndtTIme = 0
  7664. }
  7665. theEndtTIme = theTime.Unix()
  7666. }
  7667. if statistics_type == 1 {
  7668. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  7669. this.ServeSuccessJSON(map[string]interface{}{
  7670. "list": list,
  7671. "total": total,
  7672. })
  7673. } else {
  7674. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  7675. this.ServeSuccessJSON(map[string]interface{}{
  7676. "list": list,
  7677. "total": total,
  7678. })
  7679. }
  7680. }
  7681. func (c *HisApiController) PostProjectInformation() {
  7682. adminUser := c.GetAdminUserInfo()
  7683. orgId := adminUser.CurrentOrgId
  7684. dataBody := make(map[string]interface{}, 0)
  7685. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7686. if err != nil {
  7687. utils.ErrorLog(err.Error())
  7688. return
  7689. }
  7690. utils.ErrorLog("%v", dataBody)
  7691. var projectList []*models.HisProject
  7692. var total_goods []interface{}
  7693. tempProjects := dataBody["projects"].([]interface{})
  7694. total_goods = tempProjects
  7695. for index, projectMap := range tempProjects {
  7696. projectM := projectMap.(map[string]interface{})
  7697. var project models.HisProject
  7698. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  7699. utils.ErrorLog("project_name")
  7700. return
  7701. }
  7702. project_name, _ := projectM["project_name"].(string)
  7703. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  7704. err_log := models.ExportErrLog{
  7705. LogType: 6,
  7706. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7707. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  7708. Status: 1,
  7709. CreateTime: time.Now().Unix(),
  7710. UpdateTime: time.Now().Unix(),
  7711. ExportTime: time.Now().Unix(),
  7712. }
  7713. service.CreateExportErrLog(&err_log)
  7714. continue
  7715. }
  7716. project.ProjectName = project_name
  7717. prices := projectM["price"].(string)
  7718. price, _ := strconv.ParseFloat(prices, 64)
  7719. if price <= 0 { //名字为空则生成一条导入错误日志
  7720. err_log := models.ExportErrLog{
  7721. LogType: 6,
  7722. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7723. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  7724. Status: 1,
  7725. CreateTime: time.Now().Unix(),
  7726. UpdateTime: time.Now().Unix(),
  7727. ExportTime: time.Now().Unix(),
  7728. }
  7729. service.CreateExportErrLog(&err_log)
  7730. continue
  7731. }
  7732. project.Price = price
  7733. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  7734. utils.ErrorLog("unit_id")
  7735. return
  7736. }
  7737. unit := projectM["unit"].(string)
  7738. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  7739. err_log := models.ExportErrLog{
  7740. LogType: 6,
  7741. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7742. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  7743. Status: 1,
  7744. CreateTime: time.Now().Unix(),
  7745. UpdateTime: time.Now().Unix(),
  7746. ExportTime: time.Now().Unix(),
  7747. }
  7748. service.CreateExportErrLog(&err_log)
  7749. continue
  7750. }
  7751. project.Unit = unit
  7752. cost_classify := projectM["cost_classify"].(string)
  7753. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  7754. err_log := models.ExportErrLog{
  7755. LogType: 6,
  7756. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7757. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  7758. Status: 1,
  7759. CreateTime: time.Now().Unix(),
  7760. UpdateTime: time.Now().Unix(),
  7761. ExportTime: time.Now().Unix(),
  7762. }
  7763. service.CreateExportErrLog(&err_log)
  7764. continue
  7765. }
  7766. var costClassify = "费用类别"
  7767. var cost_classify_id int64
  7768. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  7769. if len(cost_classify) != 0 {
  7770. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  7771. if errcode == gorm.ErrRecordNotFound {
  7772. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  7773. dataconfig := models.DictDataconfig{
  7774. ParentId: costClassifyConfig.ID,
  7775. Module: "system",
  7776. OrgId: orgId,
  7777. Name: cost_classify,
  7778. FieldName: "",
  7779. Value: costConfig.Value + 1,
  7780. CreatedTime: "",
  7781. UpdatedTime: "",
  7782. CreateUserId: adminUser.AdminUser.Id,
  7783. Status: 1,
  7784. Remark: "",
  7785. DeleteIdSystem: 0,
  7786. Title: "",
  7787. Content: "",
  7788. Order: 0,
  7789. Code: "",
  7790. }
  7791. service.CreatedDicConfig(&dataconfig)
  7792. }
  7793. }
  7794. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  7795. for _, it := range costClassList {
  7796. if cost_classify == it.Name {
  7797. cost_classify_id = int64(it.Value)
  7798. }
  7799. }
  7800. project.CostClassify = cost_classify_id
  7801. executive_section := projectM["executive_section"].(string)
  7802. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  7803. err_log := models.ExportErrLog{
  7804. LogType: 6,
  7805. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7806. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  7807. Status: 1,
  7808. CreateTime: time.Now().Unix(),
  7809. UpdateTime: time.Now().Unix(),
  7810. ExportTime: time.Now().Unix(),
  7811. }
  7812. service.CreateExportErrLog(&err_log)
  7813. continue
  7814. }
  7815. if len(executive_section) != 0 {
  7816. //查找科室是否有内容
  7817. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  7818. if errcodedepart == gorm.ErrRecordNotFound {
  7819. department := models.XtHisDepartment{
  7820. Name: executive_section,
  7821. Status: 1,
  7822. UserOrgId: adminUser.CurrentOrgId,
  7823. CreatedTime: time.Now().Unix(),
  7824. }
  7825. service.CreateDePartment(&department)
  7826. }
  7827. }
  7828. var executive_section_id int64
  7829. departMentList, _ := service.GetAllDepartMent(orgId)
  7830. for _, it := range departMentList {
  7831. if executive_section == it.Name {
  7832. executive_section_id = it.ID
  7833. }
  7834. }
  7835. project.ExecutiveSection = executive_section_id
  7836. medical_coverage := projectM["medical_coverage"].(string)
  7837. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  7838. err_log := models.ExportErrLog{
  7839. LogType: 6,
  7840. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7841. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  7842. Status: 1,
  7843. CreateTime: time.Now().Unix(),
  7844. UpdateTime: time.Now().Unix(),
  7845. ExportTime: time.Now().Unix(),
  7846. }
  7847. service.CreateExportErrLog(&err_log)
  7848. continue
  7849. }
  7850. var medicalCoverage = "医保等级"
  7851. var medical_coverage_id int64
  7852. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  7853. if len(medical_coverage) != 0 {
  7854. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  7855. if errormedicalcoverage == gorm.ErrRecordNotFound {
  7856. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  7857. dataconfig := models.DictDataconfig{
  7858. ParentId: medicalCoverageConfig.ID,
  7859. Module: "system",
  7860. OrgId: orgId,
  7861. Name: medical_coverage,
  7862. FieldName: "",
  7863. Value: medicalCoverageConfig.Value + 1,
  7864. CreatedTime: "",
  7865. UpdatedTime: "",
  7866. CreateUserId: adminUser.AdminUser.Id,
  7867. Status: 1,
  7868. Remark: "",
  7869. DeleteIdSystem: 0,
  7870. Title: "",
  7871. Content: "",
  7872. Order: 0,
  7873. Code: "",
  7874. }
  7875. service.CreatedDicConfig(&dataconfig)
  7876. }
  7877. }
  7878. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  7879. for _, it := range medicalCoverageList {
  7880. if medical_coverage == it.Name {
  7881. medical_coverage_id = int64(it.Value)
  7882. }
  7883. }
  7884. project.MedicalCoverage = medical_coverage_id
  7885. pinyin := projectM["pinyin"].(string)
  7886. project.Pinyin = pinyin
  7887. wubi := projectM["wubi"].(string)
  7888. project.Wubi = wubi
  7889. statistical_classification := projectM["statistical_classification"].(string)
  7890. var statisticalClassification = "统计分类"
  7891. var statistical_classification_id int64
  7892. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  7893. if len(statistical_classification) != 0 {
  7894. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  7895. if classificationerrcodes == gorm.ErrRecordNotFound {
  7896. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  7897. dataconfig := models.DictDataconfig{
  7898. ParentId: classiFication.ID,
  7899. Module: "system",
  7900. OrgId: orgId,
  7901. Name: statistical_classification,
  7902. FieldName: "",
  7903. Value: classiFicationConfig.Value + 1,
  7904. CreatedTime: "",
  7905. UpdatedTime: "",
  7906. CreateUserId: adminUser.AdminUser.Id,
  7907. Status: 1,
  7908. Remark: "",
  7909. DeleteIdSystem: 0,
  7910. Title: "",
  7911. Content: "",
  7912. Order: 0,
  7913. Code: "",
  7914. }
  7915. service.CreatedDicConfig(&dataconfig)
  7916. }
  7917. }
  7918. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  7919. for _, it := range classiFicationList {
  7920. if statistical_classification == it.Name {
  7921. statistical_classification_id = int64(it.Value)
  7922. }
  7923. }
  7924. project.StatisticalClassification = statistical_classification_id
  7925. disease_directory := int64(projectM["disease_directory"].(float64))
  7926. project.DiseaseDirectory = disease_directory
  7927. is_record := int64(projectM["is_record"].(float64))
  7928. project.IsRecord = is_record
  7929. medical_code := projectM["medical_code"].(string)
  7930. project.MedicalCode = medical_code
  7931. tube_color := projectM["tube_color"].(string)
  7932. var tubeColor = "试管颜色"
  7933. var tube_color_id int64
  7934. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  7935. if len(tube_color) != 0 {
  7936. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  7937. if errcodetube == gorm.ErrRecordNotFound {
  7938. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  7939. dataconfig := models.DictDataconfig{
  7940. ParentId: tubeColorConfig.ID,
  7941. Module: "system",
  7942. OrgId: orgId,
  7943. Name: tube_color,
  7944. FieldName: "",
  7945. Value: tubeConfig.Value + 1,
  7946. CreatedTime: "",
  7947. UpdatedTime: "",
  7948. CreateUserId: adminUser.AdminUser.Id,
  7949. Status: 1,
  7950. Remark: "",
  7951. DeleteIdSystem: 0,
  7952. Title: "",
  7953. Content: "",
  7954. Order: 0,
  7955. Code: "",
  7956. }
  7957. service.CreatedDicConfig(&dataconfig)
  7958. }
  7959. }
  7960. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  7961. for _, it := range tubeColorList {
  7962. if tube_color == it.Name {
  7963. tube_color_id = int64(it.Value)
  7964. }
  7965. }
  7966. project.TubeColor = tube_color_id
  7967. single_dose := projectM["single_dose"].(string)
  7968. project.SingleDose = single_dose
  7969. execution_frequency := projectM["execution_frequency"].(string)
  7970. project.ExecutionFrequency = execution_frequency
  7971. delivery_way := projectM["delivery_way"].(string)
  7972. project.DeliveryWay = delivery_way
  7973. number_days := projectM["number_days"].(string)
  7974. project.NumberDays = number_days
  7975. total := projectM["total"].(string)
  7976. project.Total = total
  7977. medical_status := int64(projectM["medical_status"].(float64))
  7978. project.MedicalStatus = medical_status
  7979. category := int64(projectM["category"].(float64))
  7980. project.Category = category
  7981. specail_project := int64(projectM["specail_project"].(float64))
  7982. project.SpecailProject = specail_project
  7983. social_security_directory_code := projectM["social_security_directory_code"].(string)
  7984. project.SocialSecurityDirectoryCode = social_security_directory_code
  7985. remark := projectM["remark"].(string)
  7986. project.Remark = remark
  7987. record_date := projectM["record_date"].(string)
  7988. timeLayout := "2006-01-02"
  7989. loc, _ := time.LoadLocation("Local")
  7990. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7991. project.RecordDate = theTime.Unix()
  7992. projectList = append(projectList, &project)
  7993. }
  7994. export_time := time.Now().Unix()
  7995. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  7996. if len(projectList) > 0 {
  7997. for _, item := range projectList {
  7998. project := models.HisProject{
  7999. ProjectName: item.ProjectName,
  8000. Price: item.Price,
  8001. Unit: item.Unit,
  8002. CostClassify: item.CostClassify,
  8003. ExecutiveSection: item.ExecutiveSection,
  8004. MedicalCoverage: item.MedicalCoverage,
  8005. UserOrgId: orgId,
  8006. Status: 1,
  8007. CreatedTime: time.Now().Unix(),
  8008. Pinyin: item.Pinyin,
  8009. Wubi: item.Wubi,
  8010. StatisticalClassification: item.StatisticalClassification,
  8011. DiseaseDirectory: item.DiseaseDirectory,
  8012. IsRecord: item.IsRecord,
  8013. MedicalCode: item.MedicalCode,
  8014. TubeColor: item.TubeColor,
  8015. SingleDose: item.SingleDose,
  8016. DeliveryWay: item.DeliveryWay,
  8017. NumberDays: item.NumberDays,
  8018. Total: item.Total,
  8019. Category: item.Category,
  8020. MedicalStatus: item.MedicalStatus,
  8021. SpecailProject: item.SpecailProject,
  8022. RecordDate: item.RecordDate,
  8023. Remark: item.Remark,
  8024. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  8025. ExecutionFrequency: item.ExecutionFrequency,
  8026. }
  8027. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  8028. if errcodeproject == gorm.ErrRecordNotFound {
  8029. service.CreateProjectInfomation(&project)
  8030. } else if errcodeproject == nil {
  8031. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  8032. }
  8033. log := models.ExportLog{
  8034. LogType: 6,
  8035. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8036. TotalNum: int64(len(total_goods)),
  8037. FailNum: int64(len(errLogs)),
  8038. SuccessNum: int64(len(projectList)),
  8039. CreateTime: time.Now().Unix(),
  8040. UpdateTime: time.Now().Unix(),
  8041. ExportTime: export_time,
  8042. Status: 1,
  8043. }
  8044. service.CreateExportLog(&log)
  8045. c.ServeSuccessJSON(map[string]interface{}{
  8046. "msg": "导入成功",
  8047. "total_num": len(total_goods),
  8048. "success_num": len(projectList),
  8049. "fail_num": int64(len(errLogs)),
  8050. })
  8051. }
  8052. } else {
  8053. log := models.ExportLog{
  8054. LogType: 6,
  8055. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8056. TotalNum: int64(len(total_goods)),
  8057. FailNum: int64(len(errLogs)),
  8058. SuccessNum: int64(len(projectList)),
  8059. CreateTime: time.Now().Unix(),
  8060. UpdateTime: time.Now().Unix(),
  8061. ExportTime: export_time,
  8062. Status: 1,
  8063. }
  8064. service.CreateExportLog(&log)
  8065. c.ServeSuccessJSON(map[string]interface{}{
  8066. "msg": "导入成功",
  8067. "total_num": len(total_goods),
  8068. "success_num": len(projectList),
  8069. "fail_num": int64(len(errLogs)),
  8070. })
  8071. }
  8072. }
  8073. //func (this *HisApiController) EditProjectInformation(){
  8074. //
  8075. // id, _ := this.GetInt64("id")
  8076. // project_team := this.GetString("project_team")
  8077. // price := this.GetString("price")
  8078. // price_float, _ := strconv.ParseFloat(price, 64)
  8079. // pinyin := this.GetString("pinyin")
  8080. // wubi := this.GetString("wubi")
  8081. // tube_color, _ := this.GetInt64("tube_color")
  8082. // team_type, _ := this.GetInt64("team_type")
  8083. // remark := this.GetString("remark")
  8084. // ids := this.GetString("ids")
  8085. // item_id := this.GetString("item_id")
  8086. // projectTeam := models.XtHisProjectTeam{
  8087. // ProjectTeam: project_team,
  8088. // Price: price_float,
  8089. // Pinyin: pinyin,
  8090. // Wubi: wubi,
  8091. // TubeColor: tube_color,
  8092. // TeamType: team_type,
  8093. // Remark: remark,
  8094. // ProjectId: ids,
  8095. // ItemId: item_id,
  8096. // }
  8097. //
  8098. //
  8099. // dataBody := make(map[string]interface{}, 0)
  8100. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8101. // if err != nil {
  8102. // utils.ErrorLog(err.Error())
  8103. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8104. // return
  8105. // }
  8106. //
  8107. // err = service.UpdatedProjectTeam(id, &projectTeam)
  8108. //
  8109. //
  8110. // if err != nil {
  8111. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  8112. // return
  8113. // }
  8114. //
  8115. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  8116. // infos, _ := dataBody["info"].([]interface{})
  8117. // if len(infos) > 0 {
  8118. // var ids []string
  8119. //
  8120. // for _, item := range infos {
  8121. // items := item.(map[string]interface{})
  8122. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  8123. // utils.ErrorLog("id")
  8124. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8125. // return
  8126. // }
  8127. // id := int64(items["id"].(float64))
  8128. //
  8129. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8130. // utils.ErrorLog("type")
  8131. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8132. // return
  8133. // }
  8134. // types := int64(items["type"].(float64))
  8135. //
  8136. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  8137. // utils.ErrorLog("number")
  8138. // }
  8139. //
  8140. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  8141. //
  8142. // projectList := models.XtHisProjectList{
  8143. // Number: number,
  8144. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  8145. // ProjectId: id,
  8146. // Status: 1,
  8147. // CreatedTime: time.Now().Unix(),
  8148. // UpdatedTime: time.Now().Unix(),
  8149. // TeamId: projectTeam.ID,
  8150. // Type: types,
  8151. // }
  8152. // list := projectList
  8153. //
  8154. // service.CreateProjectList(&list)
  8155. //
  8156. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  8157. //
  8158. // }
  8159. // ids_str := strings.Join(ids, ",")
  8160. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  8161. // service.SaveProjectTeam(&projectTeam)
  8162. // this.ServeSuccessJSON(map[string]interface{}{
  8163. // "projectTeam": projectTeam,
  8164. // })
  8165. // }
  8166. // }
  8167. //}
  8168. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  8169. name := c.GetString("name")
  8170. mode_id, _ := c.GetInt64("mode", 0)
  8171. types, _ := c.GetInt64("type", 0)
  8172. patient_id, _ := c.GetInt64("patient_id", 0)
  8173. types = 1
  8174. adminInfo := c.GetAdminUserInfo()
  8175. template := &models.HisPrescriptionTemplate{
  8176. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8177. PatientId: patient_id,
  8178. Type: types,
  8179. Status: 1,
  8180. Ctime: time.Now().Unix(),
  8181. Mtime: time.Now().Unix(),
  8182. Name: name,
  8183. Mode: mode_id,
  8184. }
  8185. dataBody := make(map[string]interface{}, 0)
  8186. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8187. if err != nil {
  8188. utils.ErrorLog(err.Error())
  8189. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8190. return
  8191. }
  8192. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  8193. //如果已经存在记录则删除处方
  8194. if template_one.ID > 0 {
  8195. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  8196. for _, item := range ps {
  8197. service.DelelteHisPrescriptionInfoTemplate(item.ID, item.UserOrgId)
  8198. }
  8199. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  8200. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  8201. if len(prescriptions) > 0 {
  8202. for _, item := range prescriptions {
  8203. items := item.(map[string]interface{})
  8204. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8205. utils.ErrorLog("type")
  8206. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8207. return
  8208. }
  8209. types := int64(items["type"].(float64))
  8210. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  8211. utils.ErrorLog("med_type")
  8212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8213. return
  8214. }
  8215. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  8216. ctime := time.Now().Unix()
  8217. prescription := &models.HisPrescriptionInfoTemplate{
  8218. PatientId: patient_id,
  8219. UserOrgId: adminInfo.CurrentOrgId,
  8220. Ctime: ctime,
  8221. Mtime: ctime,
  8222. Type: types,
  8223. Modifier: adminInfo.AdminUser.Id,
  8224. Creator: adminInfo.AdminUser.Id,
  8225. Status: 1,
  8226. PTemplateId: template_one.ID,
  8227. MedType: med_type,
  8228. }
  8229. service.CreateHisPrescriptionInfoTemplate(prescription)
  8230. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  8231. advices := items["advices"].([]interface{})
  8232. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  8233. ctime := time.Now().Unix()
  8234. mtime := ctime
  8235. if len(advices) > 0 {
  8236. for _, advice := range advices {
  8237. var s models.HisPrescriptionAdviceTemplate
  8238. s.PrescriptionId = prescription.ID
  8239. s.AdviceType = 2
  8240. s.StopState = 2
  8241. s.ExecutionState = 2
  8242. s.Status = 1
  8243. s.UserOrgId = adminInfo.CurrentOrgId
  8244. s.CreatedTime = ctime
  8245. s.UpdatedTime = mtime
  8246. s.PatientId = patient_id
  8247. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  8248. if errcode > 0 {
  8249. c.ServeFailJSONWithSGJErrorCode(errcode)
  8250. return
  8251. }
  8252. service.CreateHisPrescriptionAdviceTemplate(&s)
  8253. }
  8254. }
  8255. }
  8256. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  8257. projects := items["project"].([]interface{})
  8258. if len(projects) > 0 {
  8259. for _, project := range projects {
  8260. var p models.HisPrescriptionProjectTemplate
  8261. p.PrescriptionId = prescription.ID
  8262. p.Ctime = time.Now().Unix()
  8263. p.Mtime = time.Now().Unix()
  8264. p.PatientId = patient_id
  8265. p.UserOrgId = adminInfo.CurrentOrgId
  8266. p.Status = 1
  8267. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  8268. if errcode > 0 {
  8269. c.ServeFailJSONWithSGJErrorCode(errcode)
  8270. return
  8271. }
  8272. service.CreateHisPrescriptionProjectTemplate(&p)
  8273. }
  8274. }
  8275. }
  8276. }
  8277. c.ServeSuccessJSON(map[string]interface{}{
  8278. "msg": "创建成功",
  8279. })
  8280. }
  8281. }
  8282. } else {
  8283. err = service.CreateHisPrescriptionTemplate(template)
  8284. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  8285. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  8286. if len(prescriptions) > 0 {
  8287. for _, item := range prescriptions {
  8288. items := item.(map[string]interface{})
  8289. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8290. utils.ErrorLog("type")
  8291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8292. return
  8293. }
  8294. types := int64(items["type"].(float64))
  8295. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  8296. utils.ErrorLog("med_type")
  8297. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8298. return
  8299. }
  8300. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  8301. ctime := time.Now().Unix()
  8302. prescription := &models.HisPrescriptionInfoTemplate{
  8303. PatientId: patient_id,
  8304. UserOrgId: adminInfo.CurrentOrgId,
  8305. Ctime: ctime,
  8306. Mtime: ctime,
  8307. Type: types,
  8308. Modifier: adminInfo.AdminUser.Id,
  8309. Creator: adminInfo.AdminUser.Id,
  8310. Status: 1,
  8311. PTemplateId: template.ID,
  8312. MedType: med_type,
  8313. }
  8314. service.CreateHisPrescriptionInfoTemplate(prescription)
  8315. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  8316. advices := items["advices"].([]interface{})
  8317. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  8318. ctime := time.Now().Unix()
  8319. mtime := ctime
  8320. if len(advices) > 0 {
  8321. for _, advice := range advices {
  8322. var s models.HisPrescriptionAdviceTemplate
  8323. s.PrescriptionId = prescription.ID
  8324. s.AdviceType = 2
  8325. s.StopState = 2
  8326. s.ExecutionState = 2
  8327. s.Status = 1
  8328. s.UserOrgId = adminInfo.CurrentOrgId
  8329. s.CreatedTime = ctime
  8330. s.UpdatedTime = mtime
  8331. s.PatientId = patient_id
  8332. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  8333. if errcode > 0 {
  8334. c.ServeFailJSONWithSGJErrorCode(errcode)
  8335. return
  8336. }
  8337. service.CreateHisPrescriptionAdviceTemplate(&s)
  8338. }
  8339. }
  8340. }
  8341. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  8342. projects := items["project"].([]interface{})
  8343. if len(projects) > 0 {
  8344. for _, project := range projects {
  8345. var p models.HisPrescriptionProjectTemplate
  8346. p.PrescriptionId = prescription.ID
  8347. p.Ctime = time.Now().Unix()
  8348. p.Mtime = time.Now().Unix()
  8349. p.PatientId = patient_id
  8350. p.UserOrgId = adminInfo.CurrentOrgId
  8351. p.Status = 1
  8352. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  8353. if errcode > 0 {
  8354. c.ServeFailJSONWithSGJErrorCode(errcode)
  8355. return
  8356. }
  8357. service.CreateHisPrescriptionProjectTemplate(&p)
  8358. }
  8359. }
  8360. }
  8361. }
  8362. c.ServeSuccessJSON(map[string]interface{}{
  8363. "msg": "创建成功",
  8364. })
  8365. }
  8366. }
  8367. }
  8368. }
  8369. func (c *HisApiController) PreSettle() {
  8370. id, _ := c.GetInt64("id")
  8371. record_time := c.GetString("record_time")
  8372. his_patient_id, _ := c.GetInt64("his_patient_id")
  8373. timeLayout := "2006-01-02"
  8374. loc, _ := time.LoadLocation("Local")
  8375. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  8376. diagnosis_id := c.GetString("diagnosis")
  8377. sick_type, _ := c.GetInt64("sick_type")
  8378. reg_type, _ := c.GetInt64("p_type")
  8379. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  8380. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8381. if err != nil {
  8382. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8383. return
  8384. }
  8385. recordDateTime := theTime.Unix()
  8386. adminUser := c.GetAdminUserInfo()
  8387. var prescriptions []*models.HisPrescription
  8388. var start_time int64
  8389. var end_time int64
  8390. ids_str := c.GetString("ids")
  8391. ids_arr := strings.Split(ids_str, ",")
  8392. fmt.Println(reg_type)
  8393. if settle_accounts_type == 1 { //日结
  8394. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  8395. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  8396. } else {
  8397. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  8398. }
  8399. fmt.Println(prescriptions)
  8400. } else { //月结
  8401. start_time_str := c.GetString("start_time")
  8402. end_time_str := c.GetString("end_time")
  8403. timeLayout := "2006-01-02"
  8404. loc, _ := time.LoadLocation("Local")
  8405. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  8406. if err != nil {
  8407. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8408. return
  8409. }
  8410. recordStartTime := theStartTime.Unix()
  8411. start_time = recordStartTime
  8412. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  8413. if err != nil {
  8414. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8415. return
  8416. }
  8417. recordEndTime := theEndTime.Unix()
  8418. end_time = recordEndTime
  8419. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  8420. }
  8421. if reg_type == 1111 || reg_type == 1112 {
  8422. reg_type = 11
  8423. }
  8424. timestamp := time.Now().Unix()
  8425. tempTime := time.Unix(timestamp, 0)
  8426. timeFormat := tempTime.Format("20060102150405")
  8427. chrgBchno := rand.Intn(100000) + 10000
  8428. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  8429. strconv.FormatInt(his.PatientId, 10)
  8430. var ids []int64
  8431. for _, item := range prescriptions {
  8432. ids = append(ids, item.ID)
  8433. }
  8434. fmt.Println(ids)
  8435. var total float64
  8436. for _, item := range prescriptions {
  8437. fmt.Println(item)
  8438. if item.Type == 1 { //药品
  8439. for _, subItem := range item.HisDoctorAdviceInfo {
  8440. total = total + (subItem.Price * subItem.PrescribingNumber)
  8441. }
  8442. }
  8443. if item.Type == 2 { //项目
  8444. for _, subItem := range item.HisPrescriptionProject {
  8445. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8446. total = total + (subItem.Price * cnt)
  8447. }
  8448. }
  8449. for _, subItem := range item.HisAdditionalCharge {
  8450. total = total + (subItem.Price * float64(subItem.Count))
  8451. }
  8452. }
  8453. allTotal := fmt.Sprintf("%.2f", total)
  8454. totals, _ := strconv.ParseFloat(allTotal, 64)
  8455. order := &models.HisOrder{
  8456. UserOrgId: adminUser.CurrentOrgId,
  8457. HisPatientId: his.ID,
  8458. PatientId: id,
  8459. SettleAccountsDate: recordDateTime,
  8460. Ctime: time.Now().Unix(),
  8461. Mtime: time.Now().Unix(),
  8462. Status: 1,
  8463. OrderStatus: 1,
  8464. MdtrtId: his.Number,
  8465. Number: chrg_bchno,
  8466. MedfeeSumamt: totals,
  8467. SettleEndTime: end_time,
  8468. SettleStartTime: start_time,
  8469. SettleType: settle_accounts_type,
  8470. PsnPartAmt: totals,
  8471. PsnCashPay: totals,
  8472. PType: 2,
  8473. IsPre: 1,
  8474. MedType: strconv.Itoa(int(reg_type)),
  8475. Diagnosis: diagnosis_id,
  8476. }
  8477. err = service.CreateOrder(order)
  8478. if err != nil {
  8479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8480. return
  8481. }
  8482. var customs []*Custom
  8483. for _, item := range prescriptions {
  8484. fmt.Println(item.Type)
  8485. if item.Type == 1 { //药品
  8486. for _, subItem := range item.HisDoctorAdviceInfo {
  8487. cus := &Custom{
  8488. AdviceId: subItem.ID,
  8489. ProjectId: 0,
  8490. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  8491. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  8492. FeedetlSn: subItem.FeedetlSn,
  8493. Price: fmt.Sprintf("%.2f", subItem.Price),
  8494. MedListCodg: subItem.MedListCodg,
  8495. Type: 1,
  8496. }
  8497. customs = append(customs, cus)
  8498. }
  8499. }
  8500. if item.Type == 2 { //项目
  8501. for _, subItem := range item.HisPrescriptionProject {
  8502. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8503. cus := &Custom{
  8504. AdviceId: 0,
  8505. ProjectId: subItem.ID,
  8506. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  8507. Cut: fmt.Sprintf("%.2f", cnt),
  8508. FeedetlSn: subItem.FeedetlSn,
  8509. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  8510. MedListCodg: subItem.MedListCodg,
  8511. Type: 2,
  8512. }
  8513. customs = append(customs, cus)
  8514. }
  8515. }
  8516. for _, item := range item.HisAdditionalCharge {
  8517. cus := &Custom{
  8518. ItemId: item.ID,
  8519. AdviceId: 0,
  8520. ProjectId: 0,
  8521. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  8522. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  8523. FeedetlSn: item.FeedetlSn,
  8524. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  8525. MedListCodg: item.XtHisAddtionConfig.Code,
  8526. Type: 3,
  8527. }
  8528. customs = append(customs, cus)
  8529. }
  8530. }
  8531. fmt.Println(customs)
  8532. for _, item := range customs {
  8533. var advice_id int64 = 0
  8534. var project_id int64 = 0
  8535. var item_id int64 = 0
  8536. var types int64 = 0
  8537. if item.Type == 1 {
  8538. advice_id = item.AdviceId
  8539. project_id = 0
  8540. item_id = 0
  8541. } else if item.Type == 2 {
  8542. advice_id = 0
  8543. item_id = 0
  8544. project_id = item.ProjectId
  8545. } else if item.Type == 3 {
  8546. advice_id = 0
  8547. item_id = item.ItemId
  8548. project_id = 0
  8549. }
  8550. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8551. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8552. pric, _ := strconv.ParseFloat(item.Price, 32)
  8553. info := &models.HisOrderInfo{
  8554. OrderNumber: order.Number,
  8555. UploadDate: time.Now().Unix(),
  8556. AdviceId: advice_id,
  8557. DetItemFeeSumamt: detItemFeeSumamt,
  8558. Cnt: cut,
  8559. Pric: pric,
  8560. PatientId: id,
  8561. Status: 1,
  8562. Mtime: time.Now().Unix(),
  8563. Ctime: time.Now().Unix(),
  8564. UserOrgId: adminUser.CurrentOrgId,
  8565. HisPatientId: his.ID,
  8566. OrderId: order.ID,
  8567. ProjectId: project_id,
  8568. Type: types,
  8569. ItemId: item_id,
  8570. }
  8571. service.CreateOrderInfo(info)
  8572. }
  8573. his.SickType = sick_type
  8574. service.UpdataHisPateint(&his)
  8575. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  8576. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  8577. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  8578. if err == nil {
  8579. c.ServeSuccessJSON(map[string]interface{}{
  8580. "msg": "结算成功",
  8581. })
  8582. }
  8583. }
  8584. type CustomOrderInfo struct {
  8585. Name string
  8586. Spec string
  8587. Unit string
  8588. Count float64
  8589. Price float64
  8590. Total float64
  8591. }
  8592. func (c *HisApiController) GetPrivateExpensesInfo() {
  8593. order_id, _ := c.GetInt64("id", 0)
  8594. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  8595. order, _ := service.GetHisOrderByID(order_id)
  8596. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  8597. if order.ID == 0 {
  8598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8599. return
  8600. }
  8601. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  8602. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  8603. org_id := c.GetAdminUserInfo().CurrentOrgId
  8604. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8605. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8606. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  8607. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  8608. orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  8609. var orderInfos_four []*models.HisOrderInfoTwo
  8610. for _, item := range orderInfos_three {
  8611. if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  8612. item.HisPrescriptionProject.IsCheckTeam = 1
  8613. orderInfos_four = append(orderInfos_four, item)
  8614. }
  8615. if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  8616. item.HisPrescriptionProject.IsCheckTeam = 2
  8617. orderInfos_two = append(orderInfos_two, item)
  8618. }
  8619. }
  8620. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  8621. var cus_slice []CustomOrderInfo
  8622. //for _, item := range new_order_info {
  8623. // var cus CustomOrderInfo
  8624. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  8625. // cus.Unit = ""
  8626. // cus.Spec = ""
  8627. // var total float64
  8628. // for _, subItem := range orderInfos_four {
  8629. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  8630. // total = total + subItem.DetItemFeeSumamt
  8631. // fmt.Println(subItem.DetItemFeeSumamt)
  8632. // }
  8633. // }
  8634. // cus.Count = 1
  8635. // cus.Total = total
  8636. // cus_slice = append(cus_slice, cus)
  8637. //}
  8638. orderInfos = append(orderInfos, orderInfos_two...)
  8639. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  8640. orderInfos = append(orderInfos, orderInfos_three...)
  8641. //}/**/
  8642. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  8643. c.ServeSuccessJSON(map[string]interface{}{
  8644. "order": order,
  8645. "order_info": orderInfos,
  8646. "patient": patient,
  8647. "admin_info": adminInfo,
  8648. "his": his,
  8649. "current_admin": role,
  8650. "org_config": miConfig,
  8651. "new_order_info": cus_slice,
  8652. })
  8653. }
  8654. func (this *HisApiController) ChangeMedType() {
  8655. med_type := this.GetString("med_type")
  8656. old_med_type := this.GetString("old_med_type")
  8657. ids := this.GetString("ids")
  8658. settle_type, _ := this.GetInt64("settle_type")
  8659. start_time := this.GetString("start_time")
  8660. end_time := this.GetString("end_time")
  8661. ids_arr := strings.Split(ids, ",")
  8662. if settle_type == 1 { //日结
  8663. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  8664. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  8665. prescription.MedType = med_type
  8666. err := service.SaveHisPrescription(&prescription)
  8667. if err == nil {
  8668. this.ServeSuccessJSON(map[string]interface{}{
  8669. "msg": "修改成功",
  8670. })
  8671. } else {
  8672. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8673. return
  8674. }
  8675. } else if settle_type == 2 {
  8676. timeLayout := "2006-01-02"
  8677. loc, _ := time.LoadLocation("Local")
  8678. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8679. if err != nil {
  8680. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8681. return
  8682. }
  8683. recordStartTime := theStartTime.Unix()
  8684. start_time_timestamp := recordStartTime
  8685. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8686. if err != nil {
  8687. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8688. return
  8689. }
  8690. recordEndTime := theEndTime.Unix()
  8691. end_time_timestamp := recordEndTime
  8692. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  8693. if updateErr == nil {
  8694. this.ServeSuccessJSON(map[string]interface{}{
  8695. "msg": "修改成功",
  8696. })
  8697. } else {
  8698. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8699. return
  8700. }
  8701. }
  8702. }
  8703. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  8704. patient_id, _ := c.GetInt64("patient_id")
  8705. his_patient_id, _ := c.GetInt64("his_patient_id")
  8706. record_date := c.GetString("record_date")
  8707. start_time := c.GetString("start_time")
  8708. end_time := c.GetString("end_time")
  8709. order_status, _ := c.GetInt64("type", 0)
  8710. p_type, _ := c.GetInt64("p_type", 0)
  8711. order_id, _ := c.GetInt64("order_id", 0)
  8712. timeLayout := "2006-01-02"
  8713. loc, _ := time.LoadLocation("Local")
  8714. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8715. if err != nil {
  8716. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8717. return
  8718. }
  8719. recordDateTime := theTime.Unix()
  8720. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8721. if err != nil {
  8722. }
  8723. startRecordDateTime := startTime.Unix()
  8724. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8725. if err != nil {
  8726. }
  8727. endRecordDateTime := endTime.Unix()
  8728. admin := c.GetAdminUserInfo()
  8729. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8730. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8731. order, _ := service.GetHisOrderByID(order_id)
  8732. var monthPrescriptions []*models.HisPrescription
  8733. if order_status == 1 || order_status == 0 {
  8734. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8735. } else if order_status == 2 {
  8736. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  8737. }
  8738. var settle_total float64
  8739. for _, item := range monthPrescriptions {
  8740. if len(item.HisPrescriptionProject) > 0 {
  8741. for _, subItem := range item.HisPrescriptionProject {
  8742. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8743. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8744. settle_total = settle_total + total
  8745. }
  8746. }
  8747. if len(item.HisDoctorAdviceInfo) > 0 {
  8748. for _, subItem := range item.HisDoctorAdviceInfo {
  8749. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8750. settle_total = settle_total + total
  8751. }
  8752. }
  8753. }
  8754. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8755. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8756. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8757. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8758. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8759. //获取所有科室信息
  8760. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8761. c.ServeSuccessJSON(map[string]interface{}{
  8762. "his_info": his_patient_info,
  8763. "xt_info": xt_patient_info,
  8764. "case_history": case_history,
  8765. "info": patientPrescriptionInfo,
  8766. "last_info": lastPatientPrescriptionInfo,
  8767. "month_prescriptions": monthPrescriptions,
  8768. "order": order,
  8769. "doctors": doctors,
  8770. "department": department,
  8771. "settle_total": settle_total,
  8772. })
  8773. return
  8774. }
  8775. func (c *HisApiController) GetHisMonthPatientInfo() {
  8776. patient_id, _ := c.GetInt64("patient_id")
  8777. his_patient_id, _ := c.GetInt64("his_patient_id")
  8778. record_date := c.GetString("record_date")
  8779. number := c.GetString("number")
  8780. start_time := c.GetString("start_time")
  8781. end_time := c.GetString("end_time")
  8782. p_type, _ := c.GetInt64("p_type")
  8783. timeLayout := "2006-01-02"
  8784. loc, _ := time.LoadLocation("Local")
  8785. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8786. if err != nil {
  8787. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8788. return
  8789. }
  8790. recordDateTime := theTime.Unix()
  8791. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8792. if err != nil {
  8793. }
  8794. startRecordDateTime := startTime.Unix()
  8795. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8796. if err != nil {
  8797. }
  8798. endRecordDateTime := endTime.Unix()
  8799. admin := c.GetAdminUserInfo()
  8800. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  8801. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8802. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  8803. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8804. var settle_total float64
  8805. for _, item := range monthPrescriptions {
  8806. if len(item.HisPrescriptionProject) > 0 {
  8807. for _, subItem := range item.HisPrescriptionProject {
  8808. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8809. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8810. settle_total = settle_total + total
  8811. }
  8812. }
  8813. if len(item.HisDoctorAdviceInfo) > 0 {
  8814. for _, subItem := range item.HisDoctorAdviceInfo {
  8815. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8816. settle_total = settle_total + total
  8817. }
  8818. }
  8819. }
  8820. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8821. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8822. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8823. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8824. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  8825. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8826. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  8827. //获取所有科室信息
  8828. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8829. c.ServeSuccessJSON(map[string]interface{}{
  8830. "his_info": his_patient_info,
  8831. "xt_info": xt_patient_info,
  8832. "case_history": case_history,
  8833. "info": patientPrescriptionInfo,
  8834. "month_prescriptions": monthPrescriptions,
  8835. "order": order,
  8836. "doctors": doctors,
  8837. "department": department,
  8838. "count": count,
  8839. "drugStockConfig": drugStockConfig,
  8840. "last_info": lastPatientPrescriptionInfo,
  8841. "settle_total": settle_total,
  8842. })
  8843. return
  8844. }
  8845. func (c *HisApiController) GetAllOrder() {
  8846. org_id := c.GetAdminUserInfo().CurrentOrgId
  8847. orders, _ := service.GetNewHisOrderList(org_id)
  8848. c.ServeSuccessJSON(map[string]interface{}{
  8849. "order": orders,
  8850. })
  8851. return
  8852. }
  8853. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  8854. newArr = make([]*models.HisOrderInfoTwo, 0)
  8855. for i := 0; i < len(arr); i++ {
  8856. repeat := false
  8857. for j := i + 1; j < len(arr); j++ {
  8858. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  8859. repeat = true
  8860. break
  8861. }
  8862. }
  8863. if !repeat {
  8864. newArr = append(newArr, arr[i])
  8865. }
  8866. }
  8867. return
  8868. }
  8869. // 修改处方退库操作 参数传修改之前的处方数据
  8870. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  8871. if advice.ExecutionState == 1 {
  8872. //查询该病人该药品是否有库存记录
  8873. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  8874. if errcode == gorm.ErrRecordNotFound {
  8875. } else {
  8876. //退库
  8877. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8878. if advice.PrescribingNumberUnit == drug.MinUnit {
  8879. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  8880. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  8881. //退库
  8882. warehouseInfo := models.DrugWarehouseInfo{
  8883. StockMinNumber: prescribingNumber,
  8884. }
  8885. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  8886. operation_time := time.Now().Unix()
  8887. creater := advice.AdviceDoctor
  8888. ctime := time.Now().Unix()
  8889. timeStr := time.Now().Format("2006-01-02")
  8890. timeArr := strings.Split(timeStr, "-")
  8891. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  8892. total = total + 1
  8893. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8894. cancelStock := models.DrugCancelStock{
  8895. OrderNumber: orderNumber,
  8896. OperaTime: operation_time,
  8897. OrgId: advice.UserOrgId,
  8898. Creater: creater,
  8899. Ctime: ctime,
  8900. Status: 1,
  8901. ReturnTime: advice.AdviceDate,
  8902. Dealer: info.Dealer,
  8903. Manufacturer: info.Manufacturer,
  8904. Type: 1,
  8905. }
  8906. service.AddSigleDrugCancelStock(&cancelStock)
  8907. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  8908. dealer, _ := service.GetDealerById(info.Dealer)
  8909. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  8910. cancelStockInfo := models.DrugCancelStockInfo{
  8911. OrderNumber: cancelInfo.OrderNumber,
  8912. CancelStockId: cancelInfo.ID,
  8913. DrugId: info.DrugId,
  8914. Count: info.Count,
  8915. Status: 1,
  8916. Ctime: ctime,
  8917. OrgId: advice.UserOrgId,
  8918. Type: 1,
  8919. Manufacturer: manufactureName.ManufacturerName,
  8920. Dealer: dealer.DealerName,
  8921. Total: 0,
  8922. RetailPrice: info.RetailPrice,
  8923. RetailTotalPrice: info.RetailTotalPrice,
  8924. Price: info.Price,
  8925. RegisterAccount: "",
  8926. Remark: info.Remark,
  8927. BatchNumber: info.BatchNumber,
  8928. MaxUnit: info.CountUnit,
  8929. ProductDate: info.ProductDate,
  8930. ExpiryDate: info.ExpiryDate,
  8931. BatchNumberId: info.WarehouseInfoId,
  8932. }
  8933. flow := models.DrugFlow{
  8934. WarehousingId: 0,
  8935. DrugId: info.DrugId,
  8936. Number: "",
  8937. BatchNumber: info.BatchNumber,
  8938. Count: info.Count,
  8939. UserOrgId: advice.UserOrgId,
  8940. PatientId: 0,
  8941. SystemTime: ctime,
  8942. ConsumableType: 4,
  8943. IsSys: 0,
  8944. WarehousingOrder: "",
  8945. WarehouseOutId: 0,
  8946. WarehouseOutOrderNumber: "",
  8947. IsEdit: 0,
  8948. CancelStockId: cancelStock.ID,
  8949. CancelOrderNumber: cancelStock.OrderNumber,
  8950. Manufacturer: info.Manufacturer,
  8951. Dealer: info.Dealer,
  8952. Creator: advice.UserOrgId,
  8953. UpdateCreator: 0,
  8954. Status: 1,
  8955. Ctime: time.Now().Unix(),
  8956. Mtime: 0,
  8957. Price: info.Price,
  8958. WarehousingDetailId: 0,
  8959. WarehouseOutDetailId: 0,
  8960. CancelOutDetailId: 0,
  8961. ExpireDate: info.ExpiryDate,
  8962. ProductDate: info.ProductDate,
  8963. MaxUnit: info.CountUnit,
  8964. MinUnit: "",
  8965. }
  8966. service.CreatedCancelStock(cancelStockInfo)
  8967. service.CreateDrugFlowOne(flow)
  8968. } else {
  8969. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  8970. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  8971. if advice.PrescribingNumberUnit == drug.MaxUnit {
  8972. warehouseInfo := models.DrugWarehouseInfo{
  8973. StockMinNumber: prescribingNumber,
  8974. }
  8975. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  8976. }
  8977. operation_time := time.Now().Unix()
  8978. creater := advice.AdviceDoctor
  8979. ctime := time.Now().Unix()
  8980. timeStr := time.Now().Format("2006-01-02")
  8981. timeArr := strings.Split(timeStr, "-")
  8982. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  8983. total = total + 1
  8984. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8985. cancelStock := models.DrugCancelStock{
  8986. OrderNumber: orderNumber,
  8987. OperaTime: operation_time,
  8988. OrgId: advice.UserOrgId,
  8989. Creater: creater,
  8990. Ctime: ctime,
  8991. Status: 1,
  8992. ReturnTime: advice.AdviceDate,
  8993. Dealer: info.Dealer,
  8994. Manufacturer: info.Manufacturer,
  8995. Type: 1,
  8996. }
  8997. service.AddSigleDrugCancelStock(&cancelStock)
  8998. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  8999. dealer, _ := service.GetDealerById(info.Dealer)
  9000. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9001. cancelStockInfo := models.DrugCancelStockInfo{
  9002. OrderNumber: cancelInfo.OrderNumber,
  9003. CancelStockId: cancelInfo.ID,
  9004. DrugId: info.DrugId,
  9005. Count: info.Count,
  9006. Status: 1,
  9007. Ctime: ctime,
  9008. OrgId: advice.UserOrgId,
  9009. Type: 1,
  9010. Manufacturer: manufactureName.ManufacturerName,
  9011. Dealer: dealer.DealerName,
  9012. Total: 0,
  9013. RetailPrice: info.RetailPrice,
  9014. RetailTotalPrice: info.RetailTotalPrice,
  9015. Price: info.Price,
  9016. RegisterAccount: "",
  9017. Remark: info.Remark,
  9018. BatchNumber: info.BatchNumber,
  9019. MaxUnit: info.CountUnit,
  9020. ProductDate: info.ProductDate,
  9021. ExpiryDate: info.ExpiryDate,
  9022. BatchNumberId: info.WarehouseInfoId,
  9023. }
  9024. flow := models.DrugFlow{
  9025. WarehousingId: 0,
  9026. DrugId: info.DrugId,
  9027. Number: "",
  9028. BatchNumber: info.BatchNumber,
  9029. Count: info.Count,
  9030. UserOrgId: advice.UserOrgId,
  9031. PatientId: 0,
  9032. SystemTime: ctime,
  9033. ConsumableType: 4,
  9034. IsSys: 0,
  9035. WarehousingOrder: "",
  9036. WarehouseOutId: 0,
  9037. WarehouseOutOrderNumber: "",
  9038. IsEdit: 0,
  9039. CancelStockId: cancelStock.ID,
  9040. CancelOrderNumber: cancelStock.OrderNumber,
  9041. Manufacturer: info.Manufacturer,
  9042. Dealer: info.Dealer,
  9043. Creator: advice.AdviceDoctor,
  9044. UpdateCreator: 0,
  9045. Status: 1,
  9046. Ctime: time.Now().Unix(),
  9047. Mtime: 0,
  9048. Price: info.Price,
  9049. WarehousingDetailId: 0,
  9050. WarehouseOutDetailId: 0,
  9051. CancelOutDetailId: 0,
  9052. ExpireDate: info.ExpiryDate,
  9053. ProductDate: info.ProductDate,
  9054. MaxUnit: info.CountUnit,
  9055. MinUnit: "",
  9056. }
  9057. service.CreatedCancelStock(cancelStockInfo)
  9058. service.CreateDrugFlowOne(flow)
  9059. }
  9060. }
  9061. }
  9062. return err
  9063. }
  9064. func (this *HisApiController) DeleteNCDS() {
  9065. id, _ := this.GetInt64("id", 0)
  9066. if id > 0 {
  9067. service.DeletePsnNCDSRecordById(id)
  9068. this.ServeSuccessJSON(map[string]interface{}{
  9069. "msg": "删除成功",
  9070. })
  9071. } else {
  9072. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  9073. return
  9074. }
  9075. }
  9076. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  9077. id, _ := c.GetInt64("id")
  9078. advice, _ := service.GetHisDoctorAdviceInfo(id)
  9079. c.ServeSuccessJSON(map[string]interface{}{
  9080. "advice": advice,
  9081. })
  9082. return
  9083. }
  9084. func (c *HisApiController) GetHisMonthChargePatientList() {
  9085. record_date := c.GetString("record_date")
  9086. start_time := c.GetString("start_time")
  9087. end_time := c.GetString("end_time")
  9088. timeLayout := "2006-01-02"
  9089. loc, _ := time.LoadLocation("Local")
  9090. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9091. if err != nil {
  9092. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9093. return
  9094. }
  9095. if err != nil {
  9096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9097. return
  9098. }
  9099. recordDateTime := theTime.Unix()
  9100. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9101. if err != nil {
  9102. }
  9103. startRecordDateTime := startTime.Unix()
  9104. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9105. if err != nil {
  9106. }
  9107. endRecordDateTime := endTime.Unix()
  9108. adminInfo := c.GetAdminUserInfo()
  9109. var tempMonthChargePatients []*service.MonthChargePatients
  9110. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  9111. for _, item := range tempPatients {
  9112. //过滤没有处方的
  9113. if len(item.HisPrescription) == 0 {
  9114. tempMonthChargePatients = append(tempMonthChargePatients, item)
  9115. }
  9116. }
  9117. c.ServeSuccessJSON(map[string]interface{}{
  9118. "list": tempMonthChargePatients,
  9119. })
  9120. }