his_api_controller.go 391KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "github.com/shopspring/decimal"
  12. "math/rand"
  13. "reflect"
  14. "strconv"
  15. "strings"
  16. "syscall"
  17. "time"
  18. "unsafe"
  19. )
  20. type HisApiController struct {
  21. BaseAuthAPIController
  22. }
  23. func HisManagerApiRegistRouters() {
  24. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  25. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  26. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  27. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  28. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  29. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  30. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  31. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  32. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  33. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  34. beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  35. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  36. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  37. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  40. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  41. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  42. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  43. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  44. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  45. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  46. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  47. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  48. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  49. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  50. //新增附加费用
  51. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  52. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  53. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  54. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  55. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  56. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  57. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  58. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  59. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  60. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  61. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  62. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  63. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  64. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  65. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  66. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  67. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. }
  84. func (c *HisApiController) GetTestOrder() {
  85. order_id, _ := c.GetInt64("order_id")
  86. admin_user_id, _ := c.GetInt64("admin_user_id")
  87. adminUser := c.GetAdminUserInfo()
  88. order, _ := service.GetHisOrderByID(order_id)
  89. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  90. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  91. orderInfos = append(orderInfos, orderInfos_two...)
  92. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  93. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  94. var dia_config []*models.HisXtDiagnoseConfig
  95. var name string
  96. var bedCostTotal float64 = 0 //床位总费
  97. var bedCostSelfTotal float64 = 0 //床位自费
  98. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  99. var bedSelfTotal float64 = 0 //床位部分项目自费
  100. var bedInscpTotal float64 = 0 //床位部分项目自费
  101. var operationCostTotal float64 = 0 //手术费
  102. var operationCostSelfTotal float64 = 0 //手术费
  103. var operationCostPartSelfTotal float64 = 0 //手术费
  104. var operationSelfTotal float64 = 0 //床位部分项目自费
  105. var operationInscpTotal float64 = 0 //床位部分项目自费
  106. var otherCostTotal float64 = 0 //其他费用
  107. var otherCostSelfTotal float64 = 0 //其他费用
  108. var otherCostPartSelfTotal float64 = 0 //其他费用
  109. var otherSelfTotal float64 = 0 //床位部分项目自费
  110. var otherInscpTotal float64 = 0 //床位部分项目自费
  111. var materialCostTotal float64 = 0 //材料费
  112. var materialCostSelfTotal float64 = 0 //材料费
  113. var materialCostPartSelfTotal float64 = 0 //材料费
  114. var materialSelfTotal float64 = 0 //床位部分项目自费
  115. var materialInscpTotal float64 = 0 //床位部分项目自费
  116. var westernMedicineCostTotal float64 = 0 //西药费
  117. var westernMedicineCostSelfTotal float64 = 0 //西药费
  118. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  119. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  120. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  121. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  122. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  123. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  124. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  125. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  126. var checkCostTotal float64 = 0 //检查费
  127. var checkCostSelfTotal float64 = 0 //检查费
  128. var checkCostPartSelfTotal float64 = 0 //检查费
  129. var checkSelfTotal float64 = 0 //床位部分项目自费
  130. var checkInscpTotal float64 = 0 //床位部分项目自费
  131. var laboratoryCostTotal float64 = 0 //化验费
  132. var laboratoryCostSelfTotal float64 = 0 //化验费
  133. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  134. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  135. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  136. var treatCostTotal float64 = 0 //治疗费用
  137. var treatCostSelfTotal float64 = 0 //治疗费用
  138. var treatCostPartSelfTotal float64 = 0 //治疗费用
  139. var treatSelfTotal float64 = 0 //床位部分项目自费
  140. var treatInscpTotal float64 = 0 //床位部分项目自费
  141. decimal.DivisionPrecision = 2
  142. for _, item := range orderInfos {
  143. if item.MedChrgitmType == "01" { //床位费
  144. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  145. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  146. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  147. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  148. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  149. }
  150. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  151. if item.MedChrgitmType == "03" { //检查费
  152. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  153. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  154. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  155. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  156. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  157. }
  158. } else {
  159. if item.MedChrgitmType == "03" { //检查费
  160. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  161. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  162. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  163. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  164. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  165. }
  166. }
  167. if item.MedChrgitmType == "04" { //化验费
  168. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  169. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  170. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  171. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  172. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  173. }
  174. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  175. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  176. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  177. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  178. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  179. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  180. }
  181. if item.MedChrgitmType == "06" { //手术费
  182. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  183. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  184. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  185. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  186. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  187. }
  188. if item.MedChrgitmType == "08" { //材料费
  189. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  190. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  191. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  192. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  193. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  194. }
  195. if item.MedChrgitmType == "09" { //西药费
  196. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  197. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  198. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  199. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  200. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  201. }
  202. if item.MedChrgitmType == "11" { //中成费
  203. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  204. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  205. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  206. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  207. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  208. }
  209. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  210. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  211. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  212. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  213. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  214. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  215. }
  216. }
  217. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  218. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  219. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  220. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  221. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  222. var doctor_name string
  223. if roles.ID == 0 {
  224. doctor_name = "管理员"
  225. } else {
  226. doctor_name = roles.UserName
  227. }
  228. yiliao_leibie := ""
  229. switch order.MedType {
  230. case "11":
  231. yiliao_leibie = "普通门诊"
  232. break
  233. case "12":
  234. yiliao_leibie = "门诊挂号"
  235. break
  236. case "13":
  237. yiliao_leibie = "急诊"
  238. break
  239. case "14":
  240. yiliao_leibie = "门诊特殊病"
  241. break
  242. case "15":
  243. yiliao_leibie = "门诊统筹"
  244. break
  245. case "16":
  246. yiliao_leibie = "门诊慢性病"
  247. break
  248. case "21":
  249. yiliao_leibie = "普通住院"
  250. break
  251. }
  252. c.ServeSuccessJSON(map[string]interface{}{
  253. "diagnosis": name,
  254. "order_infos": orderInfos,
  255. "number": order.MdtrtId,
  256. "date": order.SettleAccountsDate,
  257. "charge_admin": charge_admin,
  258. "printor_admin": printor_admin,
  259. "info": order,
  260. "order": order,
  261. "bedCostTotal": bedCostTotal,
  262. "bedCostSelfTotal": bedCostSelfTotal,
  263. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  264. "bedSelfTotal": bedSelfTotal,
  265. "bedInscpTotal": bedInscpTotal,
  266. "operationCostTotal": operationCostTotal,
  267. "operationCostSelfTotal": operationCostSelfTotal,
  268. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  269. "operationSelfTotal": operationSelfTotal,
  270. "operationInscpTotal": operationInscpTotal,
  271. "otherCostTotal": otherCostTotal,
  272. "otherCostSelfTotal": otherCostSelfTotal,
  273. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  274. "otherSelfTotal": otherSelfTotal,
  275. "otherInscpTotal": otherInscpTotal,
  276. "materialCostTotal": materialCostTotal,
  277. "materialCostSelfTotal": materialCostSelfTotal,
  278. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  279. "materialSelfTotal": materialSelfTotal,
  280. "materialInscpTotal": materialInscpTotal,
  281. "westernMedicineCostTotal": westernMedicineCostTotal,
  282. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  283. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  284. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  285. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  286. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  287. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  288. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  289. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  290. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  291. "checkCostTotal": checkCostTotal,
  292. "checkCostSelfTotal": checkCostSelfTotal,
  293. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  294. "checkSelfTotal": checkSelfTotal,
  295. "checkInscpTotal": checkInscpTotal,
  296. "laboratoryCostTotal": laboratoryCostTotal,
  297. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  298. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  299. "laboratorySelfTotal": laboratorySelfTotal,
  300. "laboratoryInscpTotal": laboratoryInscpTotal,
  301. "treatCostTotal": treatCostTotal,
  302. "treatCostSelfTotal": treatCostSelfTotal,
  303. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  304. "treatSelfTotal": treatSelfTotal,
  305. "treatInscpTotal": treatInscpTotal,
  306. "doctor_info": doctor_info,
  307. "doctor_name": doctor_name,
  308. "health_card_no": order.PsnNo,
  309. "yiliao_leibie": yiliao_leibie,
  310. "patient": patient,
  311. "org_name": miConfig.OrgName,
  312. "org_code": miConfig.Code,
  313. "order_number": order.Number,
  314. "his_hospital": his_hospital,
  315. "dia_config": dia_config,
  316. })
  317. }
  318. func (c *PublicApiController) GetBaiLinExportData() {
  319. data := service.GetBaiLinOrderData()
  320. fmt.Println(len(data))
  321. var new_data []*models.NewCustomHisOrder
  322. for _, item := range data {
  323. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  324. new_data = append(new_data, item)
  325. }
  326. }
  327. fmt.Println(len(new_data))
  328. c.ServeSuccessJSON(map[string]interface{}{
  329. "list": new_data,
  330. })
  331. }
  332. func (c *HisApiController) GetHisUnChargePatientList() {
  333. record_date := c.GetString("record_date")
  334. timeLayout := "2006-01-02"
  335. loc, _ := time.LoadLocation("Local")
  336. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  337. if err != nil {
  338. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  339. return
  340. }
  341. recordDateTime := theTime.Unix()
  342. adminInfo := c.GetAdminUserInfo()
  343. var tempPatients []*service.NewTempPatients
  344. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  345. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  346. var patients []*service.NewTempPatients
  347. var patients_two []*service.NewTempPatients
  348. for _, item := range tempPatients {
  349. //过滤掉没挂号的和没开处方的
  350. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  351. patients = append(patients, item)
  352. }
  353. //过滤掉没挂号的
  354. if len(item.HisPatient) > 0 {
  355. patients_two = append(patients_two, item)
  356. }
  357. }
  358. c.ServeSuccessJSON(map[string]interface{}{
  359. "list": patients,
  360. "list_two": patients_two,
  361. })
  362. }
  363. func (c *HisApiController) GetPrivateExpensesOrder() {
  364. //id, _ := c.GetInt64("id")
  365. //record_time := c.GetString("record_time")
  366. order_id, _ := c.GetInt64("order_id")
  367. admin_user_id, _ := c.GetInt64("admin_user_id")
  368. //timeLayout := "2006-01-02"
  369. //loc, _ := time.LoadLocation("Local")
  370. //
  371. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  372. //if err != nil {
  373. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  374. // return
  375. //}
  376. //recordDateTime := theTime.Unix()
  377. adminUser := c.GetAdminUserInfo()
  378. order, _ := service.GetHisOrderByID(order_id)
  379. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  380. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  381. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  382. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  383. //var config []*models.HisXtDiagnoseConfig
  384. var name string
  385. if order.PType == 1 {
  386. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  387. for _, item := range diagnosis_ids {
  388. id, _ := strconv.ParseInt(item, 10, 64)
  389. diagnosisConfig, _ := service.FindDiagnoseById(id)
  390. if len(name) == 0 {
  391. name = diagnosisConfig.ClassName
  392. } else {
  393. name = name + "," + diagnosisConfig.ClassName
  394. }
  395. }
  396. } else {
  397. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  398. for _, item := range diagnosis_ids {
  399. id, _ := strconv.ParseInt(item, 10, 64)
  400. diagnosisConfig, _ := service.FindDiagnoseById(id)
  401. if len(name) == 0 {
  402. name = diagnosisConfig.ClassName
  403. } else {
  404. name = name + "," + diagnosisConfig.ClassName
  405. }
  406. }
  407. }
  408. var bedCostTotal float64 = 0 //床位总费
  409. //var bedCostSelfTotal float64 = 0 //床位自费
  410. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  411. var operationCostTotal float64 = 0 //手术费
  412. //var operationCostSelfTotal float64 = 0 //手术费
  413. var operationCostPartSelfTotal float64 = 0 //手术费
  414. var otherCostTotal float64 = 0 //其他费用
  415. //var otherCostSelfTotal float64 = 0 //其他费用
  416. var otherCostPartSelfTotal float64 = 0 //其他费用
  417. var materialCostTotal float64 = 0 //材料费
  418. //var materialCostSelfTotal float64 = 0 //材料费
  419. var materialCostPartSelfTotal float64 = 0 //材料费
  420. var westernMedicineCostTotal float64 = 0 //西药费
  421. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  422. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  423. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  424. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  425. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  426. var checkCostTotal float64 = 0 //检查费
  427. //var checkCostSelfTotal float64 = 0 //检查费
  428. var checkCostPartSelfTotal float64 = 0 //检查费
  429. var laboratoryCostTotal float64 = 0 //化验费
  430. //var laboratoryCostSelfTotal float64 = 0 //化验费
  431. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  432. var treatCostTotal float64 = 0 //治疗费用
  433. //var treatCostSelfTotal float64 = 0 //治疗费用
  434. var treatCostPartSelfTotal float64 = 0 //治疗费用
  435. var zhenChaCostTotal float64 = 0 //其他费用
  436. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  437. decimal.DivisionPrecision = 2
  438. for _, item := range orderInfos {
  439. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  440. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  441. item.MedChrgitmType = "09"
  442. }
  443. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  444. if item.HisPrescriptionProject.Type == 2 {
  445. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  446. fmt.Println("CostClassify")
  447. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  448. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  449. case 0:
  450. item.MedChrgitmType = "0"
  451. break
  452. case 1:
  453. item.MedChrgitmType = "14"
  454. break
  455. case 2:
  456. item.MedChrgitmType = "05"
  457. break
  458. case 3:
  459. item.MedChrgitmType = "03"
  460. break
  461. case 4:
  462. item.MedChrgitmType = "03"
  463. break
  464. case 5:
  465. item.MedChrgitmType = "08"
  466. break
  467. case 6:
  468. item.MedChrgitmType = "14"
  469. break
  470. case 7:
  471. item.MedChrgitmType = "14"
  472. break
  473. case 8:
  474. item.MedChrgitmType = "03"
  475. break
  476. case 9:
  477. item.MedChrgitmType = "14"
  478. break
  479. case 10:
  480. item.MedChrgitmType = "14"
  481. break
  482. case 11:
  483. item.MedChrgitmType = "06"
  484. break
  485. case 12:
  486. item.MedChrgitmType = "12"
  487. break
  488. case 13:
  489. item.MedChrgitmType = "01"
  490. break
  491. case 14:
  492. item.MedChrgitmType = "04"
  493. break
  494. case 15:
  495. item.MedChrgitmType = "14"
  496. break
  497. }
  498. } else {
  499. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  500. case 1:
  501. item.MedChrgitmType = "14"
  502. break
  503. case 2:
  504. item.MedChrgitmType = "05"
  505. break
  506. case 3:
  507. item.MedChrgitmType = "04"
  508. break
  509. case 4:
  510. item.MedChrgitmType = "14"
  511. break
  512. case 5:
  513. item.MedChrgitmType = "08"
  514. break
  515. case 6:
  516. item.MedChrgitmType = "14"
  517. break
  518. case 7:
  519. item.MedChrgitmType = "14"
  520. break
  521. case 8:
  522. item.MedChrgitmType = "03"
  523. break
  524. case 9:
  525. item.MedChrgitmType = "14"
  526. break
  527. }
  528. }
  529. } else if item.HisPrescriptionProject.Type == 3 {
  530. item.MedChrgitmType = "08"
  531. }
  532. }
  533. }
  534. order.PsnCashPay = order.MedfeeSumamt
  535. for _, item := range orderInfos {
  536. if item.MedChrgitmType == "01" { //床位费
  537. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  538. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  539. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  540. }
  541. if item.MedChrgitmType == "02" { //诊察费
  542. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  543. //zhenChaCostSelfTotal = zhenChaCostTotal
  544. }
  545. if item.MedChrgitmType == "03" { //检查费
  546. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  547. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  548. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  549. }
  550. if item.MedChrgitmType == "02" { //检查费
  551. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  552. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  553. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  554. }
  555. if item.MedChrgitmType == "04" { //化验费
  556. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  557. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  558. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  559. }
  560. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  561. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  562. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  563. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  564. }
  565. if item.MedChrgitmType == "06" { //手术费
  566. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  567. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  568. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  569. }
  570. if item.MedChrgitmType == "08" { //材料费
  571. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  572. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  573. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  574. }
  575. if item.MedChrgitmType == "09" { //西药费
  576. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  577. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  578. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  579. }
  580. if item.MedChrgitmType == "11" { //中成费
  581. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  582. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  583. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  584. }
  585. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  586. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  587. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  588. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  589. }
  590. }
  591. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  592. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  593. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  594. patient, _ := service.GetPatientByID(order.UserOrgId, order.PatientId)
  595. c.ServeSuccessJSON(map[string]interface{}{
  596. "patient": patient,
  597. "order_infos": orderInfos,
  598. "diagnosis": name,
  599. "bedCostTotal": bedCostTotal,
  600. "bedCostSelfTotal": bedCostTotal,
  601. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  602. "operationCostTotal": operationCostTotal,
  603. "operationCostSelfTotal": operationCostTotal,
  604. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  605. "otherCostTotal": otherCostTotal,
  606. "otherCostSelfTotal": otherCostTotal,
  607. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  608. "materialCostTotal": materialCostTotal,
  609. "materialCostSelfTotal": materialCostTotal,
  610. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  611. "westernMedicineCostTotal": westernMedicineCostTotal,
  612. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  613. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  614. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  615. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  616. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  617. "checkCostTotal": checkCostTotal,
  618. "checkCostSelfTotal": checkCostTotal,
  619. "zhenChaCostTotal": zhenChaCostTotal,
  620. "zhenChaCostSelfTotal": zhenChaCostTotal,
  621. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  622. "laboratoryCostTotal": laboratoryCostTotal,
  623. "laboratoryCostSelfTotal": laboratoryCostTotal,
  624. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  625. "treatCostTotal": treatCostTotal,
  626. "treatCostSelfTotal": treatCostTotal,
  627. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  628. "charge_admin": charge_admin,
  629. "printor_admin": printor_admin,
  630. "org_name": org.OrgName,
  631. "org_code": miConfig.Code,
  632. "name": patient.Name,
  633. "number": order.MdtrtId,
  634. "date": order.SettleAccountsDate,
  635. "info": order,
  636. "his_hospital": his_hospital,
  637. "his": his,
  638. })
  639. }
  640. func (c *HisApiController) RefudDetail() {
  641. order_id, _ := c.GetInt64("order_id")
  642. order, _ := service.GetHisOrderByID(order_id)
  643. adminUser := c.GetAdminUserInfo()
  644. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  645. c.ServeSuccessJSON(map[string]interface{}{
  646. "msg": "撤销成功",
  647. })
  648. }
  649. func (c *HisApiController) Sscard() {
  650. //r := CardInit()
  651. //if r == 0 {
  652. // GetBaseInfo()
  653. //}
  654. //c.ServeSuccessJSON(map[string]interface{}{
  655. // "list": "11",
  656. //})
  657. }
  658. func GetBaseInfo() error {
  659. //handle := syscall.MustLoadDLL("SSCard.dll")
  660. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  661. //
  662. //str := make([]byte, 256)
  663. //str1 := make([]byte, 256)
  664. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  665. //if ferr != nil {
  666. // fmt.Println("ReadCardBas 报错", ferr.Error())
  667. // return ferr
  668. //}
  669. //
  670. //fmt.Println(string(str))
  671. //
  672. //fmt.Println(r)
  673. return nil
  674. }
  675. func CardInit() int {
  676. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  677. //add := DllTestDef.MustFindProc("Init")
  678. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  679. //if err != nil {
  680. // fmt.Println("SSCard的运算结果为:", ret)
  681. //}
  682. //result := int(ret)
  683. return 0
  684. }
  685. func IntPtr(n int) uintptr {
  686. return uintptr(n)
  687. }
  688. func StrPtr(s string) uintptr {
  689. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  690. }
  691. func (c *HisApiController) GetHisPatientList() {
  692. //types, _ := c.GetInt64("type", 0)
  693. record_date := c.GetString("record_date")
  694. sch_type, _ := c.GetInt64("sch_type")
  695. timeLayout := "2006-01-02"
  696. loc, _ := time.LoadLocation("Local")
  697. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  698. if err != nil {
  699. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  700. return
  701. }
  702. recordDateTime := theTime.Unix()
  703. adminInfo := c.GetAdminUserInfo()
  704. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  705. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  706. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  707. //获取当前用户的信息
  708. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  709. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  710. //获取所有科室信息
  711. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  712. c.ServeSuccessJSON(map[string]interface{}{
  713. "list": patients,
  714. "list_two": patients_two,
  715. "info": adminUserInfo,
  716. "doctors": doctors,
  717. "department": department,
  718. })
  719. }
  720. type CustomTemplate struct {
  721. ID int64 `gorm:"column:id" json:"id" form:"id"`
  722. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  723. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  724. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  725. Status int64 `gorm:"column:status" json:"status" form:"status"`
  726. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  727. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  728. Type int64 `gorm:"column:type" json:"type" form:"type"`
  729. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  730. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  731. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  732. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  733. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  734. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  735. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  736. }
  737. func (c *HisApiController) GetHisPatientInfo() {
  738. patient_id, _ := c.GetInt64("patient_id")
  739. his_patient_id, _ := c.GetInt64("his_patient_id")
  740. record_date := c.GetString("record_date")
  741. number := c.GetString("number")
  742. //start_time := c.GetString("start_time")
  743. //end_time := c.GetString("end_time")
  744. p_type, _ := c.GetInt64("p_type")
  745. timeLayout := "2006-01-02"
  746. loc, _ := time.LoadLocation("Local")
  747. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  748. if err != nil {
  749. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  750. return
  751. }
  752. recordDateTime := theTime.Unix()
  753. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  754. //if err != nil {
  755. //
  756. //}
  757. //startRecordDateTime := startTime.Unix()
  758. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  759. //if err != nil {
  760. //
  761. //}
  762. //endRecordDateTime := endTime.Unix()
  763. admin := c.GetAdminUserInfo()
  764. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  765. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  766. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  767. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  768. var prescriptions []*models.HisPrescription
  769. var last_prescriptions []*models.HisPrescription
  770. var sch_prescriptions []CustomTemplate
  771. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  772. if p_type == 1 { //住院
  773. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  774. for _, item := range prescriptions {
  775. for _, subItem := range item.HisDoctorAdviceInfo {
  776. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  777. if info.RetailPrice > 0 {
  778. subItem.Drug.MinPrice = info.RetailPrice
  779. }
  780. }
  781. }
  782. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  783. } else { //门诊
  784. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  785. for _, item := range prescriptions {
  786. for _, subItem := range item.HisDoctorAdviceInfo {
  787. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  788. if info.RetailPrice > 0 {
  789. subItem.Drug.MinPrice = info.RetailPrice
  790. }
  791. }
  792. }
  793. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  794. }
  795. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  796. if sch.ID > 0 {
  797. var week string
  798. t := time.Now()
  799. switch t.Weekday().String() {
  800. case "Monday":
  801. week = "周一"
  802. break
  803. case "Tuesday":
  804. week = "周二"
  805. break
  806. case "Wednesday":
  807. week = "周三"
  808. break
  809. case "Thursday":
  810. week = "周四"
  811. break
  812. case "Friday":
  813. week = "周五"
  814. break
  815. case "Saturday":
  816. week = "周六"
  817. break
  818. case "Sunday":
  819. week = "周日"
  820. break
  821. }
  822. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  823. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  824. //根据推送频率组装新的数组
  825. for _, item := range temp_sch_prescriptions {
  826. var cus CustomTemplate
  827. cus.ID = item.ID
  828. cus.UserOrgId = item.UserOrgId
  829. cus.PatientId = item.PatientId
  830. cus.MedType = item.MedType
  831. cus.RecordDate = item.RecordDate
  832. cus.Type = item.Type
  833. cus.PType = item.PType
  834. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  835. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  836. if subItem.FrequencyType == 1 { //每次必推
  837. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  838. }
  839. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  840. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  841. }
  842. if subItem.FrequencyType == 2 { //按照天数频率
  843. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  844. now := p.Unix()
  845. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  846. dayStr2 := "-" + dayStr
  847. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  848. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  849. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  850. if len(advices) == 0 {
  851. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  852. }
  853. }
  854. }
  855. }
  856. for _, subItem := range item.HisPrescriptionProjectTemplate {
  857. if subItem.Type == 2 {
  858. if subItem.XtHisProject.MedicalStatus != 1 {
  859. if subItem.FrequencyType == 1 {
  860. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  861. }
  862. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  863. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  864. }
  865. if subItem.FrequencyType == 2 {
  866. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  867. now := p.Unix()
  868. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  869. dayStr2 := "-" + dayStr
  870. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  871. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  872. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  873. if len(projects) == 0 {
  874. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  875. }
  876. }
  877. }
  878. } else if subItem.Type == 3 {
  879. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  880. if subItem.FrequencyType == 1 {
  881. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  882. }
  883. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  884. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  885. }
  886. if subItem.FrequencyType == 2 {
  887. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  888. now := p.Unix()
  889. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  890. dayStr2 := "-" + dayStr
  891. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  892. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  893. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  894. if len(projects) == 0 {
  895. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  896. }
  897. }
  898. }
  899. }
  900. }
  901. sch_prescriptions = append(sch_prescriptions, cus)
  902. }
  903. for _, item := range sch_prescriptions {
  904. if len(item.HisPrescriptionProjectTemplate) == 0 {
  905. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  906. }
  907. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  908. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  909. }
  910. }
  911. }
  912. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  913. if config.ID > 0 && config.IsOpen == 1 {
  914. for _, item := range sch_prescriptions {
  915. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  916. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  917. if info.RetailPrice > 0 {
  918. subItem.Drug.MinPrice = info.RetailPrice
  919. }
  920. }
  921. }
  922. }
  923. if config.ID > 0 && config.IsOpen == 1 {
  924. for _, item := range sch_prescriptions {
  925. for _, subItem := range item.HisPrescriptionProjectTemplate {
  926. if subItem.Type == 3 {
  927. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  928. if info.Price > 0 {
  929. subItem.GoodInfo.PackingPrice = info.Price
  930. }
  931. }
  932. }
  933. }
  934. }
  935. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  936. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  937. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  938. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  939. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  940. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  941. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  942. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  943. //获取所有科室信息
  944. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  945. c.ServeSuccessJSON(map[string]interface{}{
  946. "his_info": his_patient_info,
  947. "xt_info": xt_patient_info,
  948. "prescription": prescriptions,
  949. "case_history": case_history,
  950. "info": patientPrescriptionInfo,
  951. //"month_prescriptions": monthPrescriptions,
  952. "order": order,
  953. "doctors": doctors,
  954. "department": department,
  955. "sch_prescriptions": sch_prescriptions,
  956. "last_prescriptions": last_prescriptions,
  957. "schedule": sch,
  958. "count": count,
  959. "drugStockConfig": drugStockConfig,
  960. "last_info": lastPatientPrescriptionInfo,
  961. })
  962. return
  963. }
  964. func (c *HisApiController) GetHisPrescriptionConfig() {
  965. adminInfo := c.GetAdminUserInfo()
  966. //获取医嘱模版
  967. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  968. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  969. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  970. //获取所有基础药
  971. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  972. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  973. if config.ID > 0 && config.IsOpen == 1 {
  974. for _, item := range drugs {
  975. var index = 0
  976. for _, subItem := range item.OtherDrugWarehouseInfo {
  977. if index == 0 {
  978. index = index + 1
  979. if subItem.RetailPrice > 0 {
  980. item.MinPrice = subItem.RetailPrice
  981. }
  982. }
  983. }
  984. }
  985. }
  986. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  987. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  988. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  989. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  990. //获取所有科室信息
  991. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  992. //获取诊断信息
  993. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  994. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  995. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  996. //获取是否开启保存耗材出库的开关
  997. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  998. c.ServeSuccessJSON(map[string]interface{}{
  999. "drugs": drugs,
  1000. "advices_template": advices,
  1001. "drugways": drugways,
  1002. "efs": efs,
  1003. "doctors": doctors,
  1004. "department": department,
  1005. "sick": sick,
  1006. "additions": additions,
  1007. "diagnose": diagnose,
  1008. "manufacturers": manufacturers,
  1009. "goodOutOpen": goodOutOpen,
  1010. })
  1011. }
  1012. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1013. //获取所有基础药
  1014. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1015. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1016. if config.ID > 0 && config.IsOpen == 1 {
  1017. for _, item := range drugs {
  1018. var index = 0
  1019. for _, subItem := range item.OtherDrugWarehouseInfo {
  1020. if index == 0 {
  1021. index = index + 1
  1022. if subItem.RetailPrice > 0 {
  1023. item.MinPrice = subItem.RetailPrice
  1024. }
  1025. }
  1026. }
  1027. }
  1028. }
  1029. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1030. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1031. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1032. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1033. //获取所有科室信息
  1034. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1035. //获取诊断信息
  1036. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1037. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1038. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1039. //获取是否开启保存耗材出库的开关
  1040. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1041. c.ServeSuccessJSON(map[string]interface{}{
  1042. "drugs": drugs,
  1043. "advices_template": advices,
  1044. "drugways": drugways,
  1045. "efs": efs,
  1046. "doctors": doctors,
  1047. "department": department,
  1048. "sick": sick,
  1049. "additions": additions,
  1050. "diagnose": diagnose,
  1051. "manufacturers": manufacturers,
  1052. "goodOutOpen": goodOutOpen,
  1053. })
  1054. }
  1055. }
  1056. func (c *HisApiController) CreateHisPrescription() {
  1057. record_date := c.GetString("record_date")
  1058. patient_id, _ := c.GetInt64("patient_id")
  1059. reg_type, _ := c.GetInt64("reg_type")
  1060. diagnose := c.GetString("diagnose")
  1061. sick_type, _ := c.GetInt64("sick_type")
  1062. sick_history := c.GetString("sick_history")
  1063. doctor_id, _ := c.GetInt64("doctor", 0)
  1064. department, _ := c.GetInt64("department", 0)
  1065. his_patient_id, _ := c.GetInt64("his_patient_id")
  1066. p_type, _ := c.GetInt64("p_type")
  1067. dataBody := make(map[string]interface{}, 0)
  1068. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1069. if err != nil {
  1070. utils.ErrorLog(err.Error())
  1071. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1072. return
  1073. }
  1074. timeLayout := "2006-01-02"
  1075. loc, _ := time.LoadLocation("Local")
  1076. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1077. if err != nil {
  1078. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1079. return
  1080. }
  1081. adminInfo := c.GetAdminUserInfo()
  1082. recordDateTime := theTime.Unix()
  1083. //查询默认出库仓库库存
  1084. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1085. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1086. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1087. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1088. if len(lists) == 1 {
  1089. his_patient_id = lists[0].ID
  1090. }
  1091. }
  1092. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1093. //保存处方出库
  1094. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1095. //自动出库
  1096. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1097. //耗材保存处方出库
  1098. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1099. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1100. //已发药和已收费限制逻辑
  1101. isMidicine := false
  1102. isCharge := false
  1103. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1104. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1105. if len(prescriptions) > 0 {
  1106. for _, item := range prescriptions {
  1107. items := item.(map[string]interface{})
  1108. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1109. utils.ErrorLog("id")
  1110. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1111. return
  1112. }
  1113. id := int64(items["id"].(float64))
  1114. if id > 0 {
  1115. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1116. if err != nil {
  1117. if new_prescription.OrderStatus == 4 {
  1118. isCharge = true
  1119. }
  1120. }
  1121. }
  1122. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1123. advices := items["advices"].([]interface{})
  1124. if len(advices) > 0 {
  1125. for _, advice := range advices {
  1126. var adviceId int64
  1127. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1128. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1129. }
  1130. if adviceId > 0 {
  1131. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1132. if err == nil {
  1133. if his_advice_info.IsMedicine == 1 {
  1134. isMidicine = true
  1135. }
  1136. }
  1137. }
  1138. }
  1139. }
  1140. }
  1141. }
  1142. }
  1143. }
  1144. if isMidicine == true {
  1145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1146. return
  1147. }
  1148. if isCharge == true {
  1149. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1150. return
  1151. }
  1152. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1153. fmt.Println("0230032032032032032032023---------------", pharmacyConfig.IsOpen)
  1154. //药品发药出库
  1155. if pharmacyConfig.IsOpen == 1 {
  1156. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1157. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1158. if len(prescriptions) > 0 {
  1159. for _, item := range prescriptions {
  1160. items := item.(map[string]interface{})
  1161. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1162. advices := items["advices"].([]interface{})
  1163. if len(advices) > 0 {
  1164. for _, advice := range advices {
  1165. var drug_id int64
  1166. var prescribing_number float64
  1167. var prescribingNumberUnit string
  1168. var adviceId int64
  1169. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1170. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1171. }
  1172. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1173. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1174. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1175. }
  1176. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1177. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1178. }
  1179. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1180. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1181. }
  1182. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1183. if drug.ID == 0 {
  1184. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1185. return
  1186. }
  1187. //查询药品的所有库存
  1188. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1189. var total_count int64
  1190. for _, it := range list {
  1191. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1192. }
  1193. totals := strconv.FormatInt(total_count, 10)
  1194. //查询该药品是否存在开药记录
  1195. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1196. //新增处方
  1197. if advicelist.ID == 0 {
  1198. all_count, _ := strconv.ParseFloat(totals, 64)
  1199. if prescribingNumberUnit == drug.MinUnit {
  1200. if drug.IsUse != 1 {
  1201. if prescribing_number > all_count {
  1202. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1203. return
  1204. }
  1205. }
  1206. }
  1207. if prescribingNumberUnit == drug.MaxUnit {
  1208. num := prescribing_number * float64(drug.MinNumber)
  1209. if drug.IsUse != 1 {
  1210. if num > all_count {
  1211. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1212. return
  1213. }
  1214. }
  1215. }
  1216. }
  1217. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1218. if drugOutConfig.IsOpen != 1 {
  1219. //修改处方
  1220. for _, advice := range advices {
  1221. var drug_id int64
  1222. var prescribing_number float64
  1223. var prescribingNumberUnit string
  1224. var prescribingNumber string
  1225. var adviceId int64
  1226. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1227. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1228. }
  1229. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1230. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1231. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1232. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1233. }
  1234. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1235. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1236. }
  1237. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1238. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1239. }
  1240. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1241. if drug.ID == 0 {
  1242. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1243. return
  1244. }
  1245. //查询药品的所有库存
  1246. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1247. var total_count int64
  1248. for _, it := range list {
  1249. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1250. }
  1251. totals := strconv.FormatInt(total_count, 10)
  1252. //查询该药品是否存在开药记录
  1253. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1254. //新增处方
  1255. if advicelist.ID == 0 {
  1256. all_count, _ := strconv.ParseFloat(totals, 64)
  1257. if prescribingNumberUnit == drug.MinUnit {
  1258. if drug.IsUse != 1 {
  1259. if prescribing_number > all_count {
  1260. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1261. return
  1262. }
  1263. }
  1264. } else {
  1265. if prescribingNumberUnit == drug.MaxUnit {
  1266. num := prescribing_number * float64(drug.MinNumber)
  1267. if drug.IsUse != 1 {
  1268. if num > all_count {
  1269. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1270. return
  1271. }
  1272. }
  1273. }
  1274. }
  1275. }
  1276. //修改处方
  1277. if advicelist.ID > 0 {
  1278. var device_number int64
  1279. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1280. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1281. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1282. device_number = prescribingNumberInt * drug.MinNumber
  1283. }
  1284. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1285. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1286. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1287. device_number = prescribingNumberInt
  1288. }
  1289. var number_count int64
  1290. if prescribingNumberUnit == drug.MaxUnit {
  1291. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1292. number_count = prescribingNumberInt * drug.MinNumber
  1293. }
  1294. if prescribingNumberUnit == drug.MinUnit {
  1295. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1296. number_count = prescribingNumberInt
  1297. }
  1298. //如果修改的数量大于之前修改的数量
  1299. if (number_count - device_number) > 0 {
  1300. //如果修改的差数量 大于库存数量
  1301. if drug.IsUse != 1 {
  1302. if (number_count - device_number) > total_count {
  1303. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1304. return
  1305. }
  1306. }
  1307. }
  1308. }
  1309. }
  1310. }
  1311. }
  1312. }
  1313. }
  1314. }
  1315. }
  1316. }
  1317. }
  1318. //已发药和已收费限制逻辑
  1319. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1320. //校验库存总量
  1321. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1322. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1323. if len(prescriptions) > 0 {
  1324. for _, item := range prescriptions {
  1325. items := item.(map[string]interface{})
  1326. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1327. advices := items["advices"].([]interface{})
  1328. if len(advices) > 0 {
  1329. for _, advice := range advices {
  1330. var drug_id int64
  1331. var prescribing_number float64
  1332. var prescribingNumberUnit string
  1333. var adviceId int64
  1334. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1335. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1336. }
  1337. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1338. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1339. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1340. }
  1341. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1342. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1343. }
  1344. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1345. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1346. }
  1347. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1348. if drug.ID == 0 {
  1349. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1350. return
  1351. }
  1352. //查询药品的所有库存
  1353. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1354. var total_count int64
  1355. for _, it := range list {
  1356. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1357. }
  1358. totals := strconv.FormatInt(total_count, 10)
  1359. //查询该药品是否存在开药记录
  1360. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1361. //查询最新批次库存
  1362. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1363. var batch_number_count int64
  1364. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1365. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1366. //新增处方
  1367. if advicelist.ID == 0 {
  1368. all_count, _ := strconv.ParseFloat(totals, 64)
  1369. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1370. if prescribingNumberUnit == drug.MinUnit {
  1371. if drug.IsUse != 1 {
  1372. if prescribing_number > all_count {
  1373. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1374. return
  1375. }
  1376. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1377. if prescribing_number > batch_number_all_count {
  1378. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1379. return
  1380. }
  1381. }
  1382. }
  1383. }
  1384. if prescribingNumberUnit == drug.MaxUnit {
  1385. num := prescribing_number * float64(drug.MinNumber)
  1386. if drug.IsUse != 1 {
  1387. if num > all_count {
  1388. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1389. return
  1390. }
  1391. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1392. if num > batch_number_all_count {
  1393. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1394. return
  1395. }
  1396. }
  1397. }
  1398. }
  1399. }
  1400. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1401. if drugOutConfig.IsOpen != 1 {
  1402. //修改处方
  1403. for _, advice := range advices {
  1404. var drug_id int64
  1405. var prescribing_number float64
  1406. var prescribingNumberUnit string
  1407. var prescribingNumber string
  1408. var adviceId int64
  1409. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1410. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1411. }
  1412. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1413. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1414. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1415. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1416. }
  1417. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1418. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1419. }
  1420. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1421. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1422. }
  1423. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1424. if drug.ID == 0 {
  1425. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1426. return
  1427. }
  1428. //查询药品的所有库存
  1429. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1430. var total_count int64
  1431. for _, it := range list {
  1432. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1433. }
  1434. totals := strconv.FormatInt(total_count, 10)
  1435. //查询该药品是否存在开药记录
  1436. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1437. //新增处方
  1438. if advicelist.ID == 0 {
  1439. //查询最新批次库存
  1440. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1441. var batch_number_count int64
  1442. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1443. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1444. all_count, _ := strconv.ParseFloat(totals, 64)
  1445. if prescribingNumberUnit == drug.MinUnit {
  1446. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1447. if drug.IsUse != 1 {
  1448. if prescribing_number > all_count {
  1449. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1450. return
  1451. }
  1452. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1453. if prescribing_number > batch_number_all_count {
  1454. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1455. return
  1456. }
  1457. }
  1458. }
  1459. } else {
  1460. if prescribingNumberUnit == drug.MaxUnit {
  1461. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1462. num := prescribing_number * float64(drug.MinNumber)
  1463. if drug.IsUse != 1 {
  1464. if num > all_count {
  1465. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1466. return
  1467. }
  1468. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1469. if prescribing_number > batch_number_all_count {
  1470. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1471. return
  1472. }
  1473. }
  1474. }
  1475. }
  1476. }
  1477. }
  1478. //修改处方
  1479. if advicelist.ID > 0 {
  1480. //查询最新批次库存
  1481. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1482. var batch_number_count int64
  1483. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1484. var device_number int64
  1485. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1486. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1487. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1488. device_number = prescribingNumberInt * drug.MinNumber
  1489. }
  1490. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1491. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1492. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1493. device_number = prescribingNumberInt
  1494. }
  1495. var number_count int64
  1496. if prescribingNumberUnit == drug.MaxUnit {
  1497. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1498. number_count = prescribingNumberInt * drug.MinNumber
  1499. }
  1500. if prescribingNumberUnit == drug.MinUnit {
  1501. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1502. number_count = prescribingNumberInt
  1503. }
  1504. //如果修改的数量大于之前修改的数量
  1505. if (number_count - device_number) > 0 {
  1506. //如果修改的差数量 大于库存数量
  1507. if drug.IsUse != 1 {
  1508. if (number_count - device_number) > total_count {
  1509. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1510. return
  1511. }
  1512. if (number_count - device_number) > batch_number_count {
  1513. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1514. return
  1515. }
  1516. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1517. // 查询该药品最后一次出库记录
  1518. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1519. var out_count int64
  1520. var in_count int64
  1521. var stock_max_number int64
  1522. var stock_min_number int64
  1523. for _, it := range outInfo {
  1524. if it.CountUnit == drug.MaxUnit {
  1525. it.Count = it.Count * drug.MinNumber
  1526. }
  1527. out_count += it.Count
  1528. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1529. stock_max_number = warehouseInfoList.StockMaxNumber
  1530. stock_min_number = warehouseInfoList.StockMinNumber
  1531. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1532. }
  1533. if out_count > 0 {
  1534. if (number_count - device_number) > in_count {
  1535. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1536. return
  1537. }
  1538. }
  1539. // 未出库
  1540. if out_count == 0 {
  1541. var sum_in_count int64
  1542. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1543. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1544. fmt.Println("sum_in_count", sum_in_count)
  1545. //如果修改的数量大于有库存的第一个批次
  1546. if number_count > sum_in_count {
  1547. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  1548. return
  1549. }
  1550. }
  1551. }
  1552. }
  1553. }
  1554. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1555. fmt.Println("device_number2333233232323222323232323323322332", device_number)
  1556. fmt.Println("number_count99999999999999999999999999999999999", number_count)
  1557. if pharmacyConfig.IsOpen != 1 {
  1558. if device_number != number_count {
  1559. // 查询该药品最后一次出库记录
  1560. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  1561. //回退库存
  1562. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  1563. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  1564. }
  1565. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  1566. var stock_max_number int64
  1567. var stock_min_number int64
  1568. if number_count >= drug.MinNumber {
  1569. stock_max_number = device_number / drug.MinNumber
  1570. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  1571. stock_min_number = device_number % drug.MinNumber
  1572. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  1573. } else {
  1574. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  1575. }
  1576. }
  1577. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  1578. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  1579. }
  1580. //删除记录
  1581. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  1582. //查询默认仓库剩余多少库存
  1583. var sum_count int64
  1584. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  1585. for _, its := range stockInfo {
  1586. if its.MaxUnit == drug.MaxUnit {
  1587. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  1588. }
  1589. sum_count += its.StockMaxNumber + its.StockMinNumber
  1590. }
  1591. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  1592. }
  1593. }
  1594. }
  1595. }
  1596. }
  1597. //保存处方开药
  1598. if drugOutConfig.IsOpen == 1 {
  1599. //修改处方
  1600. for _, advice := range advices {
  1601. var drug_id int64
  1602. var prescribing_number float64
  1603. var prescribingNumberUnit string
  1604. var prescribingNumber string
  1605. var adviceId int64
  1606. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1607. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1608. }
  1609. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1610. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1611. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1612. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1613. }
  1614. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1615. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1616. }
  1617. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1618. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1619. }
  1620. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1621. if drug.ID == 0 {
  1622. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1623. return
  1624. }
  1625. //查询药品的所有库存
  1626. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1627. var total_count int64
  1628. for _, it := range list {
  1629. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1630. }
  1631. totals := strconv.FormatInt(total_count, 10)
  1632. //查询该药品是否存在开药记录
  1633. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1634. //新增处方
  1635. if advicelist.ID == 0 {
  1636. //查询最新批次库存
  1637. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1638. var batch_number_count int64
  1639. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1640. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1641. all_count, _ := strconv.ParseFloat(totals, 64)
  1642. if prescribingNumberUnit == drug.MinUnit {
  1643. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1644. if drug.IsUse != 1 {
  1645. if prescribing_number > all_count {
  1646. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1647. return
  1648. }
  1649. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1650. if prescribing_number > batch_number_all_count {
  1651. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1652. return
  1653. }
  1654. }
  1655. }
  1656. } else {
  1657. if prescribingNumberUnit == drug.MaxUnit {
  1658. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1659. num := prescribing_number * float64(drug.MinNumber)
  1660. if drug.IsUse != 1 {
  1661. if num > all_count {
  1662. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1663. return
  1664. }
  1665. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1666. if prescribing_number > batch_number_all_count {
  1667. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1668. return
  1669. }
  1670. }
  1671. }
  1672. }
  1673. }
  1674. }
  1675. //修改处方
  1676. if advicelist.ID > 0 {
  1677. //查询最新批次库存
  1678. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1679. var batch_number_count int64
  1680. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1681. var device_number int64
  1682. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1683. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1684. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1685. device_number = prescribingNumberInt * drug.MinNumber
  1686. }
  1687. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1688. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1689. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1690. device_number = prescribingNumberInt
  1691. }
  1692. var number_count int64
  1693. if prescribingNumberUnit == drug.MaxUnit {
  1694. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1695. number_count = prescribingNumberInt * drug.MinNumber
  1696. }
  1697. if prescribingNumberUnit == drug.MinUnit {
  1698. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1699. number_count = prescribingNumberInt
  1700. }
  1701. //如果修改的数量大于之前修改的数量
  1702. if (number_count - device_number) > 0 {
  1703. //如果修改的差数量 大于库存数量
  1704. if drug.IsUse != 1 {
  1705. if (number_count - device_number) > total_count {
  1706. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1707. return
  1708. }
  1709. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1710. if (number_count - device_number) > batch_number_count {
  1711. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1712. return
  1713. }
  1714. }
  1715. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1716. //查询历史出库数据总批次
  1717. // 查询该药品最后一次出库记录
  1718. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1719. var out_count int64
  1720. var in_count int64
  1721. var stock_max_number int64
  1722. var stock_min_number int64
  1723. for _, it := range outInfo {
  1724. if it.CountUnit == drug.MaxUnit {
  1725. it.Count = it.Count * drug.MinNumber
  1726. }
  1727. out_count += it.Count
  1728. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1729. stock_max_number = warehouseInfoList.StockMaxNumber
  1730. stock_min_number = warehouseInfoList.StockMinNumber
  1731. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1732. }
  1733. if out_count > 0 {
  1734. if (number_count - device_number) > in_count {
  1735. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1736. return
  1737. }
  1738. }
  1739. // 未出库
  1740. if out_count == 0 {
  1741. var sum_in_count int64
  1742. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1743. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1744. //如果修改的数量大于有库存的第一个批次
  1745. if number_count > sum_in_count {
  1746. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  1747. return
  1748. }
  1749. }
  1750. }
  1751. }
  1752. }
  1753. }
  1754. }
  1755. }
  1756. }
  1757. }
  1758. }
  1759. }
  1760. }
  1761. }
  1762. }
  1763. //校验耗材库存
  1764. if goodOutConfig.IsOpen == 1 {
  1765. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1766. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1767. if len(prescriptions) > 0 {
  1768. for _, item := range prescriptions {
  1769. items := item.(map[string]interface{})
  1770. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1771. projects := items["project"].([]interface{})
  1772. if len(projects) > 0 {
  1773. for _, project := range projects {
  1774. var project_id int64
  1775. var project_type int64
  1776. var totals float64
  1777. var project_name string
  1778. var parsetotal int64
  1779. var id int64
  1780. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  1781. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  1782. }
  1783. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  1784. project_type = int64(project.(map[string]interface{})["type"].(float64))
  1785. }
  1786. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  1787. total, _ := project.(map[string]interface{})["total"].(string)
  1788. totals, _ = strconv.ParseFloat(total, 64)
  1789. }
  1790. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  1791. project_name = project.(map[string]interface{})["project_name"].(string)
  1792. }
  1793. if project_type == 3 {
  1794. //查找该耗材的出库记录
  1795. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  1796. if len(goodWarehouseInfo) == 0 {
  1797. //查询耗材库存
  1798. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  1799. var stock_count int64
  1800. for _, it := range list {
  1801. stock_count += it.StockCount
  1802. }
  1803. stock_counts := strconv.FormatInt(stock_count, 10)
  1804. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  1805. if totals > stock_total_count {
  1806. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  1807. return
  1808. }
  1809. }
  1810. if len(goodWarehouseInfo) > 0 {
  1811. //查询该患者耗材的历史数据
  1812. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  1813. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  1814. //数量发生改变
  1815. if parsetotal != count {
  1816. //如果现在的数量大于历史数量,就要看库存是否足够
  1817. if parsetotal > count {
  1818. //查询耗材所有库存
  1819. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  1820. var stock_count int64
  1821. for _, it := range list {
  1822. stock_count += it.StockCount
  1823. }
  1824. //库存不足
  1825. if (parsetotal - count) > stock_count {
  1826. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  1827. return
  1828. }
  1829. }
  1830. }
  1831. }
  1832. }
  1833. }
  1834. }
  1835. }
  1836. }
  1837. }
  1838. }
  1839. }
  1840. //不使用耗材保存处方出库
  1841. if goodOutConfig.IsOpen != 1 {
  1842. if stockConfig.IsOpen == 1 {
  1843. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1844. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1845. if len(prescriptions) > 0 {
  1846. for _, item := range prescriptions {
  1847. items := item.(map[string]interface{})
  1848. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1849. projects := items["project"].([]interface{})
  1850. if len(projects) > 0 {
  1851. for _, project := range projects {
  1852. var project_id int64
  1853. var project_type int64
  1854. var totals float64
  1855. var project_name string
  1856. var parsetotal int64
  1857. var id int64
  1858. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  1859. id = int64(project.(map[string]interface{})["id"].(float64))
  1860. }
  1861. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  1862. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  1863. }
  1864. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  1865. project_type = int64(project.(map[string]interface{})["type"].(float64))
  1866. }
  1867. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  1868. total, _ := project.(map[string]interface{})["total"].(string)
  1869. totals, _ = strconv.ParseFloat(total, 64)
  1870. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  1871. }
  1872. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  1873. project_name = project.(map[string]interface{})["project_name"].(string)
  1874. }
  1875. if project_type == 3 {
  1876. //查找该耗材的出库记录
  1877. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  1878. //没有出库记录
  1879. if len(goodWarehouseInfo) == 0 {
  1880. //查询耗材库存
  1881. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  1882. var stock_count int64
  1883. for _, it := range list {
  1884. stock_count += it.StockCount
  1885. }
  1886. stock_counts := strconv.FormatInt(stock_count, 10)
  1887. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  1888. if totals > stock_total_count {
  1889. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  1890. return
  1891. }
  1892. //查找今日该患者已经出库的所有耗材
  1893. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  1894. for _, item := range goodList {
  1895. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  1896. var flush_count int64
  1897. for _, it := range goodListSix {
  1898. flush_count += it.StockCount
  1899. }
  1900. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  1901. creater := adminInfo.AdminUser.Id
  1902. if errs != nil {
  1903. goodErrcode := models.XtGoodErrcode{
  1904. UserOrgId: item.OrgId,
  1905. Errcode: "手动出库更新剩余出库失败",
  1906. GoodId: item.GoodId,
  1907. Status: 1,
  1908. Ctime: time.Now().Unix(),
  1909. Mtime: 0,
  1910. Count: 0,
  1911. StockCount: 0,
  1912. Creater: creater,
  1913. BatchNumberId: 0,
  1914. WarehouseOutId: 0,
  1915. }
  1916. service.CreateGoodErrcode(goodErrcode)
  1917. }
  1918. }
  1919. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  1920. }
  1921. //有出库记录
  1922. if len(goodWarehouseInfo) > 0 {
  1923. //查询该患者耗材的历史数据
  1924. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  1925. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  1926. //数量发生改变
  1927. if parsetotal != count {
  1928. //查找今日该患者已经出库的所有耗材
  1929. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  1930. for _, item := range goodList {
  1931. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  1932. var flush_count int64
  1933. for _, it := range goodListSix {
  1934. flush_count += it.StockCount
  1935. }
  1936. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  1937. //减少出库数量
  1938. creater := adminInfo.AdminUser.Id
  1939. if errs != nil {
  1940. goodErrcode := models.XtGoodErrcode{
  1941. UserOrgId: item.OrgId,
  1942. Errcode: "手动出库更新剩余出库失败",
  1943. GoodId: item.GoodId,
  1944. Status: 1,
  1945. Ctime: time.Now().Unix(),
  1946. Mtime: 0,
  1947. Count: 0,
  1948. StockCount: 0,
  1949. Creater: creater,
  1950. BatchNumberId: 0,
  1951. WarehouseOutId: 0,
  1952. }
  1953. service.CreateGoodErrcode(goodErrcode)
  1954. }
  1955. //查询默认仓库
  1956. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  1957. var total_count int64
  1958. for _, it := range stockList {
  1959. total_count += it.StockCount
  1960. }
  1961. //基础库插入数据
  1962. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  1963. }
  1964. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  1965. }
  1966. }
  1967. }
  1968. }
  1969. }
  1970. }
  1971. }
  1972. }
  1973. }
  1974. }
  1975. }
  1976. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1977. var hpInfo models.HisPrescriptionInfo
  1978. if info.ID == 0 {
  1979. var randNum int
  1980. randNum = rand.Intn(10000) + 1000
  1981. timestamp := time.Now().Unix()
  1982. tempTime := time.Unix(timestamp, 0)
  1983. timeFormat := tempTime.Format("20060102150405")
  1984. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  1985. hpInfo = models.HisPrescriptionInfo{
  1986. HisPatientId: his_patient_id,
  1987. UserOrgId: adminInfo.CurrentOrgId,
  1988. RecordDate: theTime.Unix(),
  1989. PatientId: patient_id,
  1990. Status: 1,
  1991. Ctime: time.Now().Unix(),
  1992. Mtime: time.Now().Unix(),
  1993. Creator: adminInfo.AdminUser.Id,
  1994. Modifier: adminInfo.AdminUser.Id,
  1995. Diagnosis: diagnose,
  1996. SickHistory: sick_history,
  1997. Departments: department,
  1998. RegisterType: reg_type,
  1999. PrescriptionNumber: p_number,
  2000. PrescriptionStatus: 1,
  2001. Doctor: role.UserName,
  2002. DoctorId: doctor_id,
  2003. SickType: sick_type,
  2004. PType: p_type,
  2005. }
  2006. service.SavePatientPrescriptionInfo(hpInfo)
  2007. redis := service.RedisClient()
  2008. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2009. redis.Set(key, "", time.Second)
  2010. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2011. redis.Set(keyOne, "", time.Second)
  2012. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2013. redis.Set(keySeven, "", time.Second)
  2014. defer redis.Close()
  2015. } else {
  2016. hpInfo = models.HisPrescriptionInfo{
  2017. ID: info.ID,
  2018. UserOrgId: adminInfo.CurrentOrgId,
  2019. RecordDate: info.RecordDate,
  2020. PatientId: info.PatientId,
  2021. Status: 1,
  2022. Ctime: info.Ctime,
  2023. Mtime: time.Now().Unix(),
  2024. Creator: info.Creator,
  2025. Modifier: adminInfo.AdminUser.Id,
  2026. Diagnosis: diagnose,
  2027. SickHistory: sick_history,
  2028. Departments: department,
  2029. RegisterType: reg_type,
  2030. PrescriptionNumber: info.PrescriptionNumber,
  2031. Doctor: role.UserName,
  2032. PrescriptionStatus: info.PrescriptionStatus,
  2033. DoctorId: doctor_id,
  2034. SickType: sick_type,
  2035. PType: info.PType,
  2036. HisPatientId: info.HisPatientId,
  2037. }
  2038. service.SavePatientPrescriptionInfo(hpInfo)
  2039. redis := service.RedisClient()
  2040. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2041. redis.Set(key, "", time.Second)
  2042. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2043. redis.Set(keyOne, "", time.Second)
  2044. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2045. redis.Set(keySeven, "", time.Second)
  2046. defer redis.Close()
  2047. }
  2048. //定义切片
  2049. var adviceList []models.HisDoctorAdviceInfo
  2050. var projectList []models.HisPrescriptionProject
  2051. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2052. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2053. var tempPrescription *models.HisPrescription
  2054. if len(prescriptions) > 0 {
  2055. for _, item := range prescriptions {
  2056. items := item.(map[string]interface{})
  2057. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2058. utils.ErrorLog("id")
  2059. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2060. return
  2061. }
  2062. id := int64(items["id"].(float64))
  2063. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2064. tempPrescription = &new_prescription
  2065. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2066. utils.ErrorLog("type")
  2067. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2068. return
  2069. }
  2070. types := int64(items["type"].(float64))
  2071. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2072. utils.ErrorLog("med_type")
  2073. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2074. return
  2075. }
  2076. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2077. if med_type == "0" {
  2078. med_type = "14"
  2079. }
  2080. //if order_status == 0 {
  2081. // order_status = 1
  2082. //}
  2083. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2084. utils.ErrorLog("pre_time")
  2085. }
  2086. preTime, _ := items["pre_time"].(string)
  2087. timeLayout := "2006-01-02"
  2088. loc, _ := time.LoadLocation("Local")
  2089. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2090. if err != nil {
  2091. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2092. return
  2093. }
  2094. pTime := theTime2.Unix()
  2095. ctime := time.Now().Unix()
  2096. if tempPrescription.ID == 0 {
  2097. prescription := &models.HisPrescription{
  2098. ID: 0,
  2099. PatientId: patient_id,
  2100. UserOrgId: adminInfo.CurrentOrgId,
  2101. RecordDate: recordDateTime,
  2102. Ctime: ctime,
  2103. Mtime: ctime,
  2104. Type: types,
  2105. Modifier: adminInfo.AdminUser.Id,
  2106. Creator: adminInfo.AdminUser.Id,
  2107. Status: 1,
  2108. Doctor: role.UserName,
  2109. HisPatientId: his_patient_id,
  2110. OrderStatus: 1,
  2111. BatchNumber: "",
  2112. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2113. PreTime: pTime,
  2114. PType: p_type,
  2115. MedType: med_type,
  2116. }
  2117. tempPrescription = prescription
  2118. service.SaveHisPrescription(tempPrescription)
  2119. redis := service.RedisClient()
  2120. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2121. redis.Set(key, "", time.Second)
  2122. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2123. redis.Set(keyOne, "", time.Second)
  2124. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2125. redis.Set(keySeven, "", time.Second)
  2126. defer redis.Close()
  2127. } else {
  2128. tempPrescription.ID = id
  2129. tempPrescription.Type = types
  2130. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2131. tempPrescription.Mtime = time.Now().Unix()
  2132. tempPrescription.Doctor = role.UserName
  2133. //tempPrescription.OrderStatus = order_status
  2134. tempPrescription.PreTime = pTime
  2135. tempPrescription.MedType = med_type
  2136. service.SaveHisPrescription(tempPrescription)
  2137. redis := service.RedisClient()
  2138. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2139. redis.Set(key, "", time.Second)
  2140. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2141. redis.Set(keyOne, "", time.Second)
  2142. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2143. redis.Set(keySeven, "", time.Second)
  2144. defer redis.Close()
  2145. }
  2146. //service.SaveHisPrescription(prescription)
  2147. //更改患者挂号状态
  2148. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2149. fmt.Println("更改失败", err2)
  2150. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2151. advices := items["advices"].([]interface{})
  2152. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2153. groupNo := int64(0)
  2154. ctime := time.Now().Unix()
  2155. mtime := ctime
  2156. if len(advices) > 0 {
  2157. for _, advice := range advices {
  2158. var s models.HisDoctorAdviceInfo
  2159. s.PrescriptionId = tempPrescription.ID
  2160. s.AdviceType = 2
  2161. s.AdviceDoctor = doctor_id
  2162. s.StopState = 2
  2163. s.ExecutionState = 2
  2164. s.AdviceDate = recordDateTime
  2165. s.Status = 1
  2166. s.UserOrgId = adminInfo.CurrentOrgId
  2167. s.RecordDate = recordDateTime
  2168. s.StartTime = tempPrescription.PreTime
  2169. s.Groupno = groupNo
  2170. s.CreatedTime = ctime
  2171. s.UpdatedTime = mtime
  2172. s.PatientId = patient_id
  2173. s.HisPatientId = his_patient_id
  2174. s.StartTime = pTime
  2175. s.IsSettle = 2
  2176. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2177. if errcode > 0 {
  2178. c.ServeFailJSONWithSGJErrorCode(errcode)
  2179. return
  2180. }
  2181. s.StartTime = pTime
  2182. var total_count int64 //处方总库存
  2183. //查询改药品信息
  2184. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2185. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2186. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2187. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2188. total_count += prescribingNumberSeven * medical.MinNumber
  2189. }
  2190. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2191. total_count += prescribingNumberSeven
  2192. }
  2193. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2194. total_count += prescribingNumberSeven
  2195. }
  2196. service.CreateHisDoctorAdvice(&s)
  2197. //存储切片中
  2198. adviceList = append(adviceList, s)
  2199. redis := service.RedisClient()
  2200. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2201. redis.Set(key, "", time.Second)
  2202. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2203. redis.Set(keyOne, "", time.Second)
  2204. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2205. redis.Set(keySeven, "", time.Second)
  2206. var randNum int
  2207. randNum = rand.Intn(10000) + 1000
  2208. timestamp := time.Now().Unix()
  2209. tempTime := time.Unix(timestamp, 0)
  2210. timeFormat := tempTime.Format("20060102150405")
  2211. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  2212. service.CreateHisDoctorAdvice(&s)
  2213. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2214. redis.Set(keySix, "", time.Second)
  2215. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2216. redis.Set(keyFive, "", time.Second)
  2217. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2218. redis.Set(keyEight, "", time.Second)
  2219. defer redis.Close()
  2220. }
  2221. }
  2222. }
  2223. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2224. projects := items["project"].([]interface{})
  2225. if len(projects) > 0 {
  2226. for _, project := range projects {
  2227. var p models.HisPrescriptionProject
  2228. p.PrescriptionId = tempPrescription.ID
  2229. p.Ctime = time.Now().Unix()
  2230. p.Mtime = time.Now().Unix()
  2231. p.PatientId = patient_id
  2232. p.RecordDate = recordDateTime
  2233. p.Doctor = doctor_id
  2234. p.UserOrgId = adminInfo.CurrentOrgId
  2235. p.HisPatientId = his_patient_id
  2236. p.Status = 1
  2237. p.StartTime = pTime
  2238. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  2239. if errcode > 0 {
  2240. c.ServeFailJSONWithSGJErrorCode(errcode)
  2241. return
  2242. }
  2243. if p.ID == 0 {
  2244. p.IsOut = 2
  2245. }
  2246. if p.ID > 0 {
  2247. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  2248. p.IsOut = projectDetail.IsOut
  2249. }
  2250. service.CreateHisProjectTwo(&p)
  2251. projectList = append(projectList, p)
  2252. var randNum int
  2253. randNum = rand.Intn(10000) + 1000
  2254. timestamp := time.Now().Unix()
  2255. tempTime := time.Unix(timestamp, 0)
  2256. timeFormat := tempTime.Format("20060102150405")
  2257. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  2258. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  2259. //新增或者编辑项目,修改对应的标签数据
  2260. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  2261. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  2262. var label models.HisLabelPrintInfo
  2263. project, _ := service.GetProjectDetail(p.ProjectId)
  2264. if project.CostClassify == 3 { //类别为检验检查
  2265. if p.TeamId > 0 { //检验检查组套
  2266. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  2267. if tempLabel.ID == 0 {
  2268. team, _ := service.GetProjectTeamDetail(p.TeamId)
  2269. label.Number = tempPrescription.PrescriptionNumber
  2270. label.ProjectId = project.ID
  2271. label.Status = 1
  2272. label.IsPrint = 2
  2273. label.DoctorId = info.DoctorId
  2274. label.UserOrgId = p.UserOrgId
  2275. label.PatientId = patient_id
  2276. label.RecordDate = recordDateTime
  2277. label.Ctime = time.Now().Unix()
  2278. label.Mtime = time.Now().Unix()
  2279. label.ItemId = p.TeamId
  2280. label.FeedetlSn = p.FeedetlSn
  2281. label.PProjectId = p.ID
  2282. label.ProjectName = team.ProjectTeam
  2283. label.PatientName = patient.Name
  2284. service.CreateHisLabelRecord(&label)
  2285. }
  2286. } else { //单条检验检查项目
  2287. label.Number = tempPrescription.PrescriptionNumber
  2288. label.ProjectId = project.ID
  2289. label.Status = 1
  2290. label.DoctorId = info.DoctorId
  2291. label.UserOrgId = p.UserOrgId
  2292. label.PatientId = patient_id
  2293. label.RecordDate = recordDateTime
  2294. label.IsPrint = 2
  2295. label.Ctime = time.Now().Unix()
  2296. label.Mtime = time.Now().Unix()
  2297. label.FeedetlSn = p.FeedetlSn
  2298. label.PProjectId = p.ID
  2299. label.ItemId = p.TeamId
  2300. label.ProjectName = project.ProjectName
  2301. label.PatientName = patient.Name
  2302. service.CreateHisLabelRecord(&label)
  2303. }
  2304. }
  2305. }
  2306. }
  2307. service.SaveHisProjectTwo(&p)
  2308. }
  2309. }
  2310. }
  2311. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2312. // addition := items["addition"].([]interface{})
  2313. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2314. // ctime := time.Now().Unix()
  2315. // mtime := ctime
  2316. // if len(addition) > 0 {
  2317. // for _, item := range addition {
  2318. // var s models.HisAdditionalCharge
  2319. // s.PrescriptionId = tempPrescription.ID
  2320. // s.Status = 1
  2321. // s.UserOrgId = adminInfo.CurrentOrgId
  2322. // s.RecordDate = recordDateTime
  2323. // s.CreatedTime = ctime
  2324. // s.UpdatedTime = mtime
  2325. // s.PatientId = patient_id
  2326. // s.HisPatientId = his_patient_id
  2327. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  2328. // if errcode > 0 {
  2329. // c.ServeFailJSONWithSGJErrorCode(errcode)
  2330. // return
  2331. // }
  2332. // service.CreateAdditionalCharge(&s)
  2333. // var randNum int
  2334. // randNum = rand.Intn(10000) + 1000
  2335. // timestamp := time.Now().Unix()
  2336. // tempTime := time.Unix(timestamp, 0)
  2337. // timeFormat := tempTime.Format("20060102150405")
  2338. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  2339. // service.CreateAdditionalCharge(&s)
  2340. //
  2341. // }
  2342. // }
  2343. //}
  2344. }
  2345. }
  2346. //查询今日该患者开的药品处方
  2347. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2348. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2349. //药品出库
  2350. if drugOutConfig.IsOpen == 1 {
  2351. for _, item := range hisdoctorlist {
  2352. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  2353. // 查询该药品最后一次出库记录
  2354. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  2355. if len(druginfo) > 0 {
  2356. //回退库存
  2357. for _, it := range druginfo {
  2358. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2359. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2360. }
  2361. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2362. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2363. }
  2364. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2365. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2366. }
  2367. }
  2368. }
  2369. //删除记录
  2370. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  2371. //查询最后一次数据
  2372. if drugOutConfig.IsOpen == 1 {
  2373. //出库
  2374. if drug.IsUse == 2 {
  2375. creater := adminInfo.AdminUser.Id
  2376. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  2377. }
  2378. //更新字典里面的库存
  2379. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2380. var sum_count int64
  2381. for _, its := range stockInfo {
  2382. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  2383. if its.MaxUnit == baseDrug.MaxUnit {
  2384. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  2385. }
  2386. sum_count += its.StockMaxNumber + its.StockMinNumber
  2387. }
  2388. //更新基础库存
  2389. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2390. //剩余库存
  2391. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  2392. }
  2393. }
  2394. }
  2395. //耗材保存处方出库
  2396. if goodOutConfig.IsOpen == 1 {
  2397. //查询今日耗材出库数量
  2398. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2399. for _, item := range hisgoodlist {
  2400. //查询历史出库数据
  2401. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2402. var out_count_five int64
  2403. for _, item := range flowGood {
  2404. out_count_five += item.Count
  2405. }
  2406. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  2407. if out_count_five != parseIntCount {
  2408. //查询耗材最后一次出库记录
  2409. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  2410. //查询默认出库仓库库存
  2411. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2412. if len(wareOut) > 0 {
  2413. for _, it := range wareOut {
  2414. //回退库存
  2415. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  2416. //删除出库记录
  2417. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  2418. }
  2419. }
  2420. timeStr := time.Now().Format("2006-01-02")
  2421. timeArr := strings.Split(timeStr, "-")
  2422. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  2423. total = total + 1
  2424. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2425. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2426. number = number + total
  2427. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2428. operation_time := time.Now().Unix()
  2429. creater := c.GetAdminUserInfo().AdminUser.Id
  2430. recordDateStr := time.Now().Format("2006-01-02")
  2431. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2432. nowtime := recordDate.Unix()
  2433. warehouseOut := models.WarehouseOut{
  2434. WarehouseOutOrderNumber: warehousing_out_order,
  2435. OperationTime: operation_time,
  2436. OrgId: adminInfo.CurrentOrgId,
  2437. Creater: creater,
  2438. Ctime: time.Now().Unix(),
  2439. Status: 1,
  2440. WarehouseOutTime: nowtime,
  2441. Type: 1,
  2442. StorehouseId: storeConfig.StorehouseOutInfo,
  2443. IsCheck: 1,
  2444. IsSys: 1,
  2445. }
  2446. //查询是否生成出库单
  2447. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2448. if out.ID == 0 {
  2449. service.AddSigleWarehouseOut(&warehouseOut)
  2450. }
  2451. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2452. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2453. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  2454. dialyPrepareOne := models.DialysisBeforePrepare{
  2455. GoodTypeId: goodObj.GoodTypeId,
  2456. GoodId: item.ProjectId,
  2457. PatientId: item.PatientId,
  2458. RecordDate: item.RecordDate,
  2459. UserOrgId: adminInfo.CurrentOrgId,
  2460. Count: parseIntCount,
  2461. Ctime: time.Now().Unix(),
  2462. Creater: creater,
  2463. Status: 1,
  2464. StorehouseId: houseConfig.StorehouseOutInfo,
  2465. ProjectId: item.ID,
  2466. }
  2467. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2468. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  2469. //查询历史出库数据
  2470. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2471. var out_count int64
  2472. for _, item := range flowGood {
  2473. out_count += item.Count
  2474. }
  2475. //如果历史数和当前数据不想等才进行退库出库
  2476. if out_count != parseIntCount {
  2477. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  2478. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2479. detail := models.AutomaticReduceDetail{
  2480. WarehouseOutId: 0,
  2481. WarehouseOutOrderNumber: "",
  2482. PatientId: item.PatientId,
  2483. Ctime: time.Now().Unix(),
  2484. Mtime: 0,
  2485. Status: 1,
  2486. RecordTime: item.RecordDate,
  2487. OrgId: item.UserOrgId,
  2488. GoodId: item.ProjectId,
  2489. GoodTypeId: 0,
  2490. Count: parseIntCount,
  2491. Type: 0,
  2492. ProjectId: item.ID,
  2493. StorehouseId: 0,
  2494. }
  2495. service.CreateAutoDetail(detail)
  2496. //查询剩余库存
  2497. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  2498. var sum_count int64
  2499. for _, item := range goodList {
  2500. sum_count += item.StockCount
  2501. }
  2502. //更新剩余库存
  2503. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  2504. //耗材
  2505. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  2506. }
  2507. }
  2508. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  2509. //查询历史出库数据
  2510. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2511. var out_count int64
  2512. for _, item := range flowGood {
  2513. out_count += item.Count
  2514. }
  2515. //如果历史数和当前数据不想等才进行退库出库
  2516. if out_count != parseIntCount {
  2517. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  2518. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2519. detail := models.AutomaticReduceDetail{
  2520. WarehouseOutId: 0,
  2521. WarehouseOutOrderNumber: "",
  2522. PatientId: item.PatientId,
  2523. Ctime: time.Now().Unix(),
  2524. Mtime: 0,
  2525. Status: 1,
  2526. RecordTime: item.RecordDate,
  2527. OrgId: item.UserOrgId,
  2528. GoodId: item.ProjectId,
  2529. GoodTypeId: 0,
  2530. Count: parseIntCount,
  2531. Type: 0,
  2532. ProjectId: item.ID,
  2533. StorehouseId: 0,
  2534. }
  2535. service.CreateAutoDetail(detail)
  2536. //查询剩余库存
  2537. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  2538. var sum_count int64
  2539. for _, item := range goodList {
  2540. sum_count += item.StockCount
  2541. }
  2542. //更新剩余库存
  2543. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  2544. //耗材
  2545. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  2546. }
  2547. }
  2548. }
  2549. }
  2550. }
  2551. }
  2552. //redisClient := service.RedisClient()
  2553. //defer redisClient.Close()
  2554. //
  2555. //list := models.HisList{
  2556. // Patient_id: patient_id,
  2557. // Advice_id:0,
  2558. // Record_date: 0,
  2559. // Advice: adviceList,
  2560. // Project: nil,
  2561. //}
  2562. //hisLis = append(hisLis, list)
  2563. //
  2564. //advice_json, _ := json.Marshal(&hisLis)
  2565. //redisClient.RPush("111", advice_json).Result()
  2566. //result, _ := redisClient.RPop("111").Result()
  2567. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  2568. //
  2569. //var dat []map[string]interface{}
  2570. //json.Unmarshal([]byte(result), &dat)
  2571. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  2572. //
  2573. //for k,v:=range dat{
  2574. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  2575. //}
  2576. //project_json, _ := json.Marshal(&projectList)
  2577. //redisClient.LPush("222", project_json).Result()
  2578. if err == nil {
  2579. c.ServeSuccessJSON(map[string]interface{}{
  2580. "msg": "保存成功",
  2581. })
  2582. return
  2583. } else {
  2584. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2585. return
  2586. }
  2587. }
  2588. func (c *HisApiController) EditHisPrescription() {
  2589. record_date := c.GetString("record_date")
  2590. patient_id, _ := c.GetInt64("patient_id")
  2591. reg_type, _ := c.GetInt64("reg_type")
  2592. //diagnose, _ := c.GetInt64("diagnose", 0)
  2593. diagnose := c.GetString("diagnose")
  2594. sick_type, _ := c.GetInt64("sick_type")
  2595. sick_history := c.GetString("sick_history")
  2596. doctor_id, _ := c.GetInt64("doctor", 0)
  2597. department, _ := c.GetInt64("department", 0)
  2598. his_patient_id, _ := c.GetInt64("his_patient_id")
  2599. p_type, _ := c.GetInt64("p_type")
  2600. dataBody := make(map[string]interface{}, 0)
  2601. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2602. if err != nil {
  2603. utils.ErrorLog(err.Error())
  2604. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2605. return
  2606. }
  2607. timeLayout := "2006-01-02"
  2608. loc, _ := time.LoadLocation("Local")
  2609. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2610. if err != nil {
  2611. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2612. return
  2613. }
  2614. adminInfo := c.GetAdminUserInfo()
  2615. recordDateTime := theTime.Unix()
  2616. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  2617. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2618. var hpInfo models.HisPrescriptionInfo
  2619. if info.ID == 0 {
  2620. var randNum int
  2621. randNum = rand.Intn(10000) + 1000
  2622. timestamp := time.Now().Unix()
  2623. tempTime := time.Unix(timestamp, 0)
  2624. timeFormat := tempTime.Format("20060102150405")
  2625. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2626. hpInfo = models.HisPrescriptionInfo{
  2627. UserOrgId: adminInfo.CurrentOrgId,
  2628. RecordDate: theTime.Unix(),
  2629. PatientId: patient_id,
  2630. Status: 1,
  2631. Ctime: time.Now().Unix(),
  2632. Mtime: time.Now().Unix(),
  2633. Creator: adminInfo.AdminUser.Id,
  2634. Modifier: adminInfo.AdminUser.Id,
  2635. Diagnosis: diagnose,
  2636. SickHistory: sick_history,
  2637. Departments: department,
  2638. RegisterType: reg_type,
  2639. PrescriptionNumber: p_number,
  2640. PrescriptionStatus: 1,
  2641. Doctor: role.UserName,
  2642. DoctorId: doctor_id,
  2643. SickType: sick_type,
  2644. PType: p_type,
  2645. }
  2646. service.SavePatientPrescriptionInfo(hpInfo)
  2647. } else {
  2648. hpInfo = models.HisPrescriptionInfo{
  2649. ID: info.ID,
  2650. UserOrgId: adminInfo.CurrentOrgId,
  2651. RecordDate: info.RecordDate,
  2652. PatientId: info.PatientId,
  2653. Status: 1,
  2654. Ctime: info.Ctime,
  2655. Mtime: time.Now().Unix(),
  2656. Creator: info.Creator,
  2657. Modifier: adminInfo.AdminUser.Id,
  2658. Diagnosis: diagnose,
  2659. SickHistory: sick_history,
  2660. Departments: department,
  2661. RegisterType: reg_type,
  2662. PrescriptionNumber: info.PrescriptionNumber,
  2663. Doctor: role.UserName,
  2664. PrescriptionStatus: info.PrescriptionStatus,
  2665. DoctorId: doctor_id,
  2666. SickType: sick_type,
  2667. PType: info.PType,
  2668. }
  2669. service.SavePatientPrescriptionInfo(hpInfo)
  2670. }
  2671. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2672. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2673. if len(prescriptions) > 0 {
  2674. for _, item := range prescriptions {
  2675. items := item.(map[string]interface{})
  2676. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2677. utils.ErrorLog("id")
  2678. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2679. return
  2680. }
  2681. id := int64(items["id"].(float64))
  2682. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2683. utils.ErrorLog("type")
  2684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2685. return
  2686. }
  2687. types := int64(items["type"].(float64))
  2688. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2689. utils.ErrorLog("med_type")
  2690. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2691. return
  2692. }
  2693. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2694. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  2695. ctime := time.Now().Unix()
  2696. prescription := &models.HisPrescription{
  2697. ID: id,
  2698. PatientId: patient_id,
  2699. UserOrgId: adminInfo.CurrentOrgId,
  2700. RecordDate: recordDateTime,
  2701. Ctime: ctime,
  2702. Mtime: ctime,
  2703. Type: types,
  2704. Modifier: adminInfo.AdminUser.Id,
  2705. Creator: adminInfo.AdminUser.Id,
  2706. Status: 1,
  2707. Doctor: role.UserName,
  2708. HisPatientId: his_patient_id,
  2709. OrderStatus: 1,
  2710. BatchNumber: "",
  2711. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2712. PType: hpInfo.PType,
  2713. MedType: med_type,
  2714. }
  2715. if historyPrescription.ID > 0 {
  2716. prescription.PreTime = historyPrescription.PreTime
  2717. }
  2718. service.SaveHisPrescription(prescription)
  2719. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2720. advices := items["advices"].([]interface{})
  2721. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2722. groupNo := int64(0)
  2723. ctime := time.Now().Unix()
  2724. mtime := ctime
  2725. if len(advices) > 0 {
  2726. for _, advice := range advices {
  2727. var s models.HisDoctorAdviceInfo
  2728. s.PrescriptionId = prescription.ID
  2729. s.AdviceType = 2
  2730. s.AdviceDoctor = adminInfo.AdminUser.Id
  2731. s.StopState = 2
  2732. s.ExecutionState = 2
  2733. s.AdviceDate = recordDateTime
  2734. s.Status = 1
  2735. s.UserOrgId = adminInfo.CurrentOrgId
  2736. s.RecordDate = recordDateTime
  2737. s.StartTime = prescription.PreTime
  2738. s.Groupno = groupNo
  2739. s.CreatedTime = ctime
  2740. s.UpdatedTime = mtime
  2741. s.PatientId = patient_id
  2742. s.HisPatientId = his_patient_id
  2743. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  2744. if errcode > 0 {
  2745. c.ServeFailJSONWithSGJErrorCode(errcode)
  2746. return
  2747. }
  2748. service.CreateHisDoctorAdvice(&s)
  2749. redis := service.RedisClient()
  2750. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2751. redis.Set(key, "", time.Second)
  2752. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2753. fmt.Println("keyOne", keyOne)
  2754. redis.Set(keyOne, "", time.Second)
  2755. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2756. redis.Set(keySeven, "", time.Second)
  2757. redis.Close()
  2758. }
  2759. }
  2760. }
  2761. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2762. projects := items["project"].([]interface{})
  2763. if len(projects) > 0 {
  2764. for _, project := range projects {
  2765. var p models.HisPrescriptionProject
  2766. p.PrescriptionId = prescription.ID
  2767. p.Ctime = time.Now().Unix()
  2768. p.Mtime = time.Now().Unix()
  2769. p.PatientId = patient_id
  2770. p.RecordDate = recordDateTime
  2771. p.UserOrgId = adminInfo.CurrentOrgId
  2772. p.HisPatientId = his_patient_id
  2773. p.Status = 1
  2774. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  2775. if errcode > 0 {
  2776. c.ServeFailJSONWithSGJErrorCode(errcode)
  2777. return
  2778. }
  2779. service.CreateHisProjectTwo(&p)
  2780. }
  2781. }
  2782. }
  2783. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2784. addition := items["addition"].([]interface{})
  2785. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2786. ctime := time.Now().Unix()
  2787. mtime := ctime
  2788. if len(addition) > 0 {
  2789. for _, item := range addition {
  2790. var s models.HisAdditionalCharge
  2791. s.PrescriptionId = prescription.ID
  2792. s.Status = 1
  2793. s.UserOrgId = adminInfo.CurrentOrgId
  2794. s.RecordDate = recordDateTime
  2795. s.CreatedTime = ctime
  2796. s.UpdatedTime = mtime
  2797. s.PatientId = patient_id
  2798. s.HisPatientId = his_patient_id
  2799. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  2800. if errcode > 0 {
  2801. c.ServeFailJSONWithSGJErrorCode(errcode)
  2802. return
  2803. }
  2804. service.CreateAdditionalCharge(&s)
  2805. }
  2806. }
  2807. }
  2808. }
  2809. }
  2810. }
  2811. if err == nil {
  2812. c.ServeSuccessJSON(map[string]interface{}{
  2813. "msg": "保存成功",
  2814. })
  2815. return
  2816. } else {
  2817. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2818. return
  2819. }
  2820. }
  2821. func (c *HisApiController) DeletePrescription() {
  2822. prescription_id, _ := c.GetInt64("id")
  2823. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  2824. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  2825. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2826. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2827. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  2828. //耗材保存处方出库
  2829. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  2830. //已收费和已发药限制逻辑
  2831. isCharge := false
  2832. isMedicine := false
  2833. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  2834. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  2835. for _, item := range new_prescriptions {
  2836. if item.IsMedicine == 1 {
  2837. isMedicine = true
  2838. }
  2839. }
  2840. for _, item := range new_prescriptions {
  2841. if item.OrderStatus == 4 {
  2842. isCharge = true
  2843. }
  2844. }
  2845. if p_err != nil {
  2846. if new_prescription.ID > 0 {
  2847. if new_prescription.OrderStatus == 2 {
  2848. isCharge = true
  2849. }
  2850. }
  2851. }
  2852. for _, item := range advices {
  2853. if item.IsMedicine == 1 {
  2854. isMedicine = true
  2855. }
  2856. }
  2857. if isCharge {
  2858. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  2859. return
  2860. }
  2861. if isMedicine {
  2862. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  2863. return
  2864. }
  2865. //已收费和已发药限制逻辑
  2866. if len(projects) > 0 {
  2867. for _, item := range projects {
  2868. service.DeletePrintInfo(item.ID) //删除打印信息
  2869. if goodOutConfig.IsOpen != 1 {
  2870. if stockConfig.IsOpen == 1 {
  2871. if item.Type == 3 && item.IsOut == 1 {
  2872. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  2873. f_count, _ := strconv.ParseFloat(item.Count, 64)
  2874. good.Total = good.Total + f_count
  2875. service.UpdateGoodInfo(&good)
  2876. operation_time := time.Now().Unix()
  2877. creater := c.GetAdminUserInfo().AdminUser.Id
  2878. //创建退库单
  2879. timeStr := time.Now().Format("2006-01-02")
  2880. timeArr := strings.Split(timeStr, "-")
  2881. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  2882. total = total + 1
  2883. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2884. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  2885. cancelStock := models.CancelStock{
  2886. OrderNumber: orderNumber,
  2887. OperaTime: operation_time,
  2888. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2889. Creater: creater,
  2890. Ctime: time.Now().Unix(),
  2891. Status: 1,
  2892. ReturnTime: item.RecordDate,
  2893. Type: 1,
  2894. StorehouseId: houseConfig.StorehouseOutInfo,
  2895. IsCheck: 1,
  2896. }
  2897. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  2898. if msgerrkonde == gorm.ErrRecordNotFound {
  2899. service.AddSigleCancelStock(&cancelStock)
  2900. }
  2901. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  2902. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  2903. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2904. //查询该耗材是否出库
  2905. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  2906. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  2907. deaerler, _ := service.GetDealerById(info.Dealer)
  2908. var total_count int64
  2909. count, _ := strconv.ParseInt(item.Count, 10, 64)
  2910. total_count += count
  2911. if info.ID > 0 {
  2912. if info.Count >= total_count {
  2913. //回退库存
  2914. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  2915. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  2916. var flush_count int64
  2917. for _, it := range goodList {
  2918. flush_count += it.StockCount
  2919. }
  2920. cancelStockInfo := models.CancelStockInfo{
  2921. GoodId: item.ProjectId,
  2922. CancelStockId: cancel.ID,
  2923. GoodTypeId: good.GoodTypeId,
  2924. Count: prescribingNumber,
  2925. Price: info.Price,
  2926. Total: 0,
  2927. ProductDate: info.ProductDate,
  2928. ExpiryDate: info.ExpiryDate,
  2929. Ctime: time.Now().Unix(),
  2930. Status: 1,
  2931. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2932. OrderNumber: cancel.OrderNumber,
  2933. Type: 0,
  2934. Dealer: deaerler.DealerName,
  2935. Manufacturer: manufacturer.ManufacturerName,
  2936. Number: info.Number,
  2937. RegisterAccount: "",
  2938. Remark: "",
  2939. WarehouseInfoId: info.WarehouseInfotId,
  2940. PatientId: info.PatientId,
  2941. RecordDate: info.SysRecordTime,
  2942. StorehouseId: houseConfig.StorehouseOutInfo,
  2943. IsCheck: 1,
  2944. }
  2945. service.CreateCancelStockInfoOne(&cancelStockInfo)
  2946. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  2947. flow := models.VmStockFlow{
  2948. WarehousingId: info.WarehouseInfotId,
  2949. GoodId: item.ProjectId,
  2950. Number: info.Number,
  2951. LicenseNumber: info.LicenseNumber,
  2952. Count: prescribingNumber,
  2953. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2954. PatientId: item.PatientId,
  2955. SystemTime: info.SysRecordTime,
  2956. ConsumableType: 7,
  2957. IsSys: 0,
  2958. WarehousingOrder: "",
  2959. WarehouseOutId: info.WarehouseOutId,
  2960. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2961. IsEdit: 0,
  2962. CancelStockId: cancel.ID,
  2963. CancelOrderNumber: cancel.OrderNumber,
  2964. Manufacturer: manufacturer.ID,
  2965. Dealer: 0,
  2966. Creator: c.GetAdminUserInfo().CurrentOrgId,
  2967. UpdateCreator: 0,
  2968. Status: 1,
  2969. Ctime: time.Now().Unix(),
  2970. Mtime: 0,
  2971. Price: info.Price,
  2972. WarehousingDetailId: info.WarehouseInfotId,
  2973. WarehouseOutDetailId: info.ID,
  2974. CancelOutDetailId: cancelInfo.ID,
  2975. ProductDate: info.ProductDate,
  2976. ExpireDate: info.ExpiryDate,
  2977. StorehouseId: houseConfig.StorehouseOutInfo,
  2978. OverCount: flush_count,
  2979. }
  2980. service.CreateStockFlowOne(flow)
  2981. //退库数量增加
  2982. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  2983. //出库数量减少
  2984. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  2985. }
  2986. if info.Count < total_count {
  2987. //回退库存
  2988. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  2989. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  2990. var flush_count int64
  2991. for _, it := range goodList {
  2992. flush_count += it.StockCount
  2993. }
  2994. cancelStockInfo := models.CancelStockInfo{
  2995. GoodId: item.ProjectId,
  2996. CancelStockId: cancel.ID,
  2997. GoodTypeId: good.GoodTypeId,
  2998. Count: info.Count,
  2999. Price: info.Price,
  3000. Total: 0,
  3001. ProductDate: info.ProductDate,
  3002. ExpiryDate: info.ExpiryDate,
  3003. Ctime: time.Now().Unix(),
  3004. Status: 1,
  3005. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3006. OrderNumber: cancel.OrderNumber,
  3007. Type: 0,
  3008. Dealer: deaerler.DealerName,
  3009. Manufacturer: manufacturer.ManufacturerName,
  3010. Number: info.Number,
  3011. RegisterAccount: "",
  3012. Remark: "",
  3013. WarehouseInfoId: info.WarehouseInfotId,
  3014. PatientId: info.PatientId,
  3015. RecordDate: info.SysRecordTime,
  3016. StorehouseId: houseConfig.StorehouseOutInfo,
  3017. IsCheck: 1,
  3018. }
  3019. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3020. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3021. flow := models.VmStockFlow{
  3022. WarehousingId: info.WarehouseInfotId,
  3023. GoodId: item.ProjectId,
  3024. Number: info.Number,
  3025. LicenseNumber: info.LicenseNumber,
  3026. Count: info.Count,
  3027. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3028. PatientId: item.PatientId,
  3029. SystemTime: info.SysRecordTime,
  3030. ConsumableType: 7,
  3031. IsSys: 0,
  3032. WarehousingOrder: "",
  3033. WarehouseOutId: info.WarehouseOutId,
  3034. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3035. IsEdit: 0,
  3036. CancelStockId: cancel.ID,
  3037. CancelOrderNumber: cancel.OrderNumber,
  3038. Manufacturer: manufacturer.ID,
  3039. Dealer: 0,
  3040. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3041. UpdateCreator: 0,
  3042. Status: 1,
  3043. Ctime: time.Now().Unix(),
  3044. Mtime: 0,
  3045. Price: info.Price,
  3046. WarehousingDetailId: info.WarehouseInfotId,
  3047. WarehouseOutDetailId: info.ID,
  3048. CancelOutDetailId: cancelInfo.ID,
  3049. ProductDate: info.ProductDate,
  3050. ExpireDate: info.ExpiryDate,
  3051. StorehouseId: houseConfig.StorehouseOutInfo,
  3052. OverCount: flush_count,
  3053. }
  3054. service.CreateStockFlowOne(flow)
  3055. //退库数量增加
  3056. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3057. //出库数量减少
  3058. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  3059. }
  3060. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3061. var flush_count int64
  3062. for _, it := range goodList {
  3063. flush_count += it.StockCount
  3064. }
  3065. //查询已出库数量
  3066. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3067. if prescribingNumber < dialysisInfo.Count {
  3068. //改变数量
  3069. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3070. }
  3071. if prescribingNumber >= dialysisInfo.Count {
  3072. //删除出库表
  3073. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3074. }
  3075. //更新库存
  3076. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  3077. //更新基础库库存
  3078. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  3079. }
  3080. }
  3081. }
  3082. }
  3083. //保存耗材出库
  3084. if goodOutConfig.IsOpen == 1 {
  3085. if item.Type == 3 {
  3086. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3087. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3088. good.Total = good.Total + f_count
  3089. service.UpdateGoodInfo(&good)
  3090. operation_time := time.Now().Unix()
  3091. creater := c.GetAdminUserInfo().AdminUser.Id
  3092. //创建退库单
  3093. timeStr := time.Now().Format("2006-01-02")
  3094. timeArr := strings.Split(timeStr, "-")
  3095. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3096. total = total + 1
  3097. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3098. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3099. cancelStock := models.CancelStock{
  3100. OrderNumber: orderNumber,
  3101. OperaTime: operation_time,
  3102. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3103. Creater: creater,
  3104. Ctime: time.Now().Unix(),
  3105. Status: 1,
  3106. ReturnTime: item.RecordDate,
  3107. Type: 1,
  3108. StorehouseId: houseConfig.StorehouseOutInfo,
  3109. IsCheck: 1,
  3110. }
  3111. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3112. if msgerrkonde == gorm.ErrRecordNotFound {
  3113. service.AddSigleCancelStock(&cancelStock)
  3114. }
  3115. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3116. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3117. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3118. //查询该耗材是否出库
  3119. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3120. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3121. deaerler, _ := service.GetDealerById(info.Dealer)
  3122. var total_count int64
  3123. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3124. total_count += count
  3125. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3126. var flush_count int64
  3127. for _, it := range goodList {
  3128. flush_count += it.StockCount
  3129. }
  3130. fmt.Println("历史出库数据", info.Count)
  3131. fmt.Println("出库数量", total_count)
  3132. if info.ID > 0 {
  3133. cancelStockInfo := models.CancelStockInfo{
  3134. GoodId: item.ProjectId,
  3135. CancelStockId: cancel.ID,
  3136. GoodTypeId: good.GoodTypeId,
  3137. Count: prescribingNumber,
  3138. Price: info.Price,
  3139. Total: 0,
  3140. ProductDate: info.ProductDate,
  3141. ExpiryDate: info.ExpiryDate,
  3142. Ctime: time.Now().Unix(),
  3143. Status: 1,
  3144. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3145. OrderNumber: cancel.OrderNumber,
  3146. Type: 0,
  3147. Dealer: deaerler.DealerName,
  3148. Manufacturer: manufacturer.ManufacturerName,
  3149. Number: info.Number,
  3150. RegisterAccount: "",
  3151. Remark: "",
  3152. WarehouseInfoId: info.WarehouseInfotId,
  3153. PatientId: info.PatientId,
  3154. RecordDate: info.SysRecordTime,
  3155. StorehouseId: houseConfig.StorehouseOutInfo,
  3156. IsCheck: 1,
  3157. }
  3158. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3159. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3160. //查询出库数量
  3161. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  3162. //出库数据 大于 退库数量
  3163. if len(list) > 0 {
  3164. for _, it := range list {
  3165. //回退库存
  3166. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  3167. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3168. var flush_count_one int64
  3169. for _, it := range goodList {
  3170. flush_count_one += it.StockCount
  3171. }
  3172. //查询该批次是否有退库数据
  3173. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  3174. creater := c.GetAdminUserInfo().AdminUser.Id
  3175. flow := models.VmStockFlow{
  3176. WarehousingId: it.WarehouseInfotId,
  3177. GoodId: it.GoodId,
  3178. Number: it.Number,
  3179. LicenseNumber: it.LicenseNumber,
  3180. Count: it.Count,
  3181. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3182. PatientId: it.PatientId,
  3183. SystemTime: it.SysRecordTime,
  3184. ConsumableType: 7,
  3185. IsSys: 0,
  3186. WarehousingOrder: "",
  3187. WarehouseOutId: it.WarehouseOutId,
  3188. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  3189. IsEdit: 0,
  3190. CancelStockId: cancel.ID,
  3191. CancelOrderNumber: cancel.OrderNumber,
  3192. Manufacturer: manufacturer.ID,
  3193. Dealer: 0,
  3194. Creator: creater,
  3195. UpdateCreator: 0,
  3196. Status: 1,
  3197. Ctime: time.Now().Unix(),
  3198. Mtime: 0,
  3199. Price: it.Price,
  3200. WarehousingDetailId: it.WarehouseInfotId,
  3201. WarehouseOutDetailId: it.ID,
  3202. CancelOutDetailId: cancelInfo.ID,
  3203. ProductDate: it.ProductDate,
  3204. ExpireDate: it.ExpiryDate,
  3205. StorehouseId: houseConfig.StorehouseOutInfo,
  3206. OverCount: flush_count_one,
  3207. }
  3208. service.CreateStockFlowOne(flow)
  3209. //if flow.ID > 0 {
  3210. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  3211. //}
  3212. }
  3213. }
  3214. //flow := models.VmStockFlow{
  3215. // WarehousingId: info.WarehouseInfotId,
  3216. // GoodId: item.ProjectId,
  3217. // Number: info.Number,
  3218. // LicenseNumber: info.LicenseNumber,
  3219. // Count: prescribingNumber,
  3220. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3221. // PatientId: item.PatientId,
  3222. // SystemTime: info.SysRecordTime,
  3223. // ConsumableType: 7,
  3224. // IsSys: 0,
  3225. // WarehousingOrder: "",
  3226. // WarehouseOutId: info.WarehouseOutId,
  3227. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3228. // IsEdit: 0,
  3229. // CancelStockId: cancel.ID,
  3230. // CancelOrderNumber: cancel.OrderNumber,
  3231. // Manufacturer: manufacturer.ID,
  3232. // Dealer: 0,
  3233. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  3234. // UpdateCreator: 0,
  3235. // Status: 1,
  3236. // Ctime: time.Now().Unix(),
  3237. // Mtime: 0,
  3238. // Price: info.Price,
  3239. // WarehousingDetailId: info.WarehouseInfotId,
  3240. // WarehouseOutDetailId: info.ID,
  3241. // CancelOutDetailId: cancelInfo.ID,
  3242. // ProductDate: info.ProductDate,
  3243. // ExpireDate: info.ExpiryDate,
  3244. // StorehouseId: houseConfig.StorehouseOutInfo,
  3245. // OverCount: flush_count,
  3246. //}
  3247. //service.CreateStockFlowOne(flow)
  3248. //退库数量增加
  3249. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3250. //出库数量减少
  3251. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3252. //查询已出库数量
  3253. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3254. if prescribingNumber < dialysisInfo.Count {
  3255. //改变数量
  3256. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3257. }
  3258. if prescribingNumber >= dialysisInfo.Count {
  3259. //删除出库表
  3260. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3261. }
  3262. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3263. var flush_count_one int64
  3264. for _, it := range goodList {
  3265. flush_count_one += it.StockCount
  3266. }
  3267. //更新库存
  3268. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  3269. fmt.Println("msgerrkonde23332323", msgerrkonde)
  3270. //更新基础库库存
  3271. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  3272. }
  3273. }
  3274. }
  3275. }
  3276. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3277. fmt.Println(err)
  3278. }
  3279. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3280. fmt.Println(err)
  3281. if len(advices) > 0 {
  3282. for _, item := range advices {
  3283. redis := service.RedisClient()
  3284. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  3285. redis.Set(keyFive, "", time.Second)
  3286. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  3287. redis.Set(keyOne, "", time.Second)
  3288. redis.Close()
  3289. }
  3290. }
  3291. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3292. if len(advices) > 0 {
  3293. for _, item := range advices {
  3294. creater := c.GetAdminUserInfo().AdminUser.Id
  3295. service.DrugAutoAddCancelInfo(item, creater)
  3296. }
  3297. }
  3298. } else {
  3299. if drugOutConfig.IsOpen == 1 {
  3300. if len(advices) > 0 {
  3301. for _, item := range advices {
  3302. creater := c.GetAdminUserInfo().AdminUser.Id
  3303. service.DrugAutoAddCancelInfo(item, creater)
  3304. }
  3305. }
  3306. } else {
  3307. if len(advices) > 0 {
  3308. for _, item := range advices {
  3309. creater := c.GetAdminUserInfo().AdminUser.Id
  3310. service.DrugAutoAddCancelInfo(item, creater)
  3311. }
  3312. }
  3313. }
  3314. }
  3315. c.ServeSuccessJSON(map[string]interface{}{
  3316. "msg": "删除成功",
  3317. })
  3318. return
  3319. }
  3320. func (c *HisApiController) DeleteDoctorAdvice() {
  3321. id, _ := c.GetInt64("id")
  3322. advice, _ := service.GetHisDoctorAdvicesById(id)
  3323. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3324. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3325. //已收费和已发药的限制逻辑
  3326. isCharge := false
  3327. isMedicine := false
  3328. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3329. //获取今天该患者所有处方,判断是否发药或者收费
  3330. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3331. for _, item := range new_prescriptions {
  3332. if item.IsMedicine == 1 {
  3333. isMedicine = true
  3334. }
  3335. }
  3336. for _, item := range new_prescriptions {
  3337. if item.OrderStatus == 4 {
  3338. isCharge = true
  3339. }
  3340. }
  3341. if isMedicine {
  3342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3343. return
  3344. }
  3345. if isCharge {
  3346. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3347. return
  3348. }
  3349. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  3350. for _, item := range advices {
  3351. if item.IsMedicine == 1 {
  3352. isMedicine = true
  3353. }
  3354. }
  3355. if isMedicine {
  3356. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  3357. return
  3358. }
  3359. if new_prescription.ID > 0 {
  3360. if new_prescription.OrderStatus == 2 {
  3361. isCharge = true
  3362. }
  3363. }
  3364. if isCharge {
  3365. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3366. return
  3367. }
  3368. //已收费和已发药的限制逻辑
  3369. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  3370. redis := service.RedisClient()
  3371. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  3372. redis.Set(keyFive, "", time.Second)
  3373. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  3374. redis.Set(keyOne, "", time.Second)
  3375. defer redis.Close()
  3376. if err == nil {
  3377. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3378. //查询是否在处方中出库
  3379. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3380. if openConfig.IsOpen != 1 {
  3381. //判断该医嘱是否执行了
  3382. if advice.ExecutionState == 1 {
  3383. creater := c.GetAdminUserInfo().AdminUser.Id
  3384. service.DrugAutoAddCancelInfo(&advice, creater)
  3385. }
  3386. }
  3387. //开启保存处方扣减功能
  3388. if openConfig.IsOpen == 1 {
  3389. creater := c.GetAdminUserInfo().AdminUser.Id
  3390. service.DrugAutoAddCancelInfo(&advice, creater)
  3391. }
  3392. } else {
  3393. if drugOutConfig.IsOpen == 1 {
  3394. //查询是否在处方中出库
  3395. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3396. if openConfig.IsOpen != 1 {
  3397. //判断该医嘱是否执行了
  3398. if advice.ExecutionState == 1 {
  3399. creater := c.GetAdminUserInfo().AdminUser.Id
  3400. service.DrugAutoAddCancelInfo(&advice, creater)
  3401. }
  3402. }
  3403. //开启保存处方扣减功能
  3404. if openConfig.IsOpen == 1 {
  3405. creater := c.GetAdminUserInfo().AdminUser.Id
  3406. service.DrugAutoAddCancelInfo(&advice, creater)
  3407. }
  3408. } else {
  3409. //判断该医嘱是否执行了
  3410. if advice.ExecutionState == 1 {
  3411. creater := c.GetAdminUserInfo().AdminUser.Id
  3412. service.DrugAutoAddCancelInfo(&advice, creater)
  3413. }
  3414. }
  3415. }
  3416. c.ServeSuccessJSON(map[string]interface{}{
  3417. "msg": "删除成功",
  3418. })
  3419. return
  3420. } else {
  3421. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3422. return
  3423. }
  3424. }
  3425. func (c *HisApiController) DeleteProject() {
  3426. id, _ := c.GetInt64("id")
  3427. adminInfo := c.GetAdminUserInfo()
  3428. project, _ := service.GetHisProjectByID(id)
  3429. // var consumable models.DialysisBeforePrepare
  3430. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3431. //耗材保存处方出库
  3432. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3433. isCharge := false
  3434. isMedicine := false
  3435. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3436. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3437. for _, item := range new_prescriptions {
  3438. if item.IsMedicine == 1 {
  3439. isMedicine = true
  3440. }
  3441. }
  3442. for _, item := range new_prescriptions {
  3443. if item.OrderStatus == 4 {
  3444. isCharge = true
  3445. }
  3446. }
  3447. if isMedicine {
  3448. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3449. return
  3450. }
  3451. if isCharge {
  3452. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3453. return
  3454. }
  3455. if new_prescription.ID > 0 {
  3456. if new_prescription.OrderStatus == 2 {
  3457. isCharge = true
  3458. }
  3459. }
  3460. if isCharge {
  3461. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3462. return
  3463. }
  3464. service.DeletePrintInfo(id)
  3465. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  3466. label.Status = 0
  3467. service.CreateHisLabelRecord(&label)
  3468. fmt.Println(goodOutConfig.IsOpen)
  3469. if goodOutConfig.IsOpen != 1 {
  3470. if stockConfig.IsOpen == 1 {
  3471. if project.Type == 2 {
  3472. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3473. fmt.Println(err)
  3474. }
  3475. if project.Type == 3 && project.IsOut == 1 {
  3476. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3477. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3478. f_count, _ := strconv.ParseFloat(project.Count, 64)
  3479. operation_time := time.Now().Unix()
  3480. creater := adminInfo.AdminUser.Id
  3481. //创建退库单
  3482. timeStr := time.Now().Format("2006-01-02")
  3483. timeArr := strings.Split(timeStr, "-")
  3484. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  3485. total = total + 1
  3486. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3487. cancelStock := models.CancelStock{
  3488. OrderNumber: orderNumber,
  3489. OperaTime: operation_time,
  3490. OrgId: adminInfo.CurrentOrgId,
  3491. Creater: creater,
  3492. Ctime: time.Now().Unix(),
  3493. Status: 1,
  3494. ReturnTime: project.RecordDate,
  3495. Type: 1,
  3496. StorehouseId: houseConfig.StorehouseOutInfo,
  3497. IsCheck: 1,
  3498. }
  3499. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  3500. if msgerrkonde == gorm.ErrRecordNotFound {
  3501. service.AddSigleCancelStock(&cancelStock)
  3502. }
  3503. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  3504. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3505. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3506. //查询是否有出库
  3507. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  3508. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3509. deaerler, _ := service.GetDealerById(info.Dealer)
  3510. if info.ID > 0 {
  3511. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  3512. if info.Count >= prescribingNumber {
  3513. cancelStockInfo := models.CancelStockInfo{
  3514. GoodId: project.ProjectId,
  3515. CancelStockId: cancel.ID,
  3516. GoodTypeId: good.GoodTypeId,
  3517. Count: prescribingNumber,
  3518. Price: info.Price,
  3519. Total: 0,
  3520. ProductDate: info.ProductDate,
  3521. ExpiryDate: info.ExpiryDate,
  3522. Ctime: time.Now().Unix(),
  3523. Status: 1,
  3524. OrgId: adminInfo.CurrentOrgId,
  3525. OrderNumber: cancel.OrderNumber,
  3526. Type: 0,
  3527. Dealer: deaerler.DealerName,
  3528. Manufacturer: manufacturer.ManufacturerName,
  3529. Number: info.Number,
  3530. RegisterAccount: "",
  3531. Remark: "",
  3532. WarehouseInfoId: info.WarehouseInfotId,
  3533. PatientId: info.PatientId,
  3534. RecordDate: info.SysRecordTime,
  3535. StorehouseId: houseConfig.StorehouseOutInfo,
  3536. IsCheck: 1,
  3537. }
  3538. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3539. //回退库存
  3540. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  3541. //退库数量增加
  3542. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  3543. //出库数量减少
  3544. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  3545. }
  3546. if info.Count < prescribingNumber {
  3547. cancelStockInfo := models.CancelStockInfo{
  3548. GoodId: project.ProjectId,
  3549. CancelStockId: cancel.ID,
  3550. GoodTypeId: good.GoodTypeId,
  3551. Count: info.Count,
  3552. Price: info.Price,
  3553. Total: 0,
  3554. ProductDate: info.ProductDate,
  3555. ExpiryDate: info.ExpiryDate,
  3556. Ctime: time.Now().Unix(),
  3557. Status: 1,
  3558. OrgId: adminInfo.CurrentOrgId,
  3559. OrderNumber: cancel.OrderNumber,
  3560. Type: 0,
  3561. Dealer: deaerler.DealerName,
  3562. Manufacturer: manufacturer.ManufacturerName,
  3563. Number: info.Number,
  3564. RegisterAccount: "",
  3565. Remark: "",
  3566. WarehouseInfoId: info.WarehouseInfotId,
  3567. PatientId: info.PatientId,
  3568. RecordDate: info.SysRecordTime,
  3569. StorehouseId: houseConfig.StorehouseOutInfo,
  3570. IsCheck: 1,
  3571. }
  3572. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3573. //回退库存
  3574. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  3575. //退库数量增加
  3576. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3577. //出库数量减少
  3578. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  3579. }
  3580. //查询剩余库存
  3581. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3582. var over_count int64
  3583. for _, it := range goodList {
  3584. over_count += it.StockCount
  3585. }
  3586. //出库数据 大于 退库数量
  3587. if info.Count >= prescribingNumber {
  3588. flow := models.VmStockFlow{
  3589. WarehousingId: info.WarehouseInfotId,
  3590. GoodId: project.ProjectId,
  3591. Number: info.Number,
  3592. LicenseNumber: info.LicenseNumber,
  3593. Count: prescribingNumber,
  3594. UserOrgId: adminInfo.CurrentOrgId,
  3595. PatientId: project.PatientId,
  3596. SystemTime: info.SysRecordTime,
  3597. ConsumableType: 7,
  3598. IsSys: 0,
  3599. WarehousingOrder: "",
  3600. WarehouseOutId: info.WarehouseOutId,
  3601. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3602. IsEdit: 0,
  3603. CancelStockId: cancel.ID,
  3604. CancelOrderNumber: cancel.OrderNumber,
  3605. Manufacturer: manufacturer.ID,
  3606. Dealer: 0,
  3607. Creator: adminInfo.AdminUser.Id,
  3608. UpdateCreator: 0,
  3609. Status: 1,
  3610. Ctime: time.Now().Unix(),
  3611. Mtime: 0,
  3612. Price: info.Price,
  3613. WarehousingDetailId: info.WarehouseInfotId,
  3614. WarehouseOutDetailId: info.ID,
  3615. CancelOutDetailId: cancelInfo.ID,
  3616. ProductDate: info.ProductDate,
  3617. ExpireDate: info.ExpiryDate,
  3618. StorehouseId: houseConfig.StorehouseOutInfo,
  3619. OverCount: over_count,
  3620. }
  3621. service.CreateStockFlowOne(flow)
  3622. }
  3623. //出库数据小于退库数据
  3624. if info.Count < prescribingNumber {
  3625. flow := models.VmStockFlow{
  3626. WarehousingId: info.WarehouseInfotId,
  3627. GoodId: project.ProjectId,
  3628. Number: info.Number,
  3629. LicenseNumber: info.LicenseNumber,
  3630. Count: info.Count,
  3631. UserOrgId: adminInfo.CurrentOrgId,
  3632. PatientId: project.PatientId,
  3633. SystemTime: info.SysRecordTime,
  3634. ConsumableType: 7,
  3635. IsSys: 0,
  3636. WarehousingOrder: "",
  3637. WarehouseOutId: info.WarehouseOutId,
  3638. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3639. IsEdit: 0,
  3640. CancelStockId: cancel.ID,
  3641. CancelOrderNumber: cancel.OrderNumber,
  3642. Manufacturer: manufacturer.ID,
  3643. Dealer: 0,
  3644. Creator: adminInfo.AdminUser.Id,
  3645. UpdateCreator: 0,
  3646. Status: 1,
  3647. Ctime: time.Now().Unix(),
  3648. Mtime: 0,
  3649. Price: info.Price,
  3650. WarehousingDetailId: info.WarehouseInfotId,
  3651. WarehouseOutDetailId: info.ID,
  3652. CancelOutDetailId: cancelInfo.ID,
  3653. ProductDate: info.ProductDate,
  3654. ExpireDate: info.ExpiryDate,
  3655. StorehouseId: houseConfig.StorehouseOutInfo,
  3656. OverCount: over_count,
  3657. }
  3658. service.CreateStockFlowOne(flow)
  3659. }
  3660. //查询已出库数量
  3661. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  3662. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  3663. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  3664. if prescribingNumber < dialysisInfo.Count {
  3665. //改变数量
  3666. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  3667. }
  3668. if prescribingNumber >= dialysisInfo.Count {
  3669. //删除出库表
  3670. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  3671. }
  3672. //更新剩余库存
  3673. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  3674. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  3675. var total_count_one int64
  3676. for _, it := range stockList {
  3677. total_count_one += it.StockCount
  3678. }
  3679. //基础库插入数据
  3680. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  3681. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3682. var flush_count int64
  3683. for _, it := range goodListOne {
  3684. flush_count += it.StockCount
  3685. }
  3686. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  3687. if errs != nil {
  3688. goodErrcode := models.XtGoodErrcode{
  3689. UserOrgId: project.UserOrgId,
  3690. Errcode: "手动出库更新剩余出库失败",
  3691. GoodId: project.ProjectId,
  3692. Status: 1,
  3693. Ctime: time.Now().Unix(),
  3694. Mtime: 0,
  3695. Count: 0,
  3696. StockCount: 0,
  3697. Creater: creater,
  3698. BatchNumberId: 0,
  3699. WarehouseOutId: 0,
  3700. }
  3701. service.CreateGoodErrcode(goodErrcode)
  3702. }
  3703. }
  3704. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3705. fmt.Println(err)
  3706. } else {
  3707. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3708. fmt.Println(err)
  3709. }
  3710. } else {
  3711. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3712. fmt.Println(err)
  3713. }
  3714. }
  3715. //保存处方出库
  3716. if goodOutConfig.IsOpen == 1 {
  3717. if project.Type == 3 {
  3718. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3719. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3720. f_count, _ := strconv.ParseFloat(project.Count, 64)
  3721. operation_time := time.Now().Unix()
  3722. creater := adminInfo.AdminUser.Id
  3723. //创建退库单
  3724. timeStr := time.Now().Format("2006-01-02")
  3725. timeArr := strings.Split(timeStr, "-")
  3726. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  3727. total = total + 1
  3728. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3729. cancelStock := models.CancelStock{
  3730. OrderNumber: orderNumber,
  3731. OperaTime: operation_time,
  3732. OrgId: adminInfo.CurrentOrgId,
  3733. Creater: creater,
  3734. Ctime: time.Now().Unix(),
  3735. Status: 1,
  3736. ReturnTime: project.RecordDate,
  3737. Type: 1,
  3738. StorehouseId: houseConfig.StorehouseOutInfo,
  3739. IsCheck: 1,
  3740. }
  3741. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  3742. if msgerrkonde == gorm.ErrRecordNotFound {
  3743. service.AddSigleCancelStock(&cancelStock)
  3744. }
  3745. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  3746. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3747. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3748. //获取出库数据
  3749. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  3750. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3751. deaerler, _ := service.GetDealerById(info.Dealer)
  3752. if info.ID > 0 {
  3753. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  3754. if info.Count >= prescribingNumber {
  3755. cancelStockInfo := models.CancelStockInfo{
  3756. GoodId: project.ProjectId,
  3757. CancelStockId: cancel.ID,
  3758. GoodTypeId: good.GoodTypeId,
  3759. Count: prescribingNumber,
  3760. Price: info.Price,
  3761. Total: 0,
  3762. ProductDate: info.ProductDate,
  3763. ExpiryDate: info.ExpiryDate,
  3764. Ctime: time.Now().Unix(),
  3765. Status: 1,
  3766. OrgId: adminInfo.CurrentOrgId,
  3767. OrderNumber: cancel.OrderNumber,
  3768. Type: 0,
  3769. Dealer: deaerler.DealerName,
  3770. Manufacturer: manufacturer.ManufacturerName,
  3771. Number: info.Number,
  3772. RegisterAccount: "",
  3773. Remark: "",
  3774. WarehouseInfoId: info.WarehouseInfotId,
  3775. PatientId: info.PatientId,
  3776. RecordDate: info.SysRecordTime,
  3777. StorehouseId: houseConfig.StorehouseOutInfo,
  3778. IsCheck: 1,
  3779. }
  3780. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3781. //退库数量增加
  3782. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  3783. //出库数量减少
  3784. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  3785. }
  3786. if info.Count < prescribingNumber {
  3787. cancelStockInfo := models.CancelStockInfo{
  3788. GoodId: project.ProjectId,
  3789. CancelStockId: cancel.ID,
  3790. GoodTypeId: good.GoodTypeId,
  3791. Count: prescribingNumber,
  3792. Price: info.Price,
  3793. Total: 0,
  3794. ProductDate: info.ProductDate,
  3795. ExpiryDate: info.ExpiryDate,
  3796. Ctime: time.Now().Unix(),
  3797. Status: 1,
  3798. OrgId: adminInfo.CurrentOrgId,
  3799. OrderNumber: cancel.OrderNumber,
  3800. Type: 0,
  3801. Dealer: deaerler.DealerName,
  3802. Manufacturer: manufacturer.ManufacturerName,
  3803. Number: info.Number,
  3804. RegisterAccount: "",
  3805. Remark: "",
  3806. WarehouseInfoId: info.WarehouseInfotId,
  3807. PatientId: info.PatientId,
  3808. RecordDate: info.SysRecordTime,
  3809. StorehouseId: houseConfig.StorehouseOutInfo,
  3810. IsCheck: 1,
  3811. }
  3812. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3813. //回退库存
  3814. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  3815. }
  3816. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3817. var over_count int64
  3818. for _, it := range goodList {
  3819. over_count += it.StockCount
  3820. }
  3821. //查询出库数量
  3822. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  3823. //出库数据 大于 退库数量
  3824. if len(list) > 0 {
  3825. for _, it := range list {
  3826. //回退库存
  3827. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  3828. //退库数量增加
  3829. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  3830. //出库数量减少
  3831. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  3832. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3833. var over_count_one int64
  3834. for _, it := range goodList {
  3835. over_count_one += it.StockCount
  3836. }
  3837. //查询该批次是否有退库数据
  3838. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  3839. flow := models.VmStockFlow{
  3840. WarehousingId: it.WarehouseInfotId,
  3841. GoodId: it.GoodId,
  3842. Number: it.Number,
  3843. LicenseNumber: it.LicenseNumber,
  3844. Count: it.Count,
  3845. UserOrgId: adminInfo.CurrentOrgId,
  3846. PatientId: it.PatientId,
  3847. SystemTime: it.SysRecordTime,
  3848. ConsumableType: 7,
  3849. IsSys: 0,
  3850. WarehousingOrder: "",
  3851. WarehouseOutId: it.WarehouseOutId,
  3852. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  3853. IsEdit: 0,
  3854. CancelStockId: cancel.ID,
  3855. CancelOrderNumber: cancel.OrderNumber,
  3856. Manufacturer: manufacturer.ID,
  3857. Dealer: 0,
  3858. Creator: adminInfo.AdminUser.Id,
  3859. UpdateCreator: 0,
  3860. Status: 1,
  3861. Ctime: time.Now().Unix(),
  3862. Mtime: 0,
  3863. Price: it.Price,
  3864. WarehousingDetailId: it.WarehouseInfotId,
  3865. WarehouseOutDetailId: it.ID,
  3866. CancelOutDetailId: cancelInfo.ID,
  3867. ProductDate: it.ProductDate,
  3868. ExpireDate: it.ExpiryDate,
  3869. StorehouseId: houseConfig.StorehouseOutInfo,
  3870. OverCount: over_count_one,
  3871. }
  3872. service.CreateStockFlowOne(flow)
  3873. }
  3874. }
  3875. //查询已出库数量
  3876. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  3877. if prescribingNumber < dialysisInfo.Count {
  3878. //改变数量
  3879. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  3880. }
  3881. if prescribingNumber >= dialysisInfo.Count {
  3882. //删除出库表
  3883. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  3884. }
  3885. //更新剩余库存
  3886. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  3887. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  3888. var total_count_one int64
  3889. for _, it := range stockList {
  3890. total_count_one += it.StockCount
  3891. }
  3892. //基础库插入数据
  3893. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  3894. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3895. var flush_count int64
  3896. for _, it := range goodListOne {
  3897. flush_count += it.StockCount
  3898. }
  3899. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  3900. if errs != nil {
  3901. goodErrcode := models.XtGoodErrcode{
  3902. UserOrgId: project.UserOrgId,
  3903. Errcode: "手动出库更新剩余出库失败",
  3904. GoodId: project.ProjectId,
  3905. Status: 1,
  3906. Ctime: time.Now().Unix(),
  3907. Mtime: 0,
  3908. Count: 0,
  3909. StockCount: 0,
  3910. Creater: creater,
  3911. BatchNumberId: 0,
  3912. WarehouseOutId: 0,
  3913. }
  3914. service.CreateGoodErrcode(goodErrcode)
  3915. }
  3916. }
  3917. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3918. fmt.Println(err)
  3919. } else {
  3920. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3921. fmt.Println(err)
  3922. }
  3923. }
  3924. c.ServeSuccessJSON(map[string]interface{}{
  3925. "msg": "删除成功",
  3926. })
  3927. return
  3928. }
  3929. func (c *HisApiController) CreateHisAdditionalCharge() {
  3930. his_patient_id, _ := c.GetInt64("his_patient_id")
  3931. patient_id, _ := c.GetInt64("patient_id")
  3932. record_date := c.GetString("record_date")
  3933. timeLayout := "2006-01-02"
  3934. loc, _ := time.LoadLocation("Local")
  3935. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3936. if err != nil {
  3937. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3938. return
  3939. }
  3940. adminInfo := c.GetAdminUserInfo()
  3941. recordDateTime := theTime.Unix()
  3942. dataBody := make(map[string]interface{}, 0)
  3943. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3944. if err != nil {
  3945. utils.ErrorLog(err.Error())
  3946. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3947. return
  3948. }
  3949. var additions []*models.HisAdditionalCharge
  3950. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  3951. additions, _ := dataBody["addition"].([]interface{})
  3952. if len(additions) > 0 {
  3953. for _, item := range additions {
  3954. items := item.(map[string]interface{})
  3955. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  3956. utils.ErrorLog("item_id")
  3957. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3958. return
  3959. }
  3960. item_id := int64(items["item_id"].(float64))
  3961. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  3962. utils.ErrorLog("item_name")
  3963. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3964. return
  3965. }
  3966. item_name := items["item_name"].(string)
  3967. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  3968. utils.ErrorLog("price")
  3969. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3970. return
  3971. }
  3972. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  3973. ctime := time.Now().Unix()
  3974. additional := &models.HisAdditionalCharge{
  3975. PatientId: patient_id,
  3976. HisPatientId: his_patient_id,
  3977. UserOrgId: adminInfo.CurrentOrgId,
  3978. RecordDate: recordDateTime,
  3979. CreatedTime: ctime,
  3980. UpdatedTime: ctime,
  3981. Modifier: adminInfo.AdminUser.Id,
  3982. Creator: adminInfo.AdminUser.Id,
  3983. Price: price,
  3984. ItemName: item_name,
  3985. ItemId: item_id,
  3986. Status: 1,
  3987. }
  3988. additions = append(additions, additional)
  3989. }
  3990. }
  3991. }
  3992. for _, item := range additions {
  3993. service.CreateAddtionalCharge(item)
  3994. }
  3995. c.ServeSuccessJSON(map[string]interface{}{
  3996. "msg": "创建成功",
  3997. })
  3998. }
  3999. func (c *HisApiController) CreateHisPatientCaseHistory() {
  4000. blood_fat := c.GetString("blood_fat")
  4001. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  4002. blood_sugar := c.GetString("blood_sugar")
  4003. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  4004. chief_conplaint := c.GetString("chief_conplaint")
  4005. dbp := c.GetString("dbp")
  4006. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  4007. delivery_way, _ := c.GetInt64("delivery_way")
  4008. diagnostic := c.GetString("diagnostic")
  4009. family_history := c.GetString("family_history")
  4010. height := c.GetString("height")
  4011. history_of_present_illness := c.GetString("history_of_present_illness")
  4012. is_infect, _ := c.GetInt64("is_infect")
  4013. past_history := c.GetString("past_history")
  4014. patient_id, _ := c.GetInt64("patient_id")
  4015. his_patient_id, _ := c.GetInt64("his_patient_id")
  4016. personal_history := c.GetString("personal_history")
  4017. pulse := c.GetString("pulse")
  4018. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  4019. sbp := c.GetString("sbp")
  4020. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  4021. heightfloat, _ := strconv.ParseFloat(height, 64)
  4022. sicktype := c.GetString("sick_type")
  4023. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  4024. symptom := c.GetString("symptom")
  4025. sick_date := c.GetString("sick_date")
  4026. temperatures := c.GetString("temperature")
  4027. temperature, _ := strconv.ParseFloat(temperatures, 64)
  4028. record_date := c.GetString("record_date")
  4029. breathing := c.GetString("breathing")
  4030. doctor_advice := c.GetString("doctor_advice")
  4031. remark := c.GetString("remark")
  4032. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  4033. sick, _ := c.GetInt64("sick")
  4034. diagnose, _ := c.GetInt64("diagnose")
  4035. //id, _ := c.GetInt64("id")
  4036. timeLayout := "2006-01-02"
  4037. loc, _ := time.LoadLocation("Local")
  4038. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4039. allergic_history := c.GetString("allergic_history")
  4040. if err != nil {
  4041. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4042. return
  4043. }
  4044. recordDateTime := theTime.Unix()
  4045. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  4046. if err != nil {
  4047. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4048. return
  4049. }
  4050. sickTimes := sickTime.Unix()
  4051. ctime := time.Now().Unix()
  4052. primary_disease := c.GetString("primary_disease")
  4053. confirm_failure_date := c.GetString("confirm_failure_date")
  4054. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  4055. drug_allergy_history := c.GetString("drug_allergy_history")
  4056. physical_examination := c.GetString("physical_examination")
  4057. special_inspection := c.GetString("special_inspection")
  4058. lab_apparatus := c.GetString("lab_apparatus")
  4059. caseHistory := models.HisPatientCaseHistory{
  4060. HisPatientId: his_patient_id,
  4061. PatientId: patient_id,
  4062. Temperature: temperature,
  4063. BloodSugar: bloodsugarfloat,
  4064. Pulse: pulsefloat,
  4065. Sbp: sbpfloat,
  4066. Dbp: dbpfloat,
  4067. Height: heightfloat,
  4068. BloodFat: bloodfatfloat,
  4069. SickType: sick_type,
  4070. Symptom: symptom,
  4071. SickDate: sickTimes,
  4072. IsInfect: is_infect,
  4073. HistoryOfPresentIllness: history_of_present_illness,
  4074. PastHistory: past_history,
  4075. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  4076. ChiefConplaint: chief_conplaint,
  4077. PersonalHistory: personal_history,
  4078. FamilyHistory: family_history,
  4079. Diagnostic: diagnostic,
  4080. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4081. Status: 1,
  4082. Ctime: ctime,
  4083. Mtime: ctime,
  4084. RecordDate: recordDateTime,
  4085. DeliveryWay: delivery_way,
  4086. Breathing: breathingfloat,
  4087. DoctorAdvice: doctor_advice,
  4088. Remark: remark,
  4089. Sick: sick,
  4090. Diagnose: diagnose,
  4091. AllergicHistory: allergic_history,
  4092. PrimaryDisease: primary_disease,
  4093. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  4094. DrugAllergyHistory: drug_allergy_history,
  4095. PhysicalExamination: physical_examination,
  4096. SpecialInspection: special_inspection,
  4097. LabApparatus: lab_apparatus,
  4098. }
  4099. //查询该患者是否有病历
  4100. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  4101. if errcodes == gorm.ErrRecordNotFound {
  4102. err = service.SaveHisPatientCaseHistory(&caseHistory)
  4103. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4104. if err != nil {
  4105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4106. return
  4107. }
  4108. c.ServeSuccessJSON(map[string]interface{}{
  4109. "caseHistory": caseHistory,
  4110. "historyInfo": historyInfo,
  4111. })
  4112. return
  4113. } else if errcodes == nil {
  4114. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  4115. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4116. if err != nil {
  4117. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4118. return
  4119. }
  4120. c.ServeSuccessJSON(map[string]interface{}{
  4121. "caseHistory": caseHistory,
  4122. "historyInfo": historyInfo,
  4123. })
  4124. }
  4125. //查询该患者是否有病历
  4126. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  4127. //if errcode == gorm.ErrRecordNotFound {
  4128. // err = service.SaveHisPatientCaseHistory(caseHistory)
  4129. // if err != nil {
  4130. // c.ServeSuccessJSON(map[string]interface{}{
  4131. // "msg": "保存成功",
  4132. // })
  4133. // }
  4134. //} else if errcode == nil {
  4135. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4136. // return
  4137. //}
  4138. }
  4139. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  4140. patient_id, _ := c.GetInt64("patient_id", 0)
  4141. adminUser := c.GetAdminUserInfo()
  4142. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  4143. c.ServeSuccessJSON(map[string]interface{}{
  4144. "list": caseHistorys,
  4145. })
  4146. }
  4147. func (c *HisApiController) GetHisPatientCaseHistory() {
  4148. record_date, _ := c.GetInt64("record_date", 0)
  4149. patient_id, _ := c.GetInt64("patient_id", 0)
  4150. admin := c.GetAdminUserInfo()
  4151. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  4152. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  4153. c.ServeSuccessJSON(map[string]interface{}{
  4154. "info": info,
  4155. "case_history": case_history,
  4156. })
  4157. }
  4158. func (c *HisApiController) CreateCaseHistoryTemplate() {
  4159. template_name := c.GetString("template_name")
  4160. template_remark := c.GetString("template_remark")
  4161. doctor := c.GetAdminUserInfo().AdminUser.Id
  4162. diagnostic := c.GetString("diagnostic")
  4163. chief_conplaint := c.GetString("chief_conplain")
  4164. history_of_present_illness := c.GetString("history_of_present_illness")
  4165. past_history := c.GetString("past_history")
  4166. personal_history := c.GetString("personal_history")
  4167. family_history := c.GetString("family_history")
  4168. user_name := c.GetString("user_name")
  4169. doctor_advice := c.GetString("doctor_advice")
  4170. remark := c.GetString("remark")
  4171. //record_date := c.GetString("record_date")
  4172. //fmt.Println("record_date--------",record_date)
  4173. //timeLayout := "2006-01-02"
  4174. //loc, _ := time.LoadLocation("Local")
  4175. //
  4176. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4177. //if err != nil {
  4178. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4179. // return
  4180. //}
  4181. //recordDateTime := theTime.Unix()
  4182. ctime := time.Now().Unix()
  4183. template := models.HisCaseHistoryTemplate{
  4184. HistoryOfPresentIllness: history_of_present_illness,
  4185. PastHistory: past_history,
  4186. ChiefConplaint: chief_conplaint,
  4187. PersonalHistory: personal_history,
  4188. FamilyHistory: family_history,
  4189. Diagnostic: diagnostic,
  4190. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4191. Status: 1,
  4192. Ctime: ctime,
  4193. Mtime: ctime,
  4194. RecordDate: time.Now().Unix(),
  4195. TemplateName: template_name,
  4196. TemplateRemark: template_remark,
  4197. Creator: doctor,
  4198. Modifier: doctor,
  4199. UserName: user_name,
  4200. DoctorAdvice: doctor_advice,
  4201. Remark: remark,
  4202. }
  4203. err := service.SaveHisPatientCaseHistoryTemplate(template)
  4204. if err == nil {
  4205. c.ServeSuccessJSON(map[string]interface{}{
  4206. "msg": "保存成功",
  4207. })
  4208. } else {
  4209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4210. return
  4211. }
  4212. }
  4213. func (c *HisApiController) GetCaseHistoryTemplate() {
  4214. timeLayout := "2006-01-02"
  4215. loc, _ := time.LoadLocation("Local")
  4216. keyword := c.GetString("keyword")
  4217. start_time := c.GetString("start_time")
  4218. end_time := c.GetString("end_time")
  4219. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4220. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4221. admin := c.GetAdminUserInfo()
  4222. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  4223. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  4224. c.ServeSuccessJSON(map[string]interface{}{
  4225. "template": template,
  4226. //"history": history,
  4227. })
  4228. }
  4229. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4230. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4231. utils.ErrorLog("drug_name")
  4232. return enums.ErrorCodeParamWrong
  4233. }
  4234. adviceName, _ := json["drug_name"].(string)
  4235. if len(adviceName) == 0 {
  4236. utils.ErrorLog("len(advice_name) == 0")
  4237. return enums.ErrorCodeParamWrong
  4238. }
  4239. advice.AdviceName = adviceName
  4240. adviceDesc, _ := json["advice_desc"].(string)
  4241. advice.AdviceDesc = adviceDesc
  4242. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4243. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4244. advice.DrugSpec = drugSpec
  4245. }
  4246. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4247. remark, _ := json["remark"].(string)
  4248. advice.Remark = remark
  4249. }
  4250. if json["id"] == nil {
  4251. advice.DrugId = 0
  4252. } else {
  4253. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4254. drug_id := int64(json["id"].(float64))
  4255. advice.DrugId = drug_id
  4256. }
  4257. }
  4258. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4259. advice_id := int64(json["advice_id"].(float64))
  4260. advice.ID = advice_id
  4261. if advice.ID > 0 {
  4262. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4263. if err == nil {
  4264. if hisAdvice.ID > 0 {
  4265. advice.ExecutionTime = hisAdvice.ExecutionTime
  4266. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4267. advice.ExecutionState = hisAdvice.ExecutionState
  4268. advice.CheckTime = hisAdvice.CheckTime
  4269. advice.Checker = hisAdvice.Checker
  4270. advice.CheckState = hisAdvice.CheckState
  4271. advice.StartTime = hisAdvice.StartTime
  4272. advice.FeedetlSn = hisAdvice.FeedetlSn
  4273. }
  4274. }
  4275. }
  4276. }
  4277. //
  4278. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4279. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4280. // advice.ExecutionTime = execution_time
  4281. //}
  4282. //
  4283. //
  4284. //
  4285. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  4286. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  4287. // advice.ExecutionStaff = execution_staff
  4288. //}
  4289. //
  4290. //
  4291. //
  4292. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  4293. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  4294. // advice.ExecutionState = execution_state
  4295. //}
  4296. //
  4297. //
  4298. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  4299. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  4300. // advice.CheckTime = check_time
  4301. //}
  4302. //
  4303. //
  4304. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  4305. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  4306. // advice.CheckState = check_state
  4307. //}
  4308. //
  4309. //
  4310. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  4311. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  4312. // advice.Checker = checker
  4313. //}
  4314. //
  4315. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  4316. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  4317. // advice.StartTime = start_time
  4318. //}
  4319. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4320. drugSpecUnit, _ := json["min_unit"].(string)
  4321. advice.DrugSpecUnit = drugSpecUnit
  4322. }
  4323. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4324. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4325. advice.SingleDose = singleDose
  4326. }
  4327. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4328. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4329. advice.SingleDoseUnit = singleDoseUnit
  4330. }
  4331. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4332. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4333. advice.PrescribingNumber = prescribingNumber
  4334. }
  4335. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4336. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4337. advice.PrescribingNumberUnit = prescribingNumberUnit
  4338. }
  4339. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4340. deliveryWay, _ := json["delivery_way"].(string)
  4341. advice.DeliveryWay = deliveryWay
  4342. }
  4343. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4344. executionFrequency, _ := json["execution_frequency"].(string)
  4345. advice.ExecutionFrequency = executionFrequency
  4346. }
  4347. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4348. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4349. advice.Price = price
  4350. }
  4351. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4352. med_list_codg, _ := json["medical_insurance_number"].(string)
  4353. advice.MedListCodg = med_list_codg
  4354. }
  4355. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4356. day := int64(json["day"].(float64))
  4357. advice.Day = day
  4358. }
  4359. return 0
  4360. }
  4361. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  4362. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4363. id := int64(json["id"].(float64))
  4364. project.ID = id
  4365. historyProject, _ := service.GetHisProjectByID(id)
  4366. project.FeedetlSn = historyProject.FeedetlSn
  4367. }
  4368. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4369. project_id := int64(json["project_id"].(float64))
  4370. project.ProjectId = project_id
  4371. }
  4372. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4373. // price := int64(json["price"].(float64))
  4374. // formatInt_price := strconv.FormatInt(price, 10)
  4375. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4376. // project.Price = float_price
  4377. // }
  4378. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4379. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4380. project.Price = price
  4381. }
  4382. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  4383. total, _ := json["total"].(string)
  4384. project.Count = total
  4385. }
  4386. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  4387. medical_code, _ := json["medical_code"].(string)
  4388. project.MedListCodg = medical_code
  4389. }
  4390. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4391. single_dose, _ := json["single_dose"].(string)
  4392. project.SingleDose = single_dose
  4393. }
  4394. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4395. delivery_way, _ := json["delivery_way"].(string)
  4396. project.DeliveryWay = delivery_way
  4397. }
  4398. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4399. execution_frequency, _ := json["execution_frequency"].(string)
  4400. project.ExecutionFrequency = execution_frequency
  4401. }
  4402. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4403. remark, _ := json["remark"].(string)
  4404. project.Remark = remark
  4405. }
  4406. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  4407. day, _ := json["number_days"].(string)
  4408. project.Day = day
  4409. }
  4410. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  4411. unit, _ := json["unit"].(string)
  4412. project.Unit = unit
  4413. }
  4414. return 0
  4415. }
  4416. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  4417. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4418. id := int64(json["id"].(float64))
  4419. historyAddtions, _ := service.GetHisAdditionByID(id)
  4420. additionalCharge.ID = id
  4421. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  4422. }
  4423. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  4424. item_id := int64(json["item_id"].(float64))
  4425. additionalCharge.ItemId = item_id
  4426. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  4427. if config.ID > 0 {
  4428. if len(config.Code) > 0 {
  4429. additionalCharge.MedListCodg = config.Code
  4430. }
  4431. }
  4432. }
  4433. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4434. // price := int64(json["price"].(float64))
  4435. // formatInt_price := strconv.FormatInt(price, 10)
  4436. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4437. // additionalCharge.Price = float_price
  4438. // }
  4439. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4440. // price := int64(json["price"].(float64))
  4441. // formatInt_price := strconv.FormatInt(price, 10)
  4442. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4443. // additionalCharge.Price = float_price
  4444. //}
  4445. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4446. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4447. additionalCharge.Price = price
  4448. }
  4449. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  4450. count, _ := json["count"].(string)
  4451. counts, _ := strconv.ParseInt(count, 10, 64)
  4452. additionalCharge.Count = counts
  4453. }
  4454. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  4455. item_name, _ := json["item_name"].(string)
  4456. additionalCharge.ItemName = item_name
  4457. }
  4458. return 0
  4459. }
  4460. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4461. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4462. utils.ErrorLog("drug_name")
  4463. return enums.ErrorCodeParamWrong
  4464. }
  4465. adviceName, _ := json["drug_name"].(string)
  4466. if len(adviceName) == 0 {
  4467. utils.ErrorLog("len(advice_name) == 0")
  4468. return enums.ErrorCodeParamWrong
  4469. }
  4470. advice.AdviceName = adviceName
  4471. adviceDesc, _ := json["advice_desc"].(string)
  4472. advice.AdviceDesc = adviceDesc
  4473. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4474. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4475. advice.DrugSpec = drugSpec
  4476. }
  4477. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4478. remark, _ := json["remark"].(string)
  4479. advice.Remark = remark
  4480. }
  4481. if json["id"] == nil {
  4482. advice.DrugId = 0
  4483. } else {
  4484. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4485. drug_id := int64(json["id"].(float64))
  4486. advice.DrugId = drug_id
  4487. }
  4488. }
  4489. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  4490. groupno := int64(json["groupno"].(float64))
  4491. advice.Groupno = groupno
  4492. }
  4493. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  4494. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  4495. advice.HospApprFlag = hosp_appr_flag
  4496. }
  4497. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4498. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4499. advice.PrescribingNumber = prescribingNumber
  4500. }
  4501. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  4502. // frequency_type := int64(json["frequency_type"].(float64))
  4503. // advice.FrequencyType = frequency_type
  4504. //}
  4505. //
  4506. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  4507. // day_count := int64(json["day_count"].(float64))
  4508. // advice.DayCount = day_count
  4509. //}
  4510. //
  4511. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  4512. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  4513. // week_day, _ := json["week_day"].(string)
  4514. // advice.WeekDay = week_day
  4515. //}
  4516. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4517. drugSpecUnit, _ := json["min_unit"].(string)
  4518. advice.DrugSpecUnit = drugSpecUnit
  4519. }
  4520. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4521. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4522. advice.SingleDose = singleDose
  4523. }
  4524. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4525. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4526. advice.SingleDoseUnit = singleDoseUnit
  4527. }
  4528. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4529. deliveryWay, _ := json["delivery_way"].(string)
  4530. advice.DeliveryWay = deliveryWay
  4531. }
  4532. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4533. executionFrequency, _ := json["execution_frequency"].(string)
  4534. advice.ExecutionFrequency = executionFrequency
  4535. }
  4536. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4537. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4538. advice.Price = price
  4539. }
  4540. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4541. med_list_codg, _ := json["medical_insurance_number"].(string)
  4542. advice.MedListCodg = med_list_codg
  4543. }
  4544. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4545. day := int64(json["day"].(float64))
  4546. advice.Day = day
  4547. }
  4548. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4549. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4550. advice.PrescribingNumberUnit = prescribingNumberUnit
  4551. }
  4552. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4553. advice_id := int64(json["advice_id"].(float64))
  4554. advice.ID = advice_id
  4555. if advice.ID > 0 {
  4556. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4557. if err == nil {
  4558. if hisAdvice.ID > 0 {
  4559. advice.ExecutionTime = hisAdvice.ExecutionTime
  4560. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4561. advice.ExecutionState = hisAdvice.ExecutionState
  4562. advice.CheckTime = hisAdvice.CheckTime
  4563. advice.Checker = hisAdvice.Checker
  4564. advice.CheckState = hisAdvice.CheckState
  4565. advice.StartTime = hisAdvice.StartTime
  4566. advice.HospApprFlag = hisAdvice.HospApprFlag
  4567. advice.IsMedicine = hisAdvice.IsMedicine
  4568. if hisAdvice.UserOrgId == 10028 {
  4569. 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 {
  4570. advice.ExecutionTime = 0
  4571. advice.ExecutionStaff = 0
  4572. advice.ExecutionState = 2
  4573. advice.CheckTime = 0
  4574. advice.Checker = 0
  4575. advice.CheckState = 2
  4576. }
  4577. } else {
  4578. 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 {
  4579. advice.ExecutionTime = 0
  4580. advice.ExecutionStaff = 0
  4581. advice.ExecutionState = 2
  4582. advice.CheckTime = 0
  4583. advice.Checker = 0
  4584. advice.CheckState = 2
  4585. }
  4586. }
  4587. //advice.Groupno = hisAdvice.Groupno
  4588. }
  4589. }
  4590. }
  4591. }
  4592. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  4593. //
  4594. //if drugStockConfig.IsOpen == 1 {
  4595. //
  4596. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  4597. // if advice.ID == 0 { //医嘱不存在
  4598. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  4599. // drug.Total = drug.Total - advice.PrescribingNumber
  4600. // service.UpdateBaseDrugLib(&drug)
  4601. //
  4602. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  4603. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  4604. // drug.Total = drug.Total - num
  4605. // service.UpdateBaseDrugLib(&drug)
  4606. // }
  4607. //
  4608. // } else if advice.ID > 0 { //医嘱存在
  4609. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  4610. // var num float64
  4611. //
  4612. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  4613. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  4614. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  4615. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  4616. // drug.Total = drug.Total + num
  4617. // service.UpdateBaseDrugLib(&drug)
  4618. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  4619. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  4620. // drug.Total = drug.Total - num
  4621. // service.UpdateBaseDrugLib(&drug)
  4622. // }
  4623. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  4624. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  4625. // if num2 > advice.PrescribingNumber {
  4626. // num = num2 - advice.PrescribingNumber
  4627. // drug.Total = drug.Total + num
  4628. // service.UpdateBaseDrugLib(&drug)
  4629. // } else if num2 < advice.PrescribingNumber {
  4630. // num = advice.PrescribingNumber - num2
  4631. // drug.Total = drug.Total - num
  4632. // service.UpdateBaseDrugLib(&drug)
  4633. // }
  4634. //
  4635. // }
  4636. //
  4637. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  4638. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  4639. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  4640. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  4641. // if num1 > num2 {
  4642. // num = num1 - num2
  4643. // drug.Total = drug.Total + num
  4644. // service.UpdateBaseDrugLib(&drug)
  4645. // } else if num1 < num2 {
  4646. // num = num2 - num1
  4647. // drug.Total = drug.Total - num
  4648. // service.UpdateBaseDrugLib(&drug)
  4649. // }
  4650. //
  4651. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  4652. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  4653. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  4654. // if hisAdvice.PrescribingNumber > num2 {
  4655. // num = hisAdvice.PrescribingNumber - num2
  4656. // drug.Total = drug.Total + num
  4657. // service.UpdateBaseDrugLib(&drug)
  4658. // } else if num2 < advice.PrescribingNumber {
  4659. // num = num2 - hisAdvice.PrescribingNumber
  4660. // drug.Total = drug.Total - num
  4661. // service.UpdateBaseDrugLib(&drug)
  4662. // }
  4663. //
  4664. // }
  4665. // }
  4666. // }
  4667. //}
  4668. //
  4669. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4670. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4671. // advice.ExecutionTime = execution_time
  4672. //}
  4673. //
  4674. //
  4675. //
  4676. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  4677. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  4678. // advice.ExecutionStaff = execution_staff
  4679. //}
  4680. //
  4681. //
  4682. //
  4683. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  4684. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  4685. // advice.ExecutionState = execution_state
  4686. //}
  4687. //
  4688. //
  4689. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  4690. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  4691. // advice.CheckTime = check_time
  4692. //}
  4693. //
  4694. //
  4695. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  4696. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  4697. // advice.CheckState = check_state
  4698. //}
  4699. //
  4700. //
  4701. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  4702. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  4703. // advice.Checker = checker
  4704. //}
  4705. //
  4706. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  4707. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  4708. // advice.StartTime = start_time
  4709. //}
  4710. return 0
  4711. }
  4712. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  4713. project.ExecutionStaff = 0
  4714. project.ExecutionState = 2
  4715. project.ExecutionTime = 0
  4716. project.Checker = 0
  4717. project.CheckState = 2
  4718. project.CheckTime = 0
  4719. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4720. id := int64(json["id"].(float64))
  4721. project.ID = id
  4722. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  4723. project.ExecutionStaff = temp_project.ExecutionStaff
  4724. project.ExecutionState = temp_project.ExecutionState
  4725. project.ExecutionTime = temp_project.ExecutionTime
  4726. project.Checker = temp_project.Checker
  4727. project.CheckState = temp_project.CheckState
  4728. project.CheckTime = temp_project.CheckTime
  4729. project.TeamId = temp_project.TeamId
  4730. }
  4731. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  4732. types := int64(json["type"].(float64))
  4733. project.Type = types
  4734. }
  4735. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4736. project_id := int64(json["project_id"].(float64))
  4737. project.ProjectId = project_id
  4738. }
  4739. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  4740. team_id := int64(json["team_id"].(float64))
  4741. project.TeamId = team_id
  4742. }
  4743. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4744. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4745. project.Price = price
  4746. }
  4747. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  4748. total, _ := json["total"].(string)
  4749. //totals, _ := strconv.ParseInt(total, 10, 64)
  4750. project.Count = total
  4751. }
  4752. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  4753. medical_code, _ := json["medical_code"].(string)
  4754. project.MedListCodg = medical_code
  4755. }
  4756. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4757. single_dose, _ := json["single_dose"].(string)
  4758. project.SingleDose = single_dose
  4759. }
  4760. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4761. delivery_way, _ := json["delivery_way"].(string)
  4762. project.DeliveryWay = delivery_way
  4763. }
  4764. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4765. execution_frequency, _ := json["execution_frequency"].(string)
  4766. project.ExecutionFrequency = execution_frequency
  4767. }
  4768. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4769. remark, _ := json["remark"].(string)
  4770. project.Remark = remark
  4771. }
  4772. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  4773. day, _ := json["number_days"].(string)
  4774. project.Day = day
  4775. }
  4776. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  4777. unit, _ := json["unit"].(string)
  4778. project.Unit = unit
  4779. }
  4780. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  4781. // frequency_type := int64(json["frequency_type"].(float64))
  4782. // project.FrequencyType = frequency_type
  4783. //}
  4784. //
  4785. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  4786. // day_count := int64(json["day_count"].(float64))
  4787. // project.DayCount = day_count
  4788. //}
  4789. //
  4790. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  4791. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  4792. // week_day, _ := json["week_day"].(string)
  4793. // project.WeekDay = week_day
  4794. //}
  4795. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  4796. //
  4797. //if project.ID == 0 {
  4798. // if stockConfig.IsOpen == 1 {
  4799. // if project.Type == 3 {
  4800. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4801. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  4802. // good.Total = good.Total - f_count
  4803. // service.UpdateGoodInfo(&good)
  4804. // }
  4805. // }
  4806. //
  4807. //} else {
  4808. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  4809. //
  4810. // if stockConfig.IsOpen == 1 {
  4811. // if project.Type == 3 {
  4812. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4813. // if project.Count < temp_project.Count {
  4814. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  4815. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  4816. //
  4817. // other_count := f_count_two - f_count_one
  4818. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  4819. // good.Total = good.Total + other_count_two
  4820. // service.UpdateGoodInfo(&good)
  4821. // } else if project.Count > temp_project.Count {
  4822. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  4823. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  4824. //
  4825. // other_count := f_count_one - f_count_two
  4826. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  4827. // good.Total = good.Total - other_count_two
  4828. // service.UpdateGoodInfo(&good)
  4829. // }
  4830. //
  4831. // }
  4832. // }
  4833. //
  4834. //}
  4835. return 0
  4836. }
  4837. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  4838. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4839. id := int64(json["id"].(float64))
  4840. additionalCharge.ID = id
  4841. }
  4842. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  4843. item_id := int64(json["item_id"].(float64))
  4844. additionalCharge.ItemId = item_id
  4845. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  4846. if config.ID > 0 {
  4847. if len(config.Code) > 0 {
  4848. additionalCharge.MedListCodg = config.Code
  4849. }
  4850. }
  4851. }
  4852. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4853. // price := int64(json["price"].(float64))
  4854. // formatInt_price := strconv.FormatInt(price, 10)
  4855. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4856. // additionalCharge.Price = float_price
  4857. // }
  4858. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4859. // price := int64(json["price"].(float64))
  4860. // formatInt_price := strconv.FormatInt(price, 10)
  4861. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4862. // additionalCharge.Price = float_price
  4863. //}
  4864. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4865. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4866. additionalCharge.Price = price
  4867. }
  4868. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  4869. count, _ := json["count"].(string)
  4870. counts, _ := strconv.ParseInt(count, 10, 64)
  4871. additionalCharge.Count = counts
  4872. }
  4873. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  4874. item_name, _ := json["item_name"].(string)
  4875. additionalCharge.ItemName = item_name
  4876. }
  4877. return 0
  4878. }
  4879. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  4880. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4881. utils.ErrorLog("drug_name")
  4882. return enums.ErrorCodeParamWrong
  4883. }
  4884. adviceName, _ := json["drug_name"].(string)
  4885. if len(adviceName) == 0 {
  4886. utils.ErrorLog("len(advice_name) == 0")
  4887. return enums.ErrorCodeParamWrong
  4888. }
  4889. advice.AdviceName = adviceName
  4890. adviceDesc, _ := json["advice_desc"].(string)
  4891. advice.AdviceDesc = adviceDesc
  4892. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4893. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4894. advice.DrugSpec = drugSpec
  4895. }
  4896. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4897. remark, _ := json["remark"].(string)
  4898. advice.Remark = remark
  4899. }
  4900. if json["id"] == nil {
  4901. advice.DrugId = 0
  4902. } else {
  4903. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4904. drug_id := int64(json["id"].(float64))
  4905. advice.DrugId = drug_id
  4906. }
  4907. }
  4908. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4909. drugSpecUnit, _ := json["min_unit"].(string)
  4910. advice.DrugSpecUnit = drugSpecUnit
  4911. }
  4912. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4913. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4914. advice.SingleDose = singleDose
  4915. }
  4916. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4917. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4918. advice.SingleDoseUnit = singleDoseUnit
  4919. }
  4920. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4921. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4922. advice.PrescribingNumber = prescribingNumber
  4923. }
  4924. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4925. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4926. advice.PrescribingNumberUnit = prescribingNumberUnit
  4927. }
  4928. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4929. deliveryWay, _ := json["delivery_way"].(string)
  4930. advice.DeliveryWay = deliveryWay
  4931. }
  4932. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4933. executionFrequency, _ := json["execution_frequency"].(string)
  4934. advice.ExecutionFrequency = executionFrequency
  4935. }
  4936. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4937. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4938. advice.Price = price
  4939. }
  4940. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4941. med_list_codg, _ := json["medical_insurance_number"].(string)
  4942. advice.MedListCodg = med_list_codg
  4943. }
  4944. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4945. day := int64(json["day"].(float64))
  4946. advice.Day = day
  4947. }
  4948. return 0
  4949. }
  4950. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  4951. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  4952. types := int64(json["type"].(float64))
  4953. project.Type = types
  4954. }
  4955. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4956. project_id := int64(json["project_id"].(float64))
  4957. project.ProjectId = project_id
  4958. }
  4959. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4960. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4961. project.Price = price
  4962. }
  4963. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  4964. total, _ := json["total"].(string)
  4965. //totals, _ := strconv.ParseInt(total, 10, 64)
  4966. project.Count = total
  4967. }
  4968. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  4969. medical_code, _ := json["medical_code"].(string)
  4970. project.MedListCodg = medical_code
  4971. }
  4972. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4973. single_dose, _ := json["single_dose"].(string)
  4974. project.SingleDose = single_dose
  4975. }
  4976. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4977. delivery_way, _ := json["delivery_way"].(string)
  4978. project.DeliveryWay = delivery_way
  4979. }
  4980. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4981. execution_frequency, _ := json["execution_frequency"].(string)
  4982. project.ExecutionFrequency = execution_frequency
  4983. }
  4984. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4985. remark, _ := json["remark"].(string)
  4986. project.Remark = remark
  4987. }
  4988. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  4989. day, _ := json["number_days"].(string)
  4990. project.Day = day
  4991. }
  4992. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  4993. unit, _ := json["unit"].(string)
  4994. project.Unit = unit
  4995. }
  4996. return 0
  4997. }
  4998. func (c *HisApiController) GetHisOrderList() {
  4999. page, _ := c.GetInt64("page", -1)
  5000. limit, _ := c.GetInt64("limit", -1)
  5001. start_time := c.GetString("start_time")
  5002. end_time := c.GetString("end_time")
  5003. types, _ := c.GetInt64("type", 0)
  5004. keywords := c.GetString("keywords")
  5005. p_type, _ := c.GetInt64("p_type", 0)
  5006. sort_type, _ := c.GetInt64("sort_type", 0)
  5007. charge_type, _ := c.GetInt64("charge_type", 0)
  5008. timeLayout := "2006-01-02"
  5009. loc, _ := time.LoadLocation("Local")
  5010. var startTime int64
  5011. if len(start_time) > 0 {
  5012. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5013. if err != nil {
  5014. //fmt.Println(err)
  5015. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5016. return
  5017. }
  5018. startTime = theTime.Unix()
  5019. }
  5020. var endTime int64
  5021. if len(end_time) > 0 {
  5022. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5023. if err != nil {
  5024. utils.ErrorLog(err.Error())
  5025. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5026. return
  5027. }
  5028. endTime = theTime.Unix()
  5029. }
  5030. adminUser := c.GetAdminUserInfo()
  5031. org_id := adminUser.CurrentOrgId
  5032. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time, charge_type)
  5033. for _, item := range order {
  5034. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  5035. item.DoctorName = info.Doctor
  5036. item.DepartmentName = info.XtHisDepartment.Name
  5037. }
  5038. if err == nil {
  5039. c.ServeSuccessJSON(map[string]interface{}{
  5040. "order": order,
  5041. "total": total,
  5042. })
  5043. } else {
  5044. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5045. return
  5046. }
  5047. }
  5048. func (c *HisApiController) GetHisOrder() {
  5049. patient_id, _ := c.GetInt64("patient_id", 0)
  5050. number := c.GetString("number")
  5051. adminInfo := c.GetAdminUserInfo()
  5052. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  5053. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  5054. if err == nil {
  5055. c.ServeSuccessJSON(map[string]interface{}{
  5056. "order": order,
  5057. "prescription": prescriptions,
  5058. })
  5059. } else {
  5060. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5061. return
  5062. }
  5063. }
  5064. func (c *HisApiController) GetHisPrescriptionList() {
  5065. record_date := c.GetString("record_date")
  5066. keywords := c.GetString("keywords")
  5067. page, _ := c.GetInt64("page")
  5068. limit, _ := c.GetInt64("limit")
  5069. sch_type, _ := c.GetInt64("sch_type")
  5070. timeLayout := "2006-01-02"
  5071. loc, _ := time.LoadLocation("Local")
  5072. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5073. if err != nil {
  5074. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5075. return
  5076. }
  5077. recordDateTime := theTime.Unix()
  5078. adminInfo := c.GetAdminUserInfo()
  5079. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  5080. //adminInfo := c.GetAdminUserInfo()
  5081. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  5082. //fmt.Println(prescriptionOrder)
  5083. if err == nil {
  5084. c.ServeSuccessJSON(map[string]interface{}{
  5085. "order": prescriptionOrder,
  5086. "total": total,
  5087. })
  5088. } else {
  5089. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5090. return
  5091. }
  5092. }
  5093. func (c *HisApiController) GetHisPrescriptionInfo() {
  5094. id, _ := c.GetInt64("id")
  5095. adminInfo := c.GetAdminUserInfo()
  5096. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  5097. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  5098. if err == nil {
  5099. c.ServeSuccessJSON(map[string]interface{}{
  5100. "order": prescriptionOrder,
  5101. "prescription": prescription,
  5102. })
  5103. } else {
  5104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5105. return
  5106. }
  5107. }
  5108. func (c *HisApiController) GetMedicalInsuranceConfig() {
  5109. adminUser := c.GetAdminUserInfo()
  5110. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5111. c.ServeSuccessJSON(map[string]interface{}{
  5112. "config": config,
  5113. })
  5114. }
  5115. type ResultTwo struct {
  5116. ErrMsg interface{} `json:"err_msg"`
  5117. InfRefmsgid string `json:"inf_refmsgid"`
  5118. Infcode int64 `json:"infcode"`
  5119. Output struct {
  5120. Baseinfo struct {
  5121. Age float64 `json:"age"`
  5122. Brdy string `json:"brdy"`
  5123. Certno string `json:"certno"`
  5124. Gend string `json:"gend"`
  5125. Naty string `json:"naty"`
  5126. PsnCertType string `json:"psn_cert_type"`
  5127. PsnName string `json:"psn_name"`
  5128. PsnNo string `json:"psn_no"`
  5129. } `json:"baseinfo"`
  5130. Idetinfo []interface{} `json:"idetinfo"`
  5131. Iinfo []struct {
  5132. Balc float64 `json:"balc"`
  5133. CvlservFlag string `json:"cvlserv_flag"`
  5134. EmpName string `json:"emp_name"`
  5135. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  5136. Insutype string `json:"insutype"`
  5137. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  5138. PausInsuDate interface{} `json:"paus_insu_date"`
  5139. PsnInsuDate string `json:"psn_insu_date"`
  5140. PsnInsuStas string `json:"psn_insu_stas"`
  5141. PsnType string `json:"psn_type"`
  5142. } `json:"insuinfo"`
  5143. } `json:"output"`
  5144. RefmsgTime string `json:"refmsg_time"`
  5145. RespondTime string `json:"respond_time"`
  5146. Signtype interface{} `json:"signtype"`
  5147. WarnInfo interface{} `json:"warn_info"`
  5148. }
  5149. type ResultThree struct {
  5150. Cainfo interface{} `json:"cainfo"`
  5151. ErrMsg interface{} `json:"err_msg"`
  5152. InfRefmsgid string `json:"inf_refmsgid"`
  5153. Infcode int64 `json:"infcode"`
  5154. Output struct {
  5155. Data struct {
  5156. IptOtpNo string `json:"ipt_otp_no"`
  5157. MdtrtID string `json:"mdtrt_id"`
  5158. PsnNo string `json:"psn_no"`
  5159. } `json:"data"`
  5160. } `json:"output"`
  5161. RefmsgTime string `json:"refmsg_time"`
  5162. RespondTime string `json:"respond_time"`
  5163. Signtype interface{} `json:"signtype"`
  5164. WarnMsg interface{} `json:"warn_msg"`
  5165. }
  5166. type ResultFour struct {
  5167. Cainfo string `json:"cainfo"`
  5168. ErrMsg string `json:"err_msg"`
  5169. InfRefmsgid string `json:"inf_refmsgid"`
  5170. Infcode int64 `json:"infcode"`
  5171. Output struct {
  5172. Result []struct {
  5173. BasMednFlag string `json:"bas_medn_flag"`
  5174. ChldMedcFlag string `json:"chld_medc_flag"`
  5175. ChrgitmLv string `json:"chrgitm_lv"`
  5176. Cnt float64 `json:"cnt"`
  5177. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  5178. DrtReimFlag string `json:"drt_reim_flag"`
  5179. FeedetlSn string `json:"feedetl_sn"`
  5180. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5181. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  5182. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5183. ListSpItemFlag string `json:"list_sp_item_flag"`
  5184. LmtUsedFlag string `json:"lmt_used_flag"`
  5185. MedChrgitmType string `json:"med_chrgitm_type"`
  5186. Memo string `json:"memo"`
  5187. OverlmtAmt float64 `json:"overlmt_amt"`
  5188. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5189. Pric float64 `json:"pric"`
  5190. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  5191. SelfpayProp float64 `json:"selfpay_prop"`
  5192. } `json:"result"`
  5193. } `json:"output"`
  5194. RefmsgTime string `json:"refmsg_time"`
  5195. RespondTime string `json:"respond_time"`
  5196. Signtype string `json:"signtype"`
  5197. WarnMsg string `json:"warn_msg"`
  5198. }
  5199. type ResultFive struct {
  5200. Insutype string `json:"insutype"`
  5201. }
  5202. type ResultSix struct {
  5203. Cainfo interface{} `json:"cainfo"`
  5204. ErrMsg interface{} `json:"err_msg"`
  5205. InfRefmsgid string `json:"inf_refmsgid"`
  5206. Infcode int64 `json:"infcode"`
  5207. Output struct {
  5208. } `json:"output"`
  5209. RefmsgTime string `json:"refmsg_time"`
  5210. RespondTime string `json:"respond_time"`
  5211. Signtype interface{} `json:"signtype"`
  5212. WarnMsg interface{} `json:"warn_msg"`
  5213. }
  5214. type ResultSeven struct {
  5215. Cainfo string `json:"cainfo"`
  5216. ErrMsg string `json:"err_msg"`
  5217. InfRefmsgid string `json:"inf_refmsgid"`
  5218. Infcode int64 `json:"infcode"`
  5219. Output struct {
  5220. Setldetail []interface{} `json:"setldetail"`
  5221. Setlinfo struct {
  5222. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5223. AcctPay float64 `json:"acct_pay"`
  5224. ActPayDedc float64 `json:"act_pay_dedc"`
  5225. Age float64 `json:"age"`
  5226. Balc float64 `json:"balc"`
  5227. Brdy string `json:"brdy"`
  5228. Certno string `json:"certno"`
  5229. ClrOptins string `json:"clr_optins"`
  5230. ClrType string `json:"clr_type"`
  5231. ClrWay string `json:"clr_way"`
  5232. CvlservFlag string `json:"cvlserv_flag"`
  5233. CvlservPay float64 `json:"cvlserv_pay"`
  5234. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5235. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5236. Gend string `json:"gend"`
  5237. HifesPay float64 `json:"hifes_pay"`
  5238. HifmiPay float64 `json:"hifmi_pay"`
  5239. HifobPay float64 `json:"hifob_pay"`
  5240. HifpPay float64 `json:"hifp_pay"`
  5241. HospPartAmt float64 `json:"hosp_part_amt"`
  5242. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5243. Insutype string `json:"insutype"`
  5244. MafPay float64 `json:"maf_pay"`
  5245. MdtrtCertType string `json:"mdtrt_cert_type"`
  5246. MdtrtID string `json:"mdtrt_id"`
  5247. MedType string `json:"med_type"`
  5248. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5249. MedinsSetlID string `json:"medins_setl_id"`
  5250. Naty string `json:"naty"`
  5251. OthPay float64 `json:"oth_pay"`
  5252. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5253. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5254. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5255. PsnCashPay float64 `json:"psn_cash_pay"`
  5256. PsnCertType string `json:"psn_cert_type"`
  5257. PsnName string `json:"psn_name"`
  5258. PsnNo string `json:"psn_no"`
  5259. PsnPartAmt float64 `json:"psn_part_amt"`
  5260. PsnType string `json:"psn_type"`
  5261. SetlID string `json:"setl_id"`
  5262. SetlTime string `json:"setl_time"`
  5263. } `json:"setlinfo"`
  5264. } `json:"output"`
  5265. RefmsgTime string `json:"refmsg_time"`
  5266. RespondTime string `json:"respond_time"`
  5267. Signtype interface{} `json:"signtype"`
  5268. WarnMsg interface{} `json:"warn_msg"`
  5269. }
  5270. type ResultEight struct {
  5271. Cainfo string `json:"cainfo"`
  5272. ErrMsg string `json:"err_msg"`
  5273. InfRefmsgid string `json:"inf_refmsgid"`
  5274. Infcode int64 `json:"infcode"`
  5275. Output struct {
  5276. Stmtinfo struct {
  5277. SetlOptins string `json:"setl_optins"`
  5278. StmtRslt string `json:"stmt_rslt"`
  5279. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  5280. } `json:"stmtinfo"`
  5281. } `json:"output"`
  5282. RefmsgTime string `json:"refmsg_time"`
  5283. RespondTime string `json:"respond_time"`
  5284. Signtype interface{} `json:"signtype"`
  5285. WarnMsg interface{} `json:"warn_msg"`
  5286. }
  5287. type ResultNine struct {
  5288. Cainfo string `json:"cainfo"`
  5289. ErrMsg string `json:"err_msg"`
  5290. InfRefmsgid string `json:"inf_refmsgid"`
  5291. Infcode int64 `json:"infcode"`
  5292. Output struct {
  5293. FileQuryNo string `json:"file_qury_no"`
  5294. } `json:"output"`
  5295. RefmsgTime string `json:"refmsg_time"`
  5296. RespondTime string `json:"respond_time"`
  5297. Signtype interface{} `json:"signtype"`
  5298. WarnMsg interface{} `json:"warn_msg"`
  5299. }
  5300. type ResultTen struct {
  5301. Cainfo string `json:"cainfo"`
  5302. ErrMsg string `json:"err_msg"`
  5303. InfRefmsgid string `json:"inf_refmsgid"`
  5304. Infcode int64 `json:"infcode"`
  5305. Output struct {
  5306. DldEndtime string `json:"dld_endtime"`
  5307. FileQuryNo string `json:"file_qury_no"`
  5308. Filename string `json:"filename"`
  5309. } `json:"output"`
  5310. RefmsgTime string `json:"refmsg_time"`
  5311. RespondTime string `json:"respond_time"`
  5312. Signtype interface{} `json:"signtype"`
  5313. WarnMsg interface{} `json:"warn_msg"`
  5314. }
  5315. type ResultEleven struct {
  5316. Cainfo string `json:"cainfo"`
  5317. ErrMsg string `json:"err_msg"`
  5318. InfRefmsgid string `json:"inf_refmsgid"`
  5319. Infcode int64 `json:"infcode"`
  5320. Output struct {
  5321. Setlinfo struct {
  5322. FixmedinsName string `json:"fixmedins_name"`
  5323. FixmedinsCode string `json:"fixmedins_code"`
  5324. PsnNo string `json:"psn_no"`
  5325. PsnName string `json:"psn_name"`
  5326. HifobPay float64 `json:"hifob_pay"`
  5327. Gend string `json:"gend"`
  5328. Brdy string `json:"brdy"`
  5329. PsnCertType string `json:"psn_cert_type"`
  5330. PsnType string `json:"psn_type"`
  5331. EmpName string `json:"emp_name"`
  5332. Certno string `json:"certno"`
  5333. Insutype string `json:"insutype"`
  5334. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5335. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5336. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5337. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5338. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5339. ActPayDedc float64 `json:"act_pay_dedc"`
  5340. HifpPay float64 `json:"hifp_pay"`
  5341. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5342. CvlservPay float64 `json:"cvlserv_pay"`
  5343. HifesPay float64 `json:"hifes_pay"`
  5344. HifmiPay float64 `json:"hifmi_pay"`
  5345. MafPay float64 `json:"maf_pay"`
  5346. OthPay float64 `json:"oth_pay"`
  5347. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5348. PsnPay float64 `json:"psn_pay"`
  5349. AcctPay float64 `json:"acct_pay"`
  5350. CashPayamt float64 `json:"cash_payamt"`
  5351. Balc float64 `json:"balc"`
  5352. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5353. MedinsSetlId string `json:"medins_setl_id"`
  5354. RefdSetlFlag string `json:"refd_setl_flag"`
  5355. SetlTime string `json:"setl_time"`
  5356. MedType string `json:"med_type"`
  5357. } `json:"setlinfo"`
  5358. } `json:"output"`
  5359. RefmsgTime string `json:"refmsg_time"`
  5360. RespondTime string `json:"respond_time"`
  5361. Signtype interface{} `json:"signtype"`
  5362. WarnMsg interface{} `json:"warn_msg"`
  5363. }
  5364. type Custom struct {
  5365. DetItemFeeSumamt string
  5366. Cut string
  5367. FeedetlSn string
  5368. Price string
  5369. MedListCodg string
  5370. Type int64
  5371. AdviceId int64
  5372. ProjectId int64
  5373. ItemId int64
  5374. }
  5375. // 获取个人信息----挂号-----上传就诊信息
  5376. func (c *HisApiController) GetRegisterInfo() {
  5377. id, _ := c.GetInt64("id")
  5378. record_time := c.GetString("record_time")
  5379. settlementValue, _ := c.GetInt64("settlement_value")
  5380. medical_insurance_card := c.GetString("medical_insurance_card")
  5381. name := c.GetString("name")
  5382. id_card_type, _ := c.GetInt64("id_card_type")
  5383. certificates, _ := c.GetInt64("certificates")
  5384. medical_care, _ := c.GetInt64("medical_care")
  5385. birthday := c.GetString("birthday")
  5386. age, _ := c.GetInt64("age")
  5387. id_card := c.GetString("id_card")
  5388. register_type, _ := c.GetInt64("register")
  5389. doctor, _ := c.GetInt64("doctor")
  5390. department, _ := c.GetInt64("department")
  5391. gender, _ := c.GetInt64("sex")
  5392. phone := c.GetString("phone")
  5393. registration_fee, _ := c.GetFloat("registration_fee")
  5394. medical_expenses, _ := c.GetFloat("medical_expenses")
  5395. social_type, _ := c.GetInt64("social_type")
  5396. //diagnosis_id, _ := c.GetInt64("diagnosis")
  5397. diagnosis_ids := c.GetString("diagnosis")
  5398. sick_type, _ := c.GetInt64("sick_type")
  5399. reg_type := c.GetString("p_type")
  5400. timeLayout := "2006-01-02"
  5401. loc, _ := time.LoadLocation("Local")
  5402. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  5403. birthUnix := birthdays.Unix()
  5404. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5405. if err != nil {
  5406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5407. return
  5408. }
  5409. recordDateTime := theTime.Unix()
  5410. adminInfo := c.GetAdminUserInfo()
  5411. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  5412. if tempPatient.ID == 0 {
  5413. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  5414. return
  5415. }
  5416. var patient service.Patients
  5417. if id == 0 {
  5418. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  5419. } else {
  5420. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  5421. }
  5422. if patient.ID == 0 {
  5423. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  5424. return
  5425. }
  5426. if len(patient.IdCardNo) == 0 {
  5427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  5428. return
  5429. }
  5430. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5431. if len(his) >= 1 {
  5432. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  5433. if len(his) >= 1 && order.ID == 0 {
  5434. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  5435. return
  5436. }
  5437. }
  5438. timeStr := time.Now().Format("2006-01-02 15:04:05")
  5439. fmt.Println(timeStr)
  5440. timeArr := strings.Split(timeStr, " ")
  5441. fmt.Println(timeArr)
  5442. timeArrTwo := strings.Split(timeArr[0], "-")
  5443. timeArrThree := strings.Split(timeArr[1], ":")
  5444. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  5445. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5446. if len(lists) == 0 {
  5447. var hisPatient models.XtHisPatient
  5448. hisPatient = models.XtHisPatient{
  5449. Name: name,
  5450. Age: age,
  5451. Gender: gender,
  5452. Birthday: birthUnix,
  5453. Phone: phone,
  5454. MedicalTreatmentType: medical_care,
  5455. IdType: certificates,
  5456. IdCardNo: id_card,
  5457. BalanceAccountsType: settlementValue,
  5458. SocialType: social_type,
  5459. MedicalInsuranceNumber: medical_insurance_card,
  5460. RegisterType: register_type,
  5461. RegisterCost: registration_fee,
  5462. TreatmentCost: medical_expenses,
  5463. AdminUserId: adminInfo.AdminUser.Id,
  5464. UserOrgId: adminInfo.CurrentOrgId,
  5465. Status: 1,
  5466. RecordDate: recordDateTime,
  5467. IsReturn: 1,
  5468. PatientId: patient.ID,
  5469. Ctime: time.Now().Unix(),
  5470. Mtime: time.Now().Unix(),
  5471. Number: str,
  5472. IdCardType: id_card_type,
  5473. Departments: department,
  5474. Doctor: doctor,
  5475. PType: reg_type,
  5476. Diagnosis: diagnosis_ids,
  5477. SickType: sick_type,
  5478. }
  5479. service.CreateHisPatient(&hisPatient)
  5480. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  5481. c.ServeSuccessJSON(map[string]interface{}{
  5482. "his_info": hisPatient,
  5483. })
  5484. } else {
  5485. //chrgBchno := rand.Intn(1000000) + 10000
  5486. var hisPatient models.XtHisPatient
  5487. hisPatient = models.XtHisPatient{
  5488. Name: name,
  5489. Age: age,
  5490. Gender: gender,
  5491. Birthday: birthUnix,
  5492. Phone: phone,
  5493. MedicalTreatmentType: medical_care,
  5494. IdType: certificates,
  5495. IdCardNo: id_card,
  5496. BalanceAccountsType: settlementValue,
  5497. SocialType: social_type,
  5498. MedicalInsuranceNumber: medical_insurance_card,
  5499. RegisterType: register_type,
  5500. RegisterCost: registration_fee,
  5501. TreatmentCost: medical_expenses,
  5502. AdminUserId: adminInfo.AdminUser.Id,
  5503. UserOrgId: adminInfo.CurrentOrgId,
  5504. Status: 1,
  5505. RecordDate: recordDateTime,
  5506. IsReturn: 1,
  5507. PatientId: patient.ID,
  5508. Ctime: time.Now().Unix(),
  5509. Mtime: time.Now().Unix(),
  5510. Number: str,
  5511. IdCardType: id_card_type,
  5512. Departments: department,
  5513. Doctor: doctor,
  5514. PType: reg_type,
  5515. Diagnosis: diagnosis_ids,
  5516. SickType: sick_type,
  5517. }
  5518. service.CreateHisPatient(&hisPatient)
  5519. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  5520. c.ServeSuccessJSON(map[string]interface{}{
  5521. "his_info": hisPatient,
  5522. })
  5523. }
  5524. }
  5525. // 上传明细----结算
  5526. func (c *HisApiController) GetUploadInfo() {
  5527. id, _ := c.GetInt64("id")
  5528. record_time := c.GetString("record_time")
  5529. his_patient_id, _ := c.GetInt64("his_patient_id")
  5530. oth_desc := c.GetString("oth_desc")
  5531. pay_way, _ := c.GetInt64("pay_way")
  5532. pay_ways := c.GetString("pay_ways")
  5533. cash_pay := c.GetString("cash_pay")
  5534. band_card_pay := c.GetString("band_card_pay")
  5535. wechat_pay := c.GetString("wechat_pay")
  5536. ali_pay := c.GetString("ali_pay")
  5537. jifen_pay := c.GetString("jifen_pay")
  5538. pay_price, _ := c.GetFloat("pay_price")
  5539. pay_card_no := c.GetString("pay_card_no")
  5540. discount_price, _ := c.GetFloat("discount_price")
  5541. preferential_price, _ := c.GetFloat("preferential_price")
  5542. reality_price, _ := c.GetFloat("reality_price")
  5543. found_price, _ := c.GetFloat("found_price")
  5544. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  5545. private_price, _ := c.GetFloat("private_price")
  5546. timeLayout := "2006-01-02"
  5547. loc, _ := time.LoadLocation("Local")
  5548. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  5549. fapiao_code := c.GetString("fapiao_code")
  5550. fapiao_number := c.GetString("fapiao_number")
  5551. diagnosis_id := c.GetString("diagnosis")
  5552. sick_type, _ := c.GetInt64("sick_type")
  5553. reg_type, _ := c.GetInt64("p_type")
  5554. order_id, _ := c.GetInt64("order_id")
  5555. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  5556. tmp_decimal := c.GetString("tmp_decimal")
  5557. var decimal float64 //本次使用的押金
  5558. var errmsg error
  5559. tx := service.XTWriteDB().Begin() //开了事务
  5560. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  5561. defer func() {
  5562. if errmsg != nil {
  5563. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  5564. tx.Rollback()
  5565. } else {
  5566. tx.Commit()
  5567. }
  5568. }()
  5569. fmt.Println("dec_way", dec_way)
  5570. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  5571. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  5572. return
  5573. }
  5574. if len(tmp_decimal) > 0 {
  5575. if tmp_decimal[0] == 45 {
  5576. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  5577. return
  5578. }
  5579. }
  5580. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  5581. fmt.Println(errs)
  5582. //if errs != nil {
  5583. // c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金金额错误")
  5584. // return
  5585. //}
  5586. decimal = tt
  5587. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  5588. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  5589. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5590. if err != nil {
  5591. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5592. return
  5593. }
  5594. recordDateTime := theTime.Unix()
  5595. adminUser := c.GetAdminUserInfo()
  5596. var prescriptions []*models.HisPrescription
  5597. var prescriptionsOne []*models.HisPrescription
  5598. var start_time int64
  5599. var end_time int64
  5600. ids_str := c.GetString("ids")
  5601. ids_arr := strings.Split(ids_str, ",")
  5602. if tempOrder.ID == 0 {
  5603. if settle_accounts_type == 1 { //日结
  5604. fmt.Println(reg_type)
  5605. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  5606. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  5607. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  5608. } else {
  5609. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5610. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5611. }
  5612. } else { //月结
  5613. start_time_str := c.GetString("start_time")
  5614. end_time_str := c.GetString("end_time")
  5615. timeLayout := "2006-01-02"
  5616. loc, _ := time.LoadLocation("Local")
  5617. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  5618. if err != nil {
  5619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5620. return
  5621. }
  5622. recordStartTime := theStartTime.Unix()
  5623. start_time = recordStartTime
  5624. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  5625. if err != nil {
  5626. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5627. return
  5628. }
  5629. recordEndTime := theEndTime.Unix()
  5630. end_time = recordEndTime
  5631. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  5632. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5633. }
  5634. var goods []*models.DialysisBeforePrepareGoods
  5635. var newGoods []*models.NewDialysisBeforePrepareGoods
  5636. var oldGoods []*models.OldDialysisBeforePrepareGoods
  5637. var infos []*models.HisDoctorAdviceInfo
  5638. var infoList []*models.HisDoctorAdviceInfo
  5639. var hisAdvice []*models.HisDoctorAdviceInfo
  5640. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  5641. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  5642. //判断库存不足
  5643. //结算出库开关
  5644. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  5645. if settConfig.IsOpen == 1 {
  5646. //判断库存的地方
  5647. for _, info := range prescriptions {
  5648. if info.Type == 1 {
  5649. infos = append(infos, info.HisDoctorAdviceInfo...)
  5650. }
  5651. if info.Type == 2 {
  5652. for _, sumItem := range info.HisPrescriptionProject {
  5653. if sumItem.Type == 3 {
  5654. var good models.DialysisBeforePrepareGoods
  5655. var newGood models.NewDialysisBeforePrepareGoods
  5656. good.GoodId = sumItem.GoodInfo.ID
  5657. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5658. count, _ := strconv.Atoi(sumItem.Count)
  5659. good.Count = int64(count)
  5660. good.StorehouseId = houseConfig.StorehouseOutInfo
  5661. good.ProjectId = sumItem.ID
  5662. goods = append(goods, &good)
  5663. newGood.GoodId = sumItem.GoodInfo.ID
  5664. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5665. count2, _ := strconv.Atoi(sumItem.Count)
  5666. newGood.Count = int64(count2)
  5667. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5668. newGood.ProjectId = sumItem.ID
  5669. newGoods = append(newGoods, &newGood)
  5670. }
  5671. }
  5672. }
  5673. }
  5674. for _, info := range prescriptionsOne {
  5675. if info.Type == 1 {
  5676. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  5677. }
  5678. if info.Type == 2 {
  5679. for _, sumItem := range info.HisPrescriptionProject {
  5680. if sumItem.Type == 3 {
  5681. var newGood models.NewDialysisBeforePrepareGoods
  5682. newGood.GoodId = sumItem.GoodInfo.ID
  5683. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5684. count2, _ := strconv.Atoi(sumItem.Count)
  5685. newGood.Count = int64(count2)
  5686. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5687. newGood.ProjectId = sumItem.ID
  5688. newGoodOne = append(newGoodOne, &newGood)
  5689. }
  5690. }
  5691. }
  5692. }
  5693. //判断
  5694. for _, itemOne := range infos {
  5695. for _, itemTwo := range hisAdvice {
  5696. if itemOne.DrugId == itemTwo.DrugId {
  5697. itemTwo.Child = append(itemTwo.Child, itemOne)
  5698. }
  5699. }
  5700. }
  5701. for _, itemTwo := range hisAdvice {
  5702. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  5703. var sum_out_count int64
  5704. for _, itemThree := range itemTwo.Child {
  5705. var prescribing_number int64
  5706. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  5707. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5708. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5709. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5710. }
  5711. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5712. prescribing_number = parseIntPrescribingNumber
  5713. }
  5714. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5715. prescribing_number = parseIntPrescribingNumber
  5716. }
  5717. sum_out_count += prescribing_number
  5718. }
  5719. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  5720. fmt.Println("sum_out_count233232323232wo", sum_out_count)
  5721. fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
  5722. if sum_out_count > drugStockOut.FlushCount {
  5723. c.ServeSuccessJSON(map[string]interface{}{
  5724. "msg": "2",
  5725. "drug": medical,
  5726. })
  5727. return
  5728. }
  5729. }
  5730. fmt.Println("newGoods99999988882os", newGoods)
  5731. for _, itemOne := range newGoods {
  5732. for _, item := range newGoodOne {
  5733. if itemOne.GoodId == item.GoodId {
  5734. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  5735. }
  5736. }
  5737. }
  5738. for _, item := range newGoodOne {
  5739. var sum_out_count_one int64
  5740. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  5741. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  5742. sum_out_count_one += itemOne.Count
  5743. }
  5744. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5745. fmt.Println("sum_out_count_one", sum_out_count_one)
  5746. fmt.Println("list.FlushCount", list.FlushCount)
  5747. if sum_out_count_one > list.FlushCount {
  5748. c.ServeSuccessJSON(map[string]interface{}{
  5749. "msg": "3",
  5750. "good": good,
  5751. })
  5752. return
  5753. }
  5754. }
  5755. }
  5756. timestamp := time.Now().Unix()
  5757. tempTime := time.Unix(timestamp, 0)
  5758. timeFormat := tempTime.Format("20060102150405")
  5759. chrgBchno := rand.Intn(100000) + 10000
  5760. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  5761. strconv.FormatInt(his.PatientId, 10)
  5762. var ids []int64
  5763. for _, item := range prescriptions {
  5764. ids = append(ids, item.ID)
  5765. }
  5766. var total float64
  5767. for _, item := range prescriptions {
  5768. fmt.Println(item)
  5769. if item.Type == 1 { //药品
  5770. for _, subItem := range item.HisDoctorAdviceInfo {
  5771. total = total + (subItem.Price * subItem.PrescribingNumber)
  5772. }
  5773. }
  5774. if item.Type == 2 { //项目
  5775. for _, subItem := range item.HisPrescriptionProject {
  5776. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  5777. total = total + (subItem.Price * cnt)
  5778. }
  5779. }
  5780. for _, subItem := range item.HisAdditionalCharge {
  5781. total = total + (subItem.Price * float64(subItem.Count))
  5782. }
  5783. }
  5784. if reg_type == 1111 || reg_type == 1112 {
  5785. reg_type = 11
  5786. }
  5787. tm := time.Unix(time.Now().Unix(), 0)
  5788. allTotal := fmt.Sprintf("%.4f", total)
  5789. totals, _ := strconv.ParseFloat(allTotal, 64)
  5790. order := &models.HisOrder{
  5791. UserOrgId: adminUser.CurrentOrgId,
  5792. HisPatientId: his.ID,
  5793. PatientId: id,
  5794. SettleAccountsDate: recordDateTime,
  5795. Ctime: time.Now().Unix(),
  5796. Mtime: time.Now().Unix(),
  5797. Status: 1,
  5798. OrderStatus: 2,
  5799. MdtrtId: his.Number,
  5800. Number: chrg_bchno,
  5801. MedfeeSumamt: totals,
  5802. PayWay: pay_way,
  5803. PayWays: pay_ways,
  5804. PayPrice: pay_price,
  5805. MedType: strconv.Itoa(int(reg_type)),
  5806. PayCardNo: pay_card_no,
  5807. DiscountPrice: discount_price,
  5808. PreferentialPrice: preferential_price,
  5809. RealityPrice: reality_price,
  5810. FoundPrice: found_price,
  5811. MedicalInsurancePrice: medical_insurance_price,
  5812. PrivatePrice: private_price,
  5813. SettleEndTime: end_time,
  5814. SettleStartTime: start_time,
  5815. PsnPartAmt: totals,
  5816. PsnCashPay: totals,
  5817. SettleType: settle_accounts_type,
  5818. FaPiaoCode: fapiao_code,
  5819. FaPiaoNumber: fapiao_number,
  5820. Diagnosis: diagnosis_id,
  5821. PType: 2,
  5822. SetlTime: tm.Format("2006-01-02 15:04:05"),
  5823. Decimal: decimal,
  5824. OthDesc: oth_desc,
  5825. CashPay: cash_pay,
  5826. WechatPay: wechat_pay,
  5827. AliPay: ali_pay,
  5828. JifenPay: jifen_pay,
  5829. BandCardPay: band_card_pay,
  5830. }
  5831. err = service.CreateOrderTX(order, tx)
  5832. if err != nil {
  5833. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  5834. return
  5835. }
  5836. var customs []*Custom
  5837. for _, item := range prescriptions {
  5838. if item.Type == 1 { //药品a
  5839. for _, subItem := range item.HisDoctorAdviceInfo {
  5840. cus := &Custom{
  5841. AdviceId: subItem.ID,
  5842. ProjectId: 0,
  5843. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  5844. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  5845. FeedetlSn: subItem.FeedetlSn,
  5846. Price: fmt.Sprintf("%.4f", subItem.Price),
  5847. MedListCodg: subItem.MedListCodg,
  5848. Type: 1,
  5849. }
  5850. customs = append(customs, cus)
  5851. }
  5852. }
  5853. if item.Type == 2 { //项目
  5854. for _, subItem := range item.HisPrescriptionProject {
  5855. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  5856. cus := &Custom{
  5857. AdviceId: 0,
  5858. ProjectId: subItem.ID,
  5859. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  5860. Cut: fmt.Sprintf("%.4f", cnt),
  5861. FeedetlSn: subItem.FeedetlSn,
  5862. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  5863. MedListCodg: subItem.MedListCodg,
  5864. Type: 2,
  5865. }
  5866. customs = append(customs, cus)
  5867. }
  5868. }
  5869. for _, item := range item.HisAdditionalCharge {
  5870. cus := &Custom{
  5871. ItemId: item.ID,
  5872. AdviceId: 0,
  5873. ProjectId: 0,
  5874. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  5875. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  5876. FeedetlSn: item.FeedetlSn,
  5877. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  5878. MedListCodg: item.XtHisAddtionConfig.Code,
  5879. Type: 3,
  5880. }
  5881. customs = append(customs, cus)
  5882. }
  5883. }
  5884. for _, item := range customs {
  5885. var advice_id int64 = 0
  5886. var project_id int64 = 0
  5887. var item_id int64 = 0
  5888. var types int64 = 0
  5889. if item.Type == 1 {
  5890. advice_id = item.AdviceId
  5891. project_id = 0
  5892. item_id = 0
  5893. } else if item.Type == 2 {
  5894. advice_id = 0
  5895. item_id = 0
  5896. project_id = item.ProjectId
  5897. } else if item.Type == 3 {
  5898. advice_id = 0
  5899. item_id = item.ItemId
  5900. project_id = 0
  5901. }
  5902. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  5903. cut, _ := strconv.ParseFloat(item.Cut, 32)
  5904. pric, _ := strconv.ParseFloat(item.Price, 32)
  5905. info := &models.HisOrderInfo{
  5906. OrderNumber: order.Number,
  5907. UploadDate: time.Now().Unix(),
  5908. AdviceId: advice_id,
  5909. DetItemFeeSumamt: detItemFeeSumamt,
  5910. Cnt: cut,
  5911. Pric: pric,
  5912. PatientId: id,
  5913. Status: 1,
  5914. Mtime: time.Now().Unix(),
  5915. Ctime: time.Now().Unix(),
  5916. UserOrgId: adminUser.CurrentOrgId,
  5917. HisPatientId: his.ID,
  5918. OrderId: order.ID,
  5919. ProjectId: project_id,
  5920. Type: types,
  5921. ItemId: item_id,
  5922. }
  5923. service.CreateOrderInfoTX(info, tx)
  5924. }
  5925. his.Diagnosis = diagnosis_id
  5926. his.SickType = sick_type
  5927. his.RegisterType = reg_type
  5928. his.MedicalTreatmentType = reg_type
  5929. service.UpdataHisPateintTX(&his, tx)
  5930. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  5931. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  5932. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  5933. //判断是否使用了押金
  5934. if dec_way == "true" {
  5935. tmpstring := strconv.FormatInt(order.ID, 10)
  5936. //扣押金
  5937. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  5938. order.Decimal = decimal
  5939. service.UpDateOrderTwo(order)
  5940. if errmsg != nil {
  5941. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  5942. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  5943. return
  5944. }
  5945. }
  5946. if err == nil {
  5947. for _, info := range prescriptions {
  5948. if info.Type == 1 {
  5949. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  5950. }
  5951. if info.Type == 2 {
  5952. for _, sumItem := range info.HisPrescriptionProject {
  5953. if sumItem.Type == 3 {
  5954. var good models.DialysisBeforePrepareGoods
  5955. var newGood models.NewDialysisBeforePrepareGoods
  5956. var oldGood models.OldDialysisBeforePrepareGoods
  5957. good.GoodId = sumItem.GoodInfo.ID
  5958. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5959. count, _ := strconv.Atoi(sumItem.Count)
  5960. good.Count = int64(count)
  5961. good.StorehouseId = houseConfig.StorehouseOutInfo
  5962. good.ProjectId = sumItem.ID
  5963. good.PatientId = sumItem.PatientId
  5964. goods = append(goods, &good)
  5965. newGood.GoodId = sumItem.GoodInfo.ID
  5966. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5967. count2, _ := strconv.Atoi(sumItem.Count)
  5968. newGood.Count = int64(count2)
  5969. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5970. newGood.ProjectId = sumItem.ID
  5971. newGood.PatientId = sumItem.HisPatientId
  5972. newGoods = append(newGoods, &newGood)
  5973. oldGood.GoodId = sumItem.GoodInfo.ID
  5974. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5975. count3, _ := strconv.Atoi(sumItem.Count)
  5976. oldGood.Count = int64(count3)
  5977. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  5978. oldGood.ProjectId = sumItem.ID
  5979. oldGood.RecordDate = sumItem.RecordDate
  5980. oldGood.PatientId = sumItem.HisPatientId
  5981. oldGoods = append(oldGoods, &oldGood)
  5982. }
  5983. }
  5984. }
  5985. }
  5986. if settConfig.IsOpen == 1 {
  5987. for _, item := range infoList {
  5988. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  5989. if medical.IsUse == 2 {
  5990. //药品出库
  5991. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  5992. //查询默认仓库
  5993. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  5994. //查询默认仓库剩余多少库存
  5995. var sum_count int64
  5996. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  5997. for _, its := range stockInfo {
  5998. if its.MaxUnit == medical.MaxUnit {
  5999. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6000. }
  6001. sum_count += its.StockMaxNumber + its.StockMinNumber
  6002. }
  6003. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6004. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6005. }
  6006. }
  6007. orgId := c.GetAdminUserInfo().CurrentOrgId
  6008. if len(oldGoods) > 0 {
  6009. timeStr := time.Now().Format("2006-01-02")
  6010. timeArr := strings.Split(timeStr, "-")
  6011. total, _ := service.FindAllWarehouseOut(orgId)
  6012. total = total + 1
  6013. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6014. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6015. number = number + total
  6016. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6017. operation_time := time.Now().Unix()
  6018. creater := c.GetAdminUserInfo().AdminUser.Id
  6019. //查询默认出库仓库库存
  6020. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6021. recordDateStr := time.Now().Format("2006-01-02")
  6022. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6023. nowtime := recordDate.Unix()
  6024. warehouseOut := models.WarehouseOut{
  6025. WarehouseOutOrderNumber: warehousing_out_order,
  6026. OperationTime: operation_time,
  6027. OrgId: orgId,
  6028. Creater: creater,
  6029. Ctime: time.Now().Unix(),
  6030. Status: 1,
  6031. WarehouseOutTime: nowtime,
  6032. Type: 1,
  6033. StorehouseId: storeConfig.StorehouseOutInfo,
  6034. IsCheck: 1,
  6035. OrderId: order.ID,
  6036. IsSys: 5,
  6037. }
  6038. //查询是否生成出库单
  6039. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6040. if out.ID == 0 {
  6041. service.AddSigleWarehouseOut(&warehouseOut)
  6042. }
  6043. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6044. for _, item := range oldGoods {
  6045. dialyPrepareOne := models.DialysisBeforePrepare{
  6046. GoodTypeId: item.GoodTypeId,
  6047. GoodId: item.GoodId,
  6048. PatientId: his.PatientId,
  6049. RecordDate: item.RecordDate,
  6050. UserOrgId: adminUser.CurrentOrgId,
  6051. Count: item.Count,
  6052. Ctime: time.Now().Unix(),
  6053. Creater: adminUser.AdminUser.Id,
  6054. CommdityCode: item.CommdityCode,
  6055. Status: 1,
  6056. StorehouseId: houseConfig.StorehouseOutInfo,
  6057. }
  6058. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  6059. //非零用
  6060. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  6061. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6062. //查询剩余库存
  6063. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6064. var sum_count int64
  6065. for _, item := range goodList {
  6066. sum_count += item.StockCount
  6067. }
  6068. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6069. //耗材
  6070. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6071. }
  6072. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  6073. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6074. //查询剩余库存
  6075. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6076. var sum_count int64
  6077. for _, item := range goodList {
  6078. sum_count += item.StockCount
  6079. }
  6080. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6081. //耗材
  6082. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6083. }
  6084. }
  6085. }
  6086. }
  6087. c.ServeSuccessJSON(map[string]interface{}{
  6088. "msg": "结算成功",
  6089. })
  6090. }
  6091. } else {
  6092. if tempOrder.IsPre > 0 {
  6093. allTotal := fmt.Sprintf("%.2f", tempOrder.MedfeeSumamt)
  6094. totals, _ := strconv.ParseFloat(allTotal, 64)
  6095. tempOrder.OrderStatus = 2
  6096. tempOrder.PayWay = pay_way
  6097. tempOrder.PayPrice = pay_price
  6098. tempOrder.PayCardNo = pay_card_no
  6099. tempOrder.DiscountPrice = discount_price
  6100. tempOrder.PreferentialPrice = preferential_price
  6101. tempOrder.RealityPrice = reality_price
  6102. tempOrder.FoundPrice = found_price
  6103. tempOrder.MedicalInsurancePrice = medical_insurance_price
  6104. tempOrder.PrivatePrice = private_price
  6105. tempOrder.FaPiaoCode = fapiao_code
  6106. tempOrder.FaPiaoNumber = fapiao_number
  6107. tempOrder.PType = 2
  6108. tempOrder.MedfeeSumamt = totals
  6109. tempOrder.Diagnosis = diagnosis_id
  6110. err = service.SaveHisOrder(&tempOrder)
  6111. err = service.UpdataOrderStatusTwo(tempOrder.Number, adminUser.CurrentOrgId)
  6112. if err != nil {
  6113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6114. return
  6115. }
  6116. if err == nil {
  6117. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  6118. var goods []*models.DialysisBeforePrepareGoods
  6119. var newGoods []*models.NewDialysisBeforePrepareGoods
  6120. var infos []*models.HisDoctorAdviceInfo
  6121. var hisAdvice []*models.HisDoctorAdviceInfo
  6122. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  6123. var infolist []*models.HisDoctorAdviceInfo
  6124. var oldGoods []*models.OldDialysisBeforePrepareGoods
  6125. for _, info := range prescriptions {
  6126. if info.Type == 1 {
  6127. infos = append(infos, info.HisDoctorAdviceInfo...)
  6128. }
  6129. if info.Type == 2 {
  6130. for _, sumItem := range info.HisPrescriptionProject {
  6131. if sumItem.Type == 3 {
  6132. var good models.DialysisBeforePrepareGoods
  6133. var newGood models.NewDialysisBeforePrepareGoods
  6134. good.GoodId = sumItem.GoodInfo.ID
  6135. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6136. count, _ := strconv.Atoi(sumItem.Count)
  6137. good.Count = int64(count)
  6138. good.StorehouseId = houseConfig.StorehouseOutInfo
  6139. good.ProjectId = sumItem.ID
  6140. goods = append(goods, &good)
  6141. newGood.GoodId = sumItem.GoodInfo.ID
  6142. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6143. count2, _ := strconv.Atoi(sumItem.Count)
  6144. newGood.Count = int64(count2)
  6145. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6146. newGood.ProjectId = sumItem.ID
  6147. newGoods = append(newGoods, &newGood)
  6148. }
  6149. }
  6150. }
  6151. }
  6152. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6153. if settConfig.IsOpen == 1 {
  6154. //判断库存的地方
  6155. for _, info := range prescriptions {
  6156. if info.Type == 1 {
  6157. infolist = append(infolist, info.HisDoctorAdviceInfo...)
  6158. }
  6159. if info.Type == 2 {
  6160. for _, sumItem := range info.HisPrescriptionProject {
  6161. if sumItem.Type == 3 {
  6162. var good models.DialysisBeforePrepareGoods
  6163. var newGood models.NewDialysisBeforePrepareGoods
  6164. var oldGood models.OldDialysisBeforePrepareGoods
  6165. good.GoodId = sumItem.GoodInfo.ID
  6166. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6167. count, _ := strconv.Atoi(sumItem.Count)
  6168. good.Count = int64(count)
  6169. good.StorehouseId = houseConfig.StorehouseOutInfo
  6170. good.ProjectId = sumItem.ID
  6171. goods = append(goods, &good)
  6172. newGood.GoodId = sumItem.GoodInfo.ID
  6173. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6174. count2, _ := strconv.Atoi(sumItem.Count)
  6175. newGood.Count = int64(count2)
  6176. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6177. newGood.ProjectId = sumItem.ID
  6178. newGoods = append(newGoods, &newGood)
  6179. oldGood.GoodId = sumItem.GoodInfo.ID
  6180. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6181. count3, _ := strconv.Atoi(sumItem.Count)
  6182. oldGood.Count = int64(count3)
  6183. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  6184. oldGood.ProjectId = sumItem.ID
  6185. oldGood.RecordDate = sumItem.RecordDate
  6186. oldGoods = append(oldGoods, &oldGood)
  6187. }
  6188. }
  6189. }
  6190. }
  6191. for _, info := range prescriptionsOne {
  6192. if info.Type == 1 {
  6193. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  6194. }
  6195. if info.Type == 2 {
  6196. for _, sumItem := range info.HisPrescriptionProject {
  6197. if sumItem.Type == 3 {
  6198. var newGood models.NewDialysisBeforePrepareGoods
  6199. newGood.GoodId = sumItem.GoodInfo.ID
  6200. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6201. count2, _ := strconv.Atoi(sumItem.Count)
  6202. newGood.Count = int64(count2)
  6203. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6204. newGood.ProjectId = sumItem.ID
  6205. newGoodOne = append(newGoodOne, &newGood)
  6206. }
  6207. }
  6208. }
  6209. }
  6210. //判断
  6211. for _, itemOne := range infos {
  6212. for _, itemTwo := range hisAdvice {
  6213. if itemOne.DrugId == itemTwo.DrugId {
  6214. itemTwo.Child = append(itemTwo.ChildDoctorAdvice, itemOne)
  6215. }
  6216. }
  6217. }
  6218. for _, itemTwo := range hisAdvice {
  6219. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  6220. var sum_out_count int64
  6221. for _, itemThree := range itemTwo.Child {
  6222. var prescribing_number int64
  6223. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6224. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6225. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6226. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6227. }
  6228. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6229. prescribing_number = parseIntPrescribingNumber
  6230. }
  6231. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6232. prescribing_number = parseIntPrescribingNumber
  6233. }
  6234. sum_out_count += prescribing_number
  6235. }
  6236. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  6237. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  6238. if sum_out_count > drugStockOut.FlushCount {
  6239. c.ServeSuccessJSON(map[string]interface{}{
  6240. "msg": "2",
  6241. "drug": medical,
  6242. })
  6243. return
  6244. }
  6245. }
  6246. for _, itemOne := range newGoods {
  6247. for _, item := range newGoodOne {
  6248. if itemOne.ProjectId == item.ProjectId {
  6249. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, item)
  6250. }
  6251. }
  6252. }
  6253. for _, item := range newGoodOne {
  6254. var sum_out_count_one int64
  6255. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  6256. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  6257. sum_out_count_one += itemOne.Count
  6258. }
  6259. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6260. fmt.Println("sum_out_count_one", sum_out_count_one)
  6261. fmt.Println("list.FlushCount", list.FlushCount)
  6262. if sum_out_count_one > list.FlushCount {
  6263. c.ServeSuccessJSON(map[string]interface{}{
  6264. "msg": "3",
  6265. "good": good,
  6266. })
  6267. return
  6268. }
  6269. }
  6270. for _, item := range infolist {
  6271. service.HisDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item)
  6272. }
  6273. for _, item := range oldGoods {
  6274. dialyPrepareOne := models.DialysisBeforePrepare{
  6275. GoodTypeId: item.GoodTypeId,
  6276. GoodId: item.GoodId,
  6277. PatientId: item.PatientId,
  6278. RecordDate: item.RecordDate,
  6279. UserOrgId: item.UserOrgId,
  6280. Count: item.Count,
  6281. Ctime: time.Now().Unix(),
  6282. Creater: adminUser.AdminUser.Id,
  6283. CommdityCode: item.CommdityCode,
  6284. Status: 1,
  6285. StorehouseId: houseConfig.StorehouseOutInfo,
  6286. }
  6287. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  6288. }
  6289. service.ConsumablesDeliveryTotal(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, goods, newGoods, adminUser.AdminUser.Id)
  6290. }
  6291. c.ServeSuccessJSON(map[string]interface{}{
  6292. "msg": "结算成功",
  6293. })
  6294. }
  6295. }
  6296. }
  6297. }
  6298. // 退款
  6299. func (c *HisApiController) Refund() {
  6300. order_id, _ := c.GetInt64("order_id")
  6301. order, _ := service.GetHisOrderByID(order_id)
  6302. adminUser := c.GetAdminUserInfo()
  6303. orgid := c.GetAdminUserInfo().CurrentOrgId
  6304. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  6305. if err != nil {
  6306. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6307. return
  6308. }
  6309. tmp := strconv.FormatInt(order.ID, 10)
  6310. //当押金不为零时产生退费记录
  6311. if order.Decimal != 0 {
  6312. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  6313. if err != nil {
  6314. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6315. return
  6316. }
  6317. }
  6318. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  6319. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  6320. var goods []*models.DialysisBeforePrepareGoods
  6321. var newGoods []*models.NewDialysisBeforePrepareGoods
  6322. var infos []*models.HisDoctorAdviceInfo
  6323. for _, info := range orders {
  6324. if info.AdviceId > 0 && info.ProjectId == 0 {
  6325. infos = append(infos, &info.HisDoctorAdviceInfo)
  6326. }
  6327. if info.ProjectId > 0 && info.AdviceId == 0 {
  6328. if info.HisPrescriptionProject.Type == 3 {
  6329. var good models.DialysisBeforePrepareGoods
  6330. var newGood models.NewDialysisBeforePrepareGoods
  6331. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6332. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6333. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6334. good.Count = int64(count)
  6335. good.StorehouseId = houseConfig.StorehouseOutInfo
  6336. good.ProjectId = info.HisPrescriptionProject.ID
  6337. good.PatientId = info.PatientId
  6338. good.OrderId = order_id
  6339. goods = append(goods, &good)
  6340. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6341. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6342. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6343. newGood.Count = int64(count2)
  6344. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6345. newGood.ProjectId = info.HisPrescriptionProject.ID
  6346. newGood.RecordDate = order.SettleAccountsDate
  6347. newGood.UserOrgId = order.UserOrgId
  6348. newGood.PatientId = info.PatientId
  6349. newGood.OrderId = order_id
  6350. newGoods = append(newGoods, &newGood)
  6351. }
  6352. }
  6353. }
  6354. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6355. if settConfig.IsOpen == 1 {
  6356. for _, item := range infos {
  6357. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6358. }
  6359. for _, item := range newGoods {
  6360. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6361. }
  6362. }
  6363. c.ServeSuccessJSON(map[string]interface{}{
  6364. "msg": "退费成功",
  6365. })
  6366. }
  6367. func (c *HisApiController) RefundNumber() {
  6368. his_patient_id, _ := c.GetInt64("id")
  6369. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6370. info.Status = 0
  6371. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  6372. if count > 0 {
  6373. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  6374. return
  6375. }
  6376. err := service.SaveHisPatient(info)
  6377. if err == nil {
  6378. c.ServeSuccessJSON(map[string]interface{}{
  6379. "msg": "退号成功",
  6380. })
  6381. } else {
  6382. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6383. return
  6384. }
  6385. }
  6386. func (this *HisApiController) AdditionalCharge() {
  6387. dataBody := make(map[string]interface{}, 0)
  6388. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6389. fmt.Println(err)
  6390. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  6391. patient_id := int64(dataBody["patient_id"].(float64))
  6392. medicineData, _ := dataBody["medicineData"].([]interface{})
  6393. adminUserInfo := this.GetAdminUserInfo()
  6394. orgId := adminUserInfo.CurrentOrgId
  6395. admin_user_id := adminUserInfo.AdminUser.Id
  6396. timeStr := time.Now().Format("2006-01-02")
  6397. timeLayout := "2006-01-02 15:04:05"
  6398. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  6399. timenow := timeStringToTime.Unix()
  6400. var additionalCharges []*models.HisAdditionalCharge
  6401. for _, item := range medicineData {
  6402. var randNum int
  6403. randNum = rand.Intn(10000) + 1000
  6404. timestamp := time.Now().Unix()
  6405. tempTime := time.Unix(timestamp, 0)
  6406. timeFormat := tempTime.Format("20060102150405")
  6407. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  6408. items := item.(map[string]interface{})
  6409. money := items["price"].(string)
  6410. item_id_str := items["item_id"].(string)
  6411. name := items["name"].(string)
  6412. id_str := items["id"].(string)
  6413. moneys, _ := strconv.ParseInt(money, 10, 64)
  6414. monStr := strconv.FormatInt(moneys, 10)
  6415. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  6416. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  6417. id, _ := strconv.ParseInt(id_str, 10, 64)
  6418. additionalCharge := &models.HisAdditionalCharge{
  6419. ID: id,
  6420. HisPatientId: his_patient_id,
  6421. UserOrgId: orgId,
  6422. PatientId: patient_id,
  6423. RecordDate: timenow,
  6424. Price: monneyStr,
  6425. Status: 1,
  6426. ItemName: name,
  6427. ItemId: item_id,
  6428. AdminUserId: admin_user_id,
  6429. CreatedTime: time.Now().Unix(),
  6430. OrderStatus: 0,
  6431. PrescriptionNumber: "",
  6432. BatchNumber: "",
  6433. FeedetlSn: p_number,
  6434. }
  6435. service.CreateAdditionalCharge(additionalCharge)
  6436. additionalCharges = append(additionalCharges, additionalCharge)
  6437. }
  6438. this.ServeSuccessJSON(map[string]interface{}{
  6439. "msg": "添加成功",
  6440. "additional_charges": additionalCharges,
  6441. })
  6442. }
  6443. func (this *HisApiController) DeleteAddition() {
  6444. id, _ := this.GetInt64("id")
  6445. //TODO 需要判断是否已经结算
  6446. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  6447. if err == nil {
  6448. this.ServeSuccessJSON(map[string]interface{}{
  6449. "msg": "删除成功",
  6450. })
  6451. return
  6452. } else {
  6453. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6454. return
  6455. }
  6456. }
  6457. func (this *HisApiController) GetAdminUsers() {
  6458. adminUser := this.GetAdminUserInfo()
  6459. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  6460. this.ServeSuccessJSON(map[string]interface{}{
  6461. "doctors": doctors,
  6462. })
  6463. }
  6464. func (this *HisApiController) GetLastOrNextHisPrescription() {
  6465. change_type, _ := this.GetInt64("type", 0)
  6466. record_date := this.GetString("record_time")
  6467. patient_id, _ := this.GetInt64("patient_id", 0)
  6468. p_type, _ := this.GetInt64("p_type", 0)
  6469. timeLayout := "2006-01-02"
  6470. loc, _ := time.LoadLocation("Local")
  6471. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6472. record_time := theAdviceRecordTime.Unix()
  6473. adminUserInfo := this.GetAdminUserInfo()
  6474. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  6475. if err == nil {
  6476. if len(prescriptions) == 0 {
  6477. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  6478. return
  6479. } else {
  6480. this.ServeSuccessJSON(map[string]interface{}{
  6481. "prescriptions": prescriptions,
  6482. })
  6483. return
  6484. }
  6485. } else {
  6486. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6487. return
  6488. }
  6489. }
  6490. func (this *HisApiController) GetCallHisPrescription() {
  6491. patient_id, _ := this.GetInt64("patient_id", 0)
  6492. timeLayout := "2006-01-02"
  6493. loc, _ := time.LoadLocation("Local")
  6494. start_time := this.GetString("start_time")
  6495. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6496. end_time := this.GetString("end_time")
  6497. p_type, _ := this.GetInt64("p_type")
  6498. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6499. adminUserInfo := this.GetAdminUserInfo()
  6500. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  6501. if err == nil {
  6502. this.ServeSuccessJSON(map[string]interface{}{
  6503. "prescriptions": prescriptions,
  6504. })
  6505. return
  6506. } else {
  6507. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6508. return
  6509. }
  6510. }
  6511. func (this *HisApiController) GetHisDayPrescription() {
  6512. timeLayout := "2006-01-02"
  6513. loc, _ := time.LoadLocation("Local")
  6514. start_time := this.GetString("start_time")
  6515. patient_id, _ := this.GetInt64("patient_id", 0)
  6516. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6517. end_time := this.GetString("end_time")
  6518. p_type, _ := this.GetInt64("p_type")
  6519. order_status, _ := this.GetInt64("type")
  6520. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6521. adminUserInfo := this.GetAdminUserInfo()
  6522. var dayHisPrescription []*models.HisPrescription
  6523. var err error
  6524. if order_status == 1 || order_status == 0 {
  6525. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6526. } else if order_status == 2 {
  6527. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6528. }
  6529. var settle_total float64
  6530. for _, item := range dayHisPrescription {
  6531. if len(item.HisPrescriptionProject) > 0 {
  6532. for _, subItem := range item.HisPrescriptionProject {
  6533. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6534. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6535. settle_total = settle_total + total
  6536. }
  6537. }
  6538. if len(item.HisDoctorAdviceInfo) > 0 {
  6539. for _, subItem := range item.HisDoctorAdviceInfo {
  6540. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6541. settle_total = settle_total + total
  6542. }
  6543. }
  6544. }
  6545. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6546. if err == nil {
  6547. this.ServeSuccessJSON(map[string]interface{}{
  6548. "day_prescription": dayHisPrescription,
  6549. "settle_total": settle_total,
  6550. })
  6551. return
  6552. } else {
  6553. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6554. return
  6555. }
  6556. }
  6557. func (c *HisApiController) GetHisChargePatientList() {
  6558. record_date := c.GetString("record_date")
  6559. order_status, _ := c.GetInt64("type")
  6560. timeLayout := "2006-01-02"
  6561. loc, _ := time.LoadLocation("Local")
  6562. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6563. if err != nil {
  6564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6565. return
  6566. }
  6567. recordDateTime := theTime.Unix()
  6568. adminInfo := c.GetAdminUserInfo()
  6569. var tempPatients []*service.NewTempPatients
  6570. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6571. if order_status != 2 {
  6572. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6573. } else {
  6574. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6575. }
  6576. var patients []*service.NewTempPatients
  6577. var patients_two []*service.NewTempPatients
  6578. for _, item := range tempPatients {
  6579. //过滤掉没挂号的和没开处方的
  6580. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  6581. patients = append(patients, item)
  6582. }
  6583. //过滤掉没挂号的
  6584. if len(item.HisPatient) > 0 {
  6585. patients_two = append(patients_two, item)
  6586. }
  6587. }
  6588. c.ServeSuccessJSON(map[string]interface{}{
  6589. "list": patients,
  6590. "list_two": patients_two,
  6591. })
  6592. }
  6593. func (c *HisApiController) GetHisUnRegisterPatientList() {
  6594. record_date := c.GetString("record_date")
  6595. timeLayout := "2006-01-02"
  6596. loc, _ := time.LoadLocation("Local")
  6597. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6598. if err != nil {
  6599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6600. return
  6601. }
  6602. recordDateTime := theTime.Unix()
  6603. adminUser := c.GetAdminUserInfo()
  6604. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  6605. var patients []*service.Patients
  6606. for _, item := range tempPatients {
  6607. if item.HisPatient.ID == 0 {
  6608. patients = append(patients, item)
  6609. }
  6610. }
  6611. c.ServeSuccessJSON(map[string]interface{}{
  6612. "list": patients,
  6613. //"list_two": patients_two,
  6614. })
  6615. }
  6616. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  6617. newArr = make([]*service.Patients, 0)
  6618. for i := 0; i < len(patient); i++ {
  6619. repeat := false
  6620. for j := i + 1; j < len(patient); j++ {
  6621. if patient[i].ID == patient[j].ID {
  6622. repeat = true
  6623. break
  6624. }
  6625. }
  6626. if !repeat {
  6627. newArr = append(newArr, patient[i])
  6628. }
  6629. }
  6630. return
  6631. }
  6632. func (c *HisApiController) GetHisChargePatientInfo() {
  6633. patient_id, _ := c.GetInt64("patient_id")
  6634. his_patient_id, _ := c.GetInt64("his_patient_id")
  6635. record_date := c.GetString("record_date")
  6636. //start_time := c.GetString("start_time")
  6637. //end_time := c.GetString("end_time")
  6638. order_status, _ := c.GetInt64("type", 0)
  6639. p_type, _ := c.GetInt64("p_type", 0)
  6640. order_id, _ := c.GetInt64("order_id", 0)
  6641. timeLayout := "2006-01-02"
  6642. loc, _ := time.LoadLocation("Local")
  6643. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6644. if err != nil {
  6645. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6646. return
  6647. }
  6648. recordDateTime := theTime.Unix()
  6649. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6650. //if err != nil {
  6651. //
  6652. //}
  6653. //startRecordDateTime := startTime.Unix()
  6654. //
  6655. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6656. //if err != nil {
  6657. //
  6658. //}
  6659. //endRecordDateTime := endTime.Unix()
  6660. admin := c.GetAdminUserInfo()
  6661. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6662. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6663. var prescriptions []*models.HisPrescription
  6664. //var unChargeMonthPrescriptions []*models.HisPrescription
  6665. order, _ := service.GetHisOrderByID(order_id)
  6666. if order_status == 1 || order_status == 0 {
  6667. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  6668. } else if order_status == 2 {
  6669. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  6670. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6671. }
  6672. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6673. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6674. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6675. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6676. //获取所有科室信息
  6677. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6678. c.ServeSuccessJSON(map[string]interface{}{
  6679. "his_info": his_patient_info,
  6680. "xt_info": xt_patient_info,
  6681. "prescription": prescriptions,
  6682. "case_history": case_history,
  6683. "info": patientPrescriptionInfo,
  6684. "last_info": lastPatientPrescriptionInfo,
  6685. "order": order,
  6686. "doctors": doctors,
  6687. "department": department,
  6688. })
  6689. return
  6690. }
  6691. func (c *HisApiController) GetAllOrderDetail() {
  6692. order_id, _ := c.GetInt64("id", 0)
  6693. order, _ := service.GetHisOrderByID(order_id)
  6694. if order.ID == 0 {
  6695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6696. return
  6697. }
  6698. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6699. org_id := c.GetAdminUserInfo().CurrentOrgId
  6700. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6701. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  6702. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6703. c.ServeSuccessJSON(map[string]interface{}{
  6704. "order": order,
  6705. "order_info": order_info,
  6706. "patient": patient,
  6707. "admin_info": adminInfo,
  6708. "hospital_record": record,
  6709. })
  6710. return
  6711. }
  6712. func (c *HisApiController) GetAllOrderDetailCollect() {
  6713. order_id, _ := c.GetInt64("id", 0)
  6714. order, _ := service.GetHisOrderByID(order_id)
  6715. if order.ID == 0 {
  6716. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6717. return
  6718. }
  6719. org_id := c.GetAdminUserInfo().CurrentOrgId
  6720. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6721. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6722. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  6723. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  6724. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  6725. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6726. var bedCostTotal float64 = 0 //床位总费
  6727. //var bedCostSelfTotal float64 = 0 //床位自费
  6728. var operationCostTotal float64 = 0 //手术费
  6729. //var operationCostSelfTotal float64 = 0 //手术费
  6730. var otherCostTotal float64 = 0 //其他费用
  6731. //var otherCostSelfTotal float64 = 0 //其他费用
  6732. var materialCostTotal float64 = 0 //材料费
  6733. //var materialCostSelfTotal float64 = 0 //材料费
  6734. var westernMedicineCostTotal float64 = 0 //西药费
  6735. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  6736. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  6737. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  6738. var checkCostTotal float64 = 0 //检查费
  6739. //var checkCostSelfTotal float64 = 0 //检查费
  6740. var laboratoryCostTotal float64 = 0 //化验费
  6741. //var laboratoryCostSelfTotal float64 = 0 //化验费
  6742. var treatCostTotal float64 = 0 //治疗费用
  6743. //var treatCostSelfTotal float64 = 0 //治疗费用
  6744. var zhenChaCostTotal float64 = 0 //其他费用
  6745. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  6746. decimal.DivisionPrecision = 2
  6747. var BalanceAccountsType int64
  6748. if his.ID > 0 {
  6749. BalanceAccountsType = his.BalanceAccountsType
  6750. } else {
  6751. BalanceAccountsType = record.BalanceAccountsType
  6752. }
  6753. if BalanceAccountsType != 2 {
  6754. for _, item := range order_info {
  6755. if org_id == 10215 {
  6756. if item.MedChrgitmType == "01" { //床位费
  6757. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6758. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6759. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6760. }
  6761. if item.MedChrgitmType == "02" { //诊察费
  6762. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6763. //zhenChaCostSelfTotal = zhenChaCostTotal
  6764. }
  6765. if item.MedChrgitmType == "03" { //检查费
  6766. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6767. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6768. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6769. }
  6770. //if item.MedChrgitmType == "02" { //检查费
  6771. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6772. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6773. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6774. //}
  6775. if item.MedChrgitmType == "04" { //化验费
  6776. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6777. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6778. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6779. }
  6780. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6781. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6782. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6783. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6784. }
  6785. if item.MedChrgitmType == "06" { //手术费
  6786. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6787. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6788. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6789. }
  6790. if item.MedChrgitmType == "08" { //材料费
  6791. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6792. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6793. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6794. }
  6795. if item.MedChrgitmType == "09" { //西药费
  6796. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6797. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6798. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6799. }
  6800. if item.MedChrgitmType == "11" { //中成费
  6801. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6802. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6803. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6804. }
  6805. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  6806. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6807. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6808. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6809. }
  6810. } else if org_id == 10188 || org_id == 10217 {
  6811. if item.MedChrgitmType == "01" { //床位费
  6812. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6813. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6814. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6815. }
  6816. if item.MedChrgitmType == "02" { //诊察费
  6817. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6818. //zhenChaCostSelfTotal = zhenChaCostTotal
  6819. }
  6820. if item.MedChrgitmType == "03" { //检查费
  6821. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6822. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6823. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6824. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6825. }
  6826. //if item.MedChrgitmType == "02" { //检查费
  6827. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6828. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6829. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6830. //}
  6831. if item.MedChrgitmType == "04" { //化验费
  6832. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6833. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6834. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6835. }
  6836. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6837. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6838. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6839. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6840. }
  6841. if item.MedChrgitmType == "06" { //手术费
  6842. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6843. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6844. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6845. }
  6846. if item.MedChrgitmType == "08" { //材料费
  6847. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6848. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6849. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6850. }
  6851. if item.MedChrgitmType == "09" { //西药费
  6852. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6853. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6854. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6855. }
  6856. if item.MedChrgitmType == "11" { //中成费
  6857. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6858. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6859. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6860. }
  6861. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  6862. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6863. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6864. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6865. }
  6866. } else {
  6867. if item.MedChrgitmType == "01" { //床位费
  6868. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6869. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6870. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6871. }
  6872. //if item.MedChrgitmType == "02" { //诊察费
  6873. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6874. // //zhenChaCostSelfTotal = zhenChaCostTotal
  6875. //}
  6876. if item.MedChrgitmType == "03" { //检查费
  6877. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6878. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6879. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6880. }
  6881. //if item.MedChrgitmType == "02" { //检查费
  6882. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6883. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6884. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6885. //}
  6886. if item.MedChrgitmType == "04" { //化验费
  6887. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6888. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6889. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6890. }
  6891. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6892. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6893. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6894. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6895. }
  6896. if item.MedChrgitmType == "06" { //手术费
  6897. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6898. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6899. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6900. }
  6901. if item.MedChrgitmType == "08" { //材料费
  6902. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6903. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6904. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6905. }
  6906. if item.MedChrgitmType == "09" { //西药费
  6907. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6908. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6909. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6910. }
  6911. if item.MedChrgitmType == "11" { //中成费
  6912. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6913. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6914. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6915. }
  6916. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  6917. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6918. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6919. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6920. }
  6921. }
  6922. }
  6923. c.ServeSuccessJSON(map[string]interface{}{
  6924. "order": order,
  6925. "order_info": order_info,
  6926. "patient": patient,
  6927. "admin_info": adminInfo,
  6928. "his_hospital": record,
  6929. "bedCostTotal": bedCostTotal,
  6930. "operationCostTotal": operationCostTotal,
  6931. "otherCostTotal": otherCostTotal,
  6932. "materialCostTotal": materialCostTotal,
  6933. "westernMedicineCostTotal": westernMedicineCostTotal,
  6934. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  6935. "checkCostTotal": checkCostTotal,
  6936. "zhenChaCostTotal": zhenChaCostTotal,
  6937. "laboratoryCostTotal": laboratoryCostTotal,
  6938. "treatCostTotal": treatCostTotal,
  6939. })
  6940. } else {
  6941. for _, item := range order_info {
  6942. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  6943. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  6944. item.MedChrgitmType = "09"
  6945. }
  6946. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  6947. if item.HisPrescriptionProject.Type == 2 {
  6948. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  6949. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  6950. case 0:
  6951. item.MedChrgitmType = "0"
  6952. break
  6953. case 1:
  6954. item.MedChrgitmType = "14"
  6955. break
  6956. case 2:
  6957. item.MedChrgitmType = "05"
  6958. break
  6959. case 3:
  6960. item.MedChrgitmType = "03"
  6961. break
  6962. case 4:
  6963. item.MedChrgitmType = "03"
  6964. break
  6965. case 5:
  6966. item.MedChrgitmType = "08"
  6967. break
  6968. case 6:
  6969. item.MedChrgitmType = "14"
  6970. break
  6971. case 7:
  6972. item.MedChrgitmType = "14"
  6973. break
  6974. case 8:
  6975. item.MedChrgitmType = "03"
  6976. break
  6977. case 9:
  6978. item.MedChrgitmType = "14"
  6979. break
  6980. case 10:
  6981. item.MedChrgitmType = "14"
  6982. break
  6983. case 11:
  6984. item.MedChrgitmType = "06"
  6985. break
  6986. case 12:
  6987. item.MedChrgitmType = "12"
  6988. break
  6989. case 13:
  6990. item.MedChrgitmType = "01"
  6991. break
  6992. case 14:
  6993. item.MedChrgitmType = "04"
  6994. break
  6995. case 15:
  6996. item.MedChrgitmType = "14"
  6997. break
  6998. }
  6999. } else {
  7000. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7001. case 1:
  7002. item.MedChrgitmType = "14"
  7003. break
  7004. case 2:
  7005. item.MedChrgitmType = "05"
  7006. break
  7007. case 3:
  7008. item.MedChrgitmType = "04"
  7009. break
  7010. case 4:
  7011. item.MedChrgitmType = "14"
  7012. break
  7013. case 5:
  7014. item.MedChrgitmType = "08"
  7015. break
  7016. case 6:
  7017. item.MedChrgitmType = "14"
  7018. break
  7019. case 7:
  7020. item.MedChrgitmType = "14"
  7021. break
  7022. case 8:
  7023. item.MedChrgitmType = "03"
  7024. break
  7025. case 9:
  7026. item.MedChrgitmType = "14"
  7027. break
  7028. }
  7029. }
  7030. } else if item.HisPrescriptionProject.Type == 3 {
  7031. item.MedChrgitmType = "08"
  7032. }
  7033. }
  7034. }
  7035. for _, item := range order_info {
  7036. if org_id == 10215 {
  7037. if item.MedChrgitmType == "01" { //床位费
  7038. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7039. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7040. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7041. }
  7042. if item.MedChrgitmType == "02" { //诊察费
  7043. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7044. //zhenChaCostSelfTotal = zhenChaCostTotal
  7045. }
  7046. if item.MedChrgitmType == "03" { //检查费
  7047. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7048. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7049. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7050. }
  7051. //if item.MedChrgitmType == "02" { //检查费
  7052. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7053. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7054. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7055. //}
  7056. if item.MedChrgitmType == "04" { //化验费
  7057. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7058. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7059. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7060. }
  7061. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7062. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7063. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7064. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7065. }
  7066. if item.MedChrgitmType == "06" { //手术费
  7067. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7068. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7069. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7070. }
  7071. if item.MedChrgitmType == "08" { //材料费
  7072. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7073. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7074. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7075. }
  7076. if item.MedChrgitmType == "09" { //西药费
  7077. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7078. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7079. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7080. }
  7081. if item.MedChrgitmType == "11" { //中成费
  7082. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7083. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7084. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7085. }
  7086. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7087. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7088. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7089. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7090. }
  7091. } else {
  7092. if item.MedChrgitmType == "01" { //床位费
  7093. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7094. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7095. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7096. }
  7097. //if item.MedChrgitmType == "02" { //诊察费
  7098. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7099. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7100. //}
  7101. if item.MedChrgitmType == "03" { //检查费
  7102. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7103. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7104. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7105. }
  7106. //if item.MedChrgitmType == "02" { //检查费
  7107. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7108. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7109. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7110. //}
  7111. if item.MedChrgitmType == "04" { //化验费
  7112. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7113. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7114. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7115. }
  7116. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7117. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7118. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7119. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7120. }
  7121. if item.MedChrgitmType == "06" { //手术费
  7122. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7123. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7124. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7125. }
  7126. if item.MedChrgitmType == "08" { //材料费
  7127. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7128. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7129. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7130. }
  7131. if item.MedChrgitmType == "09" { //西药费
  7132. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7133. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7134. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7135. }
  7136. if item.MedChrgitmType == "11" { //中成费
  7137. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7138. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7139. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7140. }
  7141. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7142. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7143. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7144. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7145. }
  7146. }
  7147. }
  7148. c.ServeSuccessJSON(map[string]interface{}{
  7149. "order": order,
  7150. "order_info": order_info,
  7151. "patient": patient,
  7152. "admin_info": adminInfo,
  7153. "his_hospital": record,
  7154. "bedCostTotal": bedCostTotal,
  7155. "operationCostTotal": operationCostTotal,
  7156. "otherCostTotal": otherCostTotal,
  7157. "materialCostTotal": materialCostTotal,
  7158. "westernMedicineCostTotal": westernMedicineCostTotal,
  7159. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7160. "checkCostTotal": checkCostTotal,
  7161. "zhenChaCostTotal": zhenChaCostTotal,
  7162. "laboratoryCostTotal": laboratoryCostTotal,
  7163. "treatCostTotal": treatCostTotal,
  7164. })
  7165. }
  7166. }
  7167. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  7168. page, _ := c.GetInt64("page")
  7169. limit, _ := c.GetInt64("limit")
  7170. keywords := c.GetString("keywords")
  7171. start_time := c.GetString("start_time")
  7172. end_time := c.GetString("end_time")
  7173. //clr_type := c.GetString("clr_type")
  7174. insutype := c.GetString("insutype")
  7175. timeLayout := "2006-01-02"
  7176. loc, _ := time.LoadLocation("Local")
  7177. var theStartTIme int64
  7178. if len(start_time) > 0 {
  7179. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7180. theStartTIme = theTime.Unix()
  7181. }
  7182. var theEndtTIme int64
  7183. if len(end_time) > 0 {
  7184. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7185. theEndtTIme = theTime.Unix()
  7186. }
  7187. if page <= 0 {
  7188. page = 1
  7189. }
  7190. if limit <= 0 {
  7191. limit = 10
  7192. }
  7193. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  7194. c.ServeSuccessJSON(map[string]interface{}{
  7195. "total": total,
  7196. "list": list,
  7197. })
  7198. return
  7199. }
  7200. func (c *HisApiController) GetPutOnRecordList() {
  7201. page, _ := c.GetInt64("page")
  7202. limit, _ := c.GetInt64("limit")
  7203. keywords := c.GetString("keywords")
  7204. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  7205. if page <= 0 {
  7206. page = 1
  7207. }
  7208. if limit <= 0 {
  7209. limit = 10
  7210. }
  7211. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  7212. c.ServeSuccessJSON(map[string]interface{}{
  7213. "total": total,
  7214. "list": list,
  7215. })
  7216. return
  7217. }
  7218. func (c *HisApiController) GetCompareData() {
  7219. start_time := c.GetString("start_time")
  7220. end_time := c.GetString("end_time")
  7221. insutype := c.GetString("insutype")
  7222. clr_type := c.GetString("clr_type")
  7223. timeLayout := "2006-01-02"
  7224. loc, _ := time.LoadLocation("Local")
  7225. var theStartTIme int64
  7226. if len(start_time) > 0 {
  7227. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7228. if err != nil {
  7229. theStartTIme = 0
  7230. }
  7231. theStartTIme = theTime.Unix()
  7232. }
  7233. var theEndtTIme int64
  7234. if len(end_time) > 0 {
  7235. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7236. if err != nil {
  7237. theEndtTIme = 0
  7238. }
  7239. theEndtTIme = theTime.Unix()
  7240. }
  7241. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  7242. fmt.Println(err)
  7243. if err == nil {
  7244. c.ServeSuccessJSON(map[string]interface{}{
  7245. "list": formData,
  7246. })
  7247. } else {
  7248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7249. return
  7250. }
  7251. }
  7252. func (c *HisApiController) GetFaPiaoData() {
  7253. order_id, _ := c.GetInt64("order_id")
  7254. patient_id, _ := c.GetInt64("patient_id")
  7255. number := c.GetString("number")
  7256. adminUser := c.GetAdminUserInfo()
  7257. order, _ := service.GetHisOrderByID(order_id)
  7258. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  7259. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  7260. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  7261. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, number)
  7262. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7263. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  7264. var bedCostTotal float64 = 0 //床位总费
  7265. var bedCostSelfTotal float64 = 0 //床位自费
  7266. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  7267. var operationCostTotal float64 = 0 //手术费
  7268. var operationCostSelfTotal float64 = 0 //手术费
  7269. var operationCostPartSelfTotal float64 = 0 //手术费
  7270. var otherCostTotal float64 = 0 //其他费用
  7271. var otherCostSelfTotal float64 = 0 //其他费用
  7272. var otherCostPartSelfTotal float64 = 0 //其他费用
  7273. var materialCostTotal float64 = 0 //材料费
  7274. var materialCostSelfTotal float64 = 0 //材料费
  7275. var materialCostPartSelfTotal float64 = 0 //材料费
  7276. var westernMedicineCostTotal float64 = 0 //西药费
  7277. var westernMedicineCostSelfTotal float64 = 0 //西药费
  7278. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  7279. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7280. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7281. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  7282. var checkCostTotal float64 = 0 //检查费
  7283. var checkCostSelfTotal float64 = 0 //检查费
  7284. var checkCostPartSelfTotal float64 = 0 //检查费
  7285. var laboratoryCostTotal float64 = 0 //化验费
  7286. var laboratoryCostSelfTotal float64 = 0 //化验费
  7287. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  7288. var treatCostTotal float64 = 0 //治疗费用
  7289. var treatCostSelfTotal float64 = 0 //治疗费用
  7290. var treatCostPartSelfTotal float64 = 0 //治疗费用
  7291. var zhenChaCostTotal float64 = 0 //其他费用
  7292. var zhenChaCostSelfTotal float64 = 0 //其他费用
  7293. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7294. decimal.DivisionPrecision = 2
  7295. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7296. var balanceAccountsType int64
  7297. if his.ID > 0 {
  7298. balanceAccountsType = his.BalanceAccountsType
  7299. } else {
  7300. balanceAccountsType = his_hospital_record.BalanceAccountsType
  7301. }
  7302. if balanceAccountsType == 2 {
  7303. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7304. for _, item := range orderInfos_two {
  7305. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7306. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7307. item.MedChrgitmType = "09"
  7308. }
  7309. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7310. if item.HisPrescriptionProject.Type == 2 {
  7311. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7312. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7313. case 0:
  7314. item.MedChrgitmType = "0"
  7315. break
  7316. case 1:
  7317. item.MedChrgitmType = "14"
  7318. break
  7319. case 2:
  7320. item.MedChrgitmType = "05"
  7321. break
  7322. case 3:
  7323. item.MedChrgitmType = "03"
  7324. break
  7325. case 4:
  7326. item.MedChrgitmType = "03"
  7327. break
  7328. case 5:
  7329. item.MedChrgitmType = "08"
  7330. break
  7331. case 6:
  7332. item.MedChrgitmType = "14"
  7333. break
  7334. case 7:
  7335. item.MedChrgitmType = "14"
  7336. break
  7337. case 8:
  7338. item.MedChrgitmType = "03"
  7339. break
  7340. case 9:
  7341. item.MedChrgitmType = "14"
  7342. break
  7343. case 10:
  7344. item.MedChrgitmType = "14"
  7345. break
  7346. case 11:
  7347. item.MedChrgitmType = "06"
  7348. break
  7349. case 12:
  7350. item.MedChrgitmType = "12"
  7351. break
  7352. case 13:
  7353. item.MedChrgitmType = "01"
  7354. break
  7355. case 14:
  7356. item.MedChrgitmType = "04"
  7357. break
  7358. case 15:
  7359. item.MedChrgitmType = "02"
  7360. break
  7361. }
  7362. } else {
  7363. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7364. case 1:
  7365. item.MedChrgitmType = "14"
  7366. break
  7367. case 2:
  7368. item.MedChrgitmType = "05"
  7369. break
  7370. case 3:
  7371. item.MedChrgitmType = "03"
  7372. break
  7373. case 4:
  7374. item.MedChrgitmType = "03"
  7375. break
  7376. case 5:
  7377. item.MedChrgitmType = "08"
  7378. break
  7379. case 6:
  7380. item.MedChrgitmType = "14"
  7381. break
  7382. case 7:
  7383. item.MedChrgitmType = "14"
  7384. break
  7385. case 8:
  7386. item.MedChrgitmType = "03"
  7387. break
  7388. case 9:
  7389. item.MedChrgitmType = "14"
  7390. break
  7391. }
  7392. }
  7393. } else if item.HisPrescriptionProject.Type == 3 {
  7394. item.MedChrgitmType = "08"
  7395. }
  7396. }
  7397. }
  7398. for _, item := range orderInfos_two {
  7399. fmt.Println(item.MedChrgitmType)
  7400. if item.MedChrgitmType == "01" { //床位费
  7401. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7402. bedCostSelfTotal = bedCostTotal
  7403. }
  7404. if item.MedChrgitmType == "02" { //诊察费
  7405. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7406. zhenChaCostSelfTotal = zhenChaCostTotal
  7407. }
  7408. if item.MedChrgitmType == "03" { //检查费
  7409. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7410. checkCostSelfTotal = checkCostTotal
  7411. }
  7412. if item.MedChrgitmType == "04" { //化验费
  7413. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7414. laboratoryCostSelfTotal = laboratoryCostTotal
  7415. }
  7416. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  7417. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7418. treatCostSelfTotal = treatCostTotal
  7419. }
  7420. if item.MedChrgitmType == "06" { //手术费
  7421. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7422. operationCostSelfTotal = treatCostTotal
  7423. }
  7424. if item.MedChrgitmType == "08" { //材料费
  7425. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7426. materialCostSelfTotal = materialCostTotal
  7427. }
  7428. if item.MedChrgitmType == "09" { //西药费
  7429. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7430. westernMedicineCostSelfTotal = westernMedicineCostTotal
  7431. }
  7432. if item.MedChrgitmType == "11" { //中成费
  7433. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7434. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  7435. }
  7436. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  7437. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7438. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7439. otherCostSelfTotal = otherCostTotal
  7440. }
  7441. } else {
  7442. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7443. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7444. otherCostSelfTotal = otherCostTotal
  7445. }
  7446. }
  7447. }
  7448. } else {
  7449. for _, item := range orderInfos {
  7450. if item.MedChrgitmType == "01" { //床位费
  7451. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7452. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7453. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7454. }
  7455. if item.MedChrgitmType == "02" { //诊察费
  7456. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7457. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7458. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7459. }
  7460. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  7461. if item.MedChrgitmType == "03" { //检查费
  7462. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7463. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7464. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7465. }
  7466. } else {
  7467. if item.MedChrgitmType == "03" { //检查费
  7468. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7469. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7470. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7471. }
  7472. }
  7473. if item.MedChrgitmType == "04" { //化验费
  7474. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7475. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7476. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7477. }
  7478. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7479. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7480. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7481. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7482. }
  7483. if item.MedChrgitmType == "06" { //手术费
  7484. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7485. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7486. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7487. }
  7488. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  7489. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7490. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7491. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7492. }
  7493. if item.MedChrgitmType == "09" { //西药费
  7494. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7495. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7496. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7497. }
  7498. if item.MedChrgitmType == "11" { //中成费
  7499. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7500. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7501. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7502. }
  7503. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7504. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7505. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7506. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7507. }
  7508. }
  7509. }
  7510. timeLayout := "2006-01-02"
  7511. loc, _ := time.LoadLocation("Local")
  7512. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  7513. if err != nil {
  7514. }
  7515. startRecordDateTime := startTime.Unix()
  7516. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  7517. if err != nil {
  7518. }
  7519. endRecordDateTime := endTime.Unix()
  7520. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  7521. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  7522. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  7523. c.ServeSuccessJSON(map[string]interface{}{
  7524. "order_number": order.Number, //业务流水号
  7525. "id_card_no": his.IdCardNo, //社会保障号
  7526. "department_name": department.Name, //科室
  7527. "number": his.Number, //门诊号
  7528. "date": order.SettleAccountsDate, //结算日期
  7529. "name": order.PsnName, //姓名
  7530. "gender": patient.Gender, //性别
  7531. "psn_cash_money": order.PsnCashPay, //个人支付
  7532. "pay_way": "门诊", //结算方式
  7533. "medfee_sumamt": order.MedfeeSumamt, //总费用
  7534. "admin_user_name": admin.UserName, //收款员
  7535. "order": order,
  7536. "order_info": orderInfos_two,
  7537. "his": his,
  7538. "bedCostTotal": bedCostTotal,
  7539. "bedCostSelfTotal": bedCostSelfTotal,
  7540. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  7541. "operationCostTotal": operationCostTotal,
  7542. "operationCostSelfTotal": operationCostSelfTotal,
  7543. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  7544. "otherCostTotal": otherCostTotal,
  7545. "otherCostSelfTotal": otherCostSelfTotal,
  7546. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  7547. "materialCostTotal": materialCostTotal,
  7548. "materialCostSelfTotal": materialCostSelfTotal,
  7549. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  7550. "westernMedicineCostTotal": westernMedicineCostTotal,
  7551. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  7552. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  7553. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7554. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  7555. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  7556. "checkCostTotal": checkCostTotal,
  7557. "checkCostSelfTotal": checkCostSelfTotal,
  7558. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  7559. "laboratoryCostTotal": laboratoryCostTotal,
  7560. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  7561. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  7562. "treatCostTotal": treatCostTotal,
  7563. "treatCostSelfTotal": treatCostSelfTotal,
  7564. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  7565. "zhenChaCostTotal": zhenChaCostTotal,
  7566. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  7567. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  7568. "his_hospital_record": his_hospital_record,
  7569. "pre_pay_money": pre_pay_money,
  7570. "refund_sum": sum,
  7571. })
  7572. }
  7573. func (this *HisApiController) GetIncomeStatisticsData() {
  7574. start_time := this.GetString("start_time")
  7575. end_time := this.GetString("end_time")
  7576. key_words := this.GetString("key_words")
  7577. limit, _ := this.GetInt64("limit")
  7578. page, _ := this.GetInt64("page")
  7579. if page <= 0 {
  7580. page = 1
  7581. }
  7582. if limit <= 0 {
  7583. limit = 10
  7584. }
  7585. statistics_type, _ := this.GetInt64("statistics_type")
  7586. admin := this.GetAdminUserInfo()
  7587. timeLayout := "2006-01-02"
  7588. loc, _ := time.LoadLocation("Local")
  7589. var theStartTIme int64
  7590. if len(start_time) > 0 {
  7591. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7592. if err != nil {
  7593. theStartTIme = 0
  7594. }
  7595. theStartTIme = theTime.Unix()
  7596. }
  7597. var theEndtTIme int64
  7598. if len(end_time) > 0 {
  7599. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7600. if err != nil {
  7601. theEndtTIme = 0
  7602. }
  7603. theEndtTIme = theTime.Unix()
  7604. }
  7605. if statistics_type == 1 {
  7606. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  7607. this.ServeSuccessJSON(map[string]interface{}{
  7608. "list": list,
  7609. "total": total,
  7610. })
  7611. } else {
  7612. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  7613. this.ServeSuccessJSON(map[string]interface{}{
  7614. "list": list,
  7615. "total": total,
  7616. })
  7617. }
  7618. }
  7619. func (c *HisApiController) PostProjectInformation() {
  7620. adminUser := c.GetAdminUserInfo()
  7621. orgId := adminUser.CurrentOrgId
  7622. dataBody := make(map[string]interface{}, 0)
  7623. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7624. if err != nil {
  7625. utils.ErrorLog(err.Error())
  7626. return
  7627. }
  7628. utils.ErrorLog("%v", dataBody)
  7629. var projectList []*models.HisProject
  7630. var total_goods []interface{}
  7631. tempProjects := dataBody["projects"].([]interface{})
  7632. total_goods = tempProjects
  7633. for index, projectMap := range tempProjects {
  7634. projectM := projectMap.(map[string]interface{})
  7635. var project models.HisProject
  7636. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  7637. utils.ErrorLog("project_name")
  7638. return
  7639. }
  7640. project_name, _ := projectM["project_name"].(string)
  7641. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  7642. err_log := models.ExportErrLog{
  7643. LogType: 6,
  7644. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7645. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  7646. Status: 1,
  7647. CreateTime: time.Now().Unix(),
  7648. UpdateTime: time.Now().Unix(),
  7649. ExportTime: time.Now().Unix(),
  7650. }
  7651. service.CreateExportErrLog(&err_log)
  7652. continue
  7653. }
  7654. project.ProjectName = project_name
  7655. prices := projectM["price"].(string)
  7656. price, _ := strconv.ParseFloat(prices, 64)
  7657. if price <= 0 { //名字为空则生成一条导入错误日志
  7658. err_log := models.ExportErrLog{
  7659. LogType: 6,
  7660. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7661. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  7662. Status: 1,
  7663. CreateTime: time.Now().Unix(),
  7664. UpdateTime: time.Now().Unix(),
  7665. ExportTime: time.Now().Unix(),
  7666. }
  7667. service.CreateExportErrLog(&err_log)
  7668. continue
  7669. }
  7670. project.Price = price
  7671. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  7672. utils.ErrorLog("unit_id")
  7673. return
  7674. }
  7675. unit := projectM["unit"].(string)
  7676. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  7677. err_log := models.ExportErrLog{
  7678. LogType: 6,
  7679. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7680. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  7681. Status: 1,
  7682. CreateTime: time.Now().Unix(),
  7683. UpdateTime: time.Now().Unix(),
  7684. ExportTime: time.Now().Unix(),
  7685. }
  7686. service.CreateExportErrLog(&err_log)
  7687. continue
  7688. }
  7689. project.Unit = unit
  7690. cost_classify := projectM["cost_classify"].(string)
  7691. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  7692. err_log := models.ExportErrLog{
  7693. LogType: 6,
  7694. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7695. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  7696. Status: 1,
  7697. CreateTime: time.Now().Unix(),
  7698. UpdateTime: time.Now().Unix(),
  7699. ExportTime: time.Now().Unix(),
  7700. }
  7701. service.CreateExportErrLog(&err_log)
  7702. continue
  7703. }
  7704. var costClassify = "费用类别"
  7705. var cost_classify_id int64
  7706. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  7707. if len(cost_classify) != 0 {
  7708. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  7709. if errcode == gorm.ErrRecordNotFound {
  7710. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  7711. dataconfig := models.DictDataconfig{
  7712. ParentId: costClassifyConfig.ID,
  7713. Module: "system",
  7714. OrgId: orgId,
  7715. Name: cost_classify,
  7716. FieldName: "",
  7717. Value: costConfig.Value + 1,
  7718. CreatedTime: "",
  7719. UpdatedTime: "",
  7720. CreateUserId: adminUser.AdminUser.Id,
  7721. Status: 1,
  7722. Remark: "",
  7723. DeleteIdSystem: 0,
  7724. Title: "",
  7725. Content: "",
  7726. Order: 0,
  7727. Code: "",
  7728. }
  7729. service.CreatedDicConfig(&dataconfig)
  7730. }
  7731. }
  7732. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  7733. for _, it := range costClassList {
  7734. if cost_classify == it.Name {
  7735. cost_classify_id = int64(it.Value)
  7736. }
  7737. }
  7738. project.CostClassify = cost_classify_id
  7739. executive_section := projectM["executive_section"].(string)
  7740. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  7741. err_log := models.ExportErrLog{
  7742. LogType: 6,
  7743. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7744. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  7745. Status: 1,
  7746. CreateTime: time.Now().Unix(),
  7747. UpdateTime: time.Now().Unix(),
  7748. ExportTime: time.Now().Unix(),
  7749. }
  7750. service.CreateExportErrLog(&err_log)
  7751. continue
  7752. }
  7753. if len(executive_section) != 0 {
  7754. //查找科室是否有内容
  7755. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  7756. if errcodedepart == gorm.ErrRecordNotFound {
  7757. department := models.XtHisDepartment{
  7758. Name: executive_section,
  7759. Status: 1,
  7760. UserOrgId: adminUser.CurrentOrgId,
  7761. CreatedTime: time.Now().Unix(),
  7762. }
  7763. service.CreateDePartment(&department)
  7764. }
  7765. }
  7766. var executive_section_id int64
  7767. departMentList, _ := service.GetAllDepartMent(orgId)
  7768. for _, it := range departMentList {
  7769. if executive_section == it.Name {
  7770. executive_section_id = it.ID
  7771. }
  7772. }
  7773. project.ExecutiveSection = executive_section_id
  7774. medical_coverage := projectM["medical_coverage"].(string)
  7775. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  7776. err_log := models.ExportErrLog{
  7777. LogType: 6,
  7778. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7779. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  7780. Status: 1,
  7781. CreateTime: time.Now().Unix(),
  7782. UpdateTime: time.Now().Unix(),
  7783. ExportTime: time.Now().Unix(),
  7784. }
  7785. service.CreateExportErrLog(&err_log)
  7786. continue
  7787. }
  7788. var medicalCoverage = "医保等级"
  7789. var medical_coverage_id int64
  7790. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  7791. if len(medical_coverage) != 0 {
  7792. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  7793. if errormedicalcoverage == gorm.ErrRecordNotFound {
  7794. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  7795. dataconfig := models.DictDataconfig{
  7796. ParentId: medicalCoverageConfig.ID,
  7797. Module: "system",
  7798. OrgId: orgId,
  7799. Name: medical_coverage,
  7800. FieldName: "",
  7801. Value: medicalCoverageConfig.Value + 1,
  7802. CreatedTime: "",
  7803. UpdatedTime: "",
  7804. CreateUserId: adminUser.AdminUser.Id,
  7805. Status: 1,
  7806. Remark: "",
  7807. DeleteIdSystem: 0,
  7808. Title: "",
  7809. Content: "",
  7810. Order: 0,
  7811. Code: "",
  7812. }
  7813. service.CreatedDicConfig(&dataconfig)
  7814. }
  7815. }
  7816. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  7817. for _, it := range medicalCoverageList {
  7818. if medical_coverage == it.Name {
  7819. medical_coverage_id = int64(it.Value)
  7820. }
  7821. }
  7822. project.MedicalCoverage = medical_coverage_id
  7823. pinyin := projectM["pinyin"].(string)
  7824. project.Pinyin = pinyin
  7825. wubi := projectM["wubi"].(string)
  7826. project.Wubi = wubi
  7827. statistical_classification := projectM["statistical_classification"].(string)
  7828. var statisticalClassification = "统计分类"
  7829. var statistical_classification_id int64
  7830. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  7831. if len(statistical_classification) != 0 {
  7832. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  7833. if classificationerrcodes == gorm.ErrRecordNotFound {
  7834. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  7835. dataconfig := models.DictDataconfig{
  7836. ParentId: classiFication.ID,
  7837. Module: "system",
  7838. OrgId: orgId,
  7839. Name: statistical_classification,
  7840. FieldName: "",
  7841. Value: classiFicationConfig.Value + 1,
  7842. CreatedTime: "",
  7843. UpdatedTime: "",
  7844. CreateUserId: adminUser.AdminUser.Id,
  7845. Status: 1,
  7846. Remark: "",
  7847. DeleteIdSystem: 0,
  7848. Title: "",
  7849. Content: "",
  7850. Order: 0,
  7851. Code: "",
  7852. }
  7853. service.CreatedDicConfig(&dataconfig)
  7854. }
  7855. }
  7856. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  7857. for _, it := range classiFicationList {
  7858. if statistical_classification == it.Name {
  7859. statistical_classification_id = int64(it.Value)
  7860. }
  7861. }
  7862. project.StatisticalClassification = statistical_classification_id
  7863. disease_directory := int64(projectM["disease_directory"].(float64))
  7864. project.DiseaseDirectory = disease_directory
  7865. is_record := int64(projectM["is_record"].(float64))
  7866. project.IsRecord = is_record
  7867. medical_code := projectM["medical_code"].(string)
  7868. project.MedicalCode = medical_code
  7869. tube_color := projectM["tube_color"].(string)
  7870. var tubeColor = "试管颜色"
  7871. var tube_color_id int64
  7872. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  7873. if len(tube_color) != 0 {
  7874. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  7875. if errcodetube == gorm.ErrRecordNotFound {
  7876. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  7877. dataconfig := models.DictDataconfig{
  7878. ParentId: tubeColorConfig.ID,
  7879. Module: "system",
  7880. OrgId: orgId,
  7881. Name: tube_color,
  7882. FieldName: "",
  7883. Value: tubeConfig.Value + 1,
  7884. CreatedTime: "",
  7885. UpdatedTime: "",
  7886. CreateUserId: adminUser.AdminUser.Id,
  7887. Status: 1,
  7888. Remark: "",
  7889. DeleteIdSystem: 0,
  7890. Title: "",
  7891. Content: "",
  7892. Order: 0,
  7893. Code: "",
  7894. }
  7895. service.CreatedDicConfig(&dataconfig)
  7896. }
  7897. }
  7898. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  7899. for _, it := range tubeColorList {
  7900. if tube_color == it.Name {
  7901. tube_color_id = int64(it.Value)
  7902. }
  7903. }
  7904. project.TubeColor = tube_color_id
  7905. single_dose := projectM["single_dose"].(string)
  7906. project.SingleDose = single_dose
  7907. execution_frequency := projectM["execution_frequency"].(string)
  7908. project.ExecutionFrequency = execution_frequency
  7909. delivery_way := projectM["delivery_way"].(string)
  7910. project.DeliveryWay = delivery_way
  7911. number_days := projectM["number_days"].(string)
  7912. project.NumberDays = number_days
  7913. total := projectM["total"].(string)
  7914. project.Total = total
  7915. medical_status := int64(projectM["medical_status"].(float64))
  7916. project.MedicalStatus = medical_status
  7917. category := int64(projectM["category"].(float64))
  7918. project.Category = category
  7919. specail_project := int64(projectM["specail_project"].(float64))
  7920. project.SpecailProject = specail_project
  7921. social_security_directory_code := projectM["social_security_directory_code"].(string)
  7922. project.SocialSecurityDirectoryCode = social_security_directory_code
  7923. remark := projectM["remark"].(string)
  7924. project.Remark = remark
  7925. record_date := projectM["record_date"].(string)
  7926. timeLayout := "2006-01-02"
  7927. loc, _ := time.LoadLocation("Local")
  7928. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7929. project.RecordDate = theTime.Unix()
  7930. projectList = append(projectList, &project)
  7931. }
  7932. export_time := time.Now().Unix()
  7933. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  7934. if len(projectList) > 0 {
  7935. for _, item := range projectList {
  7936. project := models.HisProject{
  7937. ProjectName: item.ProjectName,
  7938. Price: item.Price,
  7939. Unit: item.Unit,
  7940. CostClassify: item.CostClassify,
  7941. ExecutiveSection: item.ExecutiveSection,
  7942. MedicalCoverage: item.MedicalCoverage,
  7943. UserOrgId: orgId,
  7944. Status: 1,
  7945. CreatedTime: time.Now().Unix(),
  7946. Pinyin: item.Pinyin,
  7947. Wubi: item.Wubi,
  7948. StatisticalClassification: item.StatisticalClassification,
  7949. DiseaseDirectory: item.DiseaseDirectory,
  7950. IsRecord: item.IsRecord,
  7951. MedicalCode: item.MedicalCode,
  7952. TubeColor: item.TubeColor,
  7953. SingleDose: item.SingleDose,
  7954. DeliveryWay: item.DeliveryWay,
  7955. NumberDays: item.NumberDays,
  7956. Total: item.Total,
  7957. Category: item.Category,
  7958. MedicalStatus: item.MedicalStatus,
  7959. SpecailProject: item.SpecailProject,
  7960. RecordDate: item.RecordDate,
  7961. Remark: item.Remark,
  7962. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  7963. ExecutionFrequency: item.ExecutionFrequency,
  7964. }
  7965. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  7966. if errcodeproject == gorm.ErrRecordNotFound {
  7967. service.CreateProjectInfomation(&project)
  7968. } else if errcodeproject == nil {
  7969. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  7970. }
  7971. log := models.ExportLog{
  7972. LogType: 6,
  7973. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7974. TotalNum: int64(len(total_goods)),
  7975. FailNum: int64(len(errLogs)),
  7976. SuccessNum: int64(len(projectList)),
  7977. CreateTime: time.Now().Unix(),
  7978. UpdateTime: time.Now().Unix(),
  7979. ExportTime: export_time,
  7980. Status: 1,
  7981. }
  7982. service.CreateExportLog(&log)
  7983. c.ServeSuccessJSON(map[string]interface{}{
  7984. "msg": "导入成功",
  7985. "total_num": len(total_goods),
  7986. "success_num": len(projectList),
  7987. "fail_num": int64(len(errLogs)),
  7988. })
  7989. }
  7990. } else {
  7991. log := models.ExportLog{
  7992. LogType: 6,
  7993. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7994. TotalNum: int64(len(total_goods)),
  7995. FailNum: int64(len(errLogs)),
  7996. SuccessNum: int64(len(projectList)),
  7997. CreateTime: time.Now().Unix(),
  7998. UpdateTime: time.Now().Unix(),
  7999. ExportTime: export_time,
  8000. Status: 1,
  8001. }
  8002. service.CreateExportLog(&log)
  8003. c.ServeSuccessJSON(map[string]interface{}{
  8004. "msg": "导入成功",
  8005. "total_num": len(total_goods),
  8006. "success_num": len(projectList),
  8007. "fail_num": int64(len(errLogs)),
  8008. })
  8009. }
  8010. }
  8011. //func (this *HisApiController) EditProjectInformation(){
  8012. //
  8013. // id, _ := this.GetInt64("id")
  8014. // project_team := this.GetString("project_team")
  8015. // price := this.GetString("price")
  8016. // price_float, _ := strconv.ParseFloat(price, 64)
  8017. // pinyin := this.GetString("pinyin")
  8018. // wubi := this.GetString("wubi")
  8019. // tube_color, _ := this.GetInt64("tube_color")
  8020. // team_type, _ := this.GetInt64("team_type")
  8021. // remark := this.GetString("remark")
  8022. // ids := this.GetString("ids")
  8023. // item_id := this.GetString("item_id")
  8024. // projectTeam := models.XtHisProjectTeam{
  8025. // ProjectTeam: project_team,
  8026. // Price: price_float,
  8027. // Pinyin: pinyin,
  8028. // Wubi: wubi,
  8029. // TubeColor: tube_color,
  8030. // TeamType: team_type,
  8031. // Remark: remark,
  8032. // ProjectId: ids,
  8033. // ItemId: item_id,
  8034. // }
  8035. //
  8036. //
  8037. // dataBody := make(map[string]interface{}, 0)
  8038. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8039. // if err != nil {
  8040. // utils.ErrorLog(err.Error())
  8041. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8042. // return
  8043. // }
  8044. //
  8045. // err = service.UpdatedProjectTeam(id, &projectTeam)
  8046. //
  8047. //
  8048. // if err != nil {
  8049. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  8050. // return
  8051. // }
  8052. //
  8053. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  8054. // infos, _ := dataBody["info"].([]interface{})
  8055. // if len(infos) > 0 {
  8056. // var ids []string
  8057. //
  8058. // for _, item := range infos {
  8059. // items := item.(map[string]interface{})
  8060. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  8061. // utils.ErrorLog("id")
  8062. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8063. // return
  8064. // }
  8065. // id := int64(items["id"].(float64))
  8066. //
  8067. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8068. // utils.ErrorLog("type")
  8069. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8070. // return
  8071. // }
  8072. // types := int64(items["type"].(float64))
  8073. //
  8074. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  8075. // utils.ErrorLog("number")
  8076. // }
  8077. //
  8078. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  8079. //
  8080. // projectList := models.XtHisProjectList{
  8081. // Number: number,
  8082. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  8083. // ProjectId: id,
  8084. // Status: 1,
  8085. // CreatedTime: time.Now().Unix(),
  8086. // UpdatedTime: time.Now().Unix(),
  8087. // TeamId: projectTeam.ID,
  8088. // Type: types,
  8089. // }
  8090. // list := projectList
  8091. //
  8092. // service.CreateProjectList(&list)
  8093. //
  8094. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  8095. //
  8096. // }
  8097. // ids_str := strings.Join(ids, ",")
  8098. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  8099. // service.SaveProjectTeam(&projectTeam)
  8100. // this.ServeSuccessJSON(map[string]interface{}{
  8101. // "projectTeam": projectTeam,
  8102. // })
  8103. // }
  8104. // }
  8105. //}
  8106. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  8107. name := c.GetString("name")
  8108. mode_id, _ := c.GetInt64("mode", 0)
  8109. types, _ := c.GetInt64("type", 0)
  8110. patient_id, _ := c.GetInt64("patient_id", 0)
  8111. types = 1
  8112. adminInfo := c.GetAdminUserInfo()
  8113. template := &models.HisPrescriptionTemplate{
  8114. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8115. PatientId: patient_id,
  8116. Type: types,
  8117. Status: 1,
  8118. Ctime: time.Now().Unix(),
  8119. Mtime: time.Now().Unix(),
  8120. Name: name,
  8121. Mode: mode_id,
  8122. }
  8123. dataBody := make(map[string]interface{}, 0)
  8124. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8125. if err != nil {
  8126. utils.ErrorLog(err.Error())
  8127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8128. return
  8129. }
  8130. err = service.CreateHisPrescriptionTemplate(template)
  8131. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  8132. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  8133. if len(prescriptions) > 0 {
  8134. for _, item := range prescriptions {
  8135. items := item.(map[string]interface{})
  8136. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8137. utils.ErrorLog("type")
  8138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8139. return
  8140. }
  8141. types := int64(items["type"].(float64))
  8142. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  8143. utils.ErrorLog("med_type")
  8144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8145. return
  8146. }
  8147. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  8148. ctime := time.Now().Unix()
  8149. prescription := &models.HisPrescriptionInfoTemplate{
  8150. PatientId: patient_id,
  8151. UserOrgId: adminInfo.CurrentOrgId,
  8152. Ctime: ctime,
  8153. Mtime: ctime,
  8154. Type: types,
  8155. Modifier: adminInfo.AdminUser.Id,
  8156. Creator: adminInfo.AdminUser.Id,
  8157. Status: 1,
  8158. PTemplateId: template.ID,
  8159. MedType: med_type,
  8160. }
  8161. service.CreateHisPrescriptionInfoTemplate(prescription)
  8162. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  8163. advices := items["advices"].([]interface{})
  8164. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  8165. ctime := time.Now().Unix()
  8166. mtime := ctime
  8167. if len(advices) > 0 {
  8168. for _, advice := range advices {
  8169. var s models.HisPrescriptionAdviceTemplate
  8170. s.PrescriptionId = prescription.ID
  8171. s.AdviceType = 2
  8172. s.StopState = 2
  8173. s.ExecutionState = 2
  8174. s.Status = 1
  8175. s.UserOrgId = adminInfo.CurrentOrgId
  8176. s.CreatedTime = ctime
  8177. s.UpdatedTime = mtime
  8178. s.PatientId = patient_id
  8179. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  8180. if errcode > 0 {
  8181. c.ServeFailJSONWithSGJErrorCode(errcode)
  8182. return
  8183. }
  8184. service.CreateHisPrescriptionAdviceTemplate(&s)
  8185. }
  8186. }
  8187. }
  8188. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  8189. projects := items["project"].([]interface{})
  8190. if len(projects) > 0 {
  8191. for _, project := range projects {
  8192. var p models.HisPrescriptionProjectTemplate
  8193. p.PrescriptionId = prescription.ID
  8194. p.Ctime = time.Now().Unix()
  8195. p.Mtime = time.Now().Unix()
  8196. p.PatientId = patient_id
  8197. p.UserOrgId = adminInfo.CurrentOrgId
  8198. p.Status = 1
  8199. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  8200. if errcode > 0 {
  8201. c.ServeFailJSONWithSGJErrorCode(errcode)
  8202. return
  8203. }
  8204. service.CreateHisPrescriptionProjectTemplate(&p)
  8205. }
  8206. }
  8207. }
  8208. }
  8209. c.ServeSuccessJSON(map[string]interface{}{
  8210. "msg": "创建成功",
  8211. })
  8212. }
  8213. }
  8214. }
  8215. func (c *HisApiController) PreSettle() {
  8216. id, _ := c.GetInt64("id")
  8217. record_time := c.GetString("record_time")
  8218. his_patient_id, _ := c.GetInt64("his_patient_id")
  8219. timeLayout := "2006-01-02"
  8220. loc, _ := time.LoadLocation("Local")
  8221. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  8222. diagnosis_id := c.GetString("diagnosis")
  8223. sick_type, _ := c.GetInt64("sick_type")
  8224. reg_type, _ := c.GetInt64("p_type")
  8225. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  8226. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8227. if err != nil {
  8228. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8229. return
  8230. }
  8231. recordDateTime := theTime.Unix()
  8232. adminUser := c.GetAdminUserInfo()
  8233. var prescriptions []*models.HisPrescription
  8234. var start_time int64
  8235. var end_time int64
  8236. ids_str := c.GetString("ids")
  8237. ids_arr := strings.Split(ids_str, ",")
  8238. fmt.Println(reg_type)
  8239. if settle_accounts_type == 1 { //日结
  8240. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  8241. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  8242. } else {
  8243. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  8244. }
  8245. fmt.Println(prescriptions)
  8246. } else { //月结
  8247. start_time_str := c.GetString("start_time")
  8248. end_time_str := c.GetString("end_time")
  8249. timeLayout := "2006-01-02"
  8250. loc, _ := time.LoadLocation("Local")
  8251. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  8252. if err != nil {
  8253. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8254. return
  8255. }
  8256. recordStartTime := theStartTime.Unix()
  8257. start_time = recordStartTime
  8258. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  8259. if err != nil {
  8260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8261. return
  8262. }
  8263. recordEndTime := theEndTime.Unix()
  8264. end_time = recordEndTime
  8265. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  8266. }
  8267. if reg_type == 1111 || reg_type == 1112 {
  8268. reg_type = 11
  8269. }
  8270. timestamp := time.Now().Unix()
  8271. tempTime := time.Unix(timestamp, 0)
  8272. timeFormat := tempTime.Format("20060102150405")
  8273. chrgBchno := rand.Intn(100000) + 10000
  8274. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  8275. strconv.FormatInt(his.PatientId, 10)
  8276. var ids []int64
  8277. for _, item := range prescriptions {
  8278. ids = append(ids, item.ID)
  8279. }
  8280. fmt.Println(ids)
  8281. var total float64
  8282. for _, item := range prescriptions {
  8283. fmt.Println(item)
  8284. if item.Type == 1 { //药品
  8285. for _, subItem := range item.HisDoctorAdviceInfo {
  8286. total = total + (subItem.Price * subItem.PrescribingNumber)
  8287. }
  8288. }
  8289. if item.Type == 2 { //项目
  8290. for _, subItem := range item.HisPrescriptionProject {
  8291. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8292. total = total + (subItem.Price * cnt)
  8293. }
  8294. }
  8295. for _, subItem := range item.HisAdditionalCharge {
  8296. total = total + (subItem.Price * float64(subItem.Count))
  8297. }
  8298. }
  8299. allTotal := fmt.Sprintf("%.2f", total)
  8300. totals, _ := strconv.ParseFloat(allTotal, 64)
  8301. order := &models.HisOrder{
  8302. UserOrgId: adminUser.CurrentOrgId,
  8303. HisPatientId: his.ID,
  8304. PatientId: id,
  8305. SettleAccountsDate: recordDateTime,
  8306. Ctime: time.Now().Unix(),
  8307. Mtime: time.Now().Unix(),
  8308. Status: 1,
  8309. OrderStatus: 1,
  8310. MdtrtId: his.Number,
  8311. Number: chrg_bchno,
  8312. MedfeeSumamt: totals,
  8313. SettleEndTime: end_time,
  8314. SettleStartTime: start_time,
  8315. SettleType: settle_accounts_type,
  8316. PsnPartAmt: totals,
  8317. PsnCashPay: totals,
  8318. PType: 2,
  8319. IsPre: 1,
  8320. MedType: strconv.Itoa(int(reg_type)),
  8321. Diagnosis: diagnosis_id,
  8322. }
  8323. err = service.CreateOrder(order)
  8324. if err != nil {
  8325. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8326. return
  8327. }
  8328. var customs []*Custom
  8329. for _, item := range prescriptions {
  8330. fmt.Println(item.Type)
  8331. if item.Type == 1 { //药品
  8332. for _, subItem := range item.HisDoctorAdviceInfo {
  8333. cus := &Custom{
  8334. AdviceId: subItem.ID,
  8335. ProjectId: 0,
  8336. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  8337. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  8338. FeedetlSn: subItem.FeedetlSn,
  8339. Price: fmt.Sprintf("%.2f", subItem.Price),
  8340. MedListCodg: subItem.MedListCodg,
  8341. Type: 1,
  8342. }
  8343. customs = append(customs, cus)
  8344. }
  8345. }
  8346. if item.Type == 2 { //项目
  8347. for _, subItem := range item.HisPrescriptionProject {
  8348. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8349. cus := &Custom{
  8350. AdviceId: 0,
  8351. ProjectId: subItem.ID,
  8352. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  8353. Cut: fmt.Sprintf("%.2f", cnt),
  8354. FeedetlSn: subItem.FeedetlSn,
  8355. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  8356. MedListCodg: subItem.MedListCodg,
  8357. Type: 2,
  8358. }
  8359. customs = append(customs, cus)
  8360. }
  8361. }
  8362. for _, item := range item.HisAdditionalCharge {
  8363. cus := &Custom{
  8364. ItemId: item.ID,
  8365. AdviceId: 0,
  8366. ProjectId: 0,
  8367. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  8368. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  8369. FeedetlSn: item.FeedetlSn,
  8370. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  8371. MedListCodg: item.XtHisAddtionConfig.Code,
  8372. Type: 3,
  8373. }
  8374. customs = append(customs, cus)
  8375. }
  8376. }
  8377. fmt.Println(customs)
  8378. for _, item := range customs {
  8379. var advice_id int64 = 0
  8380. var project_id int64 = 0
  8381. var item_id int64 = 0
  8382. var types int64 = 0
  8383. if item.Type == 1 {
  8384. advice_id = item.AdviceId
  8385. project_id = 0
  8386. item_id = 0
  8387. } else if item.Type == 2 {
  8388. advice_id = 0
  8389. item_id = 0
  8390. project_id = item.ProjectId
  8391. } else if item.Type == 3 {
  8392. advice_id = 0
  8393. item_id = item.ItemId
  8394. project_id = 0
  8395. }
  8396. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8397. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8398. pric, _ := strconv.ParseFloat(item.Price, 32)
  8399. info := &models.HisOrderInfo{
  8400. OrderNumber: order.Number,
  8401. UploadDate: time.Now().Unix(),
  8402. AdviceId: advice_id,
  8403. DetItemFeeSumamt: detItemFeeSumamt,
  8404. Cnt: cut,
  8405. Pric: pric,
  8406. PatientId: id,
  8407. Status: 1,
  8408. Mtime: time.Now().Unix(),
  8409. Ctime: time.Now().Unix(),
  8410. UserOrgId: adminUser.CurrentOrgId,
  8411. HisPatientId: his.ID,
  8412. OrderId: order.ID,
  8413. ProjectId: project_id,
  8414. Type: types,
  8415. ItemId: item_id,
  8416. }
  8417. service.CreateOrderInfo(info)
  8418. }
  8419. his.SickType = sick_type
  8420. service.UpdataHisPateint(&his)
  8421. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  8422. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  8423. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  8424. if err == nil {
  8425. c.ServeSuccessJSON(map[string]interface{}{
  8426. "msg": "结算成功",
  8427. })
  8428. }
  8429. }
  8430. type CustomOrderInfo struct {
  8431. Name string
  8432. Spec string
  8433. Unit string
  8434. Count float64
  8435. Price float64
  8436. Total float64
  8437. }
  8438. func (c *HisApiController) GetPrivateExpensesInfo() {
  8439. order_id, _ := c.GetInt64("id", 0)
  8440. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  8441. order, _ := service.GetHisOrderByID(order_id)
  8442. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  8443. if order.ID == 0 {
  8444. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8445. return
  8446. }
  8447. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  8448. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  8449. org_id := c.GetAdminUserInfo().CurrentOrgId
  8450. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8451. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8452. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  8453. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  8454. orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  8455. var orderInfos_four []*models.HisOrderInfoTwo
  8456. for _, item := range orderInfos_three {
  8457. if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  8458. item.HisPrescriptionProject.IsCheckTeam = 1
  8459. orderInfos_four = append(orderInfos_four, item)
  8460. }
  8461. if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  8462. item.HisPrescriptionProject.IsCheckTeam = 2
  8463. orderInfos_two = append(orderInfos_two, item)
  8464. }
  8465. }
  8466. new_order_info := RemoveRepeatedTeam(orderInfos_four)
  8467. var cus_slice []CustomOrderInfo
  8468. for _, item := range new_order_info {
  8469. var cus CustomOrderInfo
  8470. cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  8471. cus.Unit = ""
  8472. cus.Spec = ""
  8473. var total float64
  8474. for _, subItem := range orderInfos_four {
  8475. if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  8476. total = total + subItem.DetItemFeeSumamt
  8477. fmt.Println(subItem.DetItemFeeSumamt)
  8478. }
  8479. }
  8480. cus.Count = 1
  8481. cus.Total = total
  8482. cus_slice = append(cus_slice, cus)
  8483. }
  8484. orderInfos = append(orderInfos, orderInfos_two...)
  8485. if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  8486. orderInfos = append(orderInfos, orderInfos_three...)
  8487. }
  8488. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  8489. c.ServeSuccessJSON(map[string]interface{}{
  8490. "order": order,
  8491. "order_info": orderInfos,
  8492. "patient": patient,
  8493. "admin_info": adminInfo,
  8494. "his": his,
  8495. "current_admin": role,
  8496. "org_config": miConfig,
  8497. "new_order_info": cus_slice,
  8498. })
  8499. }
  8500. func (this *HisApiController) ChangeMedType() {
  8501. med_type := this.GetString("med_type")
  8502. old_med_type := this.GetString("old_med_type")
  8503. ids := this.GetString("ids")
  8504. settle_type, _ := this.GetInt64("settle_type")
  8505. start_time := this.GetString("start_time")
  8506. end_time := this.GetString("end_time")
  8507. ids_arr := strings.Split(ids, ",")
  8508. if settle_type == 1 { //日结
  8509. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  8510. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  8511. prescription.MedType = med_type
  8512. err := service.SaveHisPrescription(&prescription)
  8513. if err == nil {
  8514. this.ServeSuccessJSON(map[string]interface{}{
  8515. "msg": "修改成功",
  8516. })
  8517. } else {
  8518. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8519. return
  8520. }
  8521. } else if settle_type == 2 {
  8522. timeLayout := "2006-01-02"
  8523. loc, _ := time.LoadLocation("Local")
  8524. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8525. if err != nil {
  8526. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8527. return
  8528. }
  8529. recordStartTime := theStartTime.Unix()
  8530. start_time_timestamp := recordStartTime
  8531. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8532. if err != nil {
  8533. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8534. return
  8535. }
  8536. recordEndTime := theEndTime.Unix()
  8537. end_time_timestamp := recordEndTime
  8538. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  8539. if updateErr == nil {
  8540. this.ServeSuccessJSON(map[string]interface{}{
  8541. "msg": "修改成功",
  8542. })
  8543. } else {
  8544. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8545. return
  8546. }
  8547. }
  8548. }
  8549. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  8550. patient_id, _ := c.GetInt64("patient_id")
  8551. his_patient_id, _ := c.GetInt64("his_patient_id")
  8552. record_date := c.GetString("record_date")
  8553. start_time := c.GetString("start_time")
  8554. end_time := c.GetString("end_time")
  8555. order_status, _ := c.GetInt64("type", 0)
  8556. p_type, _ := c.GetInt64("p_type", 0)
  8557. order_id, _ := c.GetInt64("order_id", 0)
  8558. timeLayout := "2006-01-02"
  8559. loc, _ := time.LoadLocation("Local")
  8560. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8561. if err != nil {
  8562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8563. return
  8564. }
  8565. recordDateTime := theTime.Unix()
  8566. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8567. if err != nil {
  8568. }
  8569. startRecordDateTime := startTime.Unix()
  8570. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8571. if err != nil {
  8572. }
  8573. endRecordDateTime := endTime.Unix()
  8574. admin := c.GetAdminUserInfo()
  8575. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8576. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8577. order, _ := service.GetHisOrderByID(order_id)
  8578. var monthPrescriptions []*models.HisPrescription
  8579. if order_status == 1 || order_status == 0 {
  8580. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8581. } else if order_status == 2 {
  8582. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  8583. }
  8584. var settle_total float64
  8585. for _, item := range monthPrescriptions {
  8586. if len(item.HisPrescriptionProject) > 0 {
  8587. for _, subItem := range item.HisPrescriptionProject {
  8588. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8589. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8590. settle_total = settle_total + total
  8591. }
  8592. }
  8593. if len(item.HisDoctorAdviceInfo) > 0 {
  8594. for _, subItem := range item.HisDoctorAdviceInfo {
  8595. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8596. settle_total = settle_total + total
  8597. }
  8598. }
  8599. }
  8600. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8601. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8602. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8603. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8604. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8605. //获取所有科室信息
  8606. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8607. c.ServeSuccessJSON(map[string]interface{}{
  8608. "his_info": his_patient_info,
  8609. "xt_info": xt_patient_info,
  8610. "case_history": case_history,
  8611. "info": patientPrescriptionInfo,
  8612. "last_info": lastPatientPrescriptionInfo,
  8613. "month_prescriptions": monthPrescriptions,
  8614. "order": order,
  8615. "doctors": doctors,
  8616. "department": department,
  8617. "settle_total": settle_total,
  8618. })
  8619. return
  8620. }
  8621. func (c *HisApiController) GetHisMonthPatientInfo() {
  8622. patient_id, _ := c.GetInt64("patient_id")
  8623. his_patient_id, _ := c.GetInt64("his_patient_id")
  8624. record_date := c.GetString("record_date")
  8625. number := c.GetString("number")
  8626. start_time := c.GetString("start_time")
  8627. end_time := c.GetString("end_time")
  8628. p_type, _ := c.GetInt64("p_type")
  8629. timeLayout := "2006-01-02"
  8630. loc, _ := time.LoadLocation("Local")
  8631. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8632. if err != nil {
  8633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8634. return
  8635. }
  8636. recordDateTime := theTime.Unix()
  8637. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8638. if err != nil {
  8639. }
  8640. startRecordDateTime := startTime.Unix()
  8641. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8642. if err != nil {
  8643. }
  8644. endRecordDateTime := endTime.Unix()
  8645. admin := c.GetAdminUserInfo()
  8646. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  8647. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8648. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  8649. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8650. var settle_total float64
  8651. for _, item := range monthPrescriptions {
  8652. if len(item.HisPrescriptionProject) > 0 {
  8653. for _, subItem := range item.HisPrescriptionProject {
  8654. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8655. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8656. settle_total = settle_total + total
  8657. }
  8658. }
  8659. if len(item.HisDoctorAdviceInfo) > 0 {
  8660. for _, subItem := range item.HisDoctorAdviceInfo {
  8661. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8662. settle_total = settle_total + total
  8663. }
  8664. }
  8665. }
  8666. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8667. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8668. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8669. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8670. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  8671. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8672. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  8673. //获取所有科室信息
  8674. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8675. c.ServeSuccessJSON(map[string]interface{}{
  8676. "his_info": his_patient_info,
  8677. "xt_info": xt_patient_info,
  8678. "case_history": case_history,
  8679. "info": patientPrescriptionInfo,
  8680. "month_prescriptions": monthPrescriptions,
  8681. "order": order,
  8682. "doctors": doctors,
  8683. "department": department,
  8684. "count": count,
  8685. "drugStockConfig": drugStockConfig,
  8686. "last_info": lastPatientPrescriptionInfo,
  8687. "settle_total": settle_total,
  8688. })
  8689. return
  8690. }
  8691. func (c *HisApiController) GetAllOrder() {
  8692. org_id := c.GetAdminUserInfo().CurrentOrgId
  8693. orders, _ := service.GetNewHisOrderList(org_id)
  8694. c.ServeSuccessJSON(map[string]interface{}{
  8695. "order": orders,
  8696. })
  8697. return
  8698. }
  8699. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  8700. newArr = make([]*models.HisOrderInfoTwo, 0)
  8701. for i := 0; i < len(arr); i++ {
  8702. repeat := false
  8703. for j := i + 1; j < len(arr); j++ {
  8704. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  8705. repeat = true
  8706. break
  8707. }
  8708. }
  8709. if !repeat {
  8710. newArr = append(newArr, arr[i])
  8711. }
  8712. }
  8713. return
  8714. }
  8715. // 修改处方退库操作 参数传修改之前的处方数据
  8716. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  8717. if advice.ExecutionState == 1 {
  8718. //查询该病人该药品是否有库存记录
  8719. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  8720. if errcode == gorm.ErrRecordNotFound {
  8721. } else {
  8722. //退库
  8723. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8724. if advice.PrescribingNumberUnit == drug.MinUnit {
  8725. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  8726. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  8727. //退库
  8728. warehouseInfo := models.DrugWarehouseInfo{
  8729. StockMinNumber: prescribingNumber,
  8730. }
  8731. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  8732. operation_time := time.Now().Unix()
  8733. creater := advice.AdviceDoctor
  8734. ctime := time.Now().Unix()
  8735. timeStr := time.Now().Format("2006-01-02")
  8736. timeArr := strings.Split(timeStr, "-")
  8737. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  8738. total = total + 1
  8739. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8740. cancelStock := models.DrugCancelStock{
  8741. OrderNumber: orderNumber,
  8742. OperaTime: operation_time,
  8743. OrgId: advice.UserOrgId,
  8744. Creater: creater,
  8745. Ctime: ctime,
  8746. Status: 1,
  8747. ReturnTime: advice.AdviceDate,
  8748. Dealer: info.Dealer,
  8749. Manufacturer: info.Manufacturer,
  8750. Type: 1,
  8751. }
  8752. service.AddSigleDrugCancelStock(&cancelStock)
  8753. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  8754. dealer, _ := service.GetDealerById(info.Dealer)
  8755. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  8756. cancelStockInfo := models.DrugCancelStockInfo{
  8757. OrderNumber: cancelInfo.OrderNumber,
  8758. CancelStockId: cancelInfo.ID,
  8759. DrugId: info.DrugId,
  8760. Count: info.Count,
  8761. Status: 1,
  8762. Ctime: ctime,
  8763. OrgId: advice.UserOrgId,
  8764. Type: 1,
  8765. Manufacturer: manufactureName.ManufacturerName,
  8766. Dealer: dealer.DealerName,
  8767. Total: 0,
  8768. RetailPrice: info.RetailPrice,
  8769. RetailTotalPrice: info.RetailTotalPrice,
  8770. Price: info.Price,
  8771. RegisterAccount: "",
  8772. Remark: info.Remark,
  8773. BatchNumber: info.BatchNumber,
  8774. MaxUnit: info.CountUnit,
  8775. ProductDate: info.ProductDate,
  8776. ExpiryDate: info.ExpiryDate,
  8777. BatchNumberId: info.WarehouseInfoId,
  8778. }
  8779. flow := models.DrugFlow{
  8780. WarehousingId: 0,
  8781. DrugId: info.DrugId,
  8782. Number: "",
  8783. BatchNumber: info.BatchNumber,
  8784. Count: info.Count,
  8785. UserOrgId: advice.UserOrgId,
  8786. PatientId: 0,
  8787. SystemTime: ctime,
  8788. ConsumableType: 4,
  8789. IsSys: 0,
  8790. WarehousingOrder: "",
  8791. WarehouseOutId: 0,
  8792. WarehouseOutOrderNumber: "",
  8793. IsEdit: 0,
  8794. CancelStockId: cancelStock.ID,
  8795. CancelOrderNumber: cancelStock.OrderNumber,
  8796. Manufacturer: info.Manufacturer,
  8797. Dealer: info.Dealer,
  8798. Creator: advice.UserOrgId,
  8799. UpdateCreator: 0,
  8800. Status: 1,
  8801. Ctime: time.Now().Unix(),
  8802. Mtime: 0,
  8803. Price: info.Price,
  8804. WarehousingDetailId: 0,
  8805. WarehouseOutDetailId: 0,
  8806. CancelOutDetailId: 0,
  8807. ExpireDate: info.ExpiryDate,
  8808. ProductDate: info.ProductDate,
  8809. MaxUnit: info.CountUnit,
  8810. MinUnit: "",
  8811. }
  8812. service.CreatedCancelStock(cancelStockInfo)
  8813. service.CreateDrugFlowOne(flow)
  8814. } else {
  8815. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  8816. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  8817. if advice.PrescribingNumberUnit == drug.MaxUnit {
  8818. warehouseInfo := models.DrugWarehouseInfo{
  8819. StockMinNumber: prescribingNumber,
  8820. }
  8821. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  8822. }
  8823. operation_time := time.Now().Unix()
  8824. creater := advice.AdviceDoctor
  8825. ctime := time.Now().Unix()
  8826. timeStr := time.Now().Format("2006-01-02")
  8827. timeArr := strings.Split(timeStr, "-")
  8828. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  8829. total = total + 1
  8830. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8831. cancelStock := models.DrugCancelStock{
  8832. OrderNumber: orderNumber,
  8833. OperaTime: operation_time,
  8834. OrgId: advice.UserOrgId,
  8835. Creater: creater,
  8836. Ctime: ctime,
  8837. Status: 1,
  8838. ReturnTime: advice.AdviceDate,
  8839. Dealer: info.Dealer,
  8840. Manufacturer: info.Manufacturer,
  8841. Type: 1,
  8842. }
  8843. service.AddSigleDrugCancelStock(&cancelStock)
  8844. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  8845. dealer, _ := service.GetDealerById(info.Dealer)
  8846. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  8847. cancelStockInfo := models.DrugCancelStockInfo{
  8848. OrderNumber: cancelInfo.OrderNumber,
  8849. CancelStockId: cancelInfo.ID,
  8850. DrugId: info.DrugId,
  8851. Count: info.Count,
  8852. Status: 1,
  8853. Ctime: ctime,
  8854. OrgId: advice.UserOrgId,
  8855. Type: 1,
  8856. Manufacturer: manufactureName.ManufacturerName,
  8857. Dealer: dealer.DealerName,
  8858. Total: 0,
  8859. RetailPrice: info.RetailPrice,
  8860. RetailTotalPrice: info.RetailTotalPrice,
  8861. Price: info.Price,
  8862. RegisterAccount: "",
  8863. Remark: info.Remark,
  8864. BatchNumber: info.BatchNumber,
  8865. MaxUnit: info.CountUnit,
  8866. ProductDate: info.ProductDate,
  8867. ExpiryDate: info.ExpiryDate,
  8868. BatchNumberId: info.WarehouseInfoId,
  8869. }
  8870. flow := models.DrugFlow{
  8871. WarehousingId: 0,
  8872. DrugId: info.DrugId,
  8873. Number: "",
  8874. BatchNumber: info.BatchNumber,
  8875. Count: info.Count,
  8876. UserOrgId: advice.UserOrgId,
  8877. PatientId: 0,
  8878. SystemTime: ctime,
  8879. ConsumableType: 4,
  8880. IsSys: 0,
  8881. WarehousingOrder: "",
  8882. WarehouseOutId: 0,
  8883. WarehouseOutOrderNumber: "",
  8884. IsEdit: 0,
  8885. CancelStockId: cancelStock.ID,
  8886. CancelOrderNumber: cancelStock.OrderNumber,
  8887. Manufacturer: info.Manufacturer,
  8888. Dealer: info.Dealer,
  8889. Creator: advice.AdviceDoctor,
  8890. UpdateCreator: 0,
  8891. Status: 1,
  8892. Ctime: time.Now().Unix(),
  8893. Mtime: 0,
  8894. Price: info.Price,
  8895. WarehousingDetailId: 0,
  8896. WarehouseOutDetailId: 0,
  8897. CancelOutDetailId: 0,
  8898. ExpireDate: info.ExpiryDate,
  8899. ProductDate: info.ProductDate,
  8900. MaxUnit: info.CountUnit,
  8901. MinUnit: "",
  8902. }
  8903. service.CreatedCancelStock(cancelStockInfo)
  8904. service.CreateDrugFlowOne(flow)
  8905. }
  8906. }
  8907. }
  8908. return err
  8909. }
  8910. func (this *HisApiController) DeleteNCDS() {
  8911. id, _ := this.GetInt64("id", 0)
  8912. if id > 0 {
  8913. service.DeletePsnNCDSRecordById(id)
  8914. this.ServeSuccessJSON(map[string]interface{}{
  8915. "msg": "删除成功",
  8916. })
  8917. } else {
  8918. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  8919. return
  8920. }
  8921. }
  8922. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  8923. id, _ := c.GetInt64("id")
  8924. advice, _ := service.GetHisDoctorAdviceInfo(id)
  8925. c.ServeSuccessJSON(map[string]interface{}{
  8926. "advice": advice,
  8927. })
  8928. return
  8929. }
  8930. func (c *HisApiController) GetHisMonthChargePatientList() {
  8931. record_date := c.GetString("record_date")
  8932. start_time := c.GetString("start_time")
  8933. end_time := c.GetString("end_time")
  8934. timeLayout := "2006-01-02"
  8935. loc, _ := time.LoadLocation("Local")
  8936. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8937. if err != nil {
  8938. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8939. return
  8940. }
  8941. if err != nil {
  8942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8943. return
  8944. }
  8945. recordDateTime := theTime.Unix()
  8946. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8947. if err != nil {
  8948. }
  8949. startRecordDateTime := startTime.Unix()
  8950. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8951. if err != nil {
  8952. }
  8953. endRecordDateTime := endTime.Unix()
  8954. adminInfo := c.GetAdminUserInfo()
  8955. var tempMonthChargePatients []*service.MonthChargePatients
  8956. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  8957. for _, item := range tempPatients {
  8958. //过滤没有处方的
  8959. if len(item.HisPrescription) == 0 {
  8960. tempMonthChargePatients = append(tempMonthChargePatients, item)
  8961. }
  8962. }
  8963. c.ServeSuccessJSON(map[string]interface{}{
  8964. "list": tempMonthChargePatients,
  8965. })
  8966. }