his_api_controller.go 366KB

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