his_api_controller.go 365KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "github.com/shopspring/decimal"
  12. "math/rand"
  13. "reflect"
  14. "strconv"
  15. "strings"
  16. "syscall"
  17. "time"
  18. "unsafe"
  19. )
  20. type HisApiController struct {
  21. BaseAuthAPIController
  22. }
  23. func HisManagerApiRegistRouters() {
  24. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  25. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  26. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  27. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  28. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  29. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  30. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  31. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  32. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  33. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  34. beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  35. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  36. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  37. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  40. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  41. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  42. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  43. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  44. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  45. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  46. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  47. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  48. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  49. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  50. //新增附加费用
  51. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  52. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  53. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  54. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  55. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  56. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  57. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  58. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  59. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  60. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  61. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  62. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  63. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  64. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  65. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  66. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  67. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. }
  83. func (c *PublicApiController) GetBaiLinExportData() {
  84. data := service.GetBaiLinOrderData()
  85. fmt.Println(len(data))
  86. var new_data []*models.NewCustomHisOrder
  87. for _, item := range data {
  88. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  89. new_data = append(new_data, item)
  90. }
  91. }
  92. fmt.Println(len(new_data))
  93. c.ServeSuccessJSON(map[string]interface{}{
  94. "list": new_data,
  95. })
  96. }
  97. func (c *HisApiController) GetHisUnChargePatientList() {
  98. record_date := c.GetString("record_date")
  99. timeLayout := "2006-01-02"
  100. loc, _ := time.LoadLocation("Local")
  101. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  102. if err != nil {
  103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  104. return
  105. }
  106. recordDateTime := theTime.Unix()
  107. adminInfo := c.GetAdminUserInfo()
  108. var tempPatients []*service.NewTempPatients
  109. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  110. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  111. var patients []*service.NewTempPatients
  112. var patients_two []*service.NewTempPatients
  113. for _, item := range tempPatients {
  114. //过滤掉没挂号的和没开处方的
  115. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  116. patients = append(patients, item)
  117. }
  118. //过滤掉没挂号的
  119. if len(item.HisPatient) > 0 {
  120. patients_two = append(patients_two, item)
  121. }
  122. }
  123. c.ServeSuccessJSON(map[string]interface{}{
  124. "list": patients,
  125. "list_two": patients_two,
  126. })
  127. }
  128. func (c *HisApiController) GetPrivateExpensesOrder() {
  129. //id, _ := c.GetInt64("id")
  130. //record_time := c.GetString("record_time")
  131. order_id, _ := c.GetInt64("order_id")
  132. admin_user_id, _ := c.GetInt64("admin_user_id")
  133. //timeLayout := "2006-01-02"
  134. //loc, _ := time.LoadLocation("Local")
  135. //
  136. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  137. //if err != nil {
  138. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  139. // return
  140. //}
  141. //recordDateTime := theTime.Unix()
  142. adminUser := c.GetAdminUserInfo()
  143. order, _ := service.GetHisOrderByID(order_id)
  144. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  145. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  146. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  147. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  148. //var config []*models.HisXtDiagnoseConfig
  149. var name string
  150. if order.PType == 1 {
  151. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  152. for _, item := range diagnosis_ids {
  153. id, _ := strconv.ParseInt(item, 10, 64)
  154. diagnosisConfig, _ := service.FindDiagnoseById(id)
  155. if len(name) == 0 {
  156. name = diagnosisConfig.ClassName
  157. } else {
  158. name = name + "," + diagnosisConfig.ClassName
  159. }
  160. }
  161. } else {
  162. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  163. for _, item := range diagnosis_ids {
  164. id, _ := strconv.ParseInt(item, 10, 64)
  165. diagnosisConfig, _ := service.FindDiagnoseById(id)
  166. if len(name) == 0 {
  167. name = diagnosisConfig.ClassName
  168. } else {
  169. name = name + "," + diagnosisConfig.ClassName
  170. }
  171. }
  172. }
  173. var bedCostTotal float64 = 0 //床位总费
  174. //var bedCostSelfTotal float64 = 0 //床位自费
  175. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  176. var operationCostTotal float64 = 0 //手术费
  177. //var operationCostSelfTotal float64 = 0 //手术费
  178. var operationCostPartSelfTotal float64 = 0 //手术费
  179. var otherCostTotal float64 = 0 //其他费用
  180. //var otherCostSelfTotal float64 = 0 //其他费用
  181. var otherCostPartSelfTotal float64 = 0 //其他费用
  182. var materialCostTotal float64 = 0 //材料费
  183. //var materialCostSelfTotal float64 = 0 //材料费
  184. var materialCostPartSelfTotal float64 = 0 //材料费
  185. var westernMedicineCostTotal float64 = 0 //西药费
  186. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  187. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  188. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  189. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  190. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  191. var checkCostTotal float64 = 0 //检查费
  192. //var checkCostSelfTotal float64 = 0 //检查费
  193. var checkCostPartSelfTotal float64 = 0 //检查费
  194. var laboratoryCostTotal float64 = 0 //化验费
  195. //var laboratoryCostSelfTotal float64 = 0 //化验费
  196. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  197. var treatCostTotal float64 = 0 //治疗费用
  198. //var treatCostSelfTotal float64 = 0 //治疗费用
  199. var treatCostPartSelfTotal float64 = 0 //治疗费用
  200. var zhenChaCostTotal float64 = 0 //其他费用
  201. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  202. decimal.DivisionPrecision = 2
  203. for _, item := range orderInfos {
  204. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  205. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  206. item.MedChrgitmType = "09"
  207. }
  208. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  209. if item.HisPrescriptionProject.Type == 2 {
  210. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  211. fmt.Println("CostClassify")
  212. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  213. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  214. case 0:
  215. item.MedChrgitmType = "0"
  216. break
  217. case 1:
  218. item.MedChrgitmType = "14"
  219. break
  220. case 2:
  221. item.MedChrgitmType = "05"
  222. break
  223. case 3:
  224. item.MedChrgitmType = "03"
  225. break
  226. case 4:
  227. item.MedChrgitmType = "03"
  228. break
  229. case 5:
  230. item.MedChrgitmType = "08"
  231. break
  232. case 6:
  233. item.MedChrgitmType = "14"
  234. break
  235. case 7:
  236. item.MedChrgitmType = "14"
  237. break
  238. case 8:
  239. item.MedChrgitmType = "03"
  240. break
  241. case 9:
  242. item.MedChrgitmType = "14"
  243. break
  244. case 10:
  245. item.MedChrgitmType = "14"
  246. break
  247. case 11:
  248. item.MedChrgitmType = "06"
  249. break
  250. case 12:
  251. item.MedChrgitmType = "12"
  252. break
  253. case 13:
  254. item.MedChrgitmType = "01"
  255. break
  256. case 14:
  257. item.MedChrgitmType = "04"
  258. break
  259. case 15:
  260. item.MedChrgitmType = "14"
  261. break
  262. }
  263. } else {
  264. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  265. case 1:
  266. item.MedChrgitmType = "14"
  267. break
  268. case 2:
  269. item.MedChrgitmType = "05"
  270. break
  271. case 3:
  272. item.MedChrgitmType = "04"
  273. break
  274. case 4:
  275. item.MedChrgitmType = "14"
  276. break
  277. case 5:
  278. item.MedChrgitmType = "08"
  279. break
  280. case 6:
  281. item.MedChrgitmType = "14"
  282. break
  283. case 7:
  284. item.MedChrgitmType = "14"
  285. break
  286. case 8:
  287. item.MedChrgitmType = "03"
  288. break
  289. case 9:
  290. item.MedChrgitmType = "14"
  291. break
  292. }
  293. }
  294. } else if item.HisPrescriptionProject.Type == 3 {
  295. item.MedChrgitmType = "08"
  296. }
  297. }
  298. }
  299. order.PsnCashPay = order.MedfeeSumamt
  300. for _, item := range orderInfos {
  301. if item.MedChrgitmType == "01" { //床位费
  302. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  303. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  304. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  305. }
  306. if item.MedChrgitmType == "02" { //诊察费
  307. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  308. //zhenChaCostSelfTotal = zhenChaCostTotal
  309. }
  310. if item.MedChrgitmType == "03" { //检查费
  311. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  312. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  313. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  314. }
  315. if item.MedChrgitmType == "02" { //检查费
  316. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  317. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  318. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  319. }
  320. if item.MedChrgitmType == "04" { //化验费
  321. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  322. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  323. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  324. }
  325. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  326. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  327. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  328. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  329. }
  330. if item.MedChrgitmType == "06" { //手术费
  331. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  332. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  333. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  334. }
  335. if item.MedChrgitmType == "08" { //材料费
  336. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  337. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  338. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  339. }
  340. if item.MedChrgitmType == "09" { //西药费
  341. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  342. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  343. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  344. }
  345. if item.MedChrgitmType == "11" { //中成费
  346. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  347. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  348. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  349. }
  350. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  351. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  352. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  353. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  354. }
  355. }
  356. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  357. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  358. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  359. patient, _ := service.GetPatientByID(order.UserOrgId, order.PatientId)
  360. c.ServeSuccessJSON(map[string]interface{}{
  361. "patient": patient,
  362. "order_infos": orderInfos,
  363. "diagnosis": name,
  364. "bedCostTotal": bedCostTotal,
  365. "bedCostSelfTotal": bedCostTotal,
  366. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  367. "operationCostTotal": operationCostTotal,
  368. "operationCostSelfTotal": operationCostTotal,
  369. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  370. "otherCostTotal": otherCostTotal,
  371. "otherCostSelfTotal": otherCostTotal,
  372. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  373. "materialCostTotal": materialCostTotal,
  374. "materialCostSelfTotal": materialCostTotal,
  375. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  376. "westernMedicineCostTotal": westernMedicineCostTotal,
  377. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  378. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  379. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  380. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  381. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  382. "checkCostTotal": checkCostTotal,
  383. "checkCostSelfTotal": checkCostTotal,
  384. "zhenChaCostTotal": zhenChaCostTotal,
  385. "zhenChaCostSelfTotal": zhenChaCostTotal,
  386. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  387. "laboratoryCostTotal": laboratoryCostTotal,
  388. "laboratoryCostSelfTotal": laboratoryCostTotal,
  389. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  390. "treatCostTotal": treatCostTotal,
  391. "treatCostSelfTotal": treatCostTotal,
  392. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  393. "charge_admin": charge_admin,
  394. "printor_admin": printor_admin,
  395. "org_name": org.OrgName,
  396. "org_code": miConfig.Code,
  397. "name": patient.Name,
  398. "number": order.MdtrtId,
  399. "date": order.SettleAccountsDate,
  400. "info": order,
  401. "his_hospital": his_hospital,
  402. "his": his,
  403. })
  404. }
  405. func (c *HisApiController) RefudDetail() {
  406. order_id, _ := c.GetInt64("order_id")
  407. order, _ := service.GetHisOrderByID(order_id)
  408. adminUser := c.GetAdminUserInfo()
  409. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  410. c.ServeSuccessJSON(map[string]interface{}{
  411. "msg": "撤销成功",
  412. })
  413. }
  414. func (c *HisApiController) Sscard() {
  415. //r := CardInit()
  416. //if r == 0 {
  417. // GetBaseInfo()
  418. //}
  419. //c.ServeSuccessJSON(map[string]interface{}{
  420. // "list": "11",
  421. //})
  422. }
  423. func GetBaseInfo() error {
  424. //handle := syscall.MustLoadDLL("SSCard.dll")
  425. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  426. //
  427. //str := make([]byte, 256)
  428. //str1 := make([]byte, 256)
  429. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  430. //if ferr != nil {
  431. // fmt.Println("ReadCardBas 报错", ferr.Error())
  432. // return ferr
  433. //}
  434. //
  435. //fmt.Println(string(str))
  436. //
  437. //fmt.Println(r)
  438. return nil
  439. }
  440. func CardInit() int {
  441. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  442. //add := DllTestDef.MustFindProc("Init")
  443. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  444. //if err != nil {
  445. // fmt.Println("SSCard的运算结果为:", ret)
  446. //}
  447. //result := int(ret)
  448. return 0
  449. }
  450. func IntPtr(n int) uintptr {
  451. return uintptr(n)
  452. }
  453. func StrPtr(s string) uintptr {
  454. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  455. }
  456. func (c *HisApiController) GetHisPatientList() {
  457. //types, _ := c.GetInt64("type", 0)
  458. record_date := c.GetString("record_date")
  459. sch_type, _ := c.GetInt64("sch_type")
  460. timeLayout := "2006-01-02"
  461. loc, _ := time.LoadLocation("Local")
  462. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  463. if err != nil {
  464. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  465. return
  466. }
  467. recordDateTime := theTime.Unix()
  468. adminInfo := c.GetAdminUserInfo()
  469. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  470. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  471. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  472. //获取当前用户的信息
  473. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  474. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  475. //获取所有科室信息
  476. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  477. c.ServeSuccessJSON(map[string]interface{}{
  478. "list": patients,
  479. "list_two": patients_two,
  480. "info": adminUserInfo,
  481. "doctors": doctors,
  482. "department": department,
  483. })
  484. }
  485. type CustomTemplate struct {
  486. ID int64 `gorm:"column:id" json:"id" form:"id"`
  487. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  488. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  489. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  490. Status int64 `gorm:"column:status" json:"status" form:"status"`
  491. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  492. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  493. Type int64 `gorm:"column:type" json:"type" form:"type"`
  494. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  495. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  496. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  497. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  498. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  499. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  500. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  501. }
  502. func (c *HisApiController) GetHisPatientInfo() {
  503. patient_id, _ := c.GetInt64("patient_id")
  504. his_patient_id, _ := c.GetInt64("his_patient_id")
  505. record_date := c.GetString("record_date")
  506. number := c.GetString("number")
  507. //start_time := c.GetString("start_time")
  508. //end_time := c.GetString("end_time")
  509. p_type, _ := c.GetInt64("p_type")
  510. timeLayout := "2006-01-02"
  511. loc, _ := time.LoadLocation("Local")
  512. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  513. if err != nil {
  514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  515. return
  516. }
  517. recordDateTime := theTime.Unix()
  518. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  519. //if err != nil {
  520. //
  521. //}
  522. //startRecordDateTime := startTime.Unix()
  523. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  524. //if err != nil {
  525. //
  526. //}
  527. //endRecordDateTime := endTime.Unix()
  528. admin := c.GetAdminUserInfo()
  529. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  530. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  531. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  532. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  533. var prescriptions []*models.HisPrescription
  534. var last_prescriptions []*models.HisPrescription
  535. var sch_prescriptions []CustomTemplate
  536. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  537. if p_type == 1 { //住院
  538. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  539. for _, item := range prescriptions {
  540. for _, subItem := range item.HisDoctorAdviceInfo {
  541. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  542. if info.RetailPrice > 0 {
  543. subItem.Drug.MinPrice = info.RetailPrice
  544. }
  545. }
  546. }
  547. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  548. } else { //门诊
  549. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  550. for _, item := range prescriptions {
  551. for _, subItem := range item.HisDoctorAdviceInfo {
  552. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  553. if info.RetailPrice > 0 {
  554. subItem.Drug.MinPrice = info.RetailPrice
  555. }
  556. }
  557. }
  558. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  559. }
  560. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  561. if sch.ID > 0 {
  562. var week string
  563. t := time.Now()
  564. switch t.Weekday().String() {
  565. case "Monday":
  566. week = "周一"
  567. break
  568. case "Tuesday":
  569. week = "周二"
  570. break
  571. case "Wednesday":
  572. week = "周三"
  573. break
  574. case "Thursday":
  575. week = "周四"
  576. break
  577. case "Friday":
  578. week = "周五"
  579. break
  580. case "Saturday":
  581. week = "周六"
  582. break
  583. case "Sunday":
  584. week = "周日"
  585. break
  586. }
  587. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  588. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  589. //根据推送频率组装新的数组
  590. for _, item := range temp_sch_prescriptions {
  591. var cus CustomTemplate
  592. cus.ID = item.ID
  593. cus.UserOrgId = item.UserOrgId
  594. cus.PatientId = item.PatientId
  595. cus.MedType = item.MedType
  596. cus.RecordDate = item.RecordDate
  597. cus.Type = item.Type
  598. cus.PType = item.PType
  599. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  600. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  601. if subItem.FrequencyType == 1 { //每次必推
  602. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  603. }
  604. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  605. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  606. }
  607. if subItem.FrequencyType == 2 { //按照天数频率
  608. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  609. now := p.Unix()
  610. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  611. dayStr2 := "-" + dayStr
  612. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  613. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  614. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  615. if len(advices) == 0 {
  616. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  617. }
  618. }
  619. }
  620. }
  621. for _, subItem := range item.HisPrescriptionProjectTemplate {
  622. if subItem.Type == 2 {
  623. if subItem.XtHisProject.MedicalStatus != 1 {
  624. if subItem.FrequencyType == 1 {
  625. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  626. }
  627. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  628. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  629. }
  630. if subItem.FrequencyType == 2 {
  631. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  632. now := p.Unix()
  633. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  634. dayStr2 := "-" + dayStr
  635. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  636. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  637. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  638. if len(projects) == 0 {
  639. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  640. }
  641. }
  642. }
  643. } else if subItem.Type == 3 {
  644. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  645. if subItem.FrequencyType == 1 {
  646. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  647. }
  648. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  649. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  650. }
  651. if subItem.FrequencyType == 2 {
  652. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  653. now := p.Unix()
  654. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  655. dayStr2 := "-" + dayStr
  656. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  657. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  658. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  659. if len(projects) == 0 {
  660. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  661. }
  662. }
  663. }
  664. }
  665. }
  666. sch_prescriptions = append(sch_prescriptions, cus)
  667. }
  668. for _, item := range sch_prescriptions {
  669. if len(item.HisPrescriptionProjectTemplate) == 0 {
  670. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  671. }
  672. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  673. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  674. }
  675. }
  676. }
  677. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  678. if config.ID > 0 && config.IsOpen == 1 {
  679. for _, item := range sch_prescriptions {
  680. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  681. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  682. if info.RetailPrice > 0 {
  683. subItem.Drug.MinPrice = info.RetailPrice
  684. }
  685. }
  686. }
  687. }
  688. if config.ID > 0 && config.IsOpen == 1 {
  689. for _, item := range sch_prescriptions {
  690. for _, subItem := range item.HisPrescriptionProjectTemplate {
  691. if subItem.Type == 3 {
  692. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  693. if info.Price > 0 {
  694. subItem.GoodInfo.PackingPrice = info.Price
  695. }
  696. }
  697. }
  698. }
  699. }
  700. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  701. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  702. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  703. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  704. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  705. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  706. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  707. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  708. //获取所有科室信息
  709. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  710. c.ServeSuccessJSON(map[string]interface{}{
  711. "his_info": his_patient_info,
  712. "xt_info": xt_patient_info,
  713. "prescription": prescriptions,
  714. "case_history": case_history,
  715. "info": patientPrescriptionInfo,
  716. //"month_prescriptions": monthPrescriptions,
  717. "order": order,
  718. "doctors": doctors,
  719. "department": department,
  720. "sch_prescriptions": sch_prescriptions,
  721. "last_prescriptions": last_prescriptions,
  722. "schedule": sch,
  723. "count": count,
  724. "drugStockConfig": drugStockConfig,
  725. "last_info": lastPatientPrescriptionInfo,
  726. })
  727. return
  728. }
  729. func (c *HisApiController) GetHisPrescriptionConfig() {
  730. adminInfo := c.GetAdminUserInfo()
  731. //获取医嘱模版
  732. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  733. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  734. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  735. //获取所有基础药
  736. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  737. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  738. if config.ID > 0 && config.IsOpen == 1 {
  739. for _, item := range drugs {
  740. var index = 0
  741. for _, subItem := range item.OtherDrugWarehouseInfo {
  742. if index == 0 {
  743. index = index + 1
  744. if subItem.RetailPrice > 0 {
  745. item.MinPrice = subItem.RetailPrice
  746. }
  747. }
  748. }
  749. }
  750. }
  751. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  752. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  753. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  754. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  755. //获取所有科室信息
  756. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  757. //获取诊断信息
  758. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  759. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  760. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  761. c.ServeSuccessJSON(map[string]interface{}{
  762. "drugs": drugs,
  763. "advices_template": advices,
  764. "drugways": drugways,
  765. "efs": efs,
  766. "doctors": doctors,
  767. "department": department,
  768. "sick": sick,
  769. "additions": additions,
  770. "diagnose": diagnose,
  771. "manufacturers": manufacturers,
  772. })
  773. }
  774. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  775. //获取所有基础药
  776. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  777. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  778. if config.ID > 0 && config.IsOpen == 1 {
  779. for _, item := range drugs {
  780. var index = 0
  781. for _, subItem := range item.OtherDrugWarehouseInfo {
  782. if index == 0 {
  783. index = index + 1
  784. if subItem.RetailPrice > 0 {
  785. item.MinPrice = subItem.RetailPrice
  786. }
  787. }
  788. }
  789. }
  790. }
  791. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  792. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  793. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  794. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  795. //获取所有科室信息
  796. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  797. //获取诊断信息
  798. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  799. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  800. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  801. c.ServeSuccessJSON(map[string]interface{}{
  802. "drugs": drugs,
  803. "advices_template": advices,
  804. "drugways": drugways,
  805. "efs": efs,
  806. "doctors": doctors,
  807. "department": department,
  808. "sick": sick,
  809. "additions": additions,
  810. "diagnose": diagnose,
  811. "manufacturers": manufacturers,
  812. })
  813. }
  814. }
  815. func (c *HisApiController) CreateHisPrescription() {
  816. record_date := c.GetString("record_date")
  817. patient_id, _ := c.GetInt64("patient_id")
  818. reg_type, _ := c.GetInt64("reg_type")
  819. diagnose := c.GetString("diagnose")
  820. sick_type, _ := c.GetInt64("sick_type")
  821. sick_history := c.GetString("sick_history")
  822. doctor_id, _ := c.GetInt64("doctor", 0)
  823. department, _ := c.GetInt64("department", 0)
  824. his_patient_id, _ := c.GetInt64("his_patient_id")
  825. p_type, _ := c.GetInt64("p_type")
  826. dataBody := make(map[string]interface{}, 0)
  827. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  828. if err != nil {
  829. utils.ErrorLog(err.Error())
  830. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  831. return
  832. }
  833. timeLayout := "2006-01-02"
  834. loc, _ := time.LoadLocation("Local")
  835. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  836. if err != nil {
  837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  838. return
  839. }
  840. adminInfo := c.GetAdminUserInfo()
  841. recordDateTime := theTime.Unix()
  842. //查询默认出库仓库库存
  843. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  844. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  845. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  846. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  847. if len(lists) == 1 {
  848. his_patient_id = lists[0].ID
  849. }
  850. }
  851. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  852. //保存处方出库
  853. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  854. //自动出库
  855. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  856. //耗材保存处方出库
  857. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  858. //已发药和已收费限制逻辑
  859. isMidicine := false
  860. isCharge := false
  861. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  862. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  863. if len(prescriptions) > 0 {
  864. for _, item := range prescriptions {
  865. items := item.(map[string]interface{})
  866. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  867. utils.ErrorLog("id")
  868. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  869. return
  870. }
  871. id := int64(items["id"].(float64))
  872. if id > 0 {
  873. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  874. if err != nil {
  875. if new_prescription.OrderStatus == 4 {
  876. isCharge = true
  877. }
  878. }
  879. }
  880. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  881. advices := items["advices"].([]interface{})
  882. if len(advices) > 0 {
  883. for _, advice := range advices {
  884. var adviceId int64
  885. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  886. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  887. }
  888. if adviceId > 0 {
  889. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  890. if err == nil {
  891. if his_advice_info.IsMedicine == 1 {
  892. isMidicine = true
  893. }
  894. }
  895. }
  896. }
  897. }
  898. }
  899. }
  900. }
  901. }
  902. if isMidicine == true {
  903. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  904. return
  905. }
  906. if isCharge == true {
  907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  908. return
  909. }
  910. //已发药和已收费限制逻辑
  911. if drugStockConfig.IsOpen == 1 {
  912. //校验库存总量
  913. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  914. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  915. if len(prescriptions) > 0 {
  916. for _, item := range prescriptions {
  917. items := item.(map[string]interface{})
  918. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  919. advices := items["advices"].([]interface{})
  920. if len(advices) > 0 {
  921. for _, advice := range advices {
  922. var drug_id int64
  923. var prescribing_number float64
  924. var prescribingNumberUnit string
  925. var adviceId int64
  926. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  927. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  928. }
  929. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  930. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  931. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  932. }
  933. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  934. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  935. }
  936. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  937. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  938. }
  939. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  940. if drug.ID == 0 {
  941. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  942. return
  943. }
  944. //查询药品的所有库存
  945. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  946. var total_count int64
  947. for _, it := range list {
  948. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  949. }
  950. totals := strconv.FormatInt(total_count, 10)
  951. //查询该药品是否存在开药记录
  952. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  953. //查询最新批次库存
  954. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  955. var batch_number_count int64
  956. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  957. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  958. //新增处方
  959. if advicelist.ID == 0 {
  960. all_count, _ := strconv.ParseFloat(totals, 64)
  961. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  962. if prescribingNumberUnit == drug.MinUnit {
  963. if drug.IsUse != 1 {
  964. if prescribing_number > all_count {
  965. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  966. return
  967. }
  968. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  969. if prescribing_number > batch_number_all_count {
  970. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  971. return
  972. }
  973. }
  974. }
  975. }
  976. if prescribingNumberUnit == drug.MaxUnit {
  977. num := prescribing_number * float64(drug.MinNumber)
  978. if drug.IsUse != 1 {
  979. if num > all_count {
  980. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  981. return
  982. }
  983. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  984. if num > batch_number_all_count {
  985. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  986. return
  987. }
  988. }
  989. }
  990. }
  991. }
  992. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  993. if drugOutConfig.IsOpen != 1 {
  994. //修改处方
  995. for _, advice := range advices {
  996. var drug_id int64
  997. var prescribing_number float64
  998. var prescribingNumberUnit string
  999. var prescribingNumber string
  1000. var adviceId int64
  1001. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1002. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1003. }
  1004. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1005. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1006. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1007. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1008. }
  1009. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1010. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1011. }
  1012. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1013. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1014. }
  1015. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1016. if drug.ID == 0 {
  1017. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1018. return
  1019. }
  1020. //查询药品的所有库存
  1021. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1022. var total_count int64
  1023. for _, it := range list {
  1024. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1025. }
  1026. totals := strconv.FormatInt(total_count, 10)
  1027. //查询该药品是否存在开药记录
  1028. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1029. //新增处方
  1030. if advicelist.ID == 0 {
  1031. //查询最新批次库存
  1032. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1033. var batch_number_count int64
  1034. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1035. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1036. all_count, _ := strconv.ParseFloat(totals, 64)
  1037. if prescribingNumberUnit == drug.MinUnit {
  1038. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1039. if drug.IsUse != 1 {
  1040. if prescribing_number > all_count {
  1041. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1042. return
  1043. }
  1044. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1045. if prescribing_number > batch_number_all_count {
  1046. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1047. return
  1048. }
  1049. }
  1050. }
  1051. } else {
  1052. if prescribingNumberUnit == drug.MaxUnit {
  1053. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1054. num := prescribing_number * float64(drug.MinNumber)
  1055. if drug.IsUse != 1 {
  1056. if num > all_count {
  1057. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1058. return
  1059. }
  1060. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1061. if prescribing_number > batch_number_all_count {
  1062. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1063. return
  1064. }
  1065. }
  1066. }
  1067. }
  1068. }
  1069. }
  1070. //修改处方
  1071. if advicelist.ID > 0 {
  1072. //查询最新批次库存
  1073. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1074. var batch_number_count int64
  1075. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1076. var device_number int64
  1077. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1078. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1079. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1080. device_number = prescribingNumberInt * drug.MinNumber
  1081. }
  1082. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1083. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1084. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1085. device_number = prescribingNumberInt
  1086. }
  1087. var number_count int64
  1088. if prescribingNumberUnit == drug.MaxUnit {
  1089. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1090. number_count = prescribingNumberInt * drug.MinNumber
  1091. }
  1092. if prescribingNumberUnit == drug.MinUnit {
  1093. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1094. number_count = prescribingNumberInt
  1095. }
  1096. //如果修改的数量大于之前修改的数量
  1097. if (number_count - device_number) > 0 {
  1098. //如果修改的差数量 大于库存数量
  1099. if drug.IsUse != 1 {
  1100. if (number_count - device_number) > total_count {
  1101. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1102. return
  1103. }
  1104. if (number_count - device_number) > batch_number_count {
  1105. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1106. return
  1107. }
  1108. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 9671 {
  1109. // 查询该药品最后一次出库记录
  1110. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1111. var out_count int64
  1112. var in_count int64
  1113. var stock_max_number int64
  1114. var stock_min_number int64
  1115. for _, it := range outInfo {
  1116. if it.CountUnit == drug.MaxUnit {
  1117. it.Count = it.Count * drug.MinNumber
  1118. }
  1119. out_count += it.Count
  1120. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1121. stock_max_number = warehouseInfoList.StockMaxNumber
  1122. stock_min_number = warehouseInfoList.StockMinNumber
  1123. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1124. }
  1125. if out_count > 0 {
  1126. if (number_count - device_number) > in_count {
  1127. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1128. return
  1129. }
  1130. }
  1131. // 未出库
  1132. if out_count == 0 {
  1133. var sum_in_count int64
  1134. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1135. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1136. fmt.Println("sum_in_count", sum_in_count)
  1137. //如果修改的数量大于有库存的第一个批次
  1138. if number_count > sum_in_count {
  1139. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  1140. return
  1141. }
  1142. }
  1143. }
  1144. }
  1145. }
  1146. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1147. fmt.Println("device_number2333233232323222323232323323322332", device_number)
  1148. fmt.Println("number_count99999999999999999999999999999999999", number_count)
  1149. if pharmacyConfig.IsOpen != 1 {
  1150. if device_number != number_count {
  1151. // 查询该药品最后一次出库记录
  1152. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  1153. //回退库存
  1154. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  1155. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  1156. }
  1157. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  1158. var stock_max_number int64
  1159. var stock_min_number int64
  1160. if number_count >= drug.MinNumber {
  1161. stock_max_number = device_number / drug.MinNumber
  1162. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  1163. stock_min_number = device_number % drug.MinNumber
  1164. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  1165. } else {
  1166. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  1167. }
  1168. }
  1169. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  1170. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  1171. }
  1172. //删除记录
  1173. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  1174. //查询默认仓库剩余多少库存
  1175. var sum_count int64
  1176. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  1177. for _, its := range stockInfo {
  1178. if its.MaxUnit == drug.MaxUnit {
  1179. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  1180. }
  1181. sum_count += its.StockMaxNumber + its.StockMinNumber
  1182. }
  1183. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  1184. }
  1185. }
  1186. }
  1187. }
  1188. }
  1189. //保存处方开药
  1190. if drugOutConfig.IsOpen == 1 {
  1191. //修改处方
  1192. for _, advice := range advices {
  1193. var drug_id int64
  1194. var prescribing_number float64
  1195. var prescribingNumberUnit string
  1196. var prescribingNumber string
  1197. var adviceId int64
  1198. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1199. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1200. }
  1201. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1202. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1203. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1204. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1205. }
  1206. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1207. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1208. }
  1209. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1210. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1211. }
  1212. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1213. if drug.ID == 0 {
  1214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1215. return
  1216. }
  1217. //查询药品的所有库存
  1218. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1219. var total_count int64
  1220. for _, it := range list {
  1221. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1222. }
  1223. totals := strconv.FormatInt(total_count, 10)
  1224. //查询该药品是否存在开药记录
  1225. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1226. //新增处方
  1227. if advicelist.ID == 0 {
  1228. //查询最新批次库存
  1229. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1230. var batch_number_count int64
  1231. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1232. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1233. all_count, _ := strconv.ParseFloat(totals, 64)
  1234. if prescribingNumberUnit == drug.MinUnit {
  1235. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1236. if drug.IsUse != 1 {
  1237. if prescribing_number > all_count {
  1238. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1239. return
  1240. }
  1241. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1242. if prescribing_number > batch_number_all_count {
  1243. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1244. return
  1245. }
  1246. }
  1247. }
  1248. } else {
  1249. if prescribingNumberUnit == drug.MaxUnit {
  1250. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1251. num := prescribing_number * float64(drug.MinNumber)
  1252. if drug.IsUse != 1 {
  1253. if num > all_count {
  1254. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1255. return
  1256. }
  1257. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1258. if prescribing_number > batch_number_all_count {
  1259. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1260. return
  1261. }
  1262. }
  1263. }
  1264. }
  1265. }
  1266. }
  1267. //修改处方
  1268. if advicelist.ID > 0 {
  1269. //查询最新批次库存
  1270. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1271. var batch_number_count int64
  1272. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1273. var device_number int64
  1274. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1275. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1276. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1277. device_number = prescribingNumberInt * drug.MinNumber
  1278. }
  1279. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1280. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1281. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1282. device_number = prescribingNumberInt
  1283. }
  1284. var number_count int64
  1285. if prescribingNumberUnit == drug.MaxUnit {
  1286. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1287. number_count = prescribingNumberInt * drug.MinNumber
  1288. }
  1289. if prescribingNumberUnit == drug.MinUnit {
  1290. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1291. number_count = prescribingNumberInt
  1292. }
  1293. //如果修改的数量大于之前修改的数量
  1294. if (number_count - device_number) > 0 {
  1295. //如果修改的差数量 大于库存数量
  1296. if drug.IsUse != 1 {
  1297. if (number_count - device_number) > total_count {
  1298. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1299. return
  1300. }
  1301. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1302. if (number_count - device_number) > batch_number_count {
  1303. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1304. return
  1305. }
  1306. }
  1307. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1308. //查询历史出库数据总批次
  1309. // 查询该药品最后一次出库记录
  1310. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1311. var out_count int64
  1312. var in_count int64
  1313. var stock_max_number int64
  1314. var stock_min_number int64
  1315. for _, it := range outInfo {
  1316. if it.CountUnit == drug.MaxUnit {
  1317. it.Count = it.Count * drug.MinNumber
  1318. }
  1319. out_count += it.Count
  1320. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1321. stock_max_number = warehouseInfoList.StockMaxNumber
  1322. stock_min_number = warehouseInfoList.StockMinNumber
  1323. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1324. }
  1325. if out_count > 0 {
  1326. if (number_count - device_number) > in_count {
  1327. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1328. return
  1329. }
  1330. }
  1331. // 未出库
  1332. if out_count == 0 {
  1333. var sum_in_count int64
  1334. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1335. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1336. //如果修改的数量大于有库存的第一个批次
  1337. if number_count > sum_in_count {
  1338. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  1339. return
  1340. }
  1341. }
  1342. }
  1343. }
  1344. }
  1345. }
  1346. }
  1347. }
  1348. }
  1349. }
  1350. }
  1351. }
  1352. }
  1353. }
  1354. }
  1355. //不使用耗材保存处方出库
  1356. if goodOutConfig.IsOpen != 1 {
  1357. if stockConfig.IsOpen == 1 {
  1358. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1359. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1360. if len(prescriptions) > 0 {
  1361. for _, item := range prescriptions {
  1362. items := item.(map[string]interface{})
  1363. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1364. projects := items["project"].([]interface{})
  1365. if len(projects) > 0 {
  1366. for _, project := range projects {
  1367. var project_id int64
  1368. var project_type int64
  1369. var totals float64
  1370. var project_name string
  1371. var parsetotal int64
  1372. var id int64
  1373. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  1374. id = int64(project.(map[string]interface{})["id"].(float64))
  1375. }
  1376. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  1377. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  1378. }
  1379. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  1380. project_type = int64(project.(map[string]interface{})["type"].(float64))
  1381. }
  1382. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  1383. total, _ := project.(map[string]interface{})["total"].(string)
  1384. totals, _ = strconv.ParseFloat(total, 64)
  1385. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  1386. }
  1387. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  1388. project_name = project.(map[string]interface{})["project_name"].(string)
  1389. }
  1390. if project_type == 3 {
  1391. //查找该耗材的出库记录
  1392. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  1393. if len(goodWarehouseInfo) == 0 {
  1394. //查询耗材库存
  1395. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  1396. var stock_count int64
  1397. for _, it := range list {
  1398. stock_count += it.StockCount
  1399. }
  1400. stock_counts := strconv.FormatInt(stock_count, 10)
  1401. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  1402. if totals > stock_total_count {
  1403. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  1404. return
  1405. }
  1406. //查找今日该患者已经出库的所有耗材
  1407. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  1408. for _, item := range goodList {
  1409. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  1410. var flush_count int64
  1411. for _, it := range goodListSix {
  1412. flush_count += it.StockCount
  1413. }
  1414. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  1415. creater := adminInfo.AdminUser.Id
  1416. if errs != nil {
  1417. goodErrcode := models.XtGoodErrcode{
  1418. UserOrgId: item.OrgId,
  1419. Errcode: "手动出库更新剩余出库失败",
  1420. GoodId: item.GoodId,
  1421. Status: 1,
  1422. Ctime: time.Now().Unix(),
  1423. Mtime: 0,
  1424. Count: 0,
  1425. StockCount: 0,
  1426. Creater: creater,
  1427. BatchNumberId: 0,
  1428. WarehouseOutId: 0,
  1429. }
  1430. service.CreateGoodErrcode(goodErrcode)
  1431. }
  1432. }
  1433. //删除记录
  1434. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  1435. }
  1436. if len(goodWarehouseInfo) > 0 {
  1437. //查询该患者耗材的历史数据
  1438. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  1439. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  1440. //数量发生改变
  1441. if parsetotal != count {
  1442. //查找今日该患者已经出库的所有耗材
  1443. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  1444. for _, item := range goodList {
  1445. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  1446. var flush_count int64
  1447. for _, it := range goodListSix {
  1448. flush_count += it.StockCount
  1449. }
  1450. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  1451. //减少出库数量
  1452. creater := adminInfo.AdminUser.Id
  1453. if errs != nil {
  1454. goodErrcode := models.XtGoodErrcode{
  1455. UserOrgId: item.OrgId,
  1456. Errcode: "手动出库更新剩余出库失败",
  1457. GoodId: item.GoodId,
  1458. Status: 1,
  1459. Ctime: time.Now().Unix(),
  1460. Mtime: 0,
  1461. Count: 0,
  1462. StockCount: 0,
  1463. Creater: creater,
  1464. BatchNumberId: 0,
  1465. WarehouseOutId: 0,
  1466. }
  1467. service.CreateGoodErrcode(goodErrcode)
  1468. }
  1469. //查询默认仓库
  1470. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  1471. var total_count int64
  1472. for _, it := range stockList {
  1473. total_count += it.StockCount
  1474. }
  1475. //基础库插入数据
  1476. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  1477. }
  1478. //删除记录
  1479. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  1480. }
  1481. }
  1482. }
  1483. }
  1484. }
  1485. }
  1486. }
  1487. }
  1488. }
  1489. }
  1490. }
  1491. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1492. var hpInfo models.HisPrescriptionInfo
  1493. if info.ID == 0 {
  1494. var randNum int
  1495. randNum = rand.Intn(10000) + 1000
  1496. timestamp := time.Now().Unix()
  1497. tempTime := time.Unix(timestamp, 0)
  1498. timeFormat := tempTime.Format("20060102150405")
  1499. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  1500. hpInfo = models.HisPrescriptionInfo{
  1501. HisPatientId: his_patient_id,
  1502. UserOrgId: adminInfo.CurrentOrgId,
  1503. RecordDate: theTime.Unix(),
  1504. PatientId: patient_id,
  1505. Status: 1,
  1506. Ctime: time.Now().Unix(),
  1507. Mtime: time.Now().Unix(),
  1508. Creator: adminInfo.AdminUser.Id,
  1509. Modifier: adminInfo.AdminUser.Id,
  1510. Diagnosis: diagnose,
  1511. SickHistory: sick_history,
  1512. Departments: department,
  1513. RegisterType: reg_type,
  1514. PrescriptionNumber: p_number,
  1515. PrescriptionStatus: 1,
  1516. Doctor: role.UserName,
  1517. DoctorId: doctor_id,
  1518. SickType: sick_type,
  1519. PType: p_type,
  1520. }
  1521. service.SavePatientPrescriptionInfo(hpInfo)
  1522. redis := service.RedisClient()
  1523. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1524. redis.Set(key, "", time.Second)
  1525. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1526. redis.Set(keyOne, "", time.Second)
  1527. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1528. redis.Set(keySeven, "", time.Second)
  1529. defer redis.Close()
  1530. } else {
  1531. hpInfo = models.HisPrescriptionInfo{
  1532. ID: info.ID,
  1533. UserOrgId: adminInfo.CurrentOrgId,
  1534. RecordDate: info.RecordDate,
  1535. PatientId: info.PatientId,
  1536. Status: 1,
  1537. Ctime: info.Ctime,
  1538. Mtime: time.Now().Unix(),
  1539. Creator: info.Creator,
  1540. Modifier: adminInfo.AdminUser.Id,
  1541. Diagnosis: diagnose,
  1542. SickHistory: sick_history,
  1543. Departments: department,
  1544. RegisterType: reg_type,
  1545. PrescriptionNumber: info.PrescriptionNumber,
  1546. Doctor: role.UserName,
  1547. PrescriptionStatus: info.PrescriptionStatus,
  1548. DoctorId: doctor_id,
  1549. SickType: sick_type,
  1550. PType: info.PType,
  1551. HisPatientId: info.HisPatientId,
  1552. }
  1553. service.SavePatientPrescriptionInfo(hpInfo)
  1554. redis := service.RedisClient()
  1555. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1556. redis.Set(key, "", time.Second)
  1557. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1558. redis.Set(keyOne, "", time.Second)
  1559. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1560. redis.Set(keySeven, "", time.Second)
  1561. defer redis.Close()
  1562. }
  1563. //定义切片
  1564. var adviceList []models.HisDoctorAdviceInfo
  1565. var projectList []models.HisPrescriptionProject
  1566. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1567. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1568. var tempPrescription *models.HisPrescription
  1569. if len(prescriptions) > 0 {
  1570. for _, item := range prescriptions {
  1571. items := item.(map[string]interface{})
  1572. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1573. utils.ErrorLog("id")
  1574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1575. return
  1576. }
  1577. id := int64(items["id"].(float64))
  1578. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1579. tempPrescription = &new_prescription
  1580. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  1581. utils.ErrorLog("type")
  1582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1583. return
  1584. }
  1585. types := int64(items["type"].(float64))
  1586. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  1587. utils.ErrorLog("med_type")
  1588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1589. return
  1590. }
  1591. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  1592. if med_type == "0" {
  1593. med_type = "14"
  1594. }
  1595. //if order_status == 0 {
  1596. // order_status = 1
  1597. //}
  1598. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  1599. utils.ErrorLog("pre_time")
  1600. }
  1601. preTime, _ := items["pre_time"].(string)
  1602. timeLayout := "2006-01-02"
  1603. loc, _ := time.LoadLocation("Local")
  1604. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  1605. if err != nil {
  1606. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1607. return
  1608. }
  1609. pTime := theTime2.Unix()
  1610. ctime := time.Now().Unix()
  1611. if tempPrescription.ID == 0 {
  1612. prescription := &models.HisPrescription{
  1613. ID: 0,
  1614. PatientId: patient_id,
  1615. UserOrgId: adminInfo.CurrentOrgId,
  1616. RecordDate: recordDateTime,
  1617. Ctime: ctime,
  1618. Mtime: ctime,
  1619. Type: types,
  1620. Modifier: adminInfo.AdminUser.Id,
  1621. Creator: adminInfo.AdminUser.Id,
  1622. Status: 1,
  1623. Doctor: role.UserName,
  1624. HisPatientId: his_patient_id,
  1625. OrderStatus: 1,
  1626. BatchNumber: "",
  1627. PrescriptionNumber: hpInfo.PrescriptionNumber,
  1628. PreTime: pTime,
  1629. PType: p_type,
  1630. MedType: med_type,
  1631. }
  1632. tempPrescription = prescription
  1633. service.SaveHisPrescription(tempPrescription)
  1634. redis := service.RedisClient()
  1635. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1636. redis.Set(key, "", time.Second)
  1637. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1638. redis.Set(keyOne, "", time.Second)
  1639. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1640. redis.Set(keySeven, "", time.Second)
  1641. defer redis.Close()
  1642. } else {
  1643. tempPrescription.ID = id
  1644. tempPrescription.Type = types
  1645. tempPrescription.Modifier = adminInfo.AdminUser.Id
  1646. tempPrescription.Mtime = time.Now().Unix()
  1647. tempPrescription.Doctor = role.UserName
  1648. //tempPrescription.OrderStatus = order_status
  1649. tempPrescription.PreTime = pTime
  1650. tempPrescription.MedType = med_type
  1651. service.SaveHisPrescription(tempPrescription)
  1652. redis := service.RedisClient()
  1653. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1654. redis.Set(key, "", time.Second)
  1655. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1656. redis.Set(keyOne, "", time.Second)
  1657. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1658. redis.Set(keySeven, "", time.Second)
  1659. defer redis.Close()
  1660. }
  1661. //service.SaveHisPrescription(prescription)
  1662. //更改患者挂号状态
  1663. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  1664. fmt.Println("更改失败", err2)
  1665. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1666. advices := items["advices"].([]interface{})
  1667. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1668. groupNo := int64(0)
  1669. ctime := time.Now().Unix()
  1670. mtime := ctime
  1671. if len(advices) > 0 {
  1672. for _, advice := range advices {
  1673. var s models.HisDoctorAdviceInfo
  1674. s.PrescriptionId = tempPrescription.ID
  1675. s.AdviceType = 2
  1676. s.AdviceDoctor = doctor_id
  1677. s.StopState = 2
  1678. s.ExecutionState = 2
  1679. s.AdviceDate = recordDateTime
  1680. s.Status = 1
  1681. s.UserOrgId = adminInfo.CurrentOrgId
  1682. s.RecordDate = recordDateTime
  1683. s.StartTime = tempPrescription.PreTime
  1684. s.Groupno = groupNo
  1685. s.CreatedTime = ctime
  1686. s.UpdatedTime = mtime
  1687. s.PatientId = patient_id
  1688. s.HisPatientId = his_patient_id
  1689. s.StartTime = pTime
  1690. s.IsSettle = 2
  1691. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  1692. if errcode > 0 {
  1693. c.ServeFailJSONWithSGJErrorCode(errcode)
  1694. return
  1695. }
  1696. s.StartTime = pTime
  1697. var total_count int64 //处方总库存
  1698. //查询改药品信息
  1699. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  1700. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  1701. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  1702. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  1703. total_count += prescribingNumberSeven * medical.MinNumber
  1704. }
  1705. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  1706. total_count += prescribingNumberSeven
  1707. }
  1708. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  1709. total_count += prescribingNumberSeven
  1710. }
  1711. service.CreateHisDoctorAdvice(&s)
  1712. //存储切片中
  1713. adviceList = append(adviceList, s)
  1714. redis := service.RedisClient()
  1715. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1716. redis.Set(key, "", time.Second)
  1717. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1718. redis.Set(keyOne, "", time.Second)
  1719. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1720. redis.Set(keySeven, "", time.Second)
  1721. var randNum int
  1722. randNum = rand.Intn(10000) + 1000
  1723. timestamp := time.Now().Unix()
  1724. tempTime := time.Unix(timestamp, 0)
  1725. timeFormat := tempTime.Format("20060102150405")
  1726. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  1727. service.CreateHisDoctorAdvice(&s)
  1728. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1729. redis.Set(keySix, "", time.Second)
  1730. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1731. redis.Set(keyFive, "", time.Second)
  1732. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1733. redis.Set(keyEight, "", time.Second)
  1734. defer redis.Close()
  1735. }
  1736. }
  1737. }
  1738. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1739. projects := items["project"].([]interface{})
  1740. if len(projects) > 0 {
  1741. for _, project := range projects {
  1742. var p models.HisPrescriptionProject
  1743. p.PrescriptionId = tempPrescription.ID
  1744. p.Ctime = time.Now().Unix()
  1745. p.Mtime = time.Now().Unix()
  1746. p.PatientId = patient_id
  1747. p.RecordDate = recordDateTime
  1748. p.Doctor = doctor_id
  1749. p.UserOrgId = adminInfo.CurrentOrgId
  1750. p.HisPatientId = his_patient_id
  1751. p.Status = 1
  1752. p.StartTime = pTime
  1753. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  1754. if errcode > 0 {
  1755. c.ServeFailJSONWithSGJErrorCode(errcode)
  1756. return
  1757. }
  1758. if p.ID == 0 {
  1759. p.IsOut = 2
  1760. }
  1761. if p.ID > 0 {
  1762. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  1763. p.IsOut = projectDetail.IsOut
  1764. }
  1765. service.CreateHisProjectTwo(&p)
  1766. projectList = append(projectList, p)
  1767. var randNum int
  1768. randNum = rand.Intn(10000) + 1000
  1769. timestamp := time.Now().Unix()
  1770. tempTime := time.Unix(timestamp, 0)
  1771. timeFormat := tempTime.Format("20060102150405")
  1772. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  1773. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  1774. //新增或者编辑项目,修改对应的标签数据
  1775. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  1776. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  1777. var label models.HisLabelPrintInfo
  1778. project, _ := service.GetProjectDetail(p.ProjectId)
  1779. if project.CostClassify == 3 { //类别为检验检查
  1780. if p.TeamId > 0 { //检验检查组套
  1781. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  1782. if tempLabel.ID == 0 {
  1783. team, _ := service.GetProjectTeamDetail(p.TeamId)
  1784. label.Number = tempPrescription.PrescriptionNumber
  1785. label.ProjectId = project.ID
  1786. label.Status = 1
  1787. label.IsPrint = 2
  1788. label.DoctorId = info.DoctorId
  1789. label.UserOrgId = p.UserOrgId
  1790. label.PatientId = patient_id
  1791. label.RecordDate = recordDateTime
  1792. label.Ctime = time.Now().Unix()
  1793. label.Mtime = time.Now().Unix()
  1794. label.ItemId = p.TeamId
  1795. label.FeedetlSn = p.FeedetlSn
  1796. label.PProjectId = p.ID
  1797. label.ProjectName = team.ProjectTeam
  1798. label.PatientName = patient.Name
  1799. service.CreateHisLabelRecord(&label)
  1800. }
  1801. } else { //单条检验检查项目
  1802. label.Number = tempPrescription.PrescriptionNumber
  1803. label.ProjectId = project.ID
  1804. label.Status = 1
  1805. label.DoctorId = info.DoctorId
  1806. label.UserOrgId = p.UserOrgId
  1807. label.PatientId = patient_id
  1808. label.RecordDate = recordDateTime
  1809. label.IsPrint = 2
  1810. label.Ctime = time.Now().Unix()
  1811. label.Mtime = time.Now().Unix()
  1812. label.FeedetlSn = p.FeedetlSn
  1813. label.PProjectId = p.ID
  1814. label.ItemId = p.TeamId
  1815. label.ProjectName = project.ProjectName
  1816. label.PatientName = patient.Name
  1817. service.CreateHisLabelRecord(&label)
  1818. }
  1819. }
  1820. }
  1821. }
  1822. service.SaveHisProjectTwo(&p)
  1823. }
  1824. }
  1825. }
  1826. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  1827. // addition := items["addition"].([]interface{})
  1828. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1829. // ctime := time.Now().Unix()
  1830. // mtime := ctime
  1831. // if len(addition) > 0 {
  1832. // for _, item := range addition {
  1833. // var s models.HisAdditionalCharge
  1834. // s.PrescriptionId = tempPrescription.ID
  1835. // s.Status = 1
  1836. // s.UserOrgId = adminInfo.CurrentOrgId
  1837. // s.RecordDate = recordDateTime
  1838. // s.CreatedTime = ctime
  1839. // s.UpdatedTime = mtime
  1840. // s.PatientId = patient_id
  1841. // s.HisPatientId = his_patient_id
  1842. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  1843. // if errcode > 0 {
  1844. // c.ServeFailJSONWithSGJErrorCode(errcode)
  1845. // return
  1846. // }
  1847. // service.CreateAdditionalCharge(&s)
  1848. // var randNum int
  1849. // randNum = rand.Intn(10000) + 1000
  1850. // timestamp := time.Now().Unix()
  1851. // tempTime := time.Unix(timestamp, 0)
  1852. // timeFormat := tempTime.Format("20060102150405")
  1853. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  1854. // service.CreateAdditionalCharge(&s)
  1855. //
  1856. // }
  1857. // }
  1858. //}
  1859. }
  1860. }
  1861. //查询今日该患者开的药品处方
  1862. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  1863. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1864. //药品出库
  1865. if drugOutConfig.IsOpen == 1 {
  1866. for _, item := range hisdoctorlist {
  1867. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  1868. // 查询该药品最后一次出库记录
  1869. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  1870. if len(druginfo) > 0 {
  1871. //回退库存
  1872. for _, it := range druginfo {
  1873. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  1874. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  1875. }
  1876. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  1877. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  1878. }
  1879. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  1880. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  1881. }
  1882. }
  1883. }
  1884. //删除记录
  1885. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  1886. //查询最后一次数据
  1887. if drugOutConfig.IsOpen == 1 {
  1888. //出库
  1889. if drug.IsUse == 2 {
  1890. creater := adminInfo.AdminUser.Id
  1891. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  1892. }
  1893. //更新字典里面的库存
  1894. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1895. var sum_count int64
  1896. for _, its := range stockInfo {
  1897. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  1898. if its.MaxUnit == baseDrug.MaxUnit {
  1899. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  1900. }
  1901. sum_count += its.StockMaxNumber + its.StockMinNumber
  1902. }
  1903. //更新基础库存
  1904. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1905. //剩余库存
  1906. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  1907. }
  1908. }
  1909. }
  1910. //耗材保存处方出库
  1911. if goodOutConfig.IsOpen == 1 {
  1912. //查询今日耗材出库数量
  1913. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  1914. for _, item := range hisgoodlist {
  1915. //查询耗材最后一次出库记录
  1916. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  1917. if len(wareOut) > 0 {
  1918. for _, it := range wareOut {
  1919. //回退库存
  1920. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  1921. //删除出库记录
  1922. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  1923. }
  1924. }
  1925. timeStr := time.Now().Format("2006-01-02")
  1926. timeArr := strings.Split(timeStr, "-")
  1927. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  1928. total = total + 1
  1929. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1930. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1931. number = number + total
  1932. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1933. operation_time := time.Now().Unix()
  1934. creater := c.GetAdminUserInfo().AdminUser.Id
  1935. //查询默认出库仓库库存
  1936. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1937. recordDateStr := time.Now().Format("2006-01-02")
  1938. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1939. nowtime := recordDate.Unix()
  1940. warehouseOut := models.WarehouseOut{
  1941. WarehouseOutOrderNumber: warehousing_out_order,
  1942. OperationTime: operation_time,
  1943. OrgId: adminInfo.CurrentOrgId,
  1944. Creater: creater,
  1945. Ctime: time.Now().Unix(),
  1946. Status: 1,
  1947. WarehouseOutTime: nowtime,
  1948. Type: 1,
  1949. StorehouseId: storeConfig.StorehouseOutInfo,
  1950. IsCheck: 1,
  1951. IsSys: 1,
  1952. }
  1953. //查询是否生成出库单
  1954. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  1955. if out.ID == 0 {
  1956. service.AddSigleWarehouseOut(&warehouseOut)
  1957. }
  1958. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  1959. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  1960. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  1961. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  1962. dialyPrepareOne := models.DialysisBeforePrepare{
  1963. GoodTypeId: goodObj.GoodTypeId,
  1964. GoodId: item.ProjectId,
  1965. PatientId: item.PatientId,
  1966. RecordDate: item.RecordDate,
  1967. UserOrgId: adminInfo.CurrentOrgId,
  1968. Count: parseIntCount,
  1969. Ctime: time.Now().Unix(),
  1970. Creater: creater,
  1971. Status: 1,
  1972. StorehouseId: houseConfig.StorehouseOutInfo,
  1973. ProjectId: item.ID,
  1974. }
  1975. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater)
  1976. //查询剩余库存
  1977. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId)
  1978. var sum_count int64
  1979. for _, item := range goodList {
  1980. sum_count += item.StockCount
  1981. }
  1982. //更新剩余库存
  1983. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  1984. //耗材
  1985. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  1986. }
  1987. }
  1988. }
  1989. //redisClient := service.RedisClient()
  1990. //defer redisClient.Close()
  1991. //
  1992. //list := models.HisList{
  1993. // Patient_id: patient_id,
  1994. // Advice_id:0,
  1995. // Record_date: 0,
  1996. // Advice: adviceList,
  1997. // Project: nil,
  1998. //}
  1999. //hisLis = append(hisLis, list)
  2000. //
  2001. //advice_json, _ := json.Marshal(&hisLis)
  2002. //redisClient.RPush("111", advice_json).Result()
  2003. //result, _ := redisClient.RPop("111").Result()
  2004. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  2005. //
  2006. //var dat []map[string]interface{}
  2007. //json.Unmarshal([]byte(result), &dat)
  2008. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  2009. //
  2010. //for k,v:=range dat{
  2011. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  2012. //}
  2013. //project_json, _ := json.Marshal(&projectList)
  2014. //redisClient.LPush("222", project_json).Result()
  2015. if err == nil {
  2016. c.ServeSuccessJSON(map[string]interface{}{
  2017. "msg": "保存成功",
  2018. })
  2019. return
  2020. } else {
  2021. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2022. return
  2023. }
  2024. }
  2025. func (c *HisApiController) EditHisPrescription() {
  2026. record_date := c.GetString("record_date")
  2027. patient_id, _ := c.GetInt64("patient_id")
  2028. reg_type, _ := c.GetInt64("reg_type")
  2029. //diagnose, _ := c.GetInt64("diagnose", 0)
  2030. diagnose := c.GetString("diagnose")
  2031. sick_type, _ := c.GetInt64("sick_type")
  2032. sick_history := c.GetString("sick_history")
  2033. doctor_id, _ := c.GetInt64("doctor", 0)
  2034. department, _ := c.GetInt64("department", 0)
  2035. his_patient_id, _ := c.GetInt64("his_patient_id")
  2036. p_type, _ := c.GetInt64("p_type")
  2037. dataBody := make(map[string]interface{}, 0)
  2038. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2039. if err != nil {
  2040. utils.ErrorLog(err.Error())
  2041. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2042. return
  2043. }
  2044. timeLayout := "2006-01-02"
  2045. loc, _ := time.LoadLocation("Local")
  2046. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2047. if err != nil {
  2048. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2049. return
  2050. }
  2051. adminInfo := c.GetAdminUserInfo()
  2052. recordDateTime := theTime.Unix()
  2053. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  2054. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2055. var hpInfo models.HisPrescriptionInfo
  2056. if info.ID == 0 {
  2057. var randNum int
  2058. randNum = rand.Intn(10000) + 1000
  2059. timestamp := time.Now().Unix()
  2060. tempTime := time.Unix(timestamp, 0)
  2061. timeFormat := tempTime.Format("20060102150405")
  2062. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2063. hpInfo = models.HisPrescriptionInfo{
  2064. UserOrgId: adminInfo.CurrentOrgId,
  2065. RecordDate: theTime.Unix(),
  2066. PatientId: patient_id,
  2067. Status: 1,
  2068. Ctime: time.Now().Unix(),
  2069. Mtime: time.Now().Unix(),
  2070. Creator: adminInfo.AdminUser.Id,
  2071. Modifier: adminInfo.AdminUser.Id,
  2072. Diagnosis: diagnose,
  2073. SickHistory: sick_history,
  2074. Departments: department,
  2075. RegisterType: reg_type,
  2076. PrescriptionNumber: p_number,
  2077. PrescriptionStatus: 1,
  2078. Doctor: role.UserName,
  2079. DoctorId: doctor_id,
  2080. SickType: sick_type,
  2081. PType: p_type,
  2082. }
  2083. service.SavePatientPrescriptionInfo(hpInfo)
  2084. } else {
  2085. hpInfo = models.HisPrescriptionInfo{
  2086. ID: info.ID,
  2087. UserOrgId: adminInfo.CurrentOrgId,
  2088. RecordDate: info.RecordDate,
  2089. PatientId: info.PatientId,
  2090. Status: 1,
  2091. Ctime: info.Ctime,
  2092. Mtime: time.Now().Unix(),
  2093. Creator: info.Creator,
  2094. Modifier: adminInfo.AdminUser.Id,
  2095. Diagnosis: diagnose,
  2096. SickHistory: sick_history,
  2097. Departments: department,
  2098. RegisterType: reg_type,
  2099. PrescriptionNumber: info.PrescriptionNumber,
  2100. Doctor: role.UserName,
  2101. PrescriptionStatus: info.PrescriptionStatus,
  2102. DoctorId: doctor_id,
  2103. SickType: sick_type,
  2104. PType: info.PType,
  2105. }
  2106. service.SavePatientPrescriptionInfo(hpInfo)
  2107. }
  2108. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2109. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2110. if len(prescriptions) > 0 {
  2111. for _, item := range prescriptions {
  2112. items := item.(map[string]interface{})
  2113. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2114. utils.ErrorLog("id")
  2115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2116. return
  2117. }
  2118. id := int64(items["id"].(float64))
  2119. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2120. utils.ErrorLog("type")
  2121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2122. return
  2123. }
  2124. types := int64(items["type"].(float64))
  2125. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2126. utils.ErrorLog("med_type")
  2127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2128. return
  2129. }
  2130. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2131. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  2132. ctime := time.Now().Unix()
  2133. prescription := &models.HisPrescription{
  2134. ID: id,
  2135. PatientId: patient_id,
  2136. UserOrgId: adminInfo.CurrentOrgId,
  2137. RecordDate: recordDateTime,
  2138. Ctime: ctime,
  2139. Mtime: ctime,
  2140. Type: types,
  2141. Modifier: adminInfo.AdminUser.Id,
  2142. Creator: adminInfo.AdminUser.Id,
  2143. Status: 1,
  2144. Doctor: role.UserName,
  2145. HisPatientId: his_patient_id,
  2146. OrderStatus: 1,
  2147. BatchNumber: "",
  2148. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2149. PType: hpInfo.PType,
  2150. MedType: med_type,
  2151. }
  2152. if historyPrescription.ID > 0 {
  2153. prescription.PreTime = historyPrescription.PreTime
  2154. }
  2155. service.SaveHisPrescription(prescription)
  2156. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2157. advices := items["advices"].([]interface{})
  2158. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2159. groupNo := int64(0)
  2160. ctime := time.Now().Unix()
  2161. mtime := ctime
  2162. if len(advices) > 0 {
  2163. for _, advice := range advices {
  2164. var s models.HisDoctorAdviceInfo
  2165. s.PrescriptionId = prescription.ID
  2166. s.AdviceType = 2
  2167. s.AdviceDoctor = adminInfo.AdminUser.Id
  2168. s.StopState = 2
  2169. s.ExecutionState = 2
  2170. s.AdviceDate = recordDateTime
  2171. s.Status = 1
  2172. s.UserOrgId = adminInfo.CurrentOrgId
  2173. s.RecordDate = recordDateTime
  2174. s.StartTime = prescription.PreTime
  2175. s.Groupno = groupNo
  2176. s.CreatedTime = ctime
  2177. s.UpdatedTime = mtime
  2178. s.PatientId = patient_id
  2179. s.HisPatientId = his_patient_id
  2180. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  2181. if errcode > 0 {
  2182. c.ServeFailJSONWithSGJErrorCode(errcode)
  2183. return
  2184. }
  2185. service.CreateHisDoctorAdvice(&s)
  2186. redis := service.RedisClient()
  2187. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2188. redis.Set(key, "", time.Second)
  2189. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2190. fmt.Println("keyOne", keyOne)
  2191. redis.Set(keyOne, "", time.Second)
  2192. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2193. redis.Set(keySeven, "", time.Second)
  2194. redis.Close()
  2195. }
  2196. }
  2197. }
  2198. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2199. projects := items["project"].([]interface{})
  2200. if len(projects) > 0 {
  2201. for _, project := range projects {
  2202. var p models.HisPrescriptionProject
  2203. p.PrescriptionId = prescription.ID
  2204. p.Ctime = time.Now().Unix()
  2205. p.Mtime = time.Now().Unix()
  2206. p.PatientId = patient_id
  2207. p.RecordDate = recordDateTime
  2208. p.UserOrgId = adminInfo.CurrentOrgId
  2209. p.HisPatientId = his_patient_id
  2210. p.Status = 1
  2211. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  2212. if errcode > 0 {
  2213. c.ServeFailJSONWithSGJErrorCode(errcode)
  2214. return
  2215. }
  2216. service.CreateHisProjectTwo(&p)
  2217. }
  2218. }
  2219. }
  2220. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2221. addition := items["addition"].([]interface{})
  2222. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2223. ctime := time.Now().Unix()
  2224. mtime := ctime
  2225. if len(addition) > 0 {
  2226. for _, item := range addition {
  2227. var s models.HisAdditionalCharge
  2228. s.PrescriptionId = prescription.ID
  2229. s.Status = 1
  2230. s.UserOrgId = adminInfo.CurrentOrgId
  2231. s.RecordDate = recordDateTime
  2232. s.CreatedTime = ctime
  2233. s.UpdatedTime = mtime
  2234. s.PatientId = patient_id
  2235. s.HisPatientId = his_patient_id
  2236. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  2237. if errcode > 0 {
  2238. c.ServeFailJSONWithSGJErrorCode(errcode)
  2239. return
  2240. }
  2241. service.CreateAdditionalCharge(&s)
  2242. }
  2243. }
  2244. }
  2245. }
  2246. }
  2247. }
  2248. if err == nil {
  2249. c.ServeSuccessJSON(map[string]interface{}{
  2250. "msg": "保存成功",
  2251. })
  2252. return
  2253. } else {
  2254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2255. return
  2256. }
  2257. }
  2258. func (c *HisApiController) DeletePrescription() {
  2259. prescription_id, _ := c.GetInt64("id")
  2260. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  2261. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  2262. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2263. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2264. //耗材保存处方出库
  2265. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  2266. //已收费和已发药限制逻辑
  2267. isCharge := false
  2268. isMedicine := false
  2269. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  2270. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  2271. for _, item := range new_prescriptions {
  2272. if item.IsMedicine == 1 {
  2273. isMedicine = true
  2274. }
  2275. }
  2276. for _, item := range new_prescriptions {
  2277. if item.OrderStatus == 4 {
  2278. isCharge = true
  2279. }
  2280. }
  2281. if p_err != nil {
  2282. if new_prescription.ID > 0 {
  2283. if new_prescription.OrderStatus == 2 {
  2284. isCharge = true
  2285. }
  2286. }
  2287. }
  2288. for _, item := range advices {
  2289. if item.IsMedicine == 1 {
  2290. isMedicine = true
  2291. }
  2292. }
  2293. if isCharge {
  2294. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  2295. return
  2296. }
  2297. if isMedicine {
  2298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  2299. return
  2300. }
  2301. //已收费和已发药限制逻辑
  2302. if len(projects) > 0 {
  2303. for _, item := range projects {
  2304. service.DeletePrintInfo(item.ID) //删除打印信息
  2305. if goodOutConfig.IsOpen != 1 {
  2306. if stockConfig.IsOpen == 1 {
  2307. if item.Type == 3 && item.IsOut == 1 {
  2308. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  2309. f_count, _ := strconv.ParseFloat(item.Count, 64)
  2310. good.Total = good.Total + f_count
  2311. service.UpdateGoodInfo(&good)
  2312. operation_time := time.Now().Unix()
  2313. creater := c.GetAdminUserInfo().AdminUser.Id
  2314. //创建退库单
  2315. timeStr := time.Now().Format("2006-01-02")
  2316. timeArr := strings.Split(timeStr, "-")
  2317. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  2318. total = total + 1
  2319. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2320. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  2321. cancelStock := models.CancelStock{
  2322. OrderNumber: orderNumber,
  2323. OperaTime: operation_time,
  2324. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2325. Creater: creater,
  2326. Ctime: time.Now().Unix(),
  2327. Status: 1,
  2328. ReturnTime: item.RecordDate,
  2329. Type: 1,
  2330. StorehouseId: houseConfig.StorehouseOutInfo,
  2331. IsCheck: 1,
  2332. }
  2333. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  2334. if msgerrkonde == gorm.ErrRecordNotFound {
  2335. service.AddSigleCancelStock(&cancelStock)
  2336. }
  2337. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  2338. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  2339. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2340. //查询该耗材是否出库
  2341. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  2342. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  2343. deaerler, _ := service.GetDealerById(info.Dealer)
  2344. var total_count int64
  2345. count, _ := strconv.ParseInt(item.Count, 10, 64)
  2346. total_count += count
  2347. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  2348. var flush_count int64
  2349. for _, it := range goodList {
  2350. flush_count += it.StockCount
  2351. }
  2352. if info.ID > 0 {
  2353. if info.Count >= total_count {
  2354. //回退库存
  2355. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  2356. cancelStockInfo := models.CancelStockInfo{
  2357. GoodId: item.ProjectId,
  2358. CancelStockId: cancel.ID,
  2359. GoodTypeId: good.GoodTypeId,
  2360. Count: prescribingNumber,
  2361. Price: info.Price,
  2362. Total: 0,
  2363. ProductDate: info.ProductDate,
  2364. ExpiryDate: info.ExpiryDate,
  2365. Ctime: time.Now().Unix(),
  2366. Status: 1,
  2367. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2368. OrderNumber: cancel.OrderNumber,
  2369. Type: 0,
  2370. Dealer: deaerler.DealerName,
  2371. Manufacturer: manufacturer.ManufacturerName,
  2372. Number: info.Number,
  2373. RegisterAccount: "",
  2374. Remark: "",
  2375. WarehouseInfoId: info.WarehouseInfotId,
  2376. PatientId: info.PatientId,
  2377. RecordDate: info.SysRecordTime,
  2378. StorehouseId: houseConfig.StorehouseOutInfo,
  2379. IsCheck: 1,
  2380. }
  2381. service.CreateCancelStockInfoOne(&cancelStockInfo)
  2382. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  2383. flow := models.VmStockFlow{
  2384. WarehousingId: info.WarehouseInfotId,
  2385. GoodId: item.ProjectId,
  2386. Number: info.Number,
  2387. LicenseNumber: info.LicenseNumber,
  2388. Count: prescribingNumber,
  2389. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2390. PatientId: item.PatientId,
  2391. SystemTime: info.SysRecordTime,
  2392. ConsumableType: 7,
  2393. IsSys: 0,
  2394. WarehousingOrder: "",
  2395. WarehouseOutId: info.WarehouseOutId,
  2396. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2397. IsEdit: 0,
  2398. CancelStockId: cancel.ID,
  2399. CancelOrderNumber: cancel.OrderNumber,
  2400. Manufacturer: manufacturer.ID,
  2401. Dealer: 0,
  2402. Creator: c.GetAdminUserInfo().CurrentOrgId,
  2403. UpdateCreator: 0,
  2404. Status: 1,
  2405. Ctime: time.Now().Unix(),
  2406. Mtime: 0,
  2407. Price: info.Price,
  2408. WarehousingDetailId: info.WarehouseInfotId,
  2409. WarehouseOutDetailId: info.ID,
  2410. CancelOutDetailId: cancelInfo.ID,
  2411. ProductDate: info.ProductDate,
  2412. ExpireDate: info.ExpiryDate,
  2413. StorehouseId: houseConfig.StorehouseOutInfo,
  2414. OverCount: flush_count,
  2415. }
  2416. service.CreateStockFlowOne(flow)
  2417. //退库数量增加
  2418. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  2419. //出库数量减少
  2420. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  2421. }
  2422. if info.Count < total_count {
  2423. //回退库存
  2424. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  2425. cancelStockInfo := models.CancelStockInfo{
  2426. GoodId: item.ProjectId,
  2427. CancelStockId: cancel.ID,
  2428. GoodTypeId: good.GoodTypeId,
  2429. Count: info.Count,
  2430. Price: info.Price,
  2431. Total: 0,
  2432. ProductDate: info.ProductDate,
  2433. ExpiryDate: info.ExpiryDate,
  2434. Ctime: time.Now().Unix(),
  2435. Status: 1,
  2436. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2437. OrderNumber: cancel.OrderNumber,
  2438. Type: 0,
  2439. Dealer: deaerler.DealerName,
  2440. Manufacturer: manufacturer.ManufacturerName,
  2441. Number: info.Number,
  2442. RegisterAccount: "",
  2443. Remark: "",
  2444. WarehouseInfoId: info.WarehouseInfotId,
  2445. PatientId: info.PatientId,
  2446. RecordDate: info.SysRecordTime,
  2447. StorehouseId: houseConfig.StorehouseOutInfo,
  2448. IsCheck: 1,
  2449. }
  2450. service.CreateCancelStockInfoOne(&cancelStockInfo)
  2451. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  2452. flow := models.VmStockFlow{
  2453. WarehousingId: info.WarehouseInfotId,
  2454. GoodId: item.ProjectId,
  2455. Number: info.Number,
  2456. LicenseNumber: info.LicenseNumber,
  2457. Count: info.Count,
  2458. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2459. PatientId: item.PatientId,
  2460. SystemTime: info.SysRecordTime,
  2461. ConsumableType: 7,
  2462. IsSys: 0,
  2463. WarehousingOrder: "",
  2464. WarehouseOutId: info.WarehouseOutId,
  2465. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2466. IsEdit: 0,
  2467. CancelStockId: cancel.ID,
  2468. CancelOrderNumber: cancel.OrderNumber,
  2469. Manufacturer: manufacturer.ID,
  2470. Dealer: 0,
  2471. Creator: c.GetAdminUserInfo().CurrentOrgId,
  2472. UpdateCreator: 0,
  2473. Status: 1,
  2474. Ctime: time.Now().Unix(),
  2475. Mtime: 0,
  2476. Price: info.Price,
  2477. WarehousingDetailId: info.WarehouseInfotId,
  2478. WarehouseOutDetailId: info.ID,
  2479. CancelOutDetailId: cancelInfo.ID,
  2480. ProductDate: info.ProductDate,
  2481. ExpireDate: info.ExpiryDate,
  2482. StorehouseId: houseConfig.StorehouseOutInfo,
  2483. OverCount: flush_count,
  2484. }
  2485. service.CreateStockFlowOne(flow)
  2486. //退库数量增加
  2487. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  2488. //出库数量减少
  2489. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  2490. }
  2491. //查询已出库数量
  2492. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  2493. if prescribingNumber < dialysisInfo.Count {
  2494. //改变数量
  2495. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  2496. }
  2497. if prescribingNumber >= dialysisInfo.Count {
  2498. //删除出库表
  2499. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  2500. }
  2501. //更新库存
  2502. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  2503. //更新基础库库存
  2504. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  2505. //查询今日该耗材退库数量
  2506. //cancelInfoOne, _ := service.GetCancelStockInfoByPatientId(info.PatientId, item.ProjectId, info.SysRecordTime)
  2507. //var cancel_Count int64
  2508. //for _, items := range cancelInfoOne {
  2509. // cancel_Count += items.Count
  2510. //}
  2511. //
  2512. //cha_count = total_count - cancel_Count
  2513. //
  2514. //if total_count > cancel_Count {
  2515. //
  2516. // out, err := service.FindStockOutByIsSys(c.GetAdminUserInfo().CurrentOrgId, 1, info.SysRecordTime)
  2517. // if err == gorm.ErrRecordNotFound {
  2518. // //没有记录,则创建出库单
  2519. // timeStr := time.Now().Format("2006-01-02")
  2520. // timeArr := strings.Split(timeStr, "-")
  2521. // total, _ := service.FindAllWarehouseOut(c.GetAdminUserInfo().CurrentOrgId)
  2522. // total = total + 1
  2523. // warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2524. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2525. // number = number + total
  2526. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2527. // warehouseOut := models.WarehouseOut{
  2528. // WarehouseOutOrderNumber: warehousing_out_order,
  2529. // OperationTime: time.Now().Unix(),
  2530. // OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2531. // Creater: creater,
  2532. // Ctime: time.Now().Unix(),
  2533. // Status: 1,
  2534. // WarehouseOutTime: info.SysRecordTime,
  2535. // Dealer: 0,
  2536. // Manufacturer: 0,
  2537. // Type: 1,
  2538. // IsSys: 1,
  2539. // StorehouseId: houseConfig.StorehouseOutInfo,
  2540. // IsCheck: 1,
  2541. // }
  2542. // err := service.AddSigleWarehouseOut(&warehouseOut)
  2543. // if err != nil {
  2544. // utils.TraceLog("创建出库单失败 err = %v", err)
  2545. // return
  2546. // }
  2547. // prepare := &models.DialysisBeforePrepare{
  2548. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2549. // PatientId: info.PatientId,
  2550. // RecordDate: info.SysRecordTime,
  2551. // GoodId: item.ProjectId,
  2552. // GoodTypeId: info.GoodTypeId,
  2553. // Count: cha_count,
  2554. // StorehouseId: houseConfig.StorehouseOutInfo,
  2555. // }
  2556. // //出库
  2557. // service.ConsumablesDelivery(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &warehouseOut, cha_count)
  2558. // } else if err == nil {
  2559. //
  2560. // prepare := &models.DialysisBeforePrepare{
  2561. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2562. // PatientId: info.PatientId,
  2563. // RecordDate: info.SysRecordTime,
  2564. // GoodId: item.ProjectId,
  2565. // GoodTypeId: info.GoodTypeId,
  2566. // Count: cha_count,
  2567. // StorehouseId: houseConfig.StorehouseOutInfo,
  2568. // }
  2569. // //出库
  2570. // service.ConsumablesDelivery(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &out, cha_count)
  2571. // }
  2572. //
  2573. //}
  2574. }
  2575. }
  2576. }
  2577. }
  2578. fmt.Println("goodOutConfig.IsOpen23232332233232232323232323", goodOutConfig.IsOpen)
  2579. //保存耗材出库
  2580. if goodOutConfig.IsOpen == 1 {
  2581. if item.Type == 3 {
  2582. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  2583. f_count, _ := strconv.ParseFloat(item.Count, 64)
  2584. good.Total = good.Total + f_count
  2585. service.UpdateGoodInfo(&good)
  2586. operation_time := time.Now().Unix()
  2587. creater := c.GetAdminUserInfo().AdminUser.Id
  2588. //创建退库单
  2589. timeStr := time.Now().Format("2006-01-02")
  2590. timeArr := strings.Split(timeStr, "-")
  2591. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  2592. total = total + 1
  2593. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2594. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  2595. cancelStock := models.CancelStock{
  2596. OrderNumber: orderNumber,
  2597. OperaTime: operation_time,
  2598. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2599. Creater: creater,
  2600. Ctime: time.Now().Unix(),
  2601. Status: 1,
  2602. ReturnTime: item.RecordDate,
  2603. Type: 1,
  2604. StorehouseId: houseConfig.StorehouseOutInfo,
  2605. IsCheck: 1,
  2606. }
  2607. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  2608. if msgerrkonde == gorm.ErrRecordNotFound {
  2609. service.AddSigleCancelStock(&cancelStock)
  2610. }
  2611. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  2612. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  2613. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2614. //查询该耗材是否出库
  2615. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  2616. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  2617. deaerler, _ := service.GetDealerById(info.Dealer)
  2618. var total_count int64
  2619. count, _ := strconv.ParseInt(item.Count, 10, 64)
  2620. total_count += count
  2621. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  2622. var flush_count int64
  2623. for _, it := range goodList {
  2624. flush_count += it.StockCount
  2625. }
  2626. fmt.Println("nfo.Count342232332323223232323", info.Count)
  2627. fmt.Println("total_count0999923923932923", total_count)
  2628. if info.ID > 0 {
  2629. if info.Count >= total_count {
  2630. //回退库存
  2631. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  2632. cancelStockInfo := models.CancelStockInfo{
  2633. GoodId: item.ProjectId,
  2634. CancelStockId: cancel.ID,
  2635. GoodTypeId: good.GoodTypeId,
  2636. Count: prescribingNumber,
  2637. Price: info.Price,
  2638. Total: 0,
  2639. ProductDate: info.ProductDate,
  2640. ExpiryDate: info.ExpiryDate,
  2641. Ctime: time.Now().Unix(),
  2642. Status: 1,
  2643. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2644. OrderNumber: cancel.OrderNumber,
  2645. Type: 0,
  2646. Dealer: deaerler.DealerName,
  2647. Manufacturer: manufacturer.ManufacturerName,
  2648. Number: info.Number,
  2649. RegisterAccount: "",
  2650. Remark: "",
  2651. WarehouseInfoId: info.WarehouseInfotId,
  2652. PatientId: info.PatientId,
  2653. RecordDate: info.SysRecordTime,
  2654. StorehouseId: houseConfig.StorehouseOutInfo,
  2655. IsCheck: 1,
  2656. }
  2657. service.CreateCancelStockInfoOne(&cancelStockInfo)
  2658. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  2659. flow := models.VmStockFlow{
  2660. WarehousingId: info.WarehouseInfotId,
  2661. GoodId: item.ProjectId,
  2662. Number: info.Number,
  2663. LicenseNumber: info.LicenseNumber,
  2664. Count: prescribingNumber,
  2665. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2666. PatientId: item.PatientId,
  2667. SystemTime: info.SysRecordTime,
  2668. ConsumableType: 7,
  2669. IsSys: 0,
  2670. WarehousingOrder: "",
  2671. WarehouseOutId: info.WarehouseOutId,
  2672. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2673. IsEdit: 0,
  2674. CancelStockId: cancel.ID,
  2675. CancelOrderNumber: cancel.OrderNumber,
  2676. Manufacturer: manufacturer.ID,
  2677. Dealer: 0,
  2678. Creator: c.GetAdminUserInfo().CurrentOrgId,
  2679. UpdateCreator: 0,
  2680. Status: 1,
  2681. Ctime: time.Now().Unix(),
  2682. Mtime: 0,
  2683. Price: info.Price,
  2684. WarehousingDetailId: info.WarehouseInfotId,
  2685. WarehouseOutDetailId: info.ID,
  2686. CancelOutDetailId: cancelInfo.ID,
  2687. ProductDate: info.ProductDate,
  2688. ExpireDate: info.ExpiryDate,
  2689. StorehouseId: houseConfig.StorehouseOutInfo,
  2690. OverCount: flush_count,
  2691. }
  2692. service.CreateStockFlowOne(flow)
  2693. //退库数量增加
  2694. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  2695. //出库数量减少
  2696. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  2697. }
  2698. if info.Count < total_count {
  2699. //回退库存
  2700. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  2701. cancelStockInfo := models.CancelStockInfo{
  2702. GoodId: item.ProjectId,
  2703. CancelStockId: cancel.ID,
  2704. GoodTypeId: good.GoodTypeId,
  2705. Count: info.Count,
  2706. Price: info.Price,
  2707. Total: 0,
  2708. ProductDate: info.ProductDate,
  2709. ExpiryDate: info.ExpiryDate,
  2710. Ctime: time.Now().Unix(),
  2711. Status: 1,
  2712. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2713. OrderNumber: cancel.OrderNumber,
  2714. Type: 0,
  2715. Dealer: deaerler.DealerName,
  2716. Manufacturer: manufacturer.ManufacturerName,
  2717. Number: info.Number,
  2718. RegisterAccount: "",
  2719. Remark: "",
  2720. WarehouseInfoId: info.WarehouseInfotId,
  2721. PatientId: info.PatientId,
  2722. RecordDate: info.SysRecordTime,
  2723. StorehouseId: houseConfig.StorehouseOutInfo,
  2724. IsCheck: 1,
  2725. }
  2726. service.CreateCancelStockInfoOne(&cancelStockInfo)
  2727. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  2728. flow := models.VmStockFlow{
  2729. WarehousingId: info.WarehouseInfotId,
  2730. GoodId: item.ProjectId,
  2731. Number: info.Number,
  2732. LicenseNumber: info.LicenseNumber,
  2733. Count: info.Count,
  2734. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2735. PatientId: item.PatientId,
  2736. SystemTime: info.SysRecordTime,
  2737. ConsumableType: 7,
  2738. IsSys: 0,
  2739. WarehousingOrder: "",
  2740. WarehouseOutId: info.WarehouseOutId,
  2741. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2742. IsEdit: 0,
  2743. CancelStockId: cancel.ID,
  2744. CancelOrderNumber: cancel.OrderNumber,
  2745. Manufacturer: manufacturer.ID,
  2746. Dealer: 0,
  2747. Creator: c.GetAdminUserInfo().CurrentOrgId,
  2748. UpdateCreator: 0,
  2749. Status: 1,
  2750. Ctime: time.Now().Unix(),
  2751. Mtime: 0,
  2752. Price: info.Price,
  2753. WarehousingDetailId: info.WarehouseInfotId,
  2754. WarehouseOutDetailId: info.ID,
  2755. CancelOutDetailId: cancelInfo.ID,
  2756. ProductDate: info.ProductDate,
  2757. ExpireDate: info.ExpiryDate,
  2758. StorehouseId: houseConfig.StorehouseOutInfo,
  2759. OverCount: flush_count,
  2760. }
  2761. service.CreateStockFlowOne(flow)
  2762. //退库数量增加
  2763. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  2764. //出库数量减少
  2765. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  2766. }
  2767. //查询已出库数量
  2768. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  2769. if prescribingNumber < dialysisInfo.Count {
  2770. //改变数量
  2771. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  2772. }
  2773. if prescribingNumber >= dialysisInfo.Count {
  2774. //删除出库表
  2775. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  2776. }
  2777. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  2778. var flush_count_one int64
  2779. for _, it := range goodList {
  2780. flush_count_one += it.StockCount
  2781. }
  2782. //更新库存
  2783. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  2784. fmt.Println("msgerrkonde23332323", msgerrkonde)
  2785. //更新基础库库存
  2786. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  2787. }
  2788. }
  2789. }
  2790. }
  2791. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  2792. fmt.Println(err)
  2793. }
  2794. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  2795. fmt.Println(err)
  2796. if len(advices) > 0 {
  2797. for _, item := range advices {
  2798. redis := service.RedisClient()
  2799. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2800. redis.Set(keyFive, "", time.Second)
  2801. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2802. redis.Set(keyOne, "", time.Second)
  2803. redis.Close()
  2804. }
  2805. }
  2806. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  2807. if len(advices) > 0 {
  2808. for _, item := range advices {
  2809. creater := c.GetAdminUserInfo().AdminUser.Id
  2810. service.DrugAutoAddCancelInfo(item, creater)
  2811. }
  2812. }
  2813. } else {
  2814. if drugStockConfig.IsOpen == 1 {
  2815. if len(advices) > 0 {
  2816. for _, item := range advices {
  2817. creater := c.GetAdminUserInfo().AdminUser.Id
  2818. service.DrugAutoAddCancelInfo(item, creater)
  2819. }
  2820. }
  2821. }
  2822. }
  2823. c.ServeSuccessJSON(map[string]interface{}{
  2824. "msg": "删除成功",
  2825. })
  2826. return
  2827. }
  2828. func (c *HisApiController) DeleteDoctorAdvice() {
  2829. id, _ := c.GetInt64("id")
  2830. advice, _ := service.GetHisDoctorAdvicesById(id)
  2831. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2832. //已收费和已发药的限制逻辑
  2833. isCharge := false
  2834. isMedicine := false
  2835. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  2836. //获取今天该患者所有处方,判断是否发药或者收费
  2837. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  2838. for _, item := range new_prescriptions {
  2839. if item.IsMedicine == 1 {
  2840. isMedicine = true
  2841. }
  2842. }
  2843. for _, item := range new_prescriptions {
  2844. if item.OrderStatus == 4 {
  2845. isCharge = true
  2846. }
  2847. }
  2848. if isMedicine {
  2849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  2850. return
  2851. }
  2852. if isCharge {
  2853. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  2854. return
  2855. }
  2856. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  2857. for _, item := range advices {
  2858. if item.IsMedicine == 1 {
  2859. isMedicine = true
  2860. }
  2861. }
  2862. if isMedicine {
  2863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  2864. return
  2865. }
  2866. if new_prescription.ID > 0 {
  2867. if new_prescription.OrderStatus == 2 {
  2868. isCharge = true
  2869. }
  2870. }
  2871. if isCharge {
  2872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  2873. return
  2874. }
  2875. //已收费和已发药的限制逻辑
  2876. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  2877. redis := service.RedisClient()
  2878. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2879. redis.Set(keyFive, "", time.Second)
  2880. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2881. redis.Set(keyOne, "", time.Second)
  2882. defer redis.Close()
  2883. if err == nil {
  2884. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  2885. //查询是否在处方中出库
  2886. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  2887. if openConfig.IsOpen != 1 {
  2888. //判断该医嘱是否执行了
  2889. if advice.ExecutionState == 1 {
  2890. creater := c.GetAdminUserInfo().AdminUser.Id
  2891. service.DrugAutoAddCancelInfo(&advice, creater)
  2892. }
  2893. }
  2894. //开启保存处方扣减功能
  2895. if openConfig.IsOpen == 1 {
  2896. creater := c.GetAdminUserInfo().AdminUser.Id
  2897. service.DrugAutoAddCancelInfo(&advice, creater)
  2898. }
  2899. } else {
  2900. if drugStockConfig.IsOpen == 1 {
  2901. //查询是否在处方中出库
  2902. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  2903. if openConfig.IsOpen != 1 {
  2904. //判断该医嘱是否执行了
  2905. if advice.ExecutionState == 1 {
  2906. creater := c.GetAdminUserInfo().AdminUser.Id
  2907. service.DrugAutoAddCancelInfo(&advice, creater)
  2908. }
  2909. }
  2910. //开启保存处方扣减功能
  2911. if openConfig.IsOpen == 1 {
  2912. creater := c.GetAdminUserInfo().AdminUser.Id
  2913. service.DrugAutoAddCancelInfo(&advice, creater)
  2914. }
  2915. }
  2916. }
  2917. c.ServeSuccessJSON(map[string]interface{}{
  2918. "msg": "删除成功",
  2919. })
  2920. return
  2921. } else {
  2922. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2923. return
  2924. }
  2925. }
  2926. func (c *HisApiController) DeleteProject() {
  2927. id, _ := c.GetInt64("id")
  2928. adminInfo := c.GetAdminUserInfo()
  2929. project, _ := service.GetHisProjectByID(id)
  2930. // var consumable models.DialysisBeforePrepare
  2931. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2932. //耗材保存处方出库
  2933. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  2934. isCharge := false
  2935. isMedicine := false
  2936. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  2937. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  2938. for _, item := range new_prescriptions {
  2939. if item.IsMedicine == 1 {
  2940. isMedicine = true
  2941. }
  2942. }
  2943. for _, item := range new_prescriptions {
  2944. if item.OrderStatus == 4 {
  2945. isCharge = true
  2946. }
  2947. }
  2948. if isMedicine {
  2949. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  2950. return
  2951. }
  2952. if isCharge {
  2953. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  2954. return
  2955. }
  2956. if new_prescription.ID > 0 {
  2957. if new_prescription.OrderStatus == 2 {
  2958. isCharge = true
  2959. }
  2960. }
  2961. if isCharge {
  2962. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  2963. return
  2964. }
  2965. service.DeletePrintInfo(id)
  2966. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  2967. label.Status = 0
  2968. service.CreateHisLabelRecord(&label)
  2969. if goodOutConfig.IsOpen != 1 {
  2970. if stockConfig.IsOpen == 1 {
  2971. if project.Type == 2 {
  2972. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  2973. fmt.Println(err)
  2974. }
  2975. if project.Type == 3 && project.IsOut == 1 {
  2976. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  2977. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  2978. f_count, _ := strconv.ParseFloat(project.Count, 64)
  2979. operation_time := time.Now().Unix()
  2980. creater := adminInfo.AdminUser.Id
  2981. //创建退库单
  2982. timeStr := time.Now().Format("2006-01-02")
  2983. timeArr := strings.Split(timeStr, "-")
  2984. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  2985. total = total + 1
  2986. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2987. cancelStock := models.CancelStock{
  2988. OrderNumber: orderNumber,
  2989. OperaTime: operation_time,
  2990. OrgId: adminInfo.CurrentOrgId,
  2991. Creater: creater,
  2992. Ctime: time.Now().Unix(),
  2993. Status: 1,
  2994. ReturnTime: project.RecordDate,
  2995. Type: 1,
  2996. StorehouseId: houseConfig.StorehouseOutInfo,
  2997. IsCheck: 1,
  2998. }
  2999. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  3000. if msgerrkonde == gorm.ErrRecordNotFound {
  3001. service.AddSigleCancelStock(&cancelStock)
  3002. }
  3003. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  3004. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3005. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3006. //获取出库数据
  3007. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  3008. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3009. deaerler, _ := service.GetDealerById(info.Dealer)
  3010. if info.ID > 0 {
  3011. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  3012. if info.Count >= prescribingNumber {
  3013. cancelStockInfo := models.CancelStockInfo{
  3014. GoodId: project.ProjectId,
  3015. CancelStockId: cancel.ID,
  3016. GoodTypeId: good.GoodTypeId,
  3017. Count: prescribingNumber,
  3018. Price: info.Price,
  3019. Total: 0,
  3020. ProductDate: info.ProductDate,
  3021. ExpiryDate: info.ExpiryDate,
  3022. Ctime: time.Now().Unix(),
  3023. Status: 1,
  3024. OrgId: adminInfo.CurrentOrgId,
  3025. OrderNumber: cancel.OrderNumber,
  3026. Type: 0,
  3027. Dealer: deaerler.DealerName,
  3028. Manufacturer: manufacturer.ManufacturerName,
  3029. Number: info.Number,
  3030. RegisterAccount: "",
  3031. Remark: "",
  3032. WarehouseInfoId: info.WarehouseInfotId,
  3033. PatientId: info.PatientId,
  3034. RecordDate: info.SysRecordTime,
  3035. StorehouseId: houseConfig.StorehouseOutInfo,
  3036. IsCheck: 1,
  3037. }
  3038. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3039. //回退库存
  3040. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  3041. //退库数量增加
  3042. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  3043. //出库数量减少
  3044. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  3045. }
  3046. if info.Count < prescribingNumber {
  3047. cancelStockInfo := models.CancelStockInfo{
  3048. GoodId: project.ProjectId,
  3049. CancelStockId: cancel.ID,
  3050. GoodTypeId: good.GoodTypeId,
  3051. Count: info.Count,
  3052. Price: info.Price,
  3053. Total: 0,
  3054. ProductDate: info.ProductDate,
  3055. ExpiryDate: info.ExpiryDate,
  3056. Ctime: time.Now().Unix(),
  3057. Status: 1,
  3058. OrgId: adminInfo.CurrentOrgId,
  3059. OrderNumber: cancel.OrderNumber,
  3060. Type: 0,
  3061. Dealer: deaerler.DealerName,
  3062. Manufacturer: manufacturer.ManufacturerName,
  3063. Number: info.Number,
  3064. RegisterAccount: "",
  3065. Remark: "",
  3066. WarehouseInfoId: info.WarehouseInfotId,
  3067. PatientId: info.PatientId,
  3068. RecordDate: info.SysRecordTime,
  3069. StorehouseId: houseConfig.StorehouseOutInfo,
  3070. IsCheck: 1,
  3071. }
  3072. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3073. //回退库存
  3074. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  3075. //退库数量增加
  3076. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3077. //出库数量减少
  3078. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  3079. }
  3080. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3081. var over_count int64
  3082. for _, it := range goodList {
  3083. over_count += it.StockCount
  3084. }
  3085. if info.Count >= prescribingNumber {
  3086. flow := models.VmStockFlow{
  3087. WarehousingId: info.WarehouseInfotId,
  3088. GoodId: project.ProjectId,
  3089. Number: info.Number,
  3090. LicenseNumber: info.LicenseNumber,
  3091. Count: prescribingNumber,
  3092. UserOrgId: adminInfo.CurrentOrgId,
  3093. PatientId: project.PatientId,
  3094. SystemTime: info.SysRecordTime,
  3095. ConsumableType: 7,
  3096. IsSys: 0,
  3097. WarehousingOrder: "",
  3098. WarehouseOutId: info.WarehouseOutId,
  3099. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3100. IsEdit: 0,
  3101. CancelStockId: cancel.ID,
  3102. CancelOrderNumber: cancel.OrderNumber,
  3103. Manufacturer: manufacturer.ID,
  3104. Dealer: 0,
  3105. Creator: adminInfo.AdminUser.Id,
  3106. UpdateCreator: 0,
  3107. Status: 1,
  3108. Ctime: time.Now().Unix(),
  3109. Mtime: 0,
  3110. Price: info.Price,
  3111. WarehousingDetailId: info.WarehouseInfotId,
  3112. WarehouseOutDetailId: info.ID,
  3113. CancelOutDetailId: cancelInfo.ID,
  3114. ProductDate: info.ProductDate,
  3115. ExpireDate: info.ExpiryDate,
  3116. StorehouseId: houseConfig.StorehouseOutInfo,
  3117. OverCount: over_count,
  3118. }
  3119. service.CreateStockFlowOne(flow)
  3120. }
  3121. if info.Count < prescribingNumber {
  3122. flow := models.VmStockFlow{
  3123. WarehousingId: info.WarehouseInfotId,
  3124. GoodId: project.ProjectId,
  3125. Number: info.Number,
  3126. LicenseNumber: info.LicenseNumber,
  3127. Count: info.Count,
  3128. UserOrgId: adminInfo.CurrentOrgId,
  3129. PatientId: project.PatientId,
  3130. SystemTime: info.SysRecordTime,
  3131. ConsumableType: 7,
  3132. IsSys: 0,
  3133. WarehousingOrder: "",
  3134. WarehouseOutId: info.WarehouseOutId,
  3135. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3136. IsEdit: 0,
  3137. CancelStockId: cancel.ID,
  3138. CancelOrderNumber: cancel.OrderNumber,
  3139. Manufacturer: manufacturer.ID,
  3140. Dealer: 0,
  3141. Creator: adminInfo.AdminUser.Id,
  3142. UpdateCreator: 0,
  3143. Status: 1,
  3144. Ctime: time.Now().Unix(),
  3145. Mtime: 0,
  3146. Price: info.Price,
  3147. WarehousingDetailId: info.WarehouseInfotId,
  3148. WarehouseOutDetailId: info.ID,
  3149. CancelOutDetailId: cancelInfo.ID,
  3150. ProductDate: info.ProductDate,
  3151. ExpireDate: info.ExpiryDate,
  3152. StorehouseId: houseConfig.StorehouseOutInfo,
  3153. OverCount: over_count,
  3154. }
  3155. service.CreateStockFlowOne(flow)
  3156. }
  3157. //查询已出库数量
  3158. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  3159. if prescribingNumber < dialysisInfo.Count {
  3160. //改变数量
  3161. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  3162. }
  3163. if prescribingNumber >= dialysisInfo.Count {
  3164. //删除出库表
  3165. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  3166. }
  3167. //更新剩余库存
  3168. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  3169. //查询今日该患者开了多少耗材
  3170. //projectList, _ := service.GetHisPrepscritionByPatientId(info.PatientId, project.ProjectId, info.SysRecordTime)
  3171. //
  3172. //var total_count int64
  3173. //var cha_count int64
  3174. //for _, item := range projectList {
  3175. // count, _ := strconv.ParseInt(item.Count, 10, 64)
  3176. // total_count += count
  3177. //}
  3178. //
  3179. ////查询今日该耗材退库数量
  3180. //cancelInfoOne, _ := service.GetCancelStockInfoByPatientId(info.PatientId, project.ProjectId, info.SysRecordTime)
  3181. //var cancel_count int64
  3182. //for _, items := range cancelInfoOne {
  3183. // cancel_count += items.Count
  3184. //}
  3185. //
  3186. //cha_count = total_count - cancel_count
  3187. //
  3188. //if total_count > cancel_count {
  3189. //
  3190. // out, err := service.FindStockOutByIsSys(adminInfo.CurrentOrgId, 1, info.SysRecordTime)
  3191. // if err == gorm.ErrRecordNotFound {
  3192. // //没有记录,则创建出库单
  3193. // timeStr := time.Now().Format("2006-01-02")
  3194. // timeArr := strings.Split(timeStr, "-")
  3195. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3196. // total = total + 1
  3197. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3198. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3199. // number = number + total
  3200. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3201. // warehouseOut := models.WarehouseOut{
  3202. // WarehouseOutOrderNumber: warehousing_out_order,
  3203. // OperationTime: time.Now().Unix(),
  3204. // OrgId: adminInfo.CurrentOrgId,
  3205. // Creater: creater,
  3206. // Ctime: time.Now().Unix(),
  3207. // Status: 1,
  3208. // WarehouseOutTime: info.SysRecordTime,
  3209. // Dealer: 0,
  3210. // Manufacturer: 0,
  3211. // Type: 1,
  3212. // IsSys: 1,
  3213. // StorehouseId: houseConfig.StorehouseOutInfo,
  3214. // }
  3215. // err := service.AddSigleWarehouseOut(&warehouseOut)
  3216. // if err != nil {
  3217. // utils.TraceLog("创建出库单失败 err = %v", err)
  3218. // return
  3219. // }
  3220. // prepare := &models.DialysisBeforePrepare{
  3221. // UserOrgId: adminInfo.CurrentOrgId,
  3222. // PatientId: info.PatientId,
  3223. // RecordDate: info.SysRecordTime,
  3224. // GoodId: project.ProjectId,
  3225. // GoodTypeId: info.GoodTypeId,
  3226. // Count: cha_count,
  3227. // StorehouseId: houseConfig.StorehouseOutInfo,
  3228. // }
  3229. // //出库
  3230. // service.ConsumablesDelivery(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &warehouseOut, cha_count)
  3231. // } else if err == nil {
  3232. // prepare := &models.DialysisBeforePrepare{
  3233. // UserOrgId: adminInfo.CurrentOrgId,
  3234. // PatientId: info.PatientId,
  3235. // RecordDate: info.SysRecordTime,
  3236. // GoodId: project.ProjectId,
  3237. // GoodTypeId: info.GoodTypeId,
  3238. // Count: cha_count,
  3239. // StorehouseId: houseConfig.StorehouseOutInfo,
  3240. // }
  3241. // //出库
  3242. // service.ConsumablesDelivery(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &out, cha_count)
  3243. // }
  3244. //
  3245. //}
  3246. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  3247. var total_count_one int64
  3248. for _, it := range stockList {
  3249. total_count_one += it.StockCount
  3250. }
  3251. //基础库插入数据
  3252. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  3253. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3254. var flush_count int64
  3255. for _, it := range goodListOne {
  3256. flush_count += it.StockCount
  3257. }
  3258. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  3259. if errs != nil {
  3260. goodErrcode := models.XtGoodErrcode{
  3261. UserOrgId: project.UserOrgId,
  3262. Errcode: "手动出库更新剩余出库失败",
  3263. GoodId: project.ProjectId,
  3264. Status: 1,
  3265. Ctime: time.Now().Unix(),
  3266. Mtime: 0,
  3267. Count: 0,
  3268. StockCount: 0,
  3269. Creater: creater,
  3270. BatchNumberId: 0,
  3271. WarehouseOutId: 0,
  3272. }
  3273. service.CreateGoodErrcode(goodErrcode)
  3274. }
  3275. }
  3276. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3277. fmt.Println(err)
  3278. } else {
  3279. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3280. fmt.Println(err)
  3281. }
  3282. }
  3283. }
  3284. if goodOutConfig.IsOpen == 1 {
  3285. if project.Type == 3 {
  3286. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3287. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3288. f_count, _ := strconv.ParseFloat(project.Count, 64)
  3289. operation_time := time.Now().Unix()
  3290. creater := adminInfo.AdminUser.Id
  3291. //创建退库单
  3292. timeStr := time.Now().Format("2006-01-02")
  3293. timeArr := strings.Split(timeStr, "-")
  3294. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  3295. total = total + 1
  3296. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3297. cancelStock := models.CancelStock{
  3298. OrderNumber: orderNumber,
  3299. OperaTime: operation_time,
  3300. OrgId: adminInfo.CurrentOrgId,
  3301. Creater: creater,
  3302. Ctime: time.Now().Unix(),
  3303. Status: 1,
  3304. ReturnTime: project.RecordDate,
  3305. Type: 1,
  3306. StorehouseId: houseConfig.StorehouseOutInfo,
  3307. IsCheck: 1,
  3308. }
  3309. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  3310. if msgerrkonde == gorm.ErrRecordNotFound {
  3311. service.AddSigleCancelStock(&cancelStock)
  3312. }
  3313. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  3314. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3315. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3316. //获取出库数据
  3317. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  3318. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3319. deaerler, _ := service.GetDealerById(info.Dealer)
  3320. if info.ID > 0 {
  3321. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  3322. if info.Count >= prescribingNumber {
  3323. cancelStockInfo := models.CancelStockInfo{
  3324. GoodId: project.ProjectId,
  3325. CancelStockId: cancel.ID,
  3326. GoodTypeId: good.GoodTypeId,
  3327. Count: prescribingNumber,
  3328. Price: info.Price,
  3329. Total: 0,
  3330. ProductDate: info.ProductDate,
  3331. ExpiryDate: info.ExpiryDate,
  3332. Ctime: time.Now().Unix(),
  3333. Status: 1,
  3334. OrgId: adminInfo.CurrentOrgId,
  3335. OrderNumber: cancel.OrderNumber,
  3336. Type: 0,
  3337. Dealer: deaerler.DealerName,
  3338. Manufacturer: manufacturer.ManufacturerName,
  3339. Number: info.Number,
  3340. RegisterAccount: "",
  3341. Remark: "",
  3342. WarehouseInfoId: info.WarehouseInfotId,
  3343. PatientId: info.PatientId,
  3344. RecordDate: info.SysRecordTime,
  3345. StorehouseId: houseConfig.StorehouseOutInfo,
  3346. IsCheck: 1,
  3347. }
  3348. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3349. //回退库存
  3350. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  3351. //退库数量增加
  3352. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  3353. //出库数量减少
  3354. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  3355. }
  3356. if info.Count < prescribingNumber {
  3357. cancelStockInfo := models.CancelStockInfo{
  3358. GoodId: project.ProjectId,
  3359. CancelStockId: cancel.ID,
  3360. GoodTypeId: good.GoodTypeId,
  3361. Count: info.Count,
  3362. Price: info.Price,
  3363. Total: 0,
  3364. ProductDate: info.ProductDate,
  3365. ExpiryDate: info.ExpiryDate,
  3366. Ctime: time.Now().Unix(),
  3367. Status: 1,
  3368. OrgId: adminInfo.CurrentOrgId,
  3369. OrderNumber: cancel.OrderNumber,
  3370. Type: 0,
  3371. Dealer: deaerler.DealerName,
  3372. Manufacturer: manufacturer.ManufacturerName,
  3373. Number: info.Number,
  3374. RegisterAccount: "",
  3375. Remark: "",
  3376. WarehouseInfoId: info.WarehouseInfotId,
  3377. PatientId: info.PatientId,
  3378. RecordDate: info.SysRecordTime,
  3379. StorehouseId: houseConfig.StorehouseOutInfo,
  3380. IsCheck: 1,
  3381. }
  3382. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3383. //回退库存
  3384. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  3385. //退库数量增加
  3386. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3387. //出库数量减少
  3388. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  3389. }
  3390. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3391. var over_count int64
  3392. for _, it := range goodList {
  3393. over_count += it.StockCount
  3394. }
  3395. if info.Count >= prescribingNumber {
  3396. flow := models.VmStockFlow{
  3397. WarehousingId: info.WarehouseInfotId,
  3398. GoodId: project.ProjectId,
  3399. Number: info.Number,
  3400. LicenseNumber: info.LicenseNumber,
  3401. Count: prescribingNumber,
  3402. UserOrgId: adminInfo.CurrentOrgId,
  3403. PatientId: project.PatientId,
  3404. SystemTime: info.SysRecordTime,
  3405. ConsumableType: 7,
  3406. IsSys: 0,
  3407. WarehousingOrder: "",
  3408. WarehouseOutId: info.WarehouseOutId,
  3409. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3410. IsEdit: 0,
  3411. CancelStockId: cancel.ID,
  3412. CancelOrderNumber: cancel.OrderNumber,
  3413. Manufacturer: manufacturer.ID,
  3414. Dealer: 0,
  3415. Creator: adminInfo.AdminUser.Id,
  3416. UpdateCreator: 0,
  3417. Status: 1,
  3418. Ctime: time.Now().Unix(),
  3419. Mtime: 0,
  3420. Price: info.Price,
  3421. WarehousingDetailId: info.WarehouseInfotId,
  3422. WarehouseOutDetailId: info.ID,
  3423. CancelOutDetailId: cancelInfo.ID,
  3424. ProductDate: info.ProductDate,
  3425. ExpireDate: info.ExpiryDate,
  3426. StorehouseId: houseConfig.StorehouseOutInfo,
  3427. OverCount: over_count,
  3428. }
  3429. service.CreateStockFlowOne(flow)
  3430. }
  3431. if info.Count < prescribingNumber {
  3432. flow := models.VmStockFlow{
  3433. WarehousingId: info.WarehouseInfotId,
  3434. GoodId: project.ProjectId,
  3435. Number: info.Number,
  3436. LicenseNumber: info.LicenseNumber,
  3437. Count: info.Count,
  3438. UserOrgId: adminInfo.CurrentOrgId,
  3439. PatientId: project.PatientId,
  3440. SystemTime: info.SysRecordTime,
  3441. ConsumableType: 7,
  3442. IsSys: 0,
  3443. WarehousingOrder: "",
  3444. WarehouseOutId: info.WarehouseOutId,
  3445. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3446. IsEdit: 0,
  3447. CancelStockId: cancel.ID,
  3448. CancelOrderNumber: cancel.OrderNumber,
  3449. Manufacturer: manufacturer.ID,
  3450. Dealer: 0,
  3451. Creator: adminInfo.AdminUser.Id,
  3452. UpdateCreator: 0,
  3453. Status: 1,
  3454. Ctime: time.Now().Unix(),
  3455. Mtime: 0,
  3456. Price: info.Price,
  3457. WarehousingDetailId: info.WarehouseInfotId,
  3458. WarehouseOutDetailId: info.ID,
  3459. CancelOutDetailId: cancelInfo.ID,
  3460. ProductDate: info.ProductDate,
  3461. ExpireDate: info.ExpiryDate,
  3462. StorehouseId: houseConfig.StorehouseOutInfo,
  3463. OverCount: over_count,
  3464. }
  3465. service.CreateStockFlowOne(flow)
  3466. }
  3467. //查询已出库数量
  3468. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  3469. if prescribingNumber < dialysisInfo.Count {
  3470. //改变数量
  3471. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  3472. }
  3473. if prescribingNumber >= dialysisInfo.Count {
  3474. //删除出库表
  3475. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  3476. }
  3477. //更新剩余库存
  3478. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  3479. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  3480. var total_count_one int64
  3481. for _, it := range stockList {
  3482. total_count_one += it.StockCount
  3483. }
  3484. //基础库插入数据
  3485. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  3486. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3487. var flush_count int64
  3488. for _, it := range goodListOne {
  3489. flush_count += it.StockCount
  3490. }
  3491. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  3492. if errs != nil {
  3493. goodErrcode := models.XtGoodErrcode{
  3494. UserOrgId: project.UserOrgId,
  3495. Errcode: "手动出库更新剩余出库失败",
  3496. GoodId: project.ProjectId,
  3497. Status: 1,
  3498. Ctime: time.Now().Unix(),
  3499. Mtime: 0,
  3500. Count: 0,
  3501. StockCount: 0,
  3502. Creater: creater,
  3503. BatchNumberId: 0,
  3504. WarehouseOutId: 0,
  3505. }
  3506. service.CreateGoodErrcode(goodErrcode)
  3507. }
  3508. }
  3509. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3510. fmt.Println(err)
  3511. } else {
  3512. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3513. fmt.Println(err)
  3514. }
  3515. }
  3516. c.ServeSuccessJSON(map[string]interface{}{
  3517. "msg": "删除成功",
  3518. })
  3519. return
  3520. }
  3521. func (c *HisApiController) CreateHisAdditionalCharge() {
  3522. his_patient_id, _ := c.GetInt64("his_patient_id")
  3523. patient_id, _ := c.GetInt64("patient_id")
  3524. record_date := c.GetString("record_date")
  3525. timeLayout := "2006-01-02"
  3526. loc, _ := time.LoadLocation("Local")
  3527. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3528. if err != nil {
  3529. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3530. return
  3531. }
  3532. adminInfo := c.GetAdminUserInfo()
  3533. recordDateTime := theTime.Unix()
  3534. dataBody := make(map[string]interface{}, 0)
  3535. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3536. if err != nil {
  3537. utils.ErrorLog(err.Error())
  3538. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3539. return
  3540. }
  3541. var additions []*models.HisAdditionalCharge
  3542. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  3543. additions, _ := dataBody["addition"].([]interface{})
  3544. if len(additions) > 0 {
  3545. for _, item := range additions {
  3546. items := item.(map[string]interface{})
  3547. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  3548. utils.ErrorLog("item_id")
  3549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3550. return
  3551. }
  3552. item_id := int64(items["item_id"].(float64))
  3553. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  3554. utils.ErrorLog("item_name")
  3555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3556. return
  3557. }
  3558. item_name := items["item_name"].(string)
  3559. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  3560. utils.ErrorLog("price")
  3561. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3562. return
  3563. }
  3564. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  3565. ctime := time.Now().Unix()
  3566. additional := &models.HisAdditionalCharge{
  3567. PatientId: patient_id,
  3568. HisPatientId: his_patient_id,
  3569. UserOrgId: adminInfo.CurrentOrgId,
  3570. RecordDate: recordDateTime,
  3571. CreatedTime: ctime,
  3572. UpdatedTime: ctime,
  3573. Modifier: adminInfo.AdminUser.Id,
  3574. Creator: adminInfo.AdminUser.Id,
  3575. Price: price,
  3576. ItemName: item_name,
  3577. ItemId: item_id,
  3578. Status: 1,
  3579. }
  3580. additions = append(additions, additional)
  3581. }
  3582. }
  3583. }
  3584. for _, item := range additions {
  3585. service.CreateAddtionalCharge(item)
  3586. }
  3587. c.ServeSuccessJSON(map[string]interface{}{
  3588. "msg": "创建成功",
  3589. })
  3590. }
  3591. func (c *HisApiController) CreateHisPatientCaseHistory() {
  3592. blood_fat := c.GetString("blood_fat")
  3593. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  3594. blood_sugar := c.GetString("blood_sugar")
  3595. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  3596. chief_conplaint := c.GetString("chief_conplaint")
  3597. dbp := c.GetString("dbp")
  3598. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  3599. delivery_way, _ := c.GetInt64("delivery_way")
  3600. diagnostic := c.GetString("diagnostic")
  3601. family_history := c.GetString("family_history")
  3602. height := c.GetString("height")
  3603. history_of_present_illness := c.GetString("history_of_present_illness")
  3604. is_infect, _ := c.GetInt64("is_infect")
  3605. past_history := c.GetString("past_history")
  3606. patient_id, _ := c.GetInt64("patient_id")
  3607. his_patient_id, _ := c.GetInt64("his_patient_id")
  3608. personal_history := c.GetString("personal_history")
  3609. pulse := c.GetString("pulse")
  3610. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  3611. sbp := c.GetString("sbp")
  3612. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  3613. heightfloat, _ := strconv.ParseFloat(height, 64)
  3614. sicktype := c.GetString("sick_type")
  3615. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  3616. symptom := c.GetString("symptom")
  3617. sick_date := c.GetString("sick_date")
  3618. temperatures := c.GetString("temperature")
  3619. temperature, _ := strconv.ParseFloat(temperatures, 64)
  3620. record_date := c.GetString("record_date")
  3621. breathing := c.GetString("breathing")
  3622. doctor_advice := c.GetString("doctor_advice")
  3623. remark := c.GetString("remark")
  3624. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  3625. sick, _ := c.GetInt64("sick")
  3626. diagnose, _ := c.GetInt64("diagnose")
  3627. //id, _ := c.GetInt64("id")
  3628. timeLayout := "2006-01-02"
  3629. loc, _ := time.LoadLocation("Local")
  3630. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3631. allergic_history := c.GetString("allergic_history")
  3632. if err != nil {
  3633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3634. return
  3635. }
  3636. recordDateTime := theTime.Unix()
  3637. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  3638. if err != nil {
  3639. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3640. return
  3641. }
  3642. sickTimes := sickTime.Unix()
  3643. ctime := time.Now().Unix()
  3644. primary_disease := c.GetString("primary_disease")
  3645. confirm_failure_date := c.GetString("confirm_failure_date")
  3646. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  3647. drug_allergy_history := c.GetString("drug_allergy_history")
  3648. physical_examination := c.GetString("physical_examination")
  3649. special_inspection := c.GetString("special_inspection")
  3650. lab_apparatus := c.GetString("lab_apparatus")
  3651. caseHistory := models.HisPatientCaseHistory{
  3652. HisPatientId: his_patient_id,
  3653. PatientId: patient_id,
  3654. Temperature: temperature,
  3655. BloodSugar: bloodsugarfloat,
  3656. Pulse: pulsefloat,
  3657. Sbp: sbpfloat,
  3658. Dbp: dbpfloat,
  3659. Height: heightfloat,
  3660. BloodFat: bloodfatfloat,
  3661. SickType: sick_type,
  3662. Symptom: symptom,
  3663. SickDate: sickTimes,
  3664. IsInfect: is_infect,
  3665. HistoryOfPresentIllness: history_of_present_illness,
  3666. PastHistory: past_history,
  3667. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  3668. ChiefConplaint: chief_conplaint,
  3669. PersonalHistory: personal_history,
  3670. FamilyHistory: family_history,
  3671. Diagnostic: diagnostic,
  3672. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3673. Status: 1,
  3674. Ctime: ctime,
  3675. Mtime: ctime,
  3676. RecordDate: recordDateTime,
  3677. DeliveryWay: delivery_way,
  3678. Breathing: breathingfloat,
  3679. DoctorAdvice: doctor_advice,
  3680. Remark: remark,
  3681. Sick: sick,
  3682. Diagnose: diagnose,
  3683. AllergicHistory: allergic_history,
  3684. PrimaryDisease: primary_disease,
  3685. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  3686. DrugAllergyHistory: drug_allergy_history,
  3687. PhysicalExamination: physical_examination,
  3688. SpecialInspection: special_inspection,
  3689. LabApparatus: lab_apparatus,
  3690. }
  3691. //查询该患者是否有病历
  3692. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  3693. if errcodes == gorm.ErrRecordNotFound {
  3694. err = service.SaveHisPatientCaseHistory(&caseHistory)
  3695. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  3696. if err != nil {
  3697. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  3698. return
  3699. }
  3700. c.ServeSuccessJSON(map[string]interface{}{
  3701. "caseHistory": caseHistory,
  3702. "historyInfo": historyInfo,
  3703. })
  3704. return
  3705. } else if errcodes == nil {
  3706. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  3707. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  3708. if err != nil {
  3709. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  3710. return
  3711. }
  3712. c.ServeSuccessJSON(map[string]interface{}{
  3713. "caseHistory": caseHistory,
  3714. "historyInfo": historyInfo,
  3715. })
  3716. }
  3717. //查询该患者是否有病历
  3718. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  3719. //if errcode == gorm.ErrRecordNotFound {
  3720. // err = service.SaveHisPatientCaseHistory(caseHistory)
  3721. // if err != nil {
  3722. // c.ServeSuccessJSON(map[string]interface{}{
  3723. // "msg": "保存成功",
  3724. // })
  3725. // }
  3726. //} else if errcode == nil {
  3727. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  3728. // return
  3729. //}
  3730. }
  3731. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  3732. patient_id, _ := c.GetInt64("patient_id", 0)
  3733. adminUser := c.GetAdminUserInfo()
  3734. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  3735. c.ServeSuccessJSON(map[string]interface{}{
  3736. "list": caseHistorys,
  3737. })
  3738. }
  3739. func (c *HisApiController) GetHisPatientCaseHistory() {
  3740. record_date, _ := c.GetInt64("record_date", 0)
  3741. patient_id, _ := c.GetInt64("patient_id", 0)
  3742. admin := c.GetAdminUserInfo()
  3743. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  3744. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  3745. c.ServeSuccessJSON(map[string]interface{}{
  3746. "info": info,
  3747. "case_history": case_history,
  3748. })
  3749. }
  3750. func (c *HisApiController) CreateCaseHistoryTemplate() {
  3751. template_name := c.GetString("template_name")
  3752. template_remark := c.GetString("template_remark")
  3753. doctor := c.GetAdminUserInfo().AdminUser.Id
  3754. diagnostic := c.GetString("diagnostic")
  3755. chief_conplaint := c.GetString("chief_conplain")
  3756. history_of_present_illness := c.GetString("history_of_present_illness")
  3757. past_history := c.GetString("past_history")
  3758. personal_history := c.GetString("personal_history")
  3759. family_history := c.GetString("family_history")
  3760. user_name := c.GetString("user_name")
  3761. doctor_advice := c.GetString("doctor_advice")
  3762. remark := c.GetString("remark")
  3763. //record_date := c.GetString("record_date")
  3764. //fmt.Println("record_date--------",record_date)
  3765. //timeLayout := "2006-01-02"
  3766. //loc, _ := time.LoadLocation("Local")
  3767. //
  3768. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3769. //if err != nil {
  3770. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3771. // return
  3772. //}
  3773. //recordDateTime := theTime.Unix()
  3774. ctime := time.Now().Unix()
  3775. template := models.HisCaseHistoryTemplate{
  3776. HistoryOfPresentIllness: history_of_present_illness,
  3777. PastHistory: past_history,
  3778. ChiefConplaint: chief_conplaint,
  3779. PersonalHistory: personal_history,
  3780. FamilyHistory: family_history,
  3781. Diagnostic: diagnostic,
  3782. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3783. Status: 1,
  3784. Ctime: ctime,
  3785. Mtime: ctime,
  3786. RecordDate: time.Now().Unix(),
  3787. TemplateName: template_name,
  3788. TemplateRemark: template_remark,
  3789. Creator: doctor,
  3790. Modifier: doctor,
  3791. UserName: user_name,
  3792. DoctorAdvice: doctor_advice,
  3793. Remark: remark,
  3794. }
  3795. err := service.SaveHisPatientCaseHistoryTemplate(template)
  3796. if err == nil {
  3797. c.ServeSuccessJSON(map[string]interface{}{
  3798. "msg": "保存成功",
  3799. })
  3800. } else {
  3801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3802. return
  3803. }
  3804. }
  3805. func (c *HisApiController) GetCaseHistoryTemplate() {
  3806. timeLayout := "2006-01-02"
  3807. loc, _ := time.LoadLocation("Local")
  3808. keyword := c.GetString("keyword")
  3809. start_time := c.GetString("start_time")
  3810. end_time := c.GetString("end_time")
  3811. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3812. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3813. admin := c.GetAdminUserInfo()
  3814. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  3815. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  3816. c.ServeSuccessJSON(map[string]interface{}{
  3817. "template": template,
  3818. //"history": history,
  3819. })
  3820. }
  3821. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  3822. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  3823. utils.ErrorLog("drug_name")
  3824. return enums.ErrorCodeParamWrong
  3825. }
  3826. adviceName, _ := json["drug_name"].(string)
  3827. if len(adviceName) == 0 {
  3828. utils.ErrorLog("len(advice_name) == 0")
  3829. return enums.ErrorCodeParamWrong
  3830. }
  3831. advice.AdviceName = adviceName
  3832. adviceDesc, _ := json["advice_desc"].(string)
  3833. advice.AdviceDesc = adviceDesc
  3834. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  3835. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  3836. advice.DrugSpec = drugSpec
  3837. }
  3838. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3839. remark, _ := json["remark"].(string)
  3840. advice.Remark = remark
  3841. }
  3842. if json["id"] == nil {
  3843. advice.DrugId = 0
  3844. } else {
  3845. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3846. drug_id := int64(json["id"].(float64))
  3847. advice.DrugId = drug_id
  3848. }
  3849. }
  3850. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  3851. advice_id := int64(json["advice_id"].(float64))
  3852. advice.ID = advice_id
  3853. if advice.ID > 0 {
  3854. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  3855. if err == nil {
  3856. if hisAdvice.ID > 0 {
  3857. advice.ExecutionTime = hisAdvice.ExecutionTime
  3858. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  3859. advice.ExecutionState = hisAdvice.ExecutionState
  3860. advice.CheckTime = hisAdvice.CheckTime
  3861. advice.Checker = hisAdvice.Checker
  3862. advice.CheckState = hisAdvice.CheckState
  3863. advice.StartTime = hisAdvice.StartTime
  3864. advice.FeedetlSn = hisAdvice.FeedetlSn
  3865. }
  3866. }
  3867. }
  3868. }
  3869. //
  3870. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  3871. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  3872. // advice.ExecutionTime = execution_time
  3873. //}
  3874. //
  3875. //
  3876. //
  3877. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  3878. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  3879. // advice.ExecutionStaff = execution_staff
  3880. //}
  3881. //
  3882. //
  3883. //
  3884. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  3885. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  3886. // advice.ExecutionState = execution_state
  3887. //}
  3888. //
  3889. //
  3890. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  3891. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  3892. // advice.CheckTime = check_time
  3893. //}
  3894. //
  3895. //
  3896. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  3897. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  3898. // advice.CheckState = check_state
  3899. //}
  3900. //
  3901. //
  3902. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  3903. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  3904. // advice.Checker = checker
  3905. //}
  3906. //
  3907. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  3908. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  3909. // advice.StartTime = start_time
  3910. //}
  3911. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  3912. drugSpecUnit, _ := json["min_unit"].(string)
  3913. advice.DrugSpecUnit = drugSpecUnit
  3914. }
  3915. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3916. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3917. advice.SingleDose = singleDose
  3918. }
  3919. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3920. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3921. advice.SingleDoseUnit = singleDoseUnit
  3922. }
  3923. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3924. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3925. advice.PrescribingNumber = prescribingNumber
  3926. }
  3927. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3928. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3929. advice.PrescribingNumberUnit = prescribingNumberUnit
  3930. }
  3931. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3932. deliveryWay, _ := json["delivery_way"].(string)
  3933. advice.DeliveryWay = deliveryWay
  3934. }
  3935. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3936. executionFrequency, _ := json["execution_frequency"].(string)
  3937. advice.ExecutionFrequency = executionFrequency
  3938. }
  3939. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  3940. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  3941. advice.Price = price
  3942. }
  3943. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  3944. med_list_codg, _ := json["medical_insurance_number"].(string)
  3945. advice.MedListCodg = med_list_codg
  3946. }
  3947. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  3948. day := int64(json["day"].(float64))
  3949. advice.Day = day
  3950. }
  3951. return 0
  3952. }
  3953. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  3954. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3955. id := int64(json["id"].(float64))
  3956. project.ID = id
  3957. historyProject, _ := service.GetHisProjectByID(id)
  3958. project.FeedetlSn = historyProject.FeedetlSn
  3959. }
  3960. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  3961. project_id := int64(json["project_id"].(float64))
  3962. project.ProjectId = project_id
  3963. }
  3964. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3965. // price := int64(json["price"].(float64))
  3966. // formatInt_price := strconv.FormatInt(price, 10)
  3967. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3968. // project.Price = float_price
  3969. // }
  3970. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3971. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3972. project.Price = price
  3973. }
  3974. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  3975. total, _ := json["total"].(string)
  3976. project.Count = total
  3977. }
  3978. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  3979. medical_code, _ := json["medical_code"].(string)
  3980. project.MedListCodg = medical_code
  3981. }
  3982. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3983. single_dose, _ := json["single_dose"].(string)
  3984. project.SingleDose = single_dose
  3985. }
  3986. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3987. delivery_way, _ := json["delivery_way"].(string)
  3988. project.DeliveryWay = delivery_way
  3989. }
  3990. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3991. execution_frequency, _ := json["execution_frequency"].(string)
  3992. project.ExecutionFrequency = execution_frequency
  3993. }
  3994. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3995. remark, _ := json["remark"].(string)
  3996. project.Remark = remark
  3997. }
  3998. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  3999. day, _ := json["number_days"].(string)
  4000. project.Day = day
  4001. }
  4002. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  4003. unit, _ := json["unit"].(string)
  4004. project.Unit = unit
  4005. }
  4006. return 0
  4007. }
  4008. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  4009. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4010. id := int64(json["id"].(float64))
  4011. historyAddtions, _ := service.GetHisAdditionByID(id)
  4012. additionalCharge.ID = id
  4013. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  4014. }
  4015. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  4016. item_id := int64(json["item_id"].(float64))
  4017. additionalCharge.ItemId = item_id
  4018. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  4019. if config.ID > 0 {
  4020. if len(config.Code) > 0 {
  4021. additionalCharge.MedListCodg = config.Code
  4022. }
  4023. }
  4024. }
  4025. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4026. // price := int64(json["price"].(float64))
  4027. // formatInt_price := strconv.FormatInt(price, 10)
  4028. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4029. // additionalCharge.Price = float_price
  4030. // }
  4031. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4032. // price := int64(json["price"].(float64))
  4033. // formatInt_price := strconv.FormatInt(price, 10)
  4034. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4035. // additionalCharge.Price = float_price
  4036. //}
  4037. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4038. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4039. additionalCharge.Price = price
  4040. }
  4041. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  4042. count, _ := json["count"].(string)
  4043. counts, _ := strconv.ParseInt(count, 10, 64)
  4044. additionalCharge.Count = counts
  4045. }
  4046. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  4047. item_name, _ := json["item_name"].(string)
  4048. additionalCharge.ItemName = item_name
  4049. }
  4050. return 0
  4051. }
  4052. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4053. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4054. utils.ErrorLog("drug_name")
  4055. return enums.ErrorCodeParamWrong
  4056. }
  4057. adviceName, _ := json["drug_name"].(string)
  4058. if len(adviceName) == 0 {
  4059. utils.ErrorLog("len(advice_name) == 0")
  4060. return enums.ErrorCodeParamWrong
  4061. }
  4062. advice.AdviceName = adviceName
  4063. adviceDesc, _ := json["advice_desc"].(string)
  4064. advice.AdviceDesc = adviceDesc
  4065. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4066. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4067. advice.DrugSpec = drugSpec
  4068. }
  4069. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4070. remark, _ := json["remark"].(string)
  4071. advice.Remark = remark
  4072. }
  4073. if json["id"] == nil {
  4074. advice.DrugId = 0
  4075. } else {
  4076. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4077. drug_id := int64(json["id"].(float64))
  4078. advice.DrugId = drug_id
  4079. }
  4080. }
  4081. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  4082. groupno := int64(json["groupno"].(float64))
  4083. advice.Groupno = groupno
  4084. }
  4085. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  4086. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  4087. advice.HospApprFlag = hosp_appr_flag
  4088. }
  4089. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4090. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4091. advice.PrescribingNumber = prescribingNumber
  4092. }
  4093. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  4094. // frequency_type := int64(json["frequency_type"].(float64))
  4095. // advice.FrequencyType = frequency_type
  4096. //}
  4097. //
  4098. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  4099. // day_count := int64(json["day_count"].(float64))
  4100. // advice.DayCount = day_count
  4101. //}
  4102. //
  4103. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  4104. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  4105. // week_day, _ := json["week_day"].(string)
  4106. // advice.WeekDay = week_day
  4107. //}
  4108. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4109. drugSpecUnit, _ := json["min_unit"].(string)
  4110. advice.DrugSpecUnit = drugSpecUnit
  4111. }
  4112. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4113. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4114. advice.SingleDose = singleDose
  4115. }
  4116. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4117. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4118. advice.SingleDoseUnit = singleDoseUnit
  4119. }
  4120. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4121. deliveryWay, _ := json["delivery_way"].(string)
  4122. advice.DeliveryWay = deliveryWay
  4123. }
  4124. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4125. executionFrequency, _ := json["execution_frequency"].(string)
  4126. advice.ExecutionFrequency = executionFrequency
  4127. }
  4128. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4129. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4130. advice.Price = price
  4131. }
  4132. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4133. med_list_codg, _ := json["medical_insurance_number"].(string)
  4134. advice.MedListCodg = med_list_codg
  4135. }
  4136. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4137. day := int64(json["day"].(float64))
  4138. advice.Day = day
  4139. }
  4140. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4141. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4142. advice.PrescribingNumberUnit = prescribingNumberUnit
  4143. }
  4144. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4145. advice_id := int64(json["advice_id"].(float64))
  4146. advice.ID = advice_id
  4147. if advice.ID > 0 {
  4148. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4149. if err == nil {
  4150. if hisAdvice.ID > 0 {
  4151. advice.ExecutionTime = hisAdvice.ExecutionTime
  4152. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4153. advice.ExecutionState = hisAdvice.ExecutionState
  4154. advice.CheckTime = hisAdvice.CheckTime
  4155. advice.Checker = hisAdvice.Checker
  4156. advice.CheckState = hisAdvice.CheckState
  4157. advice.StartTime = hisAdvice.StartTime
  4158. advice.HospApprFlag = hisAdvice.HospApprFlag
  4159. advice.IsMedicine = hisAdvice.IsMedicine
  4160. if hisAdvice.UserOrgId == 10028 {
  4161. 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 {
  4162. advice.ExecutionTime = 0
  4163. advice.ExecutionStaff = 0
  4164. advice.ExecutionState = 2
  4165. advice.CheckTime = 0
  4166. advice.Checker = 0
  4167. advice.CheckState = 2
  4168. }
  4169. } else {
  4170. 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 {
  4171. advice.ExecutionTime = 0
  4172. advice.ExecutionStaff = 0
  4173. advice.ExecutionState = 2
  4174. advice.CheckTime = 0
  4175. advice.Checker = 0
  4176. advice.CheckState = 2
  4177. }
  4178. }
  4179. //advice.Groupno = hisAdvice.Groupno
  4180. }
  4181. }
  4182. }
  4183. }
  4184. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  4185. //
  4186. //if drugStockConfig.IsOpen == 1 {
  4187. //
  4188. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  4189. // if advice.ID == 0 { //医嘱不存在
  4190. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  4191. // drug.Total = drug.Total - advice.PrescribingNumber
  4192. // service.UpdateBaseDrugLib(&drug)
  4193. //
  4194. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  4195. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  4196. // drug.Total = drug.Total - num
  4197. // service.UpdateBaseDrugLib(&drug)
  4198. // }
  4199. //
  4200. // } else if advice.ID > 0 { //医嘱存在
  4201. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  4202. // var num float64
  4203. //
  4204. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  4205. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  4206. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  4207. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  4208. // drug.Total = drug.Total + num
  4209. // service.UpdateBaseDrugLib(&drug)
  4210. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  4211. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  4212. // drug.Total = drug.Total - num
  4213. // service.UpdateBaseDrugLib(&drug)
  4214. // }
  4215. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  4216. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  4217. // if num2 > advice.PrescribingNumber {
  4218. // num = num2 - advice.PrescribingNumber
  4219. // drug.Total = drug.Total + num
  4220. // service.UpdateBaseDrugLib(&drug)
  4221. // } else if num2 < advice.PrescribingNumber {
  4222. // num = advice.PrescribingNumber - num2
  4223. // drug.Total = drug.Total - num
  4224. // service.UpdateBaseDrugLib(&drug)
  4225. // }
  4226. //
  4227. // }
  4228. //
  4229. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  4230. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  4231. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  4232. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  4233. // if num1 > num2 {
  4234. // num = num1 - num2
  4235. // drug.Total = drug.Total + num
  4236. // service.UpdateBaseDrugLib(&drug)
  4237. // } else if num1 < num2 {
  4238. // num = num2 - num1
  4239. // drug.Total = drug.Total - num
  4240. // service.UpdateBaseDrugLib(&drug)
  4241. // }
  4242. //
  4243. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  4244. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  4245. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  4246. // if hisAdvice.PrescribingNumber > num2 {
  4247. // num = hisAdvice.PrescribingNumber - num2
  4248. // drug.Total = drug.Total + num
  4249. // service.UpdateBaseDrugLib(&drug)
  4250. // } else if num2 < advice.PrescribingNumber {
  4251. // num = num2 - hisAdvice.PrescribingNumber
  4252. // drug.Total = drug.Total - num
  4253. // service.UpdateBaseDrugLib(&drug)
  4254. // }
  4255. //
  4256. // }
  4257. // }
  4258. // }
  4259. //}
  4260. //
  4261. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4262. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4263. // advice.ExecutionTime = execution_time
  4264. //}
  4265. //
  4266. //
  4267. //
  4268. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  4269. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  4270. // advice.ExecutionStaff = execution_staff
  4271. //}
  4272. //
  4273. //
  4274. //
  4275. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  4276. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  4277. // advice.ExecutionState = execution_state
  4278. //}
  4279. //
  4280. //
  4281. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  4282. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  4283. // advice.CheckTime = check_time
  4284. //}
  4285. //
  4286. //
  4287. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  4288. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  4289. // advice.CheckState = check_state
  4290. //}
  4291. //
  4292. //
  4293. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  4294. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  4295. // advice.Checker = checker
  4296. //}
  4297. //
  4298. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  4299. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  4300. // advice.StartTime = start_time
  4301. //}
  4302. return 0
  4303. }
  4304. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  4305. project.ExecutionStaff = 0
  4306. project.ExecutionState = 2
  4307. project.ExecutionTime = 0
  4308. project.Checker = 0
  4309. project.CheckState = 2
  4310. project.CheckTime = 0
  4311. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4312. id := int64(json["id"].(float64))
  4313. project.ID = id
  4314. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  4315. project.ExecutionStaff = temp_project.ExecutionStaff
  4316. project.ExecutionState = temp_project.ExecutionState
  4317. project.ExecutionTime = temp_project.ExecutionTime
  4318. project.Checker = temp_project.Checker
  4319. project.CheckState = temp_project.CheckState
  4320. project.CheckTime = temp_project.CheckTime
  4321. project.TeamId = temp_project.TeamId
  4322. }
  4323. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  4324. types := int64(json["type"].(float64))
  4325. project.Type = types
  4326. }
  4327. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4328. project_id := int64(json["project_id"].(float64))
  4329. project.ProjectId = project_id
  4330. }
  4331. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  4332. team_id := int64(json["team_id"].(float64))
  4333. project.TeamId = team_id
  4334. }
  4335. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4336. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4337. project.Price = price
  4338. }
  4339. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  4340. total, _ := json["total"].(string)
  4341. //totals, _ := strconv.ParseInt(total, 10, 64)
  4342. project.Count = total
  4343. }
  4344. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  4345. medical_code, _ := json["medical_code"].(string)
  4346. project.MedListCodg = medical_code
  4347. }
  4348. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4349. single_dose, _ := json["single_dose"].(string)
  4350. project.SingleDose = single_dose
  4351. }
  4352. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4353. delivery_way, _ := json["delivery_way"].(string)
  4354. project.DeliveryWay = delivery_way
  4355. }
  4356. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4357. execution_frequency, _ := json["execution_frequency"].(string)
  4358. project.ExecutionFrequency = execution_frequency
  4359. }
  4360. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4361. remark, _ := json["remark"].(string)
  4362. project.Remark = remark
  4363. }
  4364. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  4365. day, _ := json["number_days"].(string)
  4366. project.Day = day
  4367. }
  4368. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  4369. unit, _ := json["unit"].(string)
  4370. project.Unit = unit
  4371. }
  4372. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  4373. // frequency_type := int64(json["frequency_type"].(float64))
  4374. // project.FrequencyType = frequency_type
  4375. //}
  4376. //
  4377. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  4378. // day_count := int64(json["day_count"].(float64))
  4379. // project.DayCount = day_count
  4380. //}
  4381. //
  4382. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  4383. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  4384. // week_day, _ := json["week_day"].(string)
  4385. // project.WeekDay = week_day
  4386. //}
  4387. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  4388. //
  4389. //if project.ID == 0 {
  4390. // if stockConfig.IsOpen == 1 {
  4391. // if project.Type == 3 {
  4392. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4393. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  4394. // good.Total = good.Total - f_count
  4395. // service.UpdateGoodInfo(&good)
  4396. // }
  4397. // }
  4398. //
  4399. //} else {
  4400. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  4401. //
  4402. // if stockConfig.IsOpen == 1 {
  4403. // if project.Type == 3 {
  4404. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4405. // if project.Count < temp_project.Count {
  4406. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  4407. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  4408. //
  4409. // other_count := f_count_two - f_count_one
  4410. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  4411. // good.Total = good.Total + other_count_two
  4412. // service.UpdateGoodInfo(&good)
  4413. // } else if project.Count > temp_project.Count {
  4414. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  4415. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  4416. //
  4417. // other_count := f_count_one - f_count_two
  4418. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  4419. // good.Total = good.Total - other_count_two
  4420. // service.UpdateGoodInfo(&good)
  4421. // }
  4422. //
  4423. // }
  4424. // }
  4425. //
  4426. //}
  4427. return 0
  4428. }
  4429. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  4430. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4431. id := int64(json["id"].(float64))
  4432. additionalCharge.ID = id
  4433. }
  4434. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  4435. item_id := int64(json["item_id"].(float64))
  4436. additionalCharge.ItemId = item_id
  4437. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  4438. if config.ID > 0 {
  4439. if len(config.Code) > 0 {
  4440. additionalCharge.MedListCodg = config.Code
  4441. }
  4442. }
  4443. }
  4444. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4445. // price := int64(json["price"].(float64))
  4446. // formatInt_price := strconv.FormatInt(price, 10)
  4447. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4448. // additionalCharge.Price = float_price
  4449. // }
  4450. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4451. // price := int64(json["price"].(float64))
  4452. // formatInt_price := strconv.FormatInt(price, 10)
  4453. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4454. // additionalCharge.Price = float_price
  4455. //}
  4456. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4457. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4458. additionalCharge.Price = price
  4459. }
  4460. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  4461. count, _ := json["count"].(string)
  4462. counts, _ := strconv.ParseInt(count, 10, 64)
  4463. additionalCharge.Count = counts
  4464. }
  4465. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  4466. item_name, _ := json["item_name"].(string)
  4467. additionalCharge.ItemName = item_name
  4468. }
  4469. return 0
  4470. }
  4471. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  4472. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4473. utils.ErrorLog("drug_name")
  4474. return enums.ErrorCodeParamWrong
  4475. }
  4476. adviceName, _ := json["drug_name"].(string)
  4477. if len(adviceName) == 0 {
  4478. utils.ErrorLog("len(advice_name) == 0")
  4479. return enums.ErrorCodeParamWrong
  4480. }
  4481. advice.AdviceName = adviceName
  4482. adviceDesc, _ := json["advice_desc"].(string)
  4483. advice.AdviceDesc = adviceDesc
  4484. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4485. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4486. advice.DrugSpec = drugSpec
  4487. }
  4488. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4489. remark, _ := json["remark"].(string)
  4490. advice.Remark = remark
  4491. }
  4492. if json["id"] == nil {
  4493. advice.DrugId = 0
  4494. } else {
  4495. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4496. drug_id := int64(json["id"].(float64))
  4497. advice.DrugId = drug_id
  4498. }
  4499. }
  4500. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4501. drugSpecUnit, _ := json["min_unit"].(string)
  4502. advice.DrugSpecUnit = drugSpecUnit
  4503. }
  4504. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4505. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4506. advice.SingleDose = singleDose
  4507. }
  4508. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4509. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4510. advice.SingleDoseUnit = singleDoseUnit
  4511. }
  4512. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4513. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4514. advice.PrescribingNumber = prescribingNumber
  4515. }
  4516. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4517. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4518. advice.PrescribingNumberUnit = prescribingNumberUnit
  4519. }
  4520. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4521. deliveryWay, _ := json["delivery_way"].(string)
  4522. advice.DeliveryWay = deliveryWay
  4523. }
  4524. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4525. executionFrequency, _ := json["execution_frequency"].(string)
  4526. advice.ExecutionFrequency = executionFrequency
  4527. }
  4528. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4529. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4530. advice.Price = price
  4531. }
  4532. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4533. med_list_codg, _ := json["medical_insurance_number"].(string)
  4534. advice.MedListCodg = med_list_codg
  4535. }
  4536. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4537. day := int64(json["day"].(float64))
  4538. advice.Day = day
  4539. }
  4540. return 0
  4541. }
  4542. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  4543. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  4544. types := int64(json["type"].(float64))
  4545. project.Type = types
  4546. }
  4547. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4548. project_id := int64(json["project_id"].(float64))
  4549. project.ProjectId = project_id
  4550. }
  4551. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4552. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4553. project.Price = price
  4554. }
  4555. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  4556. total, _ := json["total"].(string)
  4557. //totals, _ := strconv.ParseInt(total, 10, 64)
  4558. project.Count = total
  4559. }
  4560. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  4561. medical_code, _ := json["medical_code"].(string)
  4562. project.MedListCodg = medical_code
  4563. }
  4564. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4565. single_dose, _ := json["single_dose"].(string)
  4566. project.SingleDose = single_dose
  4567. }
  4568. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4569. delivery_way, _ := json["delivery_way"].(string)
  4570. project.DeliveryWay = delivery_way
  4571. }
  4572. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4573. execution_frequency, _ := json["execution_frequency"].(string)
  4574. project.ExecutionFrequency = execution_frequency
  4575. }
  4576. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4577. remark, _ := json["remark"].(string)
  4578. project.Remark = remark
  4579. }
  4580. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  4581. day, _ := json["number_days"].(string)
  4582. project.Day = day
  4583. }
  4584. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  4585. unit, _ := json["unit"].(string)
  4586. project.Unit = unit
  4587. }
  4588. return 0
  4589. }
  4590. func (c *HisApiController) GetHisOrderList() {
  4591. page, _ := c.GetInt64("page", -1)
  4592. limit, _ := c.GetInt64("limit", -1)
  4593. start_time := c.GetString("start_time")
  4594. end_time := c.GetString("end_time")
  4595. types, _ := c.GetInt64("type", 0)
  4596. keywords := c.GetString("keywords")
  4597. p_type, _ := c.GetInt64("p_type", 0)
  4598. sort_type, _ := c.GetInt64("sort_type", 0)
  4599. charge_type, _ := c.GetInt64("charge_type", 0)
  4600. timeLayout := "2006-01-02"
  4601. loc, _ := time.LoadLocation("Local")
  4602. var startTime int64
  4603. if len(start_time) > 0 {
  4604. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4605. if err != nil {
  4606. //fmt.Println(err)
  4607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4608. return
  4609. }
  4610. startTime = theTime.Unix()
  4611. }
  4612. var endTime int64
  4613. if len(end_time) > 0 {
  4614. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4615. if err != nil {
  4616. utils.ErrorLog(err.Error())
  4617. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4618. return
  4619. }
  4620. endTime = theTime.Unix()
  4621. }
  4622. adminUser := c.GetAdminUserInfo()
  4623. org_id := adminUser.CurrentOrgId
  4624. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time, charge_type)
  4625. for _, item := range order {
  4626. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  4627. item.DoctorName = info.Doctor
  4628. item.DepartmentName = info.XtHisDepartment.Name
  4629. }
  4630. if err == nil {
  4631. c.ServeSuccessJSON(map[string]interface{}{
  4632. "order": order,
  4633. "total": total,
  4634. })
  4635. } else {
  4636. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4637. return
  4638. }
  4639. }
  4640. func (c *HisApiController) GetHisOrder() {
  4641. patient_id, _ := c.GetInt64("patient_id", 0)
  4642. number := c.GetString("number")
  4643. adminInfo := c.GetAdminUserInfo()
  4644. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  4645. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  4646. if err == nil {
  4647. c.ServeSuccessJSON(map[string]interface{}{
  4648. "order": order,
  4649. "prescription": prescriptions,
  4650. })
  4651. } else {
  4652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4653. return
  4654. }
  4655. }
  4656. func (c *HisApiController) GetHisPrescriptionList() {
  4657. record_date := c.GetString("record_date")
  4658. keywords := c.GetString("keywords")
  4659. page, _ := c.GetInt64("page")
  4660. limit, _ := c.GetInt64("limit")
  4661. timeLayout := "2006-01-02"
  4662. loc, _ := time.LoadLocation("Local")
  4663. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4664. if err != nil {
  4665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4666. return
  4667. }
  4668. recordDateTime := theTime.Unix()
  4669. adminInfo := c.GetAdminUserInfo()
  4670. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit)
  4671. //adminInfo := c.GetAdminUserInfo()
  4672. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  4673. //fmt.Println(prescriptionOrder)
  4674. if err == nil {
  4675. c.ServeSuccessJSON(map[string]interface{}{
  4676. "order": prescriptionOrder,
  4677. "total": total,
  4678. })
  4679. } else {
  4680. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4681. return
  4682. }
  4683. }
  4684. func (c *HisApiController) GetHisPrescriptionInfo() {
  4685. id, _ := c.GetInt64("id")
  4686. adminInfo := c.GetAdminUserInfo()
  4687. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  4688. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  4689. if err == nil {
  4690. c.ServeSuccessJSON(map[string]interface{}{
  4691. "order": prescriptionOrder,
  4692. "prescription": prescription,
  4693. })
  4694. } else {
  4695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4696. return
  4697. }
  4698. }
  4699. func (c *HisApiController) GetMedicalInsuranceConfig() {
  4700. adminUser := c.GetAdminUserInfo()
  4701. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4702. c.ServeSuccessJSON(map[string]interface{}{
  4703. "config": config,
  4704. })
  4705. }
  4706. type ResultTwo struct {
  4707. ErrMsg interface{} `json:"err_msg"`
  4708. InfRefmsgid string `json:"inf_refmsgid"`
  4709. Infcode int64 `json:"infcode"`
  4710. Output struct {
  4711. Baseinfo struct {
  4712. Age float64 `json:"age"`
  4713. Brdy string `json:"brdy"`
  4714. Certno string `json:"certno"`
  4715. Gend string `json:"gend"`
  4716. Naty string `json:"naty"`
  4717. PsnCertType string `json:"psn_cert_type"`
  4718. PsnName string `json:"psn_name"`
  4719. PsnNo string `json:"psn_no"`
  4720. } `json:"baseinfo"`
  4721. Idetinfo []interface{} `json:"idetinfo"`
  4722. Iinfo []struct {
  4723. Balc float64 `json:"balc"`
  4724. CvlservFlag string `json:"cvlserv_flag"`
  4725. EmpName string `json:"emp_name"`
  4726. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  4727. Insutype string `json:"insutype"`
  4728. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  4729. PausInsuDate interface{} `json:"paus_insu_date"`
  4730. PsnInsuDate string `json:"psn_insu_date"`
  4731. PsnInsuStas string `json:"psn_insu_stas"`
  4732. PsnType string `json:"psn_type"`
  4733. } `json:"insuinfo"`
  4734. } `json:"output"`
  4735. RefmsgTime string `json:"refmsg_time"`
  4736. RespondTime string `json:"respond_time"`
  4737. Signtype interface{} `json:"signtype"`
  4738. WarnInfo interface{} `json:"warn_info"`
  4739. }
  4740. type ResultThree struct {
  4741. Cainfo interface{} `json:"cainfo"`
  4742. ErrMsg interface{} `json:"err_msg"`
  4743. InfRefmsgid string `json:"inf_refmsgid"`
  4744. Infcode int64 `json:"infcode"`
  4745. Output struct {
  4746. Data struct {
  4747. IptOtpNo string `json:"ipt_otp_no"`
  4748. MdtrtID string `json:"mdtrt_id"`
  4749. PsnNo string `json:"psn_no"`
  4750. } `json:"data"`
  4751. } `json:"output"`
  4752. RefmsgTime string `json:"refmsg_time"`
  4753. RespondTime string `json:"respond_time"`
  4754. Signtype interface{} `json:"signtype"`
  4755. WarnMsg interface{} `json:"warn_msg"`
  4756. }
  4757. type ResultFour struct {
  4758. Cainfo string `json:"cainfo"`
  4759. ErrMsg string `json:"err_msg"`
  4760. InfRefmsgid string `json:"inf_refmsgid"`
  4761. Infcode int64 `json:"infcode"`
  4762. Output struct {
  4763. Result []struct {
  4764. BasMednFlag string `json:"bas_medn_flag"`
  4765. ChldMedcFlag string `json:"chld_medc_flag"`
  4766. ChrgitmLv string `json:"chrgitm_lv"`
  4767. Cnt float64 `json:"cnt"`
  4768. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  4769. DrtReimFlag string `json:"drt_reim_flag"`
  4770. FeedetlSn string `json:"feedetl_sn"`
  4771. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  4772. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  4773. InscpScpAmt float64 `json:"inscp_scp_amt"`
  4774. ListSpItemFlag string `json:"list_sp_item_flag"`
  4775. LmtUsedFlag string `json:"lmt_used_flag"`
  4776. MedChrgitmType string `json:"med_chrgitm_type"`
  4777. Memo string `json:"memo"`
  4778. OverlmtAmt float64 `json:"overlmt_amt"`
  4779. PreselfpayAmt float64 `json:"preselfpay_amt"`
  4780. Pric float64 `json:"pric"`
  4781. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  4782. SelfpayProp float64 `json:"selfpay_prop"`
  4783. } `json:"result"`
  4784. } `json:"output"`
  4785. RefmsgTime string `json:"refmsg_time"`
  4786. RespondTime string `json:"respond_time"`
  4787. Signtype string `json:"signtype"`
  4788. WarnMsg string `json:"warn_msg"`
  4789. }
  4790. type ResultFive struct {
  4791. Insutype string `json:"insutype"`
  4792. }
  4793. type ResultSix struct {
  4794. Cainfo interface{} `json:"cainfo"`
  4795. ErrMsg interface{} `json:"err_msg"`
  4796. InfRefmsgid string `json:"inf_refmsgid"`
  4797. Infcode int64 `json:"infcode"`
  4798. Output struct {
  4799. } `json:"output"`
  4800. RefmsgTime string `json:"refmsg_time"`
  4801. RespondTime string `json:"respond_time"`
  4802. Signtype interface{} `json:"signtype"`
  4803. WarnMsg interface{} `json:"warn_msg"`
  4804. }
  4805. type ResultSeven struct {
  4806. Cainfo string `json:"cainfo"`
  4807. ErrMsg string `json:"err_msg"`
  4808. InfRefmsgid string `json:"inf_refmsgid"`
  4809. Infcode int64 `json:"infcode"`
  4810. Output struct {
  4811. Setldetail []interface{} `json:"setldetail"`
  4812. Setlinfo struct {
  4813. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  4814. AcctPay float64 `json:"acct_pay"`
  4815. ActPayDedc float64 `json:"act_pay_dedc"`
  4816. Age float64 `json:"age"`
  4817. Balc float64 `json:"balc"`
  4818. Brdy string `json:"brdy"`
  4819. Certno string `json:"certno"`
  4820. ClrOptins string `json:"clr_optins"`
  4821. ClrType string `json:"clr_type"`
  4822. ClrWay string `json:"clr_way"`
  4823. CvlservFlag string `json:"cvlserv_flag"`
  4824. CvlservPay float64 `json:"cvlserv_pay"`
  4825. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  4826. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  4827. Gend string `json:"gend"`
  4828. HifesPay float64 `json:"hifes_pay"`
  4829. HifmiPay float64 `json:"hifmi_pay"`
  4830. HifobPay float64 `json:"hifob_pay"`
  4831. HifpPay float64 `json:"hifp_pay"`
  4832. HospPartAmt float64 `json:"hosp_part_amt"`
  4833. InscpScpAmt float64 `json:"inscp_scp_amt"`
  4834. Insutype string `json:"insutype"`
  4835. MafPay float64 `json:"maf_pay"`
  4836. MdtrtCertType string `json:"mdtrt_cert_type"`
  4837. MdtrtID string `json:"mdtrt_id"`
  4838. MedType string `json:"med_type"`
  4839. MedfeeSumamt float64 `json:"medfee_sumamt"`
  4840. MedinsSetlID string `json:"medins_setl_id"`
  4841. Naty string `json:"naty"`
  4842. OthPay float64 `json:"oth_pay"`
  4843. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  4844. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  4845. PreselfpayAmt float64 `json:"preselfpay_amt"`
  4846. PsnCashPay float64 `json:"psn_cash_pay"`
  4847. PsnCertType string `json:"psn_cert_type"`
  4848. PsnName string `json:"psn_name"`
  4849. PsnNo string `json:"psn_no"`
  4850. PsnPartAmt float64 `json:"psn_part_amt"`
  4851. PsnType string `json:"psn_type"`
  4852. SetlID string `json:"setl_id"`
  4853. SetlTime string `json:"setl_time"`
  4854. } `json:"setlinfo"`
  4855. } `json:"output"`
  4856. RefmsgTime string `json:"refmsg_time"`
  4857. RespondTime string `json:"respond_time"`
  4858. Signtype interface{} `json:"signtype"`
  4859. WarnMsg interface{} `json:"warn_msg"`
  4860. }
  4861. type ResultEight struct {
  4862. Cainfo string `json:"cainfo"`
  4863. ErrMsg string `json:"err_msg"`
  4864. InfRefmsgid string `json:"inf_refmsgid"`
  4865. Infcode int64 `json:"infcode"`
  4866. Output struct {
  4867. Stmtinfo struct {
  4868. SetlOptins string `json:"setl_optins"`
  4869. StmtRslt string `json:"stmt_rslt"`
  4870. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  4871. } `json:"stmtinfo"`
  4872. } `json:"output"`
  4873. RefmsgTime string `json:"refmsg_time"`
  4874. RespondTime string `json:"respond_time"`
  4875. Signtype interface{} `json:"signtype"`
  4876. WarnMsg interface{} `json:"warn_msg"`
  4877. }
  4878. type ResultNine struct {
  4879. Cainfo string `json:"cainfo"`
  4880. ErrMsg string `json:"err_msg"`
  4881. InfRefmsgid string `json:"inf_refmsgid"`
  4882. Infcode int64 `json:"infcode"`
  4883. Output struct {
  4884. FileQuryNo string `json:"file_qury_no"`
  4885. } `json:"output"`
  4886. RefmsgTime string `json:"refmsg_time"`
  4887. RespondTime string `json:"respond_time"`
  4888. Signtype interface{} `json:"signtype"`
  4889. WarnMsg interface{} `json:"warn_msg"`
  4890. }
  4891. type ResultTen struct {
  4892. Cainfo string `json:"cainfo"`
  4893. ErrMsg string `json:"err_msg"`
  4894. InfRefmsgid string `json:"inf_refmsgid"`
  4895. Infcode int64 `json:"infcode"`
  4896. Output struct {
  4897. DldEndtime string `json:"dld_endtime"`
  4898. FileQuryNo string `json:"file_qury_no"`
  4899. Filename string `json:"filename"`
  4900. } `json:"output"`
  4901. RefmsgTime string `json:"refmsg_time"`
  4902. RespondTime string `json:"respond_time"`
  4903. Signtype interface{} `json:"signtype"`
  4904. WarnMsg interface{} `json:"warn_msg"`
  4905. }
  4906. type ResultEleven struct {
  4907. Cainfo string `json:"cainfo"`
  4908. ErrMsg string `json:"err_msg"`
  4909. InfRefmsgid string `json:"inf_refmsgid"`
  4910. Infcode int64 `json:"infcode"`
  4911. Output struct {
  4912. Setlinfo struct {
  4913. FixmedinsName string `json:"fixmedins_name"`
  4914. FixmedinsCode string `json:"fixmedins_code"`
  4915. PsnNo string `json:"psn_no"`
  4916. PsnName string `json:"psn_name"`
  4917. HifobPay float64 `json:"hifob_pay"`
  4918. Gend string `json:"gend"`
  4919. Brdy string `json:"brdy"`
  4920. PsnCertType string `json:"psn_cert_type"`
  4921. PsnType string `json:"psn_type"`
  4922. EmpName string `json:"emp_name"`
  4923. Certno string `json:"certno"`
  4924. Insutype string `json:"insutype"`
  4925. MedfeeSumamt float64 `json:"medfee_sumamt"`
  4926. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  4927. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  4928. PreselfpayAmt float64 `json:"preselfpay_amt"`
  4929. InscpScpAmt float64 `json:"inscp_scp_amt"`
  4930. ActPayDedc float64 `json:"act_pay_dedc"`
  4931. HifpPay float64 `json:"hifp_pay"`
  4932. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  4933. CvlservPay float64 `json:"cvlserv_pay"`
  4934. HifesPay float64 `json:"hifes_pay"`
  4935. HifmiPay float64 `json:"hifmi_pay"`
  4936. MafPay float64 `json:"maf_pay"`
  4937. OthPay float64 `json:"oth_pay"`
  4938. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  4939. PsnPay float64 `json:"psn_pay"`
  4940. AcctPay float64 `json:"acct_pay"`
  4941. CashPayamt float64 `json:"cash_payamt"`
  4942. Balc float64 `json:"balc"`
  4943. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  4944. MedinsSetlId string `json:"medins_setl_id"`
  4945. RefdSetlFlag string `json:"refd_setl_flag"`
  4946. SetlTime string `json:"setl_time"`
  4947. MedType string `json:"med_type"`
  4948. } `json:"setlinfo"`
  4949. } `json:"output"`
  4950. RefmsgTime string `json:"refmsg_time"`
  4951. RespondTime string `json:"respond_time"`
  4952. Signtype interface{} `json:"signtype"`
  4953. WarnMsg interface{} `json:"warn_msg"`
  4954. }
  4955. type Custom struct {
  4956. DetItemFeeSumamt string
  4957. Cut string
  4958. FeedetlSn string
  4959. Price string
  4960. MedListCodg string
  4961. Type int64
  4962. AdviceId int64
  4963. ProjectId int64
  4964. ItemId int64
  4965. }
  4966. //获取个人信息----挂号-----上传就诊信息
  4967. func (c *HisApiController) GetRegisterInfo() {
  4968. id, _ := c.GetInt64("id")
  4969. record_time := c.GetString("record_time")
  4970. settlementValue, _ := c.GetInt64("settlement_value")
  4971. medical_insurance_card := c.GetString("medical_insurance_card")
  4972. name := c.GetString("name")
  4973. id_card_type, _ := c.GetInt64("id_card_type")
  4974. certificates, _ := c.GetInt64("certificates")
  4975. medical_care, _ := c.GetInt64("medical_care")
  4976. birthday := c.GetString("birthday")
  4977. age, _ := c.GetInt64("age")
  4978. id_card := c.GetString("id_card")
  4979. register_type, _ := c.GetInt64("register")
  4980. doctor, _ := c.GetInt64("doctor")
  4981. department, _ := c.GetInt64("department")
  4982. gender, _ := c.GetInt64("sex")
  4983. phone := c.GetString("phone")
  4984. registration_fee, _ := c.GetFloat("registration_fee")
  4985. medical_expenses, _ := c.GetFloat("medical_expenses")
  4986. social_type, _ := c.GetInt64("social_type")
  4987. //diagnosis_id, _ := c.GetInt64("diagnosis")
  4988. diagnosis_ids := c.GetString("diagnosis")
  4989. sick_type, _ := c.GetInt64("sick_type")
  4990. reg_type := c.GetString("p_type")
  4991. timeLayout := "2006-01-02"
  4992. loc, _ := time.LoadLocation("Local")
  4993. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  4994. birthUnix := birthdays.Unix()
  4995. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4996. if err != nil {
  4997. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4998. return
  4999. }
  5000. recordDateTime := theTime.Unix()
  5001. adminInfo := c.GetAdminUserInfo()
  5002. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  5003. if tempPatient.ID == 0 {
  5004. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  5005. return
  5006. }
  5007. var patient service.Patients
  5008. if id == 0 {
  5009. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  5010. } else {
  5011. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  5012. }
  5013. if patient.ID == 0 {
  5014. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  5015. return
  5016. }
  5017. if len(patient.IdCardNo) == 0 {
  5018. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  5019. return
  5020. }
  5021. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5022. if len(his) >= 1 {
  5023. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  5024. if len(his) >= 1 && order.ID == 0 {
  5025. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  5026. return
  5027. }
  5028. }
  5029. timeStr := time.Now().Format("2006-01-02 15:04:05")
  5030. fmt.Println(timeStr)
  5031. timeArr := strings.Split(timeStr, " ")
  5032. fmt.Println(timeArr)
  5033. timeArrTwo := strings.Split(timeArr[0], "-")
  5034. timeArrThree := strings.Split(timeArr[1], ":")
  5035. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  5036. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5037. if len(lists) == 0 {
  5038. var hisPatient models.XtHisPatient
  5039. hisPatient = models.XtHisPatient{
  5040. Name: name,
  5041. Age: age,
  5042. Gender: gender,
  5043. Birthday: birthUnix,
  5044. Phone: phone,
  5045. MedicalTreatmentType: medical_care,
  5046. IdType: certificates,
  5047. IdCardNo: id_card,
  5048. BalanceAccountsType: settlementValue,
  5049. SocialType: social_type,
  5050. MedicalInsuranceNumber: medical_insurance_card,
  5051. RegisterType: register_type,
  5052. RegisterCost: registration_fee,
  5053. TreatmentCost: medical_expenses,
  5054. AdminUserId: adminInfo.AdminUser.Id,
  5055. UserOrgId: adminInfo.CurrentOrgId,
  5056. Status: 1,
  5057. RecordDate: recordDateTime,
  5058. IsReturn: 1,
  5059. PatientId: patient.ID,
  5060. Ctime: time.Now().Unix(),
  5061. Mtime: time.Now().Unix(),
  5062. Number: str,
  5063. IdCardType: id_card_type,
  5064. Departments: department,
  5065. Doctor: doctor,
  5066. PType: reg_type,
  5067. Diagnosis: diagnosis_ids,
  5068. SickType: sick_type,
  5069. }
  5070. service.CreateHisPatient(&hisPatient)
  5071. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  5072. c.ServeSuccessJSON(map[string]interface{}{
  5073. "his_info": hisPatient,
  5074. })
  5075. } else {
  5076. //chrgBchno := rand.Intn(1000000) + 10000
  5077. var hisPatient models.XtHisPatient
  5078. hisPatient = models.XtHisPatient{
  5079. Name: name,
  5080. Age: age,
  5081. Gender: gender,
  5082. Birthday: birthUnix,
  5083. Phone: phone,
  5084. MedicalTreatmentType: medical_care,
  5085. IdType: certificates,
  5086. IdCardNo: id_card,
  5087. BalanceAccountsType: settlementValue,
  5088. SocialType: social_type,
  5089. MedicalInsuranceNumber: medical_insurance_card,
  5090. RegisterType: register_type,
  5091. RegisterCost: registration_fee,
  5092. TreatmentCost: medical_expenses,
  5093. AdminUserId: adminInfo.AdminUser.Id,
  5094. UserOrgId: adminInfo.CurrentOrgId,
  5095. Status: 1,
  5096. RecordDate: recordDateTime,
  5097. IsReturn: 1,
  5098. PatientId: patient.ID,
  5099. Ctime: time.Now().Unix(),
  5100. Mtime: time.Now().Unix(),
  5101. Number: str,
  5102. IdCardType: id_card_type,
  5103. Departments: department,
  5104. Doctor: doctor,
  5105. PType: reg_type,
  5106. Diagnosis: diagnosis_ids,
  5107. SickType: sick_type,
  5108. }
  5109. service.CreateHisPatient(&hisPatient)
  5110. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  5111. c.ServeSuccessJSON(map[string]interface{}{
  5112. "his_info": hisPatient,
  5113. })
  5114. }
  5115. }
  5116. //上传明细----结算
  5117. func (c *HisApiController) GetUploadInfo() {
  5118. id, _ := c.GetInt64("id")
  5119. record_time := c.GetString("record_time")
  5120. his_patient_id, _ := c.GetInt64("his_patient_id")
  5121. pay_way, _ := c.GetInt64("pay_way")
  5122. pay_price, _ := c.GetFloat("pay_price")
  5123. pay_card_no := c.GetString("pay_card_no")
  5124. discount_price, _ := c.GetFloat("discount_price")
  5125. preferential_price, _ := c.GetFloat("preferential_price")
  5126. reality_price, _ := c.GetFloat("reality_price")
  5127. found_price, _ := c.GetFloat("found_price")
  5128. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  5129. private_price, _ := c.GetFloat("private_price")
  5130. timeLayout := "2006-01-02"
  5131. loc, _ := time.LoadLocation("Local")
  5132. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  5133. fapiao_code := c.GetString("fapiao_code")
  5134. fapiao_number := c.GetString("fapiao_number")
  5135. diagnosis_id := c.GetString("diagnosis")
  5136. sick_type, _ := c.GetInt64("sick_type")
  5137. reg_type, _ := c.GetInt64("p_type")
  5138. order_id, _ := c.GetInt64("order_id")
  5139. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  5140. tmp_decimal := c.GetString("tmp_decimal")
  5141. var decimal float64 //本次使用的押金
  5142. var errmsg error
  5143. tx := service.XTWriteDB().Begin() //开了事务
  5144. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  5145. defer func() {
  5146. if errmsg != nil {
  5147. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  5148. tx.Rollback()
  5149. } else {
  5150. tx.Commit()
  5151. }
  5152. }()
  5153. fmt.Println("dec_way", dec_way)
  5154. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  5155. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  5156. return
  5157. }
  5158. if len(tmp_decimal) > 0 {
  5159. if tmp_decimal[0] == 45 {
  5160. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  5161. return
  5162. }
  5163. }
  5164. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  5165. fmt.Println(errs)
  5166. //if errs != nil {
  5167. // c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金金额错误")
  5168. // return
  5169. //}
  5170. decimal = tt
  5171. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  5172. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  5173. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5174. if err != nil {
  5175. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5176. return
  5177. }
  5178. recordDateTime := theTime.Unix()
  5179. adminUser := c.GetAdminUserInfo()
  5180. var prescriptions []*models.HisPrescription
  5181. var prescriptionsOne []*models.HisPrescription
  5182. var start_time int64
  5183. var end_time int64
  5184. ids_str := c.GetString("ids")
  5185. ids_arr := strings.Split(ids_str, ",")
  5186. if tempOrder.ID == 0 {
  5187. if settle_accounts_type == 1 { //日结
  5188. fmt.Println(reg_type)
  5189. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  5190. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  5191. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  5192. } else {
  5193. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5194. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5195. }
  5196. } else { //月结
  5197. start_time_str := c.GetString("start_time")
  5198. end_time_str := c.GetString("end_time")
  5199. timeLayout := "2006-01-02"
  5200. loc, _ := time.LoadLocation("Local")
  5201. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  5202. if err != nil {
  5203. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5204. return
  5205. }
  5206. recordStartTime := theStartTime.Unix()
  5207. start_time = recordStartTime
  5208. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  5209. if err != nil {
  5210. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5211. return
  5212. }
  5213. recordEndTime := theEndTime.Unix()
  5214. end_time = recordEndTime
  5215. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  5216. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5217. }
  5218. var goods []*models.DialysisBeforePrepareGoods
  5219. var newGoods []*models.NewDialysisBeforePrepareGoods
  5220. var oldGoods []*models.OldDialysisBeforePrepareGoods
  5221. var infos []*models.HisDoctorAdviceInfo
  5222. var infoList []*models.HisDoctorAdviceInfo
  5223. var hisAdvice []*models.HisDoctorAdviceInfo
  5224. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  5225. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  5226. //判断库存不足
  5227. //结算出库开关
  5228. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  5229. if settConfig.IsOpen == 1 {
  5230. //判断库存的地方
  5231. for _, info := range prescriptions {
  5232. if info.Type == 1 {
  5233. infos = append(infos, info.HisDoctorAdviceInfo...)
  5234. }
  5235. if info.Type == 2 {
  5236. for _, sumItem := range info.HisPrescriptionProject {
  5237. if sumItem.Type == 3 {
  5238. var good models.DialysisBeforePrepareGoods
  5239. var newGood models.NewDialysisBeforePrepareGoods
  5240. good.GoodId = sumItem.GoodInfo.ID
  5241. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5242. count, _ := strconv.Atoi(sumItem.Count)
  5243. good.Count = int64(count)
  5244. good.StorehouseId = houseConfig.StorehouseOutInfo
  5245. good.ProjectId = sumItem.ID
  5246. goods = append(goods, &good)
  5247. newGood.GoodId = sumItem.GoodInfo.ID
  5248. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5249. count2, _ := strconv.Atoi(sumItem.Count)
  5250. newGood.Count = int64(count2)
  5251. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5252. newGood.ProjectId = sumItem.ID
  5253. newGoods = append(newGoods, &newGood)
  5254. }
  5255. }
  5256. }
  5257. }
  5258. for _, info := range prescriptionsOne {
  5259. if info.Type == 1 {
  5260. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  5261. }
  5262. if info.Type == 2 {
  5263. for _, sumItem := range info.HisPrescriptionProject {
  5264. if sumItem.Type == 3 {
  5265. var newGood models.NewDialysisBeforePrepareGoods
  5266. newGood.GoodId = sumItem.GoodInfo.ID
  5267. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5268. count2, _ := strconv.Atoi(sumItem.Count)
  5269. newGood.Count = int64(count2)
  5270. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5271. newGood.ProjectId = sumItem.ID
  5272. newGoodOne = append(newGoodOne, &newGood)
  5273. }
  5274. }
  5275. }
  5276. }
  5277. //判断
  5278. for _, itemOne := range infos {
  5279. for _, itemTwo := range hisAdvice {
  5280. if itemOne.DrugId == itemTwo.DrugId {
  5281. itemTwo.Child = append(itemTwo.ChildDoctorAdvice, itemOne)
  5282. }
  5283. }
  5284. }
  5285. for _, itemTwo := range hisAdvice {
  5286. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  5287. var sum_out_count int64
  5288. for _, itemThree := range itemTwo.Child {
  5289. var prescribing_number int64
  5290. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  5291. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5292. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5293. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5294. }
  5295. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5296. prescribing_number = parseIntPrescribingNumber
  5297. }
  5298. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5299. prescribing_number = parseIntPrescribingNumber
  5300. }
  5301. sum_out_count += prescribing_number
  5302. }
  5303. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId)
  5304. if sum_out_count > drugStockOut.FlushCount {
  5305. c.ServeSuccessJSON(map[string]interface{}{
  5306. "msg": "2",
  5307. "drug": medical,
  5308. })
  5309. return
  5310. }
  5311. }
  5312. for _, itemOne := range newGoods {
  5313. for _, item := range newGoodOne {
  5314. if itemOne.ProjectId == item.ProjectId {
  5315. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, item)
  5316. }
  5317. }
  5318. }
  5319. for _, item := range newGoodOne {
  5320. var sum_out_count_one int64
  5321. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  5322. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  5323. sum_out_count_one += itemOne.Count
  5324. }
  5325. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId)
  5326. fmt.Println("sum_out_count_one", sum_out_count_one)
  5327. fmt.Println("list.FlushCount", list.FlushCount)
  5328. if sum_out_count_one > list.FlushCount {
  5329. c.ServeSuccessJSON(map[string]interface{}{
  5330. "msg": "3",
  5331. "good": good,
  5332. })
  5333. return
  5334. }
  5335. }
  5336. }
  5337. timestamp := time.Now().Unix()
  5338. tempTime := time.Unix(timestamp, 0)
  5339. timeFormat := tempTime.Format("20060102150405")
  5340. chrgBchno := rand.Intn(100000) + 10000
  5341. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  5342. strconv.FormatInt(his.PatientId, 10)
  5343. var ids []int64
  5344. for _, item := range prescriptions {
  5345. ids = append(ids, item.ID)
  5346. }
  5347. var total float64
  5348. for _, item := range prescriptions {
  5349. fmt.Println(item)
  5350. if item.Type == 1 { //药品
  5351. for _, subItem := range item.HisDoctorAdviceInfo {
  5352. total = total + (subItem.Price * subItem.PrescribingNumber)
  5353. }
  5354. }
  5355. if item.Type == 2 { //项目
  5356. for _, subItem := range item.HisPrescriptionProject {
  5357. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  5358. total = total + (subItem.Price * cnt)
  5359. }
  5360. }
  5361. for _, subItem := range item.HisAdditionalCharge {
  5362. total = total + (subItem.Price * float64(subItem.Count))
  5363. }
  5364. }
  5365. if reg_type == 1111 || reg_type == 1112 {
  5366. reg_type = 11
  5367. }
  5368. tm := time.Unix(time.Now().Unix(), 0)
  5369. allTotal := fmt.Sprintf("%.4f", total)
  5370. totals, _ := strconv.ParseFloat(allTotal, 64)
  5371. order := &models.HisOrder{
  5372. UserOrgId: adminUser.CurrentOrgId,
  5373. HisPatientId: his.ID,
  5374. PatientId: id,
  5375. SettleAccountsDate: recordDateTime,
  5376. Ctime: time.Now().Unix(),
  5377. Mtime: time.Now().Unix(),
  5378. Status: 1,
  5379. OrderStatus: 2,
  5380. MdtrtId: his.Number,
  5381. Number: chrg_bchno,
  5382. MedfeeSumamt: totals,
  5383. PayWay: pay_way,
  5384. PayPrice: pay_price,
  5385. MedType: strconv.Itoa(int(reg_type)),
  5386. PayCardNo: pay_card_no,
  5387. DiscountPrice: discount_price,
  5388. PreferentialPrice: preferential_price,
  5389. RealityPrice: reality_price,
  5390. FoundPrice: found_price,
  5391. MedicalInsurancePrice: medical_insurance_price,
  5392. PrivatePrice: private_price,
  5393. SettleEndTime: end_time,
  5394. SettleStartTime: start_time,
  5395. SettleType: settle_accounts_type,
  5396. FaPiaoCode: fapiao_code,
  5397. FaPiaoNumber: fapiao_number,
  5398. Diagnosis: diagnosis_id,
  5399. PType: 2,
  5400. SetlTime: tm.Format("2006-01-02 15:04:05"),
  5401. Decimal: decimal,
  5402. }
  5403. err = service.CreateOrderTX(order, tx)
  5404. if err != nil {
  5405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  5406. return
  5407. }
  5408. var customs []*Custom
  5409. for _, item := range prescriptions {
  5410. if item.Type == 1 { //药品a
  5411. for _, subItem := range item.HisDoctorAdviceInfo {
  5412. cus := &Custom{
  5413. AdviceId: subItem.ID,
  5414. ProjectId: 0,
  5415. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  5416. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  5417. FeedetlSn: subItem.FeedetlSn,
  5418. Price: fmt.Sprintf("%.4f", subItem.Price),
  5419. MedListCodg: subItem.MedListCodg,
  5420. Type: 1,
  5421. }
  5422. customs = append(customs, cus)
  5423. }
  5424. }
  5425. if item.Type == 2 { //项目
  5426. for _, subItem := range item.HisPrescriptionProject {
  5427. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  5428. cus := &Custom{
  5429. AdviceId: 0,
  5430. ProjectId: subItem.ID,
  5431. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  5432. Cut: fmt.Sprintf("%.4f", cnt),
  5433. FeedetlSn: subItem.FeedetlSn,
  5434. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  5435. MedListCodg: subItem.MedListCodg,
  5436. Type: 2,
  5437. }
  5438. customs = append(customs, cus)
  5439. }
  5440. }
  5441. for _, item := range item.HisAdditionalCharge {
  5442. cus := &Custom{
  5443. ItemId: item.ID,
  5444. AdviceId: 0,
  5445. ProjectId: 0,
  5446. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  5447. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  5448. FeedetlSn: item.FeedetlSn,
  5449. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  5450. MedListCodg: item.XtHisAddtionConfig.Code,
  5451. Type: 3,
  5452. }
  5453. customs = append(customs, cus)
  5454. }
  5455. }
  5456. for _, item := range customs {
  5457. var advice_id int64 = 0
  5458. var project_id int64 = 0
  5459. var item_id int64 = 0
  5460. var types int64 = 0
  5461. if item.Type == 1 {
  5462. advice_id = item.AdviceId
  5463. project_id = 0
  5464. item_id = 0
  5465. } else if item.Type == 2 {
  5466. advice_id = 0
  5467. item_id = 0
  5468. project_id = item.ProjectId
  5469. } else if item.Type == 3 {
  5470. advice_id = 0
  5471. item_id = item.ItemId
  5472. project_id = 0
  5473. }
  5474. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  5475. cut, _ := strconv.ParseFloat(item.Cut, 32)
  5476. pric, _ := strconv.ParseFloat(item.Price, 32)
  5477. info := &models.HisOrderInfo{
  5478. OrderNumber: order.Number,
  5479. UploadDate: time.Now().Unix(),
  5480. AdviceId: advice_id,
  5481. DetItemFeeSumamt: detItemFeeSumamt,
  5482. Cnt: cut,
  5483. Pric: pric,
  5484. PatientId: id,
  5485. Status: 1,
  5486. Mtime: time.Now().Unix(),
  5487. Ctime: time.Now().Unix(),
  5488. UserOrgId: adminUser.CurrentOrgId,
  5489. HisPatientId: his.ID,
  5490. OrderId: order.ID,
  5491. ProjectId: project_id,
  5492. Type: types,
  5493. ItemId: item_id,
  5494. }
  5495. service.CreateOrderInfoTX(info, tx)
  5496. }
  5497. his.Diagnosis = diagnosis_id
  5498. his.SickType = sick_type
  5499. his.RegisterType = reg_type
  5500. his.MedicalTreatmentType = reg_type
  5501. service.UpdataHisPateintTX(&his, tx)
  5502. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  5503. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  5504. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  5505. //判断是否使用了押金
  5506. if dec_way == "true" {
  5507. tmpstring := strconv.FormatInt(order.ID, 10)
  5508. //扣押金
  5509. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  5510. order.Decimal = decimal
  5511. service.UpDateOrderTwo(order)
  5512. if errmsg != nil {
  5513. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  5514. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  5515. return
  5516. }
  5517. }
  5518. if err == nil {
  5519. for _, info := range prescriptions {
  5520. if info.Type == 1 {
  5521. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  5522. }
  5523. if info.Type == 2 {
  5524. for _, sumItem := range info.HisPrescriptionProject {
  5525. if sumItem.Type == 3 {
  5526. var good models.DialysisBeforePrepareGoods
  5527. var newGood models.NewDialysisBeforePrepareGoods
  5528. var oldGood models.OldDialysisBeforePrepareGoods
  5529. good.GoodId = sumItem.GoodInfo.ID
  5530. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5531. count, _ := strconv.Atoi(sumItem.Count)
  5532. good.Count = int64(count)
  5533. good.StorehouseId = houseConfig.StorehouseOutInfo
  5534. good.ProjectId = sumItem.ID
  5535. good.PatientId = sumItem.PatientId
  5536. goods = append(goods, &good)
  5537. newGood.GoodId = sumItem.GoodInfo.ID
  5538. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5539. count2, _ := strconv.Atoi(sumItem.Count)
  5540. newGood.Count = int64(count2)
  5541. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5542. newGood.ProjectId = sumItem.ID
  5543. newGood.PatientId = sumItem.HisPatientId
  5544. newGoods = append(newGoods, &newGood)
  5545. oldGood.GoodId = sumItem.GoodInfo.ID
  5546. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5547. count3, _ := strconv.Atoi(sumItem.Count)
  5548. oldGood.Count = int64(count3)
  5549. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  5550. oldGood.ProjectId = sumItem.ID
  5551. oldGood.RecordDate = sumItem.RecordDate
  5552. oldGood.PatientId = sumItem.HisPatientId
  5553. oldGoods = append(oldGoods, &oldGood)
  5554. }
  5555. }
  5556. }
  5557. }
  5558. if settConfig.IsOpen == 1 {
  5559. for _, item := range infoList {
  5560. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  5561. //药品出库
  5562. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  5563. //查询默认仓库
  5564. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  5565. //查询默认仓库剩余多少库存
  5566. var sum_count int64
  5567. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  5568. for _, its := range stockInfo {
  5569. if its.MaxUnit == medical.MaxUnit {
  5570. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5571. }
  5572. sum_count += its.StockMaxNumber + its.StockMinNumber
  5573. }
  5574. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  5575. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  5576. }
  5577. orgId := c.GetAdminUserInfo().CurrentOrgId
  5578. if len(oldGoods) > 0 {
  5579. timeStr := time.Now().Format("2006-01-02")
  5580. timeArr := strings.Split(timeStr, "-")
  5581. total, _ := service.FindAllWarehouseOut(orgId)
  5582. total = total + 1
  5583. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5584. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5585. number = number + total
  5586. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5587. operation_time := time.Now().Unix()
  5588. creater := c.GetAdminUserInfo().AdminUser.Id
  5589. //查询默认出库仓库库存
  5590. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5591. recordDateStr := time.Now().Format("2006-01-02")
  5592. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5593. nowtime := recordDate.Unix()
  5594. warehouseOut := models.WarehouseOut{
  5595. WarehouseOutOrderNumber: warehousing_out_order,
  5596. OperationTime: operation_time,
  5597. OrgId: orgId,
  5598. Creater: creater,
  5599. Ctime: time.Now().Unix(),
  5600. Status: 1,
  5601. WarehouseOutTime: nowtime,
  5602. Type: 1,
  5603. StorehouseId: storeConfig.StorehouseOutInfo,
  5604. IsCheck: 1,
  5605. OrderId: order.ID,
  5606. IsSys: 5,
  5607. }
  5608. //查询是否生成出库单
  5609. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  5610. if out.ID == 0 {
  5611. service.AddSigleWarehouseOut(&warehouseOut)
  5612. }
  5613. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  5614. for _, item := range oldGoods {
  5615. dialyPrepareOne := models.DialysisBeforePrepare{
  5616. GoodTypeId: item.GoodTypeId,
  5617. GoodId: item.GoodId,
  5618. PatientId: his.PatientId,
  5619. RecordDate: item.RecordDate,
  5620. UserOrgId: adminUser.CurrentOrgId,
  5621. Count: item.Count,
  5622. Ctime: time.Now().Unix(),
  5623. Creater: adminUser.AdminUser.Id,
  5624. CommdityCode: item.CommdityCode,
  5625. Status: 1,
  5626. StorehouseId: houseConfig.StorehouseOutInfo,
  5627. }
  5628. //err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  5629. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  5630. //查询剩余库存
  5631. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId)
  5632. var sum_count int64
  5633. for _, item := range goodList {
  5634. sum_count += item.StockCount
  5635. }
  5636. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  5637. //耗材
  5638. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  5639. }
  5640. }
  5641. }
  5642. c.ServeSuccessJSON(map[string]interface{}{
  5643. "msg": "结算成功",
  5644. })
  5645. }
  5646. } else {
  5647. if tempOrder.IsPre > 0 {
  5648. allTotal := fmt.Sprintf("%.2f", tempOrder.MedfeeSumamt)
  5649. totals, _ := strconv.ParseFloat(allTotal, 64)
  5650. tempOrder.OrderStatus = 2
  5651. tempOrder.PayWay = pay_way
  5652. tempOrder.PayPrice = pay_price
  5653. tempOrder.PayCardNo = pay_card_no
  5654. tempOrder.DiscountPrice = discount_price
  5655. tempOrder.PreferentialPrice = preferential_price
  5656. tempOrder.RealityPrice = reality_price
  5657. tempOrder.FoundPrice = found_price
  5658. tempOrder.MedicalInsurancePrice = medical_insurance_price
  5659. tempOrder.PrivatePrice = private_price
  5660. tempOrder.FaPiaoCode = fapiao_code
  5661. tempOrder.FaPiaoNumber = fapiao_number
  5662. tempOrder.PType = 2
  5663. tempOrder.MedfeeSumamt = totals
  5664. tempOrder.Diagnosis = diagnosis_id
  5665. err = service.SaveHisOrder(&tempOrder)
  5666. err = service.UpdataOrderStatusTwo(tempOrder.Number, adminUser.CurrentOrgId)
  5667. if err != nil {
  5668. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  5669. return
  5670. }
  5671. if err == nil {
  5672. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  5673. var goods []*models.DialysisBeforePrepareGoods
  5674. var newGoods []*models.NewDialysisBeforePrepareGoods
  5675. var infos []*models.HisDoctorAdviceInfo
  5676. var hisAdvice []*models.HisDoctorAdviceInfo
  5677. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  5678. var infolist []*models.HisDoctorAdviceInfo
  5679. var oldGoods []*models.OldDialysisBeforePrepareGoods
  5680. for _, info := range prescriptions {
  5681. if info.Type == 1 {
  5682. infos = append(infos, info.HisDoctorAdviceInfo...)
  5683. }
  5684. if info.Type == 2 {
  5685. for _, sumItem := range info.HisPrescriptionProject {
  5686. if sumItem.Type == 3 {
  5687. var good models.DialysisBeforePrepareGoods
  5688. var newGood models.NewDialysisBeforePrepareGoods
  5689. good.GoodId = sumItem.GoodInfo.ID
  5690. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5691. count, _ := strconv.Atoi(sumItem.Count)
  5692. good.Count = int64(count)
  5693. good.StorehouseId = houseConfig.StorehouseOutInfo
  5694. good.ProjectId = sumItem.ID
  5695. goods = append(goods, &good)
  5696. newGood.GoodId = sumItem.GoodInfo.ID
  5697. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5698. count2, _ := strconv.Atoi(sumItem.Count)
  5699. newGood.Count = int64(count2)
  5700. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5701. newGood.ProjectId = sumItem.ID
  5702. newGoods = append(newGoods, &newGood)
  5703. }
  5704. }
  5705. }
  5706. }
  5707. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  5708. if settConfig.IsOpen == 1 {
  5709. //判断库存的地方
  5710. for _, info := range prescriptions {
  5711. if info.Type == 1 {
  5712. infolist = append(infolist, info.HisDoctorAdviceInfo...)
  5713. }
  5714. if info.Type == 2 {
  5715. for _, sumItem := range info.HisPrescriptionProject {
  5716. if sumItem.Type == 3 {
  5717. var good models.DialysisBeforePrepareGoods
  5718. var newGood models.NewDialysisBeforePrepareGoods
  5719. var oldGood models.OldDialysisBeforePrepareGoods
  5720. good.GoodId = sumItem.GoodInfo.ID
  5721. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5722. count, _ := strconv.Atoi(sumItem.Count)
  5723. good.Count = int64(count)
  5724. good.StorehouseId = houseConfig.StorehouseOutInfo
  5725. good.ProjectId = sumItem.ID
  5726. goods = append(goods, &good)
  5727. newGood.GoodId = sumItem.GoodInfo.ID
  5728. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5729. count2, _ := strconv.Atoi(sumItem.Count)
  5730. newGood.Count = int64(count2)
  5731. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5732. newGood.ProjectId = sumItem.ID
  5733. newGoods = append(newGoods, &newGood)
  5734. oldGood.GoodId = sumItem.GoodInfo.ID
  5735. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5736. count3, _ := strconv.Atoi(sumItem.Count)
  5737. oldGood.Count = int64(count3)
  5738. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  5739. oldGood.ProjectId = sumItem.ID
  5740. oldGood.RecordDate = sumItem.RecordDate
  5741. oldGoods = append(oldGoods, &oldGood)
  5742. }
  5743. }
  5744. }
  5745. }
  5746. for _, info := range prescriptionsOne {
  5747. if info.Type == 1 {
  5748. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  5749. }
  5750. if info.Type == 2 {
  5751. for _, sumItem := range info.HisPrescriptionProject {
  5752. if sumItem.Type == 3 {
  5753. var newGood models.NewDialysisBeforePrepareGoods
  5754. newGood.GoodId = sumItem.GoodInfo.ID
  5755. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5756. count2, _ := strconv.Atoi(sumItem.Count)
  5757. newGood.Count = int64(count2)
  5758. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5759. newGood.ProjectId = sumItem.ID
  5760. newGoodOne = append(newGoodOne, &newGood)
  5761. }
  5762. }
  5763. }
  5764. }
  5765. //判断
  5766. for _, itemOne := range infos {
  5767. for _, itemTwo := range hisAdvice {
  5768. if itemOne.DrugId == itemTwo.DrugId {
  5769. itemTwo.Child = append(itemTwo.ChildDoctorAdvice, itemOne)
  5770. }
  5771. }
  5772. }
  5773. for _, itemTwo := range hisAdvice {
  5774. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  5775. var sum_out_count int64
  5776. for _, itemThree := range itemTwo.Child {
  5777. var prescribing_number int64
  5778. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  5779. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5780. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5781. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5782. }
  5783. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5784. prescribing_number = parseIntPrescribingNumber
  5785. }
  5786. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5787. prescribing_number = parseIntPrescribingNumber
  5788. }
  5789. sum_out_count += prescribing_number
  5790. }
  5791. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId)
  5792. if sum_out_count > drugStockOut.FlushCount {
  5793. c.ServeSuccessJSON(map[string]interface{}{
  5794. "msg": "2",
  5795. "drug": medical,
  5796. })
  5797. return
  5798. }
  5799. }
  5800. for _, itemOne := range newGoods {
  5801. for _, item := range newGoodOne {
  5802. if itemOne.ProjectId == item.ProjectId {
  5803. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, item)
  5804. }
  5805. }
  5806. }
  5807. for _, item := range newGoodOne {
  5808. var sum_out_count_one int64
  5809. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  5810. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  5811. sum_out_count_one += itemOne.Count
  5812. }
  5813. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId)
  5814. fmt.Println("sum_out_count_one", sum_out_count_one)
  5815. fmt.Println("list.FlushCount", list.FlushCount)
  5816. if sum_out_count_one > list.FlushCount {
  5817. c.ServeSuccessJSON(map[string]interface{}{
  5818. "msg": "3",
  5819. "good": good,
  5820. })
  5821. return
  5822. }
  5823. }
  5824. for _, item := range infolist {
  5825. service.HisDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item)
  5826. }
  5827. for _, item := range oldGoods {
  5828. dialyPrepareOne := models.DialysisBeforePrepare{
  5829. GoodTypeId: item.GoodTypeId,
  5830. GoodId: item.GoodId,
  5831. PatientId: item.PatientId,
  5832. RecordDate: item.RecordDate,
  5833. UserOrgId: item.UserOrgId,
  5834. Count: item.Count,
  5835. Ctime: time.Now().Unix(),
  5836. Creater: adminUser.AdminUser.Id,
  5837. CommdityCode: item.CommdityCode,
  5838. Status: 1,
  5839. StorehouseId: houseConfig.StorehouseOutInfo,
  5840. }
  5841. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  5842. }
  5843. service.ConsumablesDeliveryTotal(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, goods, newGoods, adminUser.AdminUser.Id)
  5844. }
  5845. c.ServeSuccessJSON(map[string]interface{}{
  5846. "msg": "结算成功",
  5847. })
  5848. }
  5849. }
  5850. }
  5851. }
  5852. //退款
  5853. func (c *HisApiController) Refund() {
  5854. order_id, _ := c.GetInt64("order_id")
  5855. order, _ := service.GetHisOrderByID(order_id)
  5856. adminUser := c.GetAdminUserInfo()
  5857. orgid := c.GetAdminUserInfo().CurrentOrgId
  5858. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  5859. if err != nil {
  5860. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5861. return
  5862. }
  5863. tmp := strconv.FormatInt(order.ID, 10)
  5864. //当押金不为零时产生退费记录
  5865. if order.Decimal != 0 {
  5866. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  5867. if err != nil {
  5868. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5869. return
  5870. }
  5871. }
  5872. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  5873. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  5874. var goods []*models.DialysisBeforePrepareGoods
  5875. var newGoods []*models.NewDialysisBeforePrepareGoods
  5876. var infos []*models.HisDoctorAdviceInfo
  5877. for _, info := range orders {
  5878. if info.AdviceId > 0 && info.ProjectId == 0 {
  5879. infos = append(infos, &info.HisDoctorAdviceInfo)
  5880. }
  5881. if info.ProjectId > 0 && info.AdviceId == 0 {
  5882. fmt.Println("info232323233232233", info.PatientId)
  5883. if info.HisPrescriptionProject.Type == 3 {
  5884. var good models.DialysisBeforePrepareGoods
  5885. var newGood models.NewDialysisBeforePrepareGoods
  5886. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  5887. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  5888. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  5889. good.Count = int64(count)
  5890. good.StorehouseId = houseConfig.StorehouseOutInfo
  5891. good.ProjectId = info.HisPrescriptionProject.ID
  5892. good.PatientId = info.PatientId
  5893. goods = append(goods, &good)
  5894. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  5895. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  5896. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  5897. newGood.Count = int64(count2)
  5898. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5899. newGood.ProjectId = info.HisPrescriptionProject.ID
  5900. newGood.RecordDate = order.SettleAccountsDate
  5901. newGood.UserOrgId = order.UserOrgId
  5902. newGood.PatientId = info.PatientId
  5903. newGoods = append(newGoods, &newGood)
  5904. }
  5905. }
  5906. }
  5907. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  5908. if settConfig.IsOpen == 1 {
  5909. for _, item := range infos {
  5910. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  5911. }
  5912. for _, item := range newGoods {
  5913. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  5914. }
  5915. }
  5916. c.ServeSuccessJSON(map[string]interface{}{
  5917. "msg": "退费成功",
  5918. })
  5919. }
  5920. func (c *HisApiController) RefundNumber() {
  5921. his_patient_id, _ := c.GetInt64("id")
  5922. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  5923. info.Status = 0
  5924. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  5925. if count > 0 {
  5926. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  5927. return
  5928. }
  5929. err := service.SaveHisPatient(info)
  5930. if err == nil {
  5931. c.ServeSuccessJSON(map[string]interface{}{
  5932. "msg": "退号成功",
  5933. })
  5934. } else {
  5935. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5936. return
  5937. }
  5938. }
  5939. func (this *HisApiController) AdditionalCharge() {
  5940. dataBody := make(map[string]interface{}, 0)
  5941. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  5942. fmt.Println(err)
  5943. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  5944. patient_id := int64(dataBody["patient_id"].(float64))
  5945. medicineData, _ := dataBody["medicineData"].([]interface{})
  5946. adminUserInfo := this.GetAdminUserInfo()
  5947. orgId := adminUserInfo.CurrentOrgId
  5948. admin_user_id := adminUserInfo.AdminUser.Id
  5949. timeStr := time.Now().Format("2006-01-02")
  5950. timeLayout := "2006-01-02 15:04:05"
  5951. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  5952. timenow := timeStringToTime.Unix()
  5953. var additionalCharges []*models.HisAdditionalCharge
  5954. for _, item := range medicineData {
  5955. var randNum int
  5956. randNum = rand.Intn(10000) + 1000
  5957. timestamp := time.Now().Unix()
  5958. tempTime := time.Unix(timestamp, 0)
  5959. timeFormat := tempTime.Format("20060102150405")
  5960. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  5961. items := item.(map[string]interface{})
  5962. money := items["price"].(string)
  5963. item_id_str := items["item_id"].(string)
  5964. name := items["name"].(string)
  5965. id_str := items["id"].(string)
  5966. moneys, _ := strconv.ParseInt(money, 10, 64)
  5967. monStr := strconv.FormatInt(moneys, 10)
  5968. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  5969. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  5970. id, _ := strconv.ParseInt(id_str, 10, 64)
  5971. additionalCharge := &models.HisAdditionalCharge{
  5972. ID: id,
  5973. HisPatientId: his_patient_id,
  5974. UserOrgId: orgId,
  5975. PatientId: patient_id,
  5976. RecordDate: timenow,
  5977. Price: monneyStr,
  5978. Status: 1,
  5979. ItemName: name,
  5980. ItemId: item_id,
  5981. AdminUserId: admin_user_id,
  5982. CreatedTime: time.Now().Unix(),
  5983. OrderStatus: 0,
  5984. PrescriptionNumber: "",
  5985. BatchNumber: "",
  5986. FeedetlSn: p_number,
  5987. }
  5988. service.CreateAdditionalCharge(additionalCharge)
  5989. additionalCharges = append(additionalCharges, additionalCharge)
  5990. }
  5991. this.ServeSuccessJSON(map[string]interface{}{
  5992. "msg": "添加成功",
  5993. "additional_charges": additionalCharges,
  5994. })
  5995. }
  5996. func (this *HisApiController) DeleteAddition() {
  5997. id, _ := this.GetInt64("id")
  5998. //TODO 需要判断是否已经结算
  5999. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  6000. if err == nil {
  6001. this.ServeSuccessJSON(map[string]interface{}{
  6002. "msg": "删除成功",
  6003. })
  6004. return
  6005. } else {
  6006. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6007. return
  6008. }
  6009. }
  6010. func (this *HisApiController) GetAdminUsers() {
  6011. adminUser := this.GetAdminUserInfo()
  6012. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  6013. this.ServeSuccessJSON(map[string]interface{}{
  6014. "doctors": doctors,
  6015. })
  6016. }
  6017. func (this *HisApiController) GetLastOrNextHisPrescription() {
  6018. change_type, _ := this.GetInt64("type", 0)
  6019. record_date := this.GetString("record_time")
  6020. patient_id, _ := this.GetInt64("patient_id", 0)
  6021. p_type, _ := this.GetInt64("p_type", 0)
  6022. timeLayout := "2006-01-02"
  6023. loc, _ := time.LoadLocation("Local")
  6024. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6025. record_time := theAdviceRecordTime.Unix()
  6026. adminUserInfo := this.GetAdminUserInfo()
  6027. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  6028. if err == nil {
  6029. if len(prescriptions) == 0 {
  6030. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  6031. return
  6032. } else {
  6033. this.ServeSuccessJSON(map[string]interface{}{
  6034. "prescriptions": prescriptions,
  6035. })
  6036. return
  6037. }
  6038. } else {
  6039. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6040. return
  6041. }
  6042. }
  6043. func (this *HisApiController) GetCallHisPrescription() {
  6044. patient_id, _ := this.GetInt64("patient_id", 0)
  6045. timeLayout := "2006-01-02"
  6046. loc, _ := time.LoadLocation("Local")
  6047. start_time := this.GetString("start_time")
  6048. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6049. end_time := this.GetString("end_time")
  6050. p_type, _ := this.GetInt64("p_type")
  6051. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6052. adminUserInfo := this.GetAdminUserInfo()
  6053. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  6054. if err == nil {
  6055. this.ServeSuccessJSON(map[string]interface{}{
  6056. "prescriptions": prescriptions,
  6057. })
  6058. return
  6059. } else {
  6060. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6061. return
  6062. }
  6063. }
  6064. func (this *HisApiController) GetHisDayPrescription() {
  6065. timeLayout := "2006-01-02"
  6066. loc, _ := time.LoadLocation("Local")
  6067. start_time := this.GetString("start_time")
  6068. patient_id, _ := this.GetInt64("patient_id", 0)
  6069. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6070. end_time := this.GetString("end_time")
  6071. p_type, _ := this.GetInt64("p_type")
  6072. order_status, _ := this.GetInt64("type")
  6073. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6074. adminUserInfo := this.GetAdminUserInfo()
  6075. var dayHisPrescription []*models.HisPrescription
  6076. var err error
  6077. if order_status == 1 || order_status == 0 {
  6078. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6079. } else if order_status == 2 {
  6080. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6081. }
  6082. var settle_total float64
  6083. for _, item := range dayHisPrescription {
  6084. if len(item.HisPrescriptionProject) > 0 {
  6085. for _, subItem := range item.HisPrescriptionProject {
  6086. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6087. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6088. settle_total = settle_total + total
  6089. }
  6090. }
  6091. if len(item.HisDoctorAdviceInfo) > 0 {
  6092. for _, subItem := range item.HisDoctorAdviceInfo {
  6093. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6094. settle_total = settle_total + total
  6095. }
  6096. }
  6097. }
  6098. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6099. if err == nil {
  6100. this.ServeSuccessJSON(map[string]interface{}{
  6101. "day_prescription": dayHisPrescription,
  6102. "settle_total": settle_total,
  6103. })
  6104. return
  6105. } else {
  6106. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6107. return
  6108. }
  6109. }
  6110. func (c *HisApiController) GetHisChargePatientList() {
  6111. record_date := c.GetString("record_date")
  6112. order_status, _ := c.GetInt64("type")
  6113. timeLayout := "2006-01-02"
  6114. loc, _ := time.LoadLocation("Local")
  6115. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6116. if err != nil {
  6117. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6118. return
  6119. }
  6120. recordDateTime := theTime.Unix()
  6121. adminInfo := c.GetAdminUserInfo()
  6122. var tempPatients []*service.NewTempPatients
  6123. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6124. if order_status != 2 {
  6125. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6126. } else {
  6127. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6128. }
  6129. var patients []*service.NewTempPatients
  6130. var patients_two []*service.NewTempPatients
  6131. for _, item := range tempPatients {
  6132. //过滤掉没挂号的和没开处方的
  6133. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  6134. patients = append(patients, item)
  6135. }
  6136. //过滤掉没挂号的
  6137. if len(item.HisPatient) > 0 {
  6138. patients_two = append(patients_two, item)
  6139. }
  6140. }
  6141. c.ServeSuccessJSON(map[string]interface{}{
  6142. "list": patients,
  6143. "list_two": patients_two,
  6144. })
  6145. }
  6146. func (c *HisApiController) GetHisUnRegisterPatientList() {
  6147. record_date := c.GetString("record_date")
  6148. timeLayout := "2006-01-02"
  6149. loc, _ := time.LoadLocation("Local")
  6150. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6151. if err != nil {
  6152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6153. return
  6154. }
  6155. recordDateTime := theTime.Unix()
  6156. adminUser := c.GetAdminUserInfo()
  6157. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  6158. var patients []*service.Patients
  6159. for _, item := range tempPatients {
  6160. if item.HisPatient.ID == 0 {
  6161. patients = append(patients, item)
  6162. }
  6163. }
  6164. c.ServeSuccessJSON(map[string]interface{}{
  6165. "list": patients,
  6166. //"list_two": patients_two,
  6167. })
  6168. }
  6169. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  6170. newArr = make([]*service.Patients, 0)
  6171. for i := 0; i < len(patient); i++ {
  6172. repeat := false
  6173. for j := i + 1; j < len(patient); j++ {
  6174. if patient[i].ID == patient[j].ID {
  6175. repeat = true
  6176. break
  6177. }
  6178. }
  6179. if !repeat {
  6180. newArr = append(newArr, patient[i])
  6181. }
  6182. }
  6183. return
  6184. }
  6185. func (c *HisApiController) GetHisChargePatientInfo() {
  6186. patient_id, _ := c.GetInt64("patient_id")
  6187. his_patient_id, _ := c.GetInt64("his_patient_id")
  6188. record_date := c.GetString("record_date")
  6189. //start_time := c.GetString("start_time")
  6190. //end_time := c.GetString("end_time")
  6191. order_status, _ := c.GetInt64("type", 0)
  6192. p_type, _ := c.GetInt64("p_type", 0)
  6193. order_id, _ := c.GetInt64("order_id", 0)
  6194. timeLayout := "2006-01-02"
  6195. loc, _ := time.LoadLocation("Local")
  6196. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6197. if err != nil {
  6198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6199. return
  6200. }
  6201. recordDateTime := theTime.Unix()
  6202. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6203. //if err != nil {
  6204. //
  6205. //}
  6206. //startRecordDateTime := startTime.Unix()
  6207. //
  6208. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6209. //if err != nil {
  6210. //
  6211. //}
  6212. //endRecordDateTime := endTime.Unix()
  6213. admin := c.GetAdminUserInfo()
  6214. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6215. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6216. var prescriptions []*models.HisPrescription
  6217. //var unChargeMonthPrescriptions []*models.HisPrescription
  6218. order, _ := service.GetHisOrderByID(order_id)
  6219. if order_status == 1 || order_status == 0 {
  6220. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  6221. } else if order_status == 2 {
  6222. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  6223. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6224. }
  6225. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6226. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6227. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6228. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6229. //获取所有科室信息
  6230. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6231. c.ServeSuccessJSON(map[string]interface{}{
  6232. "his_info": his_patient_info,
  6233. "xt_info": xt_patient_info,
  6234. "prescription": prescriptions,
  6235. "case_history": case_history,
  6236. "info": patientPrescriptionInfo,
  6237. "last_info": lastPatientPrescriptionInfo,
  6238. "order": order,
  6239. "doctors": doctors,
  6240. "department": department,
  6241. })
  6242. return
  6243. }
  6244. func (c *HisApiController) GetAllOrderDetail() {
  6245. order_id, _ := c.GetInt64("id", 0)
  6246. order, _ := service.GetHisOrderByID(order_id)
  6247. if order.ID == 0 {
  6248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6249. return
  6250. }
  6251. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6252. org_id := c.GetAdminUserInfo().CurrentOrgId
  6253. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6254. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  6255. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6256. c.ServeSuccessJSON(map[string]interface{}{
  6257. "order": order,
  6258. "order_info": order_info,
  6259. "patient": patient,
  6260. "admin_info": adminInfo,
  6261. "hospital_record": record,
  6262. })
  6263. return
  6264. }
  6265. func (c *HisApiController) GetAllOrderDetailCollect() {
  6266. order_id, _ := c.GetInt64("id", 0)
  6267. order, _ := service.GetHisOrderByID(order_id)
  6268. if order.ID == 0 {
  6269. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6270. return
  6271. }
  6272. org_id := c.GetAdminUserInfo().CurrentOrgId
  6273. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6274. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6275. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  6276. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  6277. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  6278. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6279. var bedCostTotal float64 = 0 //床位总费
  6280. //var bedCostSelfTotal float64 = 0 //床位自费
  6281. var operationCostTotal float64 = 0 //手术费
  6282. //var operationCostSelfTotal float64 = 0 //手术费
  6283. var otherCostTotal float64 = 0 //其他费用
  6284. //var otherCostSelfTotal float64 = 0 //其他费用
  6285. var materialCostTotal float64 = 0 //材料费
  6286. //var materialCostSelfTotal float64 = 0 //材料费
  6287. var westernMedicineCostTotal float64 = 0 //西药费
  6288. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  6289. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  6290. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  6291. var checkCostTotal float64 = 0 //检查费
  6292. //var checkCostSelfTotal float64 = 0 //检查费
  6293. var laboratoryCostTotal float64 = 0 //化验费
  6294. //var laboratoryCostSelfTotal float64 = 0 //化验费
  6295. var treatCostTotal float64 = 0 //治疗费用
  6296. //var treatCostSelfTotal float64 = 0 //治疗费用
  6297. var zhenChaCostTotal float64 = 0 //其他费用
  6298. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  6299. decimal.DivisionPrecision = 2
  6300. var BalanceAccountsType int64
  6301. if his.ID > 0 {
  6302. BalanceAccountsType = his.BalanceAccountsType
  6303. } else {
  6304. BalanceAccountsType = record.BalanceAccountsType
  6305. }
  6306. if BalanceAccountsType != 2 {
  6307. for _, item := range order_info {
  6308. if org_id == 10215 {
  6309. if item.MedChrgitmType == "01" { //床位费
  6310. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6311. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6312. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6313. }
  6314. if item.MedChrgitmType == "02" { //诊察费
  6315. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6316. //zhenChaCostSelfTotal = zhenChaCostTotal
  6317. }
  6318. if item.MedChrgitmType == "03" { //检查费
  6319. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6320. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6321. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6322. }
  6323. //if item.MedChrgitmType == "02" { //检查费
  6324. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6325. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6326. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6327. //}
  6328. if item.MedChrgitmType == "04" { //化验费
  6329. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6330. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6331. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6332. }
  6333. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6334. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6335. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6336. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6337. }
  6338. if item.MedChrgitmType == "06" { //手术费
  6339. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6340. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6341. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6342. }
  6343. if item.MedChrgitmType == "08" { //材料费
  6344. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6345. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6346. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6347. }
  6348. if item.MedChrgitmType == "09" { //西药费
  6349. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6350. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6351. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6352. }
  6353. if item.MedChrgitmType == "11" { //中成费
  6354. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6355. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6356. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6357. }
  6358. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  6359. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6360. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6361. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6362. }
  6363. } else if org_id == 10188 || org_id == 10217 {
  6364. if item.MedChrgitmType == "01" { //床位费
  6365. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6366. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6367. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6368. }
  6369. if item.MedChrgitmType == "02" { //诊察费
  6370. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6371. //zhenChaCostSelfTotal = zhenChaCostTotal
  6372. }
  6373. if item.MedChrgitmType == "03" { //检查费
  6374. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6375. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6376. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6377. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6378. }
  6379. //if item.MedChrgitmType == "02" { //检查费
  6380. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6381. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6382. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6383. //}
  6384. if item.MedChrgitmType == "04" { //化验费
  6385. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6386. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6387. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6388. }
  6389. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6390. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6391. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6392. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6393. }
  6394. if item.MedChrgitmType == "06" { //手术费
  6395. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6396. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6397. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6398. }
  6399. if item.MedChrgitmType == "08" { //材料费
  6400. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6401. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6402. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6403. }
  6404. if item.MedChrgitmType == "09" { //西药费
  6405. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6406. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6407. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6408. }
  6409. if item.MedChrgitmType == "11" { //中成费
  6410. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6411. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6412. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6413. }
  6414. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  6415. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6416. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6417. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6418. }
  6419. } else {
  6420. if item.MedChrgitmType == "01" { //床位费
  6421. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6422. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6423. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6424. }
  6425. //if item.MedChrgitmType == "02" { //诊察费
  6426. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6427. // //zhenChaCostSelfTotal = zhenChaCostTotal
  6428. //}
  6429. if item.MedChrgitmType == "03" { //检查费
  6430. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6431. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6432. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6433. }
  6434. //if item.MedChrgitmType == "02" { //检查费
  6435. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6436. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6437. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6438. //}
  6439. if item.MedChrgitmType == "04" { //化验费
  6440. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6441. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6442. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6443. }
  6444. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6445. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6446. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6447. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6448. }
  6449. if item.MedChrgitmType == "06" { //手术费
  6450. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6451. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6452. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6453. }
  6454. if item.MedChrgitmType == "08" { //材料费
  6455. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6456. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6457. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6458. }
  6459. if item.MedChrgitmType == "09" { //西药费
  6460. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6461. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6462. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6463. }
  6464. if item.MedChrgitmType == "11" { //中成费
  6465. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6466. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6467. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6468. }
  6469. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  6470. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6471. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6472. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6473. }
  6474. }
  6475. }
  6476. c.ServeSuccessJSON(map[string]interface{}{
  6477. "order": order,
  6478. "order_info": order_info,
  6479. "patient": patient,
  6480. "admin_info": adminInfo,
  6481. "his_hospital": record,
  6482. "bedCostTotal": bedCostTotal,
  6483. "operationCostTotal": operationCostTotal,
  6484. "otherCostTotal": otherCostTotal,
  6485. "materialCostTotal": materialCostTotal,
  6486. "westernMedicineCostTotal": westernMedicineCostTotal,
  6487. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  6488. "checkCostTotal": checkCostTotal,
  6489. "zhenChaCostTotal": zhenChaCostTotal,
  6490. "laboratoryCostTotal": laboratoryCostTotal,
  6491. "treatCostTotal": treatCostTotal,
  6492. })
  6493. } else {
  6494. for _, item := range order_info {
  6495. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  6496. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  6497. item.MedChrgitmType = "09"
  6498. }
  6499. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  6500. if item.HisPrescriptionProject.Type == 2 {
  6501. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  6502. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  6503. case 0:
  6504. item.MedChrgitmType = "0"
  6505. break
  6506. case 1:
  6507. item.MedChrgitmType = "14"
  6508. break
  6509. case 2:
  6510. item.MedChrgitmType = "05"
  6511. break
  6512. case 3:
  6513. item.MedChrgitmType = "03"
  6514. break
  6515. case 4:
  6516. item.MedChrgitmType = "03"
  6517. break
  6518. case 5:
  6519. item.MedChrgitmType = "08"
  6520. break
  6521. case 6:
  6522. item.MedChrgitmType = "14"
  6523. break
  6524. case 7:
  6525. item.MedChrgitmType = "14"
  6526. break
  6527. case 8:
  6528. item.MedChrgitmType = "03"
  6529. break
  6530. case 9:
  6531. item.MedChrgitmType = "14"
  6532. break
  6533. case 10:
  6534. item.MedChrgitmType = "14"
  6535. break
  6536. case 11:
  6537. item.MedChrgitmType = "06"
  6538. break
  6539. case 12:
  6540. item.MedChrgitmType = "12"
  6541. break
  6542. case 13:
  6543. item.MedChrgitmType = "01"
  6544. break
  6545. case 14:
  6546. item.MedChrgitmType = "04"
  6547. break
  6548. case 15:
  6549. item.MedChrgitmType = "14"
  6550. break
  6551. }
  6552. } else {
  6553. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  6554. case 1:
  6555. item.MedChrgitmType = "14"
  6556. break
  6557. case 2:
  6558. item.MedChrgitmType = "05"
  6559. break
  6560. case 3:
  6561. item.MedChrgitmType = "04"
  6562. break
  6563. case 4:
  6564. item.MedChrgitmType = "14"
  6565. break
  6566. case 5:
  6567. item.MedChrgitmType = "08"
  6568. break
  6569. case 6:
  6570. item.MedChrgitmType = "14"
  6571. break
  6572. case 7:
  6573. item.MedChrgitmType = "14"
  6574. break
  6575. case 8:
  6576. item.MedChrgitmType = "03"
  6577. break
  6578. case 9:
  6579. item.MedChrgitmType = "14"
  6580. break
  6581. }
  6582. }
  6583. } else if item.HisPrescriptionProject.Type == 3 {
  6584. item.MedChrgitmType = "08"
  6585. }
  6586. }
  6587. }
  6588. for _, item := range order_info {
  6589. if org_id == 10215 {
  6590. if item.MedChrgitmType == "01" { //床位费
  6591. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6592. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6593. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6594. }
  6595. if item.MedChrgitmType == "02" { //诊察费
  6596. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6597. //zhenChaCostSelfTotal = zhenChaCostTotal
  6598. }
  6599. if item.MedChrgitmType == "03" { //检查费
  6600. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6601. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6602. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6603. }
  6604. //if item.MedChrgitmType == "02" { //检查费
  6605. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6606. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6607. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6608. //}
  6609. if item.MedChrgitmType == "04" { //化验费
  6610. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6611. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6612. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6613. }
  6614. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6615. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6616. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6617. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6618. }
  6619. if item.MedChrgitmType == "06" { //手术费
  6620. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6621. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6622. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6623. }
  6624. if item.MedChrgitmType == "08" { //材料费
  6625. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6626. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6627. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6628. }
  6629. if item.MedChrgitmType == "09" { //西药费
  6630. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6631. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6632. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6633. }
  6634. if item.MedChrgitmType == "11" { //中成费
  6635. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6636. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6637. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6638. }
  6639. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  6640. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6641. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6642. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6643. }
  6644. } else {
  6645. if item.MedChrgitmType == "01" { //床位费
  6646. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6647. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6648. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6649. }
  6650. //if item.MedChrgitmType == "02" { //诊察费
  6651. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6652. // //zhenChaCostSelfTotal = zhenChaCostTotal
  6653. //}
  6654. if item.MedChrgitmType == "03" { //检查费
  6655. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6656. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6657. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6658. }
  6659. //if item.MedChrgitmType == "02" { //检查费
  6660. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6661. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6662. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6663. //}
  6664. if item.MedChrgitmType == "04" { //化验费
  6665. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6666. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6667. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6668. }
  6669. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6670. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6671. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6672. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6673. }
  6674. if item.MedChrgitmType == "06" { //手术费
  6675. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6676. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6677. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6678. }
  6679. if item.MedChrgitmType == "08" { //材料费
  6680. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6681. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6682. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6683. }
  6684. if item.MedChrgitmType == "09" { //西药费
  6685. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6686. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6687. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6688. }
  6689. if item.MedChrgitmType == "11" { //中成费
  6690. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6691. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6692. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6693. }
  6694. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  6695. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6696. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6697. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6698. }
  6699. }
  6700. }
  6701. c.ServeSuccessJSON(map[string]interface{}{
  6702. "order": order,
  6703. "order_info": order_info,
  6704. "patient": patient,
  6705. "admin_info": adminInfo,
  6706. "his_hospital": record,
  6707. "bedCostTotal": bedCostTotal,
  6708. "operationCostTotal": operationCostTotal,
  6709. "otherCostTotal": otherCostTotal,
  6710. "materialCostTotal": materialCostTotal,
  6711. "westernMedicineCostTotal": westernMedicineCostTotal,
  6712. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  6713. "checkCostTotal": checkCostTotal,
  6714. "zhenChaCostTotal": zhenChaCostTotal,
  6715. "laboratoryCostTotal": laboratoryCostTotal,
  6716. "treatCostTotal": treatCostTotal,
  6717. })
  6718. }
  6719. }
  6720. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  6721. page, _ := c.GetInt64("page")
  6722. limit, _ := c.GetInt64("limit")
  6723. keywords := c.GetString("keywords")
  6724. start_time := c.GetString("start_time")
  6725. end_time := c.GetString("end_time")
  6726. //clr_type := c.GetString("clr_type")
  6727. insutype := c.GetString("insutype")
  6728. timeLayout := "2006-01-02"
  6729. loc, _ := time.LoadLocation("Local")
  6730. var theStartTIme int64
  6731. if len(start_time) > 0 {
  6732. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6733. theStartTIme = theTime.Unix()
  6734. }
  6735. var theEndtTIme int64
  6736. if len(end_time) > 0 {
  6737. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6738. theEndtTIme = theTime.Unix()
  6739. }
  6740. if page <= 0 {
  6741. page = 1
  6742. }
  6743. if limit <= 0 {
  6744. limit = 10
  6745. }
  6746. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  6747. c.ServeSuccessJSON(map[string]interface{}{
  6748. "total": total,
  6749. "list": list,
  6750. })
  6751. return
  6752. }
  6753. func (c *HisApiController) GetPutOnRecordList() {
  6754. page, _ := c.GetInt64("page")
  6755. limit, _ := c.GetInt64("limit")
  6756. keywords := c.GetString("keywords")
  6757. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  6758. if page <= 0 {
  6759. page = 1
  6760. }
  6761. if limit <= 0 {
  6762. limit = 10
  6763. }
  6764. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  6765. c.ServeSuccessJSON(map[string]interface{}{
  6766. "total": total,
  6767. "list": list,
  6768. })
  6769. return
  6770. }
  6771. func (c *HisApiController) GetCompareData() {
  6772. start_time := c.GetString("start_time")
  6773. end_time := c.GetString("end_time")
  6774. insutype := c.GetString("insutype")
  6775. clr_type := c.GetString("clr_type")
  6776. timeLayout := "2006-01-02"
  6777. loc, _ := time.LoadLocation("Local")
  6778. var theStartTIme int64
  6779. if len(start_time) > 0 {
  6780. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6781. if err != nil {
  6782. theStartTIme = 0
  6783. }
  6784. theStartTIme = theTime.Unix()
  6785. }
  6786. var theEndtTIme int64
  6787. if len(end_time) > 0 {
  6788. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6789. if err != nil {
  6790. theEndtTIme = 0
  6791. }
  6792. theEndtTIme = theTime.Unix()
  6793. }
  6794. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  6795. fmt.Println(err)
  6796. if err == nil {
  6797. c.ServeSuccessJSON(map[string]interface{}{
  6798. "list": formData,
  6799. })
  6800. } else {
  6801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6802. return
  6803. }
  6804. }
  6805. func (c *HisApiController) GetFaPiaoData() {
  6806. order_id, _ := c.GetInt64("order_id")
  6807. patient_id, _ := c.GetInt64("patient_id")
  6808. number := c.GetString("number")
  6809. adminUser := c.GetAdminUserInfo()
  6810. order, _ := service.GetHisOrderByID(order_id)
  6811. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  6812. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  6813. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  6814. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, number)
  6815. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6816. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  6817. var bedCostTotal float64 = 0 //床位总费
  6818. var bedCostSelfTotal float64 = 0 //床位自费
  6819. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  6820. var operationCostTotal float64 = 0 //手术费
  6821. var operationCostSelfTotal float64 = 0 //手术费
  6822. var operationCostPartSelfTotal float64 = 0 //手术费
  6823. var otherCostTotal float64 = 0 //其他费用
  6824. var otherCostSelfTotal float64 = 0 //其他费用
  6825. var otherCostPartSelfTotal float64 = 0 //其他费用
  6826. var materialCostTotal float64 = 0 //材料费
  6827. var materialCostSelfTotal float64 = 0 //材料费
  6828. var materialCostPartSelfTotal float64 = 0 //材料费
  6829. var westernMedicineCostTotal float64 = 0 //西药费
  6830. var westernMedicineCostSelfTotal float64 = 0 //西药费
  6831. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  6832. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  6833. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  6834. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  6835. var checkCostTotal float64 = 0 //检查费
  6836. var checkCostSelfTotal float64 = 0 //检查费
  6837. var checkCostPartSelfTotal float64 = 0 //检查费
  6838. var laboratoryCostTotal float64 = 0 //化验费
  6839. var laboratoryCostSelfTotal float64 = 0 //化验费
  6840. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  6841. var treatCostTotal float64 = 0 //治疗费用
  6842. var treatCostSelfTotal float64 = 0 //治疗费用
  6843. var treatCostPartSelfTotal float64 = 0 //治疗费用
  6844. var zhenChaCostTotal float64 = 0 //其他费用
  6845. var zhenChaCostSelfTotal float64 = 0 //其他费用
  6846. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  6847. decimal.DivisionPrecision = 2
  6848. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  6849. var balanceAccountsType int64
  6850. if his.ID > 0 {
  6851. balanceAccountsType = his.BalanceAccountsType
  6852. } else {
  6853. balanceAccountsType = his_hospital_record.BalanceAccountsType
  6854. }
  6855. if balanceAccountsType == 2 {
  6856. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  6857. for _, item := range orderInfos_two {
  6858. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  6859. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  6860. item.MedChrgitmType = "09"
  6861. }
  6862. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  6863. if item.HisPrescriptionProject.Type == 2 {
  6864. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  6865. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  6866. case 0:
  6867. item.MedChrgitmType = "0"
  6868. break
  6869. case 1:
  6870. item.MedChrgitmType = "14"
  6871. break
  6872. case 2:
  6873. item.MedChrgitmType = "05"
  6874. break
  6875. case 3:
  6876. item.MedChrgitmType = "03"
  6877. break
  6878. case 4:
  6879. item.MedChrgitmType = "03"
  6880. break
  6881. case 5:
  6882. item.MedChrgitmType = "08"
  6883. break
  6884. case 6:
  6885. item.MedChrgitmType = "14"
  6886. break
  6887. case 7:
  6888. item.MedChrgitmType = "14"
  6889. break
  6890. case 8:
  6891. item.MedChrgitmType = "03"
  6892. break
  6893. case 9:
  6894. item.MedChrgitmType = "14"
  6895. break
  6896. case 10:
  6897. item.MedChrgitmType = "14"
  6898. break
  6899. case 11:
  6900. item.MedChrgitmType = "06"
  6901. break
  6902. case 12:
  6903. item.MedChrgitmType = "12"
  6904. break
  6905. case 13:
  6906. item.MedChrgitmType = "01"
  6907. break
  6908. case 14:
  6909. item.MedChrgitmType = "04"
  6910. break
  6911. case 15:
  6912. item.MedChrgitmType = "02"
  6913. break
  6914. }
  6915. } else {
  6916. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  6917. case 1:
  6918. item.MedChrgitmType = "14"
  6919. break
  6920. case 2:
  6921. item.MedChrgitmType = "05"
  6922. break
  6923. case 3:
  6924. item.MedChrgitmType = "03"
  6925. break
  6926. case 4:
  6927. item.MedChrgitmType = "03"
  6928. break
  6929. case 5:
  6930. item.MedChrgitmType = "08"
  6931. break
  6932. case 6:
  6933. item.MedChrgitmType = "14"
  6934. break
  6935. case 7:
  6936. item.MedChrgitmType = "14"
  6937. break
  6938. case 8:
  6939. item.MedChrgitmType = "03"
  6940. break
  6941. case 9:
  6942. item.MedChrgitmType = "14"
  6943. break
  6944. }
  6945. }
  6946. } else if item.HisPrescriptionProject.Type == 3 {
  6947. item.MedChrgitmType = "08"
  6948. }
  6949. }
  6950. }
  6951. for _, item := range orderInfos_two {
  6952. fmt.Println(item.MedChrgitmType)
  6953. if item.MedChrgitmType == "01" { //床位费
  6954. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6955. bedCostSelfTotal = bedCostTotal
  6956. }
  6957. if item.MedChrgitmType == "02" { //诊察费
  6958. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6959. zhenChaCostSelfTotal = zhenChaCostTotal
  6960. }
  6961. if item.MedChrgitmType == "03" { //检查费
  6962. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6963. checkCostSelfTotal = checkCostTotal
  6964. }
  6965. if item.MedChrgitmType == "04" { //化验费
  6966. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6967. laboratoryCostSelfTotal = laboratoryCostTotal
  6968. }
  6969. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  6970. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6971. treatCostSelfTotal = treatCostTotal
  6972. }
  6973. if item.MedChrgitmType == "06" { //手术费
  6974. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6975. operationCostSelfTotal = treatCostTotal
  6976. }
  6977. if item.MedChrgitmType == "08" { //材料费
  6978. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6979. materialCostSelfTotal = materialCostTotal
  6980. }
  6981. if item.MedChrgitmType == "09" { //西药费
  6982. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6983. westernMedicineCostSelfTotal = westernMedicineCostTotal
  6984. }
  6985. if item.MedChrgitmType == "11" { //中成费
  6986. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6987. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  6988. }
  6989. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  6990. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  6991. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6992. otherCostSelfTotal = otherCostTotal
  6993. }
  6994. } else {
  6995. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  6996. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6997. otherCostSelfTotal = otherCostTotal
  6998. }
  6999. }
  7000. }
  7001. } else {
  7002. for _, item := range orderInfos {
  7003. if item.MedChrgitmType == "01" { //床位费
  7004. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7005. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7006. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7007. }
  7008. if item.MedChrgitmType == "02" { //诊察费
  7009. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7010. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7011. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7012. }
  7013. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  7014. if item.MedChrgitmType == "03" { //检查费
  7015. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7016. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7017. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7018. }
  7019. } else {
  7020. if item.MedChrgitmType == "03" { //检查费
  7021. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7022. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7023. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7024. }
  7025. }
  7026. if item.MedChrgitmType == "04" { //化验费
  7027. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7028. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7029. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7030. }
  7031. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7032. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7033. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7034. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7035. }
  7036. if item.MedChrgitmType == "06" { //手术费
  7037. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7038. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7039. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7040. }
  7041. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  7042. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7043. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7044. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7045. }
  7046. if item.MedChrgitmType == "09" { //西药费
  7047. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7048. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7049. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7050. }
  7051. if item.MedChrgitmType == "11" { //中成费
  7052. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7053. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7054. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7055. }
  7056. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7057. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7058. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7059. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7060. }
  7061. }
  7062. }
  7063. timeLayout := "2006-01-02"
  7064. loc, _ := time.LoadLocation("Local")
  7065. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  7066. if err != nil {
  7067. }
  7068. startRecordDateTime := startTime.Unix()
  7069. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  7070. if err != nil {
  7071. }
  7072. endRecordDateTime := endTime.Unix()
  7073. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  7074. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  7075. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  7076. c.ServeSuccessJSON(map[string]interface{}{
  7077. "order_number": order.Number, //业务流水号
  7078. "id_card_no": his.IdCardNo, //社会保障号
  7079. "department_name": department.Name, //科室
  7080. "number": his.Number, //门诊号
  7081. "date": order.SettleAccountsDate, //结算日期
  7082. "name": order.PsnName, //姓名
  7083. "gender": patient.Gender, //性别
  7084. "psn_cash_money": order.PsnCashPay, //个人支付
  7085. "pay_way": "门诊", //结算方式
  7086. "medfee_sumamt": order.MedfeeSumamt, //总费用
  7087. "admin_user_name": admin.UserName, //收款员
  7088. "order": order,
  7089. "order_info": orderInfos_two,
  7090. "his": his,
  7091. "bedCostTotal": bedCostTotal,
  7092. "bedCostSelfTotal": bedCostSelfTotal,
  7093. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  7094. "operationCostTotal": operationCostTotal,
  7095. "operationCostSelfTotal": operationCostSelfTotal,
  7096. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  7097. "otherCostTotal": otherCostTotal,
  7098. "otherCostSelfTotal": otherCostSelfTotal,
  7099. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  7100. "materialCostTotal": materialCostTotal,
  7101. "materialCostSelfTotal": materialCostSelfTotal,
  7102. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  7103. "westernMedicineCostTotal": westernMedicineCostTotal,
  7104. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  7105. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  7106. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7107. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  7108. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  7109. "checkCostTotal": checkCostTotal,
  7110. "checkCostSelfTotal": checkCostSelfTotal,
  7111. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  7112. "laboratoryCostTotal": laboratoryCostTotal,
  7113. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  7114. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  7115. "treatCostTotal": treatCostTotal,
  7116. "treatCostSelfTotal": treatCostSelfTotal,
  7117. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  7118. "zhenChaCostTotal": zhenChaCostTotal,
  7119. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  7120. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  7121. "his_hospital_record": his_hospital_record,
  7122. "pre_pay_money": pre_pay_money,
  7123. "refund_sum": sum,
  7124. })
  7125. }
  7126. func (this *HisApiController) GetIncomeStatisticsData() {
  7127. start_time := this.GetString("start_time")
  7128. end_time := this.GetString("end_time")
  7129. key_words := this.GetString("key_words")
  7130. limit, _ := this.GetInt64("limit")
  7131. page, _ := this.GetInt64("page")
  7132. if page <= 0 {
  7133. page = 1
  7134. }
  7135. if limit <= 0 {
  7136. limit = 10
  7137. }
  7138. statistics_type, _ := this.GetInt64("statistics_type")
  7139. admin := this.GetAdminUserInfo()
  7140. timeLayout := "2006-01-02"
  7141. loc, _ := time.LoadLocation("Local")
  7142. var theStartTIme int64
  7143. if len(start_time) > 0 {
  7144. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7145. if err != nil {
  7146. theStartTIme = 0
  7147. }
  7148. theStartTIme = theTime.Unix()
  7149. }
  7150. var theEndtTIme int64
  7151. if len(end_time) > 0 {
  7152. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7153. if err != nil {
  7154. theEndtTIme = 0
  7155. }
  7156. theEndtTIme = theTime.Unix()
  7157. }
  7158. if statistics_type == 1 {
  7159. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  7160. this.ServeSuccessJSON(map[string]interface{}{
  7161. "list": list,
  7162. "total": total,
  7163. })
  7164. } else {
  7165. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  7166. this.ServeSuccessJSON(map[string]interface{}{
  7167. "list": list,
  7168. "total": total,
  7169. })
  7170. }
  7171. }
  7172. func (c *HisApiController) PostProjectInformation() {
  7173. adminUser := c.GetAdminUserInfo()
  7174. orgId := adminUser.CurrentOrgId
  7175. dataBody := make(map[string]interface{}, 0)
  7176. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7177. if err != nil {
  7178. utils.ErrorLog(err.Error())
  7179. return
  7180. }
  7181. utils.ErrorLog("%v", dataBody)
  7182. var projectList []*models.HisProject
  7183. var total_goods []interface{}
  7184. tempProjects := dataBody["projects"].([]interface{})
  7185. total_goods = tempProjects
  7186. for index, projectMap := range tempProjects {
  7187. projectM := projectMap.(map[string]interface{})
  7188. var project models.HisProject
  7189. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  7190. utils.ErrorLog("project_name")
  7191. return
  7192. }
  7193. project_name, _ := projectM["project_name"].(string)
  7194. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  7195. err_log := models.ExportErrLog{
  7196. LogType: 6,
  7197. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7198. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  7199. Status: 1,
  7200. CreateTime: time.Now().Unix(),
  7201. UpdateTime: time.Now().Unix(),
  7202. ExportTime: time.Now().Unix(),
  7203. }
  7204. service.CreateExportErrLog(&err_log)
  7205. continue
  7206. }
  7207. project.ProjectName = project_name
  7208. prices := projectM["price"].(string)
  7209. price, _ := strconv.ParseFloat(prices, 64)
  7210. if price <= 0 { //名字为空则生成一条导入错误日志
  7211. err_log := models.ExportErrLog{
  7212. LogType: 6,
  7213. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7214. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  7215. Status: 1,
  7216. CreateTime: time.Now().Unix(),
  7217. UpdateTime: time.Now().Unix(),
  7218. ExportTime: time.Now().Unix(),
  7219. }
  7220. service.CreateExportErrLog(&err_log)
  7221. continue
  7222. }
  7223. project.Price = price
  7224. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  7225. utils.ErrorLog("unit_id")
  7226. return
  7227. }
  7228. unit := projectM["unit"].(string)
  7229. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  7230. err_log := models.ExportErrLog{
  7231. LogType: 6,
  7232. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7233. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  7234. Status: 1,
  7235. CreateTime: time.Now().Unix(),
  7236. UpdateTime: time.Now().Unix(),
  7237. ExportTime: time.Now().Unix(),
  7238. }
  7239. service.CreateExportErrLog(&err_log)
  7240. continue
  7241. }
  7242. project.Unit = unit
  7243. cost_classify := projectM["cost_classify"].(string)
  7244. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  7245. err_log := models.ExportErrLog{
  7246. LogType: 6,
  7247. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7248. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  7249. Status: 1,
  7250. CreateTime: time.Now().Unix(),
  7251. UpdateTime: time.Now().Unix(),
  7252. ExportTime: time.Now().Unix(),
  7253. }
  7254. service.CreateExportErrLog(&err_log)
  7255. continue
  7256. }
  7257. var costClassify = "费用类别"
  7258. var cost_classify_id int64
  7259. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  7260. if len(cost_classify) != 0 {
  7261. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  7262. if errcode == gorm.ErrRecordNotFound {
  7263. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  7264. dataconfig := models.DictDataconfig{
  7265. ParentId: costClassifyConfig.ID,
  7266. Module: "system",
  7267. OrgId: orgId,
  7268. Name: cost_classify,
  7269. FieldName: "",
  7270. Value: costConfig.Value + 1,
  7271. CreatedTime: "",
  7272. UpdatedTime: "",
  7273. CreateUserId: adminUser.AdminUser.Id,
  7274. Status: 1,
  7275. Remark: "",
  7276. DeleteIdSystem: 0,
  7277. Title: "",
  7278. Content: "",
  7279. Order: 0,
  7280. Code: "",
  7281. }
  7282. service.CreatedDicConfig(&dataconfig)
  7283. }
  7284. }
  7285. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  7286. for _, it := range costClassList {
  7287. if cost_classify == it.Name {
  7288. cost_classify_id = int64(it.Value)
  7289. }
  7290. }
  7291. project.CostClassify = cost_classify_id
  7292. executive_section := projectM["executive_section"].(string)
  7293. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  7294. err_log := models.ExportErrLog{
  7295. LogType: 6,
  7296. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7297. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  7298. Status: 1,
  7299. CreateTime: time.Now().Unix(),
  7300. UpdateTime: time.Now().Unix(),
  7301. ExportTime: time.Now().Unix(),
  7302. }
  7303. service.CreateExportErrLog(&err_log)
  7304. continue
  7305. }
  7306. if len(executive_section) != 0 {
  7307. //查找科室是否有内容
  7308. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  7309. if errcodedepart == gorm.ErrRecordNotFound {
  7310. department := models.XtHisDepartment{
  7311. Name: executive_section,
  7312. Status: 1,
  7313. UserOrgId: adminUser.CurrentOrgId,
  7314. CreatedTime: time.Now().Unix(),
  7315. }
  7316. service.CreateDePartment(&department)
  7317. }
  7318. }
  7319. var executive_section_id int64
  7320. departMentList, _ := service.GetAllDepartMent(orgId)
  7321. for _, it := range departMentList {
  7322. if executive_section == it.Name {
  7323. executive_section_id = it.ID
  7324. }
  7325. }
  7326. project.ExecutiveSection = executive_section_id
  7327. medical_coverage := projectM["medical_coverage"].(string)
  7328. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  7329. err_log := models.ExportErrLog{
  7330. LogType: 6,
  7331. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7332. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  7333. Status: 1,
  7334. CreateTime: time.Now().Unix(),
  7335. UpdateTime: time.Now().Unix(),
  7336. ExportTime: time.Now().Unix(),
  7337. }
  7338. service.CreateExportErrLog(&err_log)
  7339. continue
  7340. }
  7341. var medicalCoverage = "医保等级"
  7342. var medical_coverage_id int64
  7343. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  7344. if len(medical_coverage) != 0 {
  7345. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  7346. if errormedicalcoverage == gorm.ErrRecordNotFound {
  7347. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  7348. dataconfig := models.DictDataconfig{
  7349. ParentId: medicalCoverageConfig.ID,
  7350. Module: "system",
  7351. OrgId: orgId,
  7352. Name: medical_coverage,
  7353. FieldName: "",
  7354. Value: medicalCoverageConfig.Value + 1,
  7355. CreatedTime: "",
  7356. UpdatedTime: "",
  7357. CreateUserId: adminUser.AdminUser.Id,
  7358. Status: 1,
  7359. Remark: "",
  7360. DeleteIdSystem: 0,
  7361. Title: "",
  7362. Content: "",
  7363. Order: 0,
  7364. Code: "",
  7365. }
  7366. service.CreatedDicConfig(&dataconfig)
  7367. }
  7368. }
  7369. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  7370. for _, it := range medicalCoverageList {
  7371. if medical_coverage == it.Name {
  7372. medical_coverage_id = int64(it.Value)
  7373. }
  7374. }
  7375. project.MedicalCoverage = medical_coverage_id
  7376. pinyin := projectM["pinyin"].(string)
  7377. project.Pinyin = pinyin
  7378. wubi := projectM["wubi"].(string)
  7379. project.Wubi = wubi
  7380. statistical_classification := projectM["statistical_classification"].(string)
  7381. var statisticalClassification = "统计分类"
  7382. var statistical_classification_id int64
  7383. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  7384. if len(statistical_classification) != 0 {
  7385. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  7386. if classificationerrcodes == gorm.ErrRecordNotFound {
  7387. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  7388. dataconfig := models.DictDataconfig{
  7389. ParentId: classiFication.ID,
  7390. Module: "system",
  7391. OrgId: orgId,
  7392. Name: statistical_classification,
  7393. FieldName: "",
  7394. Value: classiFicationConfig.Value + 1,
  7395. CreatedTime: "",
  7396. UpdatedTime: "",
  7397. CreateUserId: adminUser.AdminUser.Id,
  7398. Status: 1,
  7399. Remark: "",
  7400. DeleteIdSystem: 0,
  7401. Title: "",
  7402. Content: "",
  7403. Order: 0,
  7404. Code: "",
  7405. }
  7406. service.CreatedDicConfig(&dataconfig)
  7407. }
  7408. }
  7409. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  7410. for _, it := range classiFicationList {
  7411. if statistical_classification == it.Name {
  7412. statistical_classification_id = int64(it.Value)
  7413. }
  7414. }
  7415. project.StatisticalClassification = statistical_classification_id
  7416. disease_directory := int64(projectM["disease_directory"].(float64))
  7417. project.DiseaseDirectory = disease_directory
  7418. is_record := int64(projectM["is_record"].(float64))
  7419. project.IsRecord = is_record
  7420. medical_code := projectM["medical_code"].(string)
  7421. project.MedicalCode = medical_code
  7422. tube_color := projectM["tube_color"].(string)
  7423. var tubeColor = "试管颜色"
  7424. var tube_color_id int64
  7425. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  7426. if len(tube_color) != 0 {
  7427. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  7428. if errcodetube == gorm.ErrRecordNotFound {
  7429. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  7430. dataconfig := models.DictDataconfig{
  7431. ParentId: tubeColorConfig.ID,
  7432. Module: "system",
  7433. OrgId: orgId,
  7434. Name: tube_color,
  7435. FieldName: "",
  7436. Value: tubeConfig.Value + 1,
  7437. CreatedTime: "",
  7438. UpdatedTime: "",
  7439. CreateUserId: adminUser.AdminUser.Id,
  7440. Status: 1,
  7441. Remark: "",
  7442. DeleteIdSystem: 0,
  7443. Title: "",
  7444. Content: "",
  7445. Order: 0,
  7446. Code: "",
  7447. }
  7448. service.CreatedDicConfig(&dataconfig)
  7449. }
  7450. }
  7451. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  7452. for _, it := range tubeColorList {
  7453. if tube_color == it.Name {
  7454. tube_color_id = int64(it.Value)
  7455. }
  7456. }
  7457. project.TubeColor = tube_color_id
  7458. single_dose := projectM["single_dose"].(string)
  7459. project.SingleDose = single_dose
  7460. execution_frequency := projectM["execution_frequency"].(string)
  7461. project.ExecutionFrequency = execution_frequency
  7462. delivery_way := projectM["delivery_way"].(string)
  7463. project.DeliveryWay = delivery_way
  7464. number_days := projectM["number_days"].(string)
  7465. project.NumberDays = number_days
  7466. total := projectM["total"].(string)
  7467. project.Total = total
  7468. medical_status := int64(projectM["medical_status"].(float64))
  7469. project.MedicalStatus = medical_status
  7470. category := int64(projectM["category"].(float64))
  7471. project.Category = category
  7472. specail_project := int64(projectM["specail_project"].(float64))
  7473. project.SpecailProject = specail_project
  7474. social_security_directory_code := projectM["social_security_directory_code"].(string)
  7475. project.SocialSecurityDirectoryCode = social_security_directory_code
  7476. remark := projectM["remark"].(string)
  7477. project.Remark = remark
  7478. record_date := projectM["record_date"].(string)
  7479. timeLayout := "2006-01-02"
  7480. loc, _ := time.LoadLocation("Local")
  7481. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7482. project.RecordDate = theTime.Unix()
  7483. projectList = append(projectList, &project)
  7484. }
  7485. export_time := time.Now().Unix()
  7486. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  7487. if len(projectList) > 0 {
  7488. for _, item := range projectList {
  7489. project := models.HisProject{
  7490. ProjectName: item.ProjectName,
  7491. Price: item.Price,
  7492. Unit: item.Unit,
  7493. CostClassify: item.CostClassify,
  7494. ExecutiveSection: item.ExecutiveSection,
  7495. MedicalCoverage: item.MedicalCoverage,
  7496. UserOrgId: orgId,
  7497. Status: 1,
  7498. CreatedTime: time.Now().Unix(),
  7499. Pinyin: item.Pinyin,
  7500. Wubi: item.Wubi,
  7501. StatisticalClassification: item.StatisticalClassification,
  7502. DiseaseDirectory: item.DiseaseDirectory,
  7503. IsRecord: item.IsRecord,
  7504. MedicalCode: item.MedicalCode,
  7505. TubeColor: item.TubeColor,
  7506. SingleDose: item.SingleDose,
  7507. DeliveryWay: item.DeliveryWay,
  7508. NumberDays: item.NumberDays,
  7509. Total: item.Total,
  7510. Category: item.Category,
  7511. MedicalStatus: item.MedicalStatus,
  7512. SpecailProject: item.SpecailProject,
  7513. RecordDate: item.RecordDate,
  7514. Remark: item.Remark,
  7515. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  7516. ExecutionFrequency: item.ExecutionFrequency,
  7517. }
  7518. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  7519. if errcodeproject == gorm.ErrRecordNotFound {
  7520. service.CreateProjectInfomation(&project)
  7521. } else if errcodeproject == nil {
  7522. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  7523. }
  7524. log := models.ExportLog{
  7525. LogType: 6,
  7526. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7527. TotalNum: int64(len(total_goods)),
  7528. FailNum: int64(len(errLogs)),
  7529. SuccessNum: int64(len(projectList)),
  7530. CreateTime: time.Now().Unix(),
  7531. UpdateTime: time.Now().Unix(),
  7532. ExportTime: export_time,
  7533. Status: 1,
  7534. }
  7535. service.CreateExportLog(&log)
  7536. c.ServeSuccessJSON(map[string]interface{}{
  7537. "msg": "导入成功",
  7538. "total_num": len(total_goods),
  7539. "success_num": len(projectList),
  7540. "fail_num": int64(len(errLogs)),
  7541. })
  7542. }
  7543. } else {
  7544. log := models.ExportLog{
  7545. LogType: 6,
  7546. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7547. TotalNum: int64(len(total_goods)),
  7548. FailNum: int64(len(errLogs)),
  7549. SuccessNum: int64(len(projectList)),
  7550. CreateTime: time.Now().Unix(),
  7551. UpdateTime: time.Now().Unix(),
  7552. ExportTime: export_time,
  7553. Status: 1,
  7554. }
  7555. service.CreateExportLog(&log)
  7556. c.ServeSuccessJSON(map[string]interface{}{
  7557. "msg": "导入成功",
  7558. "total_num": len(total_goods),
  7559. "success_num": len(projectList),
  7560. "fail_num": int64(len(errLogs)),
  7561. })
  7562. }
  7563. }
  7564. //func (this *HisApiController) EditProjectInformation(){
  7565. //
  7566. // id, _ := this.GetInt64("id")
  7567. // project_team := this.GetString("project_team")
  7568. // price := this.GetString("price")
  7569. // price_float, _ := strconv.ParseFloat(price, 64)
  7570. // pinyin := this.GetString("pinyin")
  7571. // wubi := this.GetString("wubi")
  7572. // tube_color, _ := this.GetInt64("tube_color")
  7573. // team_type, _ := this.GetInt64("team_type")
  7574. // remark := this.GetString("remark")
  7575. // ids := this.GetString("ids")
  7576. // item_id := this.GetString("item_id")
  7577. // projectTeam := models.XtHisProjectTeam{
  7578. // ProjectTeam: project_team,
  7579. // Price: price_float,
  7580. // Pinyin: pinyin,
  7581. // Wubi: wubi,
  7582. // TubeColor: tube_color,
  7583. // TeamType: team_type,
  7584. // Remark: remark,
  7585. // ProjectId: ids,
  7586. // ItemId: item_id,
  7587. // }
  7588. //
  7589. //
  7590. // dataBody := make(map[string]interface{}, 0)
  7591. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  7592. // if err != nil {
  7593. // utils.ErrorLog(err.Error())
  7594. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7595. // return
  7596. // }
  7597. //
  7598. // err = service.UpdatedProjectTeam(id, &projectTeam)
  7599. //
  7600. //
  7601. // if err != nil {
  7602. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7603. // return
  7604. // }
  7605. //
  7606. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  7607. // infos, _ := dataBody["info"].([]interface{})
  7608. // if len(infos) > 0 {
  7609. // var ids []string
  7610. //
  7611. // for _, item := range infos {
  7612. // items := item.(map[string]interface{})
  7613. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  7614. // utils.ErrorLog("id")
  7615. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7616. // return
  7617. // }
  7618. // id := int64(items["id"].(float64))
  7619. //
  7620. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  7621. // utils.ErrorLog("type")
  7622. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7623. // return
  7624. // }
  7625. // types := int64(items["type"].(float64))
  7626. //
  7627. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  7628. // utils.ErrorLog("number")
  7629. // }
  7630. //
  7631. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  7632. //
  7633. // projectList := models.XtHisProjectList{
  7634. // Number: number,
  7635. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  7636. // ProjectId: id,
  7637. // Status: 1,
  7638. // CreatedTime: time.Now().Unix(),
  7639. // UpdatedTime: time.Now().Unix(),
  7640. // TeamId: projectTeam.ID,
  7641. // Type: types,
  7642. // }
  7643. // list := projectList
  7644. //
  7645. // service.CreateProjectList(&list)
  7646. //
  7647. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  7648. //
  7649. // }
  7650. // ids_str := strings.Join(ids, ",")
  7651. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  7652. // service.SaveProjectTeam(&projectTeam)
  7653. // this.ServeSuccessJSON(map[string]interface{}{
  7654. // "projectTeam": projectTeam,
  7655. // })
  7656. // }
  7657. // }
  7658. //}
  7659. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  7660. name := c.GetString("name")
  7661. mode_id, _ := c.GetInt64("mode", 0)
  7662. types, _ := c.GetInt64("type", 0)
  7663. patient_id, _ := c.GetInt64("patient_id", 0)
  7664. types = 1
  7665. adminInfo := c.GetAdminUserInfo()
  7666. template := &models.HisPrescriptionTemplate{
  7667. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7668. PatientId: patient_id,
  7669. Type: types,
  7670. Status: 1,
  7671. Ctime: time.Now().Unix(),
  7672. Mtime: time.Now().Unix(),
  7673. Name: name,
  7674. Mode: mode_id,
  7675. }
  7676. dataBody := make(map[string]interface{}, 0)
  7677. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7678. if err != nil {
  7679. utils.ErrorLog(err.Error())
  7680. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7681. return
  7682. }
  7683. err = service.CreateHisPrescriptionTemplate(template)
  7684. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  7685. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  7686. if len(prescriptions) > 0 {
  7687. for _, item := range prescriptions {
  7688. items := item.(map[string]interface{})
  7689. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  7690. utils.ErrorLog("type")
  7691. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7692. return
  7693. }
  7694. types := int64(items["type"].(float64))
  7695. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  7696. utils.ErrorLog("med_type")
  7697. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7698. return
  7699. }
  7700. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  7701. ctime := time.Now().Unix()
  7702. prescription := &models.HisPrescriptionInfoTemplate{
  7703. PatientId: patient_id,
  7704. UserOrgId: adminInfo.CurrentOrgId,
  7705. Ctime: ctime,
  7706. Mtime: ctime,
  7707. Type: types,
  7708. Modifier: adminInfo.AdminUser.Id,
  7709. Creator: adminInfo.AdminUser.Id,
  7710. Status: 1,
  7711. PTemplateId: template.ID,
  7712. MedType: med_type,
  7713. }
  7714. service.CreateHisPrescriptionInfoTemplate(prescription)
  7715. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  7716. advices := items["advices"].([]interface{})
  7717. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  7718. ctime := time.Now().Unix()
  7719. mtime := ctime
  7720. if len(advices) > 0 {
  7721. for _, advice := range advices {
  7722. var s models.HisPrescriptionAdviceTemplate
  7723. s.PrescriptionId = prescription.ID
  7724. s.AdviceType = 2
  7725. s.StopState = 2
  7726. s.ExecutionState = 2
  7727. s.Status = 1
  7728. s.UserOrgId = adminInfo.CurrentOrgId
  7729. s.CreatedTime = ctime
  7730. s.UpdatedTime = mtime
  7731. s.PatientId = patient_id
  7732. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  7733. if errcode > 0 {
  7734. c.ServeFailJSONWithSGJErrorCode(errcode)
  7735. return
  7736. }
  7737. service.CreateHisPrescriptionAdviceTemplate(&s)
  7738. }
  7739. }
  7740. }
  7741. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  7742. projects := items["project"].([]interface{})
  7743. if len(projects) > 0 {
  7744. for _, project := range projects {
  7745. var p models.HisPrescriptionProjectTemplate
  7746. p.PrescriptionId = prescription.ID
  7747. p.Ctime = time.Now().Unix()
  7748. p.Mtime = time.Now().Unix()
  7749. p.PatientId = patient_id
  7750. p.UserOrgId = adminInfo.CurrentOrgId
  7751. p.Status = 1
  7752. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  7753. if errcode > 0 {
  7754. c.ServeFailJSONWithSGJErrorCode(errcode)
  7755. return
  7756. }
  7757. service.CreateHisPrescriptionProjectTemplate(&p)
  7758. }
  7759. }
  7760. }
  7761. }
  7762. c.ServeSuccessJSON(map[string]interface{}{
  7763. "msg": "创建成功",
  7764. })
  7765. }
  7766. }
  7767. }
  7768. func (c *HisApiController) PreSettle() {
  7769. id, _ := c.GetInt64("id")
  7770. record_time := c.GetString("record_time")
  7771. his_patient_id, _ := c.GetInt64("his_patient_id")
  7772. timeLayout := "2006-01-02"
  7773. loc, _ := time.LoadLocation("Local")
  7774. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  7775. diagnosis_id := c.GetString("diagnosis")
  7776. sick_type, _ := c.GetInt64("sick_type")
  7777. reg_type, _ := c.GetInt64("p_type")
  7778. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  7779. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  7780. if err != nil {
  7781. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7782. return
  7783. }
  7784. recordDateTime := theTime.Unix()
  7785. adminUser := c.GetAdminUserInfo()
  7786. var prescriptions []*models.HisPrescription
  7787. var start_time int64
  7788. var end_time int64
  7789. ids_str := c.GetString("ids")
  7790. ids_arr := strings.Split(ids_str, ",")
  7791. fmt.Println(reg_type)
  7792. if settle_accounts_type == 1 { //日结
  7793. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  7794. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  7795. } else {
  7796. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  7797. }
  7798. fmt.Println(prescriptions)
  7799. } else { //月结
  7800. start_time_str := c.GetString("start_time")
  7801. end_time_str := c.GetString("end_time")
  7802. timeLayout := "2006-01-02"
  7803. loc, _ := time.LoadLocation("Local")
  7804. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  7805. if err != nil {
  7806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7807. return
  7808. }
  7809. recordStartTime := theStartTime.Unix()
  7810. start_time = recordStartTime
  7811. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  7812. if err != nil {
  7813. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7814. return
  7815. }
  7816. recordEndTime := theEndTime.Unix()
  7817. end_time = recordEndTime
  7818. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  7819. }
  7820. if reg_type == 1111 || reg_type == 1112 {
  7821. reg_type = 11
  7822. }
  7823. timestamp := time.Now().Unix()
  7824. tempTime := time.Unix(timestamp, 0)
  7825. timeFormat := tempTime.Format("20060102150405")
  7826. chrgBchno := rand.Intn(100000) + 10000
  7827. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  7828. strconv.FormatInt(his.PatientId, 10)
  7829. var ids []int64
  7830. for _, item := range prescriptions {
  7831. ids = append(ids, item.ID)
  7832. }
  7833. fmt.Println(ids)
  7834. var total float64
  7835. for _, item := range prescriptions {
  7836. fmt.Println(item)
  7837. if item.Type == 1 { //药品
  7838. for _, subItem := range item.HisDoctorAdviceInfo {
  7839. total = total + (subItem.Price * subItem.PrescribingNumber)
  7840. }
  7841. }
  7842. if item.Type == 2 { //项目
  7843. for _, subItem := range item.HisPrescriptionProject {
  7844. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7845. total = total + (subItem.Price * cnt)
  7846. }
  7847. }
  7848. for _, subItem := range item.HisAdditionalCharge {
  7849. total = total + (subItem.Price * float64(subItem.Count))
  7850. }
  7851. }
  7852. allTotal := fmt.Sprintf("%.2f", total)
  7853. totals, _ := strconv.ParseFloat(allTotal, 64)
  7854. order := &models.HisOrder{
  7855. UserOrgId: adminUser.CurrentOrgId,
  7856. HisPatientId: his.ID,
  7857. PatientId: id,
  7858. SettleAccountsDate: recordDateTime,
  7859. Ctime: time.Now().Unix(),
  7860. Mtime: time.Now().Unix(),
  7861. Status: 1,
  7862. OrderStatus: 1,
  7863. MdtrtId: his.Number,
  7864. Number: chrg_bchno,
  7865. MedfeeSumamt: totals,
  7866. SettleEndTime: end_time,
  7867. SettleStartTime: start_time,
  7868. SettleType: settle_accounts_type,
  7869. PType: 2,
  7870. IsPre: 1,
  7871. MedType: strconv.Itoa(int(reg_type)),
  7872. Diagnosis: diagnosis_id,
  7873. }
  7874. err = service.CreateOrder(order)
  7875. if err != nil {
  7876. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  7877. return
  7878. }
  7879. var customs []*Custom
  7880. for _, item := range prescriptions {
  7881. fmt.Println(item.Type)
  7882. if item.Type == 1 { //药品
  7883. for _, subItem := range item.HisDoctorAdviceInfo {
  7884. cus := &Custom{
  7885. AdviceId: subItem.ID,
  7886. ProjectId: 0,
  7887. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  7888. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  7889. FeedetlSn: subItem.FeedetlSn,
  7890. Price: fmt.Sprintf("%.2f", subItem.Price),
  7891. MedListCodg: subItem.MedListCodg,
  7892. Type: 1,
  7893. }
  7894. customs = append(customs, cus)
  7895. }
  7896. }
  7897. if item.Type == 2 { //项目
  7898. for _, subItem := range item.HisPrescriptionProject {
  7899. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7900. cus := &Custom{
  7901. AdviceId: 0,
  7902. ProjectId: subItem.ID,
  7903. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  7904. Cut: fmt.Sprintf("%.2f", cnt),
  7905. FeedetlSn: subItem.FeedetlSn,
  7906. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  7907. MedListCodg: subItem.MedListCodg,
  7908. Type: 2,
  7909. }
  7910. customs = append(customs, cus)
  7911. }
  7912. }
  7913. for _, item := range item.HisAdditionalCharge {
  7914. cus := &Custom{
  7915. ItemId: item.ID,
  7916. AdviceId: 0,
  7917. ProjectId: 0,
  7918. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  7919. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  7920. FeedetlSn: item.FeedetlSn,
  7921. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  7922. MedListCodg: item.XtHisAddtionConfig.Code,
  7923. Type: 3,
  7924. }
  7925. customs = append(customs, cus)
  7926. }
  7927. }
  7928. fmt.Println(customs)
  7929. for _, item := range customs {
  7930. var advice_id int64 = 0
  7931. var project_id int64 = 0
  7932. var item_id int64 = 0
  7933. var types int64 = 0
  7934. if item.Type == 1 {
  7935. advice_id = item.AdviceId
  7936. project_id = 0
  7937. item_id = 0
  7938. } else if item.Type == 2 {
  7939. advice_id = 0
  7940. item_id = 0
  7941. project_id = item.ProjectId
  7942. } else if item.Type == 3 {
  7943. advice_id = 0
  7944. item_id = item.ItemId
  7945. project_id = 0
  7946. }
  7947. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  7948. cut, _ := strconv.ParseFloat(item.Cut, 32)
  7949. pric, _ := strconv.ParseFloat(item.Price, 32)
  7950. info := &models.HisOrderInfo{
  7951. OrderNumber: order.Number,
  7952. UploadDate: time.Now().Unix(),
  7953. AdviceId: advice_id,
  7954. DetItemFeeSumamt: detItemFeeSumamt,
  7955. Cnt: cut,
  7956. Pric: pric,
  7957. PatientId: id,
  7958. Status: 1,
  7959. Mtime: time.Now().Unix(),
  7960. Ctime: time.Now().Unix(),
  7961. UserOrgId: adminUser.CurrentOrgId,
  7962. HisPatientId: his.ID,
  7963. OrderId: order.ID,
  7964. ProjectId: project_id,
  7965. Type: types,
  7966. ItemId: item_id,
  7967. }
  7968. service.CreateOrderInfo(info)
  7969. }
  7970. his.SickType = sick_type
  7971. service.UpdataHisPateint(&his)
  7972. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  7973. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  7974. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  7975. if err == nil {
  7976. c.ServeSuccessJSON(map[string]interface{}{
  7977. "msg": "结算成功",
  7978. })
  7979. }
  7980. }
  7981. type CustomOrderInfo struct {
  7982. Name string
  7983. Spec string
  7984. Unit string
  7985. Count float64
  7986. Price float64
  7987. Total float64
  7988. }
  7989. func (c *HisApiController) GetPrivateExpensesInfo() {
  7990. order_id, _ := c.GetInt64("id", 0)
  7991. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  7992. order, _ := service.GetHisOrderByID(order_id)
  7993. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  7994. if order.ID == 0 {
  7995. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7996. return
  7997. }
  7998. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  7999. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  8000. org_id := c.GetAdminUserInfo().CurrentOrgId
  8001. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8002. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8003. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  8004. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  8005. orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  8006. var orderInfos_four []*models.HisOrderInfoTwo
  8007. for _, item := range orderInfos_three {
  8008. if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  8009. item.HisPrescriptionProject.IsCheckTeam = 1
  8010. orderInfos_four = append(orderInfos_four, item)
  8011. }
  8012. if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  8013. item.HisPrescriptionProject.IsCheckTeam = 2
  8014. orderInfos_two = append(orderInfos_two, item)
  8015. }
  8016. }
  8017. new_order_info := RemoveRepeatedTeam(orderInfos_four)
  8018. var cus_slice []CustomOrderInfo
  8019. for _, item := range new_order_info {
  8020. var cus CustomOrderInfo
  8021. cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  8022. cus.Unit = ""
  8023. cus.Spec = ""
  8024. var total float64
  8025. for _, subItem := range orderInfos_four {
  8026. if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  8027. total = total + subItem.DetItemFeeSumamt
  8028. fmt.Println(subItem.DetItemFeeSumamt)
  8029. }
  8030. }
  8031. cus.Count = 1
  8032. cus.Total = total
  8033. cus_slice = append(cus_slice, cus)
  8034. }
  8035. orderInfos = append(orderInfos, orderInfos_two...)
  8036. if c.GetAdminUserInfo().CurrentOrgId != 10138 {
  8037. orderInfos = append(orderInfos, orderInfos_three...)
  8038. }
  8039. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  8040. c.ServeSuccessJSON(map[string]interface{}{
  8041. "order": order,
  8042. "order_info": orderInfos,
  8043. "patient": patient,
  8044. "admin_info": adminInfo,
  8045. "his": his,
  8046. "current_admin": role,
  8047. "org_config": miConfig,
  8048. "new_order_info": cus_slice,
  8049. })
  8050. }
  8051. func (this *HisApiController) ChangeMedType() {
  8052. med_type := this.GetString("med_type")
  8053. old_med_type := this.GetString("old_med_type")
  8054. ids := this.GetString("ids")
  8055. settle_type, _ := this.GetInt64("settle_type")
  8056. start_time := this.GetString("start_time")
  8057. end_time := this.GetString("end_time")
  8058. ids_arr := strings.Split(ids, ",")
  8059. if settle_type == 1 { //日结
  8060. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  8061. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  8062. prescription.MedType = med_type
  8063. err := service.SaveHisPrescription(&prescription)
  8064. if err == nil {
  8065. this.ServeSuccessJSON(map[string]interface{}{
  8066. "msg": "修改成功",
  8067. })
  8068. } else {
  8069. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8070. return
  8071. }
  8072. } else if settle_type == 2 {
  8073. timeLayout := "2006-01-02"
  8074. loc, _ := time.LoadLocation("Local")
  8075. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8076. if err != nil {
  8077. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8078. return
  8079. }
  8080. recordStartTime := theStartTime.Unix()
  8081. start_time_timestamp := recordStartTime
  8082. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8083. if err != nil {
  8084. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8085. return
  8086. }
  8087. recordEndTime := theEndTime.Unix()
  8088. end_time_timestamp := recordEndTime
  8089. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  8090. if updateErr == nil {
  8091. this.ServeSuccessJSON(map[string]interface{}{
  8092. "msg": "修改成功",
  8093. })
  8094. } else {
  8095. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8096. return
  8097. }
  8098. }
  8099. }
  8100. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  8101. patient_id, _ := c.GetInt64("patient_id")
  8102. his_patient_id, _ := c.GetInt64("his_patient_id")
  8103. record_date := c.GetString("record_date")
  8104. start_time := c.GetString("start_time")
  8105. end_time := c.GetString("end_time")
  8106. order_status, _ := c.GetInt64("type", 0)
  8107. p_type, _ := c.GetInt64("p_type", 0)
  8108. order_id, _ := c.GetInt64("order_id", 0)
  8109. timeLayout := "2006-01-02"
  8110. loc, _ := time.LoadLocation("Local")
  8111. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8112. if err != nil {
  8113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8114. return
  8115. }
  8116. recordDateTime := theTime.Unix()
  8117. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8118. if err != nil {
  8119. }
  8120. startRecordDateTime := startTime.Unix()
  8121. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8122. if err != nil {
  8123. }
  8124. endRecordDateTime := endTime.Unix()
  8125. admin := c.GetAdminUserInfo()
  8126. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8127. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8128. order, _ := service.GetHisOrderByID(order_id)
  8129. var monthPrescriptions []*models.HisPrescription
  8130. if order_status == 1 || order_status == 0 {
  8131. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8132. } else if order_status == 2 {
  8133. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  8134. }
  8135. var settle_total float64
  8136. for _, item := range monthPrescriptions {
  8137. if len(item.HisPrescriptionProject) > 0 {
  8138. for _, subItem := range item.HisPrescriptionProject {
  8139. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8140. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8141. settle_total = settle_total + total
  8142. }
  8143. }
  8144. if len(item.HisDoctorAdviceInfo) > 0 {
  8145. for _, subItem := range item.HisDoctorAdviceInfo {
  8146. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8147. settle_total = settle_total + total
  8148. }
  8149. }
  8150. }
  8151. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8152. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8153. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8154. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8155. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8156. //获取所有科室信息
  8157. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8158. c.ServeSuccessJSON(map[string]interface{}{
  8159. "his_info": his_patient_info,
  8160. "xt_info": xt_patient_info,
  8161. "case_history": case_history,
  8162. "info": patientPrescriptionInfo,
  8163. "last_info": lastPatientPrescriptionInfo,
  8164. "month_prescriptions": monthPrescriptions,
  8165. "order": order,
  8166. "doctors": doctors,
  8167. "department": department,
  8168. "settle_total": settle_total,
  8169. })
  8170. return
  8171. }
  8172. func (c *HisApiController) GetHisMonthPatientInfo() {
  8173. patient_id, _ := c.GetInt64("patient_id")
  8174. his_patient_id, _ := c.GetInt64("his_patient_id")
  8175. record_date := c.GetString("record_date")
  8176. number := c.GetString("number")
  8177. start_time := c.GetString("start_time")
  8178. end_time := c.GetString("end_time")
  8179. p_type, _ := c.GetInt64("p_type")
  8180. timeLayout := "2006-01-02"
  8181. loc, _ := time.LoadLocation("Local")
  8182. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8183. if err != nil {
  8184. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8185. return
  8186. }
  8187. recordDateTime := theTime.Unix()
  8188. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8189. if err != nil {
  8190. }
  8191. startRecordDateTime := startTime.Unix()
  8192. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8193. if err != nil {
  8194. }
  8195. endRecordDateTime := endTime.Unix()
  8196. admin := c.GetAdminUserInfo()
  8197. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  8198. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8199. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  8200. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8201. var settle_total float64
  8202. for _, item := range monthPrescriptions {
  8203. if len(item.HisPrescriptionProject) > 0 {
  8204. for _, subItem := range item.HisPrescriptionProject {
  8205. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8206. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8207. settle_total = settle_total + total
  8208. }
  8209. }
  8210. if len(item.HisDoctorAdviceInfo) > 0 {
  8211. for _, subItem := range item.HisDoctorAdviceInfo {
  8212. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8213. settle_total = settle_total + total
  8214. }
  8215. }
  8216. }
  8217. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8218. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8219. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8220. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8221. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  8222. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8223. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  8224. //获取所有科室信息
  8225. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8226. c.ServeSuccessJSON(map[string]interface{}{
  8227. "his_info": his_patient_info,
  8228. "xt_info": xt_patient_info,
  8229. "case_history": case_history,
  8230. "info": patientPrescriptionInfo,
  8231. "month_prescriptions": monthPrescriptions,
  8232. "order": order,
  8233. "doctors": doctors,
  8234. "department": department,
  8235. "count": count,
  8236. "drugStockConfig": drugStockConfig,
  8237. "last_info": lastPatientPrescriptionInfo,
  8238. "settle_total": settle_total,
  8239. })
  8240. return
  8241. }
  8242. func (c *HisApiController) GetAllOrder() {
  8243. org_id := c.GetAdminUserInfo().CurrentOrgId
  8244. orders, _ := service.GetNewHisOrderList(org_id)
  8245. c.ServeSuccessJSON(map[string]interface{}{
  8246. "order": orders,
  8247. })
  8248. return
  8249. }
  8250. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  8251. newArr = make([]*models.HisOrderInfoTwo, 0)
  8252. for i := 0; i < len(arr); i++ {
  8253. repeat := false
  8254. for j := i + 1; j < len(arr); j++ {
  8255. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  8256. repeat = true
  8257. break
  8258. }
  8259. }
  8260. if !repeat {
  8261. newArr = append(newArr, arr[i])
  8262. }
  8263. }
  8264. return
  8265. }
  8266. //修改处方退库操作 参数传修改之前的处方数据
  8267. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  8268. if advice.ExecutionState == 1 {
  8269. //查询该病人该药品是否有库存记录
  8270. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  8271. if errcode == gorm.ErrRecordNotFound {
  8272. } else {
  8273. //退库
  8274. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8275. if advice.PrescribingNumberUnit == drug.MinUnit {
  8276. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  8277. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  8278. //退库
  8279. warehouseInfo := models.DrugWarehouseInfo{
  8280. StockMinNumber: prescribingNumber,
  8281. }
  8282. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  8283. operation_time := time.Now().Unix()
  8284. creater := advice.AdviceDoctor
  8285. ctime := time.Now().Unix()
  8286. timeStr := time.Now().Format("2006-01-02")
  8287. timeArr := strings.Split(timeStr, "-")
  8288. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  8289. total = total + 1
  8290. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8291. cancelStock := models.DrugCancelStock{
  8292. OrderNumber: orderNumber,
  8293. OperaTime: operation_time,
  8294. OrgId: advice.UserOrgId,
  8295. Creater: creater,
  8296. Ctime: ctime,
  8297. Status: 1,
  8298. ReturnTime: advice.AdviceDate,
  8299. Dealer: info.Dealer,
  8300. Manufacturer: info.Manufacturer,
  8301. Type: 1,
  8302. }
  8303. service.AddSigleDrugCancelStock(&cancelStock)
  8304. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  8305. dealer, _ := service.GetDealerById(info.Dealer)
  8306. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  8307. cancelStockInfo := models.DrugCancelStockInfo{
  8308. OrderNumber: cancelInfo.OrderNumber,
  8309. CancelStockId: cancelInfo.ID,
  8310. DrugId: info.DrugId,
  8311. Count: info.Count,
  8312. Status: 1,
  8313. Ctime: ctime,
  8314. OrgId: advice.UserOrgId,
  8315. Type: 1,
  8316. Manufacturer: manufactureName.ManufacturerName,
  8317. Dealer: dealer.DealerName,
  8318. Total: 0,
  8319. RetailPrice: info.RetailPrice,
  8320. RetailTotalPrice: info.RetailTotalPrice,
  8321. Price: info.Price,
  8322. RegisterAccount: "",
  8323. Remark: info.Remark,
  8324. BatchNumber: info.BatchNumber,
  8325. MaxUnit: info.CountUnit,
  8326. ProductDate: info.ProductDate,
  8327. ExpiryDate: info.ExpiryDate,
  8328. BatchNumberId: info.WarehouseInfoId,
  8329. }
  8330. flow := models.DrugFlow{
  8331. WarehousingId: 0,
  8332. DrugId: info.DrugId,
  8333. Number: "",
  8334. BatchNumber: info.BatchNumber,
  8335. Count: info.Count,
  8336. UserOrgId: advice.UserOrgId,
  8337. PatientId: 0,
  8338. SystemTime: ctime,
  8339. ConsumableType: 4,
  8340. IsSys: 0,
  8341. WarehousingOrder: "",
  8342. WarehouseOutId: 0,
  8343. WarehouseOutOrderNumber: "",
  8344. IsEdit: 0,
  8345. CancelStockId: cancelStock.ID,
  8346. CancelOrderNumber: cancelStock.OrderNumber,
  8347. Manufacturer: info.Manufacturer,
  8348. Dealer: info.Dealer,
  8349. Creator: advice.UserOrgId,
  8350. UpdateCreator: 0,
  8351. Status: 1,
  8352. Ctime: time.Now().Unix(),
  8353. Mtime: 0,
  8354. Price: info.Price,
  8355. WarehousingDetailId: 0,
  8356. WarehouseOutDetailId: 0,
  8357. CancelOutDetailId: 0,
  8358. ExpireDate: info.ExpiryDate,
  8359. ProductDate: info.ProductDate,
  8360. MaxUnit: info.CountUnit,
  8361. MinUnit: "",
  8362. }
  8363. service.CreatedCancelStock(cancelStockInfo)
  8364. service.CreateDrugFlowOne(flow)
  8365. } else {
  8366. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  8367. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  8368. if advice.PrescribingNumberUnit == drug.MaxUnit {
  8369. warehouseInfo := models.DrugWarehouseInfo{
  8370. StockMinNumber: prescribingNumber,
  8371. }
  8372. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  8373. }
  8374. operation_time := time.Now().Unix()
  8375. creater := advice.AdviceDoctor
  8376. ctime := time.Now().Unix()
  8377. timeStr := time.Now().Format("2006-01-02")
  8378. timeArr := strings.Split(timeStr, "-")
  8379. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  8380. total = total + 1
  8381. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8382. cancelStock := models.DrugCancelStock{
  8383. OrderNumber: orderNumber,
  8384. OperaTime: operation_time,
  8385. OrgId: advice.UserOrgId,
  8386. Creater: creater,
  8387. Ctime: ctime,
  8388. Status: 1,
  8389. ReturnTime: advice.AdviceDate,
  8390. Dealer: info.Dealer,
  8391. Manufacturer: info.Manufacturer,
  8392. Type: 1,
  8393. }
  8394. service.AddSigleDrugCancelStock(&cancelStock)
  8395. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  8396. dealer, _ := service.GetDealerById(info.Dealer)
  8397. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  8398. cancelStockInfo := models.DrugCancelStockInfo{
  8399. OrderNumber: cancelInfo.OrderNumber,
  8400. CancelStockId: cancelInfo.ID,
  8401. DrugId: info.DrugId,
  8402. Count: info.Count,
  8403. Status: 1,
  8404. Ctime: ctime,
  8405. OrgId: advice.UserOrgId,
  8406. Type: 1,
  8407. Manufacturer: manufactureName.ManufacturerName,
  8408. Dealer: dealer.DealerName,
  8409. Total: 0,
  8410. RetailPrice: info.RetailPrice,
  8411. RetailTotalPrice: info.RetailTotalPrice,
  8412. Price: info.Price,
  8413. RegisterAccount: "",
  8414. Remark: info.Remark,
  8415. BatchNumber: info.BatchNumber,
  8416. MaxUnit: info.CountUnit,
  8417. ProductDate: info.ProductDate,
  8418. ExpiryDate: info.ExpiryDate,
  8419. BatchNumberId: info.WarehouseInfoId,
  8420. }
  8421. flow := models.DrugFlow{
  8422. WarehousingId: 0,
  8423. DrugId: info.DrugId,
  8424. Number: "",
  8425. BatchNumber: info.BatchNumber,
  8426. Count: info.Count,
  8427. UserOrgId: advice.UserOrgId,
  8428. PatientId: 0,
  8429. SystemTime: ctime,
  8430. ConsumableType: 4,
  8431. IsSys: 0,
  8432. WarehousingOrder: "",
  8433. WarehouseOutId: 0,
  8434. WarehouseOutOrderNumber: "",
  8435. IsEdit: 0,
  8436. CancelStockId: cancelStock.ID,
  8437. CancelOrderNumber: cancelStock.OrderNumber,
  8438. Manufacturer: info.Manufacturer,
  8439. Dealer: info.Dealer,
  8440. Creator: advice.AdviceDoctor,
  8441. UpdateCreator: 0,
  8442. Status: 1,
  8443. Ctime: time.Now().Unix(),
  8444. Mtime: 0,
  8445. Price: info.Price,
  8446. WarehousingDetailId: 0,
  8447. WarehouseOutDetailId: 0,
  8448. CancelOutDetailId: 0,
  8449. ExpireDate: info.ExpiryDate,
  8450. ProductDate: info.ProductDate,
  8451. MaxUnit: info.CountUnit,
  8452. MinUnit: "",
  8453. }
  8454. service.CreatedCancelStock(cancelStockInfo)
  8455. service.CreateDrugFlowOne(flow)
  8456. }
  8457. }
  8458. }
  8459. return err
  8460. }
  8461. func (this *HisApiController) DeleteNCDS() {
  8462. id, _ := this.GetInt64("id", 0)
  8463. if id > 0 {
  8464. service.DeletePsnNCDSRecordById(id)
  8465. this.ServeSuccessJSON(map[string]interface{}{
  8466. "msg": "删除成功",
  8467. })
  8468. } else {
  8469. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  8470. return
  8471. }
  8472. }
  8473. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  8474. id, _ := c.GetInt64("id")
  8475. advice, _ := service.GetHisDoctorAdviceInfo(id)
  8476. c.ServeSuccessJSON(map[string]interface{}{
  8477. "advice": advice,
  8478. })
  8479. return
  8480. }
  8481. func (c *HisApiController) GetHisMonthChargePatientList() {
  8482. record_date := c.GetString("record_date")
  8483. start_time := c.GetString("start_time")
  8484. end_time := c.GetString("end_time")
  8485. timeLayout := "2006-01-02"
  8486. loc, _ := time.LoadLocation("Local")
  8487. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8488. if err != nil {
  8489. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8490. return
  8491. }
  8492. if err != nil {
  8493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8494. return
  8495. }
  8496. recordDateTime := theTime.Unix()
  8497. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8498. if err != nil {
  8499. }
  8500. startRecordDateTime := startTime.Unix()
  8501. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8502. if err != nil {
  8503. }
  8504. endRecordDateTime := endTime.Unix()
  8505. adminInfo := c.GetAdminUserInfo()
  8506. var tempMonthChargePatients []*service.MonthChargePatients
  8507. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  8508. for _, item := range tempPatients {
  8509. //过滤没有处方的
  8510. if len(item.HisPrescription) == 0 {
  8511. tempMonthChargePatients = append(tempMonthChargePatients, item)
  8512. }
  8513. }
  8514. c.ServeSuccessJSON(map[string]interface{}{
  8515. "list": tempMonthChargePatients,
  8516. })
  8517. }