his_api_controller.go 563KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math/rand"
  6. "reflect"
  7. "strconv"
  8. "strings"
  9. "syscall"
  10. "time"
  11. "unsafe"
  12. "XT_New/enums"
  13. "XT_New/models"
  14. "XT_New/service"
  15. "XT_New/utils"
  16. "github.com/astaxie/beego"
  17. "github.com/jinzhu/gorm"
  18. "github.com/mozillazg/go-pinyin"
  19. "github.com/shopspring/decimal"
  20. )
  21. type HisApiController struct {
  22. BaseAuthAPIController
  23. }
  24. func HisManagerApiRegistRouters() {
  25. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  26. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  27. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  28. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  29. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  30. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  31. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  32. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  33. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  34. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  35. //beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  36. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  37. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  41. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  42. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  43. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  44. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  45. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  46. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  47. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  48. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  49. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  50. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  51. //新增附加费用
  52. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  53. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  54. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  55. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  56. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  57. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  58. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  59. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  60. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  61. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  62. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  63. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  64. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  65. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  66. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  67. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  86. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  87. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  88. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  89. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  90. beego.Router("/api/getallgoodinforlist", &HisApiController{}, "Get:GetAllGoodInforList")
  91. beego.Router("/api/savegoodlist", &HisApiController{}, "Post:SaveGoodList")
  92. beego.Router("/api/getgoodlist", &HisApiController{}, "Get:GetGoodList")
  93. beego.Router("/api/getgoodnamedetail", &HisApiController{}, "Get:GetGoodNameDetail")
  94. beego.Router("/api/updategoodlist", &HisApiController{}, "Post:UpdateGoodList")
  95. beego.Router("/api/deletegoodteam", &HisApiController{}, "Get:DeleteGoodTeam")
  96. beego.Router("/api/deletegood", &HisApiController{}, "Get:DeleteGood")
  97. }
  98. func (c *HisApiController) CheckHisPatient() {
  99. record_date := c.GetString("record_date")
  100. patient_id, _ := c.GetInt64("patient_id")
  101. timeLayout := "2006-01-02"
  102. loc, _ := time.LoadLocation("Local")
  103. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  104. if err != nil {
  105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  106. return
  107. }
  108. recordDateTime := theTime.Unix()
  109. adminInfo := c.GetAdminUserInfo()
  110. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  111. if len(patients) > 1 {
  112. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  113. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  114. c.ServeSuccessJSON(map[string]interface{}{
  115. "status": 1,
  116. "msg": "关联",
  117. "ps": ps,
  118. "his_patient_id": patients[len(patients)-1].ID,
  119. "patient_id": patients[len(patients)-1].PatientId,
  120. })
  121. } else {
  122. c.ServeSuccessJSON(map[string]interface{}{
  123. "status": 0,
  124. "msg": "无需关联",
  125. })
  126. }
  127. } else {
  128. c.ServeSuccessJSON(map[string]interface{}{
  129. "status": 0,
  130. "msg": "无需关联",
  131. })
  132. return
  133. }
  134. }
  135. func (c *HisApiController) AssociationHisPrescription() {
  136. record_date := c.GetString("record_date")
  137. his_patient_id, _ := c.GetInt64("his_patient_id")
  138. patient_id, _ := c.GetInt64("patient_id")
  139. p_ids := c.GetString("p_ids")
  140. p_ids_arr := strings.Split(p_ids, ",")
  141. timeLayout := "2006-01-02"
  142. loc, _ := time.LoadLocation("Local")
  143. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  144. if err != nil {
  145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  146. return
  147. }
  148. recordDateTime := theTime.Unix()
  149. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  150. if his_patient_id == 0 || his_patient.ID == 0 {
  151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  152. return
  153. }
  154. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  155. if err == nil {
  156. c.ServeSuccessJSON(map[string]interface{}{
  157. "msg": "关联处方成功",
  158. })
  159. return
  160. } else {
  161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  162. return
  163. }
  164. }
  165. //func (c *HisApiController) AssociationHisPrescription() {
  166. // record_date, _ := c.GetInt64("record_date")
  167. // his_patient_id, _ := c.GetInt64("his_patient_id")
  168. // patient_id, _ := c.GetInt64("patient_id")
  169. // p_ids := c.GetString("p_ids")
  170. // p_ids_arr := strings.Split(p_ids, ",")
  171. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  172. // if his_patient_id == 0 || his_patient.ID == 0 {
  173. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  174. // return
  175. // }
  176. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  177. // if err == nil {
  178. // c.ServeSuccessJSON(map[string]interface{}{
  179. // "msg": "关联处方成功",
  180. // })
  181. // return
  182. // } else {
  183. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  184. // return
  185. // }
  186. //}
  187. func (c *HisApiController) GetFaPiaoNumber() {
  188. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  189. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  190. fmt.Println(count)
  191. var zero string
  192. number := count + 1
  193. //if number >= 1000 {
  194. // zero = "0000" + strconv.FormatInt(number, 10)
  195. //} else if number >= 10000 {
  196. // zero = "000" + strconv.FormatInt(number, 10)
  197. //} else if number >= 100000 {
  198. // zero = "00" + strconv.FormatInt(number, 10)
  199. //} else if number >= 1000000 {
  200. // zero = "0" + strconv.FormatInt(number, 10)
  201. //} else {
  202. zero = "0" + strconv.FormatInt(number, 10)
  203. //}
  204. c.ServeSuccessJSON(map[string]interface{}{
  205. "fapiao_number": zero,
  206. })
  207. return
  208. }
  209. func (c *HisApiController) ChangeOrderDesc() {
  210. id, _ := c.GetInt64("id")
  211. desc := c.GetString("desc")
  212. change_type := c.GetString("change_type")
  213. order, _ := service.GetHisOrderByID(id)
  214. if order.ID == 0 {
  215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  216. return
  217. }
  218. switch change_type {
  219. case "oth_desc":
  220. order.OthDesc = desc
  221. break
  222. case "cash_pay":
  223. order.CashPay = desc
  224. break
  225. case "jifen_pay":
  226. order.JifenPay = desc
  227. break
  228. case "band_card_pay":
  229. order.BandCardPay = desc
  230. break
  231. case "ali_pay":
  232. order.AliPay = desc
  233. break
  234. case "wechat_pay":
  235. order.WechatPay = desc
  236. break
  237. case "fa_piao_number":
  238. order.FaPiaoNumber = desc
  239. break
  240. case "fa_piao_code":
  241. order.FaPiaoCode = desc
  242. break
  243. }
  244. err := service.SaveHisOrder(&order)
  245. if err == nil {
  246. c.ServeSuccessJSON(map[string]interface{}{
  247. "msg": "修改成功",
  248. })
  249. return
  250. } else {
  251. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  252. return
  253. }
  254. }
  255. func (c *HisApiController) GetMonthHisPatient() {
  256. record_date := c.GetString("record_date")
  257. //order_status, _ := c.GetInt64("type")
  258. timeLayout := "2006-01-02"
  259. loc, _ := time.LoadLocation("Local")
  260. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  261. if err != nil {
  262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  263. return
  264. }
  265. recordDateTime := theTime.Unix()
  266. adminInfo := c.GetAdminUserInfo()
  267. var tempPatients []service.NewTempPatients
  268. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  269. // 获取当前时间
  270. now := time.Now()
  271. // 获取本月的第一天
  272. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  273. // 获取下个月的第一天
  274. nextMonth := firstDay.AddDate(0, 1, 0)
  275. // 获取本月的最后一天
  276. lastDay := nextMonth.Add(-time.Nanosecond)
  277. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  278. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  279. var patients []service.NewTempPatients
  280. var patients_two []service.NewTempPatients
  281. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  282. for _, item := range tempPatients {
  283. //过滤掉没挂号的和没开处方的
  284. if len(item.HisPrescription) > 0 {
  285. patients = append(patients, item)
  286. patients_two = append(patients_two, item)
  287. }
  288. ////过滤掉没挂号的
  289. //if len(item.HisPatient) > 0 {
  290. //}
  291. }
  292. } else {
  293. for _, item := range tempPatients {
  294. //过滤掉没挂号的和没开处方的
  295. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  296. patients = append(patients, item)
  297. }
  298. ////过滤掉没挂号的
  299. //if len(item.HisPatient) > 0 {
  300. // patients_two = append(patients_two, item)
  301. //}
  302. }
  303. }
  304. c.ServeSuccessJSON(map[string]interface{}{
  305. "list": patients,
  306. "list_two": patients_two,
  307. "chargePatients": chargePatients,
  308. })
  309. }
  310. func (c *HisApiController) GetBatchSettleAccounts() {
  311. order_ids := c.GetString("order_ids")
  312. admin_user_id, _ := c.GetInt64("admin_user_id")
  313. adminUser := c.GetAdminUserInfo()
  314. orders := strings.Split(order_ids, ",")
  315. var newOrders []models.Orders
  316. for _, item := range orders {
  317. order, _ := service.GetHisOrderByIDTenOne(item)
  318. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  319. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  320. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  321. orderInfos = append(orderInfos, orderInfos_two...)
  322. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  323. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  324. var diagnosis_ids []string
  325. if his.ID > 0 {
  326. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  327. } else {
  328. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  329. }
  330. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  331. var dia_config []*models.HisXtDiagnoseConfig
  332. var name string
  333. for _, item := range diagnosis_ids {
  334. id, _ := strconv.ParseInt(item, 10, 64)
  335. diagnosisConfig, _ := service.FindDiagnoseById(id)
  336. dia_config = append(dia_config, diagnosisConfig)
  337. if len(name) == 0 {
  338. name = diagnosisConfig.ClassName
  339. } else {
  340. name = name + "," + diagnosisConfig.ClassName
  341. }
  342. }
  343. var bedCostTotal float64 = 0 //床位总费
  344. var bedCostSelfTotal float64 = 0 //床位自费
  345. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  346. var bedSelfTotal float64 = 0 //床位部分项目自费
  347. var bedInscpTotal float64 = 0 //床位部分项目自费
  348. var operationCostTotal float64 = 0 //手术费
  349. var operationCostSelfTotal float64 = 0 //手术费
  350. var operationCostPartSelfTotal float64 = 0 //手术费
  351. var operationSelfTotal float64 = 0 //床位部分项目自费
  352. var operationInscpTotal float64 = 0 //床位部分项目自费
  353. var otherCostTotal float64 = 0 //其他费用
  354. var otherCostSelfTotal float64 = 0 //其他费用
  355. var otherCostPartSelfTotal float64 = 0 //其他费用
  356. var otherSelfTotal float64 = 0 //床位部分项目自费
  357. var otherInscpTotal float64 = 0 //床位部分项目自费
  358. var materialCostTotal float64 = 0 //材料费
  359. var materialCostSelfTotal float64 = 0 //材料费
  360. var materialCostPartSelfTotal float64 = 0 //材料费
  361. var materialSelfTotal float64 = 0 //床位部分项目自费
  362. var materialInscpTotal float64 = 0 //床位部分项目自费
  363. var westernMedicineCostTotal float64 = 0 //西药费
  364. var westernMedicineCostSelfTotal float64 = 0 //西药费
  365. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  366. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  367. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  368. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  369. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  370. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  371. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  372. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  373. var checkCostTotal float64 = 0 //检查费
  374. var checkCostSelfTotal float64 = 0 //检查费
  375. var checkCostPartSelfTotal float64 = 0 //检查费
  376. var checkSelfTotal float64 = 0 //床位部分项目自费
  377. var checkInscpTotal float64 = 0 //床位部分项目自费
  378. var laboratoryCostTotal float64 = 0 //化验费
  379. var laboratoryCostSelfTotal float64 = 0 //化验费
  380. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  381. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  382. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  383. var treatCostTotal float64 = 0 //治疗费用
  384. var treatCostSelfTotal float64 = 0 //治疗费用
  385. var treatCostPartSelfTotal float64 = 0 //治疗费用
  386. var treatSelfTotal float64 = 0 //床位部分项目自费
  387. var treatInscpTotal float64 = 0 //床位部分项目自费
  388. decimal.DivisionPrecision = 2
  389. for _, item := range orderInfos {
  390. if item.MedChrgitmType == "01" { //床位费
  391. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  392. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  393. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  394. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  395. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  396. }
  397. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  398. if item.MedChrgitmType == "03" { //检查费
  399. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  400. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  401. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  402. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  403. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  404. }
  405. } else {
  406. if item.MedChrgitmType == "03" { //检查费
  407. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  408. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  409. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  410. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  411. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  412. }
  413. }
  414. if item.MedChrgitmType == "04" { //化验费
  415. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  416. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  417. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  418. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  419. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  420. }
  421. if item.MedChrgitmType == "05" { //治疗费
  422. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  423. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  424. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  425. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  426. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  427. }
  428. if item.MedChrgitmType == "06" { //手术费
  429. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  430. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  431. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  432. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  433. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  434. }
  435. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  436. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  437. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  438. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  439. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  440. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  441. }
  442. if item.MedChrgitmType == "09" { //西药费
  443. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  444. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  445. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  446. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  447. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  448. }
  449. if item.MedChrgitmType == "11" { //中成费
  450. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  451. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  452. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  453. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  454. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  455. }
  456. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  457. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  458. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  459. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  460. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  461. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  462. }
  463. }
  464. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  465. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  466. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  467. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  468. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  469. var doctor_name string
  470. if roles.ID == 0 {
  471. doctor_name = "管理员"
  472. } else {
  473. doctor_name = roles.UserName
  474. }
  475. yiliao_leibie := ""
  476. switch order.MedType {
  477. case "11":
  478. yiliao_leibie = "普通门诊"
  479. break
  480. case "12":
  481. yiliao_leibie = "门诊挂号"
  482. break
  483. case "13":
  484. yiliao_leibie = "急诊"
  485. break
  486. case "14":
  487. yiliao_leibie = "门诊特殊病"
  488. break
  489. case "15":
  490. yiliao_leibie = "门诊统筹"
  491. break
  492. case "16":
  493. yiliao_leibie = "门诊慢性病"
  494. break
  495. case "21":
  496. yiliao_leibie = "普通住院"
  497. break
  498. }
  499. var newOrder models.Orders
  500. newOrder.Diagnosis = name
  501. newOrder.OrderInfos = orderInfos
  502. newOrder.Number = order.MdtrtId
  503. newOrder.Date = order.SettleAccountsDate
  504. newOrder.ChargeAdmin = charge_admin
  505. newOrder.PrintorAdmin = printor_admin
  506. newOrder.Order = order
  507. newOrder.BedCostTotal = bedCostTotal
  508. newOrder.BedCostSelfTotal = bedCostSelfTotal
  509. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  510. newOrder.BedSelfTotal = bedSelfTotal
  511. newOrder.BedInscpTotal = bedInscpTotal
  512. newOrder.OperationCostTotal = operationCostTotal
  513. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  514. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  515. newOrder.OperationSelfTotal = operationSelfTotal
  516. newOrder.OperationInscpTotal = operationInscpTotal
  517. newOrder.OtherCostTotal = otherCostTotal
  518. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  519. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  520. newOrder.OtherSelfTotal = otherSelfTotal
  521. newOrder.OtherInscpTotal = otherInscpTotal
  522. newOrder.MaterialCostTotal = materialCostTotal
  523. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  524. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  525. newOrder.MaterialSelfTotal = materialSelfTotal
  526. newOrder.MaterialInscpTotal = materialInscpTotal
  527. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  528. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  529. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  530. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  531. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  532. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  533. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  534. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  535. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  536. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  537. newOrder.CheckCostTotal = checkCostTotal
  538. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  539. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  540. newOrder.CheckSelfTotal = checkSelfTotal
  541. newOrder.CheckInscpTotal = checkInscpTotal
  542. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  543. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  544. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  545. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  546. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  547. newOrder.TreatCostTotal = treatCostTotal
  548. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  549. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  550. newOrder.TreatSelfTotal = treatSelfTotal
  551. newOrder.TreatInscpTotal = treatInscpTotal
  552. newOrder.DoctorInfo = doctor_info
  553. newOrder.DoctorName = doctor_name
  554. newOrder.HealthCardNo = order.PsnNo
  555. newOrder.YiliaoLeibie = yiliao_leibie
  556. newOrder.Patient = patient
  557. newOrder.OrgName = miConfig.OrgName
  558. newOrder.OrgCode = miConfig.Code
  559. newOrder.OrderNumber = order.Number
  560. newOrder.HisPatient = his
  561. newOrder.DiaConfig = dia_config
  562. newOrders = append(newOrders, newOrder)
  563. }
  564. c.ServeSuccessJSON(map[string]interface{}{
  565. "orders": newOrders,
  566. })
  567. }
  568. func (c *HisApiController) GetTestOrder() {
  569. order_id, _ := c.GetInt64("order_id")
  570. admin_user_id, _ := c.GetInt64("admin_user_id")
  571. adminUser := c.GetAdminUserInfo()
  572. order, _ := service.GetHisOrderByID(order_id)
  573. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  574. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  575. orderInfos = append(orderInfos, orderInfos_two...)
  576. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  577. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  578. var dia_config []*models.HisXtDiagnoseConfig
  579. var name string
  580. var bedCostTotal float64 = 0 //床位总费
  581. var bedCostSelfTotal float64 = 0 //床位自费
  582. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  583. var bedSelfTotal float64 = 0 //床位部分项目自费
  584. var bedInscpTotal float64 = 0 //床位部分项目自费
  585. var operationCostTotal float64 = 0 //手术费
  586. var operationCostSelfTotal float64 = 0 //手术费
  587. var operationCostPartSelfTotal float64 = 0 //手术费
  588. var operationSelfTotal float64 = 0 //床位部分项目自费
  589. var operationInscpTotal float64 = 0 //床位部分项目自费
  590. var otherCostTotal float64 = 0 //其他费用
  591. var otherCostSelfTotal float64 = 0 //其他费用
  592. var otherCostPartSelfTotal float64 = 0 //其他费用
  593. var otherSelfTotal float64 = 0 //床位部分项目自费
  594. var otherInscpTotal float64 = 0 //床位部分项目自费
  595. var materialCostTotal float64 = 0 //材料费
  596. var materialCostSelfTotal float64 = 0 //材料费
  597. var materialCostPartSelfTotal float64 = 0 //材料费
  598. var materialSelfTotal float64 = 0 //床位部分项目自费
  599. var materialInscpTotal float64 = 0 //床位部分项目自费
  600. var westernMedicineCostTotal float64 = 0 //西药费
  601. var westernMedicineCostSelfTotal float64 = 0 //西药费
  602. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  603. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  604. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  605. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  606. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  607. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  608. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  609. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  610. var checkCostTotal float64 = 0 //检查费
  611. var checkCostSelfTotal float64 = 0 //检查费
  612. var checkCostPartSelfTotal float64 = 0 //检查费
  613. var checkSelfTotal float64 = 0 //床位部分项目自费
  614. var checkInscpTotal float64 = 0 //床位部分项目自费
  615. var laboratoryCostTotal float64 = 0 //化验费
  616. var laboratoryCostSelfTotal float64 = 0 //化验费
  617. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  618. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  619. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  620. var treatCostTotal float64 = 0 //治疗费用
  621. var treatCostSelfTotal float64 = 0 //治疗费用
  622. var treatCostPartSelfTotal float64 = 0 //治疗费用
  623. var treatSelfTotal float64 = 0 //床位部分项目自费
  624. var treatInscpTotal float64 = 0 //床位部分项目自费
  625. decimal.DivisionPrecision = 2
  626. for _, item := range orderInfos {
  627. if item.MedChrgitmType == "01" { //床位费
  628. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  629. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  630. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  631. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  632. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  633. }
  634. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  635. if item.MedChrgitmType == "03" { //检查费
  636. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  637. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  638. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  639. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  640. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  641. }
  642. } else {
  643. if item.MedChrgitmType == "03" { //检查费
  644. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  645. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  646. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  647. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  648. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  649. }
  650. }
  651. if item.MedChrgitmType == "04" { //化验费
  652. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  653. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  654. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  655. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  656. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  657. }
  658. if item.MedChrgitmType == "05" { //治疗费
  659. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  660. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  661. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  662. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  663. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  664. }
  665. if item.MedChrgitmType == "06" { //手术费
  666. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  667. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  668. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  669. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  670. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  671. }
  672. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  673. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  674. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  675. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  676. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  677. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  678. }
  679. if item.MedChrgitmType == "09" { //西药费
  680. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  681. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  682. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  683. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  684. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  685. }
  686. if item.MedChrgitmType == "11" { //中成费
  687. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  688. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  689. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  690. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  691. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  692. }
  693. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  694. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  695. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  696. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  697. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  698. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  699. }
  700. }
  701. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  702. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  703. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  704. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  705. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  706. var doctor_name string
  707. if roles.ID == 0 {
  708. doctor_name = "管理员"
  709. } else {
  710. doctor_name = roles.UserName
  711. }
  712. yiliao_leibie := ""
  713. switch order.MedType {
  714. case "11":
  715. yiliao_leibie = "普通门诊"
  716. break
  717. case "12":
  718. yiliao_leibie = "门诊挂号"
  719. break
  720. case "13":
  721. yiliao_leibie = "急诊"
  722. break
  723. case "14":
  724. yiliao_leibie = "门诊特殊病"
  725. break
  726. case "15":
  727. yiliao_leibie = "门诊统筹"
  728. break
  729. case "16":
  730. yiliao_leibie = "门诊慢性病"
  731. break
  732. case "21":
  733. yiliao_leibie = "普通住院"
  734. break
  735. }
  736. c.ServeSuccessJSON(map[string]interface{}{
  737. "diagnosis": name,
  738. "order_infos": orderInfos,
  739. "number": order.MdtrtId,
  740. "date": order.SettleAccountsDate,
  741. "charge_admin": charge_admin,
  742. "printor_admin": printor_admin,
  743. "info": order,
  744. "order": order,
  745. "bedCostTotal": bedCostTotal,
  746. "bedCostSelfTotal": bedCostSelfTotal,
  747. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  748. "bedSelfTotal": bedSelfTotal,
  749. "bedInscpTotal": bedInscpTotal,
  750. "operationCostTotal": operationCostTotal,
  751. "operationCostSelfTotal": operationCostSelfTotal,
  752. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  753. "operationSelfTotal": operationSelfTotal,
  754. "operationInscpTotal": operationInscpTotal,
  755. "otherCostTotal": otherCostTotal,
  756. "otherCostSelfTotal": otherCostSelfTotal,
  757. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  758. "otherSelfTotal": otherSelfTotal,
  759. "otherInscpTotal": otherInscpTotal,
  760. "materialCostTotal": materialCostTotal,
  761. "materialCostSelfTotal": materialCostSelfTotal,
  762. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  763. "materialSelfTotal": materialSelfTotal,
  764. "materialInscpTotal": materialInscpTotal,
  765. "westernMedicineCostTotal": westernMedicineCostTotal,
  766. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  767. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  768. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  769. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  770. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  771. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  772. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  773. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  774. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  775. "checkCostTotal": checkCostTotal,
  776. "checkCostSelfTotal": checkCostSelfTotal,
  777. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  778. "checkSelfTotal": checkSelfTotal,
  779. "checkInscpTotal": checkInscpTotal,
  780. "laboratoryCostTotal": laboratoryCostTotal,
  781. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  782. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  783. "laboratorySelfTotal": laboratorySelfTotal,
  784. "laboratoryInscpTotal": laboratoryInscpTotal,
  785. "treatCostTotal": treatCostTotal,
  786. "treatCostSelfTotal": treatCostSelfTotal,
  787. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  788. "treatSelfTotal": treatSelfTotal,
  789. "treatInscpTotal": treatInscpTotal,
  790. "doctor_info": doctor_info,
  791. "doctor_name": doctor_name,
  792. "health_card_no": order.PsnNo,
  793. "yiliao_leibie": yiliao_leibie,
  794. "patient": patient,
  795. "org_name": miConfig.OrgName,
  796. "org_code": miConfig.Code,
  797. "order_number": order.Number,
  798. "his_hospital": his_hospital,
  799. "dia_config": dia_config,
  800. })
  801. }
  802. type CustomFundPay struct {
  803. FundPayType string `json:"fund_pay_type"`
  804. FundPayamt float64 `json:"fund_payamt"`
  805. InscpScpAmt float64 `json:"inscp_scp_amt"`
  806. }
  807. func (c *PublicApiController) GetBaiLinExportData() {
  808. data := service.GetBaiLinOrderData()
  809. fmt.Println(len(data))
  810. var new_data []*models.NewCustomHisOrder
  811. for _, item := range data {
  812. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  813. new_data = append(new_data, item)
  814. }
  815. }
  816. fmt.Println(len(new_data))
  817. c.ServeSuccessJSON(map[string]interface{}{
  818. "list": new_data,
  819. })
  820. }
  821. func (c *HisApiController) GetHisUnChargePatientList() {
  822. record_date := c.GetString("record_date")
  823. sch_type, _ := c.GetInt64("sch_type")
  824. timeLayout := "2006-01-02"
  825. loc, _ := time.LoadLocation("Local")
  826. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  827. if err != nil {
  828. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  829. return
  830. }
  831. recordDateTime := theTime.Unix()
  832. adminInfo := c.GetAdminUserInfo()
  833. var tempPatients []*service.NewTempPatients
  834. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  835. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  836. var patients []*service.NewTempPatients
  837. var patients_two []*service.NewTempPatients
  838. for _, item := range tempPatients {
  839. //过滤掉没挂号的和没开处方的
  840. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  841. patients = append(patients, item)
  842. }
  843. //过滤掉没挂号的
  844. if len(item.HisPatient) > 0 {
  845. patients_two = append(patients_two, item)
  846. }
  847. }
  848. c.ServeSuccessJSON(map[string]interface{}{
  849. "list": patients,
  850. "list_two": patients_two,
  851. })
  852. }
  853. func (c *HisApiController) GetPrivateExpensesOrder() {
  854. //id, _ := c.GetInt64("id")
  855. //record_time := c.GetString("record_time")
  856. order_id, _ := c.GetInt64("order_id")
  857. admin_user_id, _ := c.GetInt64("admin_user_id")
  858. //timeLayout := "2006-01-02"
  859. //loc, _ := time.LoadLocation("Local")
  860. //
  861. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  862. //if err != nil {
  863. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  864. // return
  865. //}
  866. //recordDateTime := theTime.Unix()
  867. adminUser := c.GetAdminUserInfo()
  868. order, _ := service.GetHisOrderByID(order_id)
  869. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  870. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  871. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  872. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  873. //var config []*models.HisXtDiagnoseConfig
  874. var name string
  875. if order.PType == 1 {
  876. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  877. for _, item := range diagnosis_ids {
  878. id, _ := strconv.ParseInt(item, 10, 64)
  879. diagnosisConfig, _ := service.FindDiagnoseById(id)
  880. if len(name) == 0 {
  881. name = diagnosisConfig.ClassName
  882. } else {
  883. name = name + "," + diagnosisConfig.ClassName
  884. }
  885. }
  886. } else {
  887. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  888. for _, item := range diagnosis_ids {
  889. id, _ := strconv.ParseInt(item, 10, 64)
  890. diagnosisConfig, _ := service.FindDiagnoseById(id)
  891. if len(name) == 0 {
  892. name = diagnosisConfig.ClassName
  893. } else {
  894. name = name + "," + diagnosisConfig.ClassName
  895. }
  896. }
  897. }
  898. var bedCostTotal float64 = 0 //床位总费
  899. //var bedCostSelfTotal float64 = 0 //床位自费
  900. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  901. var operationCostTotal float64 = 0 //手术费
  902. //var operationCostSelfTotal float64 = 0 //手术费
  903. var operationCostPartSelfTotal float64 = 0 //手术费
  904. var otherCostTotal float64 = 0 //其他费用
  905. //var otherCostSelfTotal float64 = 0 //其他费用
  906. var otherCostPartSelfTotal float64 = 0 //其他费用
  907. var materialCostTotal float64 = 0 //材料费
  908. //var materialCostSelfTotal float64 = 0 //材料费
  909. var materialCostPartSelfTotal float64 = 0 //材料费
  910. var westernMedicineCostTotal float64 = 0 //西药费
  911. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  912. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  913. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  914. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  915. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  916. var checkCostTotal float64 = 0 //检查费
  917. //var checkCostSelfTotal float64 = 0 //检查费
  918. var checkCostPartSelfTotal float64 = 0 //检查费
  919. var laboratoryCostTotal float64 = 0 //化验费
  920. //var laboratoryCostSelfTotal float64 = 0 //化验费
  921. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  922. var treatCostTotal float64 = 0 //治疗费用
  923. //var treatCostSelfTotal float64 = 0 //治疗费用
  924. var treatCostPartSelfTotal float64 = 0 //治疗费用
  925. var zhenChaCostTotal float64 = 0 //其他费用
  926. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  927. decimal.DivisionPrecision = 2
  928. for _, item := range orderInfos {
  929. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  930. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  931. item.MedChrgitmType = "09"
  932. }
  933. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  934. if item.HisPrescriptionProject.Type == 2 {
  935. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  936. fmt.Println("CostClassify")
  937. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  938. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  939. case 0:
  940. item.MedChrgitmType = "0"
  941. break
  942. case 1:
  943. item.MedChrgitmType = "14"
  944. break
  945. case 2:
  946. item.MedChrgitmType = "05"
  947. break
  948. case 3:
  949. item.MedChrgitmType = "03"
  950. break
  951. case 4:
  952. item.MedChrgitmType = "03"
  953. break
  954. case 5:
  955. item.MedChrgitmType = "08"
  956. break
  957. case 6:
  958. item.MedChrgitmType = "14"
  959. break
  960. case 7:
  961. item.MedChrgitmType = "14"
  962. break
  963. case 8:
  964. item.MedChrgitmType = "03"
  965. break
  966. case 9:
  967. item.MedChrgitmType = "14"
  968. break
  969. case 10:
  970. item.MedChrgitmType = "14"
  971. break
  972. case 11:
  973. item.MedChrgitmType = "06"
  974. break
  975. case 12:
  976. item.MedChrgitmType = "12"
  977. break
  978. case 13:
  979. item.MedChrgitmType = "01"
  980. break
  981. case 14:
  982. item.MedChrgitmType = "04"
  983. break
  984. case 15:
  985. item.MedChrgitmType = "14"
  986. break
  987. }
  988. } else {
  989. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  990. case 1:
  991. item.MedChrgitmType = "14"
  992. break
  993. case 2:
  994. item.MedChrgitmType = "05"
  995. break
  996. case 3:
  997. item.MedChrgitmType = "04"
  998. break
  999. case 4:
  1000. item.MedChrgitmType = "14"
  1001. break
  1002. case 5:
  1003. item.MedChrgitmType = "08"
  1004. break
  1005. case 6:
  1006. item.MedChrgitmType = "14"
  1007. break
  1008. case 7:
  1009. item.MedChrgitmType = "14"
  1010. break
  1011. case 8:
  1012. item.MedChrgitmType = "03"
  1013. break
  1014. case 9:
  1015. item.MedChrgitmType = "14"
  1016. break
  1017. default:
  1018. item.MedChrgitmType = "14"
  1019. break
  1020. }
  1021. }
  1022. } else if item.HisPrescriptionProject.Type == 3 {
  1023. item.MedChrgitmType = "08"
  1024. }
  1025. }
  1026. }
  1027. if order.IsMedicineInsurance != 1 {
  1028. order.PsnCashPay = order.MedfeeSumamt
  1029. }
  1030. for _, item := range orderInfos {
  1031. if item.MedChrgitmType == "01" { //床位费
  1032. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1033. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1034. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1035. }
  1036. if item.MedChrgitmType == "02" { //诊察费
  1037. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1038. //zhenChaCostSelfTotal = zhenChaCostTotal
  1039. }
  1040. if item.MedChrgitmType == "03" { //检查费
  1041. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1042. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1043. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1044. }
  1045. if item.MedChrgitmType == "02" { //检查费
  1046. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1047. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1048. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1049. }
  1050. if item.MedChrgitmType == "04" { //化验费
  1051. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1052. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1053. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1054. }
  1055. if item.MedChrgitmType == "05" { //治疗费
  1056. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1057. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1058. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1059. }
  1060. if item.MedChrgitmType == "06" { //手术费
  1061. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1062. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1063. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1064. }
  1065. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1066. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1067. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1068. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1069. }
  1070. if item.MedChrgitmType == "09" { //西药费
  1071. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1072. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1073. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1074. }
  1075. if item.MedChrgitmType == "11" { //中成费
  1076. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1077. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1078. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1079. }
  1080. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1081. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1082. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1083. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1084. }
  1085. }
  1086. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1087. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1088. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1089. var dia_config []*models.HisXtDiagnoseConfig
  1090. var diagnosis_ids []string
  1091. if his.ID > 0 {
  1092. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1093. } else {
  1094. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1095. }
  1096. for _, item := range diagnosis_ids {
  1097. id, _ := strconv.ParseInt(item, 10, 64)
  1098. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1099. dia_config = append(dia_config, diagnosisConfig)
  1100. }
  1101. var rf []CustomFundPay
  1102. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1103. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1104. c.ServeSuccessJSON(map[string]interface{}{
  1105. "patient": patient,
  1106. "order_infos": orderInfos,
  1107. "diagnosis": name,
  1108. "bedCostTotal": bedCostTotal,
  1109. "bedCostSelfTotal": bedCostTotal,
  1110. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1111. "operationCostTotal": operationCostTotal,
  1112. "operationCostSelfTotal": operationCostTotal,
  1113. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1114. "otherCostTotal": otherCostTotal,
  1115. "otherCostSelfTotal": otherCostTotal,
  1116. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1117. "materialCostTotal": materialCostTotal,
  1118. "materialCostSelfTotal": materialCostTotal,
  1119. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1120. "westernMedicineCostTotal": westernMedicineCostTotal,
  1121. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1122. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1123. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1124. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1125. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1126. "checkCostTotal": checkCostTotal,
  1127. "checkCostSelfTotal": checkCostTotal,
  1128. "zhenChaCostTotal": zhenChaCostTotal,
  1129. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1130. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1131. "laboratoryCostTotal": laboratoryCostTotal,
  1132. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1133. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1134. "treatCostTotal": treatCostTotal,
  1135. "treatCostSelfTotal": treatCostTotal,
  1136. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1137. "charge_admin": charge_admin,
  1138. "printor_admin": printor_admin,
  1139. "org_name": org.OrgName,
  1140. "org_code": miConfig.Code,
  1141. "name": patient.Name,
  1142. "number": order.MdtrtId,
  1143. "date": order.SettleAccountsDate,
  1144. "info": order,
  1145. "new_order": order,
  1146. "his_hospital": his_hospital,
  1147. "his": his,
  1148. "funds": rf,
  1149. "dia_config": dia_config,
  1150. })
  1151. }
  1152. func (c *HisApiController) RefudDetail() {
  1153. order_id, _ := c.GetInt64("order_id")
  1154. order, _ := service.GetHisOrderByID(order_id)
  1155. adminUser := c.GetAdminUserInfo()
  1156. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1157. c.ServeSuccessJSON(map[string]interface{}{
  1158. "msg": "撤销成功",
  1159. })
  1160. }
  1161. func (c *HisApiController) Sscard() {
  1162. //r := CardInit()
  1163. //if r == 0 {
  1164. // GetBaseInfo()
  1165. //}
  1166. //c.ServeSuccessJSON(map[string]interface{}{
  1167. // "list": "11",
  1168. //})
  1169. }
  1170. func GetBaseInfo() error {
  1171. //handle := syscall.MustLoadDLL("SSCard.dll")
  1172. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1173. //
  1174. //str := make([]byte, 256)
  1175. //str1 := make([]byte, 256)
  1176. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1177. //if ferr != nil {
  1178. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1179. // return ferr
  1180. //}
  1181. //
  1182. //fmt.Println(string(str))
  1183. //
  1184. //fmt.Println(r)
  1185. return nil
  1186. }
  1187. func CardInit() int {
  1188. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1189. //add := DllTestDef.MustFindProc("Init")
  1190. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1191. //if err != nil {
  1192. // fmt.Println("SSCard的运算结果为:", ret)
  1193. //}
  1194. //result := int(ret)
  1195. return 0
  1196. }
  1197. func IntPtr(n int) uintptr {
  1198. return uintptr(n)
  1199. }
  1200. func StrPtr(s string) uintptr {
  1201. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1202. }
  1203. func (c *HisApiController) GetHisPatientList() {
  1204. record_date := c.GetString("record_date")
  1205. sch_type, _ := c.GetInt64("sch_type")
  1206. patient_type, _ := c.GetInt64("patient_type")
  1207. fmt.Println("patient_type")
  1208. fmt.Println(patient_type)
  1209. timeLayout := "2006-01-02"
  1210. loc, _ := time.LoadLocation("Local")
  1211. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1212. if err != nil {
  1213. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1214. return
  1215. }
  1216. recordDateTime := theTime.Unix()
  1217. adminInfo := c.GetAdminUserInfo()
  1218. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type, 0)
  1219. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type, 0)
  1220. if patient_type == 2 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1221. fmt.Println("111111")
  1222. patients_three, _ := service.GetFuTouHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1223. fmt.Println(patients_three)
  1224. //获取当前用户的信息
  1225. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1226. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1227. //获取所有科室信息
  1228. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1229. //var aa []service.PatientThree
  1230. noElementsSlice := make([]service.PatientThree, 0)
  1231. c.ServeSuccessJSON(map[string]interface{}{
  1232. "list": patients_three,
  1233. "list_two": patients_three,
  1234. "list_three": noElementsSlice,
  1235. "info": adminUserInfo,
  1236. "doctors": doctors,
  1237. "department": department,
  1238. })
  1239. } else {
  1240. //获取当前用户的信息
  1241. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1242. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1243. //获取所有科室信息
  1244. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1245. //var aa []service.PatientThree
  1246. noElementsSlice := make([]service.PatientThree, 0)
  1247. c.ServeSuccessJSON(map[string]interface{}{
  1248. "list": patients,
  1249. "list_two": patients_two,
  1250. "list_three": noElementsSlice,
  1251. "info": adminUserInfo,
  1252. "doctors": doctors,
  1253. "department": department,
  1254. })
  1255. }
  1256. }
  1257. type CustomTemplate struct {
  1258. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1259. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1260. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1261. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1262. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1263. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1264. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1265. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1266. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1267. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1268. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1269. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1270. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1271. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1272. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1273. }
  1274. func (c *HisApiController) GetHisPatientInfo() {
  1275. patient_id, _ := c.GetInt64("patient_id")
  1276. his_patient_id, _ := c.GetInt64("his_patient_id")
  1277. record_date := c.GetString("record_date")
  1278. number := c.GetString("number")
  1279. //start_time := c.GetString("start_time")
  1280. //end_time := c.GetString("end_time")
  1281. p_type, _ := c.GetInt64("p_type")
  1282. timeLayout := "2006-01-02"
  1283. loc, _ := time.LoadLocation("Local")
  1284. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1285. if err != nil {
  1286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1287. return
  1288. }
  1289. recordDateTime := theTime.Unix()
  1290. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1291. //if err != nil {
  1292. //
  1293. //}
  1294. //startRecordDateTime := startTime.Unix()
  1295. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1296. //if err != nil {
  1297. //
  1298. //}
  1299. //endRecordDateTime := endTime.Unix()
  1300. admin := c.GetAdminUserInfo()
  1301. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1302. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1303. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1304. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1305. pre, _ := service.GetDialysisPrescription(patient_id, admin.CurrentOrgId, recordDateTime)
  1306. var prescriptions []*models.HisPrescription
  1307. var last_prescriptions []*models.HisPrescription
  1308. var sch_prescriptions []CustomTemplate
  1309. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1310. if p_type == 1 { //住院
  1311. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1312. for _, item := range prescriptions {
  1313. for _, subItem := range item.HisDoctorAdviceInfo {
  1314. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1315. if info.RetailPrice > 0 {
  1316. subItem.Drug.MinPrice = info.RetailPrice
  1317. }
  1318. }
  1319. }
  1320. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1321. } else { //门诊
  1322. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1323. for _, item := range prescriptions {
  1324. for _, subItem := range item.HisDoctorAdviceInfo {
  1325. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1326. if info.RetailPrice > 0 {
  1327. subItem.Drug.MinPrice = info.RetailPrice
  1328. }
  1329. }
  1330. }
  1331. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1332. }
  1333. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1334. if sch.ID > 0 {
  1335. var week string
  1336. t := time.Now()
  1337. switch t.Weekday().String() {
  1338. case "Monday":
  1339. week = "周一"
  1340. break
  1341. case "Tuesday":
  1342. week = "周二"
  1343. break
  1344. case "Wednesday":
  1345. week = "周三"
  1346. break
  1347. case "Thursday":
  1348. week = "周四"
  1349. break
  1350. case "Friday":
  1351. week = "周五"
  1352. break
  1353. case "Saturday":
  1354. week = "周六"
  1355. break
  1356. case "Sunday":
  1357. week = "周日"
  1358. break
  1359. }
  1360. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1361. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1362. //根据推送频率组装新的数组
  1363. for _, item := range temp_sch_prescriptions {
  1364. var cus CustomTemplate
  1365. cus.ID = item.ID
  1366. cus.UserOrgId = item.UserOrgId
  1367. cus.PatientId = item.PatientId
  1368. cus.MedType = item.MedType
  1369. cus.RecordDate = item.RecordDate
  1370. cus.Type = item.Type
  1371. cus.PType = item.PType
  1372. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1373. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1374. if subItem.FrequencyType == 1 { //每次必推
  1375. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1376. }
  1377. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1378. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1379. }
  1380. if subItem.FrequencyType == 2 { //按照天数频率
  1381. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1382. now := p.Unix()
  1383. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1384. dayStr2 := "-" + dayStr
  1385. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1386. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1387. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1388. if len(advices) == 0 {
  1389. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1390. }
  1391. }
  1392. }
  1393. }
  1394. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1395. if subItem.Type == 2 {
  1396. if subItem.XtHisProject.MedicalStatus != 1 {
  1397. if subItem.FrequencyType == 1 {
  1398. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1399. }
  1400. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1401. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1402. }
  1403. if subItem.FrequencyType == 2 {
  1404. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1405. now := p.Unix()
  1406. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1407. dayStr2 := "-" + dayStr
  1408. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1409. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1410. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1411. if len(projects) == 0 {
  1412. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1413. }
  1414. }
  1415. }
  1416. } else if subItem.Type == 3 {
  1417. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1418. if subItem.FrequencyType == 1 {
  1419. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1420. }
  1421. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1422. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1423. }
  1424. if subItem.FrequencyType == 2 {
  1425. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1426. now := p.Unix()
  1427. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1428. dayStr2 := "-" + dayStr
  1429. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1430. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1431. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1432. if len(projects) == 0 {
  1433. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1434. }
  1435. }
  1436. }
  1437. }
  1438. }
  1439. sch_prescriptions = append(sch_prescriptions, cus)
  1440. }
  1441. for _, item := range sch_prescriptions {
  1442. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1443. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1444. }
  1445. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1446. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1447. }
  1448. }
  1449. }
  1450. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1451. if config.ID > 0 && config.IsOpen == 1 {
  1452. for _, item := range sch_prescriptions {
  1453. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1454. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1455. if info.RetailPrice > 0 {
  1456. subItem.Drug.MinPrice = info.RetailPrice
  1457. if admin.CurrentOrgId != 10598 {
  1458. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1459. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1460. }
  1461. }
  1462. }
  1463. }
  1464. }
  1465. if config.ID > 0 && config.IsOpen == 1 {
  1466. for _, item := range sch_prescriptions {
  1467. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1468. if subItem.Type == 3 {
  1469. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1470. if info.Price > 0 {
  1471. subItem.GoodInfo.PackingPrice = info.Price
  1472. if admin.CurrentOrgId != 10598 {
  1473. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1474. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1475. }
  1476. }
  1477. }
  1478. }
  1479. }
  1480. }
  1481. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1482. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1483. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1484. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1485. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1486. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1487. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1488. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1489. //获取所有科室信息
  1490. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1491. beforThrity, _ := service.GetAssessmentBeforThrity(admin.CurrentOrgId, patient_id, recordDateTime)
  1492. LastCaseHistory, _ := service.GetLastHisPatientCaseHistory(admin.CurrentOrgId, patient_id)
  1493. prescriptionInfo, _ := service.GetDialysisPresriptionById(admin.CurrentOrgId, patient_id, recordDateTime)
  1494. fmt.Println(prescriptions)
  1495. fmt.Println(sch_prescriptions)
  1496. fmt.Println(last_prescriptions)
  1497. if len(prescriptions) == 0 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1498. if len(sch_prescriptions) > 0 {
  1499. var index = 0
  1500. for subindex, item := range sch_prescriptions {
  1501. if item.Type == 2 {
  1502. index = subindex
  1503. }
  1504. }
  1505. fmt.Println(index)
  1506. fmt.Println(len(sch_prescriptions))
  1507. if index >= 0 && index < len(sch_prescriptions) {
  1508. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1509. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1510. three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1511. if one.ID > 0 {
  1512. var hpt models.HisPrescriptionProjectTemplate
  1513. hpt.Type = 3
  1514. hpt.ID = 0
  1515. hpt.PatientId = sch_prescriptions[index].PatientId
  1516. hpt.Status = 1
  1517. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1518. hpt.Mtime = time.Now().Unix()
  1519. hpt.Ctime = time.Now().Unix()
  1520. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1521. hpt.Count = "1"
  1522. hpt.Price = one.RetailPrice
  1523. hpt.ProjectId = one.ID
  1524. hpt.FeedetlSn = ""
  1525. hpt.PrescriptionId = sch_prescriptions[index].ID
  1526. hpt.Unit = one.PackingUnit
  1527. hpt.Day = "1"
  1528. hpt.SingleDose = "1"
  1529. hpt.GoodInfo = one
  1530. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1531. }
  1532. if two.ID > 0 {
  1533. var hpt models.HisPrescriptionProjectTemplate
  1534. hpt.Type = 3
  1535. hpt.ID = 0
  1536. hpt.PatientId = sch_prescriptions[index].PatientId
  1537. hpt.Status = 1
  1538. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1539. hpt.Mtime = time.Now().Unix()
  1540. hpt.Ctime = time.Now().Unix()
  1541. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1542. hpt.Count = "1"
  1543. hpt.Price = two.RetailPrice
  1544. hpt.ProjectId = two.ID
  1545. hpt.FeedetlSn = ""
  1546. hpt.PrescriptionId = sch_prescriptions[index].ID
  1547. hpt.Unit = two.PackingUnit
  1548. hpt.Day = "1"
  1549. hpt.SingleDose = "1"
  1550. hpt.GoodInfo = two
  1551. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1552. }
  1553. if three.ID > 0 {
  1554. var hpt models.HisPrescriptionProjectTemplate
  1555. hpt.Type = 3
  1556. hpt.ID = 0
  1557. hpt.PatientId = sch_prescriptions[index].PatientId
  1558. hpt.Status = 1
  1559. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1560. hpt.Mtime = time.Now().Unix()
  1561. hpt.Ctime = time.Now().Unix()
  1562. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1563. hpt.Count = "1"
  1564. hpt.Price = three.RetailPrice
  1565. hpt.ProjectId = three.ID
  1566. hpt.FeedetlSn = ""
  1567. hpt.PrescriptionId = sch_prescriptions[index].ID
  1568. hpt.Unit = three.PackingUnit
  1569. hpt.Day = "1"
  1570. hpt.SingleDose = "1"
  1571. hpt.GoodInfo = three
  1572. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1573. }
  1574. fmt.Println(sch_prescriptions)
  1575. }
  1576. } else {
  1577. if len(last_prescriptions) > 0 {
  1578. var index = 0
  1579. for subindex, item := range last_prescriptions {
  1580. if item.Type == 2 {
  1581. index = subindex
  1582. }
  1583. }
  1584. if index >= 0 && index < len(last_prescriptions) {
  1585. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1586. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1587. three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1588. if one.ID > 0 {
  1589. var hpt models.HisPrescriptionProject
  1590. hpt.Type = 3
  1591. hpt.ID = 0
  1592. hpt.PatientId = last_prescriptions[index].PatientId
  1593. hpt.Status = 1
  1594. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1595. hpt.Mtime = time.Now().Unix()
  1596. hpt.Ctime = time.Now().Unix()
  1597. hpt.RecordDate = last_prescriptions[index].RecordDate
  1598. hpt.Count = "1"
  1599. hpt.Price = one.RetailPrice
  1600. hpt.ProjectId = one.ID
  1601. hpt.FeedetlSn = ""
  1602. hpt.PrescriptionId = last_prescriptions[index].ID
  1603. hpt.Unit = one.PackingUnit
  1604. hpt.Day = "1"
  1605. hpt.SingleDose = "1"
  1606. hpt.GoodInfo = one
  1607. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1608. }
  1609. if two.ID > 0 {
  1610. var hpt models.HisPrescriptionProject
  1611. hpt.Type = 3
  1612. hpt.ID = 0
  1613. hpt.PatientId = last_prescriptions[index].PatientId
  1614. hpt.Status = 1
  1615. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1616. hpt.Mtime = time.Now().Unix()
  1617. hpt.Ctime = time.Now().Unix()
  1618. hpt.RecordDate = last_prescriptions[index].RecordDate
  1619. hpt.Count = "1"
  1620. hpt.Price = two.RetailPrice
  1621. hpt.ProjectId = two.ID
  1622. hpt.FeedetlSn = ""
  1623. hpt.PrescriptionId = last_prescriptions[index].ID
  1624. hpt.Unit = two.PackingUnit
  1625. hpt.Day = "1"
  1626. hpt.SingleDose = "1"
  1627. hpt.GoodInfo = two
  1628. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1629. }
  1630. if three.ID > 0 {
  1631. var hpt models.HisPrescriptionProject
  1632. hpt.Type = 3
  1633. hpt.ID = 0
  1634. hpt.PatientId = last_prescriptions[index].PatientId
  1635. hpt.Status = 1
  1636. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1637. hpt.Mtime = time.Now().Unix()
  1638. hpt.Ctime = time.Now().Unix()
  1639. hpt.RecordDate = last_prescriptions[index].RecordDate
  1640. hpt.Count = "1"
  1641. hpt.Price = three.RetailPrice
  1642. hpt.ProjectId = three.ID
  1643. hpt.FeedetlSn = ""
  1644. hpt.PrescriptionId = last_prescriptions[index].ID
  1645. hpt.Unit = three.PackingUnit
  1646. hpt.Day = "1"
  1647. hpt.SingleDose = "1"
  1648. hpt.GoodInfo = three
  1649. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1650. }
  1651. }
  1652. }
  1653. }
  1654. }
  1655. c.ServeSuccessJSON(map[string]interface{}{
  1656. "his_info": his_patient_info,
  1657. "xt_info": xt_patient_info,
  1658. "prescription": prescriptions,
  1659. "case_history": case_history,
  1660. "info": patientPrescriptionInfo,
  1661. //"month_prescriptions": monthPrescriptions,
  1662. "order": order,
  1663. "doctors": doctors,
  1664. "department": department,
  1665. "sch_prescriptions": sch_prescriptions,
  1666. "last_prescriptions": last_prescriptions,
  1667. "schedule": sch,
  1668. "count": count,
  1669. "drugStockConfig": drugStockConfig,
  1670. "last_info": lastPatientPrescriptionInfo,
  1671. "befor": beforThrity,
  1672. "LastCaseHistory": LastCaseHistory,
  1673. "prescriptionInfo": prescriptionInfo,
  1674. })
  1675. return
  1676. }
  1677. func (c *HisApiController) GetHisPrescriptionConfig() {
  1678. adminInfo := c.GetAdminUserInfo()
  1679. //获取医嘱模版
  1680. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1681. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1682. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1683. //获取所有基础药
  1684. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1685. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1686. if config.ID > 0 && config.IsOpen == 1 {
  1687. for _, item := range drugs {
  1688. var index = 0
  1689. for _, subItem := range item.OtherDrugWarehouseInfo {
  1690. if index == 0 {
  1691. index = index + 1
  1692. if subItem.RetailPrice > 0 {
  1693. item.MinPrice = subItem.RetailPrice
  1694. }
  1695. }
  1696. }
  1697. }
  1698. }
  1699. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1700. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1701. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1702. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1703. //获取所有科室信息
  1704. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1705. //获取诊断信息
  1706. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1707. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1708. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1709. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1710. //获取是否开启保存耗材出库的开关
  1711. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1712. c.ServeSuccessJSON(map[string]interface{}{
  1713. "drugs": drugs,
  1714. "advices_template": advices,
  1715. "drugways": drugways,
  1716. "efs": efs,
  1717. "doctors": doctors,
  1718. "department": department,
  1719. "sick": sick,
  1720. "additions": additions,
  1721. "diagnose": diagnose,
  1722. "manufacturers": manufacturers,
  1723. "goodOutOpen": goodOutOpen,
  1724. "patientDiagnose": patientDiagnose,
  1725. })
  1726. }
  1727. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1728. //获取所有基础药
  1729. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1730. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1731. if config.ID > 0 && config.IsOpen == 1 {
  1732. for _, item := range drugs {
  1733. var index = 0
  1734. for _, subItem := range item.OtherDrugWarehouseInfo {
  1735. if index == 0 {
  1736. index = index + 1
  1737. if subItem.RetailPrice > 0 {
  1738. item.MinPrice = subItem.RetailPrice
  1739. }
  1740. }
  1741. }
  1742. }
  1743. }
  1744. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1745. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1746. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1747. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1748. //获取所有科室信息
  1749. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1750. //获取诊断信息
  1751. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1752. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1753. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1754. //获取是否开启保存耗材出库的开关
  1755. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1756. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1757. c.ServeSuccessJSON(map[string]interface{}{
  1758. "drugs": drugs,
  1759. "advices_template": advices,
  1760. "drugways": drugways,
  1761. "efs": efs,
  1762. "doctors": doctors,
  1763. "department": department,
  1764. "sick": sick,
  1765. "additions": additions,
  1766. "diagnose": diagnose,
  1767. "manufacturers": manufacturers,
  1768. "goodOutOpen": goodOutOpen,
  1769. "patientDiagnose": patientDiagnose,
  1770. })
  1771. }
  1772. }
  1773. func (c *HisApiController) CreateHisPrescription() {
  1774. record_date := c.GetString("record_date")
  1775. patient_id, _ := c.GetInt64("patient_id")
  1776. reg_type, _ := c.GetInt64("reg_type")
  1777. diagnose := c.GetString("diagnose")
  1778. sick_type, _ := c.GetInt64("sick_type")
  1779. sick_history := c.GetString("sick_history")
  1780. doctor_id, _ := c.GetInt64("doctor", 0)
  1781. department, _ := c.GetInt64("department", 0)
  1782. his_patient_id, _ := c.GetInt64("his_patient_id")
  1783. p_type, _ := c.GetInt64("p_type")
  1784. patient_diagnose := c.GetString("patient_diagnose")
  1785. dataBody := make(map[string]interface{}, 0)
  1786. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1787. if err != nil {
  1788. utils.ErrorLog(err.Error())
  1789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1790. return
  1791. }
  1792. //edit, src := GetCompareData(dataBody)
  1793. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1794. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1795. //fmt.Println(drugResult)
  1796. //fmt.Println(goodResult)
  1797. timeLayout := "2006-01-02"
  1798. loc, _ := time.LoadLocation("Local")
  1799. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1800. if err != nil {
  1801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1802. return
  1803. }
  1804. adminInfo := c.GetAdminUserInfo()
  1805. recordDateTime := theTime.Unix()
  1806. //查询默认出库仓库库存
  1807. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1808. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1809. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1810. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1811. if len(lists) == 1 {
  1812. his_patient_id = lists[0].ID
  1813. }
  1814. }
  1815. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1816. //自动出库的开关开启
  1817. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1818. //自动出库
  1819. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1820. //耗材保存处方出库
  1821. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1822. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1823. //已发药和已收费限制逻辑
  1824. isMidicine := false
  1825. isCharge := false
  1826. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1827. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1828. if len(prescriptions) > 0 {
  1829. for _, item := range prescriptions {
  1830. items := item.(map[string]interface{})
  1831. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1832. utils.ErrorLog("id")
  1833. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1834. return
  1835. }
  1836. id := int64(items["id"].(float64))
  1837. if id > 0 {
  1838. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1839. if err != nil {
  1840. if new_prescription.OrderStatus == 4 {
  1841. isCharge = true
  1842. }
  1843. }
  1844. }
  1845. }
  1846. }
  1847. }
  1848. if isMidicine == true {
  1849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1850. return
  1851. }
  1852. if isCharge == true {
  1853. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1854. return
  1855. }
  1856. // 开始主事务
  1857. db := service.XTWriteDB()
  1858. tx := db.Begin()
  1859. // 在函数结束时处理事务回滚
  1860. defer func() {
  1861. if r := recover(); r != nil {
  1862. tx.Rollback()
  1863. }
  1864. }()
  1865. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1866. //药品发药出库
  1867. if pharmacyConfig.IsOpen == 1 {
  1868. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1869. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1870. if len(prescriptions) > 0 {
  1871. for _, item := range prescriptions {
  1872. items := item.(map[string]interface{})
  1873. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1874. advices := items["advices"].([]interface{})
  1875. if len(advices) > 0 {
  1876. for _, advice := range advices {
  1877. var drug_id int64
  1878. var prescribing_number float64
  1879. var prescribingNumberUnit string
  1880. var adviceId int64
  1881. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1882. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1883. }
  1884. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1885. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1886. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1887. }
  1888. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1889. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1890. }
  1891. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1892. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1893. }
  1894. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1895. if drug.ID == 0 {
  1896. tx.Rollback()
  1897. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1898. return
  1899. }
  1900. //查询药品的所有库存
  1901. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1902. var total_count int64
  1903. for _, it := range list {
  1904. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1905. }
  1906. totals := strconv.FormatInt(total_count, 10)
  1907. //查询该药品是否存在开药记录
  1908. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1909. //新增处方盘点库存是否充足
  1910. if advicelist.ID == 0 {
  1911. all_count, _ := strconv.ParseFloat(totals, 64)
  1912. if prescribingNumberUnit == drug.MinUnit {
  1913. if drug.IsUse != 1 {
  1914. if drug.IsProject == 0 || drug.IsProject == 2 {
  1915. if all_count == 0 {
  1916. tx.Rollback()
  1917. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1918. return
  1919. }
  1920. if prescribing_number > all_count {
  1921. tx.Rollback()
  1922. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1923. return
  1924. }
  1925. }
  1926. }
  1927. }
  1928. if prescribingNumberUnit == drug.MaxUnit {
  1929. num := prescribing_number * float64(drug.MinNumber)
  1930. if drug.IsUse != 1 {
  1931. if drug.IsProject == 0 || drug.IsProject == 2 {
  1932. if all_count == 0 {
  1933. tx.Rollback()
  1934. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1935. return
  1936. }
  1937. if num > all_count {
  1938. tx.Rollback()
  1939. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1940. return
  1941. }
  1942. }
  1943. }
  1944. }
  1945. }
  1946. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1947. //不使用保存处方出库
  1948. if drugOutConfig.IsOpen != 1 {
  1949. //修改处方
  1950. for _, advice := range advices {
  1951. var drug_id int64
  1952. var prescribing_number float64
  1953. var prescribingNumberUnit string
  1954. var prescribingNumber string
  1955. var adviceId int64
  1956. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1957. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1958. }
  1959. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1960. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1961. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1962. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1963. }
  1964. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1965. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1966. }
  1967. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1968. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1969. }
  1970. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1971. if drug.ID == 0 {
  1972. tx.Rollback()
  1973. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1974. return
  1975. }
  1976. //查询药品的所有库存
  1977. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1978. var total_count int64
  1979. for _, it := range list {
  1980. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1981. }
  1982. totals := strconv.FormatInt(total_count, 10)
  1983. //查询该药品是否存在开药记录
  1984. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1985. //新增处方
  1986. if advicelist.ID == 0 {
  1987. all_count, _ := strconv.ParseFloat(totals, 64)
  1988. if prescribingNumberUnit == drug.MinUnit {
  1989. if drug.IsUse != 1 {
  1990. if drug.IsProject == 0 || drug.IsProject == 2 {
  1991. if all_count == 0 {
  1992. tx.Rollback()
  1993. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1994. return
  1995. }
  1996. if prescribing_number > all_count {
  1997. tx.Rollback()
  1998. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1999. return
  2000. }
  2001. }
  2002. }
  2003. } else {
  2004. if prescribingNumberUnit == drug.MaxUnit {
  2005. num := prescribing_number * float64(drug.MinNumber)
  2006. if drug.IsUse != 1 {
  2007. if drug.IsProject == 0 || drug.IsProject == 2 {
  2008. if all_count == 0 {
  2009. tx.Rollback()
  2010. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2011. return
  2012. }
  2013. if num > all_count {
  2014. tx.Rollback()
  2015. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2016. return
  2017. }
  2018. }
  2019. }
  2020. }
  2021. }
  2022. }
  2023. //修改处方
  2024. if advicelist.ID > 0 {
  2025. var device_number int64
  2026. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2027. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2028. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2029. device_number = prescribingNumberInt * drug.MinNumber
  2030. }
  2031. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2032. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2033. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2034. device_number = prescribingNumberInt
  2035. }
  2036. var number_count int64
  2037. if prescribingNumberUnit == drug.MaxUnit {
  2038. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2039. number_count = prescribingNumberInt * drug.MinNumber
  2040. }
  2041. if prescribingNumberUnit == drug.MinUnit {
  2042. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2043. number_count = prescribingNumberInt
  2044. }
  2045. //如果修改的数量大于之前修改的数量
  2046. if (number_count - device_number) > 0 {
  2047. //如果修改的差数量 大于库存数量
  2048. if drug.IsUse != 1 {
  2049. if (number_count - device_number) > total_count {
  2050. tx.Rollback()
  2051. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2052. return
  2053. }
  2054. }
  2055. }
  2056. }
  2057. }
  2058. }
  2059. }
  2060. }
  2061. }
  2062. }
  2063. }
  2064. }
  2065. }
  2066. //已发药和已收费限制逻辑
  2067. //执行出库的逻辑
  2068. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  2069. //校验库存总量
  2070. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2071. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2072. if len(prescriptions) > 0 {
  2073. for _, item := range prescriptions {
  2074. items := item.(map[string]interface{})
  2075. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2076. advices := items["advices"].([]interface{})
  2077. if len(advices) > 0 {
  2078. for _, advice := range advices {
  2079. var drug_id int64
  2080. var prescribing_number float64
  2081. var prescribingNumberUnit string
  2082. var adviceId int64
  2083. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2084. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2085. }
  2086. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2087. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2088. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2089. }
  2090. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2091. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2092. }
  2093. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2094. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2095. }
  2096. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2097. if drug.ID == 0 {
  2098. tx.Rollback()
  2099. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2100. return
  2101. }
  2102. //查询药品的所有库存
  2103. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2104. var total_count int64
  2105. for _, it := range list {
  2106. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2107. }
  2108. totals := strconv.FormatInt(total_count, 10)
  2109. //查询该药品是否存在开药记录
  2110. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2111. //查询最新批次库存
  2112. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2113. var batch_number_count int64
  2114. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2115. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2116. //新增处方
  2117. if advicelist.ID == 0 {
  2118. all_count, _ := strconv.ParseFloat(totals, 64)
  2119. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2120. if prescribingNumberUnit == drug.MinUnit {
  2121. if drug.IsUse != 1 {
  2122. if drug.IsProject == 0 || drug.IsProject == 2 {
  2123. if all_count == 0 {
  2124. tx.Rollback()
  2125. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2126. return
  2127. }
  2128. if prescribing_number > all_count {
  2129. tx.Rollback()
  2130. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2131. return
  2132. }
  2133. }
  2134. if adminInfo.CurrentOrgId == 10215 {
  2135. if prescribing_number > batch_number_all_count {
  2136. tx.Rollback()
  2137. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2138. return
  2139. }
  2140. }
  2141. }
  2142. }
  2143. if prescribingNumberUnit == drug.MaxUnit {
  2144. num := prescribing_number * float64(drug.MinNumber)
  2145. if drug.IsUse != 1 {
  2146. if drug.IsProject == 0 || drug.IsProject == 2 {
  2147. if all_count == 0 {
  2148. tx.Rollback()
  2149. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2150. return
  2151. }
  2152. if num > all_count {
  2153. tx.Rollback()
  2154. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2155. return
  2156. }
  2157. }
  2158. if adminInfo.CurrentOrgId == 10215 {
  2159. if num > batch_number_all_count {
  2160. tx.Rollback()
  2161. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2162. return
  2163. }
  2164. }
  2165. }
  2166. }
  2167. }
  2168. //不是保存处方出库
  2169. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2170. if drugOutConfig.IsOpen != 1 {
  2171. //修改处方
  2172. for _, advice := range advices {
  2173. var drug_id int64
  2174. var prescribing_number float64
  2175. var prescribingNumberUnit string
  2176. var prescribingNumber string
  2177. var adviceId int64
  2178. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2179. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2180. }
  2181. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2182. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2183. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2184. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2185. }
  2186. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2187. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2188. }
  2189. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2190. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2191. }
  2192. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2193. if drug.ID == 0 {
  2194. tx.Rollback()
  2195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2196. return
  2197. }
  2198. //查询药品的所有库存
  2199. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2200. var total_count int64
  2201. for _, it := range list {
  2202. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2203. }
  2204. totals := strconv.FormatInt(total_count, 10)
  2205. //查询该药品是否存在开药记录
  2206. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2207. //新增处方
  2208. if advicelist.ID == 0 {
  2209. //查询最新批次库存
  2210. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2211. var batch_number_count int64
  2212. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2213. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2214. all_count, _ := strconv.ParseFloat(totals, 64)
  2215. if all_count == 0 {
  2216. tx.Rollback()
  2217. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2218. return
  2219. }
  2220. if prescribingNumberUnit == drug.MinUnit {
  2221. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2222. if drug.IsUse != 1 {
  2223. if drug.IsProject == 0 || drug.IsProject == 2 {
  2224. if all_count == 0 {
  2225. tx.Rollback()
  2226. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2227. return
  2228. }
  2229. if prescribing_number > all_count {
  2230. tx.Rollback()
  2231. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2232. return
  2233. }
  2234. }
  2235. if adminInfo.CurrentOrgId == 10215 {
  2236. if prescribing_number > batch_number_all_count {
  2237. tx.Rollback()
  2238. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2239. return
  2240. }
  2241. }
  2242. }
  2243. } else {
  2244. if prescribingNumberUnit == drug.MaxUnit {
  2245. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2246. num := prescribing_number * float64(drug.MinNumber)
  2247. if drug.IsUse != 1 {
  2248. if drug.IsProject == 0 || drug.IsProject == 2 {
  2249. if all_count == 0 {
  2250. tx.Rollback()
  2251. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2252. return
  2253. }
  2254. if num > all_count {
  2255. tx.Rollback()
  2256. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2257. return
  2258. }
  2259. }
  2260. if adminInfo.CurrentOrgId == 10215 {
  2261. if prescribing_number > batch_number_all_count {
  2262. tx.Rollback()
  2263. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2264. return
  2265. }
  2266. }
  2267. }
  2268. }
  2269. }
  2270. }
  2271. //修改处方
  2272. if advicelist.ID > 0 {
  2273. //查询最新批次库存
  2274. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2275. var batch_number_count int64
  2276. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2277. var device_number int64
  2278. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2279. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2280. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2281. device_number = prescribingNumberInt * drug.MinNumber
  2282. }
  2283. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2284. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2285. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2286. device_number = prescribingNumberInt
  2287. //回退库存
  2288. }
  2289. var number_count int64
  2290. if prescribingNumberUnit == drug.MaxUnit {
  2291. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2292. number_count = prescribingNumberInt * drug.MinNumber
  2293. //回退库存
  2294. }
  2295. if prescribingNumberUnit == drug.MinUnit {
  2296. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2297. number_count = prescribingNumberInt
  2298. //回退库存
  2299. }
  2300. //如果修改的数量大于之前修改的数量
  2301. if (number_count - device_number) > 0 {
  2302. //如果修改的差数量 大于库存数量
  2303. if drug.IsUse != 1 {
  2304. if drug.IsProject == 0 || drug.IsProject == 2 {
  2305. if total_count == 0 {
  2306. tx.Rollback()
  2307. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2308. return
  2309. }
  2310. if (number_count - device_number) > total_count {
  2311. tx.Rollback()
  2312. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2313. return
  2314. }
  2315. if (number_count - device_number) > batch_number_count {
  2316. tx.Rollback()
  2317. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2318. return
  2319. }
  2320. }
  2321. if adminInfo.CurrentOrgId == 10215 {
  2322. // 查询该药品最后一次出库记录
  2323. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2324. var out_count int64
  2325. var in_count int64
  2326. var stock_max_number int64
  2327. var stock_min_number int64
  2328. for _, it := range outInfo {
  2329. if it.CountUnit == drug.MaxUnit {
  2330. it.Count = it.Count * drug.MinNumber
  2331. }
  2332. out_count += it.Count
  2333. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2334. stock_max_number = warehouseInfoList.StockMaxNumber
  2335. stock_min_number = warehouseInfoList.StockMinNumber
  2336. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2337. }
  2338. if out_count > 0 {
  2339. if (number_count - device_number) > in_count {
  2340. tx.Rollback()
  2341. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2342. return
  2343. }
  2344. }
  2345. // 未出库
  2346. if out_count == 0 {
  2347. var sum_in_count int64
  2348. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2349. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2350. //如果修改的数量大于有库存的第一个批次
  2351. if number_count > sum_in_count {
  2352. tx.Rollback()
  2353. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2354. return
  2355. }
  2356. }
  2357. }
  2358. }
  2359. }
  2360. //药品发药
  2361. //pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2362. //不使用药品发药的功能
  2363. //if pharmacyConfig.IsOpen != 1 {
  2364. // if device_number != number_count {
  2365. //
  2366. // //查询该药品的出库记录
  2367. // outListExport, _ := service.GetWarehouseOutListExport(drug_id, patient_id, recordDateTime, adviceId)
  2368. // if len(outListExport) > 0 {
  2369. // //
  2370. // for _, item := range outListExport {
  2371. // //回退库存
  2372. // if item.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2373. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, number_count)
  2374. // }
  2375. // if item.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2376. // var stock_max_number int64
  2377. // var stock_min_number int64
  2378. //
  2379. // if number_count >= drug.MinNumber {
  2380. //
  2381. // stock_max_number = device_number / drug.MinNumber
  2382. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, stock_max_number)
  2383. //
  2384. // stock_min_number = device_number % drug.MinNumber
  2385. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, stock_min_number)
  2386. //
  2387. // } else {
  2388. //
  2389. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, device_number)
  2390. //
  2391. // }
  2392. // }
  2393. //
  2394. // if item.CountUnit == drug.MaxUnit && item.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2395. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, device_number)
  2396. // }
  2397. // }
  2398. // }
  2399. //
  2400. // service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2401. // var sum_count int64
  2402. // orgId := c.GetAdminUserInfo().CurrentOrgId
  2403. // stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgId, drug_id)
  2404. // for _, its := range stockInfo {
  2405. // if its.MaxUnit == drug.MaxUnit {
  2406. // its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2407. // }
  2408. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2409. // }
  2410. // //更新字典里面的库存
  2411. // service.UpdateBaseDrugSumTwo(drug_id, sum_count, orgId)
  2412. //
  2413. // //剩余库存
  2414. // service.UpdateDrugStockCount(drug_id, orgId, storeConfig.DrugStorehouseOut, sum_count)
  2415. //
  2416. // over, _ := service.FindOverCount(drug_id, orgId, storeConfig.DrugStorehouseOut)
  2417. // //减少出库数量
  2418. // service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2419. //
  2420. // }
  2421. //}
  2422. }
  2423. }
  2424. }
  2425. //保存处方开药
  2426. if drugOutConfig.IsOpen == 1 {
  2427. //修改处方
  2428. for _, advice := range advices {
  2429. var drug_id int64
  2430. var prescribing_number float64
  2431. var prescribingNumberUnit string
  2432. var prescribingNumber string
  2433. var adviceId int64
  2434. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2435. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2436. }
  2437. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2438. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2439. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2440. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2441. }
  2442. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2443. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2444. }
  2445. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2446. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2447. }
  2448. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2449. if drug.ID == 0 {
  2450. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2451. return
  2452. }
  2453. //查询药品的所有库存
  2454. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2455. var total_count int64
  2456. for _, it := range list {
  2457. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2458. }
  2459. totals := strconv.FormatInt(total_count, 10)
  2460. //查询该药品是否存在开药记录
  2461. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2462. //新增处方
  2463. if advicelist.ID == 0 {
  2464. //查询最新批次库存
  2465. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2466. var batch_number_count int64
  2467. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2468. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2469. all_count, _ := strconv.ParseFloat(totals, 64)
  2470. if prescribingNumberUnit == drug.MinUnit {
  2471. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2472. if drug.IsUse != 1 {
  2473. if drug.IsProject == 0 || drug.IsProject == 2 {
  2474. if all_count == 0 {
  2475. tx.Rollback()
  2476. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2477. return
  2478. }
  2479. if prescribing_number > all_count {
  2480. tx.Rollback()
  2481. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2482. return
  2483. }
  2484. }
  2485. if adminInfo.CurrentOrgId == 10215 {
  2486. if prescribing_number > batch_number_all_count {
  2487. tx.Rollback()
  2488. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2489. return
  2490. }
  2491. }
  2492. }
  2493. } else {
  2494. if prescribingNumberUnit == drug.MaxUnit {
  2495. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2496. num := prescribing_number * float64(drug.MinNumber)
  2497. if drug.IsUse != 1 {
  2498. if drug.IsProject == 0 || drug.IsProject == 2 {
  2499. if all_count == 0 {
  2500. tx.Rollback()
  2501. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2502. return
  2503. }
  2504. if num > all_count {
  2505. tx.Rollback()
  2506. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2507. return
  2508. }
  2509. }
  2510. if adminInfo.CurrentOrgId == 10215 {
  2511. if prescribing_number > batch_number_all_count {
  2512. tx.Rollback()
  2513. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2514. return
  2515. }
  2516. }
  2517. }
  2518. }
  2519. }
  2520. }
  2521. //修改处方
  2522. if advicelist.ID > 0 {
  2523. //查询最新批次库存
  2524. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2525. var batch_number_count int64
  2526. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2527. var device_number int64
  2528. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2529. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2530. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2531. device_number = prescribingNumberInt * drug.MinNumber
  2532. }
  2533. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2534. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2535. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2536. device_number = prescribingNumberInt
  2537. }
  2538. var number_count int64
  2539. if prescribingNumberUnit == drug.MaxUnit {
  2540. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2541. number_count = prescribingNumberInt * drug.MinNumber
  2542. }
  2543. if prescribingNumberUnit == drug.MinUnit {
  2544. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2545. number_count = prescribingNumberInt
  2546. }
  2547. //如果修改的数量大于之前修改的数量
  2548. if (number_count - device_number) > 0 {
  2549. //如果修改的差数量 大于库存数量
  2550. if drug.IsUse != 1 {
  2551. if drug.IsProject == 0 || drug.IsProject == 2 {
  2552. if total_count == 0 {
  2553. tx.Rollback()
  2554. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2555. return
  2556. }
  2557. if (number_count - device_number) > total_count {
  2558. tx.Rollback()
  2559. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2560. return
  2561. }
  2562. }
  2563. if adminInfo.CurrentOrgId == 10215 {
  2564. if (number_count - device_number) > batch_number_count {
  2565. tx.Rollback()
  2566. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2567. return
  2568. }
  2569. }
  2570. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2571. //查询历史出库数据总批次
  2572. // 查询该药品最后一次出库记录
  2573. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2574. var out_count int64
  2575. var in_count int64
  2576. var stock_max_number int64
  2577. var stock_min_number int64
  2578. for _, it := range outInfo {
  2579. if it.CountUnit == drug.MaxUnit {
  2580. it.Count = it.Count * drug.MinNumber
  2581. }
  2582. out_count += it.Count
  2583. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2584. stock_max_number = warehouseInfoList.StockMaxNumber
  2585. stock_min_number = warehouseInfoList.StockMinNumber
  2586. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2587. }
  2588. if out_count > 0 {
  2589. if (number_count - device_number) > in_count {
  2590. tx.Rollback()
  2591. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2592. return
  2593. }
  2594. }
  2595. // 未出库
  2596. if out_count == 0 {
  2597. var sum_in_count int64
  2598. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2599. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2600. if sum_in_count == 0 {
  2601. tx.Rollback()
  2602. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2603. return
  2604. }
  2605. //如果修改的数量大于有库存的第一个批次
  2606. if number_count > sum_in_count {
  2607. tx.Rollback()
  2608. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2609. return
  2610. }
  2611. }
  2612. }
  2613. }
  2614. }
  2615. }
  2616. }
  2617. }
  2618. }
  2619. }
  2620. }
  2621. }
  2622. }
  2623. }
  2624. }
  2625. //校验耗材库存
  2626. if goodOutConfig.IsOpen == 1 {
  2627. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2628. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2629. if len(prescriptions) > 0 {
  2630. for _, item := range prescriptions {
  2631. items := item.(map[string]interface{})
  2632. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2633. projects := items["project"].([]interface{})
  2634. if len(projects) > 0 {
  2635. for _, project := range projects {
  2636. var project_id int64
  2637. var project_type int64
  2638. var totals float64
  2639. var project_name string
  2640. var parsetotal int64
  2641. var id int64
  2642. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2643. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2644. }
  2645. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2646. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2647. }
  2648. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2649. total, _ := project.(map[string]interface{})["total"].(string)
  2650. totals, _ = strconv.ParseFloat(total, 64)
  2651. }
  2652. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2653. project_name = project.(map[string]interface{})["project_name"].(string)
  2654. }
  2655. if project_type == 3 {
  2656. //查找该耗材的出库记录
  2657. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2658. if len(goodWarehouseInfo) == 0 {
  2659. //查询耗材库存
  2660. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2661. var stock_count int64
  2662. for _, it := range list {
  2663. stock_count += it.StockCount
  2664. }
  2665. stock_counts := strconv.FormatInt(stock_count, 10)
  2666. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2667. if stock_total_count == 0 {
  2668. tx.Rollback()
  2669. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2670. return
  2671. }
  2672. if totals > stock_total_count {
  2673. tx.Rollback()
  2674. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2675. return
  2676. }
  2677. }
  2678. if len(goodWarehouseInfo) > 0 {
  2679. //查询该患者耗材的历史数据
  2680. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2681. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2682. //数量发生改变
  2683. if parsetotal != count {
  2684. //如果现在的数量大于历史数量,就要看库存是否足够
  2685. if parsetotal > count {
  2686. //查询耗材所有库存
  2687. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2688. var stock_count int64
  2689. for _, it := range list {
  2690. stock_count += it.StockCount
  2691. }
  2692. //库存不足
  2693. if stock_count == 0 {
  2694. tx.Rollback()
  2695. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2696. return
  2697. }
  2698. if (parsetotal - count) > stock_count {
  2699. tx.Rollback()
  2700. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2701. return
  2702. }
  2703. }
  2704. }
  2705. }
  2706. }
  2707. }
  2708. }
  2709. }
  2710. }
  2711. }
  2712. }
  2713. }
  2714. //不使用耗材保存处方出库
  2715. if goodOutConfig.IsOpen != 1 {
  2716. if stockConfig.IsOpen == 1 {
  2717. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2718. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2719. if len(prescriptions) > 0 {
  2720. for _, item := range prescriptions {
  2721. items := item.(map[string]interface{})
  2722. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2723. projects := items["project"].([]interface{})
  2724. if len(projects) > 0 {
  2725. for _, project := range projects {
  2726. var project_id int64
  2727. var project_type int64
  2728. var totals float64
  2729. var project_name string
  2730. var parsetotal int64
  2731. var id int64
  2732. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2733. id = int64(project.(map[string]interface{})["id"].(float64))
  2734. }
  2735. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2736. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2737. }
  2738. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2739. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2740. }
  2741. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2742. total, _ := project.(map[string]interface{})["total"].(string)
  2743. totals, _ = strconv.ParseFloat(total, 64)
  2744. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2745. }
  2746. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2747. project_name = project.(map[string]interface{})["project_name"].(string)
  2748. }
  2749. if project_type == 3 {
  2750. //查找该耗材的出库记录
  2751. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2752. //没有出库记录
  2753. if len(goodWarehouseInfo) == 0 {
  2754. //查询耗材库存
  2755. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2756. var stock_count int64
  2757. for _, it := range list {
  2758. stock_count += it.StockCount
  2759. }
  2760. stock_counts := strconv.FormatInt(stock_count, 10)
  2761. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2762. if stock_total_count == 0 {
  2763. tx.Rollback()
  2764. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2765. return
  2766. }
  2767. if totals > stock_total_count {
  2768. tx.Rollback()
  2769. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2770. return
  2771. }
  2772. //查找今日该患者已经出库的所有耗材
  2773. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2774. for _, item := range goodList {
  2775. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2776. var flush_count int64
  2777. for _, it := range goodListSix {
  2778. flush_count += it.StockCount
  2779. }
  2780. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2781. creater := adminInfo.AdminUser.Id
  2782. if errs != nil {
  2783. goodErrcode := models.XtGoodErrcode{
  2784. UserOrgId: item.OrgId,
  2785. Errcode: "手动出库更新剩余出库失败",
  2786. GoodId: item.GoodId,
  2787. Status: 1,
  2788. Ctime: time.Now().Unix(),
  2789. Mtime: 0,
  2790. Count: 0,
  2791. StockCount: 0,
  2792. Creater: creater,
  2793. BatchNumberId: 0,
  2794. WarehouseOutId: 0,
  2795. }
  2796. service.CreateGoodErrcode(goodErrcode)
  2797. }
  2798. }
  2799. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2800. }
  2801. //有出库记录
  2802. if len(goodWarehouseInfo) > 0 {
  2803. //查询该患者耗材的历史数据
  2804. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2805. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2806. //数量发生改变
  2807. if parsetotal != count {
  2808. //查找今日该患者已经出库的所有耗材
  2809. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2810. for _, item := range goodList {
  2811. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2812. var flush_count int64
  2813. for _, it := range goodListSix {
  2814. flush_count += it.StockCount
  2815. }
  2816. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2817. //减少出库数量
  2818. creater := adminInfo.AdminUser.Id
  2819. if errs != nil {
  2820. goodErrcode := models.XtGoodErrcode{
  2821. UserOrgId: item.OrgId,
  2822. Errcode: "手动出库更新剩余出库失败",
  2823. GoodId: item.GoodId,
  2824. Status: 1,
  2825. Ctime: time.Now().Unix(),
  2826. Mtime: 0,
  2827. Count: 0,
  2828. StockCount: 0,
  2829. Creater: creater,
  2830. BatchNumberId: 0,
  2831. WarehouseOutId: 0,
  2832. }
  2833. service.CreateGoodErrcode(goodErrcode)
  2834. }
  2835. //查询默认仓库
  2836. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2837. var total_count int64
  2838. for _, it := range stockList {
  2839. total_count += it.StockCount
  2840. }
  2841. //基础库插入数据
  2842. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2843. }
  2844. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2845. }
  2846. }
  2847. }
  2848. }
  2849. }
  2850. }
  2851. }
  2852. }
  2853. }
  2854. }
  2855. }
  2856. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2857. var hpInfo models.HisPrescriptionInfo
  2858. if info.ID == 0 {
  2859. var randNum int
  2860. randNum = rand.Intn(10000) + 1000
  2861. timestamp := time.Now().Unix()
  2862. tempTime := time.Unix(timestamp, 0)
  2863. timeFormat := tempTime.Format("20060102150405")
  2864. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2865. hpInfo = models.HisPrescriptionInfo{
  2866. HisPatientId: his_patient_id,
  2867. UserOrgId: adminInfo.CurrentOrgId,
  2868. RecordDate: theTime.Unix(),
  2869. PatientId: patient_id,
  2870. Status: 1,
  2871. Ctime: time.Now().Unix(),
  2872. Mtime: time.Now().Unix(),
  2873. Creator: adminInfo.AdminUser.Id,
  2874. Modifier: adminInfo.AdminUser.Id,
  2875. Diagnosis: diagnose,
  2876. SickHistory: sick_history,
  2877. Departments: department,
  2878. RegisterType: reg_type,
  2879. PrescriptionNumber: p_number,
  2880. PrescriptionStatus: 1,
  2881. Doctor: role.UserName,
  2882. DoctorId: doctor_id,
  2883. SickType: sick_type,
  2884. PType: p_type,
  2885. PatientDiagnosis: patient_diagnose,
  2886. }
  2887. service.SavePatientPrescriptionInfo(hpInfo)
  2888. //创建步骤表
  2889. finish := models.XtDialysisFinish{
  2890. IsFinish: 1,
  2891. UserOrgId: adminInfo.CurrentOrgId,
  2892. Status: 1,
  2893. Ctime: time.Now().Unix(),
  2894. Mtime: 0,
  2895. Module: 4,
  2896. RecordDate: theTime.Unix(),
  2897. Sourse: 1,
  2898. PatientId: patient_id,
  2899. }
  2900. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2901. if dialysisFinish.ID == 0 {
  2902. service.CreateDialysisFinish(finish)
  2903. }
  2904. redis := service.RedisClient()
  2905. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2906. redis.Set(key, "", time.Second)
  2907. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2908. redis.Set(keyOne, "", time.Second)
  2909. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2910. redis.Set(keySeven, "", time.Second)
  2911. defer redis.Close()
  2912. } else {
  2913. hpInfo = models.HisPrescriptionInfo{
  2914. ID: info.ID,
  2915. UserOrgId: adminInfo.CurrentOrgId,
  2916. RecordDate: info.RecordDate,
  2917. PatientId: info.PatientId,
  2918. Status: 1,
  2919. Ctime: info.Ctime,
  2920. Mtime: time.Now().Unix(),
  2921. Creator: info.Creator,
  2922. Modifier: adminInfo.AdminUser.Id,
  2923. Diagnosis: diagnose,
  2924. SickHistory: sick_history,
  2925. Departments: department,
  2926. RegisterType: reg_type,
  2927. PrescriptionNumber: info.PrescriptionNumber,
  2928. Doctor: role.UserName,
  2929. PrescriptionStatus: info.PrescriptionStatus,
  2930. DoctorId: doctor_id,
  2931. SickType: sick_type,
  2932. PType: info.PType,
  2933. HisPatientId: info.HisPatientId,
  2934. PatientDiagnosis: patient_diagnose,
  2935. }
  2936. service.SavePatientPrescriptionInfo(hpInfo)
  2937. //创建步骤表
  2938. finish := models.XtDialysisFinish{
  2939. IsFinish: 1,
  2940. UserOrgId: adminInfo.CurrentOrgId,
  2941. Status: 1,
  2942. Ctime: time.Now().Unix(),
  2943. Mtime: 0,
  2944. Module: 4,
  2945. RecordDate: info.RecordDate,
  2946. Sourse: 1,
  2947. PatientId: info.PatientId,
  2948. }
  2949. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2950. if dialysisFinish.ID == 0 {
  2951. service.CreateDialysisFinish(finish)
  2952. }
  2953. redis := service.RedisClient()
  2954. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2955. redis.Set(key, "", time.Second)
  2956. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2957. redis.Set(keyOne, "", time.Second)
  2958. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2959. redis.Set(keySeven, "", time.Second)
  2960. defer redis.Close()
  2961. }
  2962. //定义切片
  2963. var adviceList []models.HisDoctorAdviceInfo
  2964. var projectList []models.HisPrescriptionProject
  2965. if adminInfo.CurrentOrgId == 10489 || adminInfo.CurrentOrgId == 10510 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 10478 || adminInfo.CurrentOrgId == 10318 || adminInfo.CurrentOrgId == 10480 || adminInfo.CurrentOrgId == 10633 || adminInfo.CurrentOrgId == 10610 || adminInfo.CurrentOrgId == 10402 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10537 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10644 || adminInfo.CurrentOrgId == 10635 || adminInfo.CurrentOrgId == 10598 || adminInfo.CurrentOrgId == 10028 {
  2966. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2967. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2968. var tempPrescription *models.HisPrescription
  2969. if len(prescriptions) > 0 {
  2970. for _, item := range prescriptions {
  2971. // 开始外部循环的事务
  2972. tx := db.Begin()
  2973. // 在函数结束时处理事务回滚
  2974. defer func() {
  2975. if r := recover(); r != nil {
  2976. tx.Rollback()
  2977. }
  2978. }()
  2979. items := item.(map[string]interface{})
  2980. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2981. utils.ErrorLog("id")
  2982. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2983. return
  2984. }
  2985. id := int64(items["id"].(float64))
  2986. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2987. tempPrescription = &new_prescription
  2988. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2989. utils.ErrorLog("type")
  2990. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2991. return
  2992. }
  2993. types := int64(items["type"].(float64))
  2994. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2995. utils.ErrorLog("med_type")
  2996. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2997. return
  2998. }
  2999. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3000. if med_type == "0" {
  3001. med_type = "14"
  3002. }
  3003. //if order_status == 0 {
  3004. // order_status = 1
  3005. //}
  3006. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3007. utils.ErrorLog("pre_time")
  3008. }
  3009. preTime, _ := items["pre_time"].(string)
  3010. fmt.Println("preTime", preTime)
  3011. timeLayout := "2006-01-02"
  3012. loc, _ := time.LoadLocation("Local")
  3013. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3014. //result := strings.Split(preTime, " ")
  3015. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3016. if err != nil {
  3017. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3018. return
  3019. }
  3020. pTime := theTime2.Unix()
  3021. ctime := time.Now().Unix()
  3022. if tempPrescription.ID == 0 {
  3023. prescription := &models.HisPrescription{
  3024. ID: 0,
  3025. PatientId: patient_id,
  3026. UserOrgId: adminInfo.CurrentOrgId,
  3027. RecordDate: recordDateTime,
  3028. Ctime: ctime,
  3029. Mtime: ctime,
  3030. Type: types,
  3031. Modifier: adminInfo.AdminUser.Id,
  3032. Creator: adminInfo.AdminUser.Id,
  3033. Status: 1,
  3034. Doctor: role.UserName,
  3035. HisPatientId: his_patient_id,
  3036. OrderStatus: 1,
  3037. BatchNumber: "",
  3038. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3039. PreTime: pTime,
  3040. PType: p_type,
  3041. MedType: med_type,
  3042. }
  3043. tempPrescription = prescription
  3044. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3045. redis := service.RedisClient()
  3046. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3047. redis.Set(key, "", time.Second)
  3048. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3049. redis.Set(keyOne, "", time.Second)
  3050. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3051. redis.Set(keySeven, "", time.Second)
  3052. defer redis.Close()
  3053. } else {
  3054. tempPrescription.ID = id
  3055. tempPrescription.Type = types
  3056. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3057. tempPrescription.Mtime = time.Now().Unix()
  3058. tempPrescription.Doctor = role.UserName
  3059. //tempPrescription.OrderStatus = order_status
  3060. tempPrescription.PreTime = pTime
  3061. tempPrescription.MedType = med_type
  3062. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3063. redis := service.RedisClient()
  3064. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3065. redis.Set(key, "", time.Second)
  3066. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3067. redis.Set(keyOne, "", time.Second)
  3068. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3069. redis.Set(keySeven, "", time.Second)
  3070. defer redis.Close()
  3071. }
  3072. //service.SaveHisPrescription(prescription)
  3073. //更改患者挂号状态
  3074. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3075. fmt.Println("更改失败", err2)
  3076. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3077. advices := items["advices"].([]interface{})
  3078. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3079. groupNo := int64(0)
  3080. if len(advices) > 0 {
  3081. for _, advice := range advices {
  3082. tx := db.Begin()
  3083. // 在函数结束时处理事务回滚
  3084. defer func() {
  3085. if r := recover(); r != nil {
  3086. tx.Rollback()
  3087. }
  3088. }()
  3089. var s models.HisDoctorAdviceInfo
  3090. s.PrescriptionId = tempPrescription.ID
  3091. s.AdviceType = 2
  3092. s.AdviceDoctor = doctor_id
  3093. s.StopState = 2
  3094. s.ExecutionState = 2
  3095. s.AdviceDate = theTime3.Unix()
  3096. s.Status = 1
  3097. s.UserOrgId = adminInfo.CurrentOrgId
  3098. s.RecordDate = theTime3.Unix()
  3099. s.StartTime = tempPrescription.PreTime
  3100. s.Groupno = groupNo
  3101. s.PatientId = patient_id
  3102. s.HisPatientId = his_patient_id
  3103. s.StartTime = pTime
  3104. s.IsSettle = 2
  3105. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3106. if errcode > 0 {
  3107. c.ServeFailJSONWithSGJErrorCode(errcode)
  3108. return
  3109. }
  3110. s.StartTime = pTime
  3111. var total_count int64 //处方总库存
  3112. //查询改药品信息
  3113. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3114. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3115. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3116. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3117. total_count += prescribingNumberSeven * medical.MinNumber
  3118. }
  3119. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3120. total_count += prescribingNumberSeven
  3121. }
  3122. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3123. total_count += prescribingNumberSeven
  3124. }
  3125. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3126. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3127. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3128. if s.Price != lastWarehouse.RetailPrice {
  3129. s.Price = lastWarehouse.RetailPrice
  3130. }
  3131. if s.Price == 0 {
  3132. if lastWarehouse.ID == 0 {
  3133. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  3134. s.Price = lastWarehouseTwo.RetailPrice
  3135. }
  3136. }
  3137. }
  3138. //查询保存处方出库开关是否打开
  3139. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3140. if s.PatientId != 30038 {
  3141. if drugOutConfig.IsOpen == 1 {
  3142. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  3143. // 查询该药品最后一次出库记录
  3144. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  3145. var is_user_total int64
  3146. var no_user_total int64
  3147. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3148. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3149. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3150. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  3151. }
  3152. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3153. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3154. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3155. no_user_total += prescribingNumberSevenTy
  3156. }
  3157. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3158. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3159. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3160. no_user_total += prescribingNumberSevenTy
  3161. }
  3162. if len(druginfo) > 0 {
  3163. for _, it := range druginfo {
  3164. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3165. it.Count = it.Count * drug.MinNumber
  3166. is_user_total += it.Count
  3167. }
  3168. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3169. is_user_total += it.Count
  3170. }
  3171. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3172. is_user_total += it.Count
  3173. }
  3174. }
  3175. }
  3176. //fmt.Println("药品名称----------------------", drug.DrugName)
  3177. //fmt.Println("药品名称----------------------", drug.IsUse)
  3178. //fmt.Println("is_user_total-------------------------", is_user_total)
  3179. //fmt.Println("no_user_total-------------------------", no_user_total)
  3180. if is_user_total != no_user_total {
  3181. //出库
  3182. if drug.IsUse == 2 {
  3183. creater := adminInfo.AdminUser.Id
  3184. newadviceInfo := &models.HisDoctorAdviceInfo{
  3185. ID: s.ID,
  3186. UserOrgId: s.UserOrgId,
  3187. PatientId: s.PatientId,
  3188. HisPatientId: s.HisPatientId,
  3189. AdviceType: s.AdviceType,
  3190. AdviceDate: s.AdviceDate,
  3191. StartTime: s.StartTime,
  3192. AdviceName: s.AdviceName,
  3193. AdviceDesc: s.AdviceDesc,
  3194. ReminderDate: s.ReminderDate,
  3195. SingleDose: s.SingleDose,
  3196. SingleDoseUnit: s.SingleDoseUnit,
  3197. PrescribingNumber: s.PrescribingNumber,
  3198. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3199. DeliveryWay: s.DeliveryWay,
  3200. ExecutionFrequency: s.ExecutionFrequency,
  3201. AdviceDoctor: s.AdviceDoctor,
  3202. Status: s.Status,
  3203. CreatedTime: s.CreatedTime,
  3204. UpdatedTime: s.UpdatedTime,
  3205. AdviceAffirm: s.AdviceAffirm,
  3206. Remark: s.Remark,
  3207. StopTime: s.StopTime,
  3208. StopReason: s.StopReason,
  3209. StopDoctor: s.StopDoctor,
  3210. StopState: s.StopState,
  3211. ParentId: s.ParentId,
  3212. ExecutionTime: s.ExecutionTime,
  3213. ExecutionStaff: s.ExecutionStaff,
  3214. ExecutionState: s.ExecutionState,
  3215. Checker: s.Checker,
  3216. RecordDate: s.RecordDate,
  3217. DialysisOrderId: s.DialysisOrderId,
  3218. CheckTime: s.CheckTime,
  3219. CheckState: s.CheckState,
  3220. DrugSpec: s.DrugSpec,
  3221. DrugSpecUnit: s.DrugSpecUnit,
  3222. Groupno: s.Groupno,
  3223. RemindType: s.RemindType,
  3224. FrequencyType: s.FrequencyType,
  3225. DayCount: s.DayCount,
  3226. WeekDay: s.WeekDay,
  3227. TemplateId: s.TemplateId,
  3228. Modifier: s.Modifier,
  3229. DrugId: s.DrugId,
  3230. Price: s.Price,
  3231. PrescriptionId: s.PrescriptionId,
  3232. MedListCodg: s.MedListCodg,
  3233. FeedetlSn: s.FeedetlSn,
  3234. Day: s.DayCount,
  3235. ChildDoctorAdvice: nil,
  3236. Drug: models.Drug{},
  3237. Diagnosis: s.Diagnosis,
  3238. Way: s.Way,
  3239. HospApprFlag: s.HospApprFlag,
  3240. LmtUsedFlag: s.LmtUsedFlag,
  3241. HisOrderInfo: models.HisOrderInfo{},
  3242. IsMedicine: s.IsMedicine,
  3243. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3244. Child: nil,
  3245. IsSettle: s.IsSettle,
  3246. IsMobile: s.IsMobile,
  3247. IsSelfDrug: s.IsSelfDrug,
  3248. DrugWayCount: s.DrugWayCount,
  3249. }
  3250. var history_count int64
  3251. var local_count int64
  3252. //查找已经开过的医嘱信息
  3253. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3254. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3255. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3256. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3257. local_count += prescribingNumberSevenTy * drug.MinNumber
  3258. }
  3259. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3260. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3261. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3262. local_count += prescribingNumberSevenTy
  3263. }
  3264. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3265. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3266. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3267. local_count += prescribingNumberSevenTy
  3268. }
  3269. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3270. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3271. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3272. history_count += prescribingNumberSevenTy * drug.MinNumber
  3273. }
  3274. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3275. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3276. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3277. history_count += prescribingNumberSevenTy
  3278. }
  3279. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3280. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3281. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3282. history_count += prescribingNumberSevenTy
  3283. }
  3284. //如果当前出库数量大于历史出库数量则需要出库
  3285. if local_count > history_count {
  3286. //按最小单位出库
  3287. var cha_count = local_count - history_count
  3288. newadviceInfo.PrescribingNumber = float64(cha_count)
  3289. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3290. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3291. }
  3292. //如果当前出库数量小于历史出库数量则需要退库
  3293. if local_count < history_count {
  3294. var cha_count = history_count - local_count
  3295. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3296. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3297. }
  3298. if local_count == history_count {
  3299. if is_user_total == 0 {
  3300. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3301. }
  3302. }
  3303. }
  3304. //更新字典里面的库存
  3305. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3306. var sum_count int64
  3307. for _, its := range stockInfo {
  3308. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3309. if its.MaxUnit == baseDrug.MaxUnit {
  3310. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3311. }
  3312. sum_count += its.StockMaxNumber + its.StockMinNumber
  3313. }
  3314. //更新基础库存
  3315. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3316. //剩余库存
  3317. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3318. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3319. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3320. //创建医嘱
  3321. service.CreateHisDoctorAdviceOne(&s, tx)
  3322. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3323. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3324. if len(outInfoTwo) > 0 {
  3325. for _, item := range outInfoTwo {
  3326. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3327. }
  3328. }
  3329. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3330. if len(drugAutoDetail) > 0 {
  3331. for _, item := range drugAutoDetail {
  3332. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3333. }
  3334. }
  3335. }
  3336. }
  3337. }
  3338. //记录日志
  3339. byterequest, _ := json.Marshal(s)
  3340. adviceLog := models.XtDoctorAdviceLog{
  3341. UserOrgId: s.UserOrgId,
  3342. PatientId: s.PatientId,
  3343. AdminUserId: adminInfo.AdminUser.Id,
  3344. Module: 1,
  3345. ErrLog: string(byterequest),
  3346. Status: 1,
  3347. Ctime: time.Now().Unix(),
  3348. Mtime: 0,
  3349. Source: "电脑端新建his医嘱",
  3350. RecordDate: s.AdviceDate,
  3351. }
  3352. service.CreateDoctorAdviceLog(adviceLog)
  3353. //存储切片中
  3354. adviceList = append(adviceList, s)
  3355. redis := service.RedisClient()
  3356. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3357. redis.Set(key, "", time.Second)
  3358. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3359. redis.Set(keyOne, "", time.Second)
  3360. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3361. redis.Set(keySeven, "", time.Second)
  3362. var randNum int
  3363. randNum = rand.Intn(10000) + 1000
  3364. timestamp := time.Now().Unix()
  3365. tempTime := time.Unix(timestamp, 0)
  3366. timeFormat := tempTime.Format("20060102150405")
  3367. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3368. if s.UserOrgId != 10206 {
  3369. if s.ID == 0 {
  3370. //查询改药品是否已经停用
  3371. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3372. if base.ID > 0 {
  3373. tx.Rollback()
  3374. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3375. return
  3376. }
  3377. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3378. if drugMedical.SumCount == 0 {
  3379. tx.Rollback()
  3380. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3381. return
  3382. }
  3383. }
  3384. }
  3385. //赤峰
  3386. if adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3387. drug, _ := service.FindNewBaseDrugLibRecord(adminInfo.CurrentOrgId, s.DrugId, tx)
  3388. info, _ := service.FindNewLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut, tx)
  3389. if info.RetailPrice > 0 {
  3390. if s.DeliveryWay == "口服" {
  3391. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3392. s.Price = drug.RetailPrice
  3393. }
  3394. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3395. s.Price = info.RetailPrice
  3396. }
  3397. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3398. s.Price = info.RetailPrice
  3399. }
  3400. }
  3401. }
  3402. }
  3403. service.CreateHisDoctorAdviceOne(&s, tx)
  3404. tx.Commit()
  3405. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3406. redis.Set(keySix, "", time.Second)
  3407. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3408. redis.Set(keyFive, "", time.Second)
  3409. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3410. redis.Set(keyEight, "", time.Second)
  3411. defer redis.Close()
  3412. }
  3413. }
  3414. }
  3415. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3416. projects := items["project"].([]interface{})
  3417. if len(projects) > 0 {
  3418. for _, project := range projects {
  3419. tx := db.Begin()
  3420. // 在函数结束时处理事务回滚
  3421. defer func() {
  3422. if r := recover(); r != nil {
  3423. tx.Rollback()
  3424. }
  3425. }()
  3426. var p models.HisPrescriptionProject
  3427. p.PrescriptionId = tempPrescription.ID
  3428. p.PatientId = patient_id
  3429. p.RecordDate = theTime3.Unix()
  3430. p.Doctor = doctor_id
  3431. p.UserOrgId = adminInfo.CurrentOrgId
  3432. p.HisPatientId = his_patient_id
  3433. p.Status = 1
  3434. p.StartTime = pTime
  3435. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3436. if errcode > 0 {
  3437. tx.Rollback()
  3438. c.ServeFailJSONWithSGJErrorCode(errcode)
  3439. return
  3440. }
  3441. if p.ID == 0 {
  3442. p.IsOut = 2
  3443. }
  3444. if p.ID > 0 {
  3445. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3446. p.IsOut = projectDetail.IsOut
  3447. }
  3448. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3449. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3450. if p.Type == 3 {
  3451. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3452. if p.Price != lastWarehouse.PackingPrice {
  3453. p.Price = lastWarehouse.PackingPrice
  3454. }
  3455. if p.Price == 0 {
  3456. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3457. p.Price = lastWarehouseTwo.PackingPrice
  3458. }
  3459. if p.Unit == "" {
  3460. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3461. p.Unit = goodInfoOne.PackingUnit
  3462. }
  3463. }
  3464. }
  3465. if adminInfo.CurrentOrgId != 10206 {
  3466. if p.Type == 3 {
  3467. if p.ID == 0 {
  3468. //查询该耗材是否停用
  3469. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3470. //表示该耗材已经停用,不能保存
  3471. if goodInfoSeven.ID == 0 {
  3472. tx.Rollback()
  3473. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3474. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3475. return
  3476. }
  3477. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3478. if goodInfoOne.SumCount == 0 {
  3479. tx.Rollback()
  3480. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3481. return
  3482. }
  3483. }
  3484. }
  3485. }
  3486. //查询保存耗材出库开关是否打开
  3487. if p.PatientId != 30038 {
  3488. if goodOutConfig.IsOpen == 1 {
  3489. //耗材出库
  3490. if p.Type == 3 {
  3491. //对比当前数据和历史出库数据
  3492. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3493. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3494. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3495. //fmt.Println("p----------------------------------------------------", p.ProjectId)
  3496. //fmt.Println("p----------------------------------------------------", nowCount)
  3497. //fmt.Println("p----------------------------------------------------", historyCount)
  3498. //如果当前处方数量大于历史数据,则需要出库
  3499. if nowCount > historyCount {
  3500. var cha_count int64
  3501. cha_count = nowCount - historyCount
  3502. timeStr := time.Now().Format("2006-01-02")
  3503. timeArr := strings.Split(timeStr, "-")
  3504. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3505. total = total + 1
  3506. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3507. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3508. number = number + total
  3509. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3510. operation_time := time.Now().Unix()
  3511. creater := c.GetAdminUserInfo().AdminUser.Id
  3512. recordDateStr := time.Now().Format("2006-01-02")
  3513. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3514. nowtime := recordDate.Unix()
  3515. warehouseOut := models.WarehouseOut{
  3516. WarehouseOutOrderNumber: warehousing_out_order,
  3517. OperationTime: operation_time,
  3518. OrgId: adminInfo.CurrentOrgId,
  3519. Creater: creater,
  3520. Ctime: time.Now().Unix(),
  3521. Status: 1,
  3522. WarehouseOutTime: nowtime,
  3523. Type: 1,
  3524. StorehouseId: storeConfig.StorehouseOutInfo,
  3525. IsCheck: 1,
  3526. IsSys: 1,
  3527. }
  3528. //查询是否生成出库单
  3529. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3530. if out.ID == 0 {
  3531. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3532. }
  3533. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3534. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3535. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3536. dialyPrepareOne := models.DialysisBeforePrepare{
  3537. GoodTypeId: goodObj.GoodTypeId,
  3538. GoodId: p.ProjectId,
  3539. PatientId: p.PatientId,
  3540. RecordDate: p.RecordDate,
  3541. UserOrgId: adminInfo.CurrentOrgId,
  3542. Count: cha_count,
  3543. Ctime: time.Now().Unix(),
  3544. Creater: creater,
  3545. Status: 1,
  3546. StorehouseId: houseConfig.StorehouseOutInfo,
  3547. ProjectId: p.ID,
  3548. }
  3549. //出库
  3550. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3551. }
  3552. //如果当前处方数量小于历史数据,怎需要退库
  3553. if nowCount < historyCount {
  3554. var cha_count int64
  3555. cha_count = historyCount - nowCount
  3556. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3557. creater := c.GetAdminUserInfo().AdminUser.Id
  3558. newPrescriptionProject := &models.HisPrescriptionProject{
  3559. ID: p.ID,
  3560. ProjectId: p.ProjectId,
  3561. Price: p.Price,
  3562. UserOrgId: p.UserOrgId,
  3563. Status: 1,
  3564. Ctime: time.Now().Unix(),
  3565. Mtime: time.Now().Unix(),
  3566. PatientId: p.PatientId,
  3567. HisPatientId: p.HisPatientId,
  3568. RecordDate: p.RecordDate,
  3569. PrescriptionId: p.PrescriptionId,
  3570. Count: p.Count,
  3571. FeedetlSn: p.FeedetlSn,
  3572. MedListCodg: p.MedListCodg,
  3573. SingleDose: p.SingleDose,
  3574. DeliveryWay: p.DeliveryWay,
  3575. ExecutionFrequency: p.ExecutionFrequency,
  3576. Day: p.Day,
  3577. HisProject: models.HisProject{},
  3578. GoodInfo: models.GoodInfo{},
  3579. Remark: p.Remark,
  3580. Unit: p.Unit,
  3581. Type: p.Type,
  3582. Doctor: p.Doctor,
  3583. ExecutionTime: p.ExecutionTime,
  3584. ExecutionStaff: p.ExecutionStaff,
  3585. ExecutionState: p.ExecutionState,
  3586. CheckTime: p.CheckTime,
  3587. CheckState: p.CheckState,
  3588. Checker: p.Checker,
  3589. StartTime: p.StartTime,
  3590. TeamId: p.TeamId,
  3591. XtHisProjectTeam: models.XtHisProjectTeam{},
  3592. FrequencyType: p.FrequencyType,
  3593. DayCount: p.DayCount,
  3594. WeekDay: p.WeekDay,
  3595. IsCheckTeam: p.IsCheckTeam,
  3596. HisOrderInfo: models.HisOrderInfo{},
  3597. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3598. IsOut: p.IsOut,
  3599. YbSyncStatus: p.YbSyncStatus,
  3600. }
  3601. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3602. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3603. }
  3604. if nowCount == historyCount {
  3605. if historyCount == 0 {
  3606. recordDateStr := time.Now().Format("2006-01-02")
  3607. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3608. nowtime := recordDate.Unix()
  3609. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3610. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3611. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3612. creater := c.GetAdminUserInfo().AdminUser.Id
  3613. dialyPrepareOne := models.DialysisBeforePrepare{
  3614. GoodTypeId: goodObj.GoodTypeId,
  3615. GoodId: p.ProjectId,
  3616. PatientId: p.PatientId,
  3617. RecordDate: p.RecordDate,
  3618. UserOrgId: adminInfo.CurrentOrgId,
  3619. Count: nowCount,
  3620. Ctime: time.Now().Unix(),
  3621. Creater: creater,
  3622. Status: 1,
  3623. StorehouseId: houseConfig.StorehouseOutInfo,
  3624. ProjectId: p.ID,
  3625. }
  3626. //出库
  3627. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3628. }
  3629. }
  3630. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3631. //查询历史出库数据
  3632. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3633. var out_count_five int64
  3634. for _, item := range flowGood {
  3635. out_count_five += item.Count
  3636. }
  3637. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3638. //fmt.Println("p.ProjectId-----------------", p.ProjectId)
  3639. //fmt.Println("out_count_five===============", out_count_five)
  3640. //fmt.Println("parseIntCount===============", parseIntCount)
  3641. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3642. if out_count_five != parseIntCount {
  3643. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3644. detail := models.AutomaticReduceDetail{
  3645. WarehouseOutId: 0,
  3646. WarehouseOutOrderNumber: "",
  3647. PatientId: p.PatientId,
  3648. Ctime: time.Now().Unix(),
  3649. Mtime: 0,
  3650. Status: 1,
  3651. RecordTime: p.RecordDate,
  3652. OrgId: p.UserOrgId,
  3653. GoodId: p.ProjectId,
  3654. GoodTypeId: 0,
  3655. Count: parseIntCount,
  3656. Type: 0,
  3657. ProjectId: lastHisProject.ID,
  3658. StorehouseId: 0,
  3659. }
  3660. service.CreateNewAutoDetail(detail, tx)
  3661. }
  3662. // //查询耗材最后一次出库记录
  3663. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3664. // //查询默认出库仓库库存
  3665. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3666. // if len(wareOut) > 0 {
  3667. //
  3668. // for _, it := range wareOut {
  3669. // //回退库存
  3670. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3671. //
  3672. // //删除出库记录
  3673. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3674. //
  3675. // }
  3676. // }
  3677. //
  3678. // timeStr := time.Now().Format("2006-01-02")
  3679. // timeArr := strings.Split(timeStr, "-")
  3680. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3681. //
  3682. // total = total + 1
  3683. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3684. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3685. // number = number + total
  3686. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3687. //
  3688. // operation_time := time.Now().Unix()
  3689. // creater := c.GetAdminUserInfo().AdminUser.Id
  3690. //
  3691. // recordDateStr := time.Now().Format("2006-01-02")
  3692. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3693. // nowtime := recordDate.Unix()
  3694. // warehouseOut := models.WarehouseOut{
  3695. // WarehouseOutOrderNumber: warehousing_out_order,
  3696. // OperationTime: operation_time,
  3697. // OrgId: adminInfo.CurrentOrgId,
  3698. // Creater: creater,
  3699. // Ctime: time.Now().Unix(),
  3700. // Status: 1,
  3701. // WarehouseOutTime: nowtime,
  3702. // Type: 1,
  3703. // StorehouseId: storeConfig.StorehouseOutInfo,
  3704. // IsCheck: 1,
  3705. // IsSys: 1,
  3706. // }
  3707. // //查询是否生成出库单
  3708. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3709. // if out.ID == 0 {
  3710. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3711. // }
  3712. //
  3713. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3714. //
  3715. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3716. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3717. //
  3718. // dialyPrepareOne := models.DialysisBeforePrepare{
  3719. // GoodTypeId: goodObj.GoodTypeId,
  3720. // GoodId: p.ProjectId,
  3721. // PatientId: p.PatientId,
  3722. // RecordDate: p.RecordDate,
  3723. // UserOrgId: adminInfo.CurrentOrgId,
  3724. // Count: parseIntCount,
  3725. // Ctime: time.Now().Unix(),
  3726. // Creater: creater,
  3727. // Status: 1,
  3728. // StorehouseId: houseConfig.StorehouseOutInfo,
  3729. // ProjectId: lastHisProject.ID,
  3730. // }
  3731. // //判断是否是零用耗材(非零用)
  3732. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3733. //
  3734. // //查询历史出库数据
  3735. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3736. // var out_count int64
  3737. // for _, item := range flowGood {
  3738. // out_count += item.Count
  3739. // }
  3740. // //如果历史数和当前数据不想等才进行退库出库
  3741. // if out_count != parseIntCount {
  3742. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3743. //
  3744. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3745. // detail := models.AutomaticReduceDetail{
  3746. // WarehouseOutId: 0,
  3747. // WarehouseOutOrderNumber: "",
  3748. // PatientId: p.PatientId,
  3749. // Ctime: time.Now().Unix(),
  3750. // Mtime: 0,
  3751. // Status: 1,
  3752. // RecordTime: p.RecordDate,
  3753. // OrgId: p.UserOrgId,
  3754. // GoodId: p.ProjectId,
  3755. // GoodTypeId: 0,
  3756. // Count: parseIntCount,
  3757. // Type: 0,
  3758. // ProjectId: lastHisProject.ID,
  3759. // StorehouseId: 0,
  3760. // }
  3761. //
  3762. // service.CreateNewAutoDetail(detail, tx)
  3763. //
  3764. // //查询剩余库存
  3765. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3766. // var sum_count int64
  3767. // for _, item := range goodList {
  3768. // sum_count += item.StockCount
  3769. // }
  3770. //
  3771. // //更新剩余库存
  3772. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3773. //
  3774. // //耗材
  3775. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3776. //
  3777. // }
  3778. // //判断是否是零用耗材(零用但是是出库耗材)
  3779. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3780. //
  3781. // //查询历史出库数据
  3782. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3783. // var out_count int64
  3784. // for _, item := range flowGood {
  3785. // out_count += item.Count
  3786. // }
  3787. // //如果历史数和当前数据不想等才进行退库出库
  3788. // if out_count != parseIntCount {
  3789. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3790. //
  3791. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3792. // detail := models.AutomaticReduceDetail{
  3793. // WarehouseOutId: 0,
  3794. // WarehouseOutOrderNumber: "",
  3795. // PatientId: p.PatientId,
  3796. // Ctime: time.Now().Unix(),
  3797. // Mtime: 0,
  3798. // Status: 1,
  3799. // RecordTime: p.RecordDate,
  3800. // OrgId: p.UserOrgId,
  3801. // GoodId: p.ProjectId,
  3802. // GoodTypeId: 0,
  3803. // Count: parseIntCount,
  3804. // Type: 0,
  3805. // ProjectId: p.ID,
  3806. // StorehouseId: 0,
  3807. // }
  3808. //
  3809. // service.CreateNewAutoDetail(detail, tx)
  3810. //
  3811. // //查询剩余库存
  3812. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3813. // var sum_count int64
  3814. // for _, item := range goodList {
  3815. // sum_count += item.StockCount
  3816. // }
  3817. //
  3818. // //更新剩余库存
  3819. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3820. //
  3821. // //耗材
  3822. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3823. // }
  3824. //
  3825. // }
  3826. //
  3827. // }
  3828. //
  3829. //}
  3830. //记录日志
  3831. byterequest, _ := json.Marshal(p)
  3832. adviceLog := models.XtDoctorAdviceLog{
  3833. UserOrgId: p.UserOrgId,
  3834. PatientId: p.PatientId,
  3835. AdminUserId: adminInfo.AdminUser.Id,
  3836. Module: 1,
  3837. ErrLog: string(byterequest),
  3838. Status: 1,
  3839. Ctime: time.Now().Unix(),
  3840. Mtime: 0,
  3841. Source: "电脑端新建his项目",
  3842. RecordDate: p.RecordDate,
  3843. }
  3844. service.CreateDoctorAdviceLog(adviceLog)
  3845. projectList = append(projectList, p)
  3846. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3847. //新增或者编辑项目,修改对应的标签数据
  3848. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3849. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3850. var label models.HisLabelPrintInfo
  3851. project, _ := service.GetProjectDetail(p.ProjectId)
  3852. if project.CostClassify == 3 { //类别为检验检查
  3853. if p.TeamId > 0 { //检验检查组套
  3854. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3855. if tempLabel.ID == 0 {
  3856. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3857. label.Number = tempPrescription.PrescriptionNumber
  3858. label.ProjectId = project.ID
  3859. label.Status = 1
  3860. label.IsPrint = 2
  3861. label.DoctorId = info.DoctorId
  3862. label.UserOrgId = p.UserOrgId
  3863. label.PatientId = patient_id
  3864. label.RecordDate = recordDateTime
  3865. label.Ctime = time.Now().Unix()
  3866. label.Mtime = time.Now().Unix()
  3867. label.ItemId = p.TeamId
  3868. label.FeedetlSn = p.FeedetlSn
  3869. label.PProjectId = p.ID
  3870. label.ProjectName = team.ProjectTeam
  3871. label.PatientName = patient.Name
  3872. service.CreateNewHisLabelRecord(&label, tx)
  3873. }
  3874. } else { //单条检验检查项目
  3875. label.Number = tempPrescription.PrescriptionNumber
  3876. label.ProjectId = project.ID
  3877. label.Status = 1
  3878. label.DoctorId = info.DoctorId
  3879. label.UserOrgId = p.UserOrgId
  3880. label.PatientId = patient_id
  3881. label.RecordDate = recordDateTime
  3882. label.IsPrint = 2
  3883. label.Ctime = time.Now().Unix()
  3884. label.Mtime = time.Now().Unix()
  3885. label.FeedetlSn = p.FeedetlSn
  3886. label.PProjectId = p.ID
  3887. label.ItemId = p.TeamId
  3888. label.ProjectName = project.ProjectName
  3889. label.PatientName = patient.Name
  3890. service.CreateNewHisLabelRecord(&label, tx)
  3891. }
  3892. }
  3893. }
  3894. }
  3895. }
  3896. }
  3897. }
  3898. //插入检验数据
  3899. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3900. //新增或者编辑项目,修改对应的标签数据
  3901. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3902. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3903. var label models.HisLabelPrintInfo
  3904. project, _ := service.GetProjectDetail(p.ProjectId)
  3905. if project.CostClassify == 3 { //类别为检验检查
  3906. if p.TeamId > 0 { //检验检查组套
  3907. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3908. if tempLabel.ID == 0 {
  3909. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3910. label.Number = tempPrescription.PrescriptionNumber
  3911. label.ProjectId = project.ID
  3912. label.Status = 1
  3913. label.IsPrint = 2
  3914. label.DoctorId = info.DoctorId
  3915. label.UserOrgId = p.UserOrgId
  3916. label.PatientId = patient_id
  3917. label.RecordDate = recordDateTime
  3918. label.Ctime = time.Now().Unix()
  3919. label.Mtime = time.Now().Unix()
  3920. label.ItemId = p.TeamId
  3921. label.FeedetlSn = p.FeedetlSn
  3922. label.PProjectId = p.ID
  3923. label.ProjectName = team.ProjectTeam
  3924. label.PatientName = patient.Name
  3925. service.CreateHisLabelRecord(&label)
  3926. }
  3927. } else { //单条检验检查项目
  3928. label.Number = tempPrescription.PrescriptionNumber
  3929. label.ProjectId = project.ID
  3930. label.Status = 1
  3931. label.DoctorId = info.DoctorId
  3932. label.UserOrgId = p.UserOrgId
  3933. label.PatientId = patient_id
  3934. label.RecordDate = recordDateTime
  3935. label.IsPrint = 2
  3936. label.Ctime = time.Now().Unix()
  3937. label.Mtime = time.Now().Unix()
  3938. label.FeedetlSn = p.FeedetlSn
  3939. label.PProjectId = p.ID
  3940. label.ItemId = p.TeamId
  3941. label.ProjectName = project.ProjectName
  3942. label.PatientName = patient.Name
  3943. service.CreateHisLabelRecord(&label)
  3944. }
  3945. }
  3946. }
  3947. }
  3948. service.CreateNewHisProjectTwo(&p, tx)
  3949. var randNum int
  3950. randNum = rand.Intn(10000) + 1000
  3951. timestamp := time.Now().Unix()
  3952. tempTime := time.Unix(timestamp, 0)
  3953. timeFormat := tempTime.Format("20060102150405")
  3954. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3955. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  3956. if goodBase.ID > 0 {
  3957. tx.Rollback()
  3958. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  3959. return
  3960. }
  3961. service.CreateNewHisProjectTwo(&p, tx)
  3962. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3963. //查询剩余库存
  3964. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3965. var sum_count int64
  3966. for _, item := range goodList {
  3967. sum_count += item.StockCount
  3968. }
  3969. //更新剩余库存
  3970. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3971. //耗材
  3972. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3973. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3974. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3975. if len(outInfoTwo) > 0 {
  3976. for _, item := range outInfoTwo {
  3977. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3978. }
  3979. }
  3980. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3981. if len(drugAutoDetail) > 0 {
  3982. for _, item := range drugAutoDetail {
  3983. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  3984. }
  3985. }
  3986. tx.Commit()
  3987. }
  3988. }
  3989. }
  3990. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3991. // addition := items["addition"].([]interface{})
  3992. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3993. // ctime := time.Now().Unix()
  3994. // mtime := ctime
  3995. // if len(addition) > 0 {
  3996. // for _, item := range addition {
  3997. // var s models.HisAdditionalCharge
  3998. // s.PrescriptionId = tempPrescription.ID
  3999. // s.Status = 1
  4000. // s.UserOrgId = adminInfo.CurrentOrgId
  4001. // s.RecordDate = recordDateTime
  4002. // s.CreatedTime = ctime
  4003. // s.UpdatedTime = mtime
  4004. // s.PatientId = patient_id
  4005. // s.HisPatientId = his_patient_id
  4006. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4007. // if errcode > 0 {
  4008. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4009. // return
  4010. // }
  4011. // service.CreateAdditionalCharge(&s)
  4012. // var randNum int
  4013. // randNum = rand.Intn(10000) + 1000
  4014. // timestamp := time.Now().Unix()
  4015. // tempTime := time.Unix(timestamp, 0)
  4016. // timeFormat := tempTime.Format("20060102150405")
  4017. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4018. // service.CreateAdditionalCharge(&s)
  4019. //
  4020. // }
  4021. // }
  4022. //}
  4023. }
  4024. }
  4025. }
  4026. tx.Commit()
  4027. if err == nil {
  4028. c.ServeSuccessJSON(map[string]interface{}{
  4029. "msg": "保存成功",
  4030. })
  4031. return
  4032. } else {
  4033. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4034. return
  4035. }
  4036. } else {
  4037. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4038. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4039. var tempPrescription *models.HisPrescription
  4040. if len(prescriptions) > 0 {
  4041. for _, item := range prescriptions {
  4042. items := item.(map[string]interface{})
  4043. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4044. utils.ErrorLog("id")
  4045. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4046. return
  4047. }
  4048. id := int64(items["id"].(float64))
  4049. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  4050. tempPrescription = &new_prescription
  4051. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4052. utils.ErrorLog("type")
  4053. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4054. return
  4055. }
  4056. types := int64(items["type"].(float64))
  4057. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4058. utils.ErrorLog("med_type")
  4059. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4060. return
  4061. }
  4062. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4063. if med_type == "0" {
  4064. med_type = "14"
  4065. }
  4066. //if order_status == 0 {
  4067. // order_status = 1
  4068. //}
  4069. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  4070. utils.ErrorLog("pre_time")
  4071. }
  4072. preTime, _ := items["pre_time"].(string)
  4073. timeLayout := "2006-01-02"
  4074. loc, _ := time.LoadLocation("Local")
  4075. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  4076. //result := strings.Split(preTime, " ")
  4077. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4078. if err != nil {
  4079. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4080. return
  4081. }
  4082. pTime := theTime2.Unix()
  4083. ctime := time.Now().Unix()
  4084. if tempPrescription.ID == 0 {
  4085. prescription := &models.HisPrescription{
  4086. ID: 0,
  4087. PatientId: patient_id,
  4088. UserOrgId: adminInfo.CurrentOrgId,
  4089. RecordDate: recordDateTime,
  4090. Ctime: ctime,
  4091. Mtime: ctime,
  4092. Type: types,
  4093. Modifier: adminInfo.AdminUser.Id,
  4094. Creator: adminInfo.AdminUser.Id,
  4095. Status: 1,
  4096. Doctor: role.UserName,
  4097. HisPatientId: his_patient_id,
  4098. OrderStatus: 1,
  4099. BatchNumber: "",
  4100. PrescriptionNumber: hpInfo.PrescriptionNumber,
  4101. PreTime: pTime,
  4102. PType: p_type,
  4103. MedType: med_type,
  4104. }
  4105. tempPrescription = prescription
  4106. service.SaveHisPrescription(tempPrescription)
  4107. redis := service.RedisClient()
  4108. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4109. redis.Set(key, "", time.Second)
  4110. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4111. redis.Set(keyOne, "", time.Second)
  4112. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4113. redis.Set(keySeven, "", time.Second)
  4114. defer redis.Close()
  4115. } else {
  4116. tempPrescription.ID = id
  4117. tempPrescription.Type = types
  4118. tempPrescription.Modifier = adminInfo.AdminUser.Id
  4119. tempPrescription.Mtime = time.Now().Unix()
  4120. tempPrescription.Doctor = role.UserName
  4121. //tempPrescription.OrderStatus = order_status
  4122. tempPrescription.PreTime = pTime
  4123. tempPrescription.MedType = med_type
  4124. service.SaveHisPrescription(tempPrescription)
  4125. redis := service.RedisClient()
  4126. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4127. redis.Set(key, "", time.Second)
  4128. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4129. redis.Set(keyOne, "", time.Second)
  4130. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4131. redis.Set(keySeven, "", time.Second)
  4132. defer redis.Close()
  4133. }
  4134. //service.SaveHisPrescription(prescription)
  4135. //更改患者挂号状态
  4136. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4137. fmt.Println("更改失败", err2)
  4138. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4139. advices := items["advices"].([]interface{})
  4140. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4141. groupNo := int64(0)
  4142. if len(advices) > 0 {
  4143. for _, advice := range advices {
  4144. var s models.HisDoctorAdviceInfo
  4145. s.PrescriptionId = tempPrescription.ID
  4146. s.AdviceType = 2
  4147. s.AdviceDoctor = doctor_id
  4148. s.StopState = 2
  4149. s.ExecutionState = 2
  4150. s.AdviceDate = theTime3.Unix()
  4151. s.Status = 1
  4152. s.UserOrgId = adminInfo.CurrentOrgId
  4153. s.RecordDate = theTime3.Unix()
  4154. s.StartTime = tempPrescription.PreTime
  4155. s.Groupno = groupNo
  4156. s.PatientId = patient_id
  4157. s.HisPatientId = his_patient_id
  4158. s.StartTime = pTime
  4159. s.IsSettle = 2
  4160. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  4161. if errcode > 0 {
  4162. c.ServeFailJSONWithSGJErrorCode(errcode)
  4163. return
  4164. }
  4165. s.StartTime = pTime
  4166. var total_count int64 //处方总库存
  4167. //查询改药品信息
  4168. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  4169. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  4170. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  4171. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  4172. total_count += prescribingNumberSeven * medical.MinNumber
  4173. }
  4174. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  4175. total_count += prescribingNumberSeven
  4176. }
  4177. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  4178. total_count += prescribingNumberSeven
  4179. }
  4180. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4181. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4182. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4183. if s.Price != lastWarehouse.RetailPrice {
  4184. s.Price = lastWarehouse.RetailPrice
  4185. }
  4186. if s.Price == 0 {
  4187. if lastWarehouse.ID == 0 {
  4188. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  4189. s.Price = lastWarehouseTwo.RetailPrice
  4190. }
  4191. }
  4192. }
  4193. if adminInfo.CurrentOrgId != 10206 {
  4194. if s.ID == 0 {
  4195. //查询改药品是否已经停用
  4196. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  4197. if base.ID > 0 {
  4198. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  4199. return
  4200. }
  4201. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  4202. if drugMedical.SumCount == 0 {
  4203. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  4204. return
  4205. }
  4206. }
  4207. }
  4208. //赤峰
  4209. if s.UserOrgId == 10265 || s.UserOrgId == 10489 {
  4210. drug, _ := service.GetDrugByGoodId(s.DrugId)
  4211. info, _ := service.GetWarehoseInfoByDrugId(s.DrugId, s.UserOrgId)
  4212. if info.RetailPrice > 0 {
  4213. if s.DeliveryWay == "口服" {
  4214. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4215. s.Price = drug.RetailPrice
  4216. }
  4217. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4218. s.Price = info.RetailPrice
  4219. }
  4220. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4221. s.Price = info.RetailPrice
  4222. }
  4223. }
  4224. }
  4225. }
  4226. service.CreateHisDoctorAdvice(&s)
  4227. //记录日志
  4228. byterequest, _ := json.Marshal(s)
  4229. adviceLog := models.XtDoctorAdviceLog{
  4230. UserOrgId: s.UserOrgId,
  4231. PatientId: s.PatientId,
  4232. AdminUserId: adminInfo.AdminUser.Id,
  4233. Module: 1,
  4234. ErrLog: string(byterequest),
  4235. Status: 1,
  4236. Ctime: time.Now().Unix(),
  4237. Mtime: 0,
  4238. Source: "电脑端新建his医嘱",
  4239. RecordDate: s.AdviceDate,
  4240. }
  4241. service.CreateDoctorAdviceLog(adviceLog)
  4242. //存储切片中
  4243. adviceList = append(adviceList, s)
  4244. redis := service.RedisClient()
  4245. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4246. redis.Set(key, "", time.Second)
  4247. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4248. redis.Set(keyOne, "", time.Second)
  4249. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4250. redis.Set(keySeven, "", time.Second)
  4251. var randNum int
  4252. randNum = rand.Intn(10000) + 1000
  4253. timestamp := time.Now().Unix()
  4254. tempTime := time.Unix(timestamp, 0)
  4255. timeFormat := tempTime.Format("20060102150405")
  4256. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  4257. service.CreateHisDoctorAdvice(&s)
  4258. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4259. redis.Set(keySix, "", time.Second)
  4260. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4261. redis.Set(keyFive, "", time.Second)
  4262. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4263. redis.Set(keyEight, "", time.Second)
  4264. defer redis.Close()
  4265. }
  4266. }
  4267. }
  4268. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4269. projects := items["project"].([]interface{})
  4270. if len(projects) > 0 {
  4271. for _, project := range projects {
  4272. var p models.HisPrescriptionProject
  4273. p.PrescriptionId = tempPrescription.ID
  4274. p.PatientId = patient_id
  4275. p.RecordDate = theTime3.Unix()
  4276. p.Doctor = doctor_id
  4277. p.UserOrgId = adminInfo.CurrentOrgId
  4278. p.HisPatientId = his_patient_id
  4279. p.Status = 1
  4280. p.StartTime = pTime
  4281. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  4282. if errcode > 0 {
  4283. c.ServeFailJSONWithSGJErrorCode(errcode)
  4284. return
  4285. }
  4286. if p.ID == 0 {
  4287. p.IsOut = 2
  4288. }
  4289. if p.ID > 0 {
  4290. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  4291. p.IsOut = projectDetail.IsOut
  4292. }
  4293. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4294. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4295. if p.Type == 3 {
  4296. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  4297. if p.Price != lastWarehouse.PackingPrice {
  4298. p.Price = lastWarehouse.PackingPrice
  4299. }
  4300. if p.Price == 0 {
  4301. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  4302. p.Price = lastWarehouseTwo.PackingPrice
  4303. }
  4304. if p.Unit == "" {
  4305. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4306. p.Unit = goodInfoOne.PackingUnit
  4307. }
  4308. }
  4309. }
  4310. if adminInfo.CurrentOrgId != 10206 {
  4311. if p.Type == 3 {
  4312. if p.ID == 0 {
  4313. //查询该耗材是否停用
  4314. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  4315. //表示该耗材已经停用,不能保存
  4316. if goodInfoSeven.ID == 0 {
  4317. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4318. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  4319. return
  4320. }
  4321. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4322. if goodInfoOne.SumCount == 0 {
  4323. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  4324. return
  4325. }
  4326. }
  4327. }
  4328. }
  4329. service.CreateHisProjectTwo(&p)
  4330. //记录日志
  4331. byterequest, _ := json.Marshal(p)
  4332. adviceLog := models.XtDoctorAdviceLog{
  4333. UserOrgId: p.UserOrgId,
  4334. PatientId: p.PatientId,
  4335. AdminUserId: adminInfo.AdminUser.Id,
  4336. Module: 1,
  4337. ErrLog: string(byterequest),
  4338. Status: 1,
  4339. Ctime: time.Now().Unix(),
  4340. Mtime: 0,
  4341. Source: "电脑端新建his项目",
  4342. RecordDate: p.RecordDate,
  4343. }
  4344. service.CreateDoctorAdviceLog(adviceLog)
  4345. projectList = append(projectList, p)
  4346. var randNum int
  4347. randNum = rand.Intn(10000) + 1000
  4348. timestamp := time.Now().Unix()
  4349. tempTime := time.Unix(timestamp, 0)
  4350. timeFormat := tempTime.Format("20060102150405")
  4351. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4352. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4353. //新增或者编辑项目,修改对应的标签数据
  4354. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4355. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4356. var label models.HisLabelPrintInfo
  4357. project, _ := service.GetProjectDetail(p.ProjectId)
  4358. if project.CostClassify == 3 { //类别为检验检查
  4359. if p.TeamId > 0 { //检验检查组套
  4360. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4361. if tempLabel.ID == 0 {
  4362. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4363. label.Number = tempPrescription.PrescriptionNumber
  4364. label.ProjectId = project.ID
  4365. label.Status = 1
  4366. label.IsPrint = 2
  4367. label.DoctorId = info.DoctorId
  4368. label.UserOrgId = p.UserOrgId
  4369. label.PatientId = patient_id
  4370. label.RecordDate = recordDateTime
  4371. label.Ctime = time.Now().Unix()
  4372. label.Mtime = time.Now().Unix()
  4373. label.ItemId = p.TeamId
  4374. label.FeedetlSn = p.FeedetlSn
  4375. label.PProjectId = p.ID
  4376. label.ProjectName = team.ProjectTeam
  4377. label.PatientName = patient.Name
  4378. service.CreateHisLabelRecord(&label)
  4379. }
  4380. } else { //单条检验检查项目
  4381. label.Number = tempPrescription.PrescriptionNumber
  4382. label.ProjectId = project.ID
  4383. label.Status = 1
  4384. label.DoctorId = info.DoctorId
  4385. label.UserOrgId = p.UserOrgId
  4386. label.PatientId = patient_id
  4387. label.RecordDate = recordDateTime
  4388. label.IsPrint = 2
  4389. label.Ctime = time.Now().Unix()
  4390. label.Mtime = time.Now().Unix()
  4391. label.FeedetlSn = p.FeedetlSn
  4392. label.PProjectId = p.ID
  4393. label.ItemId = p.TeamId
  4394. label.ProjectName = project.ProjectName
  4395. label.PatientName = patient.Name
  4396. service.CreateHisLabelRecord(&label)
  4397. }
  4398. }
  4399. }
  4400. }
  4401. service.SaveHisProjectTwo(&p)
  4402. }
  4403. }
  4404. }
  4405. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4406. // addition := items["addition"].([]interface{})
  4407. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4408. // ctime := time.Now().Unix()
  4409. // mtime := ctime
  4410. // if len(addition) > 0 {
  4411. // for _, item := range addition {
  4412. // var s models.HisAdditionalCharge
  4413. // s.PrescriptionId = tempPrescription.ID
  4414. // s.Status = 1
  4415. // s.UserOrgId = adminInfo.CurrentOrgId
  4416. // s.RecordDate = recordDateTime
  4417. // s.CreatedTime = ctime
  4418. // s.UpdatedTime = mtime
  4419. // s.PatientId = patient_id
  4420. // s.HisPatientId = his_patient_id
  4421. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4422. // if errcode > 0 {
  4423. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4424. // return
  4425. // }
  4426. // service.CreateAdditionalCharge(&s)
  4427. // var randNum int
  4428. // randNum = rand.Intn(10000) + 1000
  4429. // timestamp := time.Now().Unix()
  4430. // tempTime := time.Unix(timestamp, 0)
  4431. // timeFormat := tempTime.Format("20060102150405")
  4432. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4433. // service.CreateAdditionalCharge(&s)
  4434. //
  4435. // }
  4436. // }
  4437. //}
  4438. }
  4439. }
  4440. //查询今日该患者开的药品处方
  4441. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4442. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  4443. //药品出库
  4444. if drugOutConfig.IsOpen == 1 {
  4445. for _, item := range hisdoctorlist {
  4446. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  4447. // 查询该药品最后一次出库记录
  4448. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  4449. if len(druginfo) > 0 {
  4450. //回退库存
  4451. for _, it := range druginfo {
  4452. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4453. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4454. }
  4455. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4456. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4457. }
  4458. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4459. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4460. }
  4461. }
  4462. }
  4463. //删除记录
  4464. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4465. //查询最后一次数据
  4466. if drugOutConfig.IsOpen == 1 {
  4467. //出库
  4468. if drug.IsUse == 2 {
  4469. creater := adminInfo.AdminUser.Id
  4470. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4471. }
  4472. //更新字典里面的库存
  4473. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4474. var sum_count int64
  4475. for _, its := range stockInfo {
  4476. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4477. if its.MaxUnit == baseDrug.MaxUnit {
  4478. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4479. }
  4480. sum_count += its.StockMaxNumber + its.StockMinNumber
  4481. }
  4482. //更新基础库存
  4483. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4484. //剩余库存
  4485. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4486. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4487. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4488. }
  4489. }
  4490. }
  4491. //耗材保存处方出库
  4492. if goodOutConfig.IsOpen == 1 {
  4493. //查询今日耗材出库数量
  4494. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4495. for _, item := range hisgoodlist {
  4496. //查询历史出库数据
  4497. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4498. var out_count_five int64
  4499. for _, item := range flowGood {
  4500. out_count_five += item.Count
  4501. }
  4502. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  4503. if out_count_five != parseIntCount {
  4504. //查询耗材最后一次出库记录
  4505. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  4506. //查询默认出库仓库库存
  4507. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4508. if len(wareOut) > 0 {
  4509. for _, it := range wareOut {
  4510. //回退库存
  4511. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4512. //删除出库记录
  4513. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4514. }
  4515. }
  4516. timeStr := time.Now().Format("2006-01-02")
  4517. timeArr := strings.Split(timeStr, "-")
  4518. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4519. total = total + 1
  4520. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4521. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4522. number = number + total
  4523. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4524. operation_time := time.Now().Unix()
  4525. creater := c.GetAdminUserInfo().AdminUser.Id
  4526. recordDateStr := time.Now().Format("2006-01-02")
  4527. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4528. nowtime := recordDate.Unix()
  4529. warehouseOut := models.WarehouseOut{
  4530. WarehouseOutOrderNumber: warehousing_out_order,
  4531. OperationTime: operation_time,
  4532. OrgId: adminInfo.CurrentOrgId,
  4533. Creater: creater,
  4534. Ctime: time.Now().Unix(),
  4535. Status: 1,
  4536. WarehouseOutTime: nowtime,
  4537. Type: 1,
  4538. StorehouseId: storeConfig.StorehouseOutInfo,
  4539. IsCheck: 1,
  4540. IsSys: 1,
  4541. }
  4542. //查询是否生成出库单
  4543. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4544. if out.ID == 0 {
  4545. service.AddSigleWarehouseOut(&warehouseOut)
  4546. }
  4547. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4548. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4549. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4550. dialyPrepareOne := models.DialysisBeforePrepare{
  4551. GoodTypeId: goodObj.GoodTypeId,
  4552. GoodId: item.ProjectId,
  4553. PatientId: item.PatientId,
  4554. RecordDate: item.RecordDate,
  4555. UserOrgId: adminInfo.CurrentOrgId,
  4556. Count: parseIntCount,
  4557. Ctime: time.Now().Unix(),
  4558. Creater: creater,
  4559. Status: 1,
  4560. StorehouseId: houseConfig.StorehouseOutInfo,
  4561. ProjectId: item.ID,
  4562. }
  4563. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4564. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  4565. //查询历史出库数据
  4566. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4567. var out_count int64
  4568. for _, item := range flowGood {
  4569. out_count += item.Count
  4570. }
  4571. //如果历史数和当前数据不想等才进行退库出库
  4572. if out_count != parseIntCount {
  4573. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4574. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4575. detail := models.AutomaticReduceDetail{
  4576. WarehouseOutId: 0,
  4577. WarehouseOutOrderNumber: "",
  4578. PatientId: item.PatientId,
  4579. Ctime: time.Now().Unix(),
  4580. Mtime: 0,
  4581. Status: 1,
  4582. RecordTime: item.RecordDate,
  4583. OrgId: item.UserOrgId,
  4584. GoodId: item.ProjectId,
  4585. GoodTypeId: 0,
  4586. Count: parseIntCount,
  4587. Type: 0,
  4588. ProjectId: item.ID,
  4589. StorehouseId: 0,
  4590. }
  4591. service.CreateAutoDetail(detail)
  4592. //查询剩余库存
  4593. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4594. var sum_count int64
  4595. for _, item := range goodList {
  4596. sum_count += item.StockCount
  4597. }
  4598. //更新剩余库存
  4599. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4600. //耗材
  4601. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4602. }
  4603. }
  4604. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  4605. //查询历史出库数据
  4606. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4607. var out_count int64
  4608. for _, item := range flowGood {
  4609. out_count += item.Count
  4610. }
  4611. //如果历史数和当前数据不想等才进行退库出库
  4612. if out_count != parseIntCount {
  4613. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4614. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4615. detail := models.AutomaticReduceDetail{
  4616. WarehouseOutId: 0,
  4617. WarehouseOutOrderNumber: "",
  4618. PatientId: item.PatientId,
  4619. Ctime: time.Now().Unix(),
  4620. Mtime: 0,
  4621. Status: 1,
  4622. RecordTime: item.RecordDate,
  4623. OrgId: item.UserOrgId,
  4624. GoodId: item.ProjectId,
  4625. GoodTypeId: 0,
  4626. Count: parseIntCount,
  4627. Type: 0,
  4628. ProjectId: item.ID,
  4629. StorehouseId: 0,
  4630. }
  4631. service.CreateAutoDetail(detail)
  4632. //查询剩余库存
  4633. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4634. var sum_count int64
  4635. for _, item := range goodList {
  4636. sum_count += item.StockCount
  4637. }
  4638. //更新剩余库存
  4639. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4640. //耗材
  4641. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4642. }
  4643. }
  4644. }
  4645. }
  4646. }
  4647. ////同步到自备药
  4648. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  4649. if selfPrescriptionOpen.IsOpen == 1 {
  4650. timeStr := time.Now().Format("2006-01-02")
  4651. timeArr := strings.Split(timeStr, "-")
  4652. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  4653. total = total + 1
  4654. operation_time := time.Now().Unix()
  4655. creater := adminInfo.AdminUser.Id
  4656. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4657. warehousing := models.XtSelfDrugWarehouse{
  4658. WarehousingOrder: warehousing_order,
  4659. OperationTime: operation_time,
  4660. OrgId: adminInfo.CurrentOrgId,
  4661. Creater: creater,
  4662. Ctime: time.Now().Unix(),
  4663. Status: 1,
  4664. WarehousingTime: recordDateTime,
  4665. Type: 0,
  4666. StorehouseId: 0,
  4667. IsCheck: 1,
  4668. PatientId: patient_id,
  4669. IsSys: 1,
  4670. }
  4671. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  4672. if selfDrugWarehouse.ID == 0 {
  4673. service.AddSelfDrugWarehouse(&warehousing, tx)
  4674. }
  4675. if selfDrugWarehouse.ID > 0 {
  4676. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  4677. }
  4678. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  4679. fmt.Println(info)
  4680. for _, item := range hisdoctorlist {
  4681. //查询该病人的该药品是否已经入库
  4682. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  4683. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  4684. var in_count int64
  4685. if len(selfdruginfo) > 0 {
  4686. for _, item := range selfdruginfo {
  4687. var in_count_one int64
  4688. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4689. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  4690. }
  4691. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4692. in_count_one = item.WarehousingCount
  4693. }
  4694. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4695. in_count_one = item.WarehousingCount
  4696. }
  4697. in_count += in_count_one
  4698. }
  4699. }
  4700. if selfBasedrug.IsSelfDrug == 1 {
  4701. var total_count int64
  4702. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  4703. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  4704. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4705. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  4706. }
  4707. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4708. total_count += prescribingNumberSeven
  4709. }
  4710. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4711. total_count += prescribingNumberSeven
  4712. }
  4713. //入库
  4714. if total_count > in_count {
  4715. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  4716. WarehousingOrder: warehousing_order,
  4717. WarehousingId: info.ID,
  4718. DrugId: item.DrugId,
  4719. Number: "",
  4720. ProductDate: 0,
  4721. ExpiryDate: 0,
  4722. WarehousingCount: total_count - in_count,
  4723. WarehouseingUnit: selfBasedrug.MinUnit,
  4724. Price: 0,
  4725. TotalPrice: 0,
  4726. Status: 1,
  4727. Ctime: time.Now().Unix(),
  4728. Remark: "",
  4729. OrgId: adminInfo.CurrentOrgId,
  4730. Type: 0,
  4731. Manufacturer: selfBasedrug.Manufacturer,
  4732. Dealer: selfBasedrug.Dealer,
  4733. StockMaxNumber: total_count - in_count,
  4734. RetailTotalPrice: 0,
  4735. BatchNumber: "",
  4736. MaxUnit: selfBasedrug.MinUnit,
  4737. MinUnit: selfBasedrug.MinUnit,
  4738. RetailPrice: 0,
  4739. StorehouseId: 0,
  4740. IsCheck: 1,
  4741. StockMinNumber: 0,
  4742. PatientId: patient_id,
  4743. IsSys: 1,
  4744. RecordDate: item.RecordDate,
  4745. AdviceId: item.ID,
  4746. }
  4747. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  4748. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  4749. Creator := adminInfo.AdminUser.Id
  4750. //查询默认仓库剩余多少库存
  4751. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  4752. var sum_count int64
  4753. for _, it := range list {
  4754. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  4755. if it.MaxUnit == baseDrug.MaxUnit {
  4756. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  4757. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  4758. }
  4759. sum_count += it.StockMaxNumber + it.StockMinNumber
  4760. }
  4761. flow := &models.XtSelfDrugFlow{
  4762. WarehousingId: info.ID,
  4763. DrugId: item.DrugId,
  4764. Number: "",
  4765. BatchNumber: "",
  4766. Count: total_count - in_count,
  4767. UserOrgId: adminInfo.CurrentOrgId,
  4768. PatientId: item.PatientId,
  4769. SystemTime: time.Now().Unix(),
  4770. ConsumableType: 1,
  4771. IsSys: 1,
  4772. WarehousingOrder: warehousing_order,
  4773. WarehouseOutId: 0,
  4774. WarehouseOutOrderNumber: "",
  4775. IsEdit: 0,
  4776. CancelStockId: 0,
  4777. CancelOrderNumber: "",
  4778. Manufacturer: selfBasedrug.Manufacturer,
  4779. Dealer: selfBasedrug.Dealer,
  4780. Creator: Creator,
  4781. UpdateCreator: Creator,
  4782. Status: 1,
  4783. Ctime: item.AdviceDate,
  4784. Mtime: 0,
  4785. Price: item.Price,
  4786. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  4787. WarehouseOutDetailId: 0,
  4788. CancelOutDetailId: 0,
  4789. ExpireDate: 0,
  4790. ProductDate: 0,
  4791. MaxUnit: selfBasedrug.MinUnit,
  4792. MinUnit: selfBasedrug.MinUnit,
  4793. StorehouseId: 0,
  4794. OverCount: sum_count,
  4795. OperateTime: time.Now().Unix(),
  4796. AdviceId: item.ID,
  4797. }
  4798. service.CreateSelfDrugFlow(flow, tx)
  4799. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  4800. var total_count int64 // 入库总数量
  4801. var over_count int64 //剩余库存
  4802. for _, it := range drugInfolist {
  4803. if it.MaxUnit == selfBasedrug.MaxUnit {
  4804. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  4805. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  4806. }
  4807. }
  4808. for _, it := range drugInfolist {
  4809. total_count += it.WarehousingCount
  4810. over_count += it.StockMaxNumber + it.StockMinNumber
  4811. }
  4812. //查询该仓库是否有默认数据
  4813. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  4814. if selfDrugStock.ID == 0 {
  4815. drugStock := models.XtSelfDrugStockCount{
  4816. UserOrgId: item.UserOrgId,
  4817. PatientId: item.PatientId,
  4818. SumInCount: total_count,
  4819. SumOutCount: 0,
  4820. SumCancelCount: 0,
  4821. DrugId: item.DrugId,
  4822. Ctime: time.Now().Unix(),
  4823. Mtime: 0,
  4824. Status: 1,
  4825. FlushCount: over_count,
  4826. SumActOutCount: 0,
  4827. }
  4828. service.CreateSelfDrugStockSum(drugStock, tx)
  4829. }
  4830. if selfDrugStock.ID > 0 {
  4831. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  4832. }
  4833. }
  4834. //查询这个单据的出库数量
  4835. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  4836. var his_out_count int64
  4837. for _, item := range drugFlowList {
  4838. his_out_count += item.Count
  4839. }
  4840. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  4841. if (total_count + his_out_count) <= in_count {
  4842. // 出库
  4843. if total_count < in_count {
  4844. var cha_count int64
  4845. cha_count = in_count - total_count
  4846. var stock_number int64 = 0
  4847. //查询库存是否充足
  4848. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  4849. // 将该批次的剩余库存数量转换为拆零数量
  4850. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4851. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  4852. }
  4853. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4854. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  4855. }
  4856. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4857. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  4858. }
  4859. if stock_number >= cha_count {
  4860. var maxNumber int64 = 0
  4861. var minNumber int64 = 0
  4862. maxNumber = cha_count / selfBasedrug.MinNumber
  4863. minNumber = cha_count % selfBasedrug.MinNumber
  4864. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4865. minNumber = maxNumber
  4866. }
  4867. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4868. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  4869. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4870. return
  4871. }
  4872. }
  4873. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4874. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  4875. }
  4876. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4877. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  4878. }
  4879. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4880. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  4881. }
  4882. if warehouse.StockMaxNumber < 0 {
  4883. warehouse.StockMaxNumber = 0
  4884. }
  4885. if warehouse.StockMinNumber < 0 {
  4886. warehouse.StockMinNumber = 0
  4887. }
  4888. warehouse.Mtime = time.Now().Unix()
  4889. if warehouse.StockMinNumber < minNumber {
  4890. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  4891. if warehouse.MaxUnit != warehouse.MinUnit {
  4892. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  4893. }
  4894. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  4895. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  4896. }
  4897. } else {
  4898. if minNumber > 0 {
  4899. if (warehouse.StockMinNumber - minNumber) >= 0 {
  4900. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  4901. }
  4902. }
  4903. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  4904. if warehouse.StockMinNumber > 0 {
  4905. if warehouse.StockMinNumber-cha_count >= 0 {
  4906. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  4907. }
  4908. }
  4909. }
  4910. }
  4911. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  4912. if (warehouse.StockMinNumber - cha_count) >= 0 {
  4913. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  4914. }
  4915. }
  4916. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4917. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  4918. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4919. return
  4920. }
  4921. }
  4922. if warehouse.StockMinNumber <= 0 {
  4923. warehouse.StockMinNumber = 0
  4924. }
  4925. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  4926. //查询该药品剩余库存
  4927. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  4928. var over_count int64
  4929. for _, its := range infolist {
  4930. if its.MaxUnit == selfBasedrug.MaxUnit {
  4931. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  4932. }
  4933. over_count += its.StockMaxNumber + its.StockMinNumber
  4934. }
  4935. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  4936. drugflow := models.XtSelfDrugFlow{
  4937. WarehouseOutId: 0,
  4938. WarehouseOutOrderNumber: warehousing_order,
  4939. WarehousingOrder: warehousing_order,
  4940. DrugId: item.DrugId,
  4941. Number: warehouse.Number,
  4942. ProductDate: warehouse.ProductDate,
  4943. ExpireDate: warehouse.ExpiryDate,
  4944. Count: cha_count,
  4945. Price: warehouse.RetailPrice,
  4946. Status: 1,
  4947. Ctime: item.AdviceDate,
  4948. Mtime: time.Now().Unix(),
  4949. UserOrgId: item.UserOrgId,
  4950. Manufacturer: warehouse.Manufacturer,
  4951. Dealer: warehouse.Dealer,
  4952. BatchNumber: warehouse.BatchNumber,
  4953. MaxUnit: selfBasedrug.MinUnit,
  4954. ConsumableType: 20,
  4955. IsEdit: 1,
  4956. Creator: 0,
  4957. IsSys: 3,
  4958. WarehouseOutDetailId: drugWareInfo.ID,
  4959. AdviceId: item.ID,
  4960. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  4961. StorehouseId: 0,
  4962. AdminUserId: creater,
  4963. LastPrice: warehouse.Price,
  4964. StockCount: "",
  4965. WarehousingDetailId: 0,
  4966. OverCount: over_count,
  4967. RetailPrice: item.Price, //手动出库出库价格
  4968. WarehousingId: warehouse.ID,
  4969. SystemTime: item.AdviceDate,
  4970. PatientId: item.PatientId,
  4971. Remark: "保存处方入库数据差",
  4972. OperateTime: time.Now().Unix(),
  4973. }
  4974. if warehouse.RetailPrice == 0 {
  4975. drugflow.Price = item.Price
  4976. }
  4977. service.CreateSelfDrugFlowOne(drugflow, tx)
  4978. var out_count int64
  4979. out_count = in_count - total_count
  4980. //
  4981. //fmt.Println("in_count------------------", in_count)
  4982. //fmt.Println("total_count------------------", total_count)
  4983. //添加出库数量
  4984. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  4985. //查询剩余库存
  4986. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  4987. var sum_count int64
  4988. for _, its := range stockInfo {
  4989. if its.MaxUnit == selfBasedrug.MaxUnit {
  4990. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  4991. }
  4992. sum_count += its.StockMaxNumber + its.StockMinNumber
  4993. }
  4994. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  4995. } else {
  4996. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4997. return
  4998. }
  4999. }
  5000. }
  5001. }
  5002. }
  5003. }
  5004. }
  5005. tx.Commit()
  5006. if err == nil {
  5007. c.ServeSuccessJSON(map[string]interface{}{
  5008. "msg": "保存成功",
  5009. })
  5010. return
  5011. } else {
  5012. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5013. return
  5014. }
  5015. }
  5016. }
  5017. //func (c *HisApiController) EditHisPrescription() {
  5018. // record_date := c.GetString("record_date")
  5019. // patient_id, _ := c.GetInt64("patient_id")
  5020. // reg_type, _ := c.GetInt64("reg_type")
  5021. // //diagnose, _ := c.GetInt64("diagnose", 0)
  5022. // diagnose := c.GetString("diagnose")
  5023. // sick_type, _ := c.GetInt64("sick_type")
  5024. // sick_history := c.GetString("sick_history")
  5025. // doctor_id, _ := c.GetInt64("doctor", 0)
  5026. // department, _ := c.GetInt64("department", 0)
  5027. // his_patient_id, _ := c.GetInt64("his_patient_id")
  5028. // p_type, _ := c.GetInt64("p_type")
  5029. //
  5030. // dataBody := make(map[string]interface{}, 0)
  5031. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5032. // if err != nil {
  5033. // utils.ErrorLog(err.Error())
  5034. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5035. // return
  5036. // }
  5037. //
  5038. // timeLayout := "2006-01-02"
  5039. // loc, _ := time.LoadLocation("Local")
  5040. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5041. // if err != nil {
  5042. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5043. // return
  5044. // }
  5045. // adminInfo := c.GetAdminUserInfo()
  5046. // recordDateTime := theTime.Unix()
  5047. //
  5048. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  5049. //
  5050. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  5051. // var hpInfo models.HisPrescriptionInfo
  5052. // if info.ID == 0 {
  5053. // var randNum int
  5054. // randNum = rand.Intn(10000) + 1000
  5055. // timestamp := time.Now().Unix()
  5056. // tempTime := time.Unix(timestamp, 0)
  5057. // timeFormat := tempTime.Format("20060102150405")
  5058. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  5059. //
  5060. // hpInfo = models.HisPrescriptionInfo{
  5061. // UserOrgId: adminInfo.CurrentOrgId,
  5062. // RecordDate: theTime.Unix(),
  5063. // PatientId: patient_id,
  5064. // Status: 1,
  5065. // Ctime: time.Now().Unix(),
  5066. // Mtime: time.Now().Unix(),
  5067. // Creator: adminInfo.AdminUser.Id,
  5068. // Modifier: adminInfo.AdminUser.Id,
  5069. // Diagnosis: diagnose,
  5070. // SickHistory: sick_history,
  5071. // Departments: department,
  5072. // RegisterType: reg_type,
  5073. // PrescriptionNumber: p_number,
  5074. // PrescriptionStatus: 1,
  5075. // Doctor: role.UserName,
  5076. // DoctorId: doctor_id,
  5077. // SickType: sick_type,
  5078. // PType: p_type,
  5079. // }
  5080. // service.SavePatientPrescriptionInfo(hpInfo)
  5081. //
  5082. // } else {
  5083. // hpInfo = models.HisPrescriptionInfo{
  5084. // ID: info.ID,
  5085. // UserOrgId: adminInfo.CurrentOrgId,
  5086. // RecordDate: info.RecordDate,
  5087. // PatientId: info.PatientId,
  5088. // Status: 1,
  5089. // Ctime: info.Ctime,
  5090. // Mtime: time.Now().Unix(),
  5091. // Creator: info.Creator,
  5092. // Modifier: adminInfo.AdminUser.Id,
  5093. // Diagnosis: diagnose,
  5094. // SickHistory: sick_history,
  5095. // Departments: department,
  5096. // RegisterType: reg_type,
  5097. // PrescriptionNumber: info.PrescriptionNumber,
  5098. // Doctor: role.UserName,
  5099. // PrescriptionStatus: info.PrescriptionStatus,
  5100. // DoctorId: doctor_id,
  5101. // SickType: sick_type,
  5102. // PType: info.PType,
  5103. // }
  5104. // service.SavePatientPrescriptionInfo(hpInfo)
  5105. // }
  5106. //
  5107. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  5108. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  5109. //
  5110. // if len(prescriptions) > 0 {
  5111. // for _, item := range prescriptions {
  5112. // items := item.(map[string]interface{})
  5113. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5114. // utils.ErrorLog("id")
  5115. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5116. // return
  5117. // }
  5118. // id := int64(items["id"].(float64))
  5119. //
  5120. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5121. // utils.ErrorLog("type")
  5122. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5123. // return
  5124. // }
  5125. // types := int64(items["type"].(float64))
  5126. //
  5127. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  5128. // utils.ErrorLog("med_type")
  5129. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5130. // return
  5131. // }
  5132. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  5133. //
  5134. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  5135. //
  5136. // ctime := time.Now().Unix()
  5137. //
  5138. // prescription := &models.HisPrescription{
  5139. // ID: id,
  5140. // PatientId: patient_id,
  5141. // UserOrgId: adminInfo.CurrentOrgId,
  5142. // RecordDate: recordDateTime,
  5143. // Ctime: ctime,
  5144. // Mtime: ctime,
  5145. // Type: types,
  5146. // Modifier: adminInfo.AdminUser.Id,
  5147. // Creator: adminInfo.AdminUser.Id,
  5148. // Status: 1,
  5149. // Doctor: role.UserName,
  5150. // HisPatientId: his_patient_id,
  5151. // OrderStatus: 1,
  5152. // BatchNumber: "",
  5153. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  5154. // PType: hpInfo.PType,
  5155. // MedType: med_type,
  5156. // }
  5157. //
  5158. // if historyPrescription.ID > 0 {
  5159. // prescription.PreTime = historyPrescription.PreTime
  5160. //
  5161. // }
  5162. //
  5163. // service.SaveHisPrescription(prescription)
  5164. //
  5165. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  5166. // advices := items["advices"].([]interface{})
  5167. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5168. // groupNo := int64(0)
  5169. // ctime := time.Now().Unix()
  5170. // mtime := ctime
  5171. // if len(advices) > 0 {
  5172. // for _, advice := range advices {
  5173. // var s models.HisDoctorAdviceInfo
  5174. // s.PrescriptionId = prescription.ID
  5175. // s.AdviceType = 2
  5176. // s.AdviceDoctor = adminInfo.AdminUser.Id
  5177. // s.StopState = 2
  5178. // s.ExecutionState = 2
  5179. // s.AdviceDate = recordDateTime
  5180. // s.Status = 1
  5181. // s.UserOrgId = adminInfo.CurrentOrgId
  5182. // s.RecordDate = recordDateTime
  5183. // s.StartTime = prescription.PreTime
  5184. // s.Groupno = groupNo
  5185. // s.CreatedTime = ctime
  5186. // s.UpdatedTime = mtime
  5187. // s.PatientId = patient_id
  5188. // s.HisPatientId = his_patient_id
  5189. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  5190. // if errcode > 0 {
  5191. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5192. // return
  5193. // }
  5194. //
  5195. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5196. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5197. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  5198. // if s.Price == 0 {
  5199. // s.Price = lastWarehouse.RetailPrice
  5200. // }
  5201. // }
  5202. //
  5203. // service.CreateHisDoctorAdvice(&s)
  5204. // //记录日志
  5205. // byterequest, _ := json.Marshal(s)
  5206. // adviceLog := models.XtDoctorAdviceLog{
  5207. // UserOrgId: s.UserOrgId,
  5208. // PatientId: s.PatientId,
  5209. // AdminUserId: adminInfo.AdminUser.Id,
  5210. // Module: 1,
  5211. // ErrLog: string(byterequest),
  5212. // Status: 1,
  5213. // Ctime: time.Now().Unix(),
  5214. // Mtime: 0,
  5215. // Source: "电脑端his医嘱修改",
  5216. // RecordDate: s.AdviceDate,
  5217. // }
  5218. // service.CreateDoctorAdviceLog(adviceLog)
  5219. // redis := service.RedisClient()
  5220. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5221. // redis.Set(key, "", time.Second)
  5222. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5223. // fmt.Println("keyOne", keyOne)
  5224. // redis.Set(keyOne, "", time.Second)
  5225. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5226. // redis.Set(keySeven, "", time.Second)
  5227. // redis.Close()
  5228. //
  5229. // }
  5230. // }
  5231. // }
  5232. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5233. // projects := items["project"].([]interface{})
  5234. // if len(projects) > 0 {
  5235. // for _, project := range projects {
  5236. // var p models.HisPrescriptionProject
  5237. // p.PrescriptionId = prescription.ID
  5238. // p.Ctime = time.Now().Unix()
  5239. // p.Mtime = time.Now().Unix()
  5240. // p.PatientId = patient_id
  5241. // p.RecordDate = recordDateTime
  5242. // p.UserOrgId = adminInfo.CurrentOrgId
  5243. // p.HisPatientId = his_patient_id
  5244. // p.Status = 1
  5245. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  5246. // if errcode > 0 {
  5247. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5248. // return
  5249. // }
  5250. // service.CreateHisProjectTwo(&p)
  5251. //
  5252. // //记录日志
  5253. // byterequest, _ := json.Marshal(p)
  5254. // adviceLog := models.XtDoctorAdviceLog{
  5255. // UserOrgId: p.UserOrgId,
  5256. // PatientId: p.PatientId,
  5257. // AdminUserId: adminInfo.AdminUser.Id,
  5258. // Module: 1,
  5259. // ErrLog: string(byterequest),
  5260. // Status: 1,
  5261. // Ctime: time.Now().Unix(),
  5262. // Mtime: 0,
  5263. // Source: "电脑端his项目修改",
  5264. // RecordDate: p.RecordDate,
  5265. // }
  5266. // service.CreateDoctorAdviceLog(adviceLog)
  5267. // }
  5268. // }
  5269. // }
  5270. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  5271. // addition := items["addition"].([]interface{})
  5272. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5273. // ctime := time.Now().Unix()
  5274. // mtime := ctime
  5275. // if len(addition) > 0 {
  5276. // for _, item := range addition {
  5277. // var s models.HisAdditionalCharge
  5278. // s.PrescriptionId = prescription.ID
  5279. // s.Status = 1
  5280. // s.UserOrgId = adminInfo.CurrentOrgId
  5281. // s.RecordDate = recordDateTime
  5282. // s.CreatedTime = ctime
  5283. // s.UpdatedTime = mtime
  5284. // s.PatientId = patient_id
  5285. // s.HisPatientId = his_patient_id
  5286. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5287. // if errcode > 0 {
  5288. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5289. // return
  5290. // }
  5291. // service.CreateAdditionalCharge(&s)
  5292. // }
  5293. // }
  5294. // }
  5295. //
  5296. // }
  5297. // }
  5298. // }
  5299. // if err == nil {
  5300. // c.ServeSuccessJSON(map[string]interface{}{
  5301. // "msg": "保存成功",
  5302. // })
  5303. // return
  5304. //
  5305. // } else {
  5306. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5307. // return
  5308. // }
  5309. //}
  5310. func (c *HisApiController) DeletePrescription() {
  5311. prescription_id, _ := c.GetInt64("id")
  5312. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  5313. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  5314. ////同步到自备药
  5315. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  5316. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  5317. if selfPrescriptionOpen.IsOpen == 1 {
  5318. // 在函数结束时处理事务回滚
  5319. db := service.XTWriteDB()
  5320. tx := db.Begin()
  5321. defer func() {
  5322. if r := recover(); r != nil {
  5323. tx.Rollback()
  5324. } else {
  5325. tx.Commit()
  5326. }
  5327. }()
  5328. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  5329. for _, item := range advicesList {
  5330. timeStr := time.Now().Format("2006-01-02")
  5331. timeArr := strings.Split(timeStr, "-")
  5332. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5333. total = total + 1
  5334. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5335. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5336. number = number + total
  5337. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5338. operation_time := time.Now().Unix()
  5339. creater := c.GetAdminUserInfo().AdminUser.Id
  5340. //创建一个出库单
  5341. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5342. WarehouseOutOrderNumber: warehousing_out_order,
  5343. OperationTime: operation_time,
  5344. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5345. Creater: creater,
  5346. Ctime: time.Now().Unix(),
  5347. Status: 1,
  5348. WarehouseOutTime: item.AdviceDate,
  5349. Type: 0,
  5350. PatientId: item.PatientId,
  5351. IsCheck: 1,
  5352. }
  5353. //查询今日是否有出库数据
  5354. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  5355. fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
  5356. if lastWarehouseOut.ID == 0 {
  5357. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5358. }
  5359. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5360. var total_count int64
  5361. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5362. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5363. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5364. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5365. }
  5366. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5367. total_count += prescribingNumberSeven
  5368. }
  5369. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5370. total_count += prescribingNumberSeven
  5371. }
  5372. //出库
  5373. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5374. WarehouseOutOrderNumber: warehousing_out_order,
  5375. WarehouseOutId: lastWarehouseOut.ID,
  5376. DrugId: item.DrugId,
  5377. Count: total_count,
  5378. Price: 0,
  5379. TotalPrice: 0,
  5380. Status: 1,
  5381. Ctime: item.AdviceDate,
  5382. Mtime: item.AdviceDate,
  5383. Remark: "",
  5384. OrgId: item.UserOrgId,
  5385. Type: 0,
  5386. Manufacturer: selfBasedrug.Manufacturer,
  5387. Dealer: selfBasedrug.Dealer,
  5388. RetailPrice: 0,
  5389. RetailTotalPrice: 0,
  5390. CountUnit: selfBasedrug.MinUnit,
  5391. ExpiryDate: 0,
  5392. ProductDate: 0,
  5393. Number: "",
  5394. BatchNumber: "",
  5395. IsSys: 1,
  5396. WarehouseInfoId: 0,
  5397. AdminUserId: 0,
  5398. StockCount: "",
  5399. IsCheck: 1,
  5400. SysRecordTime: item.AdviceDate,
  5401. PatientId: item.PatientId,
  5402. ClassType: "",
  5403. AdviceId: item.ID,
  5404. }
  5405. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5406. }
  5407. fmt.Println("长度-------------------------------", warehousingOutInfo)
  5408. for _, it := range warehousingOutInfo {
  5409. //查询今日是否有出库数据
  5410. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  5411. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5412. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5413. //出库逻辑
  5414. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  5415. //查询剩余库存
  5416. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5417. var sum_count int64
  5418. for _, its := range stockInfo {
  5419. if its.MaxUnit == medical.MaxUnit {
  5420. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5421. }
  5422. sum_count += its.StockMaxNumber + its.StockMinNumber
  5423. }
  5424. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5425. }
  5426. }
  5427. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5428. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5429. //耗材保存处方出库
  5430. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5431. //已收费和已发药限制逻辑
  5432. isCharge := false
  5433. isMedicine := false
  5434. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5435. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5436. if new_prescription.IsMedicine == 1 {
  5437. isMedicine = true
  5438. }
  5439. for _, item := range new_prescriptions {
  5440. if item.OrderStatus == 4 {
  5441. isCharge = true
  5442. }
  5443. }
  5444. if p_err != nil {
  5445. if new_prescription.ID > 0 {
  5446. if new_prescription.OrderStatus == 2 {
  5447. isCharge = true
  5448. }
  5449. }
  5450. }
  5451. for _, item := range advices {
  5452. if item.IsMedicine == 1 {
  5453. isMedicine = true
  5454. }
  5455. }
  5456. if isCharge {
  5457. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5458. return
  5459. }
  5460. if isMedicine {
  5461. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5462. return
  5463. }
  5464. //已收费和已发药限制逻辑
  5465. if len(projects) > 0 {
  5466. for _, item := range projects {
  5467. service.DeletePrintInfo(item.ID) //删除打印信息
  5468. if goodOutConfig.IsOpen != 1 {
  5469. if stockConfig.IsOpen == 1 {
  5470. if item.Type == 3 && item.IsOut == 1 {
  5471. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5472. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5473. good.Total = good.Total + f_count
  5474. service.UpdateGoodInfo(&good)
  5475. operation_time := time.Now().Unix()
  5476. creater := c.GetAdminUserInfo().AdminUser.Id
  5477. //创建退库单
  5478. timeStr := time.Now().Format("2006-01-02")
  5479. timeArr := strings.Split(timeStr, "-")
  5480. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5481. total = total + 1
  5482. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5483. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5484. cancelStock := models.CancelStock{
  5485. OrderNumber: orderNumber,
  5486. OperaTime: operation_time,
  5487. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5488. Creater: creater,
  5489. Ctime: time.Now().Unix(),
  5490. Status: 1,
  5491. ReturnTime: item.RecordDate,
  5492. Type: 1,
  5493. StorehouseId: houseConfig.StorehouseOutInfo,
  5494. IsCheck: 1,
  5495. }
  5496. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5497. if msgerrkonde == gorm.ErrRecordNotFound {
  5498. service.AddSigleCancelStock(&cancelStock)
  5499. }
  5500. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5501. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5502. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5503. //查询该耗材是否出库
  5504. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5505. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5506. deaerler, _ := service.GetDealerById(info.Dealer)
  5507. var total_count int64
  5508. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5509. total_count += count
  5510. if info.ID > 0 {
  5511. if info.Count >= total_count {
  5512. //回退库存
  5513. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5514. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5515. var flush_count int64
  5516. for _, it := range goodList {
  5517. flush_count += it.StockCount
  5518. }
  5519. cancelStockInfo := models.CancelStockInfo{
  5520. GoodId: item.ProjectId,
  5521. CancelStockId: cancel.ID,
  5522. GoodTypeId: good.GoodTypeId,
  5523. Count: prescribingNumber,
  5524. Price: info.Price,
  5525. Total: 0,
  5526. ProductDate: info.ProductDate,
  5527. ExpiryDate: info.ExpiryDate,
  5528. Ctime: time.Now().Unix(),
  5529. Status: 1,
  5530. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5531. OrderNumber: cancel.OrderNumber,
  5532. Type: 0,
  5533. Dealer: deaerler.DealerName,
  5534. Manufacturer: manufacturer.ManufacturerName,
  5535. Number: info.Number,
  5536. RegisterAccount: "",
  5537. Remark: "",
  5538. WarehouseInfoId: info.WarehouseInfotId,
  5539. PatientId: info.PatientId,
  5540. RecordDate: info.SysRecordTime,
  5541. StorehouseId: houseConfig.StorehouseOutInfo,
  5542. IsCheck: 1,
  5543. }
  5544. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5545. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5546. flow := models.VmStockFlow{
  5547. WarehousingId: info.WarehouseInfotId,
  5548. GoodId: item.ProjectId,
  5549. Number: info.Number,
  5550. LicenseNumber: info.LicenseNumber,
  5551. Count: prescribingNumber,
  5552. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5553. PatientId: item.PatientId,
  5554. SystemTime: info.SysRecordTime,
  5555. ConsumableType: 7,
  5556. IsSys: 0,
  5557. WarehousingOrder: "",
  5558. WarehouseOutId: info.WarehouseOutId,
  5559. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5560. IsEdit: 0,
  5561. CancelStockId: cancel.ID,
  5562. CancelOrderNumber: cancel.OrderNumber,
  5563. Manufacturer: manufacturer.ID,
  5564. Dealer: 0,
  5565. Creator: c.GetAdminUserInfo().CurrentOrgId,
  5566. UpdateCreator: 0,
  5567. Status: 1,
  5568. Ctime: time.Now().Unix(),
  5569. Mtime: 0,
  5570. Price: info.Price,
  5571. WarehousingDetailId: info.WarehouseInfotId,
  5572. WarehouseOutDetailId: info.ID,
  5573. CancelOutDetailId: cancelInfo.ID,
  5574. ProductDate: info.ProductDate,
  5575. ExpireDate: info.ExpiryDate,
  5576. StorehouseId: houseConfig.StorehouseOutInfo,
  5577. OverCount: flush_count,
  5578. OperateTime: time.Now().Unix(),
  5579. }
  5580. service.CreateStockFlowOne(flow)
  5581. //退库数量增加
  5582. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  5583. //出库数量减少
  5584. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  5585. }
  5586. if info.Count < total_count {
  5587. //回退库存
  5588. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5589. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5590. var flush_count int64
  5591. for _, it := range goodList {
  5592. flush_count += it.StockCount
  5593. }
  5594. cancelStockInfo := models.CancelStockInfo{
  5595. GoodId: item.ProjectId,
  5596. CancelStockId: cancel.ID,
  5597. GoodTypeId: good.GoodTypeId,
  5598. Count: info.Count,
  5599. Price: info.Price,
  5600. Total: 0,
  5601. ProductDate: info.ProductDate,
  5602. ExpiryDate: info.ExpiryDate,
  5603. Ctime: time.Now().Unix(),
  5604. Status: 1,
  5605. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5606. OrderNumber: cancel.OrderNumber,
  5607. Type: 0,
  5608. Dealer: deaerler.DealerName,
  5609. Manufacturer: manufacturer.ManufacturerName,
  5610. Number: info.Number,
  5611. RegisterAccount: "",
  5612. Remark: "",
  5613. WarehouseInfoId: info.WarehouseInfotId,
  5614. PatientId: info.PatientId,
  5615. RecordDate: info.SysRecordTime,
  5616. StorehouseId: houseConfig.StorehouseOutInfo,
  5617. IsCheck: 1,
  5618. }
  5619. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5620. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5621. flow := models.VmStockFlow{
  5622. WarehousingId: info.WarehouseInfotId,
  5623. GoodId: item.ProjectId,
  5624. Number: info.Number,
  5625. LicenseNumber: info.LicenseNumber,
  5626. Count: info.Count,
  5627. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5628. PatientId: item.PatientId,
  5629. SystemTime: info.SysRecordTime,
  5630. ConsumableType: 7,
  5631. IsSys: 0,
  5632. WarehousingOrder: "",
  5633. WarehouseOutId: info.WarehouseOutId,
  5634. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5635. IsEdit: 0,
  5636. CancelStockId: cancel.ID,
  5637. CancelOrderNumber: cancel.OrderNumber,
  5638. Manufacturer: manufacturer.ID,
  5639. Dealer: 0,
  5640. Creator: c.GetAdminUserInfo().CurrentOrgId,
  5641. UpdateCreator: 0,
  5642. Status: 1,
  5643. Ctime: time.Now().Unix(),
  5644. Mtime: 0,
  5645. Price: info.Price,
  5646. WarehousingDetailId: info.WarehouseInfotId,
  5647. WarehouseOutDetailId: info.ID,
  5648. CancelOutDetailId: cancelInfo.ID,
  5649. ProductDate: info.ProductDate,
  5650. ExpireDate: info.ExpiryDate,
  5651. StorehouseId: houseConfig.StorehouseOutInfo,
  5652. OverCount: flush_count,
  5653. OperateTime: time.Now().Unix(),
  5654. }
  5655. service.CreateStockFlowOne(flow)
  5656. //退库数量增加
  5657. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  5658. //出库数量减少
  5659. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  5660. }
  5661. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5662. var flush_count int64
  5663. for _, it := range goodList {
  5664. flush_count += it.StockCount
  5665. }
  5666. //查询已出库数量
  5667. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  5668. if prescribingNumber < dialysisInfo.Count {
  5669. //改变数量
  5670. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  5671. }
  5672. if prescribingNumber >= dialysisInfo.Count {
  5673. //删除出库表
  5674. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  5675. }
  5676. //更新库存
  5677. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  5678. //更新基础库库存
  5679. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  5680. }
  5681. }
  5682. }
  5683. }
  5684. //保存耗材出库
  5685. if goodOutConfig.IsOpen == 1 {
  5686. if item.Type == 3 {
  5687. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5688. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5689. good.Total = good.Total + f_count
  5690. service.UpdateGoodInfo(&good)
  5691. operation_time := time.Now().Unix()
  5692. creater := c.GetAdminUserInfo().AdminUser.Id
  5693. //创建退库单
  5694. timeStr := time.Now().Format("2006-01-02")
  5695. timeArr := strings.Split(timeStr, "-")
  5696. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5697. total = total + 1
  5698. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5699. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5700. cancelStock := models.CancelStock{
  5701. OrderNumber: orderNumber,
  5702. OperaTime: operation_time,
  5703. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5704. Creater: creater,
  5705. Ctime: time.Now().Unix(),
  5706. Status: 1,
  5707. ReturnTime: item.RecordDate,
  5708. Type: 1,
  5709. StorehouseId: houseConfig.StorehouseOutInfo,
  5710. IsCheck: 1,
  5711. }
  5712. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5713. if msgerrkonde == gorm.ErrRecordNotFound {
  5714. service.AddSigleCancelStock(&cancelStock)
  5715. }
  5716. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5717. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5718. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5719. //查询该耗材是否出库
  5720. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5721. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5722. deaerler, _ := service.GetDealerById(info.Dealer)
  5723. var total_count int64
  5724. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5725. total_count += count
  5726. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5727. var flush_count int64
  5728. for _, it := range goodList {
  5729. flush_count += it.StockCount
  5730. }
  5731. fmt.Println("历史出库数据", info.Count)
  5732. fmt.Println("出库数量", total_count)
  5733. if info.ID > 0 {
  5734. cancelStockInfo := models.CancelStockInfo{
  5735. GoodId: item.ProjectId,
  5736. CancelStockId: cancel.ID,
  5737. GoodTypeId: good.GoodTypeId,
  5738. Count: prescribingNumber,
  5739. Price: info.Price,
  5740. Total: 0,
  5741. ProductDate: info.ProductDate,
  5742. ExpiryDate: info.ExpiryDate,
  5743. Ctime: time.Now().Unix(),
  5744. Status: 1,
  5745. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5746. OrderNumber: cancel.OrderNumber,
  5747. Type: 0,
  5748. Dealer: deaerler.DealerName,
  5749. Manufacturer: manufacturer.ManufacturerName,
  5750. Number: info.Number,
  5751. RegisterAccount: "",
  5752. Remark: "",
  5753. WarehouseInfoId: info.WarehouseInfotId,
  5754. PatientId: info.PatientId,
  5755. RecordDate: info.SysRecordTime,
  5756. StorehouseId: houseConfig.StorehouseOutInfo,
  5757. IsCheck: 1,
  5758. }
  5759. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5760. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5761. //查询出库数量
  5762. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  5763. //出库数据 大于 退库数量
  5764. if len(list) > 0 {
  5765. for _, it := range list {
  5766. //回退库存
  5767. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  5768. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5769. var flush_count_one int64
  5770. for _, it := range goodList {
  5771. flush_count_one += it.StockCount
  5772. }
  5773. //查询该批次是否有退库数据
  5774. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  5775. creater := c.GetAdminUserInfo().AdminUser.Id
  5776. flow := models.VmStockFlow{
  5777. WarehousingId: it.WarehouseInfotId,
  5778. GoodId: it.GoodId,
  5779. Number: it.Number,
  5780. LicenseNumber: it.LicenseNumber,
  5781. Count: it.Count,
  5782. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5783. PatientId: it.PatientId,
  5784. SystemTime: it.SysRecordTime,
  5785. ConsumableType: 7,
  5786. IsSys: 0,
  5787. WarehousingOrder: "",
  5788. WarehouseOutId: it.WarehouseOutId,
  5789. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  5790. IsEdit: 0,
  5791. CancelStockId: cancel.ID,
  5792. CancelOrderNumber: cancel.OrderNumber,
  5793. Manufacturer: manufacturer.ID,
  5794. Dealer: 0,
  5795. Creator: creater,
  5796. UpdateCreator: 0,
  5797. Status: 1,
  5798. Ctime: time.Now().Unix(),
  5799. Mtime: 0,
  5800. Price: it.Price,
  5801. WarehousingDetailId: it.WarehouseInfotId,
  5802. WarehouseOutDetailId: it.ID,
  5803. CancelOutDetailId: cancelInfo.ID,
  5804. ProductDate: it.ProductDate,
  5805. ExpireDate: it.ExpiryDate,
  5806. StorehouseId: houseConfig.StorehouseOutInfo,
  5807. OverCount: flush_count_one,
  5808. }
  5809. service.CreateStockFlowOne(flow)
  5810. //if flow.ID > 0 {
  5811. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  5812. //}
  5813. }
  5814. }
  5815. //flow := models.VmStockFlow{
  5816. // WarehousingId: info.WarehouseInfotId,
  5817. // GoodId: item.ProjectId,
  5818. // Number: info.Number,
  5819. // LicenseNumber: info.LicenseNumber,
  5820. // Count: prescribingNumber,
  5821. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5822. // PatientId: item.PatientId,
  5823. // SystemTime: info.SysRecordTime,
  5824. // ConsumableType: 7,
  5825. // IsSys: 0,
  5826. // WarehousingOrder: "",
  5827. // WarehouseOutId: info.WarehouseOutId,
  5828. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5829. // IsEdit: 0,
  5830. // CancelStockId: cancel.ID,
  5831. // CancelOrderNumber: cancel.OrderNumber,
  5832. // Manufacturer: manufacturer.ID,
  5833. // Dealer: 0,
  5834. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  5835. // UpdateCreator: 0,
  5836. // Status: 1,
  5837. // Ctime: time.Now().Unix(),
  5838. // Mtime: 0,
  5839. // Price: info.Price,
  5840. // WarehousingDetailId: info.WarehouseInfotId,
  5841. // WarehouseOutDetailId: info.ID,
  5842. // CancelOutDetailId: cancelInfo.ID,
  5843. // ProductDate: info.ProductDate,
  5844. // ExpireDate: info.ExpiryDate,
  5845. // StorehouseId: houseConfig.StorehouseOutInfo,
  5846. // OverCount: flush_count,
  5847. //}
  5848. //service.CreateStockFlowOne(flow)
  5849. //退库数量增加
  5850. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  5851. //出库数量减少
  5852. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  5853. //查询已出库数量
  5854. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  5855. if prescribingNumber < dialysisInfo.Count {
  5856. //改变数量
  5857. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  5858. }
  5859. if prescribingNumber >= dialysisInfo.Count {
  5860. //删除出库表
  5861. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  5862. }
  5863. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5864. var flush_count_one int64
  5865. for _, it := range goodList {
  5866. flush_count_one += it.StockCount
  5867. }
  5868. //更新库存
  5869. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  5870. fmt.Println("msgerrkonde23332323", msgerrkonde)
  5871. //更新基础库库存
  5872. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  5873. }
  5874. }
  5875. }
  5876. }
  5877. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5878. fmt.Println(err)
  5879. }
  5880. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5881. fmt.Println(err)
  5882. if len(advices) > 0 {
  5883. for _, item := range advices {
  5884. redis := service.RedisClient()
  5885. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5886. redis.Set(keyFive, "", time.Second)
  5887. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5888. redis.Set(keyOne, "", time.Second)
  5889. redis.Close()
  5890. }
  5891. }
  5892. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5893. if len(advices) > 0 {
  5894. for _, item := range advices {
  5895. creater := c.GetAdminUserInfo().AdminUser.Id
  5896. service.DrugAutoAddCancelInfo(item, creater)
  5897. }
  5898. }
  5899. } else {
  5900. if drugOutConfig.IsOpen == 1 {
  5901. if len(advices) > 0 {
  5902. for _, item := range advices {
  5903. creater := c.GetAdminUserInfo().AdminUser.Id
  5904. service.DrugAutoAddCancelInfo(item, creater)
  5905. }
  5906. }
  5907. } else {
  5908. if len(advices) > 0 {
  5909. for _, item := range advices {
  5910. creater := c.GetAdminUserInfo().AdminUser.Id
  5911. service.DrugAutoAddCancelInfo(item, creater)
  5912. }
  5913. }
  5914. }
  5915. }
  5916. c.ServeSuccessJSON(map[string]interface{}{
  5917. "msg": "删除成功",
  5918. })
  5919. return
  5920. }
  5921. func (c *HisApiController) DeleteDoctorAdvice() {
  5922. id, _ := c.GetInt64("id")
  5923. advice, _ := service.GetHisDoctorAdvicesById(id)
  5924. ////同步到自备药
  5925. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  5926. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  5927. if selfPrescriptionOpen.IsOpen == 1 {
  5928. db := service.XTWriteDB()
  5929. tx := db.Begin()
  5930. defer func() {
  5931. if r := recover(); r != nil {
  5932. tx.Rollback()
  5933. } else {
  5934. tx.Commit()
  5935. }
  5936. }()
  5937. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  5938. var total_count int64
  5939. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  5940. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5941. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5942. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5943. }
  5944. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5945. total_count += prescribingNumberSeven
  5946. }
  5947. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5948. total_count += prescribingNumberSeven
  5949. }
  5950. timeStr := time.Now().Format("2006-01-02")
  5951. timeArr := strings.Split(timeStr, "-")
  5952. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5953. total = total + 1
  5954. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5955. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5956. number = number + total
  5957. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5958. operation_time := time.Now().Unix()
  5959. creater := c.GetAdminUserInfo().AdminUser.Id
  5960. //创建一个出库单
  5961. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5962. WarehouseOutOrderNumber: warehousing_out_order,
  5963. OperationTime: operation_time,
  5964. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5965. Creater: creater,
  5966. Ctime: time.Now().Unix(),
  5967. Status: 1,
  5968. WarehouseOutTime: advice.AdviceDate,
  5969. Type: 0,
  5970. PatientId: advice.PatientId,
  5971. IsCheck: 1,
  5972. }
  5973. //查询今日是否有出库数据
  5974. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  5975. if lastWarehouseOut.ID == 0 {
  5976. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5977. }
  5978. //出库
  5979. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5980. WarehouseOutId: lastWarehouseOut.ID,
  5981. WarehouseOutOrderNumber: warehousing_out_order,
  5982. DrugId: advice.DrugId,
  5983. Count: total_count,
  5984. Price: 0,
  5985. TotalPrice: 0,
  5986. Status: 1,
  5987. Ctime: advice.AdviceDate,
  5988. Mtime: advice.AdviceDate,
  5989. Remark: "",
  5990. OrgId: advice.UserOrgId,
  5991. Type: 0,
  5992. Manufacturer: selfBasedrug.Manufacturer,
  5993. Dealer: selfBasedrug.Dealer,
  5994. RetailPrice: 0,
  5995. RetailTotalPrice: 0,
  5996. CountUnit: advice.PrescribingNumberUnit,
  5997. ExpiryDate: 0,
  5998. ProductDate: 0,
  5999. Number: "",
  6000. BatchNumber: "",
  6001. IsSys: 0,
  6002. WarehouseInfoId: 0,
  6003. AdminUserId: 0,
  6004. StockCount: "",
  6005. IsCheck: 1,
  6006. SysRecordTime: advice.AdviceDate,
  6007. PatientId: advice.PatientId,
  6008. AdviceId: advice.ID,
  6009. ClassType: "",
  6010. }
  6011. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6012. for _, it := range warehousingOutInfo {
  6013. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6014. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6015. //出库逻辑
  6016. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  6017. //查询剩余库存
  6018. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6019. var sum_count int64
  6020. for _, its := range stockInfo {
  6021. if its.MaxUnit == medical.MaxUnit {
  6022. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6023. }
  6024. sum_count += its.StockMaxNumber + its.StockMinNumber
  6025. }
  6026. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6027. }
  6028. }
  6029. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6030. //已收费和已发药的限制逻辑
  6031. isCharge := false
  6032. isMedicine := false
  6033. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6034. //获取今天该患者所有处方,判断是否发药或者收费
  6035. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6036. //for _, item := range new_prescriptions {
  6037. if new_prescription.IsMedicine == 1 {
  6038. isMedicine = true
  6039. }
  6040. //}
  6041. for _, item := range new_prescriptions {
  6042. if item.OrderStatus == 4 {
  6043. isCharge = true
  6044. }
  6045. }
  6046. if isMedicine {
  6047. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6048. return
  6049. }
  6050. if isCharge {
  6051. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6052. return
  6053. }
  6054. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  6055. for _, item := range advices {
  6056. if item.IsMedicine == 1 {
  6057. isMedicine = true
  6058. }
  6059. }
  6060. if isMedicine {
  6061. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  6062. return
  6063. }
  6064. if new_prescription.ID > 0 {
  6065. if new_prescription.OrderStatus == 2 {
  6066. isCharge = true
  6067. }
  6068. }
  6069. if isCharge {
  6070. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6071. return
  6072. }
  6073. //已收费和已发药的限制逻辑
  6074. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  6075. redis := service.RedisClient()
  6076. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  6077. redis.Set(keyFive, "", time.Second)
  6078. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  6079. redis.Set(keyOne, "", time.Second)
  6080. defer redis.Close()
  6081. if err == nil {
  6082. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6083. //查询是否在处方中出库
  6084. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6085. if openConfig.IsOpen != 1 {
  6086. //判断该医嘱是否执行了
  6087. if advice.ExecutionState == 1 {
  6088. creater := c.GetAdminUserInfo().AdminUser.Id
  6089. service.DrugAutoAddCancelInfo(&advice, creater)
  6090. }
  6091. }
  6092. //开启保存处方扣减功能
  6093. if openConfig.IsOpen == 1 {
  6094. creater := c.GetAdminUserInfo().AdminUser.Id
  6095. service.DrugAutoAddCancelInfo(&advice, creater)
  6096. }
  6097. } else {
  6098. if drugOutConfig.IsOpen == 1 {
  6099. //查询是否在处方中出库
  6100. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6101. if openConfig.IsOpen != 1 {
  6102. //判断该医嘱是否执行了
  6103. if advice.ExecutionState == 1 {
  6104. creater := c.GetAdminUserInfo().AdminUser.Id
  6105. service.DrugAutoAddCancelInfo(&advice, creater)
  6106. }
  6107. }
  6108. //开启保存处方扣减功能
  6109. if openConfig.IsOpen == 1 {
  6110. creater := c.GetAdminUserInfo().AdminUser.Id
  6111. service.DrugAutoAddCancelInfo(&advice, creater)
  6112. }
  6113. } else {
  6114. //判断该医嘱是否执行了
  6115. if advice.ExecutionState == 1 {
  6116. creater := c.GetAdminUserInfo().AdminUser.Id
  6117. service.DrugAutoAddCancelInfo(&advice, creater)
  6118. }
  6119. }
  6120. }
  6121. c.ServeSuccessJSON(map[string]interface{}{
  6122. "msg": "删除成功",
  6123. })
  6124. return
  6125. } else {
  6126. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6127. return
  6128. }
  6129. }
  6130. func (c *HisApiController) DeleteProject() {
  6131. id, _ := c.GetInt64("id")
  6132. adminInfo := c.GetAdminUserInfo()
  6133. project, _ := service.GetHisProjectByID(id)
  6134. // var consumable models.DialysisBeforePrepare
  6135. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  6136. //耗材保存处方出库
  6137. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6138. isCharge := false
  6139. isMedicine := false
  6140. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6141. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6142. for _, item := range new_prescriptions {
  6143. if item.IsMedicine == 1 {
  6144. isMedicine = true
  6145. }
  6146. }
  6147. for _, item := range new_prescriptions {
  6148. if item.OrderStatus == 4 {
  6149. isCharge = true
  6150. }
  6151. }
  6152. if isMedicine {
  6153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6154. return
  6155. }
  6156. if isCharge {
  6157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6158. return
  6159. }
  6160. if new_prescription.ID > 0 {
  6161. if new_prescription.OrderStatus == 2 {
  6162. isCharge = true
  6163. }
  6164. }
  6165. if isCharge {
  6166. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6167. return
  6168. }
  6169. service.DeletePrintInfo(id)
  6170. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  6171. label.Status = 0
  6172. service.CreateHisLabelRecordTwo(&label)
  6173. fmt.Println(goodOutConfig.IsOpen)
  6174. if goodOutConfig.IsOpen != 1 {
  6175. if stockConfig.IsOpen == 1 {
  6176. if project.Type == 2 {
  6177. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6178. fmt.Println(err)
  6179. }
  6180. if project.Type == 3 && project.IsOut == 1 {
  6181. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6182. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6183. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6184. operation_time := time.Now().Unix()
  6185. creater := adminInfo.AdminUser.Id
  6186. //创建退库单
  6187. timeStr := time.Now().Format("2006-01-02")
  6188. timeArr := strings.Split(timeStr, "-")
  6189. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6190. total = total + 1
  6191. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6192. cancelStock := models.CancelStock{
  6193. OrderNumber: orderNumber,
  6194. OperaTime: operation_time,
  6195. OrgId: adminInfo.CurrentOrgId,
  6196. Creater: creater,
  6197. Ctime: time.Now().Unix(),
  6198. Status: 1,
  6199. ReturnTime: project.RecordDate,
  6200. Type: 1,
  6201. StorehouseId: houseConfig.StorehouseOutInfo,
  6202. IsCheck: 1,
  6203. }
  6204. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6205. if msgerrkonde == gorm.ErrRecordNotFound {
  6206. service.AddSigleCancelStock(&cancelStock)
  6207. }
  6208. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6209. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6210. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6211. //查询是否有出库
  6212. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6213. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6214. deaerler, _ := service.GetDealerById(info.Dealer)
  6215. if info.ID > 0 {
  6216. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6217. if info.Count >= prescribingNumber {
  6218. cancelStockInfo := models.CancelStockInfo{
  6219. GoodId: project.ProjectId,
  6220. CancelStockId: cancel.ID,
  6221. GoodTypeId: good.GoodTypeId,
  6222. Count: prescribingNumber,
  6223. Price: info.Price,
  6224. Total: 0,
  6225. ProductDate: info.ProductDate,
  6226. ExpiryDate: info.ExpiryDate,
  6227. Ctime: time.Now().Unix(),
  6228. Status: 1,
  6229. OrgId: adminInfo.CurrentOrgId,
  6230. OrderNumber: cancel.OrderNumber,
  6231. Type: 0,
  6232. Dealer: deaerler.DealerName,
  6233. Manufacturer: manufacturer.ManufacturerName,
  6234. Number: info.Number,
  6235. RegisterAccount: "",
  6236. Remark: "",
  6237. WarehouseInfoId: info.WarehouseInfotId,
  6238. PatientId: info.PatientId,
  6239. RecordDate: info.SysRecordTime,
  6240. StorehouseId: houseConfig.StorehouseOutInfo,
  6241. IsCheck: 1,
  6242. }
  6243. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6244. //回退库存
  6245. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  6246. //退库数量增加
  6247. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6248. //出库数量减少
  6249. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6250. }
  6251. if info.Count < prescribingNumber {
  6252. cancelStockInfo := models.CancelStockInfo{
  6253. GoodId: project.ProjectId,
  6254. CancelStockId: cancel.ID,
  6255. GoodTypeId: good.GoodTypeId,
  6256. Count: info.Count,
  6257. Price: info.Price,
  6258. Total: 0,
  6259. ProductDate: info.ProductDate,
  6260. ExpiryDate: info.ExpiryDate,
  6261. Ctime: time.Now().Unix(),
  6262. Status: 1,
  6263. OrgId: adminInfo.CurrentOrgId,
  6264. OrderNumber: cancel.OrderNumber,
  6265. Type: 0,
  6266. Dealer: deaerler.DealerName,
  6267. Manufacturer: manufacturer.ManufacturerName,
  6268. Number: info.Number,
  6269. RegisterAccount: "",
  6270. Remark: "",
  6271. WarehouseInfoId: info.WarehouseInfotId,
  6272. PatientId: info.PatientId,
  6273. RecordDate: info.SysRecordTime,
  6274. StorehouseId: houseConfig.StorehouseOutInfo,
  6275. IsCheck: 1,
  6276. }
  6277. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6278. //回退库存
  6279. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6280. //退库数量增加
  6281. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6282. //出库数量减少
  6283. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  6284. }
  6285. //查询剩余库存
  6286. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6287. var over_count int64
  6288. for _, it := range goodList {
  6289. over_count += it.StockCount
  6290. }
  6291. //出库数据 大于 退库数量
  6292. if info.Count >= prescribingNumber {
  6293. flow := models.VmStockFlow{
  6294. WarehousingId: info.WarehouseInfotId,
  6295. GoodId: project.ProjectId,
  6296. Number: info.Number,
  6297. LicenseNumber: info.LicenseNumber,
  6298. Count: prescribingNumber,
  6299. UserOrgId: adminInfo.CurrentOrgId,
  6300. PatientId: project.PatientId,
  6301. SystemTime: info.SysRecordTime,
  6302. ConsumableType: 7,
  6303. IsSys: 0,
  6304. WarehousingOrder: "",
  6305. WarehouseOutId: info.WarehouseOutId,
  6306. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6307. IsEdit: 0,
  6308. CancelStockId: cancel.ID,
  6309. CancelOrderNumber: cancel.OrderNumber,
  6310. Manufacturer: manufacturer.ID,
  6311. Dealer: 0,
  6312. Creator: adminInfo.AdminUser.Id,
  6313. UpdateCreator: 0,
  6314. Status: 1,
  6315. Ctime: time.Now().Unix(),
  6316. Mtime: 0,
  6317. Price: info.Price,
  6318. WarehousingDetailId: info.WarehouseInfotId,
  6319. WarehouseOutDetailId: info.ID,
  6320. CancelOutDetailId: cancelInfo.ID,
  6321. ProductDate: info.ProductDate,
  6322. ExpireDate: info.ExpiryDate,
  6323. StorehouseId: houseConfig.StorehouseOutInfo,
  6324. OverCount: over_count,
  6325. OperateTime: time.Now().Unix(),
  6326. }
  6327. service.CreateStockFlowOne(flow)
  6328. }
  6329. //出库数据小于退库数据
  6330. if info.Count < prescribingNumber {
  6331. flow := models.VmStockFlow{
  6332. WarehousingId: info.WarehouseInfotId,
  6333. GoodId: project.ProjectId,
  6334. Number: info.Number,
  6335. LicenseNumber: info.LicenseNumber,
  6336. Count: info.Count,
  6337. UserOrgId: adminInfo.CurrentOrgId,
  6338. PatientId: project.PatientId,
  6339. SystemTime: info.SysRecordTime,
  6340. ConsumableType: 7,
  6341. IsSys: 0,
  6342. WarehousingOrder: "",
  6343. WarehouseOutId: info.WarehouseOutId,
  6344. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6345. IsEdit: 0,
  6346. CancelStockId: cancel.ID,
  6347. CancelOrderNumber: cancel.OrderNumber,
  6348. Manufacturer: manufacturer.ID,
  6349. Dealer: 0,
  6350. Creator: adminInfo.AdminUser.Id,
  6351. UpdateCreator: 0,
  6352. Status: 1,
  6353. Ctime: time.Now().Unix(),
  6354. Mtime: 0,
  6355. Price: info.Price,
  6356. WarehousingDetailId: info.WarehouseInfotId,
  6357. WarehouseOutDetailId: info.ID,
  6358. CancelOutDetailId: cancelInfo.ID,
  6359. ProductDate: info.ProductDate,
  6360. ExpireDate: info.ExpiryDate,
  6361. StorehouseId: houseConfig.StorehouseOutInfo,
  6362. OverCount: over_count,
  6363. OperateTime: time.Now().Unix(),
  6364. }
  6365. service.CreateStockFlowOne(flow)
  6366. }
  6367. //查询已出库数量
  6368. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6369. //fmt.Println("aiwohonguo --------------------", prescribingNumber)
  6370. //fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  6371. if prescribingNumber < dialysisInfo.Count {
  6372. //改变数量
  6373. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6374. }
  6375. if prescribingNumber >= dialysisInfo.Count {
  6376. //删除出库表
  6377. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6378. }
  6379. //更新剩余库存
  6380. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6381. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6382. var total_count_one int64
  6383. for _, it := range stockList {
  6384. total_count_one += it.StockCount
  6385. }
  6386. //基础库插入数据
  6387. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6388. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6389. var flush_count int64
  6390. for _, it := range goodListOne {
  6391. flush_count += it.StockCount
  6392. }
  6393. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6394. if errs != nil {
  6395. goodErrcode := models.XtGoodErrcode{
  6396. UserOrgId: project.UserOrgId,
  6397. Errcode: "手动出库更新剩余出库失败",
  6398. GoodId: project.ProjectId,
  6399. Status: 1,
  6400. Ctime: time.Now().Unix(),
  6401. Mtime: 0,
  6402. Count: 0,
  6403. StockCount: 0,
  6404. Creater: creater,
  6405. BatchNumberId: 0,
  6406. WarehouseOutId: 0,
  6407. }
  6408. service.CreateGoodErrcode(goodErrcode)
  6409. }
  6410. }
  6411. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6412. fmt.Println(err)
  6413. } else {
  6414. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6415. fmt.Println(err)
  6416. }
  6417. } else {
  6418. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6419. fmt.Println(err)
  6420. }
  6421. }
  6422. //保存处方出库
  6423. if goodOutConfig.IsOpen == 1 {
  6424. if project.Type == 3 {
  6425. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6426. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6427. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6428. operation_time := time.Now().Unix()
  6429. creater := adminInfo.AdminUser.Id
  6430. //创建退库单
  6431. timeStr := time.Now().Format("2006-01-02")
  6432. timeArr := strings.Split(timeStr, "-")
  6433. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6434. total = total + 1
  6435. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6436. cancelStock := models.CancelStock{
  6437. OrderNumber: orderNumber,
  6438. OperaTime: operation_time,
  6439. OrgId: adminInfo.CurrentOrgId,
  6440. Creater: creater,
  6441. Ctime: time.Now().Unix(),
  6442. Status: 1,
  6443. ReturnTime: project.RecordDate,
  6444. Type: 1,
  6445. StorehouseId: houseConfig.StorehouseOutInfo,
  6446. IsCheck: 1,
  6447. }
  6448. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6449. if msgerrkonde == gorm.ErrRecordNotFound {
  6450. service.AddSigleCancelStock(&cancelStock)
  6451. }
  6452. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6453. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6454. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6455. //获取出库数据
  6456. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6457. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6458. deaerler, _ := service.GetDealerById(info.Dealer)
  6459. if info.ID > 0 {
  6460. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6461. if info.Count >= prescribingNumber {
  6462. cancelStockInfo := models.CancelStockInfo{
  6463. GoodId: project.ProjectId,
  6464. CancelStockId: cancel.ID,
  6465. GoodTypeId: good.GoodTypeId,
  6466. Count: prescribingNumber,
  6467. Price: info.Price,
  6468. Total: 0,
  6469. ProductDate: info.ProductDate,
  6470. ExpiryDate: info.ExpiryDate,
  6471. Ctime: time.Now().Unix(),
  6472. Status: 1,
  6473. OrgId: adminInfo.CurrentOrgId,
  6474. OrderNumber: cancel.OrderNumber,
  6475. Type: 0,
  6476. Dealer: deaerler.DealerName,
  6477. Manufacturer: manufacturer.ManufacturerName,
  6478. Number: info.Number,
  6479. RegisterAccount: "",
  6480. Remark: "",
  6481. WarehouseInfoId: info.WarehouseInfotId,
  6482. PatientId: info.PatientId,
  6483. RecordDate: info.SysRecordTime,
  6484. StorehouseId: houseConfig.StorehouseOutInfo,
  6485. IsCheck: 1,
  6486. }
  6487. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6488. //退库数量增加
  6489. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6490. //出库数量减少
  6491. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6492. }
  6493. if info.Count < prescribingNumber {
  6494. cancelStockInfo := models.CancelStockInfo{
  6495. GoodId: project.ProjectId,
  6496. CancelStockId: cancel.ID,
  6497. GoodTypeId: good.GoodTypeId,
  6498. Count: prescribingNumber,
  6499. Price: info.Price,
  6500. Total: 0,
  6501. ProductDate: info.ProductDate,
  6502. ExpiryDate: info.ExpiryDate,
  6503. Ctime: time.Now().Unix(),
  6504. Status: 1,
  6505. OrgId: adminInfo.CurrentOrgId,
  6506. OrderNumber: cancel.OrderNumber,
  6507. Type: 0,
  6508. Dealer: deaerler.DealerName,
  6509. Manufacturer: manufacturer.ManufacturerName,
  6510. Number: info.Number,
  6511. RegisterAccount: "",
  6512. Remark: "",
  6513. WarehouseInfoId: info.WarehouseInfotId,
  6514. PatientId: info.PatientId,
  6515. RecordDate: info.SysRecordTime,
  6516. StorehouseId: houseConfig.StorehouseOutInfo,
  6517. IsCheck: 1,
  6518. }
  6519. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6520. //回退库存
  6521. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6522. }
  6523. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6524. var over_count int64
  6525. for _, it := range goodList {
  6526. over_count += it.StockCount
  6527. }
  6528. //查询出库数量
  6529. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  6530. //出库数据 大于 退库数量
  6531. if len(list) > 0 {
  6532. for _, it := range list {
  6533. //回退库存
  6534. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6535. //退库数量增加
  6536. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  6537. //出库数量减少
  6538. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  6539. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6540. var over_count_one int64
  6541. for _, it := range goodList {
  6542. over_count_one += it.StockCount
  6543. }
  6544. //查询该批次是否有退库数据
  6545. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  6546. flow := models.VmStockFlow{
  6547. WarehousingId: it.WarehouseInfotId,
  6548. GoodId: it.GoodId,
  6549. Number: it.Number,
  6550. LicenseNumber: it.LicenseNumber,
  6551. Count: it.Count,
  6552. UserOrgId: adminInfo.CurrentOrgId,
  6553. PatientId: it.PatientId,
  6554. SystemTime: it.SysRecordTime,
  6555. ConsumableType: 7,
  6556. IsSys: 0,
  6557. WarehousingOrder: "",
  6558. WarehouseOutId: it.WarehouseOutId,
  6559. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6560. IsEdit: 0,
  6561. CancelStockId: cancel.ID,
  6562. CancelOrderNumber: cancel.OrderNumber,
  6563. Manufacturer: manufacturer.ID,
  6564. Dealer: 0,
  6565. Creator: adminInfo.AdminUser.Id,
  6566. UpdateCreator: 0,
  6567. Status: 1,
  6568. Ctime: time.Now().Unix(),
  6569. Mtime: 0,
  6570. Price: it.Price,
  6571. WarehousingDetailId: it.WarehouseInfotId,
  6572. WarehouseOutDetailId: it.ID,
  6573. CancelOutDetailId: cancelInfo.ID,
  6574. ProductDate: it.ProductDate,
  6575. ExpireDate: it.ExpiryDate,
  6576. StorehouseId: houseConfig.StorehouseOutInfo,
  6577. OverCount: over_count_one,
  6578. OperateTime: time.Now().Unix(),
  6579. }
  6580. service.CreateStockFlowOne(flow)
  6581. }
  6582. }
  6583. //查询已出库数量
  6584. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6585. if prescribingNumber < dialysisInfo.Count {
  6586. //改变数量
  6587. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6588. }
  6589. if prescribingNumber >= dialysisInfo.Count {
  6590. //删除出库表
  6591. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6592. }
  6593. //更新剩余库存
  6594. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6595. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6596. var total_count_one int64
  6597. for _, it := range stockList {
  6598. total_count_one += it.StockCount
  6599. }
  6600. //基础库插入数据
  6601. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6602. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6603. var flush_count int64
  6604. for _, it := range goodListOne {
  6605. flush_count += it.StockCount
  6606. }
  6607. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6608. if errs != nil {
  6609. goodErrcode := models.XtGoodErrcode{
  6610. UserOrgId: project.UserOrgId,
  6611. Errcode: "手动出库更新剩余出库失败",
  6612. GoodId: project.ProjectId,
  6613. Status: 1,
  6614. Ctime: time.Now().Unix(),
  6615. Mtime: 0,
  6616. Count: 0,
  6617. StockCount: 0,
  6618. Creater: creater,
  6619. BatchNumberId: 0,
  6620. WarehouseOutId: 0,
  6621. }
  6622. service.CreateGoodErrcode(goodErrcode)
  6623. }
  6624. }
  6625. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6626. fmt.Println(err)
  6627. } else {
  6628. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6629. fmt.Println(err)
  6630. }
  6631. }
  6632. c.ServeSuccessJSON(map[string]interface{}{
  6633. "msg": "删除成功",
  6634. })
  6635. return
  6636. }
  6637. func (c *HisApiController) CreateHisAdditionalCharge() {
  6638. his_patient_id, _ := c.GetInt64("his_patient_id")
  6639. patient_id, _ := c.GetInt64("patient_id")
  6640. record_date := c.GetString("record_date")
  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. adminInfo := c.GetAdminUserInfo()
  6649. recordDateTime := theTime.Unix()
  6650. dataBody := make(map[string]interface{}, 0)
  6651. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6652. if err != nil {
  6653. utils.ErrorLog(err.Error())
  6654. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6655. return
  6656. }
  6657. var additions []*models.HisAdditionalCharge
  6658. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  6659. additions, _ := dataBody["addition"].([]interface{})
  6660. if len(additions) > 0 {
  6661. for _, item := range additions {
  6662. items := item.(map[string]interface{})
  6663. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  6664. utils.ErrorLog("item_id")
  6665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6666. return
  6667. }
  6668. item_id := int64(items["item_id"].(float64))
  6669. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  6670. utils.ErrorLog("item_name")
  6671. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6672. return
  6673. }
  6674. item_name := items["item_name"].(string)
  6675. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  6676. utils.ErrorLog("price")
  6677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6678. return
  6679. }
  6680. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  6681. ctime := time.Now().Unix()
  6682. additional := &models.HisAdditionalCharge{
  6683. PatientId: patient_id,
  6684. HisPatientId: his_patient_id,
  6685. UserOrgId: adminInfo.CurrentOrgId,
  6686. RecordDate: recordDateTime,
  6687. CreatedTime: ctime,
  6688. UpdatedTime: ctime,
  6689. Modifier: adminInfo.AdminUser.Id,
  6690. Creator: adminInfo.AdminUser.Id,
  6691. Price: price,
  6692. ItemName: item_name,
  6693. ItemId: item_id,
  6694. Status: 1,
  6695. }
  6696. additions = append(additions, additional)
  6697. }
  6698. }
  6699. }
  6700. for _, item := range additions {
  6701. service.CreateAddtionalCharge(item)
  6702. }
  6703. c.ServeSuccessJSON(map[string]interface{}{
  6704. "msg": "创建成功",
  6705. })
  6706. }
  6707. func (c *HisApiController) CreateHisPatientCaseHistory() {
  6708. blood_fat := c.GetString("blood_fat")
  6709. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  6710. blood_sugar := c.GetString("blood_sugar")
  6711. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  6712. chief_conplaint := c.GetString("chief_conplaint")
  6713. dbp := c.GetString("dbp")
  6714. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  6715. delivery_way, _ := c.GetInt64("delivery_way")
  6716. diagnostic := c.GetString("diagnostic")
  6717. family_history := c.GetString("family_history")
  6718. height := c.GetString("height")
  6719. history_of_present_illness := c.GetString("history_of_present_illness")
  6720. is_infect, _ := c.GetInt64("is_infect")
  6721. past_history := c.GetString("past_history")
  6722. patient_id, _ := c.GetInt64("patient_id")
  6723. his_patient_id, _ := c.GetInt64("his_patient_id")
  6724. personal_history := c.GetString("personal_history")
  6725. pulse := c.GetString("pulse")
  6726. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  6727. sbp := c.GetString("sbp")
  6728. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  6729. heightfloat, _ := strconv.ParseFloat(height, 64)
  6730. sicktype := c.GetString("sick_type")
  6731. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  6732. symptom := c.GetString("symptom")
  6733. sick_date := c.GetString("sick_date")
  6734. temperatures := c.GetString("temperature")
  6735. temperature, _ := strconv.ParseFloat(temperatures, 64)
  6736. record_date := c.GetString("record_date")
  6737. breathing := c.GetString("breathing")
  6738. doctor_advice := c.GetString("doctor_advice")
  6739. remark := c.GetString("remark")
  6740. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  6741. sick, _ := c.GetInt64("sick")
  6742. diagnose, _ := c.GetInt64("diagnose")
  6743. //id, _ := c.GetInt64("id")
  6744. timeLayout := "2006-01-02"
  6745. loc, _ := time.LoadLocation("Local")
  6746. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6747. allergic_history := c.GetString("allergic_history")
  6748. if err != nil {
  6749. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6750. return
  6751. }
  6752. recordDateTime := theTime.Unix()
  6753. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  6754. if err != nil {
  6755. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6756. return
  6757. }
  6758. sickTimes := sickTime.Unix()
  6759. ctime := time.Now().Unix()
  6760. primary_disease := c.GetString("primary_disease")
  6761. confirm_failure_date := c.GetString("confirm_failure_date")
  6762. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  6763. drug_allergy_history := c.GetString("drug_allergy_history")
  6764. physical_examination := c.GetString("physical_examination")
  6765. special_inspection := c.GetString("special_inspection")
  6766. lab_apparatus := c.GetString("lab_apparatus")
  6767. caseHistory := models.HisPatientCaseHistory{
  6768. HisPatientId: his_patient_id,
  6769. PatientId: patient_id,
  6770. Temperature: temperature,
  6771. BloodSugar: bloodsugarfloat,
  6772. Pulse: pulsefloat,
  6773. Sbp: sbpfloat,
  6774. Dbp: dbpfloat,
  6775. Height: heightfloat,
  6776. BloodFat: bloodfatfloat,
  6777. SickType: sick_type,
  6778. Symptom: symptom,
  6779. SickDate: sickTimes,
  6780. IsInfect: is_infect,
  6781. HistoryOfPresentIllness: history_of_present_illness,
  6782. PastHistory: past_history,
  6783. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  6784. ChiefConplaint: chief_conplaint,
  6785. PersonalHistory: personal_history,
  6786. FamilyHistory: family_history,
  6787. Diagnostic: diagnostic,
  6788. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6789. Status: 1,
  6790. Ctime: ctime,
  6791. Mtime: ctime,
  6792. RecordDate: recordDateTime,
  6793. DeliveryWay: delivery_way,
  6794. Breathing: breathingfloat,
  6795. DoctorAdvice: doctor_advice,
  6796. Remark: remark,
  6797. Sick: sick,
  6798. Diagnose: diagnose,
  6799. AllergicHistory: allergic_history,
  6800. PrimaryDisease: primary_disease,
  6801. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  6802. DrugAllergyHistory: drug_allergy_history,
  6803. PhysicalExamination: physical_examination,
  6804. SpecialInspection: special_inspection,
  6805. LabApparatus: lab_apparatus,
  6806. }
  6807. //查询该患者是否有病历
  6808. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  6809. if errcodes == gorm.ErrRecordNotFound {
  6810. err = service.SaveHisPatientCaseHistory(&caseHistory)
  6811. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  6812. if err != nil {
  6813. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6814. return
  6815. }
  6816. c.ServeSuccessJSON(map[string]interface{}{
  6817. "caseHistory": caseHistory,
  6818. "historyInfo": historyInfo,
  6819. })
  6820. return
  6821. } else if errcodes == nil {
  6822. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  6823. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  6824. if err != nil {
  6825. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6826. return
  6827. }
  6828. c.ServeSuccessJSON(map[string]interface{}{
  6829. "caseHistory": caseHistory,
  6830. "historyInfo": historyInfo,
  6831. })
  6832. }
  6833. //查询该患者是否有病历
  6834. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  6835. //if errcode == gorm.ErrRecordNotFound {
  6836. // err = service.SaveHisPatientCaseHistory(caseHistory)
  6837. // if err != nil {
  6838. // c.ServeSuccessJSON(map[string]interface{}{
  6839. // "msg": "保存成功",
  6840. // })
  6841. // }
  6842. //} else if errcode == nil {
  6843. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6844. // return
  6845. //}
  6846. }
  6847. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  6848. patient_id, _ := c.GetInt64("patient_id", 0)
  6849. adminUser := c.GetAdminUserInfo()
  6850. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  6851. c.ServeSuccessJSON(map[string]interface{}{
  6852. "list": caseHistorys,
  6853. })
  6854. }
  6855. func (c *HisApiController) GetHisPatientCaseHistory() {
  6856. record_date, _ := c.GetInt64("record_date", 0)
  6857. patient_id, _ := c.GetInt64("patient_id", 0)
  6858. admin := c.GetAdminUserInfo()
  6859. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  6860. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  6861. c.ServeSuccessJSON(map[string]interface{}{
  6862. "info": info,
  6863. "case_history": case_history,
  6864. })
  6865. }
  6866. func (c *HisApiController) CreateCaseHistoryTemplate() {
  6867. template_name := c.GetString("template_name")
  6868. template_remark := c.GetString("template_remark")
  6869. doctor := c.GetAdminUserInfo().AdminUser.Id
  6870. diagnostic := c.GetString("diagnostic")
  6871. chief_conplaint := c.GetString("chief_conplain")
  6872. history_of_present_illness := c.GetString("history_of_present_illness")
  6873. past_history := c.GetString("past_history")
  6874. personal_history := c.GetString("personal_history")
  6875. family_history := c.GetString("family_history")
  6876. user_name := c.GetString("user_name")
  6877. doctor_advice := c.GetString("doctor_advice")
  6878. remark := c.GetString("remark")
  6879. //record_date := c.GetString("record_date")
  6880. //fmt.Println("record_date--------",record_date)
  6881. //timeLayout := "2006-01-02"
  6882. //loc, _ := time.LoadLocation("Local")
  6883. //
  6884. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6885. //if err != nil {
  6886. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6887. // return
  6888. //}
  6889. //recordDateTime := theTime.Unix()
  6890. ctime := time.Now().Unix()
  6891. template := models.HisCaseHistoryTemplate{
  6892. HistoryOfPresentIllness: history_of_present_illness,
  6893. PastHistory: past_history,
  6894. ChiefConplaint: chief_conplaint,
  6895. PersonalHistory: personal_history,
  6896. FamilyHistory: family_history,
  6897. Diagnostic: diagnostic,
  6898. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6899. Status: 1,
  6900. Ctime: ctime,
  6901. Mtime: ctime,
  6902. RecordDate: time.Now().Unix(),
  6903. TemplateName: template_name,
  6904. TemplateRemark: template_remark,
  6905. Creator: doctor,
  6906. Modifier: doctor,
  6907. UserName: user_name,
  6908. DoctorAdvice: doctor_advice,
  6909. Remark: remark,
  6910. }
  6911. err := service.SaveHisPatientCaseHistoryTemplate(template)
  6912. if err == nil {
  6913. c.ServeSuccessJSON(map[string]interface{}{
  6914. "msg": "保存成功",
  6915. })
  6916. } else {
  6917. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6918. return
  6919. }
  6920. }
  6921. func (c *HisApiController) GetCaseHistoryTemplate() {
  6922. timeLayout := "2006-01-02"
  6923. loc, _ := time.LoadLocation("Local")
  6924. keyword := c.GetString("keyword")
  6925. start_time := c.GetString("start_time")
  6926. end_time := c.GetString("end_time")
  6927. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6928. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6929. admin := c.GetAdminUserInfo()
  6930. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  6931. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  6932. c.ServeSuccessJSON(map[string]interface{}{
  6933. "template": template,
  6934. //"history": history,
  6935. })
  6936. }
  6937. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6938. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6939. utils.ErrorLog("drug_name")
  6940. return enums.ErrorCodeParamWrong
  6941. }
  6942. adviceName, _ := json["drug_name"].(string)
  6943. if len(adviceName) == 0 {
  6944. utils.ErrorLog("len(advice_name) == 0")
  6945. return enums.ErrorCodeParamWrong
  6946. }
  6947. advice.AdviceName = adviceName
  6948. adviceDesc, _ := json["advice_desc"].(string)
  6949. advice.AdviceDesc = adviceDesc
  6950. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6951. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6952. advice.DrugSpec = drugSpec
  6953. }
  6954. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6955. remark, _ := json["remark"].(string)
  6956. advice.Remark = remark
  6957. }
  6958. if json["id"] == nil {
  6959. advice.DrugId = 0
  6960. } else {
  6961. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6962. drug_id := int64(json["id"].(float64))
  6963. advice.DrugId = drug_id
  6964. }
  6965. }
  6966. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6967. advice_id := int64(json["advice_id"].(float64))
  6968. advice.ID = advice_id
  6969. if advice.ID > 0 {
  6970. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6971. if err == nil {
  6972. if hisAdvice.ID > 0 {
  6973. advice.ExecutionTime = hisAdvice.ExecutionTime
  6974. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6975. advice.ExecutionState = hisAdvice.ExecutionState
  6976. advice.CheckTime = hisAdvice.CheckTime
  6977. advice.Checker = hisAdvice.Checker
  6978. advice.CheckState = hisAdvice.CheckState
  6979. advice.StartTime = hisAdvice.StartTime
  6980. advice.FeedetlSn = hisAdvice.FeedetlSn
  6981. }
  6982. }
  6983. }
  6984. }
  6985. //
  6986. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6987. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6988. // advice.ExecutionTime = execution_time
  6989. //}
  6990. //
  6991. //
  6992. //
  6993. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6994. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6995. // advice.ExecutionStaff = execution_staff
  6996. //}
  6997. //
  6998. //
  6999. //
  7000. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7001. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7002. // advice.ExecutionState = execution_state
  7003. //}
  7004. //
  7005. //
  7006. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7007. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7008. // advice.CheckTime = check_time
  7009. //}
  7010. //
  7011. //
  7012. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7013. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7014. // advice.CheckState = check_state
  7015. //}
  7016. //
  7017. //
  7018. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7019. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7020. // advice.Checker = checker
  7021. //}
  7022. //
  7023. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7024. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7025. // advice.StartTime = start_time
  7026. //}
  7027. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7028. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7029. advice.IsSelfDrug = is_self_drug
  7030. }
  7031. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7032. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7033. drug_way_count, _ := json["drug_way_count"].(string)
  7034. advice.DrugWayCount = drug_way_count
  7035. }
  7036. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7037. drugSpecUnit, _ := json["min_unit"].(string)
  7038. advice.DrugSpecUnit = drugSpecUnit
  7039. }
  7040. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7041. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7042. advice.SingleDose = singleDose
  7043. }
  7044. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7045. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7046. advice.SingleDoseUnit = singleDoseUnit
  7047. }
  7048. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7049. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7050. advice.PrescribingNumber = prescribingNumber
  7051. }
  7052. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7053. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7054. advice.PrescribingNumberUnit = prescribingNumberUnit
  7055. }
  7056. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7057. deliveryWay, _ := json["delivery_way"].(string)
  7058. advice.DeliveryWay = deliveryWay
  7059. }
  7060. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7061. executionFrequency, _ := json["execution_frequency"].(string)
  7062. advice.ExecutionFrequency = executionFrequency
  7063. }
  7064. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7065. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7066. advice.Price = price
  7067. }
  7068. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7069. med_list_codg, _ := json["medical_insurance_number"].(string)
  7070. advice.MedListCodg = med_list_codg
  7071. }
  7072. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7073. day := int64(json["day"].(float64))
  7074. advice.Day = day
  7075. }
  7076. return 0
  7077. }
  7078. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7079. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7080. id := int64(json["id"].(float64))
  7081. project.ID = id
  7082. historyProject, _ := service.GetHisProjectByID(id)
  7083. project.FeedetlSn = historyProject.FeedetlSn
  7084. }
  7085. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7086. project_id := int64(json["project_id"].(float64))
  7087. project.ProjectId = project_id
  7088. }
  7089. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7090. // price := int64(json["price"].(float64))
  7091. // formatInt_price := strconv.FormatInt(price, 10)
  7092. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7093. // project.Price = float_price
  7094. // }
  7095. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7096. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7097. project.Price = price
  7098. }
  7099. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7100. total, _ := json["total"].(string)
  7101. project.Count = total
  7102. }
  7103. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7104. medical_code, _ := json["medical_code"].(string)
  7105. project.MedListCodg = medical_code
  7106. }
  7107. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7108. single_dose, _ := json["single_dose"].(string)
  7109. project.SingleDose = single_dose
  7110. }
  7111. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7112. delivery_way, _ := json["delivery_way"].(string)
  7113. project.DeliveryWay = delivery_way
  7114. }
  7115. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7116. execution_frequency, _ := json["execution_frequency"].(string)
  7117. project.ExecutionFrequency = execution_frequency
  7118. }
  7119. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7120. remark, _ := json["remark"].(string)
  7121. project.Remark = remark
  7122. }
  7123. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7124. day, _ := json["number_days"].(string)
  7125. project.Day = day
  7126. }
  7127. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7128. unit, _ := json["unit"].(string)
  7129. project.Unit = unit
  7130. }
  7131. return 0
  7132. }
  7133. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7134. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7135. id := int64(json["id"].(float64))
  7136. historyAddtions, _ := service.GetHisAdditionByID(id)
  7137. additionalCharge.ID = id
  7138. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  7139. }
  7140. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7141. item_id := int64(json["item_id"].(float64))
  7142. additionalCharge.ItemId = item_id
  7143. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7144. if config.ID > 0 {
  7145. if len(config.Code) > 0 {
  7146. additionalCharge.MedListCodg = config.Code
  7147. }
  7148. }
  7149. }
  7150. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7151. // price := int64(json["price"].(float64))
  7152. // formatInt_price := strconv.FormatInt(price, 10)
  7153. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7154. // additionalCharge.Price = float_price
  7155. // }
  7156. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7157. // price := int64(json["price"].(float64))
  7158. // formatInt_price := strconv.FormatInt(price, 10)
  7159. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7160. // additionalCharge.Price = float_price
  7161. //}
  7162. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7163. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7164. additionalCharge.Price = price
  7165. }
  7166. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  7167. count, _ := json["count"].(string)
  7168. counts, _ := strconv.ParseInt(count, 10, 64)
  7169. additionalCharge.Count = counts
  7170. }
  7171. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  7172. item_name, _ := json["item_name"].(string)
  7173. additionalCharge.ItemName = item_name
  7174. }
  7175. return 0
  7176. }
  7177. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7178. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7179. utils.ErrorLog("drug_name")
  7180. return enums.ErrorCodeParamWrong
  7181. }
  7182. adviceName, _ := json["drug_name"].(string)
  7183. if len(adviceName) == 0 {
  7184. utils.ErrorLog("len(advice_name) == 0")
  7185. return enums.ErrorCodeParamWrong
  7186. }
  7187. advice.AdviceName = adviceName
  7188. adviceDesc, _ := json["advice_desc"].(string)
  7189. advice.AdviceDesc = adviceDesc
  7190. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7191. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7192. advice.DrugSpec = drugSpec
  7193. }
  7194. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7195. remark, _ := json["remark"].(string)
  7196. advice.Remark = remark
  7197. }
  7198. if json["id"] == nil {
  7199. advice.DrugId = 0
  7200. } else {
  7201. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7202. drug_id := int64(json["id"].(float64))
  7203. advice.DrugId = drug_id
  7204. }
  7205. }
  7206. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7207. groupno := int64(json["groupno"].(float64))
  7208. advice.Groupno = groupno
  7209. }
  7210. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7211. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7212. advice.IsSelfDrug = is_self_drug
  7213. }
  7214. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7215. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7216. drug_way_count, _ := json["drug_way_count"].(string)
  7217. advice.DrugWayCount = drug_way_count
  7218. }
  7219. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7220. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7221. advice.HospApprFlag = hosp_appr_flag
  7222. }
  7223. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7224. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7225. advice.PrescribingNumber = prescribingNumber
  7226. }
  7227. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7228. // frequency_type := int64(json["frequency_type"].(float64))
  7229. // advice.FrequencyType = frequency_type
  7230. //}
  7231. //
  7232. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7233. // day_count := int64(json["day_count"].(float64))
  7234. // advice.DayCount = day_count
  7235. //}
  7236. //
  7237. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7238. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7239. // week_day, _ := json["week_day"].(string)
  7240. // advice.WeekDay = week_day
  7241. //}
  7242. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7243. drugSpecUnit, _ := json["min_unit"].(string)
  7244. advice.DrugSpecUnit = drugSpecUnit
  7245. }
  7246. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7247. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7248. advice.SingleDose = singleDose
  7249. }
  7250. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7251. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7252. advice.SingleDoseUnit = singleDoseUnit
  7253. }
  7254. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7255. deliveryWay, _ := json["delivery_way"].(string)
  7256. advice.DeliveryWay = deliveryWay
  7257. }
  7258. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7259. executionFrequency, _ := json["execution_frequency"].(string)
  7260. advice.ExecutionFrequency = executionFrequency
  7261. }
  7262. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7263. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7264. advice.Price = price
  7265. }
  7266. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7267. med_list_codg, _ := json["medical_insurance_number"].(string)
  7268. advice.MedListCodg = med_list_codg
  7269. }
  7270. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7271. day := int64(json["day"].(float64))
  7272. advice.Day = day
  7273. }
  7274. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7275. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7276. advice.PrescribingNumberUnit = prescribingNumberUnit
  7277. }
  7278. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7279. advice_id := int64(json["advice_id"].(float64))
  7280. advice.ID = advice_id
  7281. if advice.ID > 0 {
  7282. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7283. if err == nil {
  7284. if hisAdvice.ID > 0 {
  7285. advice.ExecutionTime = hisAdvice.ExecutionTime
  7286. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7287. advice.ExecutionState = hisAdvice.ExecutionState
  7288. advice.CheckTime = hisAdvice.CheckTime
  7289. advice.Checker = hisAdvice.Checker
  7290. advice.CheckState = hisAdvice.CheckState
  7291. advice.StartTime = hisAdvice.StartTime
  7292. advice.HospApprFlag = hisAdvice.HospApprFlag
  7293. advice.IsMedicine = hisAdvice.IsMedicine
  7294. if hisAdvice.UserOrgId == 10028 {
  7295. 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 {
  7296. advice.ExecutionTime = 0
  7297. advice.ExecutionStaff = 0
  7298. advice.ExecutionState = 2
  7299. advice.CheckTime = 0
  7300. advice.Checker = 0
  7301. advice.CheckState = 2
  7302. }
  7303. } else {
  7304. 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 {
  7305. advice.ExecutionTime = 0
  7306. advice.ExecutionStaff = 0
  7307. advice.ExecutionState = 2
  7308. advice.CheckTime = 0
  7309. advice.Checker = 0
  7310. advice.CheckState = 2
  7311. advice.UpdatedTime = time.Now().Unix()
  7312. }
  7313. }
  7314. //advice.Groupno = hisAdvice.Groupno
  7315. }
  7316. }
  7317. }
  7318. }
  7319. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7320. //
  7321. //if drugStockConfig.IsOpen == 1 {
  7322. //
  7323. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7324. // if advice.ID == 0 { //医嘱不存在
  7325. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7326. // drug.Total = drug.Total - advice.PrescribingNumber
  7327. // service.UpdateBaseDrugLib(&drug)
  7328. //
  7329. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7330. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7331. // drug.Total = drug.Total - num
  7332. // service.UpdateBaseDrugLib(&drug)
  7333. // }
  7334. //
  7335. // } else if advice.ID > 0 { //医嘱存在
  7336. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7337. // var num float64
  7338. //
  7339. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7340. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7341. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7342. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7343. // drug.Total = drug.Total + num
  7344. // service.UpdateBaseDrugLib(&drug)
  7345. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7346. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7347. // drug.Total = drug.Total - num
  7348. // service.UpdateBaseDrugLib(&drug)
  7349. // }
  7350. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7351. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7352. // if num2 > advice.PrescribingNumber {
  7353. // num = num2 - advice.PrescribingNumber
  7354. // drug.Total = drug.Total + num
  7355. // service.UpdateBaseDrugLib(&drug)
  7356. // } else if num2 < advice.PrescribingNumber {
  7357. // num = advice.PrescribingNumber - num2
  7358. // drug.Total = drug.Total - num
  7359. // service.UpdateBaseDrugLib(&drug)
  7360. // }
  7361. //
  7362. // }
  7363. //
  7364. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7365. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7366. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7367. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7368. // if num1 > num2 {
  7369. // num = num1 - num2
  7370. // drug.Total = drug.Total + num
  7371. // service.UpdateBaseDrugLib(&drug)
  7372. // } else if num1 < num2 {
  7373. // num = num2 - num1
  7374. // drug.Total = drug.Total - num
  7375. // service.UpdateBaseDrugLib(&drug)
  7376. // }
  7377. //
  7378. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7379. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7380. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7381. // if hisAdvice.PrescribingNumber > num2 {
  7382. // num = hisAdvice.PrescribingNumber - num2
  7383. // drug.Total = drug.Total + num
  7384. // service.UpdateBaseDrugLib(&drug)
  7385. // } else if num2 < advice.PrescribingNumber {
  7386. // num = num2 - hisAdvice.PrescribingNumber
  7387. // drug.Total = drug.Total - num
  7388. // service.UpdateBaseDrugLib(&drug)
  7389. // }
  7390. //
  7391. // }
  7392. // }
  7393. // }
  7394. //}
  7395. //
  7396. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7397. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7398. // advice.ExecutionTime = execution_time
  7399. //}
  7400. //
  7401. //
  7402. //
  7403. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7404. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7405. // advice.ExecutionStaff = execution_staff
  7406. //}
  7407. //
  7408. //
  7409. //
  7410. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7411. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7412. // advice.ExecutionState = execution_state
  7413. //}
  7414. //
  7415. //
  7416. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7417. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7418. // advice.CheckTime = check_time
  7419. //}
  7420. //
  7421. //
  7422. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7423. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7424. // advice.CheckState = check_state
  7425. //}
  7426. //
  7427. //
  7428. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7429. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7430. // advice.Checker = checker
  7431. //}
  7432. //
  7433. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7434. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7435. // advice.StartTime = start_time
  7436. //}
  7437. return 0
  7438. }
  7439. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7440. project.ExecutionStaff = 0
  7441. project.ExecutionState = 2
  7442. project.ExecutionTime = 0
  7443. project.Checker = 0
  7444. project.CheckState = 2
  7445. project.CheckTime = 0
  7446. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7447. id := int64(json["id"].(float64))
  7448. project.ID = id
  7449. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7450. project.ExecutionStaff = temp_project.ExecutionStaff
  7451. project.ExecutionState = temp_project.ExecutionState
  7452. project.ExecutionTime = temp_project.ExecutionTime
  7453. project.Checker = temp_project.Checker
  7454. project.CheckState = temp_project.CheckState
  7455. project.CheckTime = temp_project.CheckTime
  7456. project.TeamId = temp_project.TeamId
  7457. }
  7458. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7459. types := int64(json["type"].(float64))
  7460. project.Type = types
  7461. }
  7462. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7463. project_id := int64(json["project_id"].(float64))
  7464. project.ProjectId = project_id
  7465. }
  7466. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7467. team_id := int64(json["team_id"].(float64))
  7468. project.TeamId = team_id
  7469. }
  7470. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7471. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7472. project.Price = price
  7473. }
  7474. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7475. total, _ := json["total"].(string)
  7476. //totals, _ := strconv.ParseInt(total, 10, 64)
  7477. project.Count = total
  7478. }
  7479. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7480. medical_code, _ := json["medical_code"].(string)
  7481. project.MedListCodg = medical_code
  7482. }
  7483. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7484. single_dose, _ := json["single_dose"].(string)
  7485. project.SingleDose = single_dose
  7486. }
  7487. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7488. delivery_way, _ := json["delivery_way"].(string)
  7489. project.DeliveryWay = delivery_way
  7490. }
  7491. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7492. execution_frequency, _ := json["execution_frequency"].(string)
  7493. project.ExecutionFrequency = execution_frequency
  7494. }
  7495. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7496. remark, _ := json["remark"].(string)
  7497. project.Remark = remark
  7498. }
  7499. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7500. day, _ := json["number_days"].(string)
  7501. project.Day = day
  7502. }
  7503. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7504. unit, _ := json["unit"].(string)
  7505. project.Unit = unit
  7506. }
  7507. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7508. // frequency_type := int64(json["frequency_type"].(float64))
  7509. // project.FrequencyType = frequency_type
  7510. //}
  7511. //
  7512. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7513. // day_count := int64(json["day_count"].(float64))
  7514. // project.DayCount = day_count
  7515. //}
  7516. //
  7517. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7518. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7519. // week_day, _ := json["week_day"].(string)
  7520. // project.WeekDay = week_day
  7521. //}
  7522. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7523. //
  7524. //if project.ID == 0 {
  7525. // if stockConfig.IsOpen == 1 {
  7526. // if project.Type == 3 {
  7527. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7528. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7529. // good.Total = good.Total - f_count
  7530. // service.UpdateGoodInfo(&good)
  7531. // }
  7532. // }
  7533. //
  7534. //} else {
  7535. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7536. //
  7537. // if stockConfig.IsOpen == 1 {
  7538. // if project.Type == 3 {
  7539. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7540. // if project.Count < temp_project.Count {
  7541. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7542. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7543. //
  7544. // other_count := f_count_two - f_count_one
  7545. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7546. // good.Total = good.Total + other_count_two
  7547. // service.UpdateGoodInfo(&good)
  7548. // } else if project.Count > temp_project.Count {
  7549. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7550. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7551. //
  7552. // other_count := f_count_one - f_count_two
  7553. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7554. // good.Total = good.Total - other_count_two
  7555. // service.UpdateGoodInfo(&good)
  7556. // }
  7557. //
  7558. // }
  7559. // }
  7560. //
  7561. //}
  7562. return 0
  7563. }
  7564. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7565. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7566. utils.ErrorLog("drug_name")
  7567. return enums.ErrorCodeParamWrong
  7568. }
  7569. adviceName, _ := json["drug_name"].(string)
  7570. if len(adviceName) == 0 {
  7571. utils.ErrorLog("len(advice_name) == 0")
  7572. return enums.ErrorCodeParamWrong
  7573. }
  7574. advice.AdviceName = adviceName
  7575. adviceDesc, _ := json["advice_desc"].(string)
  7576. advice.AdviceDesc = adviceDesc
  7577. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7578. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7579. advice.DrugSpec = drugSpec
  7580. }
  7581. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7582. remark, _ := json["remark"].(string)
  7583. advice.Remark = remark
  7584. }
  7585. if json["id"] == nil {
  7586. advice.DrugId = 0
  7587. } else {
  7588. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7589. drug_id := int64(json["id"].(float64))
  7590. advice.DrugId = drug_id
  7591. }
  7592. }
  7593. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7594. groupno := int64(json["groupno"].(float64))
  7595. advice.Groupno = groupno
  7596. }
  7597. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7598. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7599. advice.IsSelfDrug = is_self_drug
  7600. }
  7601. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7602. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7603. drug_way_count, _ := json["drug_way_count"].(string)
  7604. advice.DrugWayCount = drug_way_count
  7605. }
  7606. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7607. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7608. advice.HospApprFlag = hosp_appr_flag
  7609. }
  7610. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7611. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7612. advice.PrescribingNumber = prescribingNumber
  7613. }
  7614. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7615. // frequency_type := int64(json["frequency_type"].(float64))
  7616. // advice.FrequencyType = frequency_type
  7617. //}
  7618. //
  7619. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7620. // day_count := int64(json["day_count"].(float64))
  7621. // advice.DayCount = day_count
  7622. //}
  7623. //
  7624. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7625. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7626. // week_day, _ := json["week_day"].(string)
  7627. // advice.WeekDay = week_day
  7628. //}
  7629. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7630. drugSpecUnit, _ := json["min_unit"].(string)
  7631. advice.DrugSpecUnit = drugSpecUnit
  7632. }
  7633. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7634. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7635. advice.SingleDose = singleDose
  7636. }
  7637. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7638. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7639. advice.SingleDoseUnit = singleDoseUnit
  7640. }
  7641. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7642. deliveryWay, _ := json["delivery_way"].(string)
  7643. advice.DeliveryWay = deliveryWay
  7644. }
  7645. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7646. executionFrequency, _ := json["execution_frequency"].(string)
  7647. advice.ExecutionFrequency = executionFrequency
  7648. }
  7649. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7650. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7651. advice.Price = price
  7652. }
  7653. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7654. med_list_codg, _ := json["medical_insurance_number"].(string)
  7655. advice.MedListCodg = med_list_codg
  7656. }
  7657. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7658. day := int64(json["day"].(float64))
  7659. advice.Day = day
  7660. }
  7661. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7662. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7663. advice.PrescribingNumberUnit = prescribingNumberUnit
  7664. }
  7665. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7666. advice_id := int64(json["advice_id"].(float64))
  7667. advice.ID = advice_id
  7668. if advice.ID > 0 {
  7669. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7670. if err == nil {
  7671. if hisAdvice.ID > 0 {
  7672. advice.ExecutionTime = hisAdvice.ExecutionTime
  7673. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7674. advice.ExecutionState = hisAdvice.ExecutionState
  7675. advice.CheckTime = hisAdvice.CheckTime
  7676. advice.Checker = hisAdvice.Checker
  7677. advice.DrugCode = hisAdvice.DrugCode
  7678. advice.CheckState = hisAdvice.CheckState
  7679. advice.StartTime = hisAdvice.StartTime
  7680. advice.HospApprFlag = hisAdvice.HospApprFlag
  7681. advice.IsMedicine = hisAdvice.IsMedicine
  7682. if hisAdvice.UserOrgId == 10028 {
  7683. 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 {
  7684. advice.ExecutionTime = 0
  7685. advice.ExecutionStaff = 0
  7686. advice.ExecutionState = 2
  7687. advice.CheckTime = 0
  7688. advice.Checker = 0
  7689. advice.CheckState = 2
  7690. }
  7691. } else {
  7692. if hisAdvice.SingleDoseUnit != advice.SingleDoseUnit || 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 {
  7693. advice.ExecutionTime = 0
  7694. advice.ExecutionStaff = 0
  7695. advice.ExecutionState = 2
  7696. advice.CheckTime = 0
  7697. advice.Checker = 0
  7698. advice.CheckState = 2
  7699. //advice.UpdatedTime = time.Now().Unix()
  7700. advice.CreatedTime = hisAdvice.CreatedTime
  7701. advice.UpdatedTime = time.Now().Unix()
  7702. } else {
  7703. advice.CreatedTime = hisAdvice.CreatedTime
  7704. advice.UpdatedTime = hisAdvice.UpdatedTime
  7705. }
  7706. }
  7707. //advice.Groupno = hisAdvice.Groupno
  7708. } else {
  7709. advice.IsMedicine = 0
  7710. ctime := time.Now().Unix()
  7711. advice.CreatedTime = ctime
  7712. advice.UpdatedTime = ctime
  7713. }
  7714. }
  7715. } else {
  7716. advice.IsMedicine = 0
  7717. ctime := time.Now().Unix()
  7718. advice.CreatedTime = ctime
  7719. advice.UpdatedTime = ctime
  7720. }
  7721. }
  7722. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7723. //
  7724. //if drugStockConfig.IsOpen == 1 {
  7725. //
  7726. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7727. // if advice.ID == 0 { //医嘱不存在
  7728. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7729. // drug.Total = drug.Total - advice.PrescribingNumber
  7730. // service.UpdateBaseDrugLib(&drug)
  7731. //
  7732. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7733. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7734. // drug.Total = drug.Total - num
  7735. // service.UpdateBaseDrugLib(&drug)
  7736. // }
  7737. //
  7738. // } else if advice.ID > 0 { //医嘱存在
  7739. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7740. // var num float64
  7741. //
  7742. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7743. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7744. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7745. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7746. // drug.Total = drug.Total + num
  7747. // service.UpdateBaseDrugLib(&drug)
  7748. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7749. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7750. // drug.Total = drug.Total - num
  7751. // service.UpdateBaseDrugLib(&drug)
  7752. // }
  7753. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7754. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7755. // if num2 > advice.PrescribingNumber {
  7756. // num = num2 - advice.PrescribingNumber
  7757. // drug.Total = drug.Total + num
  7758. // service.UpdateBaseDrugLib(&drug)
  7759. // } else if num2 < advice.PrescribingNumber {
  7760. // num = advice.PrescribingNumber - num2
  7761. // drug.Total = drug.Total - num
  7762. // service.UpdateBaseDrugLib(&drug)
  7763. // }
  7764. //
  7765. // }
  7766. //
  7767. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7768. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7769. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7770. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7771. // if num1 > num2 {
  7772. // num = num1 - num2
  7773. // drug.Total = drug.Total + num
  7774. // service.UpdateBaseDrugLib(&drug)
  7775. // } else if num1 < num2 {
  7776. // num = num2 - num1
  7777. // drug.Total = drug.Total - num
  7778. // service.UpdateBaseDrugLib(&drug)
  7779. // }
  7780. //
  7781. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7782. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7783. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7784. // if hisAdvice.PrescribingNumber > num2 {
  7785. // num = hisAdvice.PrescribingNumber - num2
  7786. // drug.Total = drug.Total + num
  7787. // service.UpdateBaseDrugLib(&drug)
  7788. // } else if num2 < advice.PrescribingNumber {
  7789. // num = num2 - hisAdvice.PrescribingNumber
  7790. // drug.Total = drug.Total - num
  7791. // service.UpdateBaseDrugLib(&drug)
  7792. // }
  7793. //
  7794. // }
  7795. // }
  7796. // }
  7797. //}
  7798. //
  7799. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7800. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7801. // advice.ExecutionTime = execution_time
  7802. //}
  7803. //
  7804. //
  7805. //
  7806. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7807. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7808. // advice.ExecutionStaff = execution_staff
  7809. //}
  7810. //
  7811. //
  7812. //
  7813. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7814. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7815. // advice.ExecutionState = execution_state
  7816. //}
  7817. //
  7818. //
  7819. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7820. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7821. // advice.CheckTime = check_time
  7822. //}
  7823. //
  7824. //
  7825. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7826. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7827. // advice.CheckState = check_state
  7828. //}
  7829. //
  7830. //
  7831. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7832. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7833. // advice.Checker = checker
  7834. //}
  7835. //
  7836. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7837. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7838. // advice.StartTime = start_time
  7839. //}
  7840. return 0
  7841. }
  7842. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7843. project.ExecutionStaff = 0
  7844. project.ExecutionState = 2
  7845. project.ExecutionTime = 0
  7846. project.Checker = 0
  7847. project.CheckState = 2
  7848. project.CheckTime = 0
  7849. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7850. id := int64(json["id"].(float64))
  7851. project.ID = id
  7852. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7853. project.ExecutionStaff = temp_project.ExecutionStaff
  7854. project.ExecutionState = temp_project.ExecutionState
  7855. project.ExecutionTime = temp_project.ExecutionTime
  7856. project.Checker = temp_project.Checker
  7857. project.CheckState = temp_project.CheckState
  7858. project.CheckTime = temp_project.CheckTime
  7859. project.TeamId = temp_project.TeamId
  7860. }
  7861. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7862. types := int64(json["type"].(float64))
  7863. project.Type = types
  7864. }
  7865. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7866. project_id := int64(json["project_id"].(float64))
  7867. project.ProjectId = project_id
  7868. }
  7869. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7870. team_id := int64(json["team_id"].(float64))
  7871. project.TeamId = team_id
  7872. }
  7873. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7874. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7875. project.Price = price
  7876. }
  7877. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7878. total, _ := json["total"].(string)
  7879. //totals, _ := strconv.ParseInt(total, 10, 64)
  7880. project.Count = total
  7881. }
  7882. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7883. medical_code, _ := json["medical_code"].(string)
  7884. project.MedListCodg = medical_code
  7885. }
  7886. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7887. single_dose, _ := json["single_dose"].(string)
  7888. project.SingleDose = single_dose
  7889. }
  7890. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7891. delivery_way, _ := json["delivery_way"].(string)
  7892. project.DeliveryWay = delivery_way
  7893. }
  7894. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7895. execution_frequency, _ := json["execution_frequency"].(string)
  7896. project.ExecutionFrequency = execution_frequency
  7897. }
  7898. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7899. remark, _ := json["remark"].(string)
  7900. project.Remark = remark
  7901. }
  7902. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7903. day, _ := json["number_days"].(string)
  7904. project.Day = day
  7905. }
  7906. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7907. unit, _ := json["unit"].(string)
  7908. project.Unit = unit
  7909. }
  7910. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7911. // frequency_type := int64(json["frequency_type"].(float64))
  7912. // project.FrequencyType = frequency_type
  7913. //}
  7914. //
  7915. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7916. // day_count := int64(json["day_count"].(float64))
  7917. // project.DayCount = day_count
  7918. //}
  7919. //
  7920. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7921. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7922. // week_day, _ := json["week_day"].(string)
  7923. // project.WeekDay = week_day
  7924. //}
  7925. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7926. //
  7927. //if project.ID == 0 {
  7928. // if stockConfig.IsOpen == 1 {
  7929. // if project.Type == 3 {
  7930. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7931. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7932. // good.Total = good.Total - f_count
  7933. // service.UpdateGoodInfo(&good)
  7934. // }
  7935. // }
  7936. //
  7937. //} else {
  7938. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7939. //
  7940. // if stockConfig.IsOpen == 1 {
  7941. // if project.Type == 3 {
  7942. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7943. // if project.Count < temp_project.Count {
  7944. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7945. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7946. //
  7947. // other_count := f_count_two - f_count_one
  7948. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7949. // good.Total = good.Total + other_count_two
  7950. // service.UpdateGoodInfo(&good)
  7951. // } else if project.Count > temp_project.Count {
  7952. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7953. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7954. //
  7955. // other_count := f_count_one - f_count_two
  7956. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7957. // good.Total = good.Total - other_count_two
  7958. // service.UpdateGoodInfo(&good)
  7959. // }
  7960. //
  7961. // }
  7962. // }
  7963. //
  7964. //}
  7965. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7966. id := int64(json["id"].(float64))
  7967. if id > 0 {
  7968. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7969. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  7970. fmt.Println("666666")
  7971. project.Mtime = time.Now().Unix()
  7972. project.Ctime = temp_project.Ctime
  7973. } else {
  7974. project.Mtime = temp_project.Mtime
  7975. project.Ctime = temp_project.Ctime
  7976. }
  7977. } else {
  7978. ctime := time.Now().Unix()
  7979. project.Mtime = ctime
  7980. project.Ctime = ctime
  7981. }
  7982. }
  7983. return 0
  7984. }
  7985. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7986. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7987. id := int64(json["id"].(float64))
  7988. additionalCharge.ID = id
  7989. }
  7990. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7991. item_id := int64(json["item_id"].(float64))
  7992. additionalCharge.ItemId = item_id
  7993. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7994. if config.ID > 0 {
  7995. if len(config.Code) > 0 {
  7996. additionalCharge.MedListCodg = config.Code
  7997. }
  7998. }
  7999. }
  8000. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8001. // price := int64(json["price"].(float64))
  8002. // formatInt_price := strconv.FormatInt(price, 10)
  8003. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8004. // additionalCharge.Price = float_price
  8005. // }
  8006. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8007. // price := int64(json["price"].(float64))
  8008. // formatInt_price := strconv.FormatInt(price, 10)
  8009. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8010. // additionalCharge.Price = float_price
  8011. //}
  8012. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8013. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8014. additionalCharge.Price = price
  8015. }
  8016. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  8017. count, _ := json["count"].(string)
  8018. counts, _ := strconv.ParseInt(count, 10, 64)
  8019. additionalCharge.Count = counts
  8020. }
  8021. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  8022. item_name, _ := json["item_name"].(string)
  8023. additionalCharge.ItemName = item_name
  8024. }
  8025. return 0
  8026. }
  8027. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  8028. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8029. utils.ErrorLog("drug_name")
  8030. return enums.ErrorCodeParamWrong
  8031. }
  8032. adviceName, _ := json["drug_name"].(string)
  8033. if len(adviceName) == 0 {
  8034. utils.ErrorLog("len(advice_name) == 0")
  8035. return enums.ErrorCodeParamWrong
  8036. }
  8037. advice.AdviceName = adviceName
  8038. adviceDesc, _ := json["advice_desc"].(string)
  8039. advice.AdviceDesc = adviceDesc
  8040. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8041. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8042. advice.DrugSpec = drugSpec
  8043. }
  8044. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8045. remark, _ := json["remark"].(string)
  8046. advice.Remark = remark
  8047. }
  8048. if json["id"] == nil {
  8049. advice.DrugId = 0
  8050. } else {
  8051. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8052. drug_id := int64(json["id"].(float64))
  8053. advice.DrugId = drug_id
  8054. }
  8055. }
  8056. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8057. groupno := int64(json["groupno"].(float64))
  8058. advice.Groupno = groupno
  8059. }
  8060. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8061. drugSpecUnit, _ := json["min_unit"].(string)
  8062. advice.DrugSpecUnit = drugSpecUnit
  8063. }
  8064. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8065. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8066. advice.SingleDose = singleDose
  8067. }
  8068. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8069. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8070. advice.SingleDoseUnit = singleDoseUnit
  8071. }
  8072. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8073. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8074. advice.PrescribingNumber = prescribingNumber
  8075. }
  8076. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8077. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8078. advice.PrescribingNumberUnit = prescribingNumberUnit
  8079. }
  8080. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8081. deliveryWay, _ := json["delivery_way"].(string)
  8082. advice.DeliveryWay = deliveryWay
  8083. }
  8084. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8085. executionFrequency, _ := json["execution_frequency"].(string)
  8086. advice.ExecutionFrequency = executionFrequency
  8087. }
  8088. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8089. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8090. advice.Price = price
  8091. }
  8092. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8093. med_list_codg, _ := json["medical_insurance_number"].(string)
  8094. advice.MedListCodg = med_list_codg
  8095. }
  8096. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8097. day := int64(json["day"].(float64))
  8098. advice.Day = day
  8099. }
  8100. advice.FrequencyType = 1
  8101. return 0
  8102. }
  8103. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  8104. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8105. types := int64(json["type"].(float64))
  8106. project.Type = types
  8107. }
  8108. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8109. project_id := int64(json["project_id"].(float64))
  8110. project.ProjectId = project_id
  8111. }
  8112. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8113. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8114. project.Price = price
  8115. }
  8116. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8117. total, _ := json["total"].(string)
  8118. //totals, _ := strconv.ParseInt(total, 10, 64)
  8119. project.Count = total
  8120. }
  8121. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8122. medical_code, _ := json["medical_code"].(string)
  8123. project.MedListCodg = medical_code
  8124. }
  8125. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8126. single_dose, _ := json["single_dose"].(string)
  8127. project.SingleDose = single_dose
  8128. }
  8129. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8130. delivery_way, _ := json["delivery_way"].(string)
  8131. project.DeliveryWay = delivery_way
  8132. }
  8133. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8134. execution_frequency, _ := json["execution_frequency"].(string)
  8135. project.ExecutionFrequency = execution_frequency
  8136. }
  8137. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8138. remark, _ := json["remark"].(string)
  8139. project.Remark = remark
  8140. }
  8141. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8142. day, _ := json["number_days"].(string)
  8143. project.Day = day
  8144. }
  8145. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8146. unit, _ := json["unit"].(string)
  8147. project.Unit = unit
  8148. }
  8149. project.FrequencyType = 1
  8150. return 0
  8151. }
  8152. func (c *HisApiController) GetHisOrderListTwo() {
  8153. start_time := c.GetString("start_time")
  8154. end_time := c.GetString("end_time")
  8155. timeLayout := "2006-01-02"
  8156. loc, _ := time.LoadLocation("Local")
  8157. var startTime int64
  8158. if len(start_time) > 0 {
  8159. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8160. if err != nil {
  8161. //fmt.Println(err)
  8162. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8163. return
  8164. }
  8165. startTime = theTime.Unix()
  8166. }
  8167. var endTime int64
  8168. if len(end_time) > 0 {
  8169. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8170. if err != nil {
  8171. utils.ErrorLog(err.Error())
  8172. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8173. return
  8174. }
  8175. endTime = theTime.Unix()
  8176. }
  8177. adminUser := c.GetAdminUserInfo()
  8178. org_id := adminUser.CurrentOrgId
  8179. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  8180. if err == nil {
  8181. c.ServeSuccessJSON(map[string]interface{}{
  8182. "order2": order,
  8183. })
  8184. } else {
  8185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8186. return
  8187. }
  8188. }
  8189. func (c *HisApiController) GetHisOrderList() {
  8190. page, _ := c.GetInt64("page", -1)
  8191. limit, _ := c.GetInt64("limit", -1)
  8192. start_time := c.GetString("start_time")
  8193. end_time := c.GetString("end_time")
  8194. types, _ := c.GetInt64("type", 0)
  8195. keywords := c.GetString("keywords")
  8196. p_type, _ := c.GetInt64("p_type", 0)
  8197. sort_type, _ := c.GetInt64("sort_type", 0)
  8198. charge_type, _ := c.GetInt64("charge_type", 0)
  8199. sch_type, _ := c.GetInt64("sch_type", 0)
  8200. zone_type, _ := c.GetInt64("zone_type", 0)
  8201. med_type, _ := c.GetInt64("med_type", 0)
  8202. timeLayout := "2006-01-02"
  8203. loc, _ := time.LoadLocation("Local")
  8204. var startTime int64
  8205. if len(start_time) > 0 {
  8206. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8207. if err != nil {
  8208. //fmt.Println(err)
  8209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8210. return
  8211. }
  8212. startTime = theTime.Unix()
  8213. }
  8214. var endTime int64
  8215. if len(end_time) > 0 {
  8216. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8217. if err != nil {
  8218. utils.ErrorLog(err.Error())
  8219. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8220. return
  8221. }
  8222. endTime = theTime.Unix()
  8223. }
  8224. adminUser := c.GetAdminUserInfo()
  8225. org_id := adminUser.CurrentOrgId
  8226. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time, charge_type, sch_type, zone_type, med_type)
  8227. for _, item := range order {
  8228. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  8229. item.DoctorName = info.Doctor
  8230. item.DepartmentName = info.XtHisDepartment.Name
  8231. }
  8232. if err == nil {
  8233. c.ServeSuccessJSON(map[string]interface{}{
  8234. "order": order,
  8235. "total": total,
  8236. })
  8237. } else {
  8238. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8239. return
  8240. }
  8241. }
  8242. func (c *HisApiController) GetHisOrder() {
  8243. patient_id, _ := c.GetInt64("patient_id", 0)
  8244. number := c.GetString("number")
  8245. adminInfo := c.GetAdminUserInfo()
  8246. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  8247. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  8248. if err == nil {
  8249. c.ServeSuccessJSON(map[string]interface{}{
  8250. "order": order,
  8251. "prescription": prescriptions,
  8252. })
  8253. } else {
  8254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8255. return
  8256. }
  8257. }
  8258. func (c *HisApiController) GetHisPrescriptionList() {
  8259. record_date := c.GetString("record_date")
  8260. keywords := c.GetString("keywords")
  8261. page, _ := c.GetInt64("page")
  8262. limit, _ := c.GetInt64("limit")
  8263. sch_type, _ := c.GetInt64("sch_type")
  8264. timeLayout := "2006-01-02"
  8265. loc, _ := time.LoadLocation("Local")
  8266. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8267. if err != nil {
  8268. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8269. return
  8270. }
  8271. recordDateTime := theTime.Unix()
  8272. adminInfo := c.GetAdminUserInfo()
  8273. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  8274. //adminInfo := c.GetAdminUserInfo()
  8275. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  8276. //fmt.Println(prescriptionOrder)
  8277. if err == nil {
  8278. c.ServeSuccessJSON(map[string]interface{}{
  8279. "order": prescriptionOrder,
  8280. "total": total,
  8281. })
  8282. } else {
  8283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8284. return
  8285. }
  8286. }
  8287. func (c *HisApiController) GetHisPrescriptionInfo() {
  8288. id, _ := c.GetInt64("id")
  8289. adminInfo := c.GetAdminUserInfo()
  8290. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  8291. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  8292. if err == nil {
  8293. c.ServeSuccessJSON(map[string]interface{}{
  8294. "order": prescriptionOrder,
  8295. "prescription": prescription,
  8296. })
  8297. } else {
  8298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8299. return
  8300. }
  8301. }
  8302. func (c *HisApiController) GetMedicalInsuranceConfig() {
  8303. adminUser := c.GetAdminUserInfo()
  8304. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  8305. c.ServeSuccessJSON(map[string]interface{}{
  8306. "config": config,
  8307. })
  8308. }
  8309. type ResultTwo struct {
  8310. ErrMsg interface{} `json:"err_msg"`
  8311. InfRefmsgid string `json:"inf_refmsgid"`
  8312. Infcode int64 `json:"infcode"`
  8313. Output struct {
  8314. Baseinfo struct {
  8315. Age float64 `json:"age"`
  8316. Brdy string `json:"brdy"`
  8317. Certno string `json:"certno"`
  8318. Gend string `json:"gend"`
  8319. Naty string `json:"naty"`
  8320. PsnCertType string `json:"psn_cert_type"`
  8321. PsnName string `json:"psn_name"`
  8322. PsnNo string `json:"psn_no"`
  8323. } `json:"baseinfo"`
  8324. Idetinfo []interface{} `json:"idetinfo"`
  8325. Iinfo []struct {
  8326. Balc float64 `json:"balc"`
  8327. CvlservFlag string `json:"cvlserv_flag"`
  8328. EmpName string `json:"emp_name"`
  8329. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  8330. Insutype string `json:"insutype"`
  8331. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  8332. PausInsuDate interface{} `json:"paus_insu_date"`
  8333. PsnInsuDate string `json:"psn_insu_date"`
  8334. PsnInsuStas string `json:"psn_insu_stas"`
  8335. PsnType string `json:"psn_type"`
  8336. } `json:"insuinfo"`
  8337. } `json:"output"`
  8338. RefmsgTime string `json:"refmsg_time"`
  8339. RespondTime string `json:"respond_time"`
  8340. Signtype interface{} `json:"signtype"`
  8341. WarnInfo interface{} `json:"warn_info"`
  8342. }
  8343. type ResultThree struct {
  8344. Cainfo interface{} `json:"cainfo"`
  8345. ErrMsg interface{} `json:"err_msg"`
  8346. InfRefmsgid string `json:"inf_refmsgid"`
  8347. Infcode int64 `json:"infcode"`
  8348. Output struct {
  8349. Data struct {
  8350. IptOtpNo string `json:"ipt_otp_no"`
  8351. MdtrtID string `json:"mdtrt_id"`
  8352. PsnNo string `json:"psn_no"`
  8353. } `json:"data"`
  8354. } `json:"output"`
  8355. RefmsgTime string `json:"refmsg_time"`
  8356. RespondTime string `json:"respond_time"`
  8357. Signtype interface{} `json:"signtype"`
  8358. WarnMsg interface{} `json:"warn_msg"`
  8359. }
  8360. type ResultFour struct {
  8361. Cainfo string `json:"cainfo"`
  8362. ErrMsg string `json:"err_msg"`
  8363. InfRefmsgid string `json:"inf_refmsgid"`
  8364. Infcode int64 `json:"infcode"`
  8365. Output struct {
  8366. Result []struct {
  8367. BasMednFlag string `json:"bas_medn_flag"`
  8368. ChldMedcFlag string `json:"chld_medc_flag"`
  8369. ChrgitmLv string `json:"chrgitm_lv"`
  8370. Cnt float64 `json:"cnt"`
  8371. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  8372. DrtReimFlag string `json:"drt_reim_flag"`
  8373. FeedetlSn string `json:"feedetl_sn"`
  8374. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8375. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  8376. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8377. ListSpItemFlag string `json:"list_sp_item_flag"`
  8378. LmtUsedFlag string `json:"lmt_used_flag"`
  8379. MedChrgitmType string `json:"med_chrgitm_type"`
  8380. Memo string `json:"memo"`
  8381. OverlmtAmt float64 `json:"overlmt_amt"`
  8382. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8383. Pric float64 `json:"pric"`
  8384. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  8385. SelfpayProp float64 `json:"selfpay_prop"`
  8386. } `json:"result"`
  8387. } `json:"output"`
  8388. RefmsgTime string `json:"refmsg_time"`
  8389. RespondTime string `json:"respond_time"`
  8390. Signtype string `json:"signtype"`
  8391. WarnMsg string `json:"warn_msg"`
  8392. }
  8393. type ResultFive struct {
  8394. Insutype string `json:"insutype"`
  8395. }
  8396. type ResultSix struct {
  8397. Cainfo interface{} `json:"cainfo"`
  8398. ErrMsg interface{} `json:"err_msg"`
  8399. InfRefmsgid string `json:"inf_refmsgid"`
  8400. Infcode int64 `json:"infcode"`
  8401. Output struct {
  8402. } `json:"output"`
  8403. RefmsgTime string `json:"refmsg_time"`
  8404. RespondTime string `json:"respond_time"`
  8405. Signtype interface{} `json:"signtype"`
  8406. WarnMsg interface{} `json:"warn_msg"`
  8407. }
  8408. type ResultSeven struct {
  8409. Cainfo string `json:"cainfo"`
  8410. ErrMsg string `json:"err_msg"`
  8411. InfRefmsgid string `json:"inf_refmsgid"`
  8412. Infcode int64 `json:"infcode"`
  8413. Output struct {
  8414. Setldetail []interface{} `json:"setldetail"`
  8415. Setlinfo struct {
  8416. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8417. AcctPay float64 `json:"acct_pay"`
  8418. ActPayDedc float64 `json:"act_pay_dedc"`
  8419. Age float64 `json:"age"`
  8420. Balc float64 `json:"balc"`
  8421. Brdy string `json:"brdy"`
  8422. Certno string `json:"certno"`
  8423. ClrOptins string `json:"clr_optins"`
  8424. ClrType string `json:"clr_type"`
  8425. ClrWay string `json:"clr_way"`
  8426. CvlservFlag string `json:"cvlserv_flag"`
  8427. CvlservPay float64 `json:"cvlserv_pay"`
  8428. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8429. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8430. Gend string `json:"gend"`
  8431. HifesPay float64 `json:"hifes_pay"`
  8432. HifmiPay float64 `json:"hifmi_pay"`
  8433. HifobPay float64 `json:"hifob_pay"`
  8434. HifpPay float64 `json:"hifp_pay"`
  8435. HospPartAmt float64 `json:"hosp_part_amt"`
  8436. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8437. Insutype string `json:"insutype"`
  8438. MafPay float64 `json:"maf_pay"`
  8439. MdtrtCertType string `json:"mdtrt_cert_type"`
  8440. MdtrtID string `json:"mdtrt_id"`
  8441. MedType string `json:"med_type"`
  8442. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8443. MedinsSetlID string `json:"medins_setl_id"`
  8444. Naty string `json:"naty"`
  8445. OthPay float64 `json:"oth_pay"`
  8446. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8447. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8448. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8449. PsnCashPay float64 `json:"psn_cash_pay"`
  8450. PsnCertType string `json:"psn_cert_type"`
  8451. PsnName string `json:"psn_name"`
  8452. PsnNo string `json:"psn_no"`
  8453. PsnPartAmt float64 `json:"psn_part_amt"`
  8454. PsnType string `json:"psn_type"`
  8455. SetlID string `json:"setl_id"`
  8456. SetlTime string `json:"setl_time"`
  8457. } `json:"setlinfo"`
  8458. } `json:"output"`
  8459. RefmsgTime string `json:"refmsg_time"`
  8460. RespondTime string `json:"respond_time"`
  8461. Signtype interface{} `json:"signtype"`
  8462. WarnMsg interface{} `json:"warn_msg"`
  8463. }
  8464. type ResultEight struct {
  8465. Cainfo string `json:"cainfo"`
  8466. ErrMsg string `json:"err_msg"`
  8467. InfRefmsgid string `json:"inf_refmsgid"`
  8468. Infcode int64 `json:"infcode"`
  8469. Output struct {
  8470. Stmtinfo struct {
  8471. SetlOptins string `json:"setl_optins"`
  8472. StmtRslt string `json:"stmt_rslt"`
  8473. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  8474. } `json:"stmtinfo"`
  8475. } `json:"output"`
  8476. RefmsgTime string `json:"refmsg_time"`
  8477. RespondTime string `json:"respond_time"`
  8478. Signtype interface{} `json:"signtype"`
  8479. WarnMsg interface{} `json:"warn_msg"`
  8480. }
  8481. type ResultNine struct {
  8482. Cainfo string `json:"cainfo"`
  8483. ErrMsg string `json:"err_msg"`
  8484. InfRefmsgid string `json:"inf_refmsgid"`
  8485. Infcode int64 `json:"infcode"`
  8486. Output struct {
  8487. FileQuryNo string `json:"file_qury_no"`
  8488. } `json:"output"`
  8489. RefmsgTime string `json:"refmsg_time"`
  8490. RespondTime string `json:"respond_time"`
  8491. Signtype interface{} `json:"signtype"`
  8492. WarnMsg interface{} `json:"warn_msg"`
  8493. }
  8494. type ResultTen struct {
  8495. Cainfo string `json:"cainfo"`
  8496. ErrMsg string `json:"err_msg"`
  8497. InfRefmsgid string `json:"inf_refmsgid"`
  8498. Infcode int64 `json:"infcode"`
  8499. Output struct {
  8500. DldEndtime string `json:"dld_endtime"`
  8501. FileQuryNo string `json:"file_qury_no"`
  8502. Filename string `json:"filename"`
  8503. } `json:"output"`
  8504. RefmsgTime string `json:"refmsg_time"`
  8505. RespondTime string `json:"respond_time"`
  8506. Signtype interface{} `json:"signtype"`
  8507. WarnMsg interface{} `json:"warn_msg"`
  8508. }
  8509. type ResultEleven struct {
  8510. Cainfo string `json:"cainfo"`
  8511. ErrMsg string `json:"err_msg"`
  8512. InfRefmsgid string `json:"inf_refmsgid"`
  8513. Infcode int64 `json:"infcode"`
  8514. Output struct {
  8515. Setlinfo struct {
  8516. FixmedinsName string `json:"fixmedins_name"`
  8517. FixmedinsCode string `json:"fixmedins_code"`
  8518. PsnNo string `json:"psn_no"`
  8519. PsnName string `json:"psn_name"`
  8520. HifobPay float64 `json:"hifob_pay"`
  8521. Gend string `json:"gend"`
  8522. Brdy string `json:"brdy"`
  8523. PsnCertType string `json:"psn_cert_type"`
  8524. PsnType string `json:"psn_type"`
  8525. EmpName string `json:"emp_name"`
  8526. Certno string `json:"certno"`
  8527. Insutype string `json:"insutype"`
  8528. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8529. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8530. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8531. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8532. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8533. ActPayDedc float64 `json:"act_pay_dedc"`
  8534. HifpPay float64 `json:"hifp_pay"`
  8535. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8536. CvlservPay float64 `json:"cvlserv_pay"`
  8537. HifesPay float64 `json:"hifes_pay"`
  8538. HifmiPay float64 `json:"hifmi_pay"`
  8539. MafPay float64 `json:"maf_pay"`
  8540. OthPay float64 `json:"oth_pay"`
  8541. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8542. PsnPay float64 `json:"psn_pay"`
  8543. AcctPay float64 `json:"acct_pay"`
  8544. CashPayamt float64 `json:"cash_payamt"`
  8545. Balc float64 `json:"balc"`
  8546. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8547. MedinsSetlId string `json:"medins_setl_id"`
  8548. RefdSetlFlag string `json:"refd_setl_flag"`
  8549. SetlTime string `json:"setl_time"`
  8550. MedType string `json:"med_type"`
  8551. } `json:"setlinfo"`
  8552. } `json:"output"`
  8553. RefmsgTime string `json:"refmsg_time"`
  8554. RespondTime string `json:"respond_time"`
  8555. Signtype interface{} `json:"signtype"`
  8556. WarnMsg interface{} `json:"warn_msg"`
  8557. }
  8558. type Custom struct {
  8559. DetItemFeeSumamt string
  8560. Cut string
  8561. FeedetlSn string
  8562. Price string
  8563. MedListCodg string
  8564. Type int64
  8565. AdviceId int64
  8566. ProjectId int64
  8567. ItemId int64
  8568. CostType int64
  8569. }
  8570. // 获取个人信息----挂号-----上传就诊信息
  8571. func (c *HisApiController) GetRegisterInfo() {
  8572. id, _ := c.GetInt64("id")
  8573. record_time := c.GetString("record_time")
  8574. settlementValue, _ := c.GetInt64("settlement_value")
  8575. medical_insurance_card := c.GetString("medical_insurance_card")
  8576. name := c.GetString("name")
  8577. id_card_type, _ := c.GetInt64("id_card_type")
  8578. certificates, _ := c.GetInt64("certificates")
  8579. medical_care, _ := c.GetInt64("medical_care")
  8580. birthday := c.GetString("birthday")
  8581. age, _ := c.GetInt64("age")
  8582. id_card := c.GetString("id_card")
  8583. register_type, _ := c.GetInt64("register")
  8584. doctor, _ := c.GetInt64("doctor")
  8585. department, _ := c.GetInt64("department")
  8586. gender, _ := c.GetInt64("sex")
  8587. phone := c.GetString("phone")
  8588. registration_fee, _ := c.GetFloat("registration_fee")
  8589. medical_expenses, _ := c.GetFloat("medical_expenses")
  8590. social_type, _ := c.GetInt64("social_type")
  8591. //diagnosis_id, _ := c.GetInt64("diagnosis")
  8592. diagnosis_ids := c.GetString("diagnosis")
  8593. sick_type, _ := c.GetInt64("sick_type")
  8594. reg_type := c.GetString("p_type")
  8595. timeLayout := "2006-01-02"
  8596. loc, _ := time.LoadLocation("Local")
  8597. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  8598. birthUnix := birthdays.Unix()
  8599. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8600. if err != nil {
  8601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8602. return
  8603. }
  8604. recordDateTime := theTime.Unix()
  8605. adminInfo := c.GetAdminUserInfo()
  8606. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  8607. if tempPatient.ID == 0 {
  8608. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  8609. return
  8610. }
  8611. var patient service.Patients
  8612. if id == 0 {
  8613. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  8614. } else {
  8615. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  8616. }
  8617. if patient.ID == 0 {
  8618. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  8619. return
  8620. }
  8621. if len(patient.IdCardNo) == 0 {
  8622. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  8623. return
  8624. }
  8625. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  8626. if len(his) >= 1 {
  8627. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  8628. if len(his) >= 1 && order.ID == 0 {
  8629. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  8630. return
  8631. }
  8632. }
  8633. timeStr := time.Now().Format("2006-01-02 15:04:05")
  8634. fmt.Println(timeStr)
  8635. timeArr := strings.Split(timeStr, " ")
  8636. fmt.Println(timeArr)
  8637. timeArrTwo := strings.Split(timeArr[0], "-")
  8638. timeArrThree := strings.Split(timeArr[1], ":")
  8639. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  8640. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  8641. if len(lists) == 0 {
  8642. var hisPatient models.XtHisPatient
  8643. hisPatient = models.XtHisPatient{
  8644. Name: name,
  8645. Age: age,
  8646. Gender: gender,
  8647. Birthday: birthUnix,
  8648. Phone: phone,
  8649. MedicalTreatmentType: medical_care,
  8650. IdType: certificates,
  8651. IdCardNo: id_card,
  8652. BalanceAccountsType: settlementValue,
  8653. SocialType: social_type,
  8654. MedicalInsuranceNumber: medical_insurance_card,
  8655. RegisterType: register_type,
  8656. RegisterCost: registration_fee,
  8657. TreatmentCost: medical_expenses,
  8658. AdminUserId: adminInfo.AdminUser.Id,
  8659. UserOrgId: adminInfo.CurrentOrgId,
  8660. Status: 1,
  8661. RecordDate: recordDateTime,
  8662. IsReturn: 1,
  8663. PatientId: patient.ID,
  8664. Ctime: time.Now().Unix(),
  8665. Mtime: time.Now().Unix(),
  8666. Number: str,
  8667. IdCardType: id_card_type,
  8668. Departments: department,
  8669. Doctor: doctor,
  8670. PType: reg_type,
  8671. Diagnosis: diagnosis_ids,
  8672. SickType: sick_type,
  8673. }
  8674. service.CreateHisPatient(&hisPatient)
  8675. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  8676. c.ServeSuccessJSON(map[string]interface{}{
  8677. "his_info": hisPatient,
  8678. })
  8679. } else {
  8680. //chrgBchno := rand.Intn(1000000) + 10000
  8681. var hisPatient models.XtHisPatient
  8682. hisPatient = models.XtHisPatient{
  8683. Name: name,
  8684. Age: age,
  8685. Gender: gender,
  8686. Birthday: birthUnix,
  8687. Phone: phone,
  8688. MedicalTreatmentType: medical_care,
  8689. IdType: certificates,
  8690. IdCardNo: id_card,
  8691. BalanceAccountsType: settlementValue,
  8692. SocialType: social_type,
  8693. MedicalInsuranceNumber: medical_insurance_card,
  8694. RegisterType: register_type,
  8695. RegisterCost: registration_fee,
  8696. TreatmentCost: medical_expenses,
  8697. AdminUserId: adminInfo.AdminUser.Id,
  8698. UserOrgId: adminInfo.CurrentOrgId,
  8699. Status: 1,
  8700. RecordDate: recordDateTime,
  8701. IsReturn: 1,
  8702. PatientId: patient.ID,
  8703. Ctime: time.Now().Unix(),
  8704. Mtime: time.Now().Unix(),
  8705. Number: str,
  8706. IdCardType: id_card_type,
  8707. Departments: department,
  8708. Doctor: doctor,
  8709. PType: reg_type,
  8710. Diagnosis: diagnosis_ids,
  8711. SickType: sick_type,
  8712. }
  8713. service.CreateHisPatient(&hisPatient)
  8714. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  8715. c.ServeSuccessJSON(map[string]interface{}{
  8716. "his_info": hisPatient,
  8717. })
  8718. }
  8719. }
  8720. // 上传明细----结算
  8721. func (c *HisApiController) GetUploadInfo() {
  8722. id, _ := c.GetInt64("id")
  8723. record_time := c.GetString("record_time")
  8724. his_patient_id, _ := c.GetInt64("his_patient_id")
  8725. oth_desc := c.GetString("oth_desc")
  8726. pay_way, _ := c.GetInt64("pay_way")
  8727. pay_ways := c.GetString("pay_ways")
  8728. pay_price, _ := c.GetFloat("pay_price")
  8729. pay_card_no := c.GetString("pay_card_no")
  8730. discount_price, _ := c.GetFloat("discount_price")
  8731. preferential_price, _ := c.GetFloat("preferential_price")
  8732. reality_price, _ := c.GetFloat("reality_price")
  8733. found_price, _ := c.GetFloat("found_price")
  8734. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  8735. private_price, _ := c.GetFloat("private_price")
  8736. timeLayout := "2006-01-02"
  8737. loc, _ := time.LoadLocation("Local")
  8738. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  8739. fapiao_code := c.GetString("fapiao_code")
  8740. fapiao_number := c.GetString("fapiao_number")
  8741. diagnosis_id := c.GetString("diagnosis")
  8742. sick_type, _ := c.GetInt64("sick_type")
  8743. reg_type, _ := c.GetInt64("p_type")
  8744. order_id, _ := c.GetInt64("order_id")
  8745. cash_pay := c.GetString("cash_pay")
  8746. wechat_pay := c.GetString("wechat_pay")
  8747. ali_pay := c.GetString("ali_pay")
  8748. jifen_pay := c.GetString("jifen_pay")
  8749. band_card_pay := c.GetString("band_card_pay")
  8750. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  8751. tmp_decimal := c.GetString("tmp_decimal")
  8752. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  8753. var decimal float64 //本次使用的押金
  8754. var errmsg error
  8755. tx := service.XTWriteDB().Begin() //开了事务
  8756. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  8757. defer func() {
  8758. if errmsg != nil {
  8759. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  8760. tx.Rollback()
  8761. } else {
  8762. tx.Commit()
  8763. }
  8764. }()
  8765. fmt.Println("dec_way", dec_way)
  8766. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  8767. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  8768. return
  8769. }
  8770. if len(tmp_decimal) > 0 {
  8771. if tmp_decimal[0] == 45 {
  8772. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  8773. return
  8774. }
  8775. }
  8776. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  8777. fmt.Println(errs)
  8778. decimal = tt
  8779. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  8780. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  8781. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8782. if err != nil {
  8783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8784. return
  8785. }
  8786. recordDateTime := theTime.Unix()
  8787. adminUser := c.GetAdminUserInfo()
  8788. var prescriptions []*models.HisPrescription
  8789. var prescriptionsOne []*models.HisPrescription
  8790. var start_time int64
  8791. var end_time int64
  8792. ids_str := c.GetString("ids")
  8793. ids_arr := strings.Split(ids_str, ",")
  8794. if tempOrder.ID == 0 {
  8795. if settle_accounts_type == 1 { //日结
  8796. fmt.Println(reg_type)
  8797. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  8798. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  8799. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  8800. } else {
  8801. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8802. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8803. }
  8804. } else { //月结
  8805. start_time_str := c.GetString("start_time")
  8806. end_time_str := c.GetString("end_time")
  8807. timeLayout := "2006-01-02"
  8808. loc, _ := time.LoadLocation("Local")
  8809. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  8810. if err != nil {
  8811. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8812. return
  8813. }
  8814. recordStartTime := theStartTime.Unix()
  8815. start_time = recordStartTime
  8816. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  8817. if err != nil {
  8818. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8819. return
  8820. }
  8821. recordEndTime := theEndTime.Unix()
  8822. end_time = recordEndTime
  8823. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  8824. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8825. }
  8826. var goods []*models.DialysisBeforePrepareGoods
  8827. var newGoods []*models.NewDialysisBeforePrepareGoods
  8828. var oldGoods []*models.OldDialysisBeforePrepareGoods
  8829. var infos []*models.HisDoctorAdviceInfo
  8830. var infoList []*models.HisDoctorAdviceInfo
  8831. var hisAdvice []*models.HisDoctorAdviceInfo
  8832. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  8833. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  8834. //判断库存不足
  8835. //结算出库开关
  8836. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  8837. if settConfig.IsOpen == 1 {
  8838. //判断库存的地方
  8839. for _, info := range prescriptions {
  8840. if info.Type == 1 {
  8841. infos = append(infos, info.HisDoctorAdviceInfo...)
  8842. }
  8843. if info.Type == 2 {
  8844. for _, sumItem := range info.HisPrescriptionProject {
  8845. if sumItem.Type == 3 {
  8846. var good models.DialysisBeforePrepareGoods
  8847. var newGood models.NewDialysisBeforePrepareGoods
  8848. good.GoodId = sumItem.GoodInfo.ID
  8849. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8850. count, _ := strconv.Atoi(sumItem.Count)
  8851. good.Count = int64(count)
  8852. good.StorehouseId = houseConfig.StorehouseOutInfo
  8853. good.ProjectId = sumItem.ID
  8854. goods = append(goods, &good)
  8855. newGood.GoodId = sumItem.GoodInfo.ID
  8856. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8857. count2, _ := strconv.Atoi(sumItem.Count)
  8858. newGood.Count = int64(count2)
  8859. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8860. newGood.ProjectId = sumItem.ID
  8861. newGoods = append(newGoods, &newGood)
  8862. }
  8863. }
  8864. }
  8865. }
  8866. for _, info := range prescriptionsOne {
  8867. if info.Type == 1 {
  8868. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  8869. }
  8870. if info.Type == 2 {
  8871. for _, sumItem := range info.HisPrescriptionProject {
  8872. if sumItem.Type == 3 {
  8873. var newGood models.NewDialysisBeforePrepareGoods
  8874. newGood.GoodId = sumItem.GoodInfo.ID
  8875. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8876. count2, _ := strconv.Atoi(sumItem.Count)
  8877. newGood.Count = int64(count2)
  8878. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8879. newGood.ProjectId = sumItem.ID
  8880. newGoodOne = append(newGoodOne, &newGood)
  8881. }
  8882. }
  8883. }
  8884. }
  8885. //判断
  8886. for _, itemOne := range infos {
  8887. for _, itemTwo := range hisAdvice {
  8888. if itemOne.DrugId == itemTwo.DrugId {
  8889. itemTwo.Child = append(itemTwo.Child, itemOne)
  8890. }
  8891. }
  8892. }
  8893. for _, itemTwo := range hisAdvice {
  8894. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  8895. var sum_out_count int64
  8896. for _, itemThree := range itemTwo.Child {
  8897. var prescribing_number int64
  8898. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8899. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8900. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8901. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8902. }
  8903. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8904. prescribing_number = parseIntPrescribingNumber
  8905. }
  8906. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8907. prescribing_number = parseIntPrescribingNumber
  8908. }
  8909. sum_out_count += prescribing_number
  8910. }
  8911. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  8912. if sum_out_count > drugStockOut.FlushCount {
  8913. c.ServeSuccessJSON(map[string]interface{}{
  8914. "msg": "2",
  8915. "drug": medical,
  8916. })
  8917. return
  8918. }
  8919. }
  8920. for _, itemOne := range newGoods {
  8921. for _, item := range newGoodOne {
  8922. if itemOne.GoodId == item.GoodId {
  8923. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  8924. }
  8925. }
  8926. }
  8927. for _, item := range newGoodOne {
  8928. var sum_out_count_one int64
  8929. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  8930. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  8931. sum_out_count_one += itemOne.Count
  8932. }
  8933. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8934. fmt.Println("sum_out_count_one", sum_out_count_one)
  8935. fmt.Println("list.FlushCount", list.FlushCount)
  8936. if sum_out_count_one > list.FlushCount {
  8937. c.ServeSuccessJSON(map[string]interface{}{
  8938. "msg": "3",
  8939. "good": good,
  8940. })
  8941. return
  8942. }
  8943. }
  8944. }
  8945. timestamp := time.Now().Unix()
  8946. tempTime := time.Unix(timestamp, 0)
  8947. timeFormat := tempTime.Format("20060102150405")
  8948. chrgBchno := rand.Intn(100000) + 10000
  8949. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  8950. strconv.FormatInt(his.PatientId, 10)
  8951. var ids []int64
  8952. for _, item := range prescriptions {
  8953. ids = append(ids, item.ID)
  8954. }
  8955. var total float64
  8956. for _, item := range prescriptions {
  8957. fmt.Println(item)
  8958. if item.Type == 1 { //药品
  8959. for _, subItem := range item.HisDoctorAdviceInfo {
  8960. total = total + (subItem.Price * subItem.PrescribingNumber)
  8961. }
  8962. }
  8963. if item.Type == 2 { //项目
  8964. for _, subItem := range item.HisPrescriptionProject {
  8965. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8966. total = total + (subItem.Price * cnt)
  8967. }
  8968. }
  8969. for _, subItem := range item.HisAdditionalCharge {
  8970. total = total + (subItem.Price * float64(subItem.Count))
  8971. }
  8972. }
  8973. if reg_type == 1111 || reg_type == 1112 {
  8974. reg_type = 11
  8975. }
  8976. tm := time.Unix(time.Now().Unix(), 0)
  8977. allTotal := fmt.Sprintf("%.4f", total)
  8978. totals, _ := strconv.ParseFloat(allTotal, 64)
  8979. order := &models.HisOrder{
  8980. UserOrgId: adminUser.CurrentOrgId,
  8981. HisPatientId: his.ID,
  8982. PatientId: id,
  8983. SettleAccountsDate: recordDateTime,
  8984. Ctime: time.Now().Unix(),
  8985. Mtime: time.Now().Unix(),
  8986. Status: 1,
  8987. OrderStatus: 2,
  8988. MdtrtId: his.Number,
  8989. Number: chrg_bchno,
  8990. MedfeeSumamt: totals,
  8991. PayWay: pay_way,
  8992. PayWays: pay_ways,
  8993. PayPrice: pay_price,
  8994. MedType: strconv.Itoa(int(reg_type)),
  8995. PayCardNo: pay_card_no,
  8996. DiscountPrice: discount_price,
  8997. PreferentialPrice: preferential_price,
  8998. RealityPrice: reality_price,
  8999. FoundPrice: found_price,
  9000. MedicalInsurancePrice: medical_insurance_price,
  9001. PrivatePrice: private_price,
  9002. SettleEndTime: end_time,
  9003. SettleStartTime: start_time,
  9004. PsnPartAmt: totals,
  9005. PsnCashPay: totals,
  9006. SettleType: settle_accounts_type,
  9007. FaPiaoCode: fapiao_code,
  9008. FaPiaoNumber: fapiao_number,
  9009. Diagnosis: diagnosis_id,
  9010. PType: 2,
  9011. SetlTime: tm.Format("2006-01-02 15:04:05"),
  9012. Decimal: decimal,
  9013. OthDesc: oth_desc,
  9014. CashPay: cash_pay,
  9015. WechatPay: wechat_pay,
  9016. AliPay: ali_pay,
  9017. JifenPay: jifen_pay,
  9018. BandCardPay: band_card_pay,
  9019. Creator: adminUser.AdminUser.Id,
  9020. }
  9021. err = service.CreateOrderTX(order, tx)
  9022. if err != nil {
  9023. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9024. return
  9025. }
  9026. var customs []*Custom
  9027. for _, item := range prescriptions {
  9028. if item.Type == 1 { //药品a
  9029. for _, subItem := range item.HisDoctorAdviceInfo {
  9030. cus := &Custom{
  9031. AdviceId: subItem.ID,
  9032. ProjectId: 0,
  9033. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  9034. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  9035. FeedetlSn: subItem.FeedetlSn,
  9036. Price: fmt.Sprintf("%.4f", subItem.Price),
  9037. MedListCodg: subItem.MedListCodg,
  9038. Type: 1,
  9039. CostType: 9,
  9040. }
  9041. customs = append(customs, cus)
  9042. }
  9043. }
  9044. if item.Type == 2 { //项目
  9045. for _, subItem := range item.HisPrescriptionProject {
  9046. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9047. cus := &Custom{
  9048. AdviceId: 0,
  9049. ProjectId: subItem.ID,
  9050. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9051. Cut: fmt.Sprintf("%.4f", cnt),
  9052. FeedetlSn: subItem.FeedetlSn,
  9053. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9054. MedListCodg: subItem.MedListCodg,
  9055. Type: 2,
  9056. CostType: subItem.HisProject.CostClassify,
  9057. }
  9058. customs = append(customs, cus)
  9059. }
  9060. }
  9061. for _, item := range item.HisAdditionalCharge {
  9062. cus := &Custom{
  9063. ItemId: item.ID,
  9064. AdviceId: 0,
  9065. ProjectId: 0,
  9066. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  9067. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  9068. FeedetlSn: item.FeedetlSn,
  9069. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  9070. MedListCodg: item.XtHisAddtionConfig.Code,
  9071. Type: 3,
  9072. CostType: 5,
  9073. }
  9074. customs = append(customs, cus)
  9075. }
  9076. }
  9077. for _, item := range customs {
  9078. var advice_id int64 = 0
  9079. var project_id int64 = 0
  9080. var item_id int64 = 0
  9081. var types int64 = 0
  9082. var med_chrgitm_type string
  9083. if item.Type == 1 {
  9084. advice_id = item.AdviceId
  9085. project_id = 0
  9086. item_id = 0
  9087. med_chrgitm_type = "09"
  9088. } else if item.Type == 2 {
  9089. med_chrgitm_type = "05"
  9090. if item.CostType == 3 {
  9091. med_chrgitm_type = "04"
  9092. }
  9093. if item.CostType == 8 {
  9094. med_chrgitm_type = "03"
  9095. }
  9096. advice_id = 0
  9097. item_id = 0
  9098. project_id = item.ProjectId
  9099. } else if item.Type == 3 {
  9100. advice_id = 0
  9101. item_id = item.ItemId
  9102. project_id = 0
  9103. med_chrgitm_type = "08"
  9104. }
  9105. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9106. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9107. pric, _ := strconv.ParseFloat(item.Price, 32)
  9108. info := &models.HisOrderInfo{
  9109. OrderNumber: order.Number,
  9110. UploadDate: time.Now().Unix(),
  9111. AdviceId: advice_id,
  9112. DetItemFeeSumamt: detItemFeeSumamt,
  9113. MedChrgitmType: med_chrgitm_type,
  9114. Cnt: cut,
  9115. Pric: pric,
  9116. PatientId: id,
  9117. Status: 1,
  9118. Mtime: time.Now().Unix(),
  9119. Ctime: time.Now().Unix(),
  9120. UserOrgId: adminUser.CurrentOrgId,
  9121. HisPatientId: his.ID,
  9122. OrderId: order.ID,
  9123. ProjectId: project_id,
  9124. Type: types,
  9125. ItemId: item_id,
  9126. }
  9127. service.CreateOrderInfoTX(info, tx)
  9128. }
  9129. his.Diagnosis = diagnosis_id
  9130. his.SickType = sick_type
  9131. his.RegisterType = reg_type
  9132. his.MedicalTreatmentType = reg_type
  9133. service.UpdataHisPateintTX(&his, tx)
  9134. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  9135. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  9136. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  9137. //判断是否使用了押金
  9138. if dec_way == "true" {
  9139. tmpstring := strconv.FormatInt(order.ID, 10)
  9140. //扣押金
  9141. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  9142. order.Decimal = decimal
  9143. service.UpDateOrderTwo(order, tx)
  9144. if errmsg != nil {
  9145. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  9146. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9147. return
  9148. }
  9149. }
  9150. if err == nil {
  9151. for _, info := range prescriptions {
  9152. if info.Type == 1 {
  9153. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  9154. }
  9155. if info.Type == 2 {
  9156. for _, sumItem := range info.HisPrescriptionProject {
  9157. if sumItem.Type == 3 {
  9158. var good models.DialysisBeforePrepareGoods
  9159. var newGood models.NewDialysisBeforePrepareGoods
  9160. var oldGood models.OldDialysisBeforePrepareGoods
  9161. good.GoodId = sumItem.GoodInfo.ID
  9162. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9163. count, _ := strconv.Atoi(sumItem.Count)
  9164. good.Count = int64(count)
  9165. good.StorehouseId = houseConfig.StorehouseOutInfo
  9166. good.ProjectId = sumItem.ID
  9167. good.PatientId = sumItem.PatientId
  9168. goods = append(goods, &good)
  9169. newGood.GoodId = sumItem.GoodInfo.ID
  9170. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9171. count2, _ := strconv.Atoi(sumItem.Count)
  9172. newGood.Count = int64(count2)
  9173. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9174. newGood.ProjectId = sumItem.ID
  9175. newGood.PatientId = sumItem.HisPatientId
  9176. newGoods = append(newGoods, &newGood)
  9177. oldGood.GoodId = sumItem.GoodInfo.ID
  9178. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9179. count3, _ := strconv.Atoi(sumItem.Count)
  9180. oldGood.Count = int64(count3)
  9181. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  9182. oldGood.ProjectId = sumItem.ID
  9183. oldGood.RecordDate = sumItem.RecordDate
  9184. oldGood.PatientId = sumItem.HisPatientId
  9185. oldGoods = append(oldGoods, &oldGood)
  9186. }
  9187. }
  9188. }
  9189. }
  9190. if settConfig.IsOpen == 1 {
  9191. for _, item := range infoList {
  9192. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9193. if medical.IsUse == 2 {
  9194. //药品出库
  9195. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  9196. //查询默认仓库
  9197. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  9198. //查询默认仓库剩余多少库存
  9199. var sum_count int64
  9200. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9201. for _, its := range stockInfo {
  9202. if its.MaxUnit == medical.MaxUnit {
  9203. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9204. }
  9205. sum_count += its.StockMaxNumber + its.StockMinNumber
  9206. }
  9207. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9208. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9209. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  9210. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  9211. }
  9212. }
  9213. orgId := c.GetAdminUserInfo().CurrentOrgId
  9214. if len(oldGoods) > 0 {
  9215. timeStr := time.Now().Format("2006-01-02")
  9216. timeArr := strings.Split(timeStr, "-")
  9217. total, _ := service.FindAllWarehouseOut(orgId)
  9218. total = total + 1
  9219. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  9220. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  9221. number = number + total
  9222. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  9223. operation_time := time.Now().Unix()
  9224. creater := c.GetAdminUserInfo().AdminUser.Id
  9225. //查询默认出库仓库库存
  9226. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9227. recordDateStr := time.Now().Format("2006-01-02")
  9228. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9229. nowtime := recordDate.Unix()
  9230. warehouseOut := models.WarehouseOut{
  9231. WarehouseOutOrderNumber: warehousing_out_order,
  9232. OperationTime: operation_time,
  9233. OrgId: orgId,
  9234. Creater: creater,
  9235. Ctime: time.Now().Unix(),
  9236. Status: 1,
  9237. WarehouseOutTime: nowtime,
  9238. Type: 1,
  9239. StorehouseId: storeConfig.StorehouseOutInfo,
  9240. IsCheck: 1,
  9241. OrderId: order.ID,
  9242. IsSys: 5,
  9243. }
  9244. //查询是否生成出库单
  9245. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9246. if out.ID == 0 {
  9247. service.AddSigleWarehouseOut(&warehouseOut)
  9248. }
  9249. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9250. for _, item := range oldGoods {
  9251. dialyPrepareOne := models.DialysisBeforePrepare{
  9252. GoodTypeId: item.GoodTypeId,
  9253. GoodId: item.GoodId,
  9254. PatientId: his.PatientId,
  9255. RecordDate: item.RecordDate,
  9256. UserOrgId: adminUser.CurrentOrgId,
  9257. Count: item.Count,
  9258. Ctime: time.Now().Unix(),
  9259. Creater: adminUser.AdminUser.Id,
  9260. CommdityCode: item.CommdityCode,
  9261. Status: 1,
  9262. StorehouseId: houseConfig.StorehouseOutInfo,
  9263. }
  9264. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  9265. //非零用
  9266. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  9267. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9268. //查询剩余库存
  9269. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9270. var sum_count int64
  9271. for _, item := range goodList {
  9272. sum_count += item.StockCount
  9273. }
  9274. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9275. //耗材
  9276. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9277. }
  9278. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  9279. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9280. //查询剩余库存
  9281. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9282. var sum_count int64
  9283. for _, item := range goodList {
  9284. sum_count += item.StockCount
  9285. }
  9286. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9287. //耗材
  9288. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9289. }
  9290. }
  9291. }
  9292. }
  9293. c.ServeSuccessJSON(map[string]interface{}{
  9294. "msg": "结算成功",
  9295. })
  9296. }
  9297. }
  9298. }
  9299. // 退款
  9300. func (c *HisApiController) Refund() {
  9301. order_id, _ := c.GetInt64("order_id")
  9302. order, _ := service.GetHisOrderByID(order_id)
  9303. adminUser := c.GetAdminUserInfo()
  9304. orgid := c.GetAdminUserInfo().CurrentOrgId
  9305. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  9306. if err != nil {
  9307. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9308. return
  9309. }
  9310. tmp := strconv.FormatInt(order.ID, 10)
  9311. //当押金不为零时产生退费记录
  9312. if order.Decimal != 0 {
  9313. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  9314. if err != nil {
  9315. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9316. return
  9317. }
  9318. }
  9319. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  9320. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  9321. var goods []*models.DialysisBeforePrepareGoods
  9322. var newGoods []*models.NewDialysisBeforePrepareGoods
  9323. var infos []*models.HisDoctorAdviceInfo
  9324. for _, info := range orders {
  9325. if info.AdviceId > 0 && info.ProjectId == 0 {
  9326. infos = append(infos, &info.HisDoctorAdviceInfo)
  9327. }
  9328. if info.ProjectId > 0 && info.AdviceId == 0 {
  9329. if info.HisPrescriptionProject.Type == 3 {
  9330. var good models.DialysisBeforePrepareGoods
  9331. var newGood models.NewDialysisBeforePrepareGoods
  9332. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9333. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9334. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9335. good.Count = int64(count)
  9336. good.StorehouseId = houseConfig.StorehouseOutInfo
  9337. good.ProjectId = info.HisPrescriptionProject.ID
  9338. good.PatientId = info.PatientId
  9339. good.OrderId = order_id
  9340. goods = append(goods, &good)
  9341. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9342. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9343. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9344. newGood.Count = int64(count2)
  9345. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9346. newGood.ProjectId = info.HisPrescriptionProject.ID
  9347. newGood.RecordDate = order.SettleAccountsDate
  9348. newGood.UserOrgId = order.UserOrgId
  9349. newGood.PatientId = info.PatientId
  9350. newGood.OrderId = order_id
  9351. newGoods = append(newGoods, &newGood)
  9352. }
  9353. }
  9354. }
  9355. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9356. if settConfig.IsOpen == 1 {
  9357. for _, item := range infos {
  9358. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9359. }
  9360. for _, item := range newGoods {
  9361. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9362. }
  9363. }
  9364. c.ServeSuccessJSON(map[string]interface{}{
  9365. "msg": "退费成功",
  9366. })
  9367. }
  9368. func (c *HisApiController) RefundNumber() {
  9369. his_patient_id, _ := c.GetInt64("id")
  9370. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9371. info.Status = 0
  9372. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  9373. if count > 0 {
  9374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  9375. return
  9376. }
  9377. err := service.SaveHisPatient(info)
  9378. if err == nil {
  9379. c.ServeSuccessJSON(map[string]interface{}{
  9380. "msg": "退号成功",
  9381. })
  9382. } else {
  9383. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9384. return
  9385. }
  9386. }
  9387. func (this *HisApiController) AdditionalCharge() {
  9388. dataBody := make(map[string]interface{}, 0)
  9389. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  9390. fmt.Println(err)
  9391. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  9392. patient_id := int64(dataBody["patient_id"].(float64))
  9393. medicineData, _ := dataBody["medicineData"].([]interface{})
  9394. adminUserInfo := this.GetAdminUserInfo()
  9395. orgId := adminUserInfo.CurrentOrgId
  9396. admin_user_id := adminUserInfo.AdminUser.Id
  9397. timeStr := time.Now().Format("2006-01-02")
  9398. timeLayout := "2006-01-02 15:04:05"
  9399. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9400. timenow := timeStringToTime.Unix()
  9401. var additionalCharges []*models.HisAdditionalCharge
  9402. for _, item := range medicineData {
  9403. var randNum int
  9404. randNum = rand.Intn(10000) + 1000
  9405. timestamp := time.Now().Unix()
  9406. tempTime := time.Unix(timestamp, 0)
  9407. timeFormat := tempTime.Format("20060102150405")
  9408. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  9409. items := item.(map[string]interface{})
  9410. money := items["price"].(string)
  9411. item_id_str := items["item_id"].(string)
  9412. name := items["name"].(string)
  9413. id_str := items["id"].(string)
  9414. moneys, _ := strconv.ParseInt(money, 10, 64)
  9415. monStr := strconv.FormatInt(moneys, 10)
  9416. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  9417. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  9418. id, _ := strconv.ParseInt(id_str, 10, 64)
  9419. additionalCharge := &models.HisAdditionalCharge{
  9420. ID: id,
  9421. HisPatientId: his_patient_id,
  9422. UserOrgId: orgId,
  9423. PatientId: patient_id,
  9424. RecordDate: timenow,
  9425. Price: monneyStr,
  9426. Status: 1,
  9427. ItemName: name,
  9428. ItemId: item_id,
  9429. AdminUserId: admin_user_id,
  9430. CreatedTime: time.Now().Unix(),
  9431. OrderStatus: 0,
  9432. PrescriptionNumber: "",
  9433. BatchNumber: "",
  9434. FeedetlSn: p_number,
  9435. }
  9436. service.CreateAdditionalCharge(additionalCharge)
  9437. additionalCharges = append(additionalCharges, additionalCharge)
  9438. }
  9439. this.ServeSuccessJSON(map[string]interface{}{
  9440. "msg": "添加成功",
  9441. "additional_charges": additionalCharges,
  9442. })
  9443. }
  9444. func (this *HisApiController) DeleteAddition() {
  9445. id, _ := this.GetInt64("id")
  9446. //TODO 需要判断是否已经结算
  9447. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  9448. if err == nil {
  9449. this.ServeSuccessJSON(map[string]interface{}{
  9450. "msg": "删除成功",
  9451. })
  9452. return
  9453. } else {
  9454. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9455. return
  9456. }
  9457. }
  9458. func (this *HisApiController) GetAdminUsers() {
  9459. adminUser := this.GetAdminUserInfo()
  9460. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  9461. this.ServeSuccessJSON(map[string]interface{}{
  9462. "doctors": doctors,
  9463. })
  9464. }
  9465. func (this *HisApiController) GetLastOrNextHisPrescription() {
  9466. change_type, _ := this.GetInt64("type", 0)
  9467. record_date := this.GetString("record_time")
  9468. patient_id, _ := this.GetInt64("patient_id", 0)
  9469. p_type, _ := this.GetInt64("p_type", 0)
  9470. timeLayout := "2006-01-02"
  9471. loc, _ := time.LoadLocation("Local")
  9472. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  9473. record_time := theAdviceRecordTime.Unix()
  9474. adminUserInfo := this.GetAdminUserInfo()
  9475. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  9476. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  9477. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9478. if config.ID > 0 && config.IsOpen == 1 {
  9479. for _, subitems := range prescriptions {
  9480. for _, item := range subitems.VMHisPrescription {
  9481. for _, subItem := range item.HisDoctorAdviceInfo {
  9482. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9483. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9484. if info.RetailPrice > 0 {
  9485. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9486. subItem.Drug.RetailPrice = drug.RetailPrice
  9487. }
  9488. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9489. subItem.Drug.MinPrice = info.RetailPrice
  9490. subItem.Drug.RetailPrice = info.RetailPrice
  9491. }
  9492. }
  9493. }
  9494. }
  9495. }
  9496. }
  9497. if config.ID > 0 && config.IsOpen == 1 {
  9498. for _, subitems := range prescriptions {
  9499. for _, item := range subitems.VMHisPrescription {
  9500. for _, subItem := range item.HisPrescriptionProject {
  9501. if subItem.Type == 3 {
  9502. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9503. if info.Price > 0 {
  9504. subItem.GoodInfo.PackingPrice = info.Price
  9505. }
  9506. }
  9507. }
  9508. }
  9509. }
  9510. }
  9511. }
  9512. if err == nil {
  9513. if len(prescriptions) == 0 {
  9514. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  9515. return
  9516. } else {
  9517. this.ServeSuccessJSON(map[string]interface{}{
  9518. "prescriptions": prescriptions,
  9519. })
  9520. return
  9521. }
  9522. } else {
  9523. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9524. return
  9525. }
  9526. }
  9527. func (this *HisApiController) GetCallHisPrescription() {
  9528. patient_id, _ := this.GetInt64("patient_id", 0)
  9529. timeLayout := "2006-01-02"
  9530. loc, _ := time.LoadLocation("Local")
  9531. start_time := this.GetString("start_time")
  9532. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9533. end_time := this.GetString("end_time")
  9534. p_type, _ := this.GetInt64("p_type")
  9535. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9536. adminUserInfo := this.GetAdminUserInfo()
  9537. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  9538. //if
  9539. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  9540. //
  9541. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  9542. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  9543. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9544. if config.ID > 0 && config.IsOpen == 1 {
  9545. for _, subitems := range prescriptions {
  9546. for _, item := range subitems.VMHisPrescription {
  9547. for _, subItem := range item.HisDoctorAdviceInfo {
  9548. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9549. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9550. if info.RetailPrice > 0 {
  9551. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9552. subItem.Drug.RetailPrice = drug.RetailPrice
  9553. }
  9554. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9555. subItem.Drug.MinPrice = info.RetailPrice
  9556. subItem.Drug.RetailPrice = info.RetailPrice
  9557. }
  9558. }
  9559. }
  9560. }
  9561. }
  9562. }
  9563. if config.ID > 0 && config.IsOpen == 1 {
  9564. for _, subitems := range prescriptions {
  9565. for _, item := range subitems.VMHisPrescription {
  9566. for _, subItem := range item.HisPrescriptionProject {
  9567. if subItem.Type == 3 {
  9568. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9569. if info.Price > 0 {
  9570. subItem.GoodInfo.PackingPrice = info.Price
  9571. }
  9572. }
  9573. }
  9574. }
  9575. }
  9576. }
  9577. }
  9578. if err == nil {
  9579. this.ServeSuccessJSON(map[string]interface{}{
  9580. "prescriptions": prescriptions,
  9581. })
  9582. return
  9583. } else {
  9584. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9585. return
  9586. }
  9587. }
  9588. func (this *HisApiController) GetHisDayPrescription() {
  9589. timeLayout := "2006-01-02"
  9590. loc, _ := time.LoadLocation("Local")
  9591. start_time := this.GetString("start_time")
  9592. patient_id, _ := this.GetInt64("patient_id", 0)
  9593. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9594. end_time := this.GetString("end_time")
  9595. p_type, _ := this.GetInt64("p_type")
  9596. order_status, _ := this.GetInt64("type")
  9597. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9598. adminUserInfo := this.GetAdminUserInfo()
  9599. var dayHisPrescription []*models.HisPrescription
  9600. var err error
  9601. if order_status == 1 || order_status == 0 {
  9602. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  9603. } else if order_status == 2 {
  9604. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  9605. }
  9606. var settle_total float64
  9607. for _, item := range dayHisPrescription {
  9608. if len(item.HisPrescriptionProject) > 0 {
  9609. for _, subItem := range item.HisPrescriptionProject {
  9610. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9611. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9612. settle_total = settle_total + total
  9613. }
  9614. }
  9615. if len(item.HisDoctorAdviceInfo) > 0 {
  9616. for _, subItem := range item.HisDoctorAdviceInfo {
  9617. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9618. settle_total = settle_total + total
  9619. }
  9620. }
  9621. }
  9622. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9623. if err == nil {
  9624. this.ServeSuccessJSON(map[string]interface{}{
  9625. "day_prescription": dayHisPrescription,
  9626. "settle_total": settle_total,
  9627. })
  9628. return
  9629. } else {
  9630. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9631. return
  9632. }
  9633. }
  9634. func (c *HisApiController) GetHisChargePatientList() {
  9635. record_date := c.GetString("record_date")
  9636. order_status, _ := c.GetInt64("type")
  9637. sch_type, _ := c.GetInt64("sch_type")
  9638. timeLayout := "2006-01-02"
  9639. loc, _ := time.LoadLocation("Local")
  9640. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9641. if err != nil {
  9642. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9643. return
  9644. }
  9645. recordDateTime := theTime.Unix()
  9646. adminInfo := c.GetAdminUserInfo()
  9647. var tempPatients []*service.NewTempPatients
  9648. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  9649. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  9650. if order_status != 2 {
  9651. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9652. } else {
  9653. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9654. }
  9655. } else {
  9656. if order_status != 2 {
  9657. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9658. } else {
  9659. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9660. }
  9661. }
  9662. var patients []*service.NewTempPatients
  9663. var patients_two []*service.NewTempPatients
  9664. for _, item := range tempPatients {
  9665. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  9666. //过滤掉没挂号的和没开处方的
  9667. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  9668. patients = append(patients, item)
  9669. }
  9670. //过滤掉没挂号的
  9671. if len(item.HisPatient) > 0 {
  9672. patients_two = append(patients_two, item)
  9673. }
  9674. } else {
  9675. if len(item.HisPrescription) > 0 {
  9676. patients = append(patients, item)
  9677. }
  9678. }
  9679. }
  9680. c.ServeSuccessJSON(map[string]interface{}{
  9681. "list": patients,
  9682. "list_two": patients_two,
  9683. })
  9684. }
  9685. func (c *HisApiController) GetHisUnRegisterPatientList() {
  9686. record_date := c.GetString("record_date")
  9687. timeLayout := "2006-01-02"
  9688. loc, _ := time.LoadLocation("Local")
  9689. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9690. if err != nil {
  9691. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9692. return
  9693. }
  9694. recordDateTime := theTime.Unix()
  9695. adminUser := c.GetAdminUserInfo()
  9696. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  9697. var patients []*service.Patients
  9698. for _, item := range tempPatients {
  9699. if item.HisPatient.ID == 0 {
  9700. patients = append(patients, item)
  9701. }
  9702. }
  9703. c.ServeSuccessJSON(map[string]interface{}{
  9704. "list": patients,
  9705. //"list_two": patients_two,
  9706. })
  9707. }
  9708. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  9709. newArr = make([]*service.Patients, 0)
  9710. for i := 0; i < len(patient); i++ {
  9711. repeat := false
  9712. for j := i + 1; j < len(patient); j++ {
  9713. if patient[i].ID == patient[j].ID {
  9714. repeat = true
  9715. break
  9716. }
  9717. }
  9718. if !repeat {
  9719. newArr = append(newArr, patient[i])
  9720. }
  9721. }
  9722. return
  9723. }
  9724. func (c *HisApiController) GetHisChargePatientInfo() {
  9725. patient_id, _ := c.GetInt64("patient_id")
  9726. his_patient_id, _ := c.GetInt64("his_patient_id")
  9727. record_date := c.GetString("record_date")
  9728. //start_time := c.GetString("start_time")
  9729. //end_time := c.GetString("end_time")
  9730. order_status, _ := c.GetInt64("type", 0)
  9731. p_type, _ := c.GetInt64("p_type", 0)
  9732. order_id, _ := c.GetInt64("order_id", 0)
  9733. timeLayout := "2006-01-02"
  9734. loc, _ := time.LoadLocation("Local")
  9735. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9736. if err != nil {
  9737. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9738. return
  9739. }
  9740. recordDateTime := theTime.Unix()
  9741. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9742. //if err != nil {
  9743. //
  9744. //}
  9745. //startRecordDateTime := startTime.Unix()
  9746. //
  9747. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9748. //if err != nil {
  9749. //
  9750. //}
  9751. //endRecordDateTime := endTime.Unix()
  9752. admin := c.GetAdminUserInfo()
  9753. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9754. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9755. var prescriptions []*models.HisPrescription
  9756. //var unChargeMonthPrescriptions []*models.HisPrescription
  9757. order, _ := service.GetHisOrderByID(order_id)
  9758. if order_status == 1 || order_status == 0 {
  9759. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  9760. } else if order_status == 2 {
  9761. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  9762. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9763. }
  9764. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9765. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9766. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9767. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9768. //获取所有科室信息
  9769. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9770. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  9771. c.ServeSuccessJSON(map[string]interface{}{
  9772. "his_info": his_patient_info,
  9773. "xt_info": xt_patient_info,
  9774. "prescription": prescriptions,
  9775. "case_history": case_history,
  9776. "info": patientPrescriptionInfo,
  9777. "last_info": lastPatientPrescriptionInfo,
  9778. "order": order,
  9779. "doctors": doctors,
  9780. "department": department,
  9781. "sch": sch,
  9782. })
  9783. return
  9784. }
  9785. func (c *HisApiController) GetAllOrderDetail() {
  9786. order_id, _ := c.GetInt64("id", 0)
  9787. order, _ := service.GetHisOrderByID(order_id)
  9788. if order.ID == 0 {
  9789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9790. return
  9791. }
  9792. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9793. org_id := c.GetAdminUserInfo().CurrentOrgId
  9794. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9795. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9796. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9797. c.ServeSuccessJSON(map[string]interface{}{
  9798. "order": order,
  9799. "order_info": order_info,
  9800. "patient": patient,
  9801. "admin_info": adminInfo,
  9802. "hospital_record": record,
  9803. })
  9804. return
  9805. }
  9806. func (c *HisApiController) GetAllOrderDetailCollect() {
  9807. order_id, _ := c.GetInt64("id", 0)
  9808. order, _ := service.GetHisOrderByID(order_id)
  9809. if order.ID == 0 {
  9810. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9811. return
  9812. }
  9813. org_id := c.GetAdminUserInfo().CurrentOrgId
  9814. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9815. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9816. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9817. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  9818. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  9819. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9820. var bedCostTotal float64 = 0 //床位总费
  9821. //var bedCostSelfTotal float64 = 0 //床位自费
  9822. var operationCostTotal float64 = 0 //手术费
  9823. //var operationCostSelfTotal float64 = 0 //手术费
  9824. var otherCostTotal float64 = 0 //其他费用
  9825. //var otherCostSelfTotal float64 = 0 //其他费用
  9826. var materialCostTotal float64 = 0 //材料费
  9827. //var materialCostSelfTotal float64 = 0 //材料费
  9828. var westernMedicineCostTotal float64 = 0 //西药费
  9829. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  9830. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9831. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9832. var checkCostTotal float64 = 0 //检查费
  9833. //var checkCostSelfTotal float64 = 0 //检查费
  9834. var laboratoryCostTotal float64 = 0 //化验费
  9835. //var laboratoryCostSelfTotal float64 = 0 //化验费
  9836. var treatCostTotal float64 = 0 //治疗费用
  9837. //var treatCostSelfTotal float64 = 0 //治疗费用
  9838. var zhenChaCostTotal float64 = 0 //其他费用
  9839. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9840. decimal.DivisionPrecision = 2
  9841. var BalanceAccountsType int64
  9842. if his.ID > 0 {
  9843. BalanceAccountsType = his.BalanceAccountsType
  9844. } else {
  9845. BalanceAccountsType = record.BalanceAccountsType
  9846. }
  9847. if BalanceAccountsType != 2 {
  9848. for _, item := range order_info {
  9849. if org_id == 10215 {
  9850. if item.MedChrgitmType == "01" { //床位费
  9851. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9852. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9853. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9854. }
  9855. if item.MedChrgitmType == "02" { //诊察费
  9856. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9857. //zhenChaCostSelfTotal = zhenChaCostTotal
  9858. }
  9859. if item.MedChrgitmType == "03" { //检查费
  9860. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9861. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9862. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9863. }
  9864. //if item.MedChrgitmType == "02" { //检查费
  9865. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9866. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9867. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9868. //}
  9869. if item.MedChrgitmType == "04" { //化验费
  9870. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9871. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9872. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9873. }
  9874. if item.MedChrgitmType == "05" { //治疗费
  9875. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9876. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9877. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9878. }
  9879. if item.MedChrgitmType == "06" { //手术费
  9880. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9881. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9882. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9883. }
  9884. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9885. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9886. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9887. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9888. }
  9889. if item.MedChrgitmType == "09" { //西药费
  9890. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9891. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9892. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9893. }
  9894. if item.MedChrgitmType == "11" { //中成费
  9895. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9896. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9897. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9898. }
  9899. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9900. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9901. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9902. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9903. }
  9904. } else if org_id == 10188 || org_id == 10217 {
  9905. if item.MedChrgitmType == "01" { //床位费
  9906. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9907. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9908. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9909. }
  9910. if item.MedChrgitmType == "02" { //诊察费
  9911. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9912. //zhenChaCostSelfTotal = zhenChaCostTotal
  9913. }
  9914. if item.MedChrgitmType == "03" { //检查费
  9915. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9916. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9917. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9918. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9919. }
  9920. //if item.MedChrgitmType == "02" { //检查费
  9921. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9922. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9923. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9924. //}
  9925. if item.MedChrgitmType == "04" { //化验费
  9926. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9927. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9928. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9929. }
  9930. if item.MedChrgitmType == "05" { //治疗费
  9931. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9932. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9933. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9934. }
  9935. if item.MedChrgitmType == "06" { //手术费
  9936. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9937. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9938. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9939. }
  9940. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9941. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9942. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9943. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9944. }
  9945. if item.MedChrgitmType == "09" { //西药费
  9946. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9947. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9948. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9949. }
  9950. if item.MedChrgitmType == "11" { //中成费
  9951. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9952. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9953. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9954. }
  9955. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9956. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9957. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9958. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9959. }
  9960. } else {
  9961. if item.MedChrgitmType == "01" { //床位费
  9962. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9963. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9964. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9965. }
  9966. //if item.MedChrgitmType == "02" { //诊察费
  9967. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9968. // //zhenChaCostSelfTotal = zhenChaCostTotal
  9969. //}
  9970. if item.MedChrgitmType == "03" { //检查费
  9971. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9972. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9973. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9974. }
  9975. //if item.MedChrgitmType == "02" { //检查费
  9976. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9977. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9978. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9979. //}
  9980. if item.MedChrgitmType == "04" { //化验费
  9981. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9982. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9983. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9984. }
  9985. if item.MedChrgitmType == "05" { //治疗费
  9986. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9987. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9988. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9989. }
  9990. if item.MedChrgitmType == "06" { //手术费
  9991. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9992. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9993. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9994. }
  9995. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9996. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9997. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9998. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9999. }
  10000. if item.MedChrgitmType == "09" { //西药费
  10001. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10002. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10003. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10004. }
  10005. if item.MedChrgitmType == "11" { //中成费
  10006. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10007. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10008. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10009. }
  10010. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10011. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10012. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10013. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10014. }
  10015. }
  10016. }
  10017. c.ServeSuccessJSON(map[string]interface{}{
  10018. "order": order,
  10019. "order_info": order_info,
  10020. "patient": patient,
  10021. "admin_info": adminInfo,
  10022. "his_hospital": record,
  10023. "bedCostTotal": bedCostTotal,
  10024. "operationCostTotal": operationCostTotal,
  10025. "otherCostTotal": otherCostTotal,
  10026. "materialCostTotal": materialCostTotal,
  10027. "westernMedicineCostTotal": westernMedicineCostTotal,
  10028. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10029. "checkCostTotal": checkCostTotal,
  10030. "zhenChaCostTotal": zhenChaCostTotal,
  10031. "laboratoryCostTotal": laboratoryCostTotal,
  10032. "treatCostTotal": treatCostTotal,
  10033. })
  10034. } else {
  10035. for _, item := range order_info {
  10036. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10037. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10038. item.MedChrgitmType = "09"
  10039. }
  10040. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10041. if item.HisPrescriptionProject.Type == 2 {
  10042. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10043. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10044. case 0:
  10045. item.MedChrgitmType = "0"
  10046. break
  10047. case 1:
  10048. item.MedChrgitmType = "14"
  10049. break
  10050. case 2:
  10051. item.MedChrgitmType = "05"
  10052. break
  10053. case 3:
  10054. item.MedChrgitmType = "03"
  10055. break
  10056. case 4:
  10057. item.MedChrgitmType = "03"
  10058. break
  10059. case 5:
  10060. item.MedChrgitmType = "08"
  10061. break
  10062. case 6:
  10063. item.MedChrgitmType = "14"
  10064. break
  10065. case 7:
  10066. item.MedChrgitmType = "14"
  10067. break
  10068. case 8:
  10069. item.MedChrgitmType = "03"
  10070. break
  10071. case 9:
  10072. item.MedChrgitmType = "14"
  10073. break
  10074. case 10:
  10075. item.MedChrgitmType = "14"
  10076. break
  10077. case 11:
  10078. item.MedChrgitmType = "06"
  10079. break
  10080. case 12:
  10081. item.MedChrgitmType = "12"
  10082. break
  10083. case 13:
  10084. item.MedChrgitmType = "01"
  10085. break
  10086. case 14:
  10087. item.MedChrgitmType = "04"
  10088. break
  10089. case 15:
  10090. item.MedChrgitmType = "14"
  10091. break
  10092. }
  10093. } else {
  10094. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10095. case 1:
  10096. item.MedChrgitmType = "14"
  10097. break
  10098. case 2:
  10099. item.MedChrgitmType = "05"
  10100. break
  10101. case 3:
  10102. item.MedChrgitmType = "04"
  10103. break
  10104. case 4:
  10105. item.MedChrgitmType = "14"
  10106. break
  10107. case 5:
  10108. item.MedChrgitmType = "08"
  10109. break
  10110. case 6:
  10111. item.MedChrgitmType = "14"
  10112. break
  10113. case 7:
  10114. item.MedChrgitmType = "14"
  10115. break
  10116. case 8:
  10117. item.MedChrgitmType = "03"
  10118. break
  10119. case 9:
  10120. item.MedChrgitmType = "14"
  10121. break
  10122. }
  10123. }
  10124. } else if item.HisPrescriptionProject.Type == 3 {
  10125. item.MedChrgitmType = "08"
  10126. }
  10127. }
  10128. }
  10129. for _, item := range order_info {
  10130. if org_id == 10215 {
  10131. if item.MedChrgitmType == "01" { //床位费
  10132. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10133. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10134. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10135. }
  10136. if item.MedChrgitmType == "02" { //诊察费
  10137. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10138. //zhenChaCostSelfTotal = zhenChaCostTotal
  10139. }
  10140. if item.MedChrgitmType == "03" { //检查费
  10141. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10142. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10143. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10144. }
  10145. //if item.MedChrgitmType == "02" { //检查费
  10146. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10147. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10148. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10149. //}
  10150. if item.MedChrgitmType == "04" { //化验费
  10151. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10152. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10153. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10154. }
  10155. if item.MedChrgitmType == "05" { //治疗费
  10156. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10157. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10158. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10159. }
  10160. if item.MedChrgitmType == "06" { //手术费
  10161. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10162. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10163. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10164. }
  10165. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10166. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10167. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10168. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10169. }
  10170. if item.MedChrgitmType == "09" { //西药费
  10171. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10172. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10173. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10174. }
  10175. if item.MedChrgitmType == "11" { //中成费
  10176. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10177. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10178. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10179. }
  10180. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10181. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10182. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10183. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10184. }
  10185. } else {
  10186. if item.MedChrgitmType == "01" { //床位费
  10187. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10188. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10189. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10190. }
  10191. //if item.MedChrgitmType == "02" { //诊察费
  10192. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10193. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10194. //}
  10195. if item.MedChrgitmType == "03" { //检查费
  10196. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10197. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10198. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10199. }
  10200. //if item.MedChrgitmType == "02" { //检查费
  10201. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10202. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10203. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10204. //}
  10205. if item.MedChrgitmType == "04" { //化验费
  10206. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10207. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10208. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10209. }
  10210. if item.MedChrgitmType == "05" { //治疗费
  10211. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10212. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10213. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10214. }
  10215. if item.MedChrgitmType == "06" { //手术费
  10216. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10217. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10218. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10219. }
  10220. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10221. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10222. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10223. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10224. }
  10225. if item.MedChrgitmType == "09" { //西药费
  10226. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10227. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10228. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10229. }
  10230. if item.MedChrgitmType == "11" { //中成费
  10231. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10232. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10233. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10234. }
  10235. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10236. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10237. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10238. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10239. }
  10240. }
  10241. }
  10242. c.ServeSuccessJSON(map[string]interface{}{
  10243. "order": order,
  10244. "order_info": order_info,
  10245. "patient": patient,
  10246. "admin_info": adminInfo,
  10247. "his_hospital": record,
  10248. "bedCostTotal": bedCostTotal,
  10249. "operationCostTotal": operationCostTotal,
  10250. "otherCostTotal": otherCostTotal,
  10251. "materialCostTotal": materialCostTotal,
  10252. "westernMedicineCostTotal": westernMedicineCostTotal,
  10253. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10254. "checkCostTotal": checkCostTotal,
  10255. "zhenChaCostTotal": zhenChaCostTotal,
  10256. "laboratoryCostTotal": laboratoryCostTotal,
  10257. "treatCostTotal": treatCostTotal,
  10258. })
  10259. }
  10260. }
  10261. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  10262. page, _ := c.GetInt64("page")
  10263. limit, _ := c.GetInt64("limit")
  10264. keywords := c.GetString("keywords")
  10265. start_time := c.GetString("start_time")
  10266. end_time := c.GetString("end_time")
  10267. //clr_type := c.GetString("clr_type")
  10268. insutype := c.GetString("insutype")
  10269. timeLayout := "2006-01-02"
  10270. loc, _ := time.LoadLocation("Local")
  10271. var theStartTIme int64
  10272. if len(start_time) > 0 {
  10273. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10274. theStartTIme = theTime.Unix()
  10275. }
  10276. var theEndtTIme int64
  10277. if len(end_time) > 0 {
  10278. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10279. theEndtTIme = theTime.Unix()
  10280. }
  10281. if page <= 0 {
  10282. page = 1
  10283. }
  10284. if limit <= 0 {
  10285. limit = 10
  10286. }
  10287. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  10288. c.ServeSuccessJSON(map[string]interface{}{
  10289. "total": total,
  10290. "list": list,
  10291. })
  10292. return
  10293. }
  10294. func (c *HisApiController) GetPutOnRecordList() {
  10295. page, _ := c.GetInt64("page")
  10296. limit, _ := c.GetInt64("limit")
  10297. keywords := c.GetString("keywords")
  10298. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  10299. if page <= 0 {
  10300. page = 1
  10301. }
  10302. if limit <= 0 {
  10303. limit = 10
  10304. }
  10305. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  10306. c.ServeSuccessJSON(map[string]interface{}{
  10307. "total": total,
  10308. "list": list,
  10309. })
  10310. return
  10311. }
  10312. func (c *HisApiController) GetCompareData() {
  10313. start_time := c.GetString("start_time")
  10314. end_time := c.GetString("end_time")
  10315. insutype := c.GetString("insutype")
  10316. clr_type := c.GetString("clr_type")
  10317. timeLayout := "2006-01-02"
  10318. loc, _ := time.LoadLocation("Local")
  10319. var theStartTIme int64
  10320. if len(start_time) > 0 {
  10321. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10322. if err != nil {
  10323. theStartTIme = 0
  10324. }
  10325. theStartTIme = theTime.Unix()
  10326. }
  10327. var theEndtTIme int64
  10328. if len(end_time) > 0 {
  10329. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10330. if err != nil {
  10331. theEndtTIme = 0
  10332. }
  10333. theEndtTIme = theTime.Unix()
  10334. }
  10335. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  10336. fmt.Println(err)
  10337. if err == nil {
  10338. c.ServeSuccessJSON(map[string]interface{}{
  10339. "list": formData,
  10340. })
  10341. } else {
  10342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10343. return
  10344. }
  10345. }
  10346. func (c *HisApiController) GetFaPiaoData() {
  10347. order_id, _ := c.GetInt64("order_id")
  10348. patient_id, _ := c.GetInt64("patient_id")
  10349. //number := c.GetString("number")
  10350. adminUser := c.GetAdminUserInfo()
  10351. order, _ := service.GetHisOrderByID(order_id)
  10352. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10353. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10354. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10355. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10356. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  10357. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  10358. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10359. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10360. var bedCostTotal float64 = 0 //床位总费
  10361. var bedCostSelfTotal float64 = 0 //床位自费
  10362. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10363. var operationCostTotal float64 = 0 //手术费
  10364. var operationCostSelfTotal float64 = 0 //手术费
  10365. var operationCostPartSelfTotal float64 = 0 //手术费
  10366. var otherCostTotal float64 = 0 //其他费用
  10367. var otherCostSelfTotal float64 = 0 //其他费用
  10368. var otherCostPartSelfTotal float64 = 0 //其他费用
  10369. var materialCostTotal float64 = 0 //材料费
  10370. var materialCostSelfTotal float64 = 0 //材料费
  10371. var materialCostPartSelfTotal float64 = 0 //材料费
  10372. var westernMedicineCostTotal float64 = 0 //西药费
  10373. var westernMedicineCostSelfTotal float64 = 0 //西药费
  10374. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10375. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10376. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10377. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10378. var checkCostTotal float64 = 0 //检查费
  10379. var checkCostSelfTotal float64 = 0 //检查费
  10380. var checkCostPartSelfTotal float64 = 0 //检查费
  10381. var hiliCostTotal float64 = 0 //护理费
  10382. var hiliCostSelfTotal float64 = 0 //护理费
  10383. var hiliCostPartSelfTotal float64 = 0 //护理费
  10384. var laboratoryCostTotal float64 = 0 //化验费
  10385. var laboratoryCostSelfTotal float64 = 0 //化验费
  10386. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10387. var treatCostTotal float64 = 0 //治疗费用
  10388. var treatCostSelfTotal float64 = 0 //治疗费用
  10389. var treatCostPartSelfTotal float64 = 0 //治疗费用
  10390. var zhenChaCostTotal float64 = 0 //其他费用
  10391. var zhenChaCostSelfTotal float64 = 0 //其他费用
  10392. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10393. decimal.DivisionPrecision = 2
  10394. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10395. var balanceAccountsType int64
  10396. if his.ID > 0 {
  10397. balanceAccountsType = his.BalanceAccountsType
  10398. } else {
  10399. balanceAccountsType = his_hospital_record.BalanceAccountsType
  10400. }
  10401. if balanceAccountsType == 2 {
  10402. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10403. for _, item := range orderInfos_two {
  10404. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10405. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10406. item.MedChrgitmType = "09"
  10407. }
  10408. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10409. if item.HisPrescriptionProject.Type == 2 {
  10410. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10411. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10412. case 0:
  10413. item.MedChrgitmType = "0"
  10414. break
  10415. case 1:
  10416. item.MedChrgitmType = "14"
  10417. break
  10418. case 2:
  10419. item.MedChrgitmType = "05"
  10420. break
  10421. case 3:
  10422. item.MedChrgitmType = "03"
  10423. break
  10424. case 4:
  10425. item.MedChrgitmType = "03"
  10426. break
  10427. case 5:
  10428. item.MedChrgitmType = "08"
  10429. break
  10430. case 6:
  10431. item.MedChrgitmType = "14"
  10432. break
  10433. case 7:
  10434. item.MedChrgitmType = "14"
  10435. break
  10436. case 8:
  10437. item.MedChrgitmType = "03"
  10438. break
  10439. case 9:
  10440. item.MedChrgitmType = "14"
  10441. break
  10442. case 10:
  10443. item.MedChrgitmType = "14"
  10444. break
  10445. case 11:
  10446. item.MedChrgitmType = "06"
  10447. break
  10448. case 12:
  10449. item.MedChrgitmType = "12"
  10450. break
  10451. case 13:
  10452. item.MedChrgitmType = "01"
  10453. break
  10454. case 14:
  10455. item.MedChrgitmType = "04"
  10456. break
  10457. case 15:
  10458. item.MedChrgitmType = "02"
  10459. break
  10460. }
  10461. } else {
  10462. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10463. case 1:
  10464. item.MedChrgitmType = "14"
  10465. break
  10466. case 2:
  10467. item.MedChrgitmType = "05"
  10468. break
  10469. case 3:
  10470. item.MedChrgitmType = "04"
  10471. break
  10472. case 4:
  10473. item.MedChrgitmType = "03"
  10474. break
  10475. case 5:
  10476. item.MedChrgitmType = "08"
  10477. break
  10478. case 6:
  10479. item.MedChrgitmType = "14"
  10480. break
  10481. case 7:
  10482. item.MedChrgitmType = "14"
  10483. break
  10484. case 8:
  10485. item.MedChrgitmType = "03"
  10486. break
  10487. case 9:
  10488. item.MedChrgitmType = "14"
  10489. break
  10490. }
  10491. }
  10492. } else if item.HisPrescriptionProject.Type == 3 {
  10493. item.MedChrgitmType = "08"
  10494. }
  10495. }
  10496. }
  10497. for _, item := range orderInfos_two {
  10498. fmt.Println(item.MedChrgitmType)
  10499. if item.MedChrgitmType == "07" { //床位费
  10500. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10501. hiliCostSelfTotal = hiliCostTotal
  10502. }
  10503. if item.MedChrgitmType == "01" { //床位费
  10504. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10505. bedCostSelfTotal = bedCostTotal
  10506. }
  10507. if item.MedChrgitmType == "02" { //诊察费
  10508. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10509. zhenChaCostSelfTotal = zhenChaCostTotal
  10510. }
  10511. if item.MedChrgitmType == "03" { //检查费
  10512. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10513. checkCostSelfTotal = checkCostTotal
  10514. }
  10515. if item.MedChrgitmType == "04" { //化验费
  10516. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10517. laboratoryCostSelfTotal = laboratoryCostTotal
  10518. }
  10519. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10520. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10521. treatCostSelfTotal = treatCostTotal
  10522. }
  10523. if item.MedChrgitmType == "06" { //手术费
  10524. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10525. operationCostSelfTotal = treatCostTotal
  10526. }
  10527. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  10528. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10529. materialCostSelfTotal = materialCostTotal
  10530. }
  10531. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10532. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10533. westernMedicineCostSelfTotal = westernMedicineCostTotal
  10534. }
  10535. if item.MedChrgitmType == "11" { //中成费
  10536. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10537. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10538. }
  10539. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10540. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10541. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10542. otherCostSelfTotal = otherCostTotal
  10543. }
  10544. } else {
  10545. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10546. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10547. otherCostSelfTotal = otherCostTotal
  10548. }
  10549. }
  10550. }
  10551. } else {
  10552. for _, item := range orderInfos {
  10553. if item.MedChrgitmType == "01" { //床位费
  10554. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10555. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10556. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10557. }
  10558. if item.MedChrgitmType == "02" { //诊察费
  10559. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10560. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10561. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10562. }
  10563. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  10564. if item.MedChrgitmType == "03" { //检查费
  10565. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10566. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10567. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10568. }
  10569. } else {
  10570. if item.MedChrgitmType == "03" { //检查费
  10571. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10572. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10573. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10574. }
  10575. }
  10576. if item.MedChrgitmType == "04" { //化验费
  10577. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10578. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10579. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10580. }
  10581. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10582. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10583. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10584. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10585. }
  10586. if item.MedChrgitmType == "06" { //手术费
  10587. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10588. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10589. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10590. }
  10591. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  10592. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10593. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10594. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10595. }
  10596. if item.MedChrgitmType == "07" { //护理
  10597. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10598. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10599. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10600. }
  10601. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10602. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10603. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10604. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10605. }
  10606. if item.MedChrgitmType == "11" { //中成费
  10607. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10608. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10609. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10610. }
  10611. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10612. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10613. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10614. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10615. }
  10616. }
  10617. }
  10618. timeLayout := "2006-01-02"
  10619. loc, _ := time.LoadLocation("Local")
  10620. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  10621. if err != nil {
  10622. }
  10623. startRecordDateTime := startTime.Unix()
  10624. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  10625. if err != nil {
  10626. }
  10627. endRecordDateTime := endTime.Unix()
  10628. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  10629. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  10630. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  10631. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  10632. c.ServeSuccessJSON(map[string]interface{}{
  10633. "charge_admin_name": charge_admin.UserName,
  10634. "order_number": order.Number, //业务流水号
  10635. "id_card_no": his.IdCardNo, //社会保障号
  10636. "patient": patient,
  10637. "department_name": department.Name, //科室
  10638. "number": his.Number, //门诊号
  10639. "date": order.SettleAccountsDate, //结算日期
  10640. "name": order.PsnName, //姓名
  10641. "gender": patient.Gender, //性别
  10642. "psn_cash_money": order.PsnCashPay, //个人支付
  10643. "pay_way": "门诊", //结算方式
  10644. "medfee_sumamt": order.MedfeeSumamt, //总费用
  10645. "admin_user_name": admin.UserName, //收款员
  10646. "order": order,
  10647. "order_info": orderInfos_two,
  10648. "his": his,
  10649. "bedCostTotal": bedCostTotal,
  10650. "bedCostSelfTotal": bedCostSelfTotal,
  10651. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  10652. "operationCostTotal": operationCostTotal,
  10653. "operationCostSelfTotal": operationCostSelfTotal,
  10654. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  10655. "otherCostTotal": otherCostTotal,
  10656. "otherCostSelfTotal": otherCostSelfTotal,
  10657. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  10658. "materialCostTotal": materialCostTotal,
  10659. "materialCostSelfTotal": materialCostSelfTotal,
  10660. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  10661. "westernMedicineCostTotal": westernMedicineCostTotal,
  10662. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  10663. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  10664. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10665. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  10666. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  10667. "checkCostTotal": checkCostTotal,
  10668. "checkCostSelfTotal": checkCostSelfTotal,
  10669. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  10670. "laboratoryCostTotal": laboratoryCostTotal,
  10671. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  10672. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  10673. "treatCostTotal": treatCostTotal,
  10674. "treatCostSelfTotal": treatCostSelfTotal,
  10675. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  10676. "zhenChaCostTotal": zhenChaCostTotal,
  10677. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  10678. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  10679. "his_hospital_record": his_hospital_record,
  10680. "pre_pay_money": pre_pay_money,
  10681. "refund_sum": sum,
  10682. "doctor_info": doctor_info,
  10683. "hiliCostTotal": hiliCostTotal,
  10684. "hiliCostSelfTotal": hiliCostSelfTotal,
  10685. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  10686. })
  10687. }
  10688. //func (c *HisApiController) GetFaPiaoDatas() {
  10689. // order_ids := c.GetString("order_ids")
  10690. // patient_id, _ := c.GetInt64("patient_id")
  10691. // adminUser := c.GetAdminUserInfo()
  10692. //
  10693. // orders := strings.Split(order_ids, ",")
  10694. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10695. //
  10696. // for _, item := range orders {
  10697. // order_id, _ := strconv.ParseInt(item, 10, 64)
  10698. // order, _ := service.GetHisOrderByID(order_id)
  10699. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10700. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10701. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10702. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10703. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10704. //
  10705. // }
  10706. //
  10707. // var bedCostTotal float64 = 0 //床位总费
  10708. // var bedCostSelfTotal float64 = 0 //床位自费
  10709. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10710. //
  10711. // var operationCostTotal float64 = 0 //手术费
  10712. // var operationCostSelfTotal float64 = 0 //手术费
  10713. // var operationCostPartSelfTotal float64 = 0 //手术费
  10714. //
  10715. // var otherCostTotal float64 = 0 //其他费用
  10716. // var otherCostSelfTotal float64 = 0 //其他费用
  10717. // var otherCostPartSelfTotal float64 = 0 //其他费用
  10718. //
  10719. // var materialCostTotal float64 = 0 //材料费
  10720. // var materialCostSelfTotal float64 = 0 //材料费
  10721. // var materialCostPartSelfTotal float64 = 0 //材料费
  10722. //
  10723. // var westernMedicineCostTotal float64 = 0 //西药费
  10724. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  10725. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10726. //
  10727. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10728. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10729. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10730. //
  10731. // var checkCostTotal float64 = 0 //检查费
  10732. // var checkCostSelfTotal float64 = 0 //检查费
  10733. // var checkCostPartSelfTotal float64 = 0 //检查费
  10734. //
  10735. // var laboratoryCostTotal float64 = 0 //化验费
  10736. // var laboratoryCostSelfTotal float64 = 0 //化验费
  10737. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10738. //
  10739. // var treatCostTotal float64 = 0 //治疗费用
  10740. // var treatCostSelfTotal float64 = 0 //治疗费用
  10741. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  10742. //
  10743. // var zhenChaCostTotal float64 = 0 //其他费用
  10744. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  10745. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10746. //
  10747. // decimal.DivisionPrecision = 2
  10748. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10749. //
  10750. // var balanceAccountsType int64
  10751. // if his.ID > 0 {
  10752. // balanceAccountsType = his.BalanceAccountsType
  10753. // } else {
  10754. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  10755. // }
  10756. // if balanceAccountsType == 2 {
  10757. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10758. // for _, item := range orderInfos_two {
  10759. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10760. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10761. // item.MedChrgitmType = "09"
  10762. // }
  10763. //
  10764. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10765. // if item.HisPrescriptionProject.Type == 2 {
  10766. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10767. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10768. // case 0:
  10769. // item.MedChrgitmType = "0"
  10770. // break
  10771. // case 1:
  10772. // item.MedChrgitmType = "14"
  10773. // break
  10774. // case 2:
  10775. // item.MedChrgitmType = "05"
  10776. //
  10777. // break
  10778. // case 3:
  10779. // item.MedChrgitmType = "03"
  10780. //
  10781. // break
  10782. // case 4:
  10783. // item.MedChrgitmType = "03"
  10784. //
  10785. // break
  10786. // case 5:
  10787. // item.MedChrgitmType = "08"
  10788. //
  10789. // break
  10790. // case 6:
  10791. // item.MedChrgitmType = "14"
  10792. //
  10793. // break
  10794. // case 7:
  10795. // item.MedChrgitmType = "14"
  10796. //
  10797. // break
  10798. // case 8:
  10799. // item.MedChrgitmType = "03"
  10800. // break
  10801. // case 9:
  10802. // item.MedChrgitmType = "14"
  10803. // break
  10804. // case 10:
  10805. // item.MedChrgitmType = "14"
  10806. // break
  10807. // case 11:
  10808. // item.MedChrgitmType = "06"
  10809. // break
  10810. // case 12:
  10811. // item.MedChrgitmType = "12"
  10812. // break
  10813. // case 13:
  10814. // item.MedChrgitmType = "01"
  10815. // break
  10816. // case 14:
  10817. // item.MedChrgitmType = "04"
  10818. // break
  10819. // case 15:
  10820. // item.MedChrgitmType = "02"
  10821. // break
  10822. //
  10823. // }
  10824. //
  10825. // } else {
  10826. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10827. //
  10828. // case 1:
  10829. // item.MedChrgitmType = "14"
  10830. // break
  10831. // case 2:
  10832. // item.MedChrgitmType = "05"
  10833. //
  10834. // break
  10835. // case 3:
  10836. // item.MedChrgitmType = "03"
  10837. //
  10838. // break
  10839. // case 4:
  10840. // item.MedChrgitmType = "03"
  10841. //
  10842. // break
  10843. // case 5:
  10844. // item.MedChrgitmType = "08"
  10845. //
  10846. // break
  10847. // case 6:
  10848. // item.MedChrgitmType = "14"
  10849. //
  10850. // break
  10851. // case 7:
  10852. // item.MedChrgitmType = "14"
  10853. //
  10854. // break
  10855. // case 8:
  10856. // item.MedChrgitmType = "03"
  10857. // break
  10858. // case 9:
  10859. // item.MedChrgitmType = "14"
  10860. // break
  10861. //
  10862. // }
  10863. //
  10864. // }
  10865. //
  10866. // } else if item.HisPrescriptionProject.Type == 3 {
  10867. // item.MedChrgitmType = "08"
  10868. // }
  10869. // }
  10870. // }
  10871. //
  10872. // for _, item := range orderInfos_two {
  10873. // fmt.Println(item.MedChrgitmType)
  10874. // if item.MedChrgitmType == "01" { //床位费
  10875. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10876. // bedCostSelfTotal = bedCostTotal
  10877. // }
  10878. //
  10879. // if item.MedChrgitmType == "02" { //诊察费
  10880. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10881. // zhenChaCostSelfTotal = zhenChaCostTotal
  10882. // }
  10883. //
  10884. // if item.MedChrgitmType == "03" { //检查费
  10885. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10886. // checkCostSelfTotal = checkCostTotal
  10887. // }
  10888. //
  10889. // if item.MedChrgitmType == "04" { //化验费
  10890. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10891. // laboratoryCostSelfTotal = laboratoryCostTotal
  10892. // }
  10893. //
  10894. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  10895. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10896. // treatCostSelfTotal = treatCostTotal
  10897. // }
  10898. //
  10899. // if item.MedChrgitmType == "06" { //手术费
  10900. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10901. // operationCostSelfTotal = treatCostTotal
  10902. // }
  10903. //
  10904. // if item.MedChrgitmType == "08" { //材料费
  10905. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10906. // materialCostSelfTotal = materialCostTotal
  10907. // }
  10908. //
  10909. // if item.MedChrgitmType == "09" { //西药费
  10910. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10911. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  10912. // }
  10913. //
  10914. // if item.MedChrgitmType == "11" { //中成费
  10915. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10916. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10917. // }
  10918. //
  10919. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10920. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10921. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10922. // otherCostSelfTotal = otherCostTotal
  10923. // }
  10924. // } else {
  10925. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10926. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10927. // otherCostSelfTotal = otherCostTotal
  10928. // }
  10929. //
  10930. // }
  10931. //
  10932. // }
  10933. //
  10934. // } else {
  10935. // for _, item := range orderInfos {
  10936. // if item.MedChrgitmType == "01" { //床位费
  10937. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10938. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10939. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10940. // }
  10941. //
  10942. // if item.MedChrgitmType == "02" { //诊察费
  10943. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10944. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10945. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10946. // }
  10947. //
  10948. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  10949. // if item.MedChrgitmType == "03" { //检查费
  10950. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10951. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10952. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10953. //
  10954. // }
  10955. // } else {
  10956. // if item.MedChrgitmType == "03" { //检查费
  10957. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10958. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10959. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10960. // }
  10961. //
  10962. // }
  10963. //
  10964. // if item.MedChrgitmType == "04" { //化验费
  10965. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10966. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10967. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10968. //
  10969. // }
  10970. //
  10971. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  10972. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10973. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10974. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10975. //
  10976. // }
  10977. //
  10978. // if item.MedChrgitmType == "06" { //手术费
  10979. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10980. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10981. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10982. // }
  10983. //
  10984. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  10985. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10986. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10987. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10988. // }
  10989. //
  10990. // if item.MedChrgitmType == "09" { //西药费
  10991. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10992. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10993. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10994. // }
  10995. //
  10996. // if item.MedChrgitmType == "11" { //中成费
  10997. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10998. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10999. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11000. // }
  11001. //
  11002. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11003. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11004. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11005. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11006. // }
  11007. //
  11008. // }
  11009. // }
  11010. // timeLayout := "2006-01-02"
  11011. // loc, _ := time.LoadLocation("Local")
  11012. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11013. // if err != nil {
  11014. // }
  11015. // startRecordDateTime := startTime.Unix()
  11016. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11017. // if err != nil {
  11018. // }
  11019. // endRecordDateTime := endTime.Unix()
  11020. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11021. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11022. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11023. //
  11024. // c.ServeSuccessJSON(map[string]interface{}{
  11025. // "order_number": order.Number, //业务流水号
  11026. // "id_card_no": his.IdCardNo, //社会保障号
  11027. // "department_name": department.Name, //科室
  11028. // "number": his.Number, //门诊号
  11029. // "date": order.SettleAccountsDate, //结算日期
  11030. // "name": order.PsnName, //姓名
  11031. // "gender": patient.Gender, //性别
  11032. // "psn_cash_money": order.PsnCashPay, //个人支付
  11033. // "pay_way": "门诊", //结算方式
  11034. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  11035. // "admin_user_name": admin.UserName, //收款员
  11036. // "order": order,
  11037. // "order_info": orderInfos_two,
  11038. // "his": his,
  11039. // "bedCostTotal": bedCostTotal,
  11040. // "bedCostSelfTotal": bedCostSelfTotal,
  11041. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11042. // "operationCostTotal": operationCostTotal,
  11043. // "operationCostSelfTotal": operationCostSelfTotal,
  11044. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11045. // "otherCostTotal": otherCostTotal,
  11046. // "otherCostSelfTotal": otherCostSelfTotal,
  11047. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11048. // "materialCostTotal": materialCostTotal,
  11049. // "materialCostSelfTotal": materialCostSelfTotal,
  11050. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11051. // "westernMedicineCostTotal": westernMedicineCostTotal,
  11052. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11053. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11054. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11055. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11056. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11057. // "checkCostTotal": checkCostTotal,
  11058. // "checkCostSelfTotal": checkCostSelfTotal,
  11059. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11060. // "laboratoryCostTotal": laboratoryCostTotal,
  11061. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11062. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11063. // "treatCostTotal": treatCostTotal,
  11064. // "treatCostSelfTotal": treatCostSelfTotal,
  11065. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11066. // "zhenChaCostTotal": zhenChaCostTotal,
  11067. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11068. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11069. // "his_hospital_record": his_hospital_record,
  11070. // "pre_pay_money": pre_pay_money,
  11071. // "refund_sum": sum,
  11072. // })
  11073. //
  11074. //}
  11075. func (this *HisApiController) GetIncomeStatisticsData() {
  11076. start_time := this.GetString("start_time")
  11077. end_time := this.GetString("end_time")
  11078. key_words := this.GetString("key_words")
  11079. limit, _ := this.GetInt64("limit")
  11080. page, _ := this.GetInt64("page")
  11081. if page <= 0 {
  11082. page = 1
  11083. }
  11084. if limit <= 0 {
  11085. limit = 10
  11086. }
  11087. statistics_type, _ := this.GetInt64("statistics_type")
  11088. admin := this.GetAdminUserInfo()
  11089. timeLayout := "2006-01-02"
  11090. loc, _ := time.LoadLocation("Local")
  11091. var theStartTIme int64
  11092. if len(start_time) > 0 {
  11093. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11094. if err != nil {
  11095. theStartTIme = 0
  11096. }
  11097. theStartTIme = theTime.Unix()
  11098. }
  11099. var theEndtTIme int64
  11100. if len(end_time) > 0 {
  11101. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11102. if err != nil {
  11103. theEndtTIme = 0
  11104. }
  11105. theEndtTIme = theTime.Unix()
  11106. }
  11107. if statistics_type == 1 {
  11108. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  11109. this.ServeSuccessJSON(map[string]interface{}{
  11110. "list": list,
  11111. "total": total,
  11112. })
  11113. } else {
  11114. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  11115. this.ServeSuccessJSON(map[string]interface{}{
  11116. "list": list,
  11117. "total": total,
  11118. })
  11119. }
  11120. }
  11121. func (c *HisApiController) PostProjectInformation() {
  11122. adminUser := c.GetAdminUserInfo()
  11123. orgId := adminUser.CurrentOrgId
  11124. dataBody := make(map[string]interface{}, 0)
  11125. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11126. if err != nil {
  11127. utils.ErrorLog(err.Error())
  11128. return
  11129. }
  11130. utils.ErrorLog("%v", dataBody)
  11131. var projectList []*models.HisProject
  11132. var total_goods []interface{}
  11133. tempProjects := dataBody["projects"].([]interface{})
  11134. total_goods = tempProjects
  11135. for index, projectMap := range tempProjects {
  11136. projectM := projectMap.(map[string]interface{})
  11137. var project models.HisProject
  11138. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  11139. utils.ErrorLog("project_name")
  11140. return
  11141. }
  11142. project_name, _ := projectM["project_name"].(string)
  11143. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  11144. err_log := models.ExportErrLog{
  11145. LogType: 6,
  11146. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11147. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  11148. Status: 1,
  11149. CreateTime: time.Now().Unix(),
  11150. UpdateTime: time.Now().Unix(),
  11151. ExportTime: time.Now().Unix(),
  11152. }
  11153. service.CreateExportErrLog(&err_log)
  11154. continue
  11155. }
  11156. project.ProjectName = project_name
  11157. prices := projectM["price"].(string)
  11158. price, _ := strconv.ParseFloat(prices, 64)
  11159. if price <= 0 { //名字为空则生成一条导入错误日志
  11160. err_log := models.ExportErrLog{
  11161. LogType: 6,
  11162. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11163. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  11164. Status: 1,
  11165. CreateTime: time.Now().Unix(),
  11166. UpdateTime: time.Now().Unix(),
  11167. ExportTime: time.Now().Unix(),
  11168. }
  11169. service.CreateExportErrLog(&err_log)
  11170. continue
  11171. }
  11172. project.Price = price
  11173. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  11174. utils.ErrorLog("unit_id")
  11175. return
  11176. }
  11177. unit := projectM["unit"].(string)
  11178. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  11179. err_log := models.ExportErrLog{
  11180. LogType: 6,
  11181. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11182. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  11183. Status: 1,
  11184. CreateTime: time.Now().Unix(),
  11185. UpdateTime: time.Now().Unix(),
  11186. ExportTime: time.Now().Unix(),
  11187. }
  11188. service.CreateExportErrLog(&err_log)
  11189. continue
  11190. }
  11191. project.Unit = unit
  11192. cost_classify := projectM["cost_classify"].(string)
  11193. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  11194. err_log := models.ExportErrLog{
  11195. LogType: 6,
  11196. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11197. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11198. Status: 1,
  11199. CreateTime: time.Now().Unix(),
  11200. UpdateTime: time.Now().Unix(),
  11201. ExportTime: time.Now().Unix(),
  11202. }
  11203. service.CreateExportErrLog(&err_log)
  11204. continue
  11205. }
  11206. var costClassify = "费用类别"
  11207. var cost_classify_id int64
  11208. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  11209. if len(cost_classify) != 0 {
  11210. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  11211. if errcode == gorm.ErrRecordNotFound {
  11212. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  11213. dataconfig := models.DictDataconfig{
  11214. ParentId: costClassifyConfig.ID,
  11215. Module: "system",
  11216. OrgId: orgId,
  11217. Name: cost_classify,
  11218. FieldName: "",
  11219. Value: costConfig.Value + 1,
  11220. CreatedTime: "",
  11221. UpdatedTime: "",
  11222. CreateUserId: adminUser.AdminUser.Id,
  11223. Status: 1,
  11224. Remark: "",
  11225. DeleteIdSystem: 0,
  11226. Title: "",
  11227. Content: "",
  11228. Order: 0,
  11229. Code: "",
  11230. }
  11231. service.CreatedDicConfig(&dataconfig)
  11232. }
  11233. }
  11234. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  11235. for _, it := range costClassList {
  11236. if cost_classify == it.Name {
  11237. cost_classify_id = int64(it.Value)
  11238. }
  11239. }
  11240. project.CostClassify = cost_classify_id
  11241. executive_section := projectM["executive_section"].(string)
  11242. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  11243. err_log := models.ExportErrLog{
  11244. LogType: 6,
  11245. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11246. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  11247. Status: 1,
  11248. CreateTime: time.Now().Unix(),
  11249. UpdateTime: time.Now().Unix(),
  11250. ExportTime: time.Now().Unix(),
  11251. }
  11252. service.CreateExportErrLog(&err_log)
  11253. continue
  11254. }
  11255. if len(executive_section) != 0 {
  11256. //查找科室是否有内容
  11257. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  11258. if errcodedepart == gorm.ErrRecordNotFound {
  11259. department := models.XtHisDepartment{
  11260. Name: executive_section,
  11261. Status: 1,
  11262. UserOrgId: adminUser.CurrentOrgId,
  11263. CreatedTime: time.Now().Unix(),
  11264. }
  11265. service.CreateDePartment(&department)
  11266. }
  11267. }
  11268. var executive_section_id int64
  11269. departMentList, _ := service.GetAllDepartMent(orgId)
  11270. for _, it := range departMentList {
  11271. if executive_section == it.Name {
  11272. executive_section_id = it.ID
  11273. }
  11274. }
  11275. project.ExecutiveSection = executive_section_id
  11276. medical_coverage := projectM["medical_coverage"].(string)
  11277. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  11278. err_log := models.ExportErrLog{
  11279. LogType: 6,
  11280. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11281. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11282. Status: 1,
  11283. CreateTime: time.Now().Unix(),
  11284. UpdateTime: time.Now().Unix(),
  11285. ExportTime: time.Now().Unix(),
  11286. }
  11287. service.CreateExportErrLog(&err_log)
  11288. continue
  11289. }
  11290. var medicalCoverage = "医保等级"
  11291. var medical_coverage_id int64
  11292. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  11293. if len(medical_coverage) != 0 {
  11294. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  11295. if errormedicalcoverage == gorm.ErrRecordNotFound {
  11296. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  11297. dataconfig := models.DictDataconfig{
  11298. ParentId: medicalCoverageConfig.ID,
  11299. Module: "system",
  11300. OrgId: orgId,
  11301. Name: medical_coverage,
  11302. FieldName: "",
  11303. Value: medicalCoverageConfig.Value + 1,
  11304. CreatedTime: "",
  11305. UpdatedTime: "",
  11306. CreateUserId: adminUser.AdminUser.Id,
  11307. Status: 1,
  11308. Remark: "",
  11309. DeleteIdSystem: 0,
  11310. Title: "",
  11311. Content: "",
  11312. Order: 0,
  11313. Code: "",
  11314. }
  11315. service.CreatedDicConfig(&dataconfig)
  11316. }
  11317. }
  11318. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  11319. for _, it := range medicalCoverageList {
  11320. if medical_coverage == it.Name {
  11321. medical_coverage_id = int64(it.Value)
  11322. }
  11323. }
  11324. project.MedicalCoverage = medical_coverage_id
  11325. pinyin := projectM["pinyin"].(string)
  11326. project.Pinyin = pinyin
  11327. wubi := projectM["wubi"].(string)
  11328. project.Wubi = wubi
  11329. statistical_classification := projectM["statistical_classification"].(string)
  11330. var statisticalClassification = "统计分类"
  11331. var statistical_classification_id int64
  11332. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  11333. if len(statistical_classification) != 0 {
  11334. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  11335. if classificationerrcodes == gorm.ErrRecordNotFound {
  11336. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  11337. dataconfig := models.DictDataconfig{
  11338. ParentId: classiFication.ID,
  11339. Module: "system",
  11340. OrgId: orgId,
  11341. Name: statistical_classification,
  11342. FieldName: "",
  11343. Value: classiFicationConfig.Value + 1,
  11344. CreatedTime: "",
  11345. UpdatedTime: "",
  11346. CreateUserId: adminUser.AdminUser.Id,
  11347. Status: 1,
  11348. Remark: "",
  11349. DeleteIdSystem: 0,
  11350. Title: "",
  11351. Content: "",
  11352. Order: 0,
  11353. Code: "",
  11354. }
  11355. service.CreatedDicConfig(&dataconfig)
  11356. }
  11357. }
  11358. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  11359. for _, it := range classiFicationList {
  11360. if statistical_classification == it.Name {
  11361. statistical_classification_id = int64(it.Value)
  11362. }
  11363. }
  11364. project.StatisticalClassification = statistical_classification_id
  11365. disease_directory := int64(projectM["disease_directory"].(float64))
  11366. project.DiseaseDirectory = disease_directory
  11367. is_record := int64(projectM["is_record"].(float64))
  11368. project.IsRecord = is_record
  11369. medical_code := projectM["medical_code"].(string)
  11370. project.MedicalCode = medical_code
  11371. tube_color := projectM["tube_color"].(string)
  11372. var tubeColor = "试管颜色"
  11373. var tube_color_id int64
  11374. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  11375. if len(tube_color) != 0 {
  11376. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  11377. if errcodetube == gorm.ErrRecordNotFound {
  11378. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  11379. dataconfig := models.DictDataconfig{
  11380. ParentId: tubeColorConfig.ID,
  11381. Module: "system",
  11382. OrgId: orgId,
  11383. Name: tube_color,
  11384. FieldName: "",
  11385. Value: tubeConfig.Value + 1,
  11386. CreatedTime: "",
  11387. UpdatedTime: "",
  11388. CreateUserId: adminUser.AdminUser.Id,
  11389. Status: 1,
  11390. Remark: "",
  11391. DeleteIdSystem: 0,
  11392. Title: "",
  11393. Content: "",
  11394. Order: 0,
  11395. Code: "",
  11396. }
  11397. service.CreatedDicConfig(&dataconfig)
  11398. }
  11399. }
  11400. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  11401. for _, it := range tubeColorList {
  11402. if tube_color == it.Name {
  11403. tube_color_id = int64(it.Value)
  11404. }
  11405. }
  11406. project.TubeColor = tube_color_id
  11407. single_dose := projectM["single_dose"].(string)
  11408. project.SingleDose = single_dose
  11409. execution_frequency := projectM["execution_frequency"].(string)
  11410. project.ExecutionFrequency = execution_frequency
  11411. delivery_way := projectM["delivery_way"].(string)
  11412. project.DeliveryWay = delivery_way
  11413. number_days := projectM["number_days"].(string)
  11414. project.NumberDays = number_days
  11415. total := projectM["total"].(string)
  11416. project.Total = total
  11417. medical_status := int64(projectM["medical_status"].(float64))
  11418. project.MedicalStatus = medical_status
  11419. category := int64(projectM["category"].(float64))
  11420. project.Category = category
  11421. specail_project := int64(projectM["specail_project"].(float64))
  11422. project.SpecailProject = specail_project
  11423. social_security_directory_code := projectM["social_security_directory_code"].(string)
  11424. project.SocialSecurityDirectoryCode = social_security_directory_code
  11425. remark := projectM["remark"].(string)
  11426. project.Remark = remark
  11427. record_date := projectM["record_date"].(string)
  11428. timeLayout := "2006-01-02"
  11429. loc, _ := time.LoadLocation("Local")
  11430. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11431. project.RecordDate = theTime.Unix()
  11432. projectList = append(projectList, &project)
  11433. }
  11434. export_time := time.Now().Unix()
  11435. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  11436. if len(projectList) > 0 {
  11437. for _, item := range projectList {
  11438. hans := item.ProjectName // 要转换的汉字字符串
  11439. // 创建一个拼音转换器
  11440. p := pinyin.NewArgs()
  11441. // 将汉字转为拼音
  11442. pinyinSlice := pinyin.Pinyin(hans, p)
  11443. // 输出拼音
  11444. fmt.Println("Pinyin:", pinyinSlice)
  11445. // 获取首字母
  11446. firstLetter := ""
  11447. for _, py := range pinyinSlice {
  11448. if len(py) > 0 {
  11449. firstLetter += string(py[0][0])
  11450. }
  11451. }
  11452. item.FirstLetter = firstLetter
  11453. project := models.HisProject{
  11454. ProjectName: item.ProjectName,
  11455. Price: item.Price,
  11456. Unit: item.Unit,
  11457. CostClassify: item.CostClassify,
  11458. ExecutiveSection: item.ExecutiveSection,
  11459. MedicalCoverage: item.MedicalCoverage,
  11460. UserOrgId: orgId,
  11461. Status: 1,
  11462. CreatedTime: time.Now().Unix(),
  11463. Pinyin: item.Pinyin,
  11464. Wubi: item.Wubi,
  11465. StatisticalClassification: item.StatisticalClassification,
  11466. DiseaseDirectory: item.DiseaseDirectory,
  11467. IsRecord: item.IsRecord,
  11468. MedicalCode: item.MedicalCode,
  11469. TubeColor: item.TubeColor,
  11470. SingleDose: item.SingleDose,
  11471. DeliveryWay: item.DeliveryWay,
  11472. NumberDays: item.NumberDays,
  11473. Total: item.Total,
  11474. Category: item.Category,
  11475. MedicalStatus: item.MedicalStatus,
  11476. SpecailProject: item.SpecailProject,
  11477. RecordDate: item.RecordDate,
  11478. Remark: item.Remark,
  11479. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  11480. ExecutionFrequency: item.ExecutionFrequency,
  11481. FirstLetter: item.FirstLetter,
  11482. }
  11483. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  11484. if errcodeproject == gorm.ErrRecordNotFound {
  11485. service.CreateProjectInfomation(&project)
  11486. } else if errcodeproject == nil {
  11487. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  11488. }
  11489. log := models.ExportLog{
  11490. LogType: 6,
  11491. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11492. TotalNum: int64(len(total_goods)),
  11493. FailNum: int64(len(errLogs)),
  11494. SuccessNum: int64(len(projectList)),
  11495. CreateTime: time.Now().Unix(),
  11496. UpdateTime: time.Now().Unix(),
  11497. ExportTime: export_time,
  11498. Status: 1,
  11499. }
  11500. service.CreateExportLog(&log)
  11501. c.ServeSuccessJSON(map[string]interface{}{
  11502. "msg": "导入成功",
  11503. "total_num": len(total_goods),
  11504. "success_num": len(projectList),
  11505. "fail_num": int64(len(errLogs)),
  11506. })
  11507. }
  11508. } else {
  11509. log := models.ExportLog{
  11510. LogType: 6,
  11511. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11512. TotalNum: int64(len(total_goods)),
  11513. FailNum: int64(len(errLogs)),
  11514. SuccessNum: int64(len(projectList)),
  11515. CreateTime: time.Now().Unix(),
  11516. UpdateTime: time.Now().Unix(),
  11517. ExportTime: export_time,
  11518. Status: 1,
  11519. }
  11520. service.CreateExportLog(&log)
  11521. c.ServeSuccessJSON(map[string]interface{}{
  11522. "msg": "导入成功",
  11523. "total_num": len(total_goods),
  11524. "success_num": len(projectList),
  11525. "fail_num": int64(len(errLogs)),
  11526. })
  11527. }
  11528. }
  11529. //func (this *HisApiController) EditProjectInformation(){
  11530. //
  11531. // id, _ := this.GetInt64("id")
  11532. // project_team := this.GetString("project_team")
  11533. // price := this.GetString("price")
  11534. // price_float, _ := strconv.ParseFloat(price, 64)
  11535. // pinyin := this.GetString("pinyin")
  11536. // wubi := this.GetString("wubi")
  11537. // tube_color, _ := this.GetInt64("tube_color")
  11538. // team_type, _ := this.GetInt64("team_type")
  11539. // remark := this.GetString("remark")
  11540. // ids := this.GetString("ids")
  11541. // item_id := this.GetString("item_id")
  11542. // projectTeam := models.XtHisProjectTeam{
  11543. // ProjectTeam: project_team,
  11544. // Price: price_float,
  11545. // Pinyin: pinyin,
  11546. // Wubi: wubi,
  11547. // TubeColor: tube_color,
  11548. // TeamType: team_type,
  11549. // Remark: remark,
  11550. // ProjectId: ids,
  11551. // ItemId: item_id,
  11552. // }
  11553. //
  11554. //
  11555. // dataBody := make(map[string]interface{}, 0)
  11556. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  11557. // if err != nil {
  11558. // utils.ErrorLog(err.Error())
  11559. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11560. // return
  11561. // }
  11562. //
  11563. // err = service.UpdatedProjectTeam(id, &projectTeam)
  11564. //
  11565. //
  11566. // if err != nil {
  11567. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  11568. // return
  11569. // }
  11570. //
  11571. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  11572. // infos, _ := dataBody["info"].([]interface{})
  11573. // if len(infos) > 0 {
  11574. // var ids []string
  11575. //
  11576. // for _, item := range infos {
  11577. // items := item.(map[string]interface{})
  11578. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  11579. // utils.ErrorLog("id")
  11580. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11581. // return
  11582. // }
  11583. // id := int64(items["id"].(float64))
  11584. //
  11585. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11586. // utils.ErrorLog("type")
  11587. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11588. // return
  11589. // }
  11590. // types := int64(items["type"].(float64))
  11591. //
  11592. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  11593. // utils.ErrorLog("number")
  11594. // }
  11595. //
  11596. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  11597. //
  11598. // projectList := models.XtHisProjectList{
  11599. // Number: number,
  11600. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  11601. // ProjectId: id,
  11602. // Status: 1,
  11603. // CreatedTime: time.Now().Unix(),
  11604. // UpdatedTime: time.Now().Unix(),
  11605. // TeamId: projectTeam.ID,
  11606. // Type: types,
  11607. // }
  11608. // list := projectList
  11609. //
  11610. // service.CreateProjectList(&list)
  11611. //
  11612. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  11613. //
  11614. // }
  11615. // ids_str := strings.Join(ids, ",")
  11616. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  11617. // service.SaveProjectTeam(&projectTeam)
  11618. // this.ServeSuccessJSON(map[string]interface{}{
  11619. // "projectTeam": projectTeam,
  11620. // })
  11621. // }
  11622. // }
  11623. //}
  11624. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  11625. name := c.GetString("name")
  11626. mode_id, _ := c.GetInt64("mode", 0)
  11627. types, _ := c.GetInt64("type", 0)
  11628. patient_id, _ := c.GetInt64("patient_id", 0)
  11629. types = 1
  11630. adminInfo := c.GetAdminUserInfo()
  11631. template := &models.HisPrescriptionTemplate{
  11632. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11633. PatientId: patient_id,
  11634. Type: types,
  11635. Status: 1,
  11636. Ctime: time.Now().Unix(),
  11637. Mtime: time.Now().Unix(),
  11638. Name: name,
  11639. Mode: mode_id,
  11640. }
  11641. dataBody := make(map[string]interface{}, 0)
  11642. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11643. if err != nil {
  11644. utils.ErrorLog(err.Error())
  11645. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11646. return
  11647. }
  11648. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  11649. //如果已经存在记录则删除处方
  11650. if template_one.ID > 0 {
  11651. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  11652. var ids []int64
  11653. var org_id int64
  11654. for _, item := range ps {
  11655. org_id = c.GetAdminUserInfo().CurrentOrgId
  11656. ids = append(ids, item.ID)
  11657. }
  11658. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  11659. if err2 == nil {
  11660. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11661. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11662. if len(prescriptions) > 0 {
  11663. for _, item := range prescriptions {
  11664. items := item.(map[string]interface{})
  11665. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11666. utils.ErrorLog("type")
  11667. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11668. return
  11669. }
  11670. types := int64(items["type"].(float64))
  11671. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  11672. utils.ErrorLog("med_type")
  11673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11674. return
  11675. }
  11676. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  11677. ctime := time.Now().Unix()
  11678. prescription := &models.HisPrescriptionInfoTemplate{
  11679. PatientId: patient_id,
  11680. UserOrgId: adminInfo.CurrentOrgId,
  11681. Ctime: ctime,
  11682. Mtime: ctime,
  11683. Type: types,
  11684. Modifier: adminInfo.AdminUser.Id,
  11685. Creator: adminInfo.AdminUser.Id,
  11686. Status: 1,
  11687. PTemplateId: template_one.ID,
  11688. MedType: med_type,
  11689. }
  11690. service.CreateHisPrescriptionInfoTemplate(prescription)
  11691. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11692. advices := items["advices"].([]interface{})
  11693. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11694. ctime := time.Now().Unix()
  11695. mtime := ctime
  11696. if len(advices) > 0 {
  11697. for _, advice := range advices {
  11698. var s models.HisPrescriptionAdviceTemplate
  11699. s.PrescriptionId = prescription.ID
  11700. s.AdviceType = 2
  11701. s.StopState = 2
  11702. s.ExecutionState = 2
  11703. s.Status = 1
  11704. s.UserOrgId = adminInfo.CurrentOrgId
  11705. s.CreatedTime = ctime
  11706. s.UpdatedTime = mtime
  11707. s.PatientId = patient_id
  11708. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  11709. if errcode > 0 {
  11710. c.ServeFailJSONWithSGJErrorCode(errcode)
  11711. return
  11712. }
  11713. service.CreateHisPrescriptionAdviceTemplate(&s)
  11714. }
  11715. }
  11716. }
  11717. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11718. projects := items["project"].([]interface{})
  11719. if len(projects) > 0 {
  11720. for _, project := range projects {
  11721. var p models.HisPrescriptionProjectTemplate
  11722. p.PrescriptionId = prescription.ID
  11723. p.Ctime = time.Now().Unix()
  11724. p.Mtime = time.Now().Unix()
  11725. p.PatientId = patient_id
  11726. p.UserOrgId = adminInfo.CurrentOrgId
  11727. p.Status = 1
  11728. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  11729. if errcode > 0 {
  11730. c.ServeFailJSONWithSGJErrorCode(errcode)
  11731. return
  11732. }
  11733. service.CreateHisPrescriptionProjectTemplate(&p)
  11734. }
  11735. }
  11736. }
  11737. }
  11738. c.ServeSuccessJSON(map[string]interface{}{
  11739. "msg": "创建成功",
  11740. })
  11741. }
  11742. }
  11743. } else {
  11744. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11745. return
  11746. }
  11747. } else {
  11748. err3 := service.CreateHisPrescriptionTemplate(template)
  11749. if err3 == nil {
  11750. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11751. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11752. if len(prescriptions) > 0 {
  11753. for _, item := range prescriptions {
  11754. items := item.(map[string]interface{})
  11755. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11756. utils.ErrorLog("type")
  11757. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11758. return
  11759. }
  11760. types := int64(items["type"].(float64))
  11761. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  11762. utils.ErrorLog("med_type")
  11763. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11764. return
  11765. }
  11766. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  11767. ctime := time.Now().Unix()
  11768. prescription := &models.HisPrescriptionInfoTemplate{
  11769. PatientId: patient_id,
  11770. UserOrgId: adminInfo.CurrentOrgId,
  11771. Ctime: ctime,
  11772. Mtime: ctime,
  11773. Type: types,
  11774. Modifier: adminInfo.AdminUser.Id,
  11775. Creator: adminInfo.AdminUser.Id,
  11776. Status: 1,
  11777. PTemplateId: template.ID,
  11778. MedType: med_type,
  11779. }
  11780. service.CreateHisPrescriptionInfoTemplate(prescription)
  11781. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11782. advices := items["advices"].([]interface{})
  11783. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11784. ctime := time.Now().Unix()
  11785. mtime := ctime
  11786. if len(advices) > 0 {
  11787. for _, advice := range advices {
  11788. var s models.HisPrescriptionAdviceTemplate
  11789. s.PrescriptionId = prescription.ID
  11790. s.AdviceType = 2
  11791. s.StopState = 2
  11792. s.ExecutionState = 2
  11793. s.Status = 1
  11794. s.UserOrgId = adminInfo.CurrentOrgId
  11795. s.CreatedTime = ctime
  11796. s.UpdatedTime = mtime
  11797. s.PatientId = patient_id
  11798. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  11799. if errcode > 0 {
  11800. c.ServeFailJSONWithSGJErrorCode(errcode)
  11801. return
  11802. }
  11803. service.CreateHisPrescriptionAdviceTemplate(&s)
  11804. }
  11805. }
  11806. }
  11807. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11808. projects := items["project"].([]interface{})
  11809. if len(projects) > 0 {
  11810. for _, project := range projects {
  11811. var p models.HisPrescriptionProjectTemplate
  11812. p.PrescriptionId = prescription.ID
  11813. p.Ctime = time.Now().Unix()
  11814. p.Mtime = time.Now().Unix()
  11815. p.PatientId = patient_id
  11816. p.UserOrgId = adminInfo.CurrentOrgId
  11817. p.Status = 1
  11818. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  11819. if errcode > 0 {
  11820. c.ServeFailJSONWithSGJErrorCode(errcode)
  11821. return
  11822. }
  11823. service.CreateHisPrescriptionProjectTemplate(&p)
  11824. }
  11825. }
  11826. }
  11827. }
  11828. c.ServeSuccessJSON(map[string]interface{}{
  11829. "msg": "创建成功",
  11830. })
  11831. }
  11832. }
  11833. } else {
  11834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11835. return
  11836. }
  11837. }
  11838. }
  11839. func (c *HisApiController) PreSettle() {
  11840. id, _ := c.GetInt64("id")
  11841. record_time := c.GetString("record_time")
  11842. his_patient_id, _ := c.GetInt64("his_patient_id")
  11843. timeLayout := "2006-01-02"
  11844. loc, _ := time.LoadLocation("Local")
  11845. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  11846. diagnosis_id := c.GetString("diagnosis")
  11847. sick_type, _ := c.GetInt64("sick_type")
  11848. reg_type, _ := c.GetInt64("p_type")
  11849. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  11850. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  11851. if err != nil {
  11852. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11853. return
  11854. }
  11855. recordDateTime := theTime.Unix()
  11856. adminUser := c.GetAdminUserInfo()
  11857. var prescriptions []*models.HisPrescription
  11858. var start_time int64
  11859. var end_time int64
  11860. ids_str := c.GetString("ids")
  11861. ids_arr := strings.Split(ids_str, ",")
  11862. fmt.Println(reg_type)
  11863. if settle_accounts_type == 1 { //日结
  11864. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  11865. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  11866. } else {
  11867. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  11868. }
  11869. fmt.Println(prescriptions)
  11870. } else { //月结
  11871. start_time_str := c.GetString("start_time")
  11872. end_time_str := c.GetString("end_time")
  11873. timeLayout := "2006-01-02"
  11874. loc, _ := time.LoadLocation("Local")
  11875. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  11876. if err != nil {
  11877. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11878. return
  11879. }
  11880. recordStartTime := theStartTime.Unix()
  11881. start_time = recordStartTime
  11882. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  11883. if err != nil {
  11884. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11885. return
  11886. }
  11887. recordEndTime := theEndTime.Unix()
  11888. end_time = recordEndTime
  11889. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  11890. }
  11891. if reg_type == 1111 || reg_type == 1112 {
  11892. reg_type = 11
  11893. }
  11894. timestamp := time.Now().Unix()
  11895. tempTime := time.Unix(timestamp, 0)
  11896. timeFormat := tempTime.Format("20060102150405")
  11897. chrgBchno := rand.Intn(100000) + 10000
  11898. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  11899. strconv.FormatInt(his.PatientId, 10)
  11900. var ids []int64
  11901. for _, item := range prescriptions {
  11902. ids = append(ids, item.ID)
  11903. }
  11904. fmt.Println(ids)
  11905. var total float64
  11906. for _, item := range prescriptions {
  11907. fmt.Println(item)
  11908. if item.Type == 1 { //药品
  11909. for _, subItem := range item.HisDoctorAdviceInfo {
  11910. total = total + (subItem.Price * subItem.PrescribingNumber)
  11911. }
  11912. }
  11913. if item.Type == 2 { //项目
  11914. for _, subItem := range item.HisPrescriptionProject {
  11915. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  11916. total = total + (subItem.Price * cnt)
  11917. }
  11918. }
  11919. for _, subItem := range item.HisAdditionalCharge {
  11920. total = total + (subItem.Price * float64(subItem.Count))
  11921. }
  11922. }
  11923. allTotal := fmt.Sprintf("%.2f", total)
  11924. totals, _ := strconv.ParseFloat(allTotal, 64)
  11925. order := &models.HisOrder{
  11926. UserOrgId: adminUser.CurrentOrgId,
  11927. HisPatientId: his.ID,
  11928. PatientId: id,
  11929. SettleAccountsDate: recordDateTime,
  11930. Ctime: time.Now().Unix(),
  11931. Mtime: time.Now().Unix(),
  11932. Status: 1,
  11933. OrderStatus: 1,
  11934. MdtrtId: his.Number,
  11935. Number: chrg_bchno,
  11936. MedfeeSumamt: totals,
  11937. SettleEndTime: end_time,
  11938. SettleStartTime: start_time,
  11939. SettleType: settle_accounts_type,
  11940. PsnPartAmt: totals,
  11941. PsnCashPay: totals,
  11942. PType: 2,
  11943. IsPre: 1,
  11944. MedType: strconv.Itoa(int(reg_type)),
  11945. Diagnosis: diagnosis_id,
  11946. }
  11947. err = service.CreateOrder(order)
  11948. if err != nil {
  11949. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  11950. return
  11951. }
  11952. var customs []*Custom
  11953. for _, item := range prescriptions {
  11954. fmt.Println(item.Type)
  11955. if item.Type == 1 { //药品
  11956. for _, subItem := range item.HisDoctorAdviceInfo {
  11957. cus := &Custom{
  11958. AdviceId: subItem.ID,
  11959. ProjectId: 0,
  11960. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  11961. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  11962. FeedetlSn: subItem.FeedetlSn,
  11963. Price: fmt.Sprintf("%.2f", subItem.Price),
  11964. MedListCodg: subItem.MedListCodg,
  11965. Type: 1,
  11966. }
  11967. customs = append(customs, cus)
  11968. }
  11969. }
  11970. if item.Type == 2 { //项目
  11971. for _, subItem := range item.HisPrescriptionProject {
  11972. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  11973. cus := &Custom{
  11974. AdviceId: 0,
  11975. ProjectId: subItem.ID,
  11976. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  11977. Cut: fmt.Sprintf("%.2f", cnt),
  11978. FeedetlSn: subItem.FeedetlSn,
  11979. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  11980. MedListCodg: subItem.MedListCodg,
  11981. Type: 2,
  11982. }
  11983. customs = append(customs, cus)
  11984. }
  11985. }
  11986. for _, item := range item.HisAdditionalCharge {
  11987. cus := &Custom{
  11988. ItemId: item.ID,
  11989. AdviceId: 0,
  11990. ProjectId: 0,
  11991. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  11992. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  11993. FeedetlSn: item.FeedetlSn,
  11994. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  11995. MedListCodg: item.XtHisAddtionConfig.Code,
  11996. Type: 3,
  11997. }
  11998. customs = append(customs, cus)
  11999. }
  12000. }
  12001. fmt.Println(customs)
  12002. for _, item := range customs {
  12003. var advice_id int64 = 0
  12004. var project_id int64 = 0
  12005. var item_id int64 = 0
  12006. var types int64 = 0
  12007. if item.Type == 1 {
  12008. advice_id = item.AdviceId
  12009. project_id = 0
  12010. item_id = 0
  12011. } else if item.Type == 2 {
  12012. advice_id = 0
  12013. item_id = 0
  12014. project_id = item.ProjectId
  12015. } else if item.Type == 3 {
  12016. advice_id = 0
  12017. item_id = item.ItemId
  12018. project_id = 0
  12019. }
  12020. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  12021. cut, _ := strconv.ParseFloat(item.Cut, 32)
  12022. pric, _ := strconv.ParseFloat(item.Price, 32)
  12023. info := &models.HisOrderInfo{
  12024. OrderNumber: order.Number,
  12025. UploadDate: time.Now().Unix(),
  12026. AdviceId: advice_id,
  12027. DetItemFeeSumamt: detItemFeeSumamt,
  12028. Cnt: cut,
  12029. Pric: pric,
  12030. PatientId: id,
  12031. Status: 1,
  12032. Mtime: time.Now().Unix(),
  12033. Ctime: time.Now().Unix(),
  12034. UserOrgId: adminUser.CurrentOrgId,
  12035. HisPatientId: his.ID,
  12036. OrderId: order.ID,
  12037. ProjectId: project_id,
  12038. Type: types,
  12039. ItemId: item_id,
  12040. }
  12041. service.CreateOrderInfo(info)
  12042. }
  12043. his.SickType = sick_type
  12044. service.UpdataHisPateint(&his)
  12045. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  12046. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  12047. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  12048. if err == nil {
  12049. c.ServeSuccessJSON(map[string]interface{}{
  12050. "msg": "结算成功",
  12051. })
  12052. }
  12053. }
  12054. type CustomOrderInfo struct {
  12055. Name string
  12056. Spec string
  12057. Unit string
  12058. Count float64
  12059. Price float64
  12060. Total float64
  12061. }
  12062. func (c *HisApiController) GetPrivateExpensesInfo() {
  12063. order_id, _ := c.GetInt64("id", 0)
  12064. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  12065. order, _ := service.GetHisOrderByID(order_id)
  12066. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  12067. if order.ID == 0 {
  12068. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  12069. return
  12070. }
  12071. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  12072. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12073. org_id := c.GetAdminUserInfo().CurrentOrgId
  12074. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  12075. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  12076. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  12077. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  12078. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  12079. //var orderInfos_four []*models.HisOrderInfoTwo
  12080. //for _, item := range orderInfos_three {
  12081. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  12082. // item.HisPrescriptionProject.IsCheckTeam = 1
  12083. // orderInfos_four = append(orderInfos_four, item)
  12084. //
  12085. // }
  12086. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  12087. // item.HisPrescriptionProject.IsCheckTeam = 2
  12088. // orderInfos_two = append(orderInfos_two, item)
  12089. // }
  12090. //}
  12091. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  12092. //var cus_slice []CustomOrderInfo
  12093. //for _, item := range new_order_info {
  12094. // var cus CustomOrderInfo
  12095. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  12096. // cus.Unit = ""
  12097. // cus.Spec = ""
  12098. // var total float64
  12099. // for _, subItem := range orderInfos_four {
  12100. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  12101. // total = total + subItem.DetItemFeeSumamt
  12102. // fmt.Println(subItem.DetItemFeeSumamt)
  12103. // }
  12104. // }
  12105. // cus.Count = 1
  12106. // cus.Total = total
  12107. // cus_slice = append(cus_slice, cus)
  12108. //}
  12109. orderInfos = append(orderInfos, orderInfos_two...)
  12110. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  12111. //orderInfos = append(orderInfos, orderInfos_three...)
  12112. //}/**/
  12113. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  12114. c.ServeSuccessJSON(map[string]interface{}{
  12115. "order": order,
  12116. "order_info": orderInfos,
  12117. "patient": patient,
  12118. "admin_info": adminInfo,
  12119. "his": his,
  12120. "current_admin": role,
  12121. "org_config": miConfig,
  12122. //"new_order_info": cus_slice,
  12123. })
  12124. }
  12125. func (this *HisApiController) ChangeMedType() {
  12126. med_type := this.GetString("med_type")
  12127. old_med_type := this.GetString("old_med_type")
  12128. ids := this.GetString("ids")
  12129. settle_type, _ := this.GetInt64("settle_type")
  12130. start_time := this.GetString("start_time")
  12131. end_time := this.GetString("end_time")
  12132. ids_arr := strings.Split(ids, ",")
  12133. if settle_type == 1 { //日结
  12134. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  12135. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  12136. prescription.MedType = med_type
  12137. err := service.SaveHisPrescriptionTwo(&prescription)
  12138. if err == nil {
  12139. this.ServeSuccessJSON(map[string]interface{}{
  12140. "msg": "修改成功",
  12141. })
  12142. } else {
  12143. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12144. return
  12145. }
  12146. } else if settle_type == 2 {
  12147. timeLayout := "2006-01-02"
  12148. loc, _ := time.LoadLocation("Local")
  12149. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12150. if err != nil {
  12151. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12152. return
  12153. }
  12154. recordStartTime := theStartTime.Unix()
  12155. start_time_timestamp := recordStartTime
  12156. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  12157. if err != nil {
  12158. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12159. return
  12160. }
  12161. recordEndTime := theEndTime.Unix()
  12162. end_time_timestamp := recordEndTime
  12163. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  12164. if updateErr == nil {
  12165. this.ServeSuccessJSON(map[string]interface{}{
  12166. "msg": "修改成功",
  12167. })
  12168. } else {
  12169. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12170. return
  12171. }
  12172. }
  12173. }
  12174. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  12175. patient_id, _ := c.GetInt64("patient_id")
  12176. his_patient_id, _ := c.GetInt64("his_patient_id")
  12177. record_date := c.GetString("record_date")
  12178. start_time := c.GetString("start_time")
  12179. end_time := c.GetString("end_time")
  12180. order_status, _ := c.GetInt64("type", 0)
  12181. p_type, _ := c.GetInt64("p_type", 0)
  12182. order_id, _ := c.GetInt64("order_id", 0)
  12183. timeLayout := "2006-01-02"
  12184. loc, _ := time.LoadLocation("Local")
  12185. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12186. if err != nil {
  12187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12188. return
  12189. }
  12190. recordDateTime := theTime.Unix()
  12191. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12192. if err != nil {
  12193. }
  12194. startRecordDateTime := startTime.Unix()
  12195. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12196. if err != nil {
  12197. }
  12198. endRecordDateTime := endTime.Unix()
  12199. admin := c.GetAdminUserInfo()
  12200. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  12201. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12202. order, _ := service.GetHisOrderByID(order_id)
  12203. var monthPrescriptions []*models.HisPrescription
  12204. if order_status == 1 || order_status == 0 {
  12205. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12206. } else if order_status == 2 {
  12207. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  12208. }
  12209. var settle_total float64
  12210. for _, item := range monthPrescriptions {
  12211. if len(item.HisPrescriptionProject) > 0 {
  12212. for _, subItem := range item.HisPrescriptionProject {
  12213. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12214. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12215. settle_total = settle_total + total
  12216. }
  12217. }
  12218. if len(item.HisDoctorAdviceInfo) > 0 {
  12219. for _, subItem := range item.HisDoctorAdviceInfo {
  12220. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12221. settle_total = settle_total + total
  12222. }
  12223. }
  12224. }
  12225. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12226. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12227. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12228. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12229. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12230. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12231. //获取所有科室信息
  12232. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12233. var dia string
  12234. for _, item := range month_p_info {
  12235. if len(dia) == 0 {
  12236. dia = item.Diagnosis
  12237. } else {
  12238. dia = dia + "," + item.Diagnosis
  12239. }
  12240. }
  12241. dia_arr := removeDuplicates(strings.Split(dia, ","))
  12242. dia_arr = removeEmptyStrings(dia_arr)
  12243. c.ServeSuccessJSON(map[string]interface{}{
  12244. "his_info": his_patient_info,
  12245. "xt_info": xt_patient_info,
  12246. "case_history": case_history,
  12247. "info": patientPrescriptionInfo,
  12248. "last_info": lastPatientPrescriptionInfo,
  12249. "month_prescriptions": monthPrescriptions,
  12250. "order": order,
  12251. "doctors": doctors,
  12252. "department": department,
  12253. "settle_total": settle_total,
  12254. "dia_arr": dia_arr,
  12255. })
  12256. return
  12257. }
  12258. func removeEmptyStrings(input []string) []string {
  12259. var output []string
  12260. for _, s := range input {
  12261. if s != "" {
  12262. output = append(output, s)
  12263. }
  12264. }
  12265. return output
  12266. }
  12267. func removeDuplicates(input []string) []string {
  12268. seen := make(map[string]bool)
  12269. output := []string{}
  12270. for _, s := range input {
  12271. if _, exists := seen[s]; !exists {
  12272. seen[s] = true
  12273. output = append(output, s)
  12274. }
  12275. }
  12276. return output
  12277. }
  12278. func (c *HisApiController) GetHisMonthPatientInfo() {
  12279. patient_id, _ := c.GetInt64("patient_id")
  12280. his_patient_id, _ := c.GetInt64("his_patient_id")
  12281. record_date := c.GetString("record_date")
  12282. number := c.GetString("number")
  12283. start_time := c.GetString("start_time")
  12284. end_time := c.GetString("end_time")
  12285. p_type, _ := c.GetInt64("p_type")
  12286. timeLayout := "2006-01-02"
  12287. loc, _ := time.LoadLocation("Local")
  12288. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12289. if err != nil {
  12290. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12291. return
  12292. }
  12293. recordDateTime := theTime.Unix()
  12294. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12295. if err != nil {
  12296. }
  12297. startRecordDateTime := startTime.Unix()
  12298. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12299. if err != nil {
  12300. }
  12301. endRecordDateTime := endTime.Unix()
  12302. admin := c.GetAdminUserInfo()
  12303. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  12304. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12305. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  12306. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12307. var settle_total float64
  12308. for _, item := range monthPrescriptions {
  12309. if len(item.HisPrescriptionProject) > 0 {
  12310. for _, subItem := range item.HisPrescriptionProject {
  12311. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12312. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12313. settle_total = settle_total + total
  12314. }
  12315. }
  12316. if len(item.HisDoctorAdviceInfo) > 0 {
  12317. for _, subItem := range item.HisDoctorAdviceInfo {
  12318. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12319. settle_total = settle_total + total
  12320. }
  12321. }
  12322. }
  12323. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12324. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12325. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12326. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12327. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  12328. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12329. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  12330. //获取所有科室信息
  12331. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12332. c.ServeSuccessJSON(map[string]interface{}{
  12333. "his_info": his_patient_info,
  12334. "xt_info": xt_patient_info,
  12335. "case_history": case_history,
  12336. "info": patientPrescriptionInfo,
  12337. "month_prescriptions": monthPrescriptions,
  12338. "order": order,
  12339. "doctors": doctors,
  12340. "department": department,
  12341. "count": count,
  12342. "drugStockConfig": drugStockConfig,
  12343. "last_info": lastPatientPrescriptionInfo,
  12344. "settle_total": settle_total,
  12345. })
  12346. return
  12347. }
  12348. func (c *HisApiController) GetAllOrder() {
  12349. org_id := c.GetAdminUserInfo().CurrentOrgId
  12350. orders, _ := service.GetNewHisOrderList(org_id)
  12351. c.ServeSuccessJSON(map[string]interface{}{
  12352. "order": orders,
  12353. })
  12354. return
  12355. }
  12356. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  12357. newArr = make([]*models.HisOrderInfoTwo, 0)
  12358. for i := 0; i < len(arr); i++ {
  12359. repeat := false
  12360. for j := i + 1; j < len(arr); j++ {
  12361. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  12362. repeat = true
  12363. break
  12364. }
  12365. }
  12366. if !repeat {
  12367. newArr = append(newArr, arr[i])
  12368. }
  12369. }
  12370. return
  12371. }
  12372. // 修改处方退库操作 参数传修改之前的处方数据
  12373. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  12374. if advice.ExecutionState == 1 {
  12375. //查询该病人该药品是否有库存记录
  12376. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  12377. if errcode == gorm.ErrRecordNotFound {
  12378. } else {
  12379. //退库
  12380. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  12381. if advice.PrescribingNumberUnit == drug.MinUnit {
  12382. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12383. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12384. //退库
  12385. warehouseInfo := models.DrugWarehouseInfo{
  12386. StockMinNumber: prescribingNumber,
  12387. }
  12388. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  12389. operation_time := time.Now().Unix()
  12390. creater := advice.AdviceDoctor
  12391. ctime := time.Now().Unix()
  12392. timeStr := time.Now().Format("2006-01-02")
  12393. timeArr := strings.Split(timeStr, "-")
  12394. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12395. total = total + 1
  12396. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12397. cancelStock := models.DrugCancelStock{
  12398. OrderNumber: orderNumber,
  12399. OperaTime: operation_time,
  12400. OrgId: advice.UserOrgId,
  12401. Creater: creater,
  12402. Ctime: ctime,
  12403. Status: 1,
  12404. ReturnTime: advice.AdviceDate,
  12405. Dealer: info.Dealer,
  12406. Manufacturer: info.Manufacturer,
  12407. Type: 1,
  12408. }
  12409. service.AddSigleDrugCancelStock(&cancelStock)
  12410. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12411. dealer, _ := service.GetDealerById(info.Dealer)
  12412. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12413. cancelStockInfo := models.DrugCancelStockInfo{
  12414. OrderNumber: cancelInfo.OrderNumber,
  12415. CancelStockId: cancelInfo.ID,
  12416. DrugId: info.DrugId,
  12417. Count: info.Count,
  12418. Status: 1,
  12419. Ctime: ctime,
  12420. OrgId: advice.UserOrgId,
  12421. Type: 1,
  12422. Manufacturer: manufactureName.ManufacturerName,
  12423. Dealer: dealer.DealerName,
  12424. Total: 0,
  12425. RetailPrice: info.RetailPrice,
  12426. RetailTotalPrice: info.RetailTotalPrice,
  12427. Price: info.Price,
  12428. RegisterAccount: "",
  12429. Remark: info.Remark,
  12430. BatchNumber: info.BatchNumber,
  12431. MaxUnit: info.CountUnit,
  12432. ProductDate: info.ProductDate,
  12433. ExpiryDate: info.ExpiryDate,
  12434. BatchNumberId: info.WarehouseInfoId,
  12435. }
  12436. flow := models.DrugFlow{
  12437. WarehousingId: 0,
  12438. DrugId: info.DrugId,
  12439. Number: "",
  12440. BatchNumber: info.BatchNumber,
  12441. Count: info.Count,
  12442. UserOrgId: advice.UserOrgId,
  12443. PatientId: 0,
  12444. SystemTime: ctime,
  12445. ConsumableType: 4,
  12446. IsSys: 0,
  12447. WarehousingOrder: "",
  12448. WarehouseOutId: 0,
  12449. WarehouseOutOrderNumber: "",
  12450. IsEdit: 0,
  12451. CancelStockId: cancelStock.ID,
  12452. CancelOrderNumber: cancelStock.OrderNumber,
  12453. Manufacturer: info.Manufacturer,
  12454. Dealer: info.Dealer,
  12455. Creator: advice.UserOrgId,
  12456. UpdateCreator: 0,
  12457. Status: 1,
  12458. Ctime: time.Now().Unix(),
  12459. Mtime: 0,
  12460. Price: info.Price,
  12461. WarehousingDetailId: 0,
  12462. WarehouseOutDetailId: 0,
  12463. CancelOutDetailId: 0,
  12464. ExpireDate: info.ExpiryDate,
  12465. ProductDate: info.ProductDate,
  12466. MaxUnit: info.CountUnit,
  12467. MinUnit: "",
  12468. }
  12469. service.CreatedCancelStock(cancelStockInfo)
  12470. service.CreateDrugFlowOne(flow)
  12471. } else {
  12472. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12473. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12474. if advice.PrescribingNumberUnit == drug.MaxUnit {
  12475. warehouseInfo := models.DrugWarehouseInfo{
  12476. StockMinNumber: prescribingNumber,
  12477. }
  12478. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  12479. }
  12480. operation_time := time.Now().Unix()
  12481. creater := advice.AdviceDoctor
  12482. ctime := time.Now().Unix()
  12483. timeStr := time.Now().Format("2006-01-02")
  12484. timeArr := strings.Split(timeStr, "-")
  12485. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12486. total = total + 1
  12487. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12488. cancelStock := models.DrugCancelStock{
  12489. OrderNumber: orderNumber,
  12490. OperaTime: operation_time,
  12491. OrgId: advice.UserOrgId,
  12492. Creater: creater,
  12493. Ctime: ctime,
  12494. Status: 1,
  12495. ReturnTime: advice.AdviceDate,
  12496. Dealer: info.Dealer,
  12497. Manufacturer: info.Manufacturer,
  12498. Type: 1,
  12499. }
  12500. service.AddSigleDrugCancelStock(&cancelStock)
  12501. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12502. dealer, _ := service.GetDealerById(info.Dealer)
  12503. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12504. cancelStockInfo := models.DrugCancelStockInfo{
  12505. OrderNumber: cancelInfo.OrderNumber,
  12506. CancelStockId: cancelInfo.ID,
  12507. DrugId: info.DrugId,
  12508. Count: info.Count,
  12509. Status: 1,
  12510. Ctime: ctime,
  12511. OrgId: advice.UserOrgId,
  12512. Type: 1,
  12513. Manufacturer: manufactureName.ManufacturerName,
  12514. Dealer: dealer.DealerName,
  12515. Total: 0,
  12516. RetailPrice: info.RetailPrice,
  12517. RetailTotalPrice: info.RetailTotalPrice,
  12518. Price: info.Price,
  12519. RegisterAccount: "",
  12520. Remark: info.Remark,
  12521. BatchNumber: info.BatchNumber,
  12522. MaxUnit: info.CountUnit,
  12523. ProductDate: info.ProductDate,
  12524. ExpiryDate: info.ExpiryDate,
  12525. BatchNumberId: info.WarehouseInfoId,
  12526. }
  12527. flow := models.DrugFlow{
  12528. WarehousingId: 0,
  12529. DrugId: info.DrugId,
  12530. Number: "",
  12531. BatchNumber: info.BatchNumber,
  12532. Count: info.Count,
  12533. UserOrgId: advice.UserOrgId,
  12534. PatientId: 0,
  12535. SystemTime: ctime,
  12536. ConsumableType: 4,
  12537. IsSys: 0,
  12538. WarehousingOrder: "",
  12539. WarehouseOutId: 0,
  12540. WarehouseOutOrderNumber: "",
  12541. IsEdit: 0,
  12542. CancelStockId: cancelStock.ID,
  12543. CancelOrderNumber: cancelStock.OrderNumber,
  12544. Manufacturer: info.Manufacturer,
  12545. Dealer: info.Dealer,
  12546. Creator: advice.AdviceDoctor,
  12547. UpdateCreator: 0,
  12548. Status: 1,
  12549. Ctime: time.Now().Unix(),
  12550. Mtime: 0,
  12551. Price: info.Price,
  12552. WarehousingDetailId: 0,
  12553. WarehouseOutDetailId: 0,
  12554. CancelOutDetailId: 0,
  12555. ExpireDate: info.ExpiryDate,
  12556. ProductDate: info.ProductDate,
  12557. MaxUnit: info.CountUnit,
  12558. MinUnit: "",
  12559. }
  12560. service.CreatedCancelStock(cancelStockInfo)
  12561. service.CreateDrugFlowOne(flow)
  12562. }
  12563. }
  12564. }
  12565. return err
  12566. }
  12567. func (this *HisApiController) DeleteNCDS() {
  12568. id, _ := this.GetInt64("id", 0)
  12569. if id > 0 {
  12570. service.DeletePsnNCDSRecordById(id)
  12571. this.ServeSuccessJSON(map[string]interface{}{
  12572. "msg": "删除成功",
  12573. })
  12574. } else {
  12575. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  12576. return
  12577. }
  12578. }
  12579. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  12580. id, _ := c.GetInt64("id")
  12581. advice, _ := service.GetHisDoctorAdviceInfo(id)
  12582. c.ServeSuccessJSON(map[string]interface{}{
  12583. "advice": advice,
  12584. })
  12585. return
  12586. }
  12587. func (c *HisApiController) GetHisMonthChargePatientList() {
  12588. record_date := c.GetString("record_date")
  12589. start_time := c.GetString("start_time")
  12590. end_time := c.GetString("end_time")
  12591. timeLayout := "2006-01-02"
  12592. loc, _ := time.LoadLocation("Local")
  12593. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12594. if err != nil {
  12595. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12596. return
  12597. }
  12598. if err != nil {
  12599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12600. return
  12601. }
  12602. recordDateTime := theTime.Unix()
  12603. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12604. if err != nil {
  12605. }
  12606. startRecordDateTime := startTime.Unix()
  12607. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12608. if err != nil {
  12609. }
  12610. endRecordDateTime := endTime.Unix()
  12611. adminInfo := c.GetAdminUserInfo()
  12612. var tempMonthChargePatients []*service.MonthChargePatients
  12613. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  12614. for _, item := range tempPatients {
  12615. //过滤没有处方的
  12616. if len(item.HisPrescription) == 0 {
  12617. tempMonthChargePatients = append(tempMonthChargePatients, item)
  12618. }
  12619. }
  12620. c.ServeSuccessJSON(map[string]interface{}{
  12621. "list": tempMonthChargePatients,
  12622. })
  12623. }
  12624. // PrescriptionDifference 医嘱数量差值结构体
  12625. type PrescriptionDrugDifference struct {
  12626. DrugID int64 //基础库药品id
  12627. ID int64 //医嘱id
  12628. Difference float64 //差值
  12629. Unit string //单位
  12630. }
  12631. type PrescriptionGoodDifference struct {
  12632. GoodID int64 //基础库项目耗材id
  12633. ID int64 //医嘱id
  12634. Difference int64 //差值
  12635. Unit string //单位
  12636. Type int64 //类型
  12637. }
  12638. type EditCustomData struct {
  12639. adviceList []*models.HisDoctorAdviceInfo
  12640. projectList []*models.HisPrescriptionProject
  12641. }
  12642. type SrcCustomData struct {
  12643. adviceList []*models.HisDoctorAdviceInfo
  12644. projectList []*models.HisPrescriptionProject
  12645. }
  12646. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  12647. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  12648. differences := make([]*PrescriptionDrugDifference, 0)
  12649. // 创建一个 map 来存储第一个切片中的药品信息
  12650. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  12651. for _, advice := range firstPrescription {
  12652. firstMap[advice.DrugId] = advice
  12653. }
  12654. // 遍历第二个切片中的药品信息,并比较数量差值
  12655. for _, advice := range secondPrescription {
  12656. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  12657. diff := &PrescriptionDrugDifference{
  12658. DrugID: advice.DrugId,
  12659. ID: firstAdvice.ID,
  12660. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  12661. Unit: firstAdvice.PrescribingNumberUnit,
  12662. }
  12663. differences = append(differences, diff)
  12664. }
  12665. }
  12666. return differences
  12667. }
  12668. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  12669. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  12670. differences := make([]*PrescriptionGoodDifference, 0)
  12671. // 创建一个 map 来存储第一个切片中的耗材信息
  12672. firstMap := make(map[int64]*models.HisPrescriptionProject)
  12673. for _, good := range firstPrescription {
  12674. firstMap[good.ProjectId] = good
  12675. }
  12676. // 遍历第二个切片中的耗材信息,并比较数量差值
  12677. for _, good := range secondPrescription {
  12678. if firstGood, ok := firstMap[good.ProjectId]; ok {
  12679. count, _ := strconv.ParseInt(good.Count, 10, 64)
  12680. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  12681. diff := &PrescriptionGoodDifference{
  12682. GoodID: good.ProjectId,
  12683. ID: firstGood.ID,
  12684. Difference: count - firstCount,
  12685. Unit: firstGood.Unit,
  12686. Type: firstGood.Type,
  12687. }
  12688. differences = append(differences, diff)
  12689. }
  12690. }
  12691. return differences
  12692. }
  12693. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  12694. var adviceList []*models.HisDoctorAdviceInfo
  12695. var projectList []*models.HisPrescriptionProject
  12696. var advice_ids []int64
  12697. var project_ids []int64
  12698. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12699. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12700. //var tempPrescription *models.HisPrescriptionProjectscription
  12701. if len(prescriptions) > 0 {
  12702. for _, item := range prescriptions {
  12703. items := item.(map[string]interface{})
  12704. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12705. advices := items["advices"].([]interface{})
  12706. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12707. groupNo := int64(0)
  12708. ctime := time.Now().Unix()
  12709. mtime := ctime
  12710. if len(advices) > 0 {
  12711. for _, advice := range advices {
  12712. var s models.HisDoctorAdviceInfo
  12713. s.AdviceType = 2
  12714. s.StopState = 2
  12715. s.ExecutionState = 2
  12716. s.Status = 1
  12717. s.Groupno = groupNo
  12718. s.CreatedTime = ctime
  12719. s.UpdatedTime = mtime
  12720. s.IsSettle = 2
  12721. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  12722. //存储切片中
  12723. if s.ID > 0 {
  12724. advice_ids = append(advice_ids, s.ID)
  12725. adviceList = append(adviceList, &s)
  12726. }
  12727. }
  12728. }
  12729. }
  12730. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12731. projects := items["project"].([]interface{})
  12732. if len(projects) > 0 {
  12733. for _, project := range projects {
  12734. var p models.HisPrescriptionProject
  12735. p.Ctime = time.Now().Unix()
  12736. p.Mtime = time.Now().Unix()
  12737. p.Status = 1
  12738. SetProjectWithJSON(&p, project.(map[string]interface{}))
  12739. if p.ID > 0 {
  12740. project_ids = append(project_ids, p.ID)
  12741. projectList = append(projectList, &p)
  12742. }
  12743. }
  12744. }
  12745. }
  12746. }
  12747. }
  12748. }
  12749. editCustomData.projectList = projectList
  12750. editCustomData.adviceList = adviceList
  12751. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  12752. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  12753. srcCustomData.adviceList = list
  12754. srcCustomData.projectList = list2
  12755. return
  12756. }
  12757. func (c *HisApiController) GetAllGoodInforList() {
  12758. orgId := c.GetAdminUserInfo().CurrentOrgId
  12759. goodList, _ := service.GetAllGoodList(orgId)
  12760. c.ServeSuccessJSON(map[string]interface{}{
  12761. "goodList": goodList,
  12762. })
  12763. return
  12764. }
  12765. func (this *HisApiController) SaveGoodList() {
  12766. project_name := this.GetString("project_name")
  12767. sort, _ := this.GetInt64("sort")
  12768. orgId := this.GetAdminUserInfo().CurrentOrgId
  12769. dataBody := make(map[string]interface{}, 0)
  12770. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  12771. if err != nil {
  12772. utils.ErrorLog(err.Error())
  12773. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12774. return
  12775. }
  12776. goodTeam := models.XtGoodTeam{
  12777. ProjectName: project_name,
  12778. Sort: sort,
  12779. UserOrgId: orgId,
  12780. Status: 1,
  12781. Ctime: time.Now().Unix(),
  12782. Mtime: time.Now().Unix(),
  12783. }
  12784. service.CreateGoodTeam(goodTeam)
  12785. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  12786. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  12787. infos, _ := dataBody["info"].([]interface{})
  12788. if len(infos) > 0 {
  12789. for _, item := range infos {
  12790. items := item.(map[string]interface{})
  12791. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  12792. utils.ErrorLog("good_id")
  12793. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12794. return
  12795. }
  12796. good_id := int64(items["good_id"].(float64))
  12797. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  12798. utils.ErrorLog("number")
  12799. }
  12800. number := int64(items["number"].(float64))
  12801. xtGoodTeamList := models.XtGoodTeamList{
  12802. GoodId: good_id,
  12803. Count: number,
  12804. TeamId: lastGoodTeam.ID,
  12805. UserOrgId: orgId,
  12806. Status: 1,
  12807. Ctime: time.Now().Unix(),
  12808. Mtime: time.Now().Unix(),
  12809. }
  12810. service.CreateGoodList(xtGoodTeamList)
  12811. }
  12812. this.ServeSuccessJSON(map[string]interface{}{
  12813. "lastGoodTeam": lastGoodTeam,
  12814. })
  12815. }
  12816. }
  12817. return
  12818. }
  12819. func (this *HisApiController) GetGoodList() {
  12820. orgId := this.GetAdminUserInfo().CurrentOrgId
  12821. limit, _ := this.GetInt64("limit")
  12822. page, _ := this.GetInt64("page")
  12823. keyword := this.GetString("keyword")
  12824. list, total, _ := service.GetGoodList(orgId, limit, page, keyword)
  12825. this.ServeSuccessJSON(map[string]interface{}{
  12826. "list": list,
  12827. "total": total,
  12828. })
  12829. }
  12830. func (this *HisApiController) GetGoodNameDetail() {
  12831. id, _ := this.GetInt64("id")
  12832. orgId := this.GetAdminUserInfo().CurrentOrgId
  12833. goodNameDetail, _ := service.GetGoodNameDetail(id, orgId)
  12834. goodList, _ := service.GetAllGoodList(orgId)
  12835. this.ServeSuccessJSON(map[string]interface{}{
  12836. "goodNameDetail": goodNameDetail,
  12837. "goodList": goodList,
  12838. })
  12839. }
  12840. func (this *HisApiController) UpdateGoodList() {
  12841. project_name := this.GetString("project_name")
  12842. sort, _ := this.GetInt64("sort")
  12843. id, _ := this.GetInt64("id")
  12844. orgId := this.GetAdminUserInfo().CurrentOrgId
  12845. dataBody := make(map[string]interface{}, 0)
  12846. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  12847. if err != nil {
  12848. utils.ErrorLog(err.Error())
  12849. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12850. return
  12851. }
  12852. goodTeam := models.XtGoodTeam{
  12853. ProjectName: project_name,
  12854. Sort: sort,
  12855. UserOrgId: orgId,
  12856. Status: 1,
  12857. Ctime: time.Now().Unix(),
  12858. Mtime: time.Now().Unix(),
  12859. ID: id,
  12860. }
  12861. service.SaveGoodTeam(goodTeam)
  12862. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  12863. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  12864. infos, _ := dataBody["info"].([]interface{})
  12865. if len(infos) > 0 {
  12866. for _, item := range infos {
  12867. items := item.(map[string]interface{})
  12868. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  12869. utils.ErrorLog("good_id")
  12870. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12871. return
  12872. }
  12873. good_id := int64(items["good_id"].(float64))
  12874. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  12875. utils.ErrorLog("id")
  12876. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12877. return
  12878. }
  12879. id := int64(items["id"].(float64))
  12880. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  12881. utils.ErrorLog("number")
  12882. }
  12883. number := int64(items["number"].(float64))
  12884. xtGoodTeamList := models.XtGoodTeamList{
  12885. ID: id,
  12886. GoodId: good_id,
  12887. Count: number,
  12888. TeamId: lastGoodTeam.ID,
  12889. UserOrgId: orgId,
  12890. Status: 1,
  12891. Ctime: time.Now().Unix(),
  12892. Mtime: time.Now().Unix(),
  12893. }
  12894. service.SaveGoodList(xtGoodTeamList)
  12895. }
  12896. this.ServeSuccessJSON(map[string]interface{}{
  12897. "lastGoodTeam": lastGoodTeam,
  12898. })
  12899. }
  12900. }
  12901. return
  12902. }
  12903. func (this *HisApiController) DeleteGoodTeam() {
  12904. id, _ := this.GetInt64("id")
  12905. team, _ := service.DeleteGoodTeam(id)
  12906. this.ServeSuccessJSON(map[string]interface{}{
  12907. "team": team,
  12908. })
  12909. }
  12910. func (this *HisApiController) DeleteGood() {
  12911. id, _ := this.GetInt64("id")
  12912. good, _ := service.DeleteGood(id)
  12913. this.ServeSuccessJSON(map[string]interface{}{
  12914. "good": good,
  12915. })
  12916. }