his_api_controller.go 546KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math/rand"
  6. "reflect"
  7. "strconv"
  8. "strings"
  9. "syscall"
  10. "time"
  11. "unsafe"
  12. "XT_New/enums"
  13. "XT_New/models"
  14. "XT_New/service"
  15. "XT_New/utils"
  16. "github.com/astaxie/beego"
  17. "github.com/jinzhu/gorm"
  18. "github.com/mozillazg/go-pinyin"
  19. "github.com/shopspring/decimal"
  20. )
  21. type HisApiController struct {
  22. BaseAuthAPIController
  23. }
  24. func HisManagerApiRegistRouters() {
  25. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  26. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  27. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  28. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  29. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  30. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  31. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  32. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  33. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  34. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  35. //beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  36. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  37. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  41. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  42. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  43. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  44. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  45. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  46. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  47. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  48. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  49. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  50. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  51. //新增附加费用
  52. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  53. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  54. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  55. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  56. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  57. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  58. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  59. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  60. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  61. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  62. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  63. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  64. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  65. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  66. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  67. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  86. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  87. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  88. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  89. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  90. }
  91. func (c *HisApiController) CheckHisPatient() {
  92. record_date := c.GetString("record_date")
  93. patient_id, _ := c.GetInt64("patient_id")
  94. timeLayout := "2006-01-02"
  95. loc, _ := time.LoadLocation("Local")
  96. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  97. if err != nil {
  98. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  99. return
  100. }
  101. recordDateTime := theTime.Unix()
  102. adminInfo := c.GetAdminUserInfo()
  103. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  104. if len(patients) > 1 {
  105. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  106. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  107. c.ServeSuccessJSON(map[string]interface{}{
  108. "status": 1,
  109. "msg": "关联",
  110. "ps": ps,
  111. "his_patient_id": patients[len(patients)-1].ID,
  112. "patient_id": patients[len(patients)-1].PatientId,
  113. })
  114. } else {
  115. c.ServeSuccessJSON(map[string]interface{}{
  116. "status": 0,
  117. "msg": "无需关联",
  118. })
  119. }
  120. } else {
  121. c.ServeSuccessJSON(map[string]interface{}{
  122. "status": 0,
  123. "msg": "无需关联",
  124. })
  125. return
  126. }
  127. }
  128. func (c *HisApiController) AssociationHisPrescription() {
  129. record_date := c.GetString("record_date")
  130. his_patient_id, _ := c.GetInt64("his_patient_id")
  131. patient_id, _ := c.GetInt64("patient_id")
  132. p_ids := c.GetString("p_ids")
  133. p_ids_arr := strings.Split(p_ids, ",")
  134. timeLayout := "2006-01-02"
  135. loc, _ := time.LoadLocation("Local")
  136. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  137. if err != nil {
  138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  139. return
  140. }
  141. recordDateTime := theTime.Unix()
  142. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  143. if his_patient_id == 0 || his_patient.ID == 0 {
  144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  145. return
  146. }
  147. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  148. if err == nil {
  149. c.ServeSuccessJSON(map[string]interface{}{
  150. "msg": "关联处方成功",
  151. })
  152. return
  153. } else {
  154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  155. return
  156. }
  157. }
  158. //func (c *HisApiController) AssociationHisPrescription() {
  159. // record_date, _ := c.GetInt64("record_date")
  160. // his_patient_id, _ := c.GetInt64("his_patient_id")
  161. // patient_id, _ := c.GetInt64("patient_id")
  162. // p_ids := c.GetString("p_ids")
  163. // p_ids_arr := strings.Split(p_ids, ",")
  164. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  165. // if his_patient_id == 0 || his_patient.ID == 0 {
  166. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  167. // return
  168. // }
  169. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  170. // if err == nil {
  171. // c.ServeSuccessJSON(map[string]interface{}{
  172. // "msg": "关联处方成功",
  173. // })
  174. // return
  175. // } else {
  176. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  177. // return
  178. // }
  179. //}
  180. func (c *HisApiController) GetFaPiaoNumber() {
  181. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  182. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  183. fmt.Println(count)
  184. var zero string
  185. number := count + 1
  186. //if number >= 1000 {
  187. // zero = "0000" + strconv.FormatInt(number, 10)
  188. //} else if number >= 10000 {
  189. // zero = "000" + strconv.FormatInt(number, 10)
  190. //} else if number >= 100000 {
  191. // zero = "00" + strconv.FormatInt(number, 10)
  192. //} else if number >= 1000000 {
  193. // zero = "0" + strconv.FormatInt(number, 10)
  194. //} else {
  195. zero = "0" + strconv.FormatInt(number, 10)
  196. //}
  197. c.ServeSuccessJSON(map[string]interface{}{
  198. "fapiao_number": zero,
  199. })
  200. return
  201. }
  202. func (c *HisApiController) ChangeOrderDesc() {
  203. id, _ := c.GetInt64("id")
  204. desc := c.GetString("desc")
  205. change_type := c.GetString("change_type")
  206. order, _ := service.GetHisOrderByID(id)
  207. if order.ID == 0 {
  208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  209. return
  210. }
  211. switch change_type {
  212. case "oth_desc":
  213. order.OthDesc = desc
  214. break
  215. case "cash_pay":
  216. order.CashPay = desc
  217. break
  218. case "jifen_pay":
  219. order.JifenPay = desc
  220. break
  221. case "band_card_pay":
  222. order.BandCardPay = desc
  223. break
  224. case "ali_pay":
  225. order.AliPay = desc
  226. break
  227. case "wechat_pay":
  228. order.WechatPay = desc
  229. break
  230. case "fa_piao_number":
  231. order.FaPiaoNumber = desc
  232. break
  233. case "fa_piao_code":
  234. order.FaPiaoCode = desc
  235. break
  236. }
  237. err := service.SaveHisOrder(&order)
  238. if err == nil {
  239. c.ServeSuccessJSON(map[string]interface{}{
  240. "msg": "修改成功",
  241. })
  242. return
  243. } else {
  244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  245. return
  246. }
  247. }
  248. func (c *HisApiController) GetMonthHisPatient() {
  249. record_date := c.GetString("record_date")
  250. //order_status, _ := c.GetInt64("type")
  251. timeLayout := "2006-01-02"
  252. loc, _ := time.LoadLocation("Local")
  253. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  254. if err != nil {
  255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  256. return
  257. }
  258. recordDateTime := theTime.Unix()
  259. adminInfo := c.GetAdminUserInfo()
  260. var tempPatients []service.NewTempPatients
  261. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  262. // 获取当前时间
  263. now := time.Now()
  264. // 获取本月的第一天
  265. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  266. // 获取下个月的第一天
  267. nextMonth := firstDay.AddDate(0, 1, 0)
  268. // 获取本月的最后一天
  269. lastDay := nextMonth.Add(-time.Nanosecond)
  270. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  271. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  272. var patients []service.NewTempPatients
  273. var patients_two []service.NewTempPatients
  274. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  275. for _, item := range tempPatients {
  276. //过滤掉没挂号的和没开处方的
  277. if len(item.HisPrescription) > 0 {
  278. patients = append(patients, item)
  279. patients_two = append(patients_two, item)
  280. }
  281. ////过滤掉没挂号的
  282. //if len(item.HisPatient) > 0 {
  283. //}
  284. }
  285. } else {
  286. for _, item := range tempPatients {
  287. //过滤掉没挂号的和没开处方的
  288. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  289. patients = append(patients, item)
  290. }
  291. ////过滤掉没挂号的
  292. //if len(item.HisPatient) > 0 {
  293. // patients_two = append(patients_two, item)
  294. //}
  295. }
  296. }
  297. c.ServeSuccessJSON(map[string]interface{}{
  298. "list": patients,
  299. "list_two": patients_two,
  300. "chargePatients": chargePatients,
  301. })
  302. }
  303. func (c *HisApiController) GetBatchSettleAccounts() {
  304. order_ids := c.GetString("order_ids")
  305. admin_user_id, _ := c.GetInt64("admin_user_id")
  306. adminUser := c.GetAdminUserInfo()
  307. orders := strings.Split(order_ids, ",")
  308. var newOrders []models.Orders
  309. for _, item := range orders {
  310. order, _ := service.GetHisOrderByIDTenOne(item)
  311. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  312. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  313. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  314. orderInfos = append(orderInfos, orderInfos_two...)
  315. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  316. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  317. var diagnosis_ids []string
  318. if his.ID > 0 {
  319. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  320. } else {
  321. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  322. }
  323. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  324. var dia_config []*models.HisXtDiagnoseConfig
  325. var name string
  326. for _, item := range diagnosis_ids {
  327. id, _ := strconv.ParseInt(item, 10, 64)
  328. diagnosisConfig, _ := service.FindDiagnoseById(id)
  329. dia_config = append(dia_config, diagnosisConfig)
  330. if len(name) == 0 {
  331. name = diagnosisConfig.ClassName
  332. } else {
  333. name = name + "," + diagnosisConfig.ClassName
  334. }
  335. }
  336. var bedCostTotal float64 = 0 //床位总费
  337. var bedCostSelfTotal float64 = 0 //床位自费
  338. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  339. var bedSelfTotal float64 = 0 //床位部分项目自费
  340. var bedInscpTotal float64 = 0 //床位部分项目自费
  341. var operationCostTotal float64 = 0 //手术费
  342. var operationCostSelfTotal float64 = 0 //手术费
  343. var operationCostPartSelfTotal float64 = 0 //手术费
  344. var operationSelfTotal float64 = 0 //床位部分项目自费
  345. var operationInscpTotal float64 = 0 //床位部分项目自费
  346. var otherCostTotal float64 = 0 //其他费用
  347. var otherCostSelfTotal float64 = 0 //其他费用
  348. var otherCostPartSelfTotal float64 = 0 //其他费用
  349. var otherSelfTotal float64 = 0 //床位部分项目自费
  350. var otherInscpTotal float64 = 0 //床位部分项目自费
  351. var materialCostTotal float64 = 0 //材料费
  352. var materialCostSelfTotal float64 = 0 //材料费
  353. var materialCostPartSelfTotal float64 = 0 //材料费
  354. var materialSelfTotal float64 = 0 //床位部分项目自费
  355. var materialInscpTotal float64 = 0 //床位部分项目自费
  356. var westernMedicineCostTotal float64 = 0 //西药费
  357. var westernMedicineCostSelfTotal float64 = 0 //西药费
  358. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  359. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  360. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  361. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  362. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  363. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  364. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  365. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  366. var checkCostTotal float64 = 0 //检查费
  367. var checkCostSelfTotal float64 = 0 //检查费
  368. var checkCostPartSelfTotal float64 = 0 //检查费
  369. var checkSelfTotal float64 = 0 //床位部分项目自费
  370. var checkInscpTotal float64 = 0 //床位部分项目自费
  371. var laboratoryCostTotal float64 = 0 //化验费
  372. var laboratoryCostSelfTotal float64 = 0 //化验费
  373. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  374. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  375. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  376. var treatCostTotal float64 = 0 //治疗费用
  377. var treatCostSelfTotal float64 = 0 //治疗费用
  378. var treatCostPartSelfTotal float64 = 0 //治疗费用
  379. var treatSelfTotal float64 = 0 //床位部分项目自费
  380. var treatInscpTotal float64 = 0 //床位部分项目自费
  381. decimal.DivisionPrecision = 2
  382. for _, item := range orderInfos {
  383. if item.MedChrgitmType == "01" { //床位费
  384. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  385. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  386. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  387. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  388. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  389. }
  390. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  391. if item.MedChrgitmType == "03" { //检查费
  392. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  393. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  394. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  395. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  396. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  397. }
  398. } else {
  399. if item.MedChrgitmType == "03" { //检查费
  400. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  401. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  402. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  403. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  404. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  405. }
  406. }
  407. if item.MedChrgitmType == "04" { //化验费
  408. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  409. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  410. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  411. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  412. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  413. }
  414. if item.MedChrgitmType == "05" { //治疗费
  415. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  416. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  417. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  418. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  419. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  420. }
  421. if item.MedChrgitmType == "06" { //手术费
  422. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  423. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  424. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  425. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  426. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  427. }
  428. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  429. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  430. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  431. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  432. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  433. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  434. }
  435. if item.MedChrgitmType == "09" { //西药费
  436. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  437. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  438. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  439. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  440. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  441. }
  442. if item.MedChrgitmType == "11" { //中成费
  443. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  444. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  445. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  446. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  447. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  448. }
  449. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  450. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  451. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  452. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  453. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  454. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  455. }
  456. }
  457. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  458. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  459. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  460. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  461. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  462. var doctor_name string
  463. if roles.ID == 0 {
  464. doctor_name = "管理员"
  465. } else {
  466. doctor_name = roles.UserName
  467. }
  468. yiliao_leibie := ""
  469. switch order.MedType {
  470. case "11":
  471. yiliao_leibie = "普通门诊"
  472. break
  473. case "12":
  474. yiliao_leibie = "门诊挂号"
  475. break
  476. case "13":
  477. yiliao_leibie = "急诊"
  478. break
  479. case "14":
  480. yiliao_leibie = "门诊特殊病"
  481. break
  482. case "15":
  483. yiliao_leibie = "门诊统筹"
  484. break
  485. case "16":
  486. yiliao_leibie = "门诊慢性病"
  487. break
  488. case "21":
  489. yiliao_leibie = "普通住院"
  490. break
  491. }
  492. var newOrder models.Orders
  493. newOrder.Diagnosis = name
  494. newOrder.OrderInfos = orderInfos
  495. newOrder.Number = order.MdtrtId
  496. newOrder.Date = order.SettleAccountsDate
  497. newOrder.ChargeAdmin = charge_admin
  498. newOrder.PrintorAdmin = printor_admin
  499. newOrder.Order = order
  500. newOrder.BedCostTotal = bedCostTotal
  501. newOrder.BedCostSelfTotal = bedCostSelfTotal
  502. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  503. newOrder.BedSelfTotal = bedSelfTotal
  504. newOrder.BedInscpTotal = bedInscpTotal
  505. newOrder.OperationCostTotal = operationCostTotal
  506. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  507. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  508. newOrder.OperationSelfTotal = operationSelfTotal
  509. newOrder.OperationInscpTotal = operationInscpTotal
  510. newOrder.OtherCostTotal = otherCostTotal
  511. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  512. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  513. newOrder.OtherSelfTotal = otherSelfTotal
  514. newOrder.OtherInscpTotal = otherInscpTotal
  515. newOrder.MaterialCostTotal = materialCostTotal
  516. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  517. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  518. newOrder.MaterialSelfTotal = materialSelfTotal
  519. newOrder.MaterialInscpTotal = materialInscpTotal
  520. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  521. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  522. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  523. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  524. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  525. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  526. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  527. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  528. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  529. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  530. newOrder.CheckCostTotal = checkCostTotal
  531. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  532. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  533. newOrder.CheckSelfTotal = checkSelfTotal
  534. newOrder.CheckInscpTotal = checkInscpTotal
  535. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  536. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  537. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  538. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  539. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  540. newOrder.TreatCostTotal = treatCostTotal
  541. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  542. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  543. newOrder.TreatSelfTotal = treatSelfTotal
  544. newOrder.TreatInscpTotal = treatInscpTotal
  545. newOrder.DoctorInfo = doctor_info
  546. newOrder.DoctorName = doctor_name
  547. newOrder.HealthCardNo = order.PsnNo
  548. newOrder.YiliaoLeibie = yiliao_leibie
  549. newOrder.Patient = patient
  550. newOrder.OrgName = miConfig.OrgName
  551. newOrder.OrgCode = miConfig.Code
  552. newOrder.OrderNumber = order.Number
  553. newOrder.HisPatient = his
  554. newOrder.DiaConfig = dia_config
  555. newOrders = append(newOrders, newOrder)
  556. }
  557. c.ServeSuccessJSON(map[string]interface{}{
  558. "orders": newOrders,
  559. })
  560. }
  561. func (c *HisApiController) GetTestOrder() {
  562. order_id, _ := c.GetInt64("order_id")
  563. admin_user_id, _ := c.GetInt64("admin_user_id")
  564. adminUser := c.GetAdminUserInfo()
  565. order, _ := service.GetHisOrderByID(order_id)
  566. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  567. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  568. orderInfos = append(orderInfos, orderInfos_two...)
  569. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  570. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  571. var dia_config []*models.HisXtDiagnoseConfig
  572. var name string
  573. var bedCostTotal float64 = 0 //床位总费
  574. var bedCostSelfTotal float64 = 0 //床位自费
  575. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  576. var bedSelfTotal float64 = 0 //床位部分项目自费
  577. var bedInscpTotal float64 = 0 //床位部分项目自费
  578. var operationCostTotal float64 = 0 //手术费
  579. var operationCostSelfTotal float64 = 0 //手术费
  580. var operationCostPartSelfTotal float64 = 0 //手术费
  581. var operationSelfTotal float64 = 0 //床位部分项目自费
  582. var operationInscpTotal float64 = 0 //床位部分项目自费
  583. var otherCostTotal float64 = 0 //其他费用
  584. var otherCostSelfTotal float64 = 0 //其他费用
  585. var otherCostPartSelfTotal float64 = 0 //其他费用
  586. var otherSelfTotal float64 = 0 //床位部分项目自费
  587. var otherInscpTotal float64 = 0 //床位部分项目自费
  588. var materialCostTotal float64 = 0 //材料费
  589. var materialCostSelfTotal float64 = 0 //材料费
  590. var materialCostPartSelfTotal float64 = 0 //材料费
  591. var materialSelfTotal float64 = 0 //床位部分项目自费
  592. var materialInscpTotal float64 = 0 //床位部分项目自费
  593. var westernMedicineCostTotal float64 = 0 //西药费
  594. var westernMedicineCostSelfTotal float64 = 0 //西药费
  595. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  596. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  597. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  598. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  599. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  600. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  601. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  602. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  603. var checkCostTotal float64 = 0 //检查费
  604. var checkCostSelfTotal float64 = 0 //检查费
  605. var checkCostPartSelfTotal float64 = 0 //检查费
  606. var checkSelfTotal float64 = 0 //床位部分项目自费
  607. var checkInscpTotal float64 = 0 //床位部分项目自费
  608. var laboratoryCostTotal float64 = 0 //化验费
  609. var laboratoryCostSelfTotal float64 = 0 //化验费
  610. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  611. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  612. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  613. var treatCostTotal float64 = 0 //治疗费用
  614. var treatCostSelfTotal float64 = 0 //治疗费用
  615. var treatCostPartSelfTotal float64 = 0 //治疗费用
  616. var treatSelfTotal float64 = 0 //床位部分项目自费
  617. var treatInscpTotal float64 = 0 //床位部分项目自费
  618. decimal.DivisionPrecision = 2
  619. for _, item := range orderInfos {
  620. if item.MedChrgitmType == "01" { //床位费
  621. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  622. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  623. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  624. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  625. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  626. }
  627. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  628. if item.MedChrgitmType == "03" { //检查费
  629. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  630. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  631. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  632. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  633. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  634. }
  635. } else {
  636. if item.MedChrgitmType == "03" { //检查费
  637. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  638. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  639. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  640. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  641. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  642. }
  643. }
  644. if item.MedChrgitmType == "04" { //化验费
  645. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  646. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  647. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  648. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  649. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  650. }
  651. if item.MedChrgitmType == "05" { //治疗费
  652. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  653. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  654. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  655. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  656. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  657. }
  658. if item.MedChrgitmType == "06" { //手术费
  659. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  660. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  661. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  662. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  663. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  664. }
  665. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  666. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  667. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  668. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  669. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  670. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  671. }
  672. if item.MedChrgitmType == "09" { //西药费
  673. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  674. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  675. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  676. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  677. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  678. }
  679. if item.MedChrgitmType == "11" { //中成费
  680. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  681. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  682. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  683. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  684. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  685. }
  686. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  687. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  688. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  689. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  690. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  691. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  692. }
  693. }
  694. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  695. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  696. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  697. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  698. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  699. var doctor_name string
  700. if roles.ID == 0 {
  701. doctor_name = "管理员"
  702. } else {
  703. doctor_name = roles.UserName
  704. }
  705. yiliao_leibie := ""
  706. switch order.MedType {
  707. case "11":
  708. yiliao_leibie = "普通门诊"
  709. break
  710. case "12":
  711. yiliao_leibie = "门诊挂号"
  712. break
  713. case "13":
  714. yiliao_leibie = "急诊"
  715. break
  716. case "14":
  717. yiliao_leibie = "门诊特殊病"
  718. break
  719. case "15":
  720. yiliao_leibie = "门诊统筹"
  721. break
  722. case "16":
  723. yiliao_leibie = "门诊慢性病"
  724. break
  725. case "21":
  726. yiliao_leibie = "普通住院"
  727. break
  728. }
  729. c.ServeSuccessJSON(map[string]interface{}{
  730. "diagnosis": name,
  731. "order_infos": orderInfos,
  732. "number": order.MdtrtId,
  733. "date": order.SettleAccountsDate,
  734. "charge_admin": charge_admin,
  735. "printor_admin": printor_admin,
  736. "info": order,
  737. "order": order,
  738. "bedCostTotal": bedCostTotal,
  739. "bedCostSelfTotal": bedCostSelfTotal,
  740. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  741. "bedSelfTotal": bedSelfTotal,
  742. "bedInscpTotal": bedInscpTotal,
  743. "operationCostTotal": operationCostTotal,
  744. "operationCostSelfTotal": operationCostSelfTotal,
  745. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  746. "operationSelfTotal": operationSelfTotal,
  747. "operationInscpTotal": operationInscpTotal,
  748. "otherCostTotal": otherCostTotal,
  749. "otherCostSelfTotal": otherCostSelfTotal,
  750. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  751. "otherSelfTotal": otherSelfTotal,
  752. "otherInscpTotal": otherInscpTotal,
  753. "materialCostTotal": materialCostTotal,
  754. "materialCostSelfTotal": materialCostSelfTotal,
  755. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  756. "materialSelfTotal": materialSelfTotal,
  757. "materialInscpTotal": materialInscpTotal,
  758. "westernMedicineCostTotal": westernMedicineCostTotal,
  759. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  760. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  761. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  762. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  763. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  764. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  765. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  766. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  767. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  768. "checkCostTotal": checkCostTotal,
  769. "checkCostSelfTotal": checkCostSelfTotal,
  770. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  771. "checkSelfTotal": checkSelfTotal,
  772. "checkInscpTotal": checkInscpTotal,
  773. "laboratoryCostTotal": laboratoryCostTotal,
  774. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  775. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  776. "laboratorySelfTotal": laboratorySelfTotal,
  777. "laboratoryInscpTotal": laboratoryInscpTotal,
  778. "treatCostTotal": treatCostTotal,
  779. "treatCostSelfTotal": treatCostSelfTotal,
  780. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  781. "treatSelfTotal": treatSelfTotal,
  782. "treatInscpTotal": treatInscpTotal,
  783. "doctor_info": doctor_info,
  784. "doctor_name": doctor_name,
  785. "health_card_no": order.PsnNo,
  786. "yiliao_leibie": yiliao_leibie,
  787. "patient": patient,
  788. "org_name": miConfig.OrgName,
  789. "org_code": miConfig.Code,
  790. "order_number": order.Number,
  791. "his_hospital": his_hospital,
  792. "dia_config": dia_config,
  793. })
  794. }
  795. type CustomFundPay struct {
  796. FundPayType string `json:"fund_pay_type"`
  797. FundPayamt float64 `json:"fund_payamt"`
  798. InscpScpAmt float64 `json:"inscp_scp_amt"`
  799. }
  800. func (c *PublicApiController) GetBaiLinExportData() {
  801. data := service.GetBaiLinOrderData()
  802. fmt.Println(len(data))
  803. var new_data []*models.NewCustomHisOrder
  804. for _, item := range data {
  805. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  806. new_data = append(new_data, item)
  807. }
  808. }
  809. fmt.Println(len(new_data))
  810. c.ServeSuccessJSON(map[string]interface{}{
  811. "list": new_data,
  812. })
  813. }
  814. func (c *HisApiController) GetHisUnChargePatientList() {
  815. record_date := c.GetString("record_date")
  816. sch_type, _ := c.GetInt64("sch_type")
  817. timeLayout := "2006-01-02"
  818. loc, _ := time.LoadLocation("Local")
  819. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  820. if err != nil {
  821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  822. return
  823. }
  824. recordDateTime := theTime.Unix()
  825. adminInfo := c.GetAdminUserInfo()
  826. var tempPatients []*service.NewTempPatients
  827. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  828. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  829. var patients []*service.NewTempPatients
  830. var patients_two []*service.NewTempPatients
  831. for _, item := range tempPatients {
  832. //过滤掉没挂号的和没开处方的
  833. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  834. patients = append(patients, item)
  835. }
  836. //过滤掉没挂号的
  837. if len(item.HisPatient) > 0 {
  838. patients_two = append(patients_two, item)
  839. }
  840. }
  841. c.ServeSuccessJSON(map[string]interface{}{
  842. "list": patients,
  843. "list_two": patients_two,
  844. })
  845. }
  846. func (c *HisApiController) GetPrivateExpensesOrder() {
  847. //id, _ := c.GetInt64("id")
  848. //record_time := c.GetString("record_time")
  849. order_id, _ := c.GetInt64("order_id")
  850. admin_user_id, _ := c.GetInt64("admin_user_id")
  851. //timeLayout := "2006-01-02"
  852. //loc, _ := time.LoadLocation("Local")
  853. //
  854. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  855. //if err != nil {
  856. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  857. // return
  858. //}
  859. //recordDateTime := theTime.Unix()
  860. adminUser := c.GetAdminUserInfo()
  861. order, _ := service.GetHisOrderByID(order_id)
  862. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  863. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  864. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  865. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  866. //var config []*models.HisXtDiagnoseConfig
  867. var name string
  868. if order.PType == 1 {
  869. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  870. for _, item := range diagnosis_ids {
  871. id, _ := strconv.ParseInt(item, 10, 64)
  872. diagnosisConfig, _ := service.FindDiagnoseById(id)
  873. if len(name) == 0 {
  874. name = diagnosisConfig.ClassName
  875. } else {
  876. name = name + "," + diagnosisConfig.ClassName
  877. }
  878. }
  879. } else {
  880. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  881. for _, item := range diagnosis_ids {
  882. id, _ := strconv.ParseInt(item, 10, 64)
  883. diagnosisConfig, _ := service.FindDiagnoseById(id)
  884. if len(name) == 0 {
  885. name = diagnosisConfig.ClassName
  886. } else {
  887. name = name + "," + diagnosisConfig.ClassName
  888. }
  889. }
  890. }
  891. var bedCostTotal float64 = 0 //床位总费
  892. //var bedCostSelfTotal float64 = 0 //床位自费
  893. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  894. var operationCostTotal float64 = 0 //手术费
  895. //var operationCostSelfTotal float64 = 0 //手术费
  896. var operationCostPartSelfTotal float64 = 0 //手术费
  897. var otherCostTotal float64 = 0 //其他费用
  898. //var otherCostSelfTotal float64 = 0 //其他费用
  899. var otherCostPartSelfTotal float64 = 0 //其他费用
  900. var materialCostTotal float64 = 0 //材料费
  901. //var materialCostSelfTotal float64 = 0 //材料费
  902. var materialCostPartSelfTotal float64 = 0 //材料费
  903. var westernMedicineCostTotal float64 = 0 //西药费
  904. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  905. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  906. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  907. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  908. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  909. var checkCostTotal float64 = 0 //检查费
  910. //var checkCostSelfTotal float64 = 0 //检查费
  911. var checkCostPartSelfTotal float64 = 0 //检查费
  912. var laboratoryCostTotal float64 = 0 //化验费
  913. //var laboratoryCostSelfTotal float64 = 0 //化验费
  914. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  915. var treatCostTotal float64 = 0 //治疗费用
  916. //var treatCostSelfTotal float64 = 0 //治疗费用
  917. var treatCostPartSelfTotal float64 = 0 //治疗费用
  918. var zhenChaCostTotal float64 = 0 //其他费用
  919. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  920. decimal.DivisionPrecision = 2
  921. for _, item := range orderInfos {
  922. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  923. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  924. item.MedChrgitmType = "09"
  925. }
  926. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  927. if item.HisPrescriptionProject.Type == 2 {
  928. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  929. fmt.Println("CostClassify")
  930. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  931. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  932. case 0:
  933. item.MedChrgitmType = "0"
  934. break
  935. case 1:
  936. item.MedChrgitmType = "14"
  937. break
  938. case 2:
  939. item.MedChrgitmType = "05"
  940. break
  941. case 3:
  942. item.MedChrgitmType = "03"
  943. break
  944. case 4:
  945. item.MedChrgitmType = "03"
  946. break
  947. case 5:
  948. item.MedChrgitmType = "08"
  949. break
  950. case 6:
  951. item.MedChrgitmType = "14"
  952. break
  953. case 7:
  954. item.MedChrgitmType = "14"
  955. break
  956. case 8:
  957. item.MedChrgitmType = "03"
  958. break
  959. case 9:
  960. item.MedChrgitmType = "14"
  961. break
  962. case 10:
  963. item.MedChrgitmType = "14"
  964. break
  965. case 11:
  966. item.MedChrgitmType = "06"
  967. break
  968. case 12:
  969. item.MedChrgitmType = "12"
  970. break
  971. case 13:
  972. item.MedChrgitmType = "01"
  973. break
  974. case 14:
  975. item.MedChrgitmType = "04"
  976. break
  977. case 15:
  978. item.MedChrgitmType = "14"
  979. break
  980. }
  981. } else {
  982. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  983. case 1:
  984. item.MedChrgitmType = "14"
  985. break
  986. case 2:
  987. item.MedChrgitmType = "05"
  988. break
  989. case 3:
  990. item.MedChrgitmType = "04"
  991. break
  992. case 4:
  993. item.MedChrgitmType = "14"
  994. break
  995. case 5:
  996. item.MedChrgitmType = "08"
  997. break
  998. case 6:
  999. item.MedChrgitmType = "14"
  1000. break
  1001. case 7:
  1002. item.MedChrgitmType = "14"
  1003. break
  1004. case 8:
  1005. item.MedChrgitmType = "03"
  1006. break
  1007. case 9:
  1008. item.MedChrgitmType = "14"
  1009. break
  1010. default:
  1011. item.MedChrgitmType = "14"
  1012. break
  1013. }
  1014. }
  1015. } else if item.HisPrescriptionProject.Type == 3 {
  1016. item.MedChrgitmType = "08"
  1017. }
  1018. }
  1019. }
  1020. if order.IsMedicineInsurance != 1 {
  1021. order.PsnCashPay = order.MedfeeSumamt
  1022. }
  1023. for _, item := range orderInfos {
  1024. if item.MedChrgitmType == "01" { //床位费
  1025. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1026. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1027. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1028. }
  1029. if item.MedChrgitmType == "02" { //诊察费
  1030. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1031. //zhenChaCostSelfTotal = zhenChaCostTotal
  1032. }
  1033. if item.MedChrgitmType == "03" { //检查费
  1034. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1035. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1036. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1037. }
  1038. if item.MedChrgitmType == "02" { //检查费
  1039. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1040. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1041. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1042. }
  1043. if item.MedChrgitmType == "04" { //化验费
  1044. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1045. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1046. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1047. }
  1048. if item.MedChrgitmType == "05" { //治疗费
  1049. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1050. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1051. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1052. }
  1053. if item.MedChrgitmType == "06" { //手术费
  1054. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1055. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1056. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1057. }
  1058. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1059. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1060. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1061. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1062. }
  1063. if item.MedChrgitmType == "09" { //西药费
  1064. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1065. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1066. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1067. }
  1068. if item.MedChrgitmType == "11" { //中成费
  1069. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1070. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1071. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1072. }
  1073. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1074. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1075. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1076. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1077. }
  1078. }
  1079. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1080. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1081. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1082. var dia_config []*models.HisXtDiagnoseConfig
  1083. var diagnosis_ids []string
  1084. if his.ID > 0 {
  1085. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1086. } else {
  1087. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1088. }
  1089. for _, item := range diagnosis_ids {
  1090. id, _ := strconv.ParseInt(item, 10, 64)
  1091. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1092. dia_config = append(dia_config, diagnosisConfig)
  1093. }
  1094. var rf []CustomFundPay
  1095. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1096. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1097. c.ServeSuccessJSON(map[string]interface{}{
  1098. "patient": patient,
  1099. "order_infos": orderInfos,
  1100. "diagnosis": name,
  1101. "bedCostTotal": bedCostTotal,
  1102. "bedCostSelfTotal": bedCostTotal,
  1103. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1104. "operationCostTotal": operationCostTotal,
  1105. "operationCostSelfTotal": operationCostTotal,
  1106. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1107. "otherCostTotal": otherCostTotal,
  1108. "otherCostSelfTotal": otherCostTotal,
  1109. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1110. "materialCostTotal": materialCostTotal,
  1111. "materialCostSelfTotal": materialCostTotal,
  1112. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1113. "westernMedicineCostTotal": westernMedicineCostTotal,
  1114. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1115. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1116. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1117. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1118. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1119. "checkCostTotal": checkCostTotal,
  1120. "checkCostSelfTotal": checkCostTotal,
  1121. "zhenChaCostTotal": zhenChaCostTotal,
  1122. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1123. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1124. "laboratoryCostTotal": laboratoryCostTotal,
  1125. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1126. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1127. "treatCostTotal": treatCostTotal,
  1128. "treatCostSelfTotal": treatCostTotal,
  1129. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1130. "charge_admin": charge_admin,
  1131. "printor_admin": printor_admin,
  1132. "org_name": org.OrgName,
  1133. "org_code": miConfig.Code,
  1134. "name": patient.Name,
  1135. "number": order.MdtrtId,
  1136. "date": order.SettleAccountsDate,
  1137. "info": order,
  1138. "new_order": order,
  1139. "his_hospital": his_hospital,
  1140. "his": his,
  1141. "funds": rf,
  1142. "dia_config": dia_config,
  1143. })
  1144. }
  1145. func (c *HisApiController) RefudDetail() {
  1146. order_id, _ := c.GetInt64("order_id")
  1147. order, _ := service.GetHisOrderByID(order_id)
  1148. adminUser := c.GetAdminUserInfo()
  1149. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1150. c.ServeSuccessJSON(map[string]interface{}{
  1151. "msg": "撤销成功",
  1152. })
  1153. }
  1154. func (c *HisApiController) Sscard() {
  1155. //r := CardInit()
  1156. //if r == 0 {
  1157. // GetBaseInfo()
  1158. //}
  1159. //c.ServeSuccessJSON(map[string]interface{}{
  1160. // "list": "11",
  1161. //})
  1162. }
  1163. func GetBaseInfo() error {
  1164. //handle := syscall.MustLoadDLL("SSCard.dll")
  1165. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1166. //
  1167. //str := make([]byte, 256)
  1168. //str1 := make([]byte, 256)
  1169. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1170. //if ferr != nil {
  1171. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1172. // return ferr
  1173. //}
  1174. //
  1175. //fmt.Println(string(str))
  1176. //
  1177. //fmt.Println(r)
  1178. return nil
  1179. }
  1180. func CardInit() int {
  1181. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1182. //add := DllTestDef.MustFindProc("Init")
  1183. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1184. //if err != nil {
  1185. // fmt.Println("SSCard的运算结果为:", ret)
  1186. //}
  1187. //result := int(ret)
  1188. return 0
  1189. }
  1190. func IntPtr(n int) uintptr {
  1191. return uintptr(n)
  1192. }
  1193. func StrPtr(s string) uintptr {
  1194. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1195. }
  1196. func (c *HisApiController) GetHisPatientList() {
  1197. //types, _ := c.GetInt64("type", 0)
  1198. record_date := c.GetString("record_date")
  1199. sch_type, _ := c.GetInt64("sch_type")
  1200. timeLayout := "2006-01-02"
  1201. loc, _ := time.LoadLocation("Local")
  1202. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1203. if err != nil {
  1204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1205. return
  1206. }
  1207. recordDateTime := theTime.Unix()
  1208. adminInfo := c.GetAdminUserInfo()
  1209. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1210. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1211. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1212. //patient_three, _ := service.GetNewHisPatientListTwo(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1213. //patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1214. //获取当前用户的信息
  1215. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1216. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1217. //获取所有科室信息
  1218. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1219. //var aa []service.PatientThree
  1220. noElementsSlice := make([]service.PatientThree, 0)
  1221. c.ServeSuccessJSON(map[string]interface{}{
  1222. "list": patients,
  1223. "list_two": patients_two,
  1224. "list_three": noElementsSlice,
  1225. "info": adminUserInfo,
  1226. "doctors": doctors,
  1227. "department": department,
  1228. })
  1229. }
  1230. type CustomTemplate struct {
  1231. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1232. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1233. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1234. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1235. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1236. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1237. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1238. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1239. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1240. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1241. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1242. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1243. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1244. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1245. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1246. }
  1247. func (c *HisApiController) GetHisPatientInfo() {
  1248. patient_id, _ := c.GetInt64("patient_id")
  1249. his_patient_id, _ := c.GetInt64("his_patient_id")
  1250. record_date := c.GetString("record_date")
  1251. number := c.GetString("number")
  1252. //start_time := c.GetString("start_time")
  1253. //end_time := c.GetString("end_time")
  1254. p_type, _ := c.GetInt64("p_type")
  1255. timeLayout := "2006-01-02"
  1256. loc, _ := time.LoadLocation("Local")
  1257. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1258. if err != nil {
  1259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1260. return
  1261. }
  1262. recordDateTime := theTime.Unix()
  1263. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1264. //if err != nil {
  1265. //
  1266. //}
  1267. //startRecordDateTime := startTime.Unix()
  1268. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1269. //if err != nil {
  1270. //
  1271. //}
  1272. //endRecordDateTime := endTime.Unix()
  1273. admin := c.GetAdminUserInfo()
  1274. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1275. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1276. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1277. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1278. var prescriptions []*models.HisPrescription
  1279. var last_prescriptions []*models.HisPrescription
  1280. var sch_prescriptions []CustomTemplate
  1281. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1282. if p_type == 1 { //住院
  1283. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1284. for _, item := range prescriptions {
  1285. for _, subItem := range item.HisDoctorAdviceInfo {
  1286. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1287. if info.RetailPrice > 0 {
  1288. subItem.Drug.MinPrice = info.RetailPrice
  1289. }
  1290. }
  1291. }
  1292. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1293. } else { //门诊
  1294. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1295. for _, item := range prescriptions {
  1296. for _, subItem := range item.HisDoctorAdviceInfo {
  1297. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1298. if info.RetailPrice > 0 {
  1299. subItem.Drug.MinPrice = info.RetailPrice
  1300. }
  1301. }
  1302. }
  1303. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1304. }
  1305. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1306. if sch.ID > 0 {
  1307. var week string
  1308. t := time.Now()
  1309. switch t.Weekday().String() {
  1310. case "Monday":
  1311. week = "周一"
  1312. break
  1313. case "Tuesday":
  1314. week = "周二"
  1315. break
  1316. case "Wednesday":
  1317. week = "周三"
  1318. break
  1319. case "Thursday":
  1320. week = "周四"
  1321. break
  1322. case "Friday":
  1323. week = "周五"
  1324. break
  1325. case "Saturday":
  1326. week = "周六"
  1327. break
  1328. case "Sunday":
  1329. week = "周日"
  1330. break
  1331. }
  1332. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1333. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1334. //根据推送频率组装新的数组
  1335. for _, item := range temp_sch_prescriptions {
  1336. var cus CustomTemplate
  1337. cus.ID = item.ID
  1338. cus.UserOrgId = item.UserOrgId
  1339. cus.PatientId = item.PatientId
  1340. cus.MedType = item.MedType
  1341. cus.RecordDate = item.RecordDate
  1342. cus.Type = item.Type
  1343. cus.PType = item.PType
  1344. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1345. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1346. if subItem.FrequencyType == 1 { //每次必推
  1347. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1348. }
  1349. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1350. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1351. }
  1352. if subItem.FrequencyType == 2 { //按照天数频率
  1353. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1354. now := p.Unix()
  1355. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1356. dayStr2 := "-" + dayStr
  1357. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1358. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1359. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1360. if len(advices) == 0 {
  1361. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1362. }
  1363. }
  1364. }
  1365. }
  1366. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1367. if subItem.Type == 2 {
  1368. if subItem.XtHisProject.MedicalStatus != 1 {
  1369. if subItem.FrequencyType == 1 {
  1370. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1371. }
  1372. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1373. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1374. }
  1375. if subItem.FrequencyType == 2 {
  1376. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1377. now := p.Unix()
  1378. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1379. dayStr2 := "-" + dayStr
  1380. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1381. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1382. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1383. if len(projects) == 0 {
  1384. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1385. }
  1386. }
  1387. }
  1388. } else if subItem.Type == 3 {
  1389. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1390. if subItem.FrequencyType == 1 {
  1391. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1392. }
  1393. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1394. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1395. }
  1396. if subItem.FrequencyType == 2 {
  1397. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1398. now := p.Unix()
  1399. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1400. dayStr2 := "-" + dayStr
  1401. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1402. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1403. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1404. if len(projects) == 0 {
  1405. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1406. }
  1407. }
  1408. }
  1409. }
  1410. }
  1411. sch_prescriptions = append(sch_prescriptions, cus)
  1412. }
  1413. for _, item := range sch_prescriptions {
  1414. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1415. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1416. }
  1417. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1418. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1419. }
  1420. }
  1421. }
  1422. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1423. if config.ID > 0 && config.IsOpen == 1 {
  1424. for _, item := range sch_prescriptions {
  1425. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1426. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1427. if info.RetailPrice > 0 {
  1428. subItem.Drug.MinPrice = info.RetailPrice
  1429. if admin.CurrentOrgId != 10598 {
  1430. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1431. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1432. }
  1433. }
  1434. }
  1435. }
  1436. }
  1437. if config.ID > 0 && config.IsOpen == 1 {
  1438. for _, item := range sch_prescriptions {
  1439. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1440. if subItem.Type == 3 {
  1441. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1442. if info.Price > 0 {
  1443. subItem.GoodInfo.PackingPrice = info.Price
  1444. if admin.CurrentOrgId != 10598 {
  1445. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1446. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1447. }
  1448. }
  1449. }
  1450. }
  1451. }
  1452. }
  1453. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1454. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1455. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1456. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1457. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1458. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1459. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1460. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1461. //获取所有科室信息
  1462. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1463. beforThrity, _ := service.GetAssessmentBeforThrity(admin.CurrentOrgId, patient_id, recordDateTime)
  1464. LastCaseHistory, _ := service.GetLastHisPatientCaseHistory(admin.CurrentOrgId, patient_id)
  1465. c.ServeSuccessJSON(map[string]interface{}{
  1466. "his_info": his_patient_info,
  1467. "xt_info": xt_patient_info,
  1468. "prescription": prescriptions,
  1469. "case_history": case_history,
  1470. "info": patientPrescriptionInfo,
  1471. //"month_prescriptions": monthPrescriptions,
  1472. "order": order,
  1473. "doctors": doctors,
  1474. "department": department,
  1475. "sch_prescriptions": sch_prescriptions,
  1476. "last_prescriptions": last_prescriptions,
  1477. "schedule": sch,
  1478. "count": count,
  1479. "drugStockConfig": drugStockConfig,
  1480. "last_info": lastPatientPrescriptionInfo,
  1481. "befor": beforThrity,
  1482. "LastCaseHistory": LastCaseHistory,
  1483. })
  1484. return
  1485. }
  1486. func (c *HisApiController) GetHisPrescriptionConfig() {
  1487. adminInfo := c.GetAdminUserInfo()
  1488. //获取医嘱模版
  1489. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1490. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1491. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1492. //获取所有基础药
  1493. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1494. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1495. if config.ID > 0 && config.IsOpen == 1 {
  1496. for _, item := range drugs {
  1497. var index = 0
  1498. for _, subItem := range item.OtherDrugWarehouseInfo {
  1499. if index == 0 {
  1500. index = index + 1
  1501. if subItem.RetailPrice > 0 {
  1502. item.MinPrice = subItem.RetailPrice
  1503. }
  1504. }
  1505. }
  1506. }
  1507. }
  1508. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1509. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1510. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1511. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1512. //获取所有科室信息
  1513. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1514. //获取诊断信息
  1515. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1516. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1517. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1518. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1519. //获取是否开启保存耗材出库的开关
  1520. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1521. c.ServeSuccessJSON(map[string]interface{}{
  1522. "drugs": drugs,
  1523. "advices_template": advices,
  1524. "drugways": drugways,
  1525. "efs": efs,
  1526. "doctors": doctors,
  1527. "department": department,
  1528. "sick": sick,
  1529. "additions": additions,
  1530. "diagnose": diagnose,
  1531. "manufacturers": manufacturers,
  1532. "goodOutOpen": goodOutOpen,
  1533. "patientDiagnose": patientDiagnose,
  1534. })
  1535. }
  1536. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1537. //获取所有基础药
  1538. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1539. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1540. if config.ID > 0 && config.IsOpen == 1 {
  1541. for _, item := range drugs {
  1542. var index = 0
  1543. for _, subItem := range item.OtherDrugWarehouseInfo {
  1544. if index == 0 {
  1545. index = index + 1
  1546. if subItem.RetailPrice > 0 {
  1547. item.MinPrice = subItem.RetailPrice
  1548. }
  1549. }
  1550. }
  1551. }
  1552. }
  1553. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1554. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1555. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1556. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1557. //获取所有科室信息
  1558. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1559. //获取诊断信息
  1560. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1561. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1562. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1563. //获取是否开启保存耗材出库的开关
  1564. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1565. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1566. c.ServeSuccessJSON(map[string]interface{}{
  1567. "drugs": drugs,
  1568. "advices_template": advices,
  1569. "drugways": drugways,
  1570. "efs": efs,
  1571. "doctors": doctors,
  1572. "department": department,
  1573. "sick": sick,
  1574. "additions": additions,
  1575. "diagnose": diagnose,
  1576. "manufacturers": manufacturers,
  1577. "goodOutOpen": goodOutOpen,
  1578. "patientDiagnose": patientDiagnose,
  1579. })
  1580. }
  1581. }
  1582. func (c *HisApiController) CreateHisPrescription() {
  1583. record_date := c.GetString("record_date")
  1584. patient_id, _ := c.GetInt64("patient_id")
  1585. reg_type, _ := c.GetInt64("reg_type")
  1586. diagnose := c.GetString("diagnose")
  1587. sick_type, _ := c.GetInt64("sick_type")
  1588. sick_history := c.GetString("sick_history")
  1589. doctor_id, _ := c.GetInt64("doctor", 0)
  1590. department, _ := c.GetInt64("department", 0)
  1591. his_patient_id, _ := c.GetInt64("his_patient_id")
  1592. p_type, _ := c.GetInt64("p_type")
  1593. patient_diagnose := c.GetString("patient_diagnose")
  1594. dataBody := make(map[string]interface{}, 0)
  1595. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1596. if err != nil {
  1597. utils.ErrorLog(err.Error())
  1598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1599. return
  1600. }
  1601. //edit, src := GetCompareData(dataBody)
  1602. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1603. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1604. //fmt.Println(drugResult)
  1605. //fmt.Println(goodResult)
  1606. timeLayout := "2006-01-02"
  1607. loc, _ := time.LoadLocation("Local")
  1608. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1609. if err != nil {
  1610. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1611. return
  1612. }
  1613. adminInfo := c.GetAdminUserInfo()
  1614. recordDateTime := theTime.Unix()
  1615. //查询默认出库仓库库存
  1616. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1617. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1618. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1619. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1620. if len(lists) == 1 {
  1621. his_patient_id = lists[0].ID
  1622. }
  1623. }
  1624. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1625. //自动出库的开关开启
  1626. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1627. //自动出库
  1628. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1629. //耗材保存处方出库
  1630. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1631. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1632. //已发药和已收费限制逻辑
  1633. isMidicine := false
  1634. isCharge := false
  1635. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1636. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1637. if len(prescriptions) > 0 {
  1638. for _, item := range prescriptions {
  1639. items := item.(map[string]interface{})
  1640. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1641. utils.ErrorLog("id")
  1642. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1643. return
  1644. }
  1645. id := int64(items["id"].(float64))
  1646. if id > 0 {
  1647. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1648. if err != nil {
  1649. if new_prescription.OrderStatus == 4 {
  1650. isCharge = true
  1651. }
  1652. }
  1653. }
  1654. }
  1655. }
  1656. }
  1657. if isMidicine == true {
  1658. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1659. return
  1660. }
  1661. if isCharge == true {
  1662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1663. return
  1664. }
  1665. // 开始主事务
  1666. db := service.XTWriteDB()
  1667. tx := db.Begin()
  1668. // 在函数结束时处理事务回滚
  1669. defer func() {
  1670. if r := recover(); r != nil {
  1671. tx.Rollback()
  1672. }
  1673. }()
  1674. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1675. //药品发药出库
  1676. if pharmacyConfig.IsOpen == 1 {
  1677. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1678. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1679. if len(prescriptions) > 0 {
  1680. for _, item := range prescriptions {
  1681. items := item.(map[string]interface{})
  1682. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1683. advices := items["advices"].([]interface{})
  1684. if len(advices) > 0 {
  1685. for _, advice := range advices {
  1686. var drug_id int64
  1687. var prescribing_number float64
  1688. var prescribingNumberUnit string
  1689. var adviceId int64
  1690. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1691. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1692. }
  1693. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1694. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1695. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1696. }
  1697. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1698. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1699. }
  1700. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1701. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1702. }
  1703. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1704. if drug.ID == 0 {
  1705. tx.Rollback()
  1706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1707. return
  1708. }
  1709. //查询药品的所有库存
  1710. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1711. var total_count int64
  1712. for _, it := range list {
  1713. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1714. }
  1715. totals := strconv.FormatInt(total_count, 10)
  1716. //查询该药品是否存在开药记录
  1717. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1718. //新增处方盘点库存是否充足
  1719. if advicelist.ID == 0 {
  1720. all_count, _ := strconv.ParseFloat(totals, 64)
  1721. if prescribingNumberUnit == drug.MinUnit {
  1722. if drug.IsUse != 1 {
  1723. if drug.IsProject == 0 || drug.IsProject == 2 {
  1724. if all_count == 0 {
  1725. tx.Rollback()
  1726. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1727. return
  1728. }
  1729. if prescribing_number > all_count {
  1730. tx.Rollback()
  1731. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1732. return
  1733. }
  1734. }
  1735. }
  1736. }
  1737. if prescribingNumberUnit == drug.MaxUnit {
  1738. num := prescribing_number * float64(drug.MinNumber)
  1739. if drug.IsUse != 1 {
  1740. if drug.IsProject == 0 || drug.IsProject == 2 {
  1741. if all_count == 0 {
  1742. tx.Rollback()
  1743. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1744. return
  1745. }
  1746. if num > all_count {
  1747. tx.Rollback()
  1748. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1749. return
  1750. }
  1751. }
  1752. }
  1753. }
  1754. }
  1755. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1756. //不使用保存处方出库
  1757. if drugOutConfig.IsOpen != 1 {
  1758. //修改处方
  1759. for _, advice := range advices {
  1760. var drug_id int64
  1761. var prescribing_number float64
  1762. var prescribingNumberUnit string
  1763. var prescribingNumber string
  1764. var adviceId int64
  1765. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1766. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1767. }
  1768. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1769. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1770. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1771. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1772. }
  1773. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1774. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1775. }
  1776. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1777. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1778. }
  1779. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1780. if drug.ID == 0 {
  1781. tx.Rollback()
  1782. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1783. return
  1784. }
  1785. //查询药品的所有库存
  1786. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1787. var total_count int64
  1788. for _, it := range list {
  1789. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1790. }
  1791. totals := strconv.FormatInt(total_count, 10)
  1792. //查询该药品是否存在开药记录
  1793. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1794. //新增处方
  1795. if advicelist.ID == 0 {
  1796. all_count, _ := strconv.ParseFloat(totals, 64)
  1797. if prescribingNumberUnit == drug.MinUnit {
  1798. if drug.IsUse != 1 {
  1799. if drug.IsProject == 0 || drug.IsProject == 2 {
  1800. if all_count == 0 {
  1801. tx.Rollback()
  1802. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1803. return
  1804. }
  1805. if prescribing_number > all_count {
  1806. tx.Rollback()
  1807. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1808. return
  1809. }
  1810. }
  1811. }
  1812. } else {
  1813. if prescribingNumberUnit == drug.MaxUnit {
  1814. num := prescribing_number * float64(drug.MinNumber)
  1815. if drug.IsUse != 1 {
  1816. if drug.IsProject == 0 || drug.IsProject == 2 {
  1817. if all_count == 0 {
  1818. tx.Rollback()
  1819. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1820. return
  1821. }
  1822. if num > all_count {
  1823. tx.Rollback()
  1824. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1825. return
  1826. }
  1827. }
  1828. }
  1829. }
  1830. }
  1831. }
  1832. //修改处方
  1833. if advicelist.ID > 0 {
  1834. var device_number int64
  1835. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1836. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1837. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1838. device_number = prescribingNumberInt * drug.MinNumber
  1839. }
  1840. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1841. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1842. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1843. device_number = prescribingNumberInt
  1844. }
  1845. var number_count int64
  1846. if prescribingNumberUnit == drug.MaxUnit {
  1847. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1848. number_count = prescribingNumberInt * drug.MinNumber
  1849. }
  1850. if prescribingNumberUnit == drug.MinUnit {
  1851. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1852. number_count = prescribingNumberInt
  1853. }
  1854. //如果修改的数量大于之前修改的数量
  1855. if (number_count - device_number) > 0 {
  1856. //如果修改的差数量 大于库存数量
  1857. if drug.IsUse != 1 {
  1858. if (number_count - device_number) > total_count {
  1859. tx.Rollback()
  1860. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1861. return
  1862. }
  1863. }
  1864. }
  1865. }
  1866. }
  1867. }
  1868. }
  1869. }
  1870. }
  1871. }
  1872. }
  1873. }
  1874. }
  1875. //已发药和已收费限制逻辑
  1876. //执行出库的逻辑
  1877. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1878. //校验库存总量
  1879. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1880. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1881. if len(prescriptions) > 0 {
  1882. for _, item := range prescriptions {
  1883. items := item.(map[string]interface{})
  1884. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1885. advices := items["advices"].([]interface{})
  1886. if len(advices) > 0 {
  1887. for _, advice := range advices {
  1888. var drug_id int64
  1889. var prescribing_number float64
  1890. var prescribingNumberUnit string
  1891. var adviceId int64
  1892. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1893. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1894. }
  1895. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1896. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1897. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1898. }
  1899. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1900. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1901. }
  1902. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1903. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1904. }
  1905. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1906. if drug.ID == 0 {
  1907. tx.Rollback()
  1908. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1909. return
  1910. }
  1911. //查询药品的所有库存
  1912. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1913. var total_count int64
  1914. for _, it := range list {
  1915. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1916. }
  1917. totals := strconv.FormatInt(total_count, 10)
  1918. //查询该药品是否存在开药记录
  1919. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1920. //查询最新批次库存
  1921. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1922. var batch_number_count int64
  1923. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1924. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1925. //新增处方
  1926. if advicelist.ID == 0 {
  1927. all_count, _ := strconv.ParseFloat(totals, 64)
  1928. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1929. if prescribingNumberUnit == drug.MinUnit {
  1930. if drug.IsUse != 1 {
  1931. if drug.IsProject == 0 || drug.IsProject == 2 {
  1932. if all_count == 0 {
  1933. tx.Rollback()
  1934. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1935. return
  1936. }
  1937. if prescribing_number > all_count {
  1938. tx.Rollback()
  1939. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1940. return
  1941. }
  1942. }
  1943. if adminInfo.CurrentOrgId == 10215 {
  1944. if prescribing_number > batch_number_all_count {
  1945. tx.Rollback()
  1946. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1947. return
  1948. }
  1949. }
  1950. }
  1951. }
  1952. if prescribingNumberUnit == drug.MaxUnit {
  1953. num := prescribing_number * float64(drug.MinNumber)
  1954. if drug.IsUse != 1 {
  1955. if drug.IsProject == 0 || drug.IsProject == 2 {
  1956. if all_count == 0 {
  1957. tx.Rollback()
  1958. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1959. return
  1960. }
  1961. if num > all_count {
  1962. tx.Rollback()
  1963. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1964. return
  1965. }
  1966. }
  1967. if adminInfo.CurrentOrgId == 10215 {
  1968. if num > batch_number_all_count {
  1969. tx.Rollback()
  1970. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1971. return
  1972. }
  1973. }
  1974. }
  1975. }
  1976. }
  1977. //不是保存处方出库
  1978. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1979. if drugOutConfig.IsOpen != 1 {
  1980. //修改处方
  1981. for _, advice := range advices {
  1982. var drug_id int64
  1983. var prescribing_number float64
  1984. var prescribingNumberUnit string
  1985. var prescribingNumber string
  1986. var adviceId int64
  1987. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1988. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1989. }
  1990. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1991. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1992. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1993. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1994. }
  1995. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1996. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1997. }
  1998. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1999. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2000. }
  2001. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2002. if drug.ID == 0 {
  2003. tx.Rollback()
  2004. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2005. return
  2006. }
  2007. //查询药品的所有库存
  2008. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2009. var total_count int64
  2010. for _, it := range list {
  2011. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2012. }
  2013. totals := strconv.FormatInt(total_count, 10)
  2014. //查询该药品是否存在开药记录
  2015. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2016. //新增处方
  2017. if advicelist.ID == 0 {
  2018. //查询最新批次库存
  2019. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2020. var batch_number_count int64
  2021. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2022. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2023. all_count, _ := strconv.ParseFloat(totals, 64)
  2024. if all_count == 0 {
  2025. tx.Rollback()
  2026. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2027. return
  2028. }
  2029. if prescribingNumberUnit == drug.MinUnit {
  2030. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2031. if drug.IsUse != 1 {
  2032. if drug.IsProject == 0 || drug.IsProject == 2 {
  2033. if all_count == 0 {
  2034. tx.Rollback()
  2035. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2036. return
  2037. }
  2038. if prescribing_number > all_count {
  2039. tx.Rollback()
  2040. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2041. return
  2042. }
  2043. }
  2044. if adminInfo.CurrentOrgId == 10215 {
  2045. if prescribing_number > batch_number_all_count {
  2046. tx.Rollback()
  2047. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2048. return
  2049. }
  2050. }
  2051. }
  2052. } else {
  2053. if prescribingNumberUnit == drug.MaxUnit {
  2054. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2055. num := prescribing_number * float64(drug.MinNumber)
  2056. if drug.IsUse != 1 {
  2057. if drug.IsProject == 0 || drug.IsProject == 2 {
  2058. if all_count == 0 {
  2059. tx.Rollback()
  2060. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2061. return
  2062. }
  2063. if num > all_count {
  2064. tx.Rollback()
  2065. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2066. return
  2067. }
  2068. }
  2069. if adminInfo.CurrentOrgId == 10215 {
  2070. if prescribing_number > batch_number_all_count {
  2071. tx.Rollback()
  2072. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2073. return
  2074. }
  2075. }
  2076. }
  2077. }
  2078. }
  2079. }
  2080. //修改处方
  2081. if advicelist.ID > 0 {
  2082. //查询最新批次库存
  2083. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2084. var batch_number_count int64
  2085. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2086. var device_number int64
  2087. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2088. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2089. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2090. device_number = prescribingNumberInt * drug.MinNumber
  2091. }
  2092. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2093. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2094. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2095. device_number = prescribingNumberInt
  2096. //回退库存
  2097. }
  2098. var number_count int64
  2099. if prescribingNumberUnit == drug.MaxUnit {
  2100. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2101. number_count = prescribingNumberInt * drug.MinNumber
  2102. //回退库存
  2103. }
  2104. if prescribingNumberUnit == drug.MinUnit {
  2105. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2106. number_count = prescribingNumberInt
  2107. //回退库存
  2108. }
  2109. //如果修改的数量大于之前修改的数量
  2110. if (number_count - device_number) > 0 {
  2111. //如果修改的差数量 大于库存数量
  2112. if drug.IsUse != 1 {
  2113. if drug.IsProject == 0 || drug.IsProject == 2 {
  2114. if total_count == 0 {
  2115. tx.Rollback()
  2116. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2117. return
  2118. }
  2119. if (number_count - device_number) > total_count {
  2120. tx.Rollback()
  2121. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2122. return
  2123. }
  2124. if (number_count - device_number) > batch_number_count {
  2125. tx.Rollback()
  2126. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2127. return
  2128. }
  2129. }
  2130. if adminInfo.CurrentOrgId == 10215 {
  2131. // 查询该药品最后一次出库记录
  2132. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2133. var out_count int64
  2134. var in_count int64
  2135. var stock_max_number int64
  2136. var stock_min_number int64
  2137. for _, it := range outInfo {
  2138. if it.CountUnit == drug.MaxUnit {
  2139. it.Count = it.Count * drug.MinNumber
  2140. }
  2141. out_count += it.Count
  2142. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2143. stock_max_number = warehouseInfoList.StockMaxNumber
  2144. stock_min_number = warehouseInfoList.StockMinNumber
  2145. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2146. }
  2147. if out_count > 0 {
  2148. if (number_count - device_number) > in_count {
  2149. tx.Rollback()
  2150. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2151. return
  2152. }
  2153. }
  2154. // 未出库
  2155. if out_count == 0 {
  2156. var sum_in_count int64
  2157. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2158. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2159. //如果修改的数量大于有库存的第一个批次
  2160. if number_count > sum_in_count {
  2161. tx.Rollback()
  2162. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2163. return
  2164. }
  2165. }
  2166. }
  2167. }
  2168. }
  2169. //药品发药
  2170. //pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2171. //不使用药品发药的功能
  2172. //if pharmacyConfig.IsOpen != 1 {
  2173. // if device_number != number_count {
  2174. //
  2175. // //查询该药品的出库记录
  2176. // outListExport, _ := service.GetWarehouseOutListExport(drug_id, patient_id, recordDateTime, adviceId)
  2177. // if len(outListExport) > 0 {
  2178. // //
  2179. // for _, item := range outListExport {
  2180. // //回退库存
  2181. // if item.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2182. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, number_count)
  2183. // }
  2184. // if item.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2185. // var stock_max_number int64
  2186. // var stock_min_number int64
  2187. //
  2188. // if number_count >= drug.MinNumber {
  2189. //
  2190. // stock_max_number = device_number / drug.MinNumber
  2191. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, stock_max_number)
  2192. //
  2193. // stock_min_number = device_number % drug.MinNumber
  2194. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, stock_min_number)
  2195. //
  2196. // } else {
  2197. //
  2198. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, device_number)
  2199. //
  2200. // }
  2201. // }
  2202. //
  2203. // if item.CountUnit == drug.MaxUnit && item.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2204. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, device_number)
  2205. // }
  2206. // }
  2207. // }
  2208. //
  2209. // service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2210. // var sum_count int64
  2211. // orgId := c.GetAdminUserInfo().CurrentOrgId
  2212. // stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgId, drug_id)
  2213. // for _, its := range stockInfo {
  2214. // if its.MaxUnit == drug.MaxUnit {
  2215. // its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2216. // }
  2217. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2218. // }
  2219. // //更新字典里面的库存
  2220. // service.UpdateBaseDrugSumTwo(drug_id, sum_count, orgId)
  2221. //
  2222. // //剩余库存
  2223. // service.UpdateDrugStockCount(drug_id, orgId, storeConfig.DrugStorehouseOut, sum_count)
  2224. //
  2225. // over, _ := service.FindOverCount(drug_id, orgId, storeConfig.DrugStorehouseOut)
  2226. // //减少出库数量
  2227. // service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2228. //
  2229. // }
  2230. //}
  2231. }
  2232. }
  2233. }
  2234. //保存处方开药
  2235. if drugOutConfig.IsOpen == 1 {
  2236. //修改处方
  2237. for _, advice := range advices {
  2238. var drug_id int64
  2239. var prescribing_number float64
  2240. var prescribingNumberUnit string
  2241. var prescribingNumber string
  2242. var adviceId int64
  2243. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2244. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2245. }
  2246. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2247. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2248. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2249. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2250. }
  2251. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2252. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2253. }
  2254. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2255. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2256. }
  2257. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2258. if drug.ID == 0 {
  2259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2260. return
  2261. }
  2262. //查询药品的所有库存
  2263. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2264. var total_count int64
  2265. for _, it := range list {
  2266. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2267. }
  2268. totals := strconv.FormatInt(total_count, 10)
  2269. //查询该药品是否存在开药记录
  2270. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2271. //新增处方
  2272. if advicelist.ID == 0 {
  2273. //查询最新批次库存
  2274. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2275. var batch_number_count int64
  2276. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2277. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2278. all_count, _ := strconv.ParseFloat(totals, 64)
  2279. if prescribingNumberUnit == drug.MinUnit {
  2280. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2281. if drug.IsUse != 1 {
  2282. if drug.IsProject == 0 || drug.IsProject == 2 {
  2283. if all_count == 0 {
  2284. tx.Rollback()
  2285. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2286. return
  2287. }
  2288. if prescribing_number > all_count {
  2289. tx.Rollback()
  2290. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2291. return
  2292. }
  2293. }
  2294. if adminInfo.CurrentOrgId == 10215 {
  2295. if prescribing_number > batch_number_all_count {
  2296. tx.Rollback()
  2297. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2298. return
  2299. }
  2300. }
  2301. }
  2302. } else {
  2303. if prescribingNumberUnit == drug.MaxUnit {
  2304. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2305. num := prescribing_number * float64(drug.MinNumber)
  2306. if drug.IsUse != 1 {
  2307. if drug.IsProject == 0 || drug.IsProject == 2 {
  2308. if all_count == 0 {
  2309. tx.Rollback()
  2310. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2311. return
  2312. }
  2313. if num > all_count {
  2314. tx.Rollback()
  2315. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2316. return
  2317. }
  2318. }
  2319. if adminInfo.CurrentOrgId == 10215 {
  2320. if prescribing_number > batch_number_all_count {
  2321. tx.Rollback()
  2322. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2323. return
  2324. }
  2325. }
  2326. }
  2327. }
  2328. }
  2329. }
  2330. //修改处方
  2331. if advicelist.ID > 0 {
  2332. //查询最新批次库存
  2333. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2334. var batch_number_count int64
  2335. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2336. var device_number int64
  2337. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2338. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2339. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2340. device_number = prescribingNumberInt * drug.MinNumber
  2341. }
  2342. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2343. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2344. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2345. device_number = prescribingNumberInt
  2346. }
  2347. var number_count int64
  2348. if prescribingNumberUnit == drug.MaxUnit {
  2349. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2350. number_count = prescribingNumberInt * drug.MinNumber
  2351. }
  2352. if prescribingNumberUnit == drug.MinUnit {
  2353. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2354. number_count = prescribingNumberInt
  2355. }
  2356. //如果修改的数量大于之前修改的数量
  2357. if (number_count - device_number) > 0 {
  2358. //如果修改的差数量 大于库存数量
  2359. if drug.IsUse != 1 {
  2360. if drug.IsProject == 0 || drug.IsProject == 2 {
  2361. if total_count == 0 {
  2362. tx.Rollback()
  2363. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2364. return
  2365. }
  2366. if (number_count - device_number) > total_count {
  2367. tx.Rollback()
  2368. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2369. return
  2370. }
  2371. }
  2372. if adminInfo.CurrentOrgId == 10215 {
  2373. if (number_count - device_number) > batch_number_count {
  2374. tx.Rollback()
  2375. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2376. return
  2377. }
  2378. }
  2379. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2380. //查询历史出库数据总批次
  2381. // 查询该药品最后一次出库记录
  2382. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2383. var out_count int64
  2384. var in_count int64
  2385. var stock_max_number int64
  2386. var stock_min_number int64
  2387. for _, it := range outInfo {
  2388. if it.CountUnit == drug.MaxUnit {
  2389. it.Count = it.Count * drug.MinNumber
  2390. }
  2391. out_count += it.Count
  2392. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2393. stock_max_number = warehouseInfoList.StockMaxNumber
  2394. stock_min_number = warehouseInfoList.StockMinNumber
  2395. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2396. }
  2397. if out_count > 0 {
  2398. if (number_count - device_number) > in_count {
  2399. tx.Rollback()
  2400. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2401. return
  2402. }
  2403. }
  2404. // 未出库
  2405. if out_count == 0 {
  2406. var sum_in_count int64
  2407. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2408. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2409. if sum_in_count == 0 {
  2410. tx.Rollback()
  2411. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2412. return
  2413. }
  2414. //如果修改的数量大于有库存的第一个批次
  2415. if number_count > sum_in_count {
  2416. tx.Rollback()
  2417. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2418. return
  2419. }
  2420. }
  2421. }
  2422. }
  2423. }
  2424. }
  2425. }
  2426. }
  2427. }
  2428. }
  2429. }
  2430. }
  2431. }
  2432. }
  2433. }
  2434. //校验耗材库存
  2435. if goodOutConfig.IsOpen == 1 {
  2436. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2437. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2438. if len(prescriptions) > 0 {
  2439. for _, item := range prescriptions {
  2440. items := item.(map[string]interface{})
  2441. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2442. projects := items["project"].([]interface{})
  2443. if len(projects) > 0 {
  2444. for _, project := range projects {
  2445. var project_id int64
  2446. var project_type int64
  2447. var totals float64
  2448. var project_name string
  2449. var parsetotal int64
  2450. var id int64
  2451. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2452. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2453. }
  2454. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2455. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2456. }
  2457. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2458. total, _ := project.(map[string]interface{})["total"].(string)
  2459. totals, _ = strconv.ParseFloat(total, 64)
  2460. }
  2461. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2462. project_name = project.(map[string]interface{})["project_name"].(string)
  2463. }
  2464. if project_type == 3 {
  2465. //查找该耗材的出库记录
  2466. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2467. if len(goodWarehouseInfo) == 0 {
  2468. //查询耗材库存
  2469. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2470. var stock_count int64
  2471. for _, it := range list {
  2472. stock_count += it.StockCount
  2473. }
  2474. stock_counts := strconv.FormatInt(stock_count, 10)
  2475. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2476. if stock_total_count == 0 {
  2477. tx.Rollback()
  2478. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2479. return
  2480. }
  2481. if totals > stock_total_count {
  2482. tx.Rollback()
  2483. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2484. return
  2485. }
  2486. }
  2487. if len(goodWarehouseInfo) > 0 {
  2488. //查询该患者耗材的历史数据
  2489. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2490. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2491. //数量发生改变
  2492. if parsetotal != count {
  2493. //如果现在的数量大于历史数量,就要看库存是否足够
  2494. if parsetotal > count {
  2495. //查询耗材所有库存
  2496. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2497. var stock_count int64
  2498. for _, it := range list {
  2499. stock_count += it.StockCount
  2500. }
  2501. //库存不足
  2502. if stock_count == 0 {
  2503. tx.Rollback()
  2504. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2505. return
  2506. }
  2507. if (parsetotal - count) > stock_count {
  2508. tx.Rollback()
  2509. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2510. return
  2511. }
  2512. }
  2513. }
  2514. }
  2515. }
  2516. }
  2517. }
  2518. }
  2519. }
  2520. }
  2521. }
  2522. }
  2523. //不使用耗材保存处方出库
  2524. if goodOutConfig.IsOpen != 1 {
  2525. if stockConfig.IsOpen == 1 {
  2526. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2527. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2528. if len(prescriptions) > 0 {
  2529. for _, item := range prescriptions {
  2530. items := item.(map[string]interface{})
  2531. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2532. projects := items["project"].([]interface{})
  2533. if len(projects) > 0 {
  2534. for _, project := range projects {
  2535. var project_id int64
  2536. var project_type int64
  2537. var totals float64
  2538. var project_name string
  2539. var parsetotal int64
  2540. var id int64
  2541. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2542. id = int64(project.(map[string]interface{})["id"].(float64))
  2543. }
  2544. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2545. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2546. }
  2547. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2548. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2549. }
  2550. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2551. total, _ := project.(map[string]interface{})["total"].(string)
  2552. totals, _ = strconv.ParseFloat(total, 64)
  2553. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2554. }
  2555. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2556. project_name = project.(map[string]interface{})["project_name"].(string)
  2557. }
  2558. if project_type == 3 {
  2559. //查找该耗材的出库记录
  2560. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2561. //没有出库记录
  2562. if len(goodWarehouseInfo) == 0 {
  2563. //查询耗材库存
  2564. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2565. var stock_count int64
  2566. for _, it := range list {
  2567. stock_count += it.StockCount
  2568. }
  2569. stock_counts := strconv.FormatInt(stock_count, 10)
  2570. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2571. if stock_total_count == 0 {
  2572. tx.Rollback()
  2573. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2574. return
  2575. }
  2576. if totals > stock_total_count {
  2577. tx.Rollback()
  2578. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2579. return
  2580. }
  2581. //查找今日该患者已经出库的所有耗材
  2582. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2583. for _, item := range goodList {
  2584. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2585. var flush_count int64
  2586. for _, it := range goodListSix {
  2587. flush_count += it.StockCount
  2588. }
  2589. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2590. creater := adminInfo.AdminUser.Id
  2591. if errs != nil {
  2592. goodErrcode := models.XtGoodErrcode{
  2593. UserOrgId: item.OrgId,
  2594. Errcode: "手动出库更新剩余出库失败",
  2595. GoodId: item.GoodId,
  2596. Status: 1,
  2597. Ctime: time.Now().Unix(),
  2598. Mtime: 0,
  2599. Count: 0,
  2600. StockCount: 0,
  2601. Creater: creater,
  2602. BatchNumberId: 0,
  2603. WarehouseOutId: 0,
  2604. }
  2605. service.CreateGoodErrcode(goodErrcode)
  2606. }
  2607. }
  2608. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2609. }
  2610. //有出库记录
  2611. if len(goodWarehouseInfo) > 0 {
  2612. //查询该患者耗材的历史数据
  2613. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2614. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2615. //数量发生改变
  2616. if parsetotal != count {
  2617. //查找今日该患者已经出库的所有耗材
  2618. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2619. for _, item := range goodList {
  2620. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2621. var flush_count int64
  2622. for _, it := range goodListSix {
  2623. flush_count += it.StockCount
  2624. }
  2625. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2626. //减少出库数量
  2627. creater := adminInfo.AdminUser.Id
  2628. if errs != nil {
  2629. goodErrcode := models.XtGoodErrcode{
  2630. UserOrgId: item.OrgId,
  2631. Errcode: "手动出库更新剩余出库失败",
  2632. GoodId: item.GoodId,
  2633. Status: 1,
  2634. Ctime: time.Now().Unix(),
  2635. Mtime: 0,
  2636. Count: 0,
  2637. StockCount: 0,
  2638. Creater: creater,
  2639. BatchNumberId: 0,
  2640. WarehouseOutId: 0,
  2641. }
  2642. service.CreateGoodErrcode(goodErrcode)
  2643. }
  2644. //查询默认仓库
  2645. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2646. var total_count int64
  2647. for _, it := range stockList {
  2648. total_count += it.StockCount
  2649. }
  2650. //基础库插入数据
  2651. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2652. }
  2653. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2654. }
  2655. }
  2656. }
  2657. }
  2658. }
  2659. }
  2660. }
  2661. }
  2662. }
  2663. }
  2664. }
  2665. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2666. var hpInfo models.HisPrescriptionInfo
  2667. if info.ID == 0 {
  2668. var randNum int
  2669. randNum = rand.Intn(10000) + 1000
  2670. timestamp := time.Now().Unix()
  2671. tempTime := time.Unix(timestamp, 0)
  2672. timeFormat := tempTime.Format("20060102150405")
  2673. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2674. hpInfo = models.HisPrescriptionInfo{
  2675. HisPatientId: his_patient_id,
  2676. UserOrgId: adminInfo.CurrentOrgId,
  2677. RecordDate: theTime.Unix(),
  2678. PatientId: patient_id,
  2679. Status: 1,
  2680. Ctime: time.Now().Unix(),
  2681. Mtime: time.Now().Unix(),
  2682. Creator: adminInfo.AdminUser.Id,
  2683. Modifier: adminInfo.AdminUser.Id,
  2684. Diagnosis: diagnose,
  2685. SickHistory: sick_history,
  2686. Departments: department,
  2687. RegisterType: reg_type,
  2688. PrescriptionNumber: p_number,
  2689. PrescriptionStatus: 1,
  2690. Doctor: role.UserName,
  2691. DoctorId: doctor_id,
  2692. SickType: sick_type,
  2693. PType: p_type,
  2694. PatientDiagnosis: patient_diagnose,
  2695. }
  2696. service.SavePatientPrescriptionInfo(hpInfo)
  2697. //创建步骤表
  2698. finish := models.XtDialysisFinish{
  2699. IsFinish: 1,
  2700. UserOrgId: adminInfo.CurrentOrgId,
  2701. Status: 1,
  2702. Ctime: time.Now().Unix(),
  2703. Mtime: 0,
  2704. Module: 4,
  2705. RecordDate: theTime.Unix(),
  2706. Sourse: 1,
  2707. PatientId: patient_id,
  2708. }
  2709. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2710. if dialysisFinish.ID == 0 {
  2711. service.CreateDialysisFinish(finish)
  2712. }
  2713. redis := service.RedisClient()
  2714. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2715. redis.Set(key, "", time.Second)
  2716. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2717. redis.Set(keyOne, "", time.Second)
  2718. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2719. redis.Set(keySeven, "", time.Second)
  2720. defer redis.Close()
  2721. } else {
  2722. hpInfo = models.HisPrescriptionInfo{
  2723. ID: info.ID,
  2724. UserOrgId: adminInfo.CurrentOrgId,
  2725. RecordDate: info.RecordDate,
  2726. PatientId: info.PatientId,
  2727. Status: 1,
  2728. Ctime: info.Ctime,
  2729. Mtime: time.Now().Unix(),
  2730. Creator: info.Creator,
  2731. Modifier: adminInfo.AdminUser.Id,
  2732. Diagnosis: diagnose,
  2733. SickHistory: sick_history,
  2734. Departments: department,
  2735. RegisterType: reg_type,
  2736. PrescriptionNumber: info.PrescriptionNumber,
  2737. Doctor: role.UserName,
  2738. PrescriptionStatus: info.PrescriptionStatus,
  2739. DoctorId: doctor_id,
  2740. SickType: sick_type,
  2741. PType: info.PType,
  2742. HisPatientId: info.HisPatientId,
  2743. PatientDiagnosis: patient_diagnose,
  2744. }
  2745. service.SavePatientPrescriptionInfo(hpInfo)
  2746. //创建步骤表
  2747. finish := models.XtDialysisFinish{
  2748. IsFinish: 1,
  2749. UserOrgId: adminInfo.CurrentOrgId,
  2750. Status: 1,
  2751. Ctime: time.Now().Unix(),
  2752. Mtime: 0,
  2753. Module: 4,
  2754. RecordDate: info.RecordDate,
  2755. Sourse: 1,
  2756. PatientId: info.PatientId,
  2757. }
  2758. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2759. if dialysisFinish.ID == 0 {
  2760. service.CreateDialysisFinish(finish)
  2761. }
  2762. redis := service.RedisClient()
  2763. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2764. redis.Set(key, "", time.Second)
  2765. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2766. redis.Set(keyOne, "", time.Second)
  2767. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2768. redis.Set(keySeven, "", time.Second)
  2769. defer redis.Close()
  2770. }
  2771. //定义切片
  2772. var adviceList []models.HisDoctorAdviceInfo
  2773. var projectList []models.HisPrescriptionProject
  2774. if adminInfo.CurrentOrgId == 10489 || adminInfo.CurrentOrgId == 10510 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 10478 || adminInfo.CurrentOrgId == 10318 || adminInfo.CurrentOrgId == 10480 || adminInfo.CurrentOrgId == 10633 || adminInfo.CurrentOrgId == 10610 || adminInfo.CurrentOrgId == 10402 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10537 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10644 {
  2775. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2776. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2777. var tempPrescription *models.HisPrescription
  2778. if len(prescriptions) > 0 {
  2779. for _, item := range prescriptions {
  2780. // 开始外部循环的事务
  2781. tx := db.Begin()
  2782. // 在函数结束时处理事务回滚
  2783. defer func() {
  2784. if r := recover(); r != nil {
  2785. tx.Rollback()
  2786. }
  2787. }()
  2788. items := item.(map[string]interface{})
  2789. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2790. utils.ErrorLog("id")
  2791. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2792. return
  2793. }
  2794. id := int64(items["id"].(float64))
  2795. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2796. tempPrescription = &new_prescription
  2797. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2798. utils.ErrorLog("type")
  2799. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2800. return
  2801. }
  2802. types := int64(items["type"].(float64))
  2803. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2804. utils.ErrorLog("med_type")
  2805. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2806. return
  2807. }
  2808. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2809. if med_type == "0" {
  2810. med_type = "14"
  2811. }
  2812. //if order_status == 0 {
  2813. // order_status = 1
  2814. //}
  2815. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2816. utils.ErrorLog("pre_time")
  2817. }
  2818. preTime, _ := items["pre_time"].(string)
  2819. fmt.Println("preTime", preTime)
  2820. timeLayout := "2006-01-02"
  2821. loc, _ := time.LoadLocation("Local")
  2822. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2823. result := strings.Split(preTime, " ")
  2824. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  2825. if err != nil {
  2826. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2827. return
  2828. }
  2829. pTime := theTime2.Unix()
  2830. ctime := time.Now().Unix()
  2831. if tempPrescription.ID == 0 {
  2832. prescription := &models.HisPrescription{
  2833. ID: 0,
  2834. PatientId: patient_id,
  2835. UserOrgId: adminInfo.CurrentOrgId,
  2836. RecordDate: recordDateTime,
  2837. Ctime: ctime,
  2838. Mtime: ctime,
  2839. Type: types,
  2840. Modifier: adminInfo.AdminUser.Id,
  2841. Creator: adminInfo.AdminUser.Id,
  2842. Status: 1,
  2843. Doctor: role.UserName,
  2844. HisPatientId: his_patient_id,
  2845. OrderStatus: 1,
  2846. BatchNumber: "",
  2847. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2848. PreTime: pTime,
  2849. PType: p_type,
  2850. MedType: med_type,
  2851. }
  2852. tempPrescription = prescription
  2853. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2854. redis := service.RedisClient()
  2855. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2856. redis.Set(key, "", time.Second)
  2857. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2858. redis.Set(keyOne, "", time.Second)
  2859. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2860. redis.Set(keySeven, "", time.Second)
  2861. defer redis.Close()
  2862. } else {
  2863. tempPrescription.ID = id
  2864. tempPrescription.Type = types
  2865. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2866. tempPrescription.Mtime = time.Now().Unix()
  2867. tempPrescription.Doctor = role.UserName
  2868. //tempPrescription.OrderStatus = order_status
  2869. tempPrescription.PreTime = pTime
  2870. tempPrescription.MedType = med_type
  2871. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2872. redis := service.RedisClient()
  2873. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2874. redis.Set(key, "", time.Second)
  2875. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2876. redis.Set(keyOne, "", time.Second)
  2877. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2878. redis.Set(keySeven, "", time.Second)
  2879. defer redis.Close()
  2880. }
  2881. //service.SaveHisPrescription(prescription)
  2882. //更改患者挂号状态
  2883. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2884. fmt.Println("更改失败", err2)
  2885. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2886. advices := items["advices"].([]interface{})
  2887. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2888. groupNo := int64(0)
  2889. if len(advices) > 0 {
  2890. for _, advice := range advices {
  2891. tx := db.Begin()
  2892. // 在函数结束时处理事务回滚
  2893. defer func() {
  2894. if r := recover(); r != nil {
  2895. tx.Rollback()
  2896. }
  2897. }()
  2898. var s models.HisDoctorAdviceInfo
  2899. s.PrescriptionId = tempPrescription.ID
  2900. s.AdviceType = 2
  2901. s.AdviceDoctor = doctor_id
  2902. s.StopState = 2
  2903. s.ExecutionState = 2
  2904. s.AdviceDate = theTime3.Unix()
  2905. s.Status = 1
  2906. s.UserOrgId = adminInfo.CurrentOrgId
  2907. s.RecordDate = theTime3.Unix()
  2908. s.StartTime = tempPrescription.PreTime
  2909. s.Groupno = groupNo
  2910. s.PatientId = patient_id
  2911. s.HisPatientId = his_patient_id
  2912. s.StartTime = pTime
  2913. s.IsSettle = 2
  2914. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2915. if errcode > 0 {
  2916. c.ServeFailJSONWithSGJErrorCode(errcode)
  2917. return
  2918. }
  2919. s.StartTime = pTime
  2920. var total_count int64 //处方总库存
  2921. //查询改药品信息
  2922. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2923. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2924. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2925. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2926. total_count += prescribingNumberSeven * medical.MinNumber
  2927. }
  2928. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2929. total_count += prescribingNumberSeven
  2930. }
  2931. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2932. total_count += prescribingNumberSeven
  2933. }
  2934. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2935. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2936. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2937. if s.Price != lastWarehouse.RetailPrice {
  2938. s.Price = lastWarehouse.RetailPrice
  2939. }
  2940. if s.Price == 0 {
  2941. if lastWarehouse.ID == 0 {
  2942. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  2943. s.Price = lastWarehouseTwo.RetailPrice
  2944. }
  2945. }
  2946. }
  2947. //查询保存处方出库开关是否打开
  2948. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2949. if s.PatientId != 30038 {
  2950. if drugOutConfig.IsOpen == 1 {
  2951. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  2952. // 查询该药品最后一次出库记录
  2953. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  2954. var is_user_total int64
  2955. var no_user_total int64
  2956. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2957. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2958. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2959. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  2960. }
  2961. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2962. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2963. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2964. no_user_total += prescribingNumberSevenTy
  2965. }
  2966. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2967. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2968. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2969. no_user_total += prescribingNumberSevenTy
  2970. }
  2971. if len(druginfo) > 0 {
  2972. for _, it := range druginfo {
  2973. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2974. it.Count = it.Count * drug.MinNumber
  2975. is_user_total += it.Count
  2976. }
  2977. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2978. is_user_total += it.Count
  2979. }
  2980. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2981. is_user_total += it.Count
  2982. }
  2983. }
  2984. }
  2985. //fmt.Println("药品名称----------------------", drug.DrugName)
  2986. //fmt.Println("药品名称----------------------", drug.IsUse)
  2987. //fmt.Println("is_user_total-------------------------", is_user_total)
  2988. //fmt.Println("no_user_total-------------------------", no_user_total)
  2989. if is_user_total != no_user_total {
  2990. //出库
  2991. if drug.IsUse == 2 {
  2992. creater := adminInfo.AdminUser.Id
  2993. newadviceInfo := &models.HisDoctorAdviceInfo{
  2994. ID: s.ID,
  2995. UserOrgId: s.UserOrgId,
  2996. PatientId: s.PatientId,
  2997. HisPatientId: s.HisPatientId,
  2998. AdviceType: s.AdviceType,
  2999. AdviceDate: s.AdviceDate,
  3000. StartTime: s.StartTime,
  3001. AdviceName: s.AdviceName,
  3002. AdviceDesc: s.AdviceDesc,
  3003. ReminderDate: s.ReminderDate,
  3004. SingleDose: s.SingleDose,
  3005. SingleDoseUnit: s.SingleDoseUnit,
  3006. PrescribingNumber: s.PrescribingNumber,
  3007. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3008. DeliveryWay: s.DeliveryWay,
  3009. ExecutionFrequency: s.ExecutionFrequency,
  3010. AdviceDoctor: s.AdviceDoctor,
  3011. Status: s.Status,
  3012. CreatedTime: s.CreatedTime,
  3013. UpdatedTime: s.UpdatedTime,
  3014. AdviceAffirm: s.AdviceAffirm,
  3015. Remark: s.Remark,
  3016. StopTime: s.StopTime,
  3017. StopReason: s.StopReason,
  3018. StopDoctor: s.StopDoctor,
  3019. StopState: s.StopState,
  3020. ParentId: s.ParentId,
  3021. ExecutionTime: s.ExecutionTime,
  3022. ExecutionStaff: s.ExecutionStaff,
  3023. ExecutionState: s.ExecutionState,
  3024. Checker: s.Checker,
  3025. RecordDate: s.RecordDate,
  3026. DialysisOrderId: s.DialysisOrderId,
  3027. CheckTime: s.CheckTime,
  3028. CheckState: s.CheckState,
  3029. DrugSpec: s.DrugSpec,
  3030. DrugSpecUnit: s.DrugSpecUnit,
  3031. Groupno: s.Groupno,
  3032. RemindType: s.RemindType,
  3033. FrequencyType: s.FrequencyType,
  3034. DayCount: s.DayCount,
  3035. WeekDay: s.WeekDay,
  3036. TemplateId: s.TemplateId,
  3037. Modifier: s.Modifier,
  3038. DrugId: s.DrugId,
  3039. Price: s.Price,
  3040. PrescriptionId: s.PrescriptionId,
  3041. MedListCodg: s.MedListCodg,
  3042. FeedetlSn: s.FeedetlSn,
  3043. Day: s.DayCount,
  3044. ChildDoctorAdvice: nil,
  3045. Drug: models.Drug{},
  3046. Diagnosis: s.Diagnosis,
  3047. Way: s.Way,
  3048. HospApprFlag: s.HospApprFlag,
  3049. LmtUsedFlag: s.LmtUsedFlag,
  3050. HisOrderInfo: models.HisOrderInfo{},
  3051. IsMedicine: s.IsMedicine,
  3052. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3053. Child: nil,
  3054. IsSettle: s.IsSettle,
  3055. IsMobile: s.IsMobile,
  3056. IsSelfDrug: s.IsSelfDrug,
  3057. DrugWayCount: s.DrugWayCount,
  3058. }
  3059. var history_count int64
  3060. var local_count int64
  3061. //查找已经开过的医嘱信息
  3062. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3063. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3064. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3065. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3066. local_count += prescribingNumberSevenTy * drug.MinNumber
  3067. }
  3068. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3069. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3070. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3071. local_count += prescribingNumberSevenTy
  3072. }
  3073. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3074. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3075. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3076. local_count += prescribingNumberSevenTy
  3077. }
  3078. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3079. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3080. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3081. history_count += prescribingNumberSevenTy * drug.MinNumber
  3082. }
  3083. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3084. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3085. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3086. history_count += prescribingNumberSevenTy
  3087. }
  3088. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3089. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3090. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3091. history_count += prescribingNumberSevenTy
  3092. }
  3093. //如果当前出库数量大于历史出库数量则需要出库
  3094. if local_count > history_count {
  3095. //按最小单位出库
  3096. var cha_count = local_count - history_count
  3097. newadviceInfo.PrescribingNumber = float64(cha_count)
  3098. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3099. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3100. }
  3101. //如果当前出库数量小于历史出库数量则需要退库
  3102. if local_count < history_count {
  3103. var cha_count = history_count - local_count
  3104. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3105. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3106. }
  3107. if local_count == history_count {
  3108. if is_user_total == 0 {
  3109. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3110. }
  3111. }
  3112. }
  3113. //更新字典里面的库存
  3114. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3115. var sum_count int64
  3116. for _, its := range stockInfo {
  3117. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3118. if its.MaxUnit == baseDrug.MaxUnit {
  3119. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3120. }
  3121. sum_count += its.StockMaxNumber + its.StockMinNumber
  3122. }
  3123. //更新基础库存
  3124. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3125. //剩余库存
  3126. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3127. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3128. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3129. //创建医嘱
  3130. service.CreateHisDoctorAdviceOne(&s, tx)
  3131. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3132. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3133. if len(outInfoTwo) > 0 {
  3134. for _, item := range outInfoTwo {
  3135. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3136. }
  3137. }
  3138. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3139. if len(drugAutoDetail) > 0 {
  3140. for _, item := range drugAutoDetail {
  3141. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3142. }
  3143. }
  3144. }
  3145. }
  3146. }
  3147. //记录日志
  3148. byterequest, _ := json.Marshal(s)
  3149. adviceLog := models.XtDoctorAdviceLog{
  3150. UserOrgId: s.UserOrgId,
  3151. PatientId: s.PatientId,
  3152. AdminUserId: adminInfo.AdminUser.Id,
  3153. Module: 1,
  3154. ErrLog: string(byterequest),
  3155. Status: 1,
  3156. Ctime: time.Now().Unix(),
  3157. Mtime: 0,
  3158. Source: "电脑端新建his医嘱",
  3159. RecordDate: s.AdviceDate,
  3160. }
  3161. service.CreateDoctorAdviceLog(adviceLog)
  3162. //存储切片中
  3163. adviceList = append(adviceList, s)
  3164. redis := service.RedisClient()
  3165. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3166. redis.Set(key, "", time.Second)
  3167. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3168. redis.Set(keyOne, "", time.Second)
  3169. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3170. redis.Set(keySeven, "", time.Second)
  3171. var randNum int
  3172. randNum = rand.Intn(10000) + 1000
  3173. timestamp := time.Now().Unix()
  3174. tempTime := time.Unix(timestamp, 0)
  3175. timeFormat := tempTime.Format("20060102150405")
  3176. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3177. if s.UserOrgId != 10206 {
  3178. if s.ID == 0 {
  3179. //查询改药品是否已经停用
  3180. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3181. if base.ID > 0 {
  3182. tx.Rollback()
  3183. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3184. return
  3185. }
  3186. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3187. if drugMedical.SumCount == 0 {
  3188. tx.Rollback()
  3189. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3190. return
  3191. }
  3192. }
  3193. }
  3194. //赤峰
  3195. if adminInfo.CurrentOrgId == 10265 {
  3196. drug, _ := service.FindNewBaseDrugLibRecord(adminInfo.CurrentOrgId, s.DrugId, tx)
  3197. info, _ := service.FindNewLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut, tx)
  3198. if info.RetailPrice > 0 {
  3199. if s.DeliveryWay == "口服" {
  3200. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3201. s.Price = drug.RetailPrice
  3202. }
  3203. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3204. s.Price = info.RetailPrice
  3205. }
  3206. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3207. s.Price = info.RetailPrice
  3208. }
  3209. }
  3210. }
  3211. }
  3212. service.CreateHisDoctorAdviceOne(&s, tx)
  3213. tx.Commit()
  3214. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3215. redis.Set(keySix, "", time.Second)
  3216. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3217. redis.Set(keyFive, "", time.Second)
  3218. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3219. redis.Set(keyEight, "", time.Second)
  3220. defer redis.Close()
  3221. }
  3222. }
  3223. }
  3224. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3225. projects := items["project"].([]interface{})
  3226. if len(projects) > 0 {
  3227. for _, project := range projects {
  3228. tx := db.Begin()
  3229. // 在函数结束时处理事务回滚
  3230. defer func() {
  3231. if r := recover(); r != nil {
  3232. tx.Rollback()
  3233. }
  3234. }()
  3235. var p models.HisPrescriptionProject
  3236. p.PrescriptionId = tempPrescription.ID
  3237. p.PatientId = patient_id
  3238. p.RecordDate = theTime3.Unix()
  3239. p.Doctor = doctor_id
  3240. p.UserOrgId = adminInfo.CurrentOrgId
  3241. p.HisPatientId = his_patient_id
  3242. p.Status = 1
  3243. p.StartTime = pTime
  3244. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3245. if errcode > 0 {
  3246. c.ServeFailJSONWithSGJErrorCode(errcode)
  3247. return
  3248. }
  3249. if p.ID == 0 {
  3250. p.IsOut = 2
  3251. }
  3252. if p.ID > 0 {
  3253. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3254. p.IsOut = projectDetail.IsOut
  3255. }
  3256. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 {
  3257. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3258. if p.Type == 3 {
  3259. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3260. if p.Price != lastWarehouse.PackingPrice {
  3261. p.Price = lastWarehouse.PackingPrice
  3262. }
  3263. if p.Price == 0 {
  3264. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3265. p.Price = lastWarehouseTwo.PackingPrice
  3266. }
  3267. if p.Unit == "" {
  3268. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3269. p.Unit = goodInfoOne.PackingUnit
  3270. }
  3271. }
  3272. }
  3273. if adminInfo.CurrentOrgId != 10206 {
  3274. if p.Type == 3 {
  3275. if p.ID == 0 {
  3276. //查询该耗材是否停用
  3277. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3278. //表示该耗材已经停用,不能保存
  3279. if goodInfoSeven.ID == 0 {
  3280. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3281. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3282. return
  3283. }
  3284. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3285. if goodInfoOne.SumCount == 0 {
  3286. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3287. return
  3288. }
  3289. }
  3290. }
  3291. }
  3292. //查询保存耗材出库开关是否打开
  3293. if p.PatientId != 30038 {
  3294. if goodOutConfig.IsOpen == 1 {
  3295. //耗材出库
  3296. if p.Type == 3 {
  3297. //对比当前数据和历史出库数据
  3298. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3299. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3300. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3301. //如果当前处方数量大于历史数据,则需要出库
  3302. if nowCount > historyCount {
  3303. var cha_count int64
  3304. cha_count = nowCount - historyCount
  3305. timeStr := time.Now().Format("2006-01-02")
  3306. timeArr := strings.Split(timeStr, "-")
  3307. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3308. total = total + 1
  3309. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3310. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3311. number = number + total
  3312. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3313. operation_time := time.Now().Unix()
  3314. creater := c.GetAdminUserInfo().AdminUser.Id
  3315. recordDateStr := time.Now().Format("2006-01-02")
  3316. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3317. nowtime := recordDate.Unix()
  3318. warehouseOut := models.WarehouseOut{
  3319. WarehouseOutOrderNumber: warehousing_out_order,
  3320. OperationTime: operation_time,
  3321. OrgId: adminInfo.CurrentOrgId,
  3322. Creater: creater,
  3323. Ctime: time.Now().Unix(),
  3324. Status: 1,
  3325. WarehouseOutTime: nowtime,
  3326. Type: 1,
  3327. StorehouseId: storeConfig.StorehouseOutInfo,
  3328. IsCheck: 1,
  3329. IsSys: 1,
  3330. }
  3331. //查询是否生成出库单
  3332. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3333. if out.ID == 0 {
  3334. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3335. }
  3336. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3337. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3338. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3339. dialyPrepareOne := models.DialysisBeforePrepare{
  3340. GoodTypeId: goodObj.GoodTypeId,
  3341. GoodId: p.ProjectId,
  3342. PatientId: p.PatientId,
  3343. RecordDate: p.RecordDate,
  3344. UserOrgId: adminInfo.CurrentOrgId,
  3345. Count: cha_count,
  3346. Ctime: time.Now().Unix(),
  3347. Creater: creater,
  3348. Status: 1,
  3349. StorehouseId: houseConfig.StorehouseOutInfo,
  3350. ProjectId: p.ID,
  3351. }
  3352. //出库
  3353. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3354. }
  3355. //如果当前处方数量小于历史数据,怎需要退库
  3356. if nowCount < historyCount {
  3357. var cha_count int64
  3358. cha_count = historyCount - nowCount
  3359. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3360. creater := c.GetAdminUserInfo().AdminUser.Id
  3361. newPrescriptionProject := &models.HisPrescriptionProject{
  3362. ID: p.ID,
  3363. ProjectId: p.ProjectId,
  3364. Price: p.Price,
  3365. UserOrgId: p.UserOrgId,
  3366. Status: 1,
  3367. Ctime: time.Now().Unix(),
  3368. Mtime: time.Now().Unix(),
  3369. PatientId: p.PatientId,
  3370. HisPatientId: p.HisPatientId,
  3371. RecordDate: p.RecordDate,
  3372. PrescriptionId: p.PrescriptionId,
  3373. Count: p.Count,
  3374. FeedetlSn: p.FeedetlSn,
  3375. MedListCodg: p.MedListCodg,
  3376. SingleDose: p.SingleDose,
  3377. DeliveryWay: p.DeliveryWay,
  3378. ExecutionFrequency: p.ExecutionFrequency,
  3379. Day: p.Day,
  3380. HisProject: models.HisProject{},
  3381. GoodInfo: models.GoodInfo{},
  3382. Remark: p.Remark,
  3383. Unit: p.Unit,
  3384. Type: p.Type,
  3385. Doctor: p.Doctor,
  3386. ExecutionTime: p.ExecutionTime,
  3387. ExecutionStaff: p.ExecutionStaff,
  3388. ExecutionState: p.ExecutionState,
  3389. CheckTime: p.CheckTime,
  3390. CheckState: p.CheckState,
  3391. Checker: p.Checker,
  3392. StartTime: p.StartTime,
  3393. TeamId: p.TeamId,
  3394. XtHisProjectTeam: models.XtHisProjectTeam{},
  3395. FrequencyType: p.FrequencyType,
  3396. DayCount: p.DayCount,
  3397. WeekDay: p.WeekDay,
  3398. IsCheckTeam: p.IsCheckTeam,
  3399. HisOrderInfo: models.HisOrderInfo{},
  3400. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3401. IsOut: p.IsOut,
  3402. YbSyncStatus: p.YbSyncStatus,
  3403. }
  3404. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3405. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3406. }
  3407. if nowCount == historyCount {
  3408. if historyCount == 0 {
  3409. recordDateStr := time.Now().Format("2006-01-02")
  3410. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3411. nowtime := recordDate.Unix()
  3412. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3413. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3414. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3415. creater := c.GetAdminUserInfo().AdminUser.Id
  3416. dialyPrepareOne := models.DialysisBeforePrepare{
  3417. GoodTypeId: goodObj.GoodTypeId,
  3418. GoodId: p.ProjectId,
  3419. PatientId: p.PatientId,
  3420. RecordDate: p.RecordDate,
  3421. UserOrgId: adminInfo.CurrentOrgId,
  3422. Count: nowCount,
  3423. Ctime: time.Now().Unix(),
  3424. Creater: creater,
  3425. Status: 1,
  3426. StorehouseId: houseConfig.StorehouseOutInfo,
  3427. ProjectId: p.ID,
  3428. }
  3429. //出库
  3430. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3431. }
  3432. }
  3433. //lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3434. ////查询历史出库数据
  3435. //flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3436. //
  3437. //var out_count_five int64
  3438. //for _, item := range flowGood {
  3439. // out_count_five += item.Count
  3440. //}
  3441. //parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3442. //
  3443. ////如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3444. //if out_count_five != parseIntCount {
  3445. // //查询耗材最后一次出库记录
  3446. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3447. // //查询默认出库仓库库存
  3448. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3449. // if len(wareOut) > 0 {
  3450. //
  3451. // for _, it := range wareOut {
  3452. // //回退库存
  3453. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3454. //
  3455. // //删除出库记录
  3456. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3457. //
  3458. // }
  3459. // }
  3460. //
  3461. // timeStr := time.Now().Format("2006-01-02")
  3462. // timeArr := strings.Split(timeStr, "-")
  3463. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3464. //
  3465. // total = total + 1
  3466. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3467. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3468. // number = number + total
  3469. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3470. //
  3471. // operation_time := time.Now().Unix()
  3472. // creater := c.GetAdminUserInfo().AdminUser.Id
  3473. //
  3474. // recordDateStr := time.Now().Format("2006-01-02")
  3475. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3476. // nowtime := recordDate.Unix()
  3477. // warehouseOut := models.WarehouseOut{
  3478. // WarehouseOutOrderNumber: warehousing_out_order,
  3479. // OperationTime: operation_time,
  3480. // OrgId: adminInfo.CurrentOrgId,
  3481. // Creater: creater,
  3482. // Ctime: time.Now().Unix(),
  3483. // Status: 1,
  3484. // WarehouseOutTime: nowtime,
  3485. // Type: 1,
  3486. // StorehouseId: storeConfig.StorehouseOutInfo,
  3487. // IsCheck: 1,
  3488. // IsSys: 1,
  3489. // }
  3490. // //查询是否生成出库单
  3491. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3492. // if out.ID == 0 {
  3493. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3494. // }
  3495. //
  3496. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3497. //
  3498. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3499. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3500. //
  3501. // dialyPrepareOne := models.DialysisBeforePrepare{
  3502. // GoodTypeId: goodObj.GoodTypeId,
  3503. // GoodId: p.ProjectId,
  3504. // PatientId: p.PatientId,
  3505. // RecordDate: p.RecordDate,
  3506. // UserOrgId: adminInfo.CurrentOrgId,
  3507. // Count: parseIntCount,
  3508. // Ctime: time.Now().Unix(),
  3509. // Creater: creater,
  3510. // Status: 1,
  3511. // StorehouseId: houseConfig.StorehouseOutInfo,
  3512. // ProjectId: lastHisProject.ID,
  3513. // }
  3514. // //判断是否是零用耗材(非零用)
  3515. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3516. //
  3517. // //查询历史出库数据
  3518. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3519. // var out_count int64
  3520. // for _, item := range flowGood {
  3521. // out_count += item.Count
  3522. // }
  3523. // //如果历史数和当前数据不想等才进行退库出库
  3524. // if out_count != parseIntCount {
  3525. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3526. //
  3527. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3528. // detail := models.AutomaticReduceDetail{
  3529. // WarehouseOutId: 0,
  3530. // WarehouseOutOrderNumber: "",
  3531. // PatientId: p.PatientId,
  3532. // Ctime: time.Now().Unix(),
  3533. // Mtime: 0,
  3534. // Status: 1,
  3535. // RecordTime: p.RecordDate,
  3536. // OrgId: p.UserOrgId,
  3537. // GoodId: p.ProjectId,
  3538. // GoodTypeId: 0,
  3539. // Count: parseIntCount,
  3540. // Type: 0,
  3541. // ProjectId: lastHisProject.ID,
  3542. // StorehouseId: 0,
  3543. // }
  3544. //
  3545. // service.CreateNewAutoDetail(detail, tx)
  3546. //
  3547. // //查询剩余库存
  3548. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3549. // var sum_count int64
  3550. // for _, item := range goodList {
  3551. // sum_count += item.StockCount
  3552. // }
  3553. //
  3554. // //更新剩余库存
  3555. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3556. //
  3557. // //耗材
  3558. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3559. //
  3560. // }
  3561. // //判断是否是零用耗材(零用但是是出库耗材)
  3562. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3563. //
  3564. // //查询历史出库数据
  3565. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3566. // var out_count int64
  3567. // for _, item := range flowGood {
  3568. // out_count += item.Count
  3569. // }
  3570. // //如果历史数和当前数据不想等才进行退库出库
  3571. // if out_count != parseIntCount {
  3572. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3573. //
  3574. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3575. // detail := models.AutomaticReduceDetail{
  3576. // WarehouseOutId: 0,
  3577. // WarehouseOutOrderNumber: "",
  3578. // PatientId: p.PatientId,
  3579. // Ctime: time.Now().Unix(),
  3580. // Mtime: 0,
  3581. // Status: 1,
  3582. // RecordTime: p.RecordDate,
  3583. // OrgId: p.UserOrgId,
  3584. // GoodId: p.ProjectId,
  3585. // GoodTypeId: 0,
  3586. // Count: parseIntCount,
  3587. // Type: 0,
  3588. // ProjectId: p.ID,
  3589. // StorehouseId: 0,
  3590. // }
  3591. //
  3592. // service.CreateNewAutoDetail(detail, tx)
  3593. //
  3594. // //查询剩余库存
  3595. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3596. // var sum_count int64
  3597. // for _, item := range goodList {
  3598. // sum_count += item.StockCount
  3599. // }
  3600. //
  3601. // //更新剩余库存
  3602. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3603. //
  3604. // //耗材
  3605. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3606. // }
  3607. //
  3608. // }
  3609. //
  3610. // }
  3611. //
  3612. //}
  3613. //记录日志
  3614. byterequest, _ := json.Marshal(p)
  3615. adviceLog := models.XtDoctorAdviceLog{
  3616. UserOrgId: p.UserOrgId,
  3617. PatientId: p.PatientId,
  3618. AdminUserId: adminInfo.AdminUser.Id,
  3619. Module: 1,
  3620. ErrLog: string(byterequest),
  3621. Status: 1,
  3622. Ctime: time.Now().Unix(),
  3623. Mtime: 0,
  3624. Source: "电脑端新建his项目",
  3625. RecordDate: p.RecordDate,
  3626. }
  3627. service.CreateDoctorAdviceLog(adviceLog)
  3628. projectList = append(projectList, p)
  3629. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3630. //新增或者编辑项目,修改对应的标签数据
  3631. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3632. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3633. var label models.HisLabelPrintInfo
  3634. project, _ := service.GetProjectDetail(p.ProjectId)
  3635. if project.CostClassify == 3 { //类别为检验检查
  3636. if p.TeamId > 0 { //检验检查组套
  3637. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3638. if tempLabel.ID == 0 {
  3639. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3640. label.Number = tempPrescription.PrescriptionNumber
  3641. label.ProjectId = project.ID
  3642. label.Status = 1
  3643. label.IsPrint = 2
  3644. label.DoctorId = info.DoctorId
  3645. label.UserOrgId = p.UserOrgId
  3646. label.PatientId = patient_id
  3647. label.RecordDate = recordDateTime
  3648. label.Ctime = time.Now().Unix()
  3649. label.Mtime = time.Now().Unix()
  3650. label.ItemId = p.TeamId
  3651. label.FeedetlSn = p.FeedetlSn
  3652. label.PProjectId = p.ID
  3653. label.ProjectName = team.ProjectTeam
  3654. label.PatientName = patient.Name
  3655. service.CreateNewHisLabelRecord(&label, tx)
  3656. }
  3657. } else { //单条检验检查项目
  3658. label.Number = tempPrescription.PrescriptionNumber
  3659. label.ProjectId = project.ID
  3660. label.Status = 1
  3661. label.DoctorId = info.DoctorId
  3662. label.UserOrgId = p.UserOrgId
  3663. label.PatientId = patient_id
  3664. label.RecordDate = recordDateTime
  3665. label.IsPrint = 2
  3666. label.Ctime = time.Now().Unix()
  3667. label.Mtime = time.Now().Unix()
  3668. label.FeedetlSn = p.FeedetlSn
  3669. label.PProjectId = p.ID
  3670. label.ItemId = p.TeamId
  3671. label.ProjectName = project.ProjectName
  3672. label.PatientName = patient.Name
  3673. service.CreateNewHisLabelRecord(&label, tx)
  3674. }
  3675. }
  3676. }
  3677. }
  3678. }
  3679. }
  3680. }
  3681. service.CreateNewHisProjectTwo(&p, tx)
  3682. var randNum int
  3683. randNum = rand.Intn(10000) + 1000
  3684. timestamp := time.Now().Unix()
  3685. tempTime := time.Unix(timestamp, 0)
  3686. timeFormat := tempTime.Format("20060102150405")
  3687. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3688. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  3689. if goodBase.ID > 0 {
  3690. tx.Rollback()
  3691. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  3692. return
  3693. }
  3694. service.CreateNewHisProjectTwo(&p, tx)
  3695. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3696. //查询剩余库存
  3697. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3698. var sum_count int64
  3699. for _, item := range goodList {
  3700. sum_count += item.StockCount
  3701. }
  3702. //更新剩余库存
  3703. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3704. //耗材
  3705. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3706. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3707. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3708. if len(outInfoTwo) > 0 {
  3709. for _, item := range outInfoTwo {
  3710. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3711. }
  3712. }
  3713. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3714. if len(drugAutoDetail) > 0 {
  3715. for _, item := range drugAutoDetail {
  3716. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  3717. }
  3718. }
  3719. tx.Commit()
  3720. }
  3721. }
  3722. }
  3723. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3724. // addition := items["addition"].([]interface{})
  3725. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3726. // ctime := time.Now().Unix()
  3727. // mtime := ctime
  3728. // if len(addition) > 0 {
  3729. // for _, item := range addition {
  3730. // var s models.HisAdditionalCharge
  3731. // s.PrescriptionId = tempPrescription.ID
  3732. // s.Status = 1
  3733. // s.UserOrgId = adminInfo.CurrentOrgId
  3734. // s.RecordDate = recordDateTime
  3735. // s.CreatedTime = ctime
  3736. // s.UpdatedTime = mtime
  3737. // s.PatientId = patient_id
  3738. // s.HisPatientId = his_patient_id
  3739. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3740. // if errcode > 0 {
  3741. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3742. // return
  3743. // }
  3744. // service.CreateAdditionalCharge(&s)
  3745. // var randNum int
  3746. // randNum = rand.Intn(10000) + 1000
  3747. // timestamp := time.Now().Unix()
  3748. // tempTime := time.Unix(timestamp, 0)
  3749. // timeFormat := tempTime.Format("20060102150405")
  3750. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3751. // service.CreateAdditionalCharge(&s)
  3752. //
  3753. // }
  3754. // }
  3755. //}
  3756. }
  3757. }
  3758. }
  3759. tx.Commit()
  3760. if err == nil {
  3761. c.ServeSuccessJSON(map[string]interface{}{
  3762. "msg": "保存成功",
  3763. })
  3764. return
  3765. } else {
  3766. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3767. return
  3768. }
  3769. } else {
  3770. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3771. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3772. var tempPrescription *models.HisPrescription
  3773. if len(prescriptions) > 0 {
  3774. for _, item := range prescriptions {
  3775. items := item.(map[string]interface{})
  3776. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3777. utils.ErrorLog("id")
  3778. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3779. return
  3780. }
  3781. id := int64(items["id"].(float64))
  3782. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3783. tempPrescription = &new_prescription
  3784. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3785. utils.ErrorLog("type")
  3786. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3787. return
  3788. }
  3789. types := int64(items["type"].(float64))
  3790. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3791. utils.ErrorLog("med_type")
  3792. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3793. return
  3794. }
  3795. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3796. if med_type == "0" {
  3797. med_type = "14"
  3798. }
  3799. //if order_status == 0 {
  3800. // order_status = 1
  3801. //}
  3802. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3803. utils.ErrorLog("pre_time")
  3804. }
  3805. preTime, _ := items["pre_time"].(string)
  3806. timeLayout := "2006-01-02"
  3807. loc, _ := time.LoadLocation("Local")
  3808. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3809. result := strings.Split(preTime, " ")
  3810. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  3811. if err != nil {
  3812. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3813. return
  3814. }
  3815. pTime := theTime2.Unix()
  3816. ctime := time.Now().Unix()
  3817. if tempPrescription.ID == 0 {
  3818. prescription := &models.HisPrescription{
  3819. ID: 0,
  3820. PatientId: patient_id,
  3821. UserOrgId: adminInfo.CurrentOrgId,
  3822. RecordDate: recordDateTime,
  3823. Ctime: ctime,
  3824. Mtime: ctime,
  3825. Type: types,
  3826. Modifier: adminInfo.AdminUser.Id,
  3827. Creator: adminInfo.AdminUser.Id,
  3828. Status: 1,
  3829. Doctor: role.UserName,
  3830. HisPatientId: his_patient_id,
  3831. OrderStatus: 1,
  3832. BatchNumber: "",
  3833. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3834. PreTime: pTime,
  3835. PType: p_type,
  3836. MedType: med_type,
  3837. }
  3838. tempPrescription = prescription
  3839. service.SaveHisPrescription(tempPrescription)
  3840. redis := service.RedisClient()
  3841. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3842. redis.Set(key, "", time.Second)
  3843. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3844. redis.Set(keyOne, "", time.Second)
  3845. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3846. redis.Set(keySeven, "", time.Second)
  3847. defer redis.Close()
  3848. } else {
  3849. tempPrescription.ID = id
  3850. tempPrescription.Type = types
  3851. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3852. tempPrescription.Mtime = time.Now().Unix()
  3853. tempPrescription.Doctor = role.UserName
  3854. //tempPrescription.OrderStatus = order_status
  3855. tempPrescription.PreTime = pTime
  3856. tempPrescription.MedType = med_type
  3857. service.SaveHisPrescription(tempPrescription)
  3858. redis := service.RedisClient()
  3859. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3860. redis.Set(key, "", time.Second)
  3861. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3862. redis.Set(keyOne, "", time.Second)
  3863. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3864. redis.Set(keySeven, "", time.Second)
  3865. defer redis.Close()
  3866. }
  3867. //service.SaveHisPrescription(prescription)
  3868. //更改患者挂号状态
  3869. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3870. fmt.Println("更改失败", err2)
  3871. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3872. advices := items["advices"].([]interface{})
  3873. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3874. groupNo := int64(0)
  3875. if len(advices) > 0 {
  3876. for _, advice := range advices {
  3877. var s models.HisDoctorAdviceInfo
  3878. s.PrescriptionId = tempPrescription.ID
  3879. s.AdviceType = 2
  3880. s.AdviceDoctor = doctor_id
  3881. s.StopState = 2
  3882. s.ExecutionState = 2
  3883. s.AdviceDate = theTime3.Unix()
  3884. s.Status = 1
  3885. s.UserOrgId = adminInfo.CurrentOrgId
  3886. s.RecordDate = theTime3.Unix()
  3887. s.StartTime = tempPrescription.PreTime
  3888. s.Groupno = groupNo
  3889. s.PatientId = patient_id
  3890. s.HisPatientId = his_patient_id
  3891. s.StartTime = pTime
  3892. s.IsSettle = 2
  3893. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3894. if errcode > 0 {
  3895. c.ServeFailJSONWithSGJErrorCode(errcode)
  3896. return
  3897. }
  3898. s.StartTime = pTime
  3899. var total_count int64 //处方总库存
  3900. //查询改药品信息
  3901. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3902. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3903. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3904. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3905. total_count += prescribingNumberSeven * medical.MinNumber
  3906. }
  3907. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3908. total_count += prescribingNumberSeven
  3909. }
  3910. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3911. total_count += prescribingNumberSeven
  3912. }
  3913. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3914. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3915. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3916. if s.Price != lastWarehouse.RetailPrice {
  3917. s.Price = lastWarehouse.RetailPrice
  3918. }
  3919. if s.Price == 0 {
  3920. if lastWarehouse.ID == 0 {
  3921. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  3922. s.Price = lastWarehouseTwo.RetailPrice
  3923. }
  3924. }
  3925. }
  3926. if adminInfo.CurrentOrgId != 10206 {
  3927. if s.ID == 0 {
  3928. //查询改药品是否已经停用
  3929. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3930. if base.ID > 0 {
  3931. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3932. return
  3933. }
  3934. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3935. if drugMedical.SumCount == 0 {
  3936. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3937. return
  3938. }
  3939. }
  3940. }
  3941. //赤峰
  3942. if s.UserOrgId == 10265 {
  3943. drug, _ := service.GetDrugByGoodId(s.DrugId)
  3944. info, _ := service.GetWarehoseInfoByDrugId(s.DrugId, s.UserOrgId)
  3945. if info.RetailPrice > 0 {
  3946. if s.DeliveryWay == "口服" {
  3947. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3948. s.Price = drug.RetailPrice
  3949. }
  3950. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3951. s.Price = info.RetailPrice
  3952. }
  3953. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3954. s.Price = info.RetailPrice
  3955. }
  3956. }
  3957. }
  3958. }
  3959. service.CreateHisDoctorAdvice(&s)
  3960. //记录日志
  3961. byterequest, _ := json.Marshal(s)
  3962. adviceLog := models.XtDoctorAdviceLog{
  3963. UserOrgId: s.UserOrgId,
  3964. PatientId: s.PatientId,
  3965. AdminUserId: adminInfo.AdminUser.Id,
  3966. Module: 1,
  3967. ErrLog: string(byterequest),
  3968. Status: 1,
  3969. Ctime: time.Now().Unix(),
  3970. Mtime: 0,
  3971. Source: "电脑端新建his医嘱",
  3972. RecordDate: s.AdviceDate,
  3973. }
  3974. service.CreateDoctorAdviceLog(adviceLog)
  3975. //存储切片中
  3976. adviceList = append(adviceList, s)
  3977. redis := service.RedisClient()
  3978. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3979. redis.Set(key, "", time.Second)
  3980. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3981. redis.Set(keyOne, "", time.Second)
  3982. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3983. redis.Set(keySeven, "", time.Second)
  3984. var randNum int
  3985. randNum = rand.Intn(10000) + 1000
  3986. timestamp := time.Now().Unix()
  3987. tempTime := time.Unix(timestamp, 0)
  3988. timeFormat := tempTime.Format("20060102150405")
  3989. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3990. service.CreateHisDoctorAdvice(&s)
  3991. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3992. redis.Set(keySix, "", time.Second)
  3993. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3994. redis.Set(keyFive, "", time.Second)
  3995. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3996. redis.Set(keyEight, "", time.Second)
  3997. defer redis.Close()
  3998. }
  3999. }
  4000. }
  4001. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4002. projects := items["project"].([]interface{})
  4003. if len(projects) > 0 {
  4004. for _, project := range projects {
  4005. var p models.HisPrescriptionProject
  4006. p.PrescriptionId = tempPrescription.ID
  4007. p.PatientId = patient_id
  4008. p.RecordDate = theTime3.Unix()
  4009. p.Doctor = doctor_id
  4010. p.UserOrgId = adminInfo.CurrentOrgId
  4011. p.HisPatientId = his_patient_id
  4012. p.Status = 1
  4013. p.StartTime = pTime
  4014. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  4015. if errcode > 0 {
  4016. c.ServeFailJSONWithSGJErrorCode(errcode)
  4017. return
  4018. }
  4019. if p.ID == 0 {
  4020. p.IsOut = 2
  4021. }
  4022. if p.ID > 0 {
  4023. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  4024. p.IsOut = projectDetail.IsOut
  4025. }
  4026. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4027. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4028. if p.Type == 3 {
  4029. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  4030. if p.Price != lastWarehouse.PackingPrice {
  4031. p.Price = lastWarehouse.PackingPrice
  4032. }
  4033. if p.Price == 0 {
  4034. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  4035. p.Price = lastWarehouseTwo.PackingPrice
  4036. }
  4037. if p.Unit == "" {
  4038. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4039. p.Unit = goodInfoOne.PackingUnit
  4040. }
  4041. }
  4042. }
  4043. if adminInfo.CurrentOrgId != 10206 {
  4044. if p.Type == 3 {
  4045. if p.ID == 0 {
  4046. //查询该耗材是否停用
  4047. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  4048. //表示该耗材已经停用,不能保存
  4049. if goodInfoSeven.ID == 0 {
  4050. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4051. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  4052. return
  4053. }
  4054. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4055. if goodInfoOne.SumCount == 0 {
  4056. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  4057. return
  4058. }
  4059. }
  4060. }
  4061. }
  4062. service.CreateHisProjectTwo(&p)
  4063. //记录日志
  4064. byterequest, _ := json.Marshal(p)
  4065. adviceLog := models.XtDoctorAdviceLog{
  4066. UserOrgId: p.UserOrgId,
  4067. PatientId: p.PatientId,
  4068. AdminUserId: adminInfo.AdminUser.Id,
  4069. Module: 1,
  4070. ErrLog: string(byterequest),
  4071. Status: 1,
  4072. Ctime: time.Now().Unix(),
  4073. Mtime: 0,
  4074. Source: "电脑端新建his项目",
  4075. RecordDate: p.RecordDate,
  4076. }
  4077. service.CreateDoctorAdviceLog(adviceLog)
  4078. projectList = append(projectList, p)
  4079. var randNum int
  4080. randNum = rand.Intn(10000) + 1000
  4081. timestamp := time.Now().Unix()
  4082. tempTime := time.Unix(timestamp, 0)
  4083. timeFormat := tempTime.Format("20060102150405")
  4084. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4085. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4086. //新增或者编辑项目,修改对应的标签数据
  4087. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4088. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4089. var label models.HisLabelPrintInfo
  4090. project, _ := service.GetProjectDetail(p.ProjectId)
  4091. if project.CostClassify == 3 { //类别为检验检查
  4092. if p.TeamId > 0 { //检验检查组套
  4093. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4094. if tempLabel.ID == 0 {
  4095. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4096. label.Number = tempPrescription.PrescriptionNumber
  4097. label.ProjectId = project.ID
  4098. label.Status = 1
  4099. label.IsPrint = 2
  4100. label.DoctorId = info.DoctorId
  4101. label.UserOrgId = p.UserOrgId
  4102. label.PatientId = patient_id
  4103. label.RecordDate = recordDateTime
  4104. label.Ctime = time.Now().Unix()
  4105. label.Mtime = time.Now().Unix()
  4106. label.ItemId = p.TeamId
  4107. label.FeedetlSn = p.FeedetlSn
  4108. label.PProjectId = p.ID
  4109. label.ProjectName = team.ProjectTeam
  4110. label.PatientName = patient.Name
  4111. service.CreateHisLabelRecord(&label)
  4112. }
  4113. } else { //单条检验检查项目
  4114. label.Number = tempPrescription.PrescriptionNumber
  4115. label.ProjectId = project.ID
  4116. label.Status = 1
  4117. label.DoctorId = info.DoctorId
  4118. label.UserOrgId = p.UserOrgId
  4119. label.PatientId = patient_id
  4120. label.RecordDate = recordDateTime
  4121. label.IsPrint = 2
  4122. label.Ctime = time.Now().Unix()
  4123. label.Mtime = time.Now().Unix()
  4124. label.FeedetlSn = p.FeedetlSn
  4125. label.PProjectId = p.ID
  4126. label.ItemId = p.TeamId
  4127. label.ProjectName = project.ProjectName
  4128. label.PatientName = patient.Name
  4129. service.CreateHisLabelRecord(&label)
  4130. }
  4131. }
  4132. }
  4133. }
  4134. service.SaveHisProjectTwo(&p)
  4135. }
  4136. }
  4137. }
  4138. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4139. // addition := items["addition"].([]interface{})
  4140. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4141. // ctime := time.Now().Unix()
  4142. // mtime := ctime
  4143. // if len(addition) > 0 {
  4144. // for _, item := range addition {
  4145. // var s models.HisAdditionalCharge
  4146. // s.PrescriptionId = tempPrescription.ID
  4147. // s.Status = 1
  4148. // s.UserOrgId = adminInfo.CurrentOrgId
  4149. // s.RecordDate = recordDateTime
  4150. // s.CreatedTime = ctime
  4151. // s.UpdatedTime = mtime
  4152. // s.PatientId = patient_id
  4153. // s.HisPatientId = his_patient_id
  4154. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4155. // if errcode > 0 {
  4156. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4157. // return
  4158. // }
  4159. // service.CreateAdditionalCharge(&s)
  4160. // var randNum int
  4161. // randNum = rand.Intn(10000) + 1000
  4162. // timestamp := time.Now().Unix()
  4163. // tempTime := time.Unix(timestamp, 0)
  4164. // timeFormat := tempTime.Format("20060102150405")
  4165. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4166. // service.CreateAdditionalCharge(&s)
  4167. //
  4168. // }
  4169. // }
  4170. //}
  4171. }
  4172. }
  4173. //查询今日该患者开的药品处方
  4174. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4175. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  4176. //药品出库
  4177. if drugOutConfig.IsOpen == 1 {
  4178. for _, item := range hisdoctorlist {
  4179. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  4180. // 查询该药品最后一次出库记录
  4181. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  4182. if len(druginfo) > 0 {
  4183. //回退库存
  4184. for _, it := range druginfo {
  4185. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4186. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4187. }
  4188. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4189. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4190. }
  4191. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4192. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4193. }
  4194. }
  4195. }
  4196. //删除记录
  4197. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4198. //查询最后一次数据
  4199. if drugOutConfig.IsOpen == 1 {
  4200. //出库
  4201. if drug.IsUse == 2 {
  4202. creater := adminInfo.AdminUser.Id
  4203. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4204. }
  4205. //更新字典里面的库存
  4206. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4207. var sum_count int64
  4208. for _, its := range stockInfo {
  4209. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4210. if its.MaxUnit == baseDrug.MaxUnit {
  4211. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4212. }
  4213. sum_count += its.StockMaxNumber + its.StockMinNumber
  4214. }
  4215. //更新基础库存
  4216. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4217. //剩余库存
  4218. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4219. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4220. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4221. }
  4222. }
  4223. }
  4224. //耗材保存处方出库
  4225. if goodOutConfig.IsOpen == 1 {
  4226. //查询今日耗材出库数量
  4227. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4228. for _, item := range hisgoodlist {
  4229. //查询历史出库数据
  4230. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4231. var out_count_five int64
  4232. for _, item := range flowGood {
  4233. out_count_five += item.Count
  4234. }
  4235. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  4236. if out_count_five != parseIntCount {
  4237. //查询耗材最后一次出库记录
  4238. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  4239. //查询默认出库仓库库存
  4240. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4241. if len(wareOut) > 0 {
  4242. for _, it := range wareOut {
  4243. //回退库存
  4244. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4245. //删除出库记录
  4246. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4247. }
  4248. }
  4249. timeStr := time.Now().Format("2006-01-02")
  4250. timeArr := strings.Split(timeStr, "-")
  4251. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4252. total = total + 1
  4253. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4254. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4255. number = number + total
  4256. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4257. operation_time := time.Now().Unix()
  4258. creater := c.GetAdminUserInfo().AdminUser.Id
  4259. recordDateStr := time.Now().Format("2006-01-02")
  4260. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4261. nowtime := recordDate.Unix()
  4262. warehouseOut := models.WarehouseOut{
  4263. WarehouseOutOrderNumber: warehousing_out_order,
  4264. OperationTime: operation_time,
  4265. OrgId: adminInfo.CurrentOrgId,
  4266. Creater: creater,
  4267. Ctime: time.Now().Unix(),
  4268. Status: 1,
  4269. WarehouseOutTime: nowtime,
  4270. Type: 1,
  4271. StorehouseId: storeConfig.StorehouseOutInfo,
  4272. IsCheck: 1,
  4273. IsSys: 1,
  4274. }
  4275. //查询是否生成出库单
  4276. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4277. if out.ID == 0 {
  4278. service.AddSigleWarehouseOut(&warehouseOut)
  4279. }
  4280. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4281. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4282. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4283. dialyPrepareOne := models.DialysisBeforePrepare{
  4284. GoodTypeId: goodObj.GoodTypeId,
  4285. GoodId: item.ProjectId,
  4286. PatientId: item.PatientId,
  4287. RecordDate: item.RecordDate,
  4288. UserOrgId: adminInfo.CurrentOrgId,
  4289. Count: parseIntCount,
  4290. Ctime: time.Now().Unix(),
  4291. Creater: creater,
  4292. Status: 1,
  4293. StorehouseId: houseConfig.StorehouseOutInfo,
  4294. ProjectId: item.ID,
  4295. }
  4296. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4297. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  4298. //查询历史出库数据
  4299. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4300. var out_count int64
  4301. for _, item := range flowGood {
  4302. out_count += item.Count
  4303. }
  4304. //如果历史数和当前数据不想等才进行退库出库
  4305. if out_count != parseIntCount {
  4306. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4307. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4308. detail := models.AutomaticReduceDetail{
  4309. WarehouseOutId: 0,
  4310. WarehouseOutOrderNumber: "",
  4311. PatientId: item.PatientId,
  4312. Ctime: time.Now().Unix(),
  4313. Mtime: 0,
  4314. Status: 1,
  4315. RecordTime: item.RecordDate,
  4316. OrgId: item.UserOrgId,
  4317. GoodId: item.ProjectId,
  4318. GoodTypeId: 0,
  4319. Count: parseIntCount,
  4320. Type: 0,
  4321. ProjectId: item.ID,
  4322. StorehouseId: 0,
  4323. }
  4324. service.CreateAutoDetail(detail)
  4325. //查询剩余库存
  4326. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4327. var sum_count int64
  4328. for _, item := range goodList {
  4329. sum_count += item.StockCount
  4330. }
  4331. //更新剩余库存
  4332. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4333. //耗材
  4334. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4335. }
  4336. }
  4337. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  4338. //查询历史出库数据
  4339. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4340. var out_count int64
  4341. for _, item := range flowGood {
  4342. out_count += item.Count
  4343. }
  4344. //如果历史数和当前数据不想等才进行退库出库
  4345. if out_count != parseIntCount {
  4346. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4347. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4348. detail := models.AutomaticReduceDetail{
  4349. WarehouseOutId: 0,
  4350. WarehouseOutOrderNumber: "",
  4351. PatientId: item.PatientId,
  4352. Ctime: time.Now().Unix(),
  4353. Mtime: 0,
  4354. Status: 1,
  4355. RecordTime: item.RecordDate,
  4356. OrgId: item.UserOrgId,
  4357. GoodId: item.ProjectId,
  4358. GoodTypeId: 0,
  4359. Count: parseIntCount,
  4360. Type: 0,
  4361. ProjectId: item.ID,
  4362. StorehouseId: 0,
  4363. }
  4364. service.CreateAutoDetail(detail)
  4365. //查询剩余库存
  4366. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4367. var sum_count int64
  4368. for _, item := range goodList {
  4369. sum_count += item.StockCount
  4370. }
  4371. //更新剩余库存
  4372. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4373. //耗材
  4374. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4375. }
  4376. }
  4377. }
  4378. }
  4379. }
  4380. ////同步到自备药
  4381. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  4382. if selfPrescriptionOpen.IsOpen == 1 {
  4383. timeStr := time.Now().Format("2006-01-02")
  4384. timeArr := strings.Split(timeStr, "-")
  4385. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  4386. total = total + 1
  4387. operation_time := time.Now().Unix()
  4388. creater := adminInfo.AdminUser.Id
  4389. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4390. warehousing := models.XtSelfDrugWarehouse{
  4391. WarehousingOrder: warehousing_order,
  4392. OperationTime: operation_time,
  4393. OrgId: adminInfo.CurrentOrgId,
  4394. Creater: creater,
  4395. Ctime: time.Now().Unix(),
  4396. Status: 1,
  4397. WarehousingTime: recordDateTime,
  4398. Type: 0,
  4399. StorehouseId: 0,
  4400. IsCheck: 1,
  4401. PatientId: patient_id,
  4402. IsSys: 1,
  4403. }
  4404. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  4405. if selfDrugWarehouse.ID == 0 {
  4406. service.AddSelfDrugWarehouse(&warehousing, tx)
  4407. }
  4408. if selfDrugWarehouse.ID > 0 {
  4409. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  4410. }
  4411. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  4412. fmt.Println(info)
  4413. for _, item := range hisdoctorlist {
  4414. //查询该病人的该药品是否已经入库
  4415. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  4416. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  4417. var in_count int64
  4418. if len(selfdruginfo) > 0 {
  4419. for _, item := range selfdruginfo {
  4420. var in_count_one int64
  4421. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4422. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  4423. }
  4424. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4425. in_count_one = item.WarehousingCount
  4426. }
  4427. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4428. in_count_one = item.WarehousingCount
  4429. }
  4430. in_count += in_count_one
  4431. }
  4432. }
  4433. if selfBasedrug.IsSelfDrug == 1 {
  4434. var total_count int64
  4435. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  4436. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  4437. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4438. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  4439. }
  4440. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4441. total_count += prescribingNumberSeven
  4442. }
  4443. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4444. total_count += prescribingNumberSeven
  4445. }
  4446. //入库
  4447. if total_count > in_count {
  4448. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  4449. WarehousingOrder: warehousing_order,
  4450. WarehousingId: info.ID,
  4451. DrugId: item.DrugId,
  4452. Number: "",
  4453. ProductDate: 0,
  4454. ExpiryDate: 0,
  4455. WarehousingCount: total_count - in_count,
  4456. WarehouseingUnit: selfBasedrug.MinUnit,
  4457. Price: 0,
  4458. TotalPrice: 0,
  4459. Status: 1,
  4460. Ctime: time.Now().Unix(),
  4461. Remark: "",
  4462. OrgId: adminInfo.CurrentOrgId,
  4463. Type: 0,
  4464. Manufacturer: selfBasedrug.Manufacturer,
  4465. Dealer: selfBasedrug.Dealer,
  4466. StockMaxNumber: total_count - in_count,
  4467. RetailTotalPrice: 0,
  4468. BatchNumber: "",
  4469. MaxUnit: selfBasedrug.MinUnit,
  4470. MinUnit: selfBasedrug.MinUnit,
  4471. RetailPrice: 0,
  4472. StorehouseId: 0,
  4473. IsCheck: 1,
  4474. StockMinNumber: 0,
  4475. PatientId: patient_id,
  4476. IsSys: 1,
  4477. RecordDate: item.RecordDate,
  4478. AdviceId: item.ID,
  4479. }
  4480. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  4481. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  4482. Creator := adminInfo.AdminUser.Id
  4483. //查询默认仓库剩余多少库存
  4484. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  4485. var sum_count int64
  4486. for _, it := range list {
  4487. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  4488. if it.MaxUnit == baseDrug.MaxUnit {
  4489. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  4490. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  4491. }
  4492. sum_count += it.StockMaxNumber + it.StockMinNumber
  4493. }
  4494. flow := &models.XtSelfDrugFlow{
  4495. WarehousingId: info.ID,
  4496. DrugId: item.DrugId,
  4497. Number: "",
  4498. BatchNumber: "",
  4499. Count: total_count - in_count,
  4500. UserOrgId: adminInfo.CurrentOrgId,
  4501. PatientId: item.PatientId,
  4502. SystemTime: time.Now().Unix(),
  4503. ConsumableType: 1,
  4504. IsSys: 1,
  4505. WarehousingOrder: warehousing_order,
  4506. WarehouseOutId: 0,
  4507. WarehouseOutOrderNumber: "",
  4508. IsEdit: 0,
  4509. CancelStockId: 0,
  4510. CancelOrderNumber: "",
  4511. Manufacturer: selfBasedrug.Manufacturer,
  4512. Dealer: selfBasedrug.Dealer,
  4513. Creator: Creator,
  4514. UpdateCreator: Creator,
  4515. Status: 1,
  4516. Ctime: item.AdviceDate,
  4517. Mtime: 0,
  4518. Price: item.Price,
  4519. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  4520. WarehouseOutDetailId: 0,
  4521. CancelOutDetailId: 0,
  4522. ExpireDate: 0,
  4523. ProductDate: 0,
  4524. MaxUnit: selfBasedrug.MinUnit,
  4525. MinUnit: selfBasedrug.MinUnit,
  4526. StorehouseId: 0,
  4527. OverCount: sum_count,
  4528. OperateTime: time.Now().Unix(),
  4529. AdviceId: item.ID,
  4530. }
  4531. service.CreateSelfDrugFlow(flow, tx)
  4532. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  4533. var total_count int64 // 入库总数量
  4534. var over_count int64 //剩余库存
  4535. for _, it := range drugInfolist {
  4536. if it.MaxUnit == selfBasedrug.MaxUnit {
  4537. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  4538. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  4539. }
  4540. }
  4541. for _, it := range drugInfolist {
  4542. total_count += it.WarehousingCount
  4543. over_count += it.StockMaxNumber + it.StockMinNumber
  4544. }
  4545. //查询该仓库是否有默认数据
  4546. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  4547. if selfDrugStock.ID == 0 {
  4548. drugStock := models.XtSelfDrugStockCount{
  4549. UserOrgId: item.UserOrgId,
  4550. PatientId: item.PatientId,
  4551. SumInCount: total_count,
  4552. SumOutCount: 0,
  4553. SumCancelCount: 0,
  4554. DrugId: item.DrugId,
  4555. Ctime: time.Now().Unix(),
  4556. Mtime: 0,
  4557. Status: 1,
  4558. FlushCount: over_count,
  4559. SumActOutCount: 0,
  4560. }
  4561. service.CreateSelfDrugStockSum(drugStock, tx)
  4562. }
  4563. if selfDrugStock.ID > 0 {
  4564. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  4565. }
  4566. }
  4567. //查询这个单据的出库数量
  4568. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  4569. var his_out_count int64
  4570. for _, item := range drugFlowList {
  4571. his_out_count += item.Count
  4572. }
  4573. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  4574. if (total_count + his_out_count) <= in_count {
  4575. // 出库
  4576. if total_count < in_count {
  4577. var cha_count int64
  4578. cha_count = in_count - total_count
  4579. var stock_number int64 = 0
  4580. //查询库存是否充足
  4581. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  4582. // 将该批次的剩余库存数量转换为拆零数量
  4583. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4584. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  4585. }
  4586. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4587. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  4588. }
  4589. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4590. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  4591. }
  4592. if stock_number >= cha_count {
  4593. var maxNumber int64 = 0
  4594. var minNumber int64 = 0
  4595. maxNumber = cha_count / selfBasedrug.MinNumber
  4596. minNumber = cha_count % selfBasedrug.MinNumber
  4597. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4598. minNumber = maxNumber
  4599. }
  4600. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4601. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  4602. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4603. return
  4604. }
  4605. }
  4606. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4607. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  4608. }
  4609. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4610. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  4611. }
  4612. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4613. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  4614. }
  4615. if warehouse.StockMaxNumber < 0 {
  4616. warehouse.StockMaxNumber = 0
  4617. }
  4618. if warehouse.StockMinNumber < 0 {
  4619. warehouse.StockMinNumber = 0
  4620. }
  4621. warehouse.Mtime = time.Now().Unix()
  4622. if warehouse.StockMinNumber < minNumber {
  4623. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  4624. if warehouse.MaxUnit != warehouse.MinUnit {
  4625. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  4626. }
  4627. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  4628. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  4629. }
  4630. } else {
  4631. if minNumber > 0 {
  4632. if (warehouse.StockMinNumber - minNumber) >= 0 {
  4633. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  4634. }
  4635. }
  4636. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  4637. if warehouse.StockMinNumber > 0 {
  4638. if warehouse.StockMinNumber-cha_count >= 0 {
  4639. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  4640. }
  4641. }
  4642. }
  4643. }
  4644. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  4645. if (warehouse.StockMinNumber - cha_count) >= 0 {
  4646. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  4647. }
  4648. }
  4649. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4650. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  4651. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4652. return
  4653. }
  4654. }
  4655. if warehouse.StockMinNumber <= 0 {
  4656. warehouse.StockMinNumber = 0
  4657. }
  4658. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  4659. //查询该药品剩余库存
  4660. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  4661. var over_count int64
  4662. for _, its := range infolist {
  4663. if its.MaxUnit == selfBasedrug.MaxUnit {
  4664. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  4665. }
  4666. over_count += its.StockMaxNumber + its.StockMinNumber
  4667. }
  4668. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  4669. drugflow := models.XtSelfDrugFlow{
  4670. WarehouseOutId: 0,
  4671. WarehouseOutOrderNumber: warehousing_order,
  4672. WarehousingOrder: warehousing_order,
  4673. DrugId: item.DrugId,
  4674. Number: warehouse.Number,
  4675. ProductDate: warehouse.ProductDate,
  4676. ExpireDate: warehouse.ExpiryDate,
  4677. Count: cha_count,
  4678. Price: warehouse.RetailPrice,
  4679. Status: 1,
  4680. Ctime: item.AdviceDate,
  4681. Mtime: time.Now().Unix(),
  4682. UserOrgId: item.UserOrgId,
  4683. Manufacturer: warehouse.Manufacturer,
  4684. Dealer: warehouse.Dealer,
  4685. BatchNumber: warehouse.BatchNumber,
  4686. MaxUnit: selfBasedrug.MinUnit,
  4687. ConsumableType: 20,
  4688. IsEdit: 1,
  4689. Creator: 0,
  4690. IsSys: 3,
  4691. WarehouseOutDetailId: drugWareInfo.ID,
  4692. AdviceId: item.ID,
  4693. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  4694. StorehouseId: 0,
  4695. AdminUserId: creater,
  4696. LastPrice: warehouse.Price,
  4697. StockCount: "",
  4698. WarehousingDetailId: 0,
  4699. OverCount: over_count,
  4700. RetailPrice: item.Price, //手动出库出库价格
  4701. WarehousingId: warehouse.ID,
  4702. SystemTime: item.AdviceDate,
  4703. PatientId: item.PatientId,
  4704. Remark: "保存处方入库数据差",
  4705. OperateTime: time.Now().Unix(),
  4706. }
  4707. if warehouse.RetailPrice == 0 {
  4708. drugflow.Price = item.Price
  4709. }
  4710. service.CreateSelfDrugFlowOne(drugflow, tx)
  4711. var out_count int64
  4712. out_count = in_count - total_count
  4713. //
  4714. //fmt.Println("in_count------------------", in_count)
  4715. //fmt.Println("total_count------------------", total_count)
  4716. //添加出库数量
  4717. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  4718. //查询剩余库存
  4719. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  4720. var sum_count int64
  4721. for _, its := range stockInfo {
  4722. if its.MaxUnit == selfBasedrug.MaxUnit {
  4723. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  4724. }
  4725. sum_count += its.StockMaxNumber + its.StockMinNumber
  4726. }
  4727. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  4728. } else {
  4729. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4730. return
  4731. }
  4732. }
  4733. }
  4734. }
  4735. }
  4736. }
  4737. }
  4738. tx.Commit()
  4739. if err == nil {
  4740. c.ServeSuccessJSON(map[string]interface{}{
  4741. "msg": "保存成功",
  4742. })
  4743. return
  4744. } else {
  4745. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4746. return
  4747. }
  4748. }
  4749. }
  4750. //func (c *HisApiController) EditHisPrescription() {
  4751. // record_date := c.GetString("record_date")
  4752. // patient_id, _ := c.GetInt64("patient_id")
  4753. // reg_type, _ := c.GetInt64("reg_type")
  4754. // //diagnose, _ := c.GetInt64("diagnose", 0)
  4755. // diagnose := c.GetString("diagnose")
  4756. // sick_type, _ := c.GetInt64("sick_type")
  4757. // sick_history := c.GetString("sick_history")
  4758. // doctor_id, _ := c.GetInt64("doctor", 0)
  4759. // department, _ := c.GetInt64("department", 0)
  4760. // his_patient_id, _ := c.GetInt64("his_patient_id")
  4761. // p_type, _ := c.GetInt64("p_type")
  4762. //
  4763. // dataBody := make(map[string]interface{}, 0)
  4764. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4765. // if err != nil {
  4766. // utils.ErrorLog(err.Error())
  4767. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4768. // return
  4769. // }
  4770. //
  4771. // timeLayout := "2006-01-02"
  4772. // loc, _ := time.LoadLocation("Local")
  4773. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4774. // if err != nil {
  4775. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4776. // return
  4777. // }
  4778. // adminInfo := c.GetAdminUserInfo()
  4779. // recordDateTime := theTime.Unix()
  4780. //
  4781. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  4782. //
  4783. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4784. // var hpInfo models.HisPrescriptionInfo
  4785. // if info.ID == 0 {
  4786. // var randNum int
  4787. // randNum = rand.Intn(10000) + 1000
  4788. // timestamp := time.Now().Unix()
  4789. // tempTime := time.Unix(timestamp, 0)
  4790. // timeFormat := tempTime.Format("20060102150405")
  4791. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4792. //
  4793. // hpInfo = models.HisPrescriptionInfo{
  4794. // UserOrgId: adminInfo.CurrentOrgId,
  4795. // RecordDate: theTime.Unix(),
  4796. // PatientId: patient_id,
  4797. // Status: 1,
  4798. // Ctime: time.Now().Unix(),
  4799. // Mtime: time.Now().Unix(),
  4800. // Creator: adminInfo.AdminUser.Id,
  4801. // Modifier: adminInfo.AdminUser.Id,
  4802. // Diagnosis: diagnose,
  4803. // SickHistory: sick_history,
  4804. // Departments: department,
  4805. // RegisterType: reg_type,
  4806. // PrescriptionNumber: p_number,
  4807. // PrescriptionStatus: 1,
  4808. // Doctor: role.UserName,
  4809. // DoctorId: doctor_id,
  4810. // SickType: sick_type,
  4811. // PType: p_type,
  4812. // }
  4813. // service.SavePatientPrescriptionInfo(hpInfo)
  4814. //
  4815. // } else {
  4816. // hpInfo = models.HisPrescriptionInfo{
  4817. // ID: info.ID,
  4818. // UserOrgId: adminInfo.CurrentOrgId,
  4819. // RecordDate: info.RecordDate,
  4820. // PatientId: info.PatientId,
  4821. // Status: 1,
  4822. // Ctime: info.Ctime,
  4823. // Mtime: time.Now().Unix(),
  4824. // Creator: info.Creator,
  4825. // Modifier: adminInfo.AdminUser.Id,
  4826. // Diagnosis: diagnose,
  4827. // SickHistory: sick_history,
  4828. // Departments: department,
  4829. // RegisterType: reg_type,
  4830. // PrescriptionNumber: info.PrescriptionNumber,
  4831. // Doctor: role.UserName,
  4832. // PrescriptionStatus: info.PrescriptionStatus,
  4833. // DoctorId: doctor_id,
  4834. // SickType: sick_type,
  4835. // PType: info.PType,
  4836. // }
  4837. // service.SavePatientPrescriptionInfo(hpInfo)
  4838. // }
  4839. //
  4840. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4841. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4842. //
  4843. // if len(prescriptions) > 0 {
  4844. // for _, item := range prescriptions {
  4845. // items := item.(map[string]interface{})
  4846. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4847. // utils.ErrorLog("id")
  4848. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4849. // return
  4850. // }
  4851. // id := int64(items["id"].(float64))
  4852. //
  4853. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4854. // utils.ErrorLog("type")
  4855. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4856. // return
  4857. // }
  4858. // types := int64(items["type"].(float64))
  4859. //
  4860. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4861. // utils.ErrorLog("med_type")
  4862. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4863. // return
  4864. // }
  4865. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4866. //
  4867. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  4868. //
  4869. // ctime := time.Now().Unix()
  4870. //
  4871. // prescription := &models.HisPrescription{
  4872. // ID: id,
  4873. // PatientId: patient_id,
  4874. // UserOrgId: adminInfo.CurrentOrgId,
  4875. // RecordDate: recordDateTime,
  4876. // Ctime: ctime,
  4877. // Mtime: ctime,
  4878. // Type: types,
  4879. // Modifier: adminInfo.AdminUser.Id,
  4880. // Creator: adminInfo.AdminUser.Id,
  4881. // Status: 1,
  4882. // Doctor: role.UserName,
  4883. // HisPatientId: his_patient_id,
  4884. // OrderStatus: 1,
  4885. // BatchNumber: "",
  4886. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  4887. // PType: hpInfo.PType,
  4888. // MedType: med_type,
  4889. // }
  4890. //
  4891. // if historyPrescription.ID > 0 {
  4892. // prescription.PreTime = historyPrescription.PreTime
  4893. //
  4894. // }
  4895. //
  4896. // service.SaveHisPrescription(prescription)
  4897. //
  4898. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4899. // advices := items["advices"].([]interface{})
  4900. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4901. // groupNo := int64(0)
  4902. // ctime := time.Now().Unix()
  4903. // mtime := ctime
  4904. // if len(advices) > 0 {
  4905. // for _, advice := range advices {
  4906. // var s models.HisDoctorAdviceInfo
  4907. // s.PrescriptionId = prescription.ID
  4908. // s.AdviceType = 2
  4909. // s.AdviceDoctor = adminInfo.AdminUser.Id
  4910. // s.StopState = 2
  4911. // s.ExecutionState = 2
  4912. // s.AdviceDate = recordDateTime
  4913. // s.Status = 1
  4914. // s.UserOrgId = adminInfo.CurrentOrgId
  4915. // s.RecordDate = recordDateTime
  4916. // s.StartTime = prescription.PreTime
  4917. // s.Groupno = groupNo
  4918. // s.CreatedTime = ctime
  4919. // s.UpdatedTime = mtime
  4920. // s.PatientId = patient_id
  4921. // s.HisPatientId = his_patient_id
  4922. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  4923. // if errcode > 0 {
  4924. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4925. // return
  4926. // }
  4927. //
  4928. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4929. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4930. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4931. // if s.Price == 0 {
  4932. // s.Price = lastWarehouse.RetailPrice
  4933. // }
  4934. // }
  4935. //
  4936. // service.CreateHisDoctorAdvice(&s)
  4937. // //记录日志
  4938. // byterequest, _ := json.Marshal(s)
  4939. // adviceLog := models.XtDoctorAdviceLog{
  4940. // UserOrgId: s.UserOrgId,
  4941. // PatientId: s.PatientId,
  4942. // AdminUserId: adminInfo.AdminUser.Id,
  4943. // Module: 1,
  4944. // ErrLog: string(byterequest),
  4945. // Status: 1,
  4946. // Ctime: time.Now().Unix(),
  4947. // Mtime: 0,
  4948. // Source: "电脑端his医嘱修改",
  4949. // RecordDate: s.AdviceDate,
  4950. // }
  4951. // service.CreateDoctorAdviceLog(adviceLog)
  4952. // redis := service.RedisClient()
  4953. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4954. // redis.Set(key, "", time.Second)
  4955. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4956. // fmt.Println("keyOne", keyOne)
  4957. // redis.Set(keyOne, "", time.Second)
  4958. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4959. // redis.Set(keySeven, "", time.Second)
  4960. // redis.Close()
  4961. //
  4962. // }
  4963. // }
  4964. // }
  4965. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4966. // projects := items["project"].([]interface{})
  4967. // if len(projects) > 0 {
  4968. // for _, project := range projects {
  4969. // var p models.HisPrescriptionProject
  4970. // p.PrescriptionId = prescription.ID
  4971. // p.Ctime = time.Now().Unix()
  4972. // p.Mtime = time.Now().Unix()
  4973. // p.PatientId = patient_id
  4974. // p.RecordDate = recordDateTime
  4975. // p.UserOrgId = adminInfo.CurrentOrgId
  4976. // p.HisPatientId = his_patient_id
  4977. // p.Status = 1
  4978. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  4979. // if errcode > 0 {
  4980. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4981. // return
  4982. // }
  4983. // service.CreateHisProjectTwo(&p)
  4984. //
  4985. // //记录日志
  4986. // byterequest, _ := json.Marshal(p)
  4987. // adviceLog := models.XtDoctorAdviceLog{
  4988. // UserOrgId: p.UserOrgId,
  4989. // PatientId: p.PatientId,
  4990. // AdminUserId: adminInfo.AdminUser.Id,
  4991. // Module: 1,
  4992. // ErrLog: string(byterequest),
  4993. // Status: 1,
  4994. // Ctime: time.Now().Unix(),
  4995. // Mtime: 0,
  4996. // Source: "电脑端his项目修改",
  4997. // RecordDate: p.RecordDate,
  4998. // }
  4999. // service.CreateDoctorAdviceLog(adviceLog)
  5000. // }
  5001. // }
  5002. // }
  5003. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  5004. // addition := items["addition"].([]interface{})
  5005. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5006. // ctime := time.Now().Unix()
  5007. // mtime := ctime
  5008. // if len(addition) > 0 {
  5009. // for _, item := range addition {
  5010. // var s models.HisAdditionalCharge
  5011. // s.PrescriptionId = prescription.ID
  5012. // s.Status = 1
  5013. // s.UserOrgId = adminInfo.CurrentOrgId
  5014. // s.RecordDate = recordDateTime
  5015. // s.CreatedTime = ctime
  5016. // s.UpdatedTime = mtime
  5017. // s.PatientId = patient_id
  5018. // s.HisPatientId = his_patient_id
  5019. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5020. // if errcode > 0 {
  5021. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5022. // return
  5023. // }
  5024. // service.CreateAdditionalCharge(&s)
  5025. // }
  5026. // }
  5027. // }
  5028. //
  5029. // }
  5030. // }
  5031. // }
  5032. // if err == nil {
  5033. // c.ServeSuccessJSON(map[string]interface{}{
  5034. // "msg": "保存成功",
  5035. // })
  5036. // return
  5037. //
  5038. // } else {
  5039. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5040. // return
  5041. // }
  5042. //}
  5043. func (c *HisApiController) DeletePrescription() {
  5044. prescription_id, _ := c.GetInt64("id")
  5045. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  5046. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  5047. ////同步到自备药
  5048. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  5049. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  5050. if selfPrescriptionOpen.IsOpen == 1 {
  5051. // 在函数结束时处理事务回滚
  5052. db := service.XTWriteDB()
  5053. tx := db.Begin()
  5054. defer func() {
  5055. if r := recover(); r != nil {
  5056. tx.Rollback()
  5057. } else {
  5058. tx.Commit()
  5059. }
  5060. }()
  5061. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  5062. for _, item := range advicesList {
  5063. timeStr := time.Now().Format("2006-01-02")
  5064. timeArr := strings.Split(timeStr, "-")
  5065. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5066. total = total + 1
  5067. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5068. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5069. number = number + total
  5070. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5071. operation_time := time.Now().Unix()
  5072. creater := c.GetAdminUserInfo().AdminUser.Id
  5073. //创建一个出库单
  5074. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5075. WarehouseOutOrderNumber: warehousing_out_order,
  5076. OperationTime: operation_time,
  5077. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5078. Creater: creater,
  5079. Ctime: time.Now().Unix(),
  5080. Status: 1,
  5081. WarehouseOutTime: item.AdviceDate,
  5082. Type: 0,
  5083. PatientId: item.PatientId,
  5084. IsCheck: 1,
  5085. }
  5086. //查询今日是否有出库数据
  5087. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  5088. fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
  5089. if lastWarehouseOut.ID == 0 {
  5090. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5091. }
  5092. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5093. var total_count int64
  5094. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5095. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5096. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5097. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5098. }
  5099. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5100. total_count += prescribingNumberSeven
  5101. }
  5102. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5103. total_count += prescribingNumberSeven
  5104. }
  5105. //出库
  5106. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5107. WarehouseOutOrderNumber: warehousing_out_order,
  5108. WarehouseOutId: lastWarehouseOut.ID,
  5109. DrugId: item.DrugId,
  5110. Count: total_count,
  5111. Price: 0,
  5112. TotalPrice: 0,
  5113. Status: 1,
  5114. Ctime: item.AdviceDate,
  5115. Mtime: item.AdviceDate,
  5116. Remark: "",
  5117. OrgId: item.UserOrgId,
  5118. Type: 0,
  5119. Manufacturer: selfBasedrug.Manufacturer,
  5120. Dealer: selfBasedrug.Dealer,
  5121. RetailPrice: 0,
  5122. RetailTotalPrice: 0,
  5123. CountUnit: selfBasedrug.MinUnit,
  5124. ExpiryDate: 0,
  5125. ProductDate: 0,
  5126. Number: "",
  5127. BatchNumber: "",
  5128. IsSys: 1,
  5129. WarehouseInfoId: 0,
  5130. AdminUserId: 0,
  5131. StockCount: "",
  5132. IsCheck: 1,
  5133. SysRecordTime: item.AdviceDate,
  5134. PatientId: item.PatientId,
  5135. ClassType: "",
  5136. AdviceId: item.ID,
  5137. }
  5138. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5139. }
  5140. fmt.Println("长度-------------------------------", warehousingOutInfo)
  5141. for _, it := range warehousingOutInfo {
  5142. //查询今日是否有出库数据
  5143. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  5144. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5145. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5146. //出库逻辑
  5147. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  5148. //查询剩余库存
  5149. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5150. var sum_count int64
  5151. for _, its := range stockInfo {
  5152. if its.MaxUnit == medical.MaxUnit {
  5153. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5154. }
  5155. sum_count += its.StockMaxNumber + its.StockMinNumber
  5156. }
  5157. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5158. }
  5159. }
  5160. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5161. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5162. //耗材保存处方出库
  5163. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5164. //已收费和已发药限制逻辑
  5165. isCharge := false
  5166. isMedicine := false
  5167. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5168. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5169. if new_prescription.IsMedicine == 1 {
  5170. isMedicine = true
  5171. }
  5172. for _, item := range new_prescriptions {
  5173. if item.OrderStatus == 4 {
  5174. isCharge = true
  5175. }
  5176. }
  5177. if p_err != nil {
  5178. if new_prescription.ID > 0 {
  5179. if new_prescription.OrderStatus == 2 {
  5180. isCharge = true
  5181. }
  5182. }
  5183. }
  5184. for _, item := range advices {
  5185. if item.IsMedicine == 1 {
  5186. isMedicine = true
  5187. }
  5188. }
  5189. if isCharge {
  5190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5191. return
  5192. }
  5193. if isMedicine {
  5194. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5195. return
  5196. }
  5197. //已收费和已发药限制逻辑
  5198. if len(projects) > 0 {
  5199. for _, item := range projects {
  5200. service.DeletePrintInfo(item.ID) //删除打印信息
  5201. if goodOutConfig.IsOpen != 1 {
  5202. if stockConfig.IsOpen == 1 {
  5203. if item.Type == 3 && item.IsOut == 1 {
  5204. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5205. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5206. good.Total = good.Total + f_count
  5207. service.UpdateGoodInfo(&good)
  5208. operation_time := time.Now().Unix()
  5209. creater := c.GetAdminUserInfo().AdminUser.Id
  5210. //创建退库单
  5211. timeStr := time.Now().Format("2006-01-02")
  5212. timeArr := strings.Split(timeStr, "-")
  5213. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5214. total = total + 1
  5215. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5216. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5217. cancelStock := models.CancelStock{
  5218. OrderNumber: orderNumber,
  5219. OperaTime: operation_time,
  5220. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5221. Creater: creater,
  5222. Ctime: time.Now().Unix(),
  5223. Status: 1,
  5224. ReturnTime: item.RecordDate,
  5225. Type: 1,
  5226. StorehouseId: houseConfig.StorehouseOutInfo,
  5227. IsCheck: 1,
  5228. }
  5229. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5230. if msgerrkonde == gorm.ErrRecordNotFound {
  5231. service.AddSigleCancelStock(&cancelStock)
  5232. }
  5233. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5234. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5235. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5236. //查询该耗材是否出库
  5237. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5238. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5239. deaerler, _ := service.GetDealerById(info.Dealer)
  5240. var total_count int64
  5241. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5242. total_count += count
  5243. if info.ID > 0 {
  5244. if info.Count >= total_count {
  5245. //回退库存
  5246. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5247. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5248. var flush_count int64
  5249. for _, it := range goodList {
  5250. flush_count += it.StockCount
  5251. }
  5252. cancelStockInfo := models.CancelStockInfo{
  5253. GoodId: item.ProjectId,
  5254. CancelStockId: cancel.ID,
  5255. GoodTypeId: good.GoodTypeId,
  5256. Count: prescribingNumber,
  5257. Price: info.Price,
  5258. Total: 0,
  5259. ProductDate: info.ProductDate,
  5260. ExpiryDate: info.ExpiryDate,
  5261. Ctime: time.Now().Unix(),
  5262. Status: 1,
  5263. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5264. OrderNumber: cancel.OrderNumber,
  5265. Type: 0,
  5266. Dealer: deaerler.DealerName,
  5267. Manufacturer: manufacturer.ManufacturerName,
  5268. Number: info.Number,
  5269. RegisterAccount: "",
  5270. Remark: "",
  5271. WarehouseInfoId: info.WarehouseInfotId,
  5272. PatientId: info.PatientId,
  5273. RecordDate: info.SysRecordTime,
  5274. StorehouseId: houseConfig.StorehouseOutInfo,
  5275. IsCheck: 1,
  5276. }
  5277. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5278. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5279. flow := models.VmStockFlow{
  5280. WarehousingId: info.WarehouseInfotId,
  5281. GoodId: item.ProjectId,
  5282. Number: info.Number,
  5283. LicenseNumber: info.LicenseNumber,
  5284. Count: prescribingNumber,
  5285. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5286. PatientId: item.PatientId,
  5287. SystemTime: info.SysRecordTime,
  5288. ConsumableType: 7,
  5289. IsSys: 0,
  5290. WarehousingOrder: "",
  5291. WarehouseOutId: info.WarehouseOutId,
  5292. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5293. IsEdit: 0,
  5294. CancelStockId: cancel.ID,
  5295. CancelOrderNumber: cancel.OrderNumber,
  5296. Manufacturer: manufacturer.ID,
  5297. Dealer: 0,
  5298. Creator: c.GetAdminUserInfo().CurrentOrgId,
  5299. UpdateCreator: 0,
  5300. Status: 1,
  5301. Ctime: time.Now().Unix(),
  5302. Mtime: 0,
  5303. Price: info.Price,
  5304. WarehousingDetailId: info.WarehouseInfotId,
  5305. WarehouseOutDetailId: info.ID,
  5306. CancelOutDetailId: cancelInfo.ID,
  5307. ProductDate: info.ProductDate,
  5308. ExpireDate: info.ExpiryDate,
  5309. StorehouseId: houseConfig.StorehouseOutInfo,
  5310. OverCount: flush_count,
  5311. OperateTime: time.Now().Unix(),
  5312. }
  5313. service.CreateStockFlowOne(flow)
  5314. //退库数量增加
  5315. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  5316. //出库数量减少
  5317. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  5318. }
  5319. if info.Count < total_count {
  5320. //回退库存
  5321. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5322. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5323. var flush_count int64
  5324. for _, it := range goodList {
  5325. flush_count += it.StockCount
  5326. }
  5327. cancelStockInfo := models.CancelStockInfo{
  5328. GoodId: item.ProjectId,
  5329. CancelStockId: cancel.ID,
  5330. GoodTypeId: good.GoodTypeId,
  5331. Count: info.Count,
  5332. Price: info.Price,
  5333. Total: 0,
  5334. ProductDate: info.ProductDate,
  5335. ExpiryDate: info.ExpiryDate,
  5336. Ctime: time.Now().Unix(),
  5337. Status: 1,
  5338. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5339. OrderNumber: cancel.OrderNumber,
  5340. Type: 0,
  5341. Dealer: deaerler.DealerName,
  5342. Manufacturer: manufacturer.ManufacturerName,
  5343. Number: info.Number,
  5344. RegisterAccount: "",
  5345. Remark: "",
  5346. WarehouseInfoId: info.WarehouseInfotId,
  5347. PatientId: info.PatientId,
  5348. RecordDate: info.SysRecordTime,
  5349. StorehouseId: houseConfig.StorehouseOutInfo,
  5350. IsCheck: 1,
  5351. }
  5352. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5353. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5354. flow := models.VmStockFlow{
  5355. WarehousingId: info.WarehouseInfotId,
  5356. GoodId: item.ProjectId,
  5357. Number: info.Number,
  5358. LicenseNumber: info.LicenseNumber,
  5359. Count: info.Count,
  5360. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5361. PatientId: item.PatientId,
  5362. SystemTime: info.SysRecordTime,
  5363. ConsumableType: 7,
  5364. IsSys: 0,
  5365. WarehousingOrder: "",
  5366. WarehouseOutId: info.WarehouseOutId,
  5367. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5368. IsEdit: 0,
  5369. CancelStockId: cancel.ID,
  5370. CancelOrderNumber: cancel.OrderNumber,
  5371. Manufacturer: manufacturer.ID,
  5372. Dealer: 0,
  5373. Creator: c.GetAdminUserInfo().CurrentOrgId,
  5374. UpdateCreator: 0,
  5375. Status: 1,
  5376. Ctime: time.Now().Unix(),
  5377. Mtime: 0,
  5378. Price: info.Price,
  5379. WarehousingDetailId: info.WarehouseInfotId,
  5380. WarehouseOutDetailId: info.ID,
  5381. CancelOutDetailId: cancelInfo.ID,
  5382. ProductDate: info.ProductDate,
  5383. ExpireDate: info.ExpiryDate,
  5384. StorehouseId: houseConfig.StorehouseOutInfo,
  5385. OverCount: flush_count,
  5386. OperateTime: time.Now().Unix(),
  5387. }
  5388. service.CreateStockFlowOne(flow)
  5389. //退库数量增加
  5390. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  5391. //出库数量减少
  5392. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  5393. }
  5394. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5395. var flush_count int64
  5396. for _, it := range goodList {
  5397. flush_count += it.StockCount
  5398. }
  5399. //查询已出库数量
  5400. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  5401. if prescribingNumber < dialysisInfo.Count {
  5402. //改变数量
  5403. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  5404. }
  5405. if prescribingNumber >= dialysisInfo.Count {
  5406. //删除出库表
  5407. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  5408. }
  5409. //更新库存
  5410. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  5411. //更新基础库库存
  5412. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  5413. }
  5414. }
  5415. }
  5416. }
  5417. //保存耗材出库
  5418. if goodOutConfig.IsOpen == 1 {
  5419. if item.Type == 3 {
  5420. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5421. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5422. good.Total = good.Total + f_count
  5423. service.UpdateGoodInfo(&good)
  5424. operation_time := time.Now().Unix()
  5425. creater := c.GetAdminUserInfo().AdminUser.Id
  5426. //创建退库单
  5427. timeStr := time.Now().Format("2006-01-02")
  5428. timeArr := strings.Split(timeStr, "-")
  5429. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5430. total = total + 1
  5431. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5432. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5433. cancelStock := models.CancelStock{
  5434. OrderNumber: orderNumber,
  5435. OperaTime: operation_time,
  5436. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5437. Creater: creater,
  5438. Ctime: time.Now().Unix(),
  5439. Status: 1,
  5440. ReturnTime: item.RecordDate,
  5441. Type: 1,
  5442. StorehouseId: houseConfig.StorehouseOutInfo,
  5443. IsCheck: 1,
  5444. }
  5445. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5446. if msgerrkonde == gorm.ErrRecordNotFound {
  5447. service.AddSigleCancelStock(&cancelStock)
  5448. }
  5449. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5450. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5451. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5452. //查询该耗材是否出库
  5453. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5454. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5455. deaerler, _ := service.GetDealerById(info.Dealer)
  5456. var total_count int64
  5457. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5458. total_count += count
  5459. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5460. var flush_count int64
  5461. for _, it := range goodList {
  5462. flush_count += it.StockCount
  5463. }
  5464. fmt.Println("历史出库数据", info.Count)
  5465. fmt.Println("出库数量", total_count)
  5466. if info.ID > 0 {
  5467. cancelStockInfo := models.CancelStockInfo{
  5468. GoodId: item.ProjectId,
  5469. CancelStockId: cancel.ID,
  5470. GoodTypeId: good.GoodTypeId,
  5471. Count: prescribingNumber,
  5472. Price: info.Price,
  5473. Total: 0,
  5474. ProductDate: info.ProductDate,
  5475. ExpiryDate: info.ExpiryDate,
  5476. Ctime: time.Now().Unix(),
  5477. Status: 1,
  5478. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5479. OrderNumber: cancel.OrderNumber,
  5480. Type: 0,
  5481. Dealer: deaerler.DealerName,
  5482. Manufacturer: manufacturer.ManufacturerName,
  5483. Number: info.Number,
  5484. RegisterAccount: "",
  5485. Remark: "",
  5486. WarehouseInfoId: info.WarehouseInfotId,
  5487. PatientId: info.PatientId,
  5488. RecordDate: info.SysRecordTime,
  5489. StorehouseId: houseConfig.StorehouseOutInfo,
  5490. IsCheck: 1,
  5491. }
  5492. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5493. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5494. //查询出库数量
  5495. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  5496. //出库数据 大于 退库数量
  5497. if len(list) > 0 {
  5498. for _, it := range list {
  5499. //回退库存
  5500. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  5501. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5502. var flush_count_one int64
  5503. for _, it := range goodList {
  5504. flush_count_one += it.StockCount
  5505. }
  5506. //查询该批次是否有退库数据
  5507. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  5508. creater := c.GetAdminUserInfo().AdminUser.Id
  5509. flow := models.VmStockFlow{
  5510. WarehousingId: it.WarehouseInfotId,
  5511. GoodId: it.GoodId,
  5512. Number: it.Number,
  5513. LicenseNumber: it.LicenseNumber,
  5514. Count: it.Count,
  5515. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5516. PatientId: it.PatientId,
  5517. SystemTime: it.SysRecordTime,
  5518. ConsumableType: 7,
  5519. IsSys: 0,
  5520. WarehousingOrder: "",
  5521. WarehouseOutId: it.WarehouseOutId,
  5522. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  5523. IsEdit: 0,
  5524. CancelStockId: cancel.ID,
  5525. CancelOrderNumber: cancel.OrderNumber,
  5526. Manufacturer: manufacturer.ID,
  5527. Dealer: 0,
  5528. Creator: creater,
  5529. UpdateCreator: 0,
  5530. Status: 1,
  5531. Ctime: time.Now().Unix(),
  5532. Mtime: 0,
  5533. Price: it.Price,
  5534. WarehousingDetailId: it.WarehouseInfotId,
  5535. WarehouseOutDetailId: it.ID,
  5536. CancelOutDetailId: cancelInfo.ID,
  5537. ProductDate: it.ProductDate,
  5538. ExpireDate: it.ExpiryDate,
  5539. StorehouseId: houseConfig.StorehouseOutInfo,
  5540. OverCount: flush_count_one,
  5541. }
  5542. service.CreateStockFlowOne(flow)
  5543. //if flow.ID > 0 {
  5544. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  5545. //}
  5546. }
  5547. }
  5548. //flow := models.VmStockFlow{
  5549. // WarehousingId: info.WarehouseInfotId,
  5550. // GoodId: item.ProjectId,
  5551. // Number: info.Number,
  5552. // LicenseNumber: info.LicenseNumber,
  5553. // Count: prescribingNumber,
  5554. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5555. // PatientId: item.PatientId,
  5556. // SystemTime: info.SysRecordTime,
  5557. // ConsumableType: 7,
  5558. // IsSys: 0,
  5559. // WarehousingOrder: "",
  5560. // WarehouseOutId: info.WarehouseOutId,
  5561. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5562. // IsEdit: 0,
  5563. // CancelStockId: cancel.ID,
  5564. // CancelOrderNumber: cancel.OrderNumber,
  5565. // Manufacturer: manufacturer.ID,
  5566. // Dealer: 0,
  5567. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  5568. // UpdateCreator: 0,
  5569. // Status: 1,
  5570. // Ctime: time.Now().Unix(),
  5571. // Mtime: 0,
  5572. // Price: info.Price,
  5573. // WarehousingDetailId: info.WarehouseInfotId,
  5574. // WarehouseOutDetailId: info.ID,
  5575. // CancelOutDetailId: cancelInfo.ID,
  5576. // ProductDate: info.ProductDate,
  5577. // ExpireDate: info.ExpiryDate,
  5578. // StorehouseId: houseConfig.StorehouseOutInfo,
  5579. // OverCount: flush_count,
  5580. //}
  5581. //service.CreateStockFlowOne(flow)
  5582. //退库数量增加
  5583. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  5584. //出库数量减少
  5585. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  5586. //查询已出库数量
  5587. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  5588. if prescribingNumber < dialysisInfo.Count {
  5589. //改变数量
  5590. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  5591. }
  5592. if prescribingNumber >= dialysisInfo.Count {
  5593. //删除出库表
  5594. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  5595. }
  5596. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5597. var flush_count_one int64
  5598. for _, it := range goodList {
  5599. flush_count_one += it.StockCount
  5600. }
  5601. //更新库存
  5602. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  5603. fmt.Println("msgerrkonde23332323", msgerrkonde)
  5604. //更新基础库库存
  5605. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  5606. }
  5607. }
  5608. }
  5609. }
  5610. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5611. fmt.Println(err)
  5612. }
  5613. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5614. fmt.Println(err)
  5615. if len(advices) > 0 {
  5616. for _, item := range advices {
  5617. redis := service.RedisClient()
  5618. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5619. redis.Set(keyFive, "", time.Second)
  5620. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5621. redis.Set(keyOne, "", time.Second)
  5622. redis.Close()
  5623. }
  5624. }
  5625. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5626. if len(advices) > 0 {
  5627. for _, item := range advices {
  5628. creater := c.GetAdminUserInfo().AdminUser.Id
  5629. service.DrugAutoAddCancelInfo(item, creater)
  5630. }
  5631. }
  5632. } else {
  5633. if drugOutConfig.IsOpen == 1 {
  5634. if len(advices) > 0 {
  5635. for _, item := range advices {
  5636. creater := c.GetAdminUserInfo().AdminUser.Id
  5637. service.DrugAutoAddCancelInfo(item, creater)
  5638. }
  5639. }
  5640. } else {
  5641. if len(advices) > 0 {
  5642. for _, item := range advices {
  5643. creater := c.GetAdminUserInfo().AdminUser.Id
  5644. service.DrugAutoAddCancelInfo(item, creater)
  5645. }
  5646. }
  5647. }
  5648. }
  5649. c.ServeSuccessJSON(map[string]interface{}{
  5650. "msg": "删除成功",
  5651. })
  5652. return
  5653. }
  5654. func (c *HisApiController) DeleteDoctorAdvice() {
  5655. id, _ := c.GetInt64("id")
  5656. advice, _ := service.GetHisDoctorAdvicesById(id)
  5657. ////同步到自备药
  5658. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  5659. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  5660. if selfPrescriptionOpen.IsOpen == 1 {
  5661. db := service.XTWriteDB()
  5662. tx := db.Begin()
  5663. defer func() {
  5664. if r := recover(); r != nil {
  5665. tx.Rollback()
  5666. } else {
  5667. tx.Commit()
  5668. }
  5669. }()
  5670. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  5671. var total_count int64
  5672. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  5673. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5674. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5675. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5676. }
  5677. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5678. total_count += prescribingNumberSeven
  5679. }
  5680. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5681. total_count += prescribingNumberSeven
  5682. }
  5683. timeStr := time.Now().Format("2006-01-02")
  5684. timeArr := strings.Split(timeStr, "-")
  5685. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5686. total = total + 1
  5687. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5688. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5689. number = number + total
  5690. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5691. operation_time := time.Now().Unix()
  5692. creater := c.GetAdminUserInfo().AdminUser.Id
  5693. //创建一个出库单
  5694. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5695. WarehouseOutOrderNumber: warehousing_out_order,
  5696. OperationTime: operation_time,
  5697. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5698. Creater: creater,
  5699. Ctime: time.Now().Unix(),
  5700. Status: 1,
  5701. WarehouseOutTime: advice.AdviceDate,
  5702. Type: 0,
  5703. PatientId: advice.PatientId,
  5704. IsCheck: 1,
  5705. }
  5706. //查询今日是否有出库数据
  5707. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  5708. if lastWarehouseOut.ID == 0 {
  5709. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5710. }
  5711. //出库
  5712. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5713. WarehouseOutId: lastWarehouseOut.ID,
  5714. WarehouseOutOrderNumber: warehousing_out_order,
  5715. DrugId: advice.DrugId,
  5716. Count: total_count,
  5717. Price: 0,
  5718. TotalPrice: 0,
  5719. Status: 1,
  5720. Ctime: advice.AdviceDate,
  5721. Mtime: advice.AdviceDate,
  5722. Remark: "",
  5723. OrgId: advice.UserOrgId,
  5724. Type: 0,
  5725. Manufacturer: selfBasedrug.Manufacturer,
  5726. Dealer: selfBasedrug.Dealer,
  5727. RetailPrice: 0,
  5728. RetailTotalPrice: 0,
  5729. CountUnit: advice.PrescribingNumberUnit,
  5730. ExpiryDate: 0,
  5731. ProductDate: 0,
  5732. Number: "",
  5733. BatchNumber: "",
  5734. IsSys: 0,
  5735. WarehouseInfoId: 0,
  5736. AdminUserId: 0,
  5737. StockCount: "",
  5738. IsCheck: 1,
  5739. SysRecordTime: advice.AdviceDate,
  5740. PatientId: advice.PatientId,
  5741. AdviceId: advice.ID,
  5742. ClassType: "",
  5743. }
  5744. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5745. for _, it := range warehousingOutInfo {
  5746. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5747. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5748. //出库逻辑
  5749. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  5750. //查询剩余库存
  5751. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5752. var sum_count int64
  5753. for _, its := range stockInfo {
  5754. if its.MaxUnit == medical.MaxUnit {
  5755. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5756. }
  5757. sum_count += its.StockMaxNumber + its.StockMinNumber
  5758. }
  5759. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5760. }
  5761. }
  5762. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5763. //已收费和已发药的限制逻辑
  5764. isCharge := false
  5765. isMedicine := false
  5766. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5767. //获取今天该患者所有处方,判断是否发药或者收费
  5768. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5769. //for _, item := range new_prescriptions {
  5770. if new_prescription.IsMedicine == 1 {
  5771. isMedicine = true
  5772. }
  5773. //}
  5774. for _, item := range new_prescriptions {
  5775. if item.OrderStatus == 4 {
  5776. isCharge = true
  5777. }
  5778. }
  5779. if isMedicine {
  5780. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5781. return
  5782. }
  5783. if isCharge {
  5784. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5785. return
  5786. }
  5787. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  5788. for _, item := range advices {
  5789. if item.IsMedicine == 1 {
  5790. isMedicine = true
  5791. }
  5792. }
  5793. if isMedicine {
  5794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  5795. return
  5796. }
  5797. if new_prescription.ID > 0 {
  5798. if new_prescription.OrderStatus == 2 {
  5799. isCharge = true
  5800. }
  5801. }
  5802. if isCharge {
  5803. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5804. return
  5805. }
  5806. //已收费和已发药的限制逻辑
  5807. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  5808. redis := service.RedisClient()
  5809. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  5810. redis.Set(keyFive, "", time.Second)
  5811. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  5812. redis.Set(keyOne, "", time.Second)
  5813. defer redis.Close()
  5814. if err == nil {
  5815. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5816. //查询是否在处方中出库
  5817. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5818. if openConfig.IsOpen != 1 {
  5819. //判断该医嘱是否执行了
  5820. if advice.ExecutionState == 1 {
  5821. creater := c.GetAdminUserInfo().AdminUser.Id
  5822. service.DrugAutoAddCancelInfo(&advice, creater)
  5823. }
  5824. }
  5825. //开启保存处方扣减功能
  5826. if openConfig.IsOpen == 1 {
  5827. creater := c.GetAdminUserInfo().AdminUser.Id
  5828. service.DrugAutoAddCancelInfo(&advice, creater)
  5829. }
  5830. } else {
  5831. if drugOutConfig.IsOpen == 1 {
  5832. //查询是否在处方中出库
  5833. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5834. if openConfig.IsOpen != 1 {
  5835. //判断该医嘱是否执行了
  5836. if advice.ExecutionState == 1 {
  5837. creater := c.GetAdminUserInfo().AdminUser.Id
  5838. service.DrugAutoAddCancelInfo(&advice, creater)
  5839. }
  5840. }
  5841. //开启保存处方扣减功能
  5842. if openConfig.IsOpen == 1 {
  5843. creater := c.GetAdminUserInfo().AdminUser.Id
  5844. service.DrugAutoAddCancelInfo(&advice, creater)
  5845. }
  5846. } else {
  5847. //判断该医嘱是否执行了
  5848. if advice.ExecutionState == 1 {
  5849. creater := c.GetAdminUserInfo().AdminUser.Id
  5850. service.DrugAutoAddCancelInfo(&advice, creater)
  5851. }
  5852. }
  5853. }
  5854. c.ServeSuccessJSON(map[string]interface{}{
  5855. "msg": "删除成功",
  5856. })
  5857. return
  5858. } else {
  5859. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5860. return
  5861. }
  5862. }
  5863. func (c *HisApiController) DeleteProject() {
  5864. id, _ := c.GetInt64("id")
  5865. adminInfo := c.GetAdminUserInfo()
  5866. project, _ := service.GetHisProjectByID(id)
  5867. // var consumable models.DialysisBeforePrepare
  5868. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5869. //耗材保存处方出库
  5870. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5871. isCharge := false
  5872. isMedicine := false
  5873. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5874. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5875. for _, item := range new_prescriptions {
  5876. if item.IsMedicine == 1 {
  5877. isMedicine = true
  5878. }
  5879. }
  5880. for _, item := range new_prescriptions {
  5881. if item.OrderStatus == 4 {
  5882. isCharge = true
  5883. }
  5884. }
  5885. if isMedicine {
  5886. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5887. return
  5888. }
  5889. if isCharge {
  5890. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5891. return
  5892. }
  5893. if new_prescription.ID > 0 {
  5894. if new_prescription.OrderStatus == 2 {
  5895. isCharge = true
  5896. }
  5897. }
  5898. if isCharge {
  5899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5900. return
  5901. }
  5902. service.DeletePrintInfo(id)
  5903. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  5904. label.Status = 0
  5905. service.CreateHisLabelRecordTwo(&label)
  5906. fmt.Println(goodOutConfig.IsOpen)
  5907. if goodOutConfig.IsOpen != 1 {
  5908. if stockConfig.IsOpen == 1 {
  5909. if project.Type == 2 {
  5910. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5911. fmt.Println(err)
  5912. }
  5913. if project.Type == 3 && project.IsOut == 1 {
  5914. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5915. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5916. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5917. operation_time := time.Now().Unix()
  5918. creater := adminInfo.AdminUser.Id
  5919. //创建退库单
  5920. timeStr := time.Now().Format("2006-01-02")
  5921. timeArr := strings.Split(timeStr, "-")
  5922. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5923. total = total + 1
  5924. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5925. cancelStock := models.CancelStock{
  5926. OrderNumber: orderNumber,
  5927. OperaTime: operation_time,
  5928. OrgId: adminInfo.CurrentOrgId,
  5929. Creater: creater,
  5930. Ctime: time.Now().Unix(),
  5931. Status: 1,
  5932. ReturnTime: project.RecordDate,
  5933. Type: 1,
  5934. StorehouseId: houseConfig.StorehouseOutInfo,
  5935. IsCheck: 1,
  5936. }
  5937. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5938. if msgerrkonde == gorm.ErrRecordNotFound {
  5939. service.AddSigleCancelStock(&cancelStock)
  5940. }
  5941. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5942. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5943. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5944. //查询是否有出库
  5945. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5946. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5947. deaerler, _ := service.GetDealerById(info.Dealer)
  5948. if info.ID > 0 {
  5949. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5950. if info.Count >= prescribingNumber {
  5951. cancelStockInfo := models.CancelStockInfo{
  5952. GoodId: project.ProjectId,
  5953. CancelStockId: cancel.ID,
  5954. GoodTypeId: good.GoodTypeId,
  5955. Count: prescribingNumber,
  5956. Price: info.Price,
  5957. Total: 0,
  5958. ProductDate: info.ProductDate,
  5959. ExpiryDate: info.ExpiryDate,
  5960. Ctime: time.Now().Unix(),
  5961. Status: 1,
  5962. OrgId: adminInfo.CurrentOrgId,
  5963. OrderNumber: cancel.OrderNumber,
  5964. Type: 0,
  5965. Dealer: deaerler.DealerName,
  5966. Manufacturer: manufacturer.ManufacturerName,
  5967. Number: info.Number,
  5968. RegisterAccount: "",
  5969. Remark: "",
  5970. WarehouseInfoId: info.WarehouseInfotId,
  5971. PatientId: info.PatientId,
  5972. RecordDate: info.SysRecordTime,
  5973. StorehouseId: houseConfig.StorehouseOutInfo,
  5974. IsCheck: 1,
  5975. }
  5976. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5977. //回退库存
  5978. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  5979. //退库数量增加
  5980. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5981. //出库数量减少
  5982. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5983. }
  5984. if info.Count < prescribingNumber {
  5985. cancelStockInfo := models.CancelStockInfo{
  5986. GoodId: project.ProjectId,
  5987. CancelStockId: cancel.ID,
  5988. GoodTypeId: good.GoodTypeId,
  5989. Count: info.Count,
  5990. Price: info.Price,
  5991. Total: 0,
  5992. ProductDate: info.ProductDate,
  5993. ExpiryDate: info.ExpiryDate,
  5994. Ctime: time.Now().Unix(),
  5995. Status: 1,
  5996. OrgId: adminInfo.CurrentOrgId,
  5997. OrderNumber: cancel.OrderNumber,
  5998. Type: 0,
  5999. Dealer: deaerler.DealerName,
  6000. Manufacturer: manufacturer.ManufacturerName,
  6001. Number: info.Number,
  6002. RegisterAccount: "",
  6003. Remark: "",
  6004. WarehouseInfoId: info.WarehouseInfotId,
  6005. PatientId: info.PatientId,
  6006. RecordDate: info.SysRecordTime,
  6007. StorehouseId: houseConfig.StorehouseOutInfo,
  6008. IsCheck: 1,
  6009. }
  6010. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6011. //回退库存
  6012. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6013. //退库数量增加
  6014. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6015. //出库数量减少
  6016. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  6017. }
  6018. //查询剩余库存
  6019. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6020. var over_count int64
  6021. for _, it := range goodList {
  6022. over_count += it.StockCount
  6023. }
  6024. //出库数据 大于 退库数量
  6025. if info.Count >= prescribingNumber {
  6026. flow := models.VmStockFlow{
  6027. WarehousingId: info.WarehouseInfotId,
  6028. GoodId: project.ProjectId,
  6029. Number: info.Number,
  6030. LicenseNumber: info.LicenseNumber,
  6031. Count: prescribingNumber,
  6032. UserOrgId: adminInfo.CurrentOrgId,
  6033. PatientId: project.PatientId,
  6034. SystemTime: info.SysRecordTime,
  6035. ConsumableType: 7,
  6036. IsSys: 0,
  6037. WarehousingOrder: "",
  6038. WarehouseOutId: info.WarehouseOutId,
  6039. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6040. IsEdit: 0,
  6041. CancelStockId: cancel.ID,
  6042. CancelOrderNumber: cancel.OrderNumber,
  6043. Manufacturer: manufacturer.ID,
  6044. Dealer: 0,
  6045. Creator: adminInfo.AdminUser.Id,
  6046. UpdateCreator: 0,
  6047. Status: 1,
  6048. Ctime: time.Now().Unix(),
  6049. Mtime: 0,
  6050. Price: info.Price,
  6051. WarehousingDetailId: info.WarehouseInfotId,
  6052. WarehouseOutDetailId: info.ID,
  6053. CancelOutDetailId: cancelInfo.ID,
  6054. ProductDate: info.ProductDate,
  6055. ExpireDate: info.ExpiryDate,
  6056. StorehouseId: houseConfig.StorehouseOutInfo,
  6057. OverCount: over_count,
  6058. OperateTime: time.Now().Unix(),
  6059. }
  6060. service.CreateStockFlowOne(flow)
  6061. }
  6062. //出库数据小于退库数据
  6063. if info.Count < prescribingNumber {
  6064. flow := models.VmStockFlow{
  6065. WarehousingId: info.WarehouseInfotId,
  6066. GoodId: project.ProjectId,
  6067. Number: info.Number,
  6068. LicenseNumber: info.LicenseNumber,
  6069. Count: info.Count,
  6070. UserOrgId: adminInfo.CurrentOrgId,
  6071. PatientId: project.PatientId,
  6072. SystemTime: info.SysRecordTime,
  6073. ConsumableType: 7,
  6074. IsSys: 0,
  6075. WarehousingOrder: "",
  6076. WarehouseOutId: info.WarehouseOutId,
  6077. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6078. IsEdit: 0,
  6079. CancelStockId: cancel.ID,
  6080. CancelOrderNumber: cancel.OrderNumber,
  6081. Manufacturer: manufacturer.ID,
  6082. Dealer: 0,
  6083. Creator: adminInfo.AdminUser.Id,
  6084. UpdateCreator: 0,
  6085. Status: 1,
  6086. Ctime: time.Now().Unix(),
  6087. Mtime: 0,
  6088. Price: info.Price,
  6089. WarehousingDetailId: info.WarehouseInfotId,
  6090. WarehouseOutDetailId: info.ID,
  6091. CancelOutDetailId: cancelInfo.ID,
  6092. ProductDate: info.ProductDate,
  6093. ExpireDate: info.ExpiryDate,
  6094. StorehouseId: houseConfig.StorehouseOutInfo,
  6095. OverCount: over_count,
  6096. OperateTime: time.Now().Unix(),
  6097. }
  6098. service.CreateStockFlowOne(flow)
  6099. }
  6100. //查询已出库数量
  6101. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6102. //fmt.Println("aiwohonguo --------------------", prescribingNumber)
  6103. //fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  6104. if prescribingNumber < dialysisInfo.Count {
  6105. //改变数量
  6106. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6107. }
  6108. if prescribingNumber >= dialysisInfo.Count {
  6109. //删除出库表
  6110. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6111. }
  6112. //更新剩余库存
  6113. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6114. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6115. var total_count_one int64
  6116. for _, it := range stockList {
  6117. total_count_one += it.StockCount
  6118. }
  6119. //基础库插入数据
  6120. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6121. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6122. var flush_count int64
  6123. for _, it := range goodListOne {
  6124. flush_count += it.StockCount
  6125. }
  6126. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6127. if errs != nil {
  6128. goodErrcode := models.XtGoodErrcode{
  6129. UserOrgId: project.UserOrgId,
  6130. Errcode: "手动出库更新剩余出库失败",
  6131. GoodId: project.ProjectId,
  6132. Status: 1,
  6133. Ctime: time.Now().Unix(),
  6134. Mtime: 0,
  6135. Count: 0,
  6136. StockCount: 0,
  6137. Creater: creater,
  6138. BatchNumberId: 0,
  6139. WarehouseOutId: 0,
  6140. }
  6141. service.CreateGoodErrcode(goodErrcode)
  6142. }
  6143. }
  6144. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6145. fmt.Println(err)
  6146. } else {
  6147. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6148. fmt.Println(err)
  6149. }
  6150. } else {
  6151. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6152. fmt.Println(err)
  6153. }
  6154. }
  6155. //保存处方出库
  6156. if goodOutConfig.IsOpen == 1 {
  6157. if project.Type == 3 {
  6158. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6159. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6160. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6161. operation_time := time.Now().Unix()
  6162. creater := adminInfo.AdminUser.Id
  6163. //创建退库单
  6164. timeStr := time.Now().Format("2006-01-02")
  6165. timeArr := strings.Split(timeStr, "-")
  6166. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6167. total = total + 1
  6168. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6169. cancelStock := models.CancelStock{
  6170. OrderNumber: orderNumber,
  6171. OperaTime: operation_time,
  6172. OrgId: adminInfo.CurrentOrgId,
  6173. Creater: creater,
  6174. Ctime: time.Now().Unix(),
  6175. Status: 1,
  6176. ReturnTime: project.RecordDate,
  6177. Type: 1,
  6178. StorehouseId: houseConfig.StorehouseOutInfo,
  6179. IsCheck: 1,
  6180. }
  6181. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6182. if msgerrkonde == gorm.ErrRecordNotFound {
  6183. service.AddSigleCancelStock(&cancelStock)
  6184. }
  6185. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6186. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6187. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6188. //获取出库数据
  6189. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6190. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6191. deaerler, _ := service.GetDealerById(info.Dealer)
  6192. if info.ID > 0 {
  6193. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6194. if info.Count >= prescribingNumber {
  6195. cancelStockInfo := models.CancelStockInfo{
  6196. GoodId: project.ProjectId,
  6197. CancelStockId: cancel.ID,
  6198. GoodTypeId: good.GoodTypeId,
  6199. Count: prescribingNumber,
  6200. Price: info.Price,
  6201. Total: 0,
  6202. ProductDate: info.ProductDate,
  6203. ExpiryDate: info.ExpiryDate,
  6204. Ctime: time.Now().Unix(),
  6205. Status: 1,
  6206. OrgId: adminInfo.CurrentOrgId,
  6207. OrderNumber: cancel.OrderNumber,
  6208. Type: 0,
  6209. Dealer: deaerler.DealerName,
  6210. Manufacturer: manufacturer.ManufacturerName,
  6211. Number: info.Number,
  6212. RegisterAccount: "",
  6213. Remark: "",
  6214. WarehouseInfoId: info.WarehouseInfotId,
  6215. PatientId: info.PatientId,
  6216. RecordDate: info.SysRecordTime,
  6217. StorehouseId: houseConfig.StorehouseOutInfo,
  6218. IsCheck: 1,
  6219. }
  6220. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6221. //退库数量增加
  6222. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6223. //出库数量减少
  6224. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6225. }
  6226. if info.Count < prescribingNumber {
  6227. cancelStockInfo := models.CancelStockInfo{
  6228. GoodId: project.ProjectId,
  6229. CancelStockId: cancel.ID,
  6230. GoodTypeId: good.GoodTypeId,
  6231. Count: prescribingNumber,
  6232. Price: info.Price,
  6233. Total: 0,
  6234. ProductDate: info.ProductDate,
  6235. ExpiryDate: info.ExpiryDate,
  6236. Ctime: time.Now().Unix(),
  6237. Status: 1,
  6238. OrgId: adminInfo.CurrentOrgId,
  6239. OrderNumber: cancel.OrderNumber,
  6240. Type: 0,
  6241. Dealer: deaerler.DealerName,
  6242. Manufacturer: manufacturer.ManufacturerName,
  6243. Number: info.Number,
  6244. RegisterAccount: "",
  6245. Remark: "",
  6246. WarehouseInfoId: info.WarehouseInfotId,
  6247. PatientId: info.PatientId,
  6248. RecordDate: info.SysRecordTime,
  6249. StorehouseId: houseConfig.StorehouseOutInfo,
  6250. IsCheck: 1,
  6251. }
  6252. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6253. //回退库存
  6254. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6255. }
  6256. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6257. var over_count int64
  6258. for _, it := range goodList {
  6259. over_count += it.StockCount
  6260. }
  6261. //查询出库数量
  6262. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  6263. //出库数据 大于 退库数量
  6264. if len(list) > 0 {
  6265. for _, it := range list {
  6266. //回退库存
  6267. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6268. //退库数量增加
  6269. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  6270. //出库数量减少
  6271. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  6272. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6273. var over_count_one int64
  6274. for _, it := range goodList {
  6275. over_count_one += it.StockCount
  6276. }
  6277. //查询该批次是否有退库数据
  6278. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  6279. flow := models.VmStockFlow{
  6280. WarehousingId: it.WarehouseInfotId,
  6281. GoodId: it.GoodId,
  6282. Number: it.Number,
  6283. LicenseNumber: it.LicenseNumber,
  6284. Count: it.Count,
  6285. UserOrgId: adminInfo.CurrentOrgId,
  6286. PatientId: it.PatientId,
  6287. SystemTime: it.SysRecordTime,
  6288. ConsumableType: 7,
  6289. IsSys: 0,
  6290. WarehousingOrder: "",
  6291. WarehouseOutId: it.WarehouseOutId,
  6292. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6293. IsEdit: 0,
  6294. CancelStockId: cancel.ID,
  6295. CancelOrderNumber: cancel.OrderNumber,
  6296. Manufacturer: manufacturer.ID,
  6297. Dealer: 0,
  6298. Creator: adminInfo.AdminUser.Id,
  6299. UpdateCreator: 0,
  6300. Status: 1,
  6301. Ctime: time.Now().Unix(),
  6302. Mtime: 0,
  6303. Price: it.Price,
  6304. WarehousingDetailId: it.WarehouseInfotId,
  6305. WarehouseOutDetailId: it.ID,
  6306. CancelOutDetailId: cancelInfo.ID,
  6307. ProductDate: it.ProductDate,
  6308. ExpireDate: it.ExpiryDate,
  6309. StorehouseId: houseConfig.StorehouseOutInfo,
  6310. OverCount: over_count_one,
  6311. OperateTime: time.Now().Unix(),
  6312. }
  6313. service.CreateStockFlowOne(flow)
  6314. }
  6315. }
  6316. //查询已出库数量
  6317. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6318. if prescribingNumber < dialysisInfo.Count {
  6319. //改变数量
  6320. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6321. }
  6322. if prescribingNumber >= dialysisInfo.Count {
  6323. //删除出库表
  6324. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6325. }
  6326. //更新剩余库存
  6327. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6328. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6329. var total_count_one int64
  6330. for _, it := range stockList {
  6331. total_count_one += it.StockCount
  6332. }
  6333. //基础库插入数据
  6334. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6335. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6336. var flush_count int64
  6337. for _, it := range goodListOne {
  6338. flush_count += it.StockCount
  6339. }
  6340. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6341. if errs != nil {
  6342. goodErrcode := models.XtGoodErrcode{
  6343. UserOrgId: project.UserOrgId,
  6344. Errcode: "手动出库更新剩余出库失败",
  6345. GoodId: project.ProjectId,
  6346. Status: 1,
  6347. Ctime: time.Now().Unix(),
  6348. Mtime: 0,
  6349. Count: 0,
  6350. StockCount: 0,
  6351. Creater: creater,
  6352. BatchNumberId: 0,
  6353. WarehouseOutId: 0,
  6354. }
  6355. service.CreateGoodErrcode(goodErrcode)
  6356. }
  6357. }
  6358. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6359. fmt.Println(err)
  6360. } else {
  6361. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6362. fmt.Println(err)
  6363. }
  6364. }
  6365. c.ServeSuccessJSON(map[string]interface{}{
  6366. "msg": "删除成功",
  6367. })
  6368. return
  6369. }
  6370. func (c *HisApiController) CreateHisAdditionalCharge() {
  6371. his_patient_id, _ := c.GetInt64("his_patient_id")
  6372. patient_id, _ := c.GetInt64("patient_id")
  6373. record_date := c.GetString("record_date")
  6374. timeLayout := "2006-01-02"
  6375. loc, _ := time.LoadLocation("Local")
  6376. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6377. if err != nil {
  6378. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6379. return
  6380. }
  6381. adminInfo := c.GetAdminUserInfo()
  6382. recordDateTime := theTime.Unix()
  6383. dataBody := make(map[string]interface{}, 0)
  6384. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6385. if err != nil {
  6386. utils.ErrorLog(err.Error())
  6387. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6388. return
  6389. }
  6390. var additions []*models.HisAdditionalCharge
  6391. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  6392. additions, _ := dataBody["addition"].([]interface{})
  6393. if len(additions) > 0 {
  6394. for _, item := range additions {
  6395. items := item.(map[string]interface{})
  6396. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  6397. utils.ErrorLog("item_id")
  6398. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6399. return
  6400. }
  6401. item_id := int64(items["item_id"].(float64))
  6402. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  6403. utils.ErrorLog("item_name")
  6404. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6405. return
  6406. }
  6407. item_name := items["item_name"].(string)
  6408. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  6409. utils.ErrorLog("price")
  6410. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6411. return
  6412. }
  6413. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  6414. ctime := time.Now().Unix()
  6415. additional := &models.HisAdditionalCharge{
  6416. PatientId: patient_id,
  6417. HisPatientId: his_patient_id,
  6418. UserOrgId: adminInfo.CurrentOrgId,
  6419. RecordDate: recordDateTime,
  6420. CreatedTime: ctime,
  6421. UpdatedTime: ctime,
  6422. Modifier: adminInfo.AdminUser.Id,
  6423. Creator: adminInfo.AdminUser.Id,
  6424. Price: price,
  6425. ItemName: item_name,
  6426. ItemId: item_id,
  6427. Status: 1,
  6428. }
  6429. additions = append(additions, additional)
  6430. }
  6431. }
  6432. }
  6433. for _, item := range additions {
  6434. service.CreateAddtionalCharge(item)
  6435. }
  6436. c.ServeSuccessJSON(map[string]interface{}{
  6437. "msg": "创建成功",
  6438. })
  6439. }
  6440. func (c *HisApiController) CreateHisPatientCaseHistory() {
  6441. blood_fat := c.GetString("blood_fat")
  6442. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  6443. blood_sugar := c.GetString("blood_sugar")
  6444. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  6445. chief_conplaint := c.GetString("chief_conplaint")
  6446. dbp := c.GetString("dbp")
  6447. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  6448. delivery_way, _ := c.GetInt64("delivery_way")
  6449. diagnostic := c.GetString("diagnostic")
  6450. family_history := c.GetString("family_history")
  6451. height := c.GetString("height")
  6452. history_of_present_illness := c.GetString("history_of_present_illness")
  6453. is_infect, _ := c.GetInt64("is_infect")
  6454. past_history := c.GetString("past_history")
  6455. patient_id, _ := c.GetInt64("patient_id")
  6456. his_patient_id, _ := c.GetInt64("his_patient_id")
  6457. personal_history := c.GetString("personal_history")
  6458. pulse := c.GetString("pulse")
  6459. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  6460. sbp := c.GetString("sbp")
  6461. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  6462. heightfloat, _ := strconv.ParseFloat(height, 64)
  6463. sicktype := c.GetString("sick_type")
  6464. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  6465. symptom := c.GetString("symptom")
  6466. sick_date := c.GetString("sick_date")
  6467. temperatures := c.GetString("temperature")
  6468. temperature, _ := strconv.ParseFloat(temperatures, 64)
  6469. record_date := c.GetString("record_date")
  6470. breathing := c.GetString("breathing")
  6471. doctor_advice := c.GetString("doctor_advice")
  6472. remark := c.GetString("remark")
  6473. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  6474. sick, _ := c.GetInt64("sick")
  6475. diagnose, _ := c.GetInt64("diagnose")
  6476. //id, _ := c.GetInt64("id")
  6477. timeLayout := "2006-01-02"
  6478. loc, _ := time.LoadLocation("Local")
  6479. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6480. allergic_history := c.GetString("allergic_history")
  6481. if err != nil {
  6482. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6483. return
  6484. }
  6485. recordDateTime := theTime.Unix()
  6486. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  6487. if err != nil {
  6488. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6489. return
  6490. }
  6491. sickTimes := sickTime.Unix()
  6492. ctime := time.Now().Unix()
  6493. primary_disease := c.GetString("primary_disease")
  6494. confirm_failure_date := c.GetString("confirm_failure_date")
  6495. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  6496. drug_allergy_history := c.GetString("drug_allergy_history")
  6497. physical_examination := c.GetString("physical_examination")
  6498. special_inspection := c.GetString("special_inspection")
  6499. lab_apparatus := c.GetString("lab_apparatus")
  6500. caseHistory := models.HisPatientCaseHistory{
  6501. HisPatientId: his_patient_id,
  6502. PatientId: patient_id,
  6503. Temperature: temperature,
  6504. BloodSugar: bloodsugarfloat,
  6505. Pulse: pulsefloat,
  6506. Sbp: sbpfloat,
  6507. Dbp: dbpfloat,
  6508. Height: heightfloat,
  6509. BloodFat: bloodfatfloat,
  6510. SickType: sick_type,
  6511. Symptom: symptom,
  6512. SickDate: sickTimes,
  6513. IsInfect: is_infect,
  6514. HistoryOfPresentIllness: history_of_present_illness,
  6515. PastHistory: past_history,
  6516. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  6517. ChiefConplaint: chief_conplaint,
  6518. PersonalHistory: personal_history,
  6519. FamilyHistory: family_history,
  6520. Diagnostic: diagnostic,
  6521. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6522. Status: 1,
  6523. Ctime: ctime,
  6524. Mtime: ctime,
  6525. RecordDate: recordDateTime,
  6526. DeliveryWay: delivery_way,
  6527. Breathing: breathingfloat,
  6528. DoctorAdvice: doctor_advice,
  6529. Remark: remark,
  6530. Sick: sick,
  6531. Diagnose: diagnose,
  6532. AllergicHistory: allergic_history,
  6533. PrimaryDisease: primary_disease,
  6534. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  6535. DrugAllergyHistory: drug_allergy_history,
  6536. PhysicalExamination: physical_examination,
  6537. SpecialInspection: special_inspection,
  6538. LabApparatus: lab_apparatus,
  6539. }
  6540. //查询该患者是否有病历
  6541. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  6542. if errcodes == gorm.ErrRecordNotFound {
  6543. err = service.SaveHisPatientCaseHistory(&caseHistory)
  6544. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  6545. if err != nil {
  6546. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6547. return
  6548. }
  6549. c.ServeSuccessJSON(map[string]interface{}{
  6550. "caseHistory": caseHistory,
  6551. "historyInfo": historyInfo,
  6552. })
  6553. return
  6554. } else if errcodes == nil {
  6555. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  6556. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  6557. if err != nil {
  6558. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6559. return
  6560. }
  6561. c.ServeSuccessJSON(map[string]interface{}{
  6562. "caseHistory": caseHistory,
  6563. "historyInfo": historyInfo,
  6564. })
  6565. }
  6566. //查询该患者是否有病历
  6567. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  6568. //if errcode == gorm.ErrRecordNotFound {
  6569. // err = service.SaveHisPatientCaseHistory(caseHistory)
  6570. // if err != nil {
  6571. // c.ServeSuccessJSON(map[string]interface{}{
  6572. // "msg": "保存成功",
  6573. // })
  6574. // }
  6575. //} else if errcode == nil {
  6576. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6577. // return
  6578. //}
  6579. }
  6580. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  6581. patient_id, _ := c.GetInt64("patient_id", 0)
  6582. adminUser := c.GetAdminUserInfo()
  6583. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  6584. c.ServeSuccessJSON(map[string]interface{}{
  6585. "list": caseHistorys,
  6586. })
  6587. }
  6588. func (c *HisApiController) GetHisPatientCaseHistory() {
  6589. record_date, _ := c.GetInt64("record_date", 0)
  6590. patient_id, _ := c.GetInt64("patient_id", 0)
  6591. admin := c.GetAdminUserInfo()
  6592. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  6593. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  6594. c.ServeSuccessJSON(map[string]interface{}{
  6595. "info": info,
  6596. "case_history": case_history,
  6597. })
  6598. }
  6599. func (c *HisApiController) CreateCaseHistoryTemplate() {
  6600. template_name := c.GetString("template_name")
  6601. template_remark := c.GetString("template_remark")
  6602. doctor := c.GetAdminUserInfo().AdminUser.Id
  6603. diagnostic := c.GetString("diagnostic")
  6604. chief_conplaint := c.GetString("chief_conplain")
  6605. history_of_present_illness := c.GetString("history_of_present_illness")
  6606. past_history := c.GetString("past_history")
  6607. personal_history := c.GetString("personal_history")
  6608. family_history := c.GetString("family_history")
  6609. user_name := c.GetString("user_name")
  6610. doctor_advice := c.GetString("doctor_advice")
  6611. remark := c.GetString("remark")
  6612. //record_date := c.GetString("record_date")
  6613. //fmt.Println("record_date--------",record_date)
  6614. //timeLayout := "2006-01-02"
  6615. //loc, _ := time.LoadLocation("Local")
  6616. //
  6617. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6618. //if err != nil {
  6619. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6620. // return
  6621. //}
  6622. //recordDateTime := theTime.Unix()
  6623. ctime := time.Now().Unix()
  6624. template := models.HisCaseHistoryTemplate{
  6625. HistoryOfPresentIllness: history_of_present_illness,
  6626. PastHistory: past_history,
  6627. ChiefConplaint: chief_conplaint,
  6628. PersonalHistory: personal_history,
  6629. FamilyHistory: family_history,
  6630. Diagnostic: diagnostic,
  6631. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6632. Status: 1,
  6633. Ctime: ctime,
  6634. Mtime: ctime,
  6635. RecordDate: time.Now().Unix(),
  6636. TemplateName: template_name,
  6637. TemplateRemark: template_remark,
  6638. Creator: doctor,
  6639. Modifier: doctor,
  6640. UserName: user_name,
  6641. DoctorAdvice: doctor_advice,
  6642. Remark: remark,
  6643. }
  6644. err := service.SaveHisPatientCaseHistoryTemplate(template)
  6645. if err == nil {
  6646. c.ServeSuccessJSON(map[string]interface{}{
  6647. "msg": "保存成功",
  6648. })
  6649. } else {
  6650. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6651. return
  6652. }
  6653. }
  6654. func (c *HisApiController) GetCaseHistoryTemplate() {
  6655. timeLayout := "2006-01-02"
  6656. loc, _ := time.LoadLocation("Local")
  6657. keyword := c.GetString("keyword")
  6658. start_time := c.GetString("start_time")
  6659. end_time := c.GetString("end_time")
  6660. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6661. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6662. admin := c.GetAdminUserInfo()
  6663. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  6664. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  6665. c.ServeSuccessJSON(map[string]interface{}{
  6666. "template": template,
  6667. //"history": history,
  6668. })
  6669. }
  6670. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6671. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6672. utils.ErrorLog("drug_name")
  6673. return enums.ErrorCodeParamWrong
  6674. }
  6675. adviceName, _ := json["drug_name"].(string)
  6676. if len(adviceName) == 0 {
  6677. utils.ErrorLog("len(advice_name) == 0")
  6678. return enums.ErrorCodeParamWrong
  6679. }
  6680. advice.AdviceName = adviceName
  6681. adviceDesc, _ := json["advice_desc"].(string)
  6682. advice.AdviceDesc = adviceDesc
  6683. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6684. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6685. advice.DrugSpec = drugSpec
  6686. }
  6687. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6688. remark, _ := json["remark"].(string)
  6689. advice.Remark = remark
  6690. }
  6691. if json["id"] == nil {
  6692. advice.DrugId = 0
  6693. } else {
  6694. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6695. drug_id := int64(json["id"].(float64))
  6696. advice.DrugId = drug_id
  6697. }
  6698. }
  6699. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6700. advice_id := int64(json["advice_id"].(float64))
  6701. advice.ID = advice_id
  6702. if advice.ID > 0 {
  6703. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6704. if err == nil {
  6705. if hisAdvice.ID > 0 {
  6706. advice.ExecutionTime = hisAdvice.ExecutionTime
  6707. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6708. advice.ExecutionState = hisAdvice.ExecutionState
  6709. advice.CheckTime = hisAdvice.CheckTime
  6710. advice.Checker = hisAdvice.Checker
  6711. advice.CheckState = hisAdvice.CheckState
  6712. advice.StartTime = hisAdvice.StartTime
  6713. advice.FeedetlSn = hisAdvice.FeedetlSn
  6714. }
  6715. }
  6716. }
  6717. }
  6718. //
  6719. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6720. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6721. // advice.ExecutionTime = execution_time
  6722. //}
  6723. //
  6724. //
  6725. //
  6726. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6727. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6728. // advice.ExecutionStaff = execution_staff
  6729. //}
  6730. //
  6731. //
  6732. //
  6733. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6734. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6735. // advice.ExecutionState = execution_state
  6736. //}
  6737. //
  6738. //
  6739. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6740. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6741. // advice.CheckTime = check_time
  6742. //}
  6743. //
  6744. //
  6745. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6746. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6747. // advice.CheckState = check_state
  6748. //}
  6749. //
  6750. //
  6751. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6752. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6753. // advice.Checker = checker
  6754. //}
  6755. //
  6756. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6757. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6758. // advice.StartTime = start_time
  6759. //}
  6760. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6761. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6762. advice.IsSelfDrug = is_self_drug
  6763. }
  6764. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6765. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6766. drug_way_count, _ := json["drug_way_count"].(string)
  6767. advice.DrugWayCount = drug_way_count
  6768. }
  6769. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6770. drugSpecUnit, _ := json["min_unit"].(string)
  6771. advice.DrugSpecUnit = drugSpecUnit
  6772. }
  6773. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6774. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6775. advice.SingleDose = singleDose
  6776. }
  6777. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6778. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6779. advice.SingleDoseUnit = singleDoseUnit
  6780. }
  6781. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6782. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6783. advice.PrescribingNumber = prescribingNumber
  6784. }
  6785. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6786. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6787. advice.PrescribingNumberUnit = prescribingNumberUnit
  6788. }
  6789. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6790. deliveryWay, _ := json["delivery_way"].(string)
  6791. advice.DeliveryWay = deliveryWay
  6792. }
  6793. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6794. executionFrequency, _ := json["execution_frequency"].(string)
  6795. advice.ExecutionFrequency = executionFrequency
  6796. }
  6797. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6798. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6799. advice.Price = price
  6800. }
  6801. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6802. med_list_codg, _ := json["medical_insurance_number"].(string)
  6803. advice.MedListCodg = med_list_codg
  6804. }
  6805. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6806. day := int64(json["day"].(float64))
  6807. advice.Day = day
  6808. }
  6809. return 0
  6810. }
  6811. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6812. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6813. id := int64(json["id"].(float64))
  6814. project.ID = id
  6815. historyProject, _ := service.GetHisProjectByID(id)
  6816. project.FeedetlSn = historyProject.FeedetlSn
  6817. }
  6818. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6819. project_id := int64(json["project_id"].(float64))
  6820. project.ProjectId = project_id
  6821. }
  6822. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6823. // price := int64(json["price"].(float64))
  6824. // formatInt_price := strconv.FormatInt(price, 10)
  6825. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6826. // project.Price = float_price
  6827. // }
  6828. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6829. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6830. project.Price = price
  6831. }
  6832. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6833. total, _ := json["total"].(string)
  6834. project.Count = total
  6835. }
  6836. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6837. medical_code, _ := json["medical_code"].(string)
  6838. project.MedListCodg = medical_code
  6839. }
  6840. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6841. single_dose, _ := json["single_dose"].(string)
  6842. project.SingleDose = single_dose
  6843. }
  6844. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6845. delivery_way, _ := json["delivery_way"].(string)
  6846. project.DeliveryWay = delivery_way
  6847. }
  6848. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6849. execution_frequency, _ := json["execution_frequency"].(string)
  6850. project.ExecutionFrequency = execution_frequency
  6851. }
  6852. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6853. remark, _ := json["remark"].(string)
  6854. project.Remark = remark
  6855. }
  6856. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6857. day, _ := json["number_days"].(string)
  6858. project.Day = day
  6859. }
  6860. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6861. unit, _ := json["unit"].(string)
  6862. project.Unit = unit
  6863. }
  6864. return 0
  6865. }
  6866. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6867. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6868. id := int64(json["id"].(float64))
  6869. historyAddtions, _ := service.GetHisAdditionByID(id)
  6870. additionalCharge.ID = id
  6871. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  6872. }
  6873. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6874. item_id := int64(json["item_id"].(float64))
  6875. additionalCharge.ItemId = item_id
  6876. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6877. if config.ID > 0 {
  6878. if len(config.Code) > 0 {
  6879. additionalCharge.MedListCodg = config.Code
  6880. }
  6881. }
  6882. }
  6883. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6884. // price := int64(json["price"].(float64))
  6885. // formatInt_price := strconv.FormatInt(price, 10)
  6886. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6887. // additionalCharge.Price = float_price
  6888. // }
  6889. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6890. // price := int64(json["price"].(float64))
  6891. // formatInt_price := strconv.FormatInt(price, 10)
  6892. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6893. // additionalCharge.Price = float_price
  6894. //}
  6895. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6896. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6897. additionalCharge.Price = price
  6898. }
  6899. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6900. count, _ := json["count"].(string)
  6901. counts, _ := strconv.ParseInt(count, 10, 64)
  6902. additionalCharge.Count = counts
  6903. }
  6904. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6905. item_name, _ := json["item_name"].(string)
  6906. additionalCharge.ItemName = item_name
  6907. }
  6908. return 0
  6909. }
  6910. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6911. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6912. utils.ErrorLog("drug_name")
  6913. return enums.ErrorCodeParamWrong
  6914. }
  6915. adviceName, _ := json["drug_name"].(string)
  6916. if len(adviceName) == 0 {
  6917. utils.ErrorLog("len(advice_name) == 0")
  6918. return enums.ErrorCodeParamWrong
  6919. }
  6920. advice.AdviceName = adviceName
  6921. adviceDesc, _ := json["advice_desc"].(string)
  6922. advice.AdviceDesc = adviceDesc
  6923. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6924. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6925. advice.DrugSpec = drugSpec
  6926. }
  6927. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6928. remark, _ := json["remark"].(string)
  6929. advice.Remark = remark
  6930. }
  6931. if json["id"] == nil {
  6932. advice.DrugId = 0
  6933. } else {
  6934. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6935. drug_id := int64(json["id"].(float64))
  6936. advice.DrugId = drug_id
  6937. }
  6938. }
  6939. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6940. groupno := int64(json["groupno"].(float64))
  6941. advice.Groupno = groupno
  6942. }
  6943. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6944. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6945. advice.IsSelfDrug = is_self_drug
  6946. }
  6947. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6948. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6949. drug_way_count, _ := json["drug_way_count"].(string)
  6950. advice.DrugWayCount = drug_way_count
  6951. }
  6952. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6953. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6954. advice.HospApprFlag = hosp_appr_flag
  6955. }
  6956. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6957. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6958. advice.PrescribingNumber = prescribingNumber
  6959. }
  6960. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6961. // frequency_type := int64(json["frequency_type"].(float64))
  6962. // advice.FrequencyType = frequency_type
  6963. //}
  6964. //
  6965. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6966. // day_count := int64(json["day_count"].(float64))
  6967. // advice.DayCount = day_count
  6968. //}
  6969. //
  6970. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6971. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6972. // week_day, _ := json["week_day"].(string)
  6973. // advice.WeekDay = week_day
  6974. //}
  6975. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6976. drugSpecUnit, _ := json["min_unit"].(string)
  6977. advice.DrugSpecUnit = drugSpecUnit
  6978. }
  6979. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6980. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6981. advice.SingleDose = singleDose
  6982. }
  6983. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6984. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6985. advice.SingleDoseUnit = singleDoseUnit
  6986. }
  6987. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6988. deliveryWay, _ := json["delivery_way"].(string)
  6989. advice.DeliveryWay = deliveryWay
  6990. }
  6991. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6992. executionFrequency, _ := json["execution_frequency"].(string)
  6993. advice.ExecutionFrequency = executionFrequency
  6994. }
  6995. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6996. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6997. advice.Price = price
  6998. }
  6999. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7000. med_list_codg, _ := json["medical_insurance_number"].(string)
  7001. advice.MedListCodg = med_list_codg
  7002. }
  7003. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7004. day := int64(json["day"].(float64))
  7005. advice.Day = day
  7006. }
  7007. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7008. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7009. advice.PrescribingNumberUnit = prescribingNumberUnit
  7010. }
  7011. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7012. advice_id := int64(json["advice_id"].(float64))
  7013. advice.ID = advice_id
  7014. if advice.ID > 0 {
  7015. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7016. if err == nil {
  7017. if hisAdvice.ID > 0 {
  7018. advice.ExecutionTime = hisAdvice.ExecutionTime
  7019. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7020. advice.ExecutionState = hisAdvice.ExecutionState
  7021. advice.CheckTime = hisAdvice.CheckTime
  7022. advice.Checker = hisAdvice.Checker
  7023. advice.CheckState = hisAdvice.CheckState
  7024. advice.StartTime = hisAdvice.StartTime
  7025. advice.HospApprFlag = hisAdvice.HospApprFlag
  7026. advice.IsMedicine = hisAdvice.IsMedicine
  7027. if hisAdvice.UserOrgId == 10028 {
  7028. 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 {
  7029. advice.ExecutionTime = 0
  7030. advice.ExecutionStaff = 0
  7031. advice.ExecutionState = 2
  7032. advice.CheckTime = 0
  7033. advice.Checker = 0
  7034. advice.CheckState = 2
  7035. }
  7036. } else {
  7037. 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 {
  7038. advice.ExecutionTime = 0
  7039. advice.ExecutionStaff = 0
  7040. advice.ExecutionState = 2
  7041. advice.CheckTime = 0
  7042. advice.Checker = 0
  7043. advice.CheckState = 2
  7044. advice.UpdatedTime = time.Now().Unix()
  7045. }
  7046. }
  7047. //advice.Groupno = hisAdvice.Groupno
  7048. }
  7049. }
  7050. }
  7051. }
  7052. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7053. //
  7054. //if drugStockConfig.IsOpen == 1 {
  7055. //
  7056. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7057. // if advice.ID == 0 { //医嘱不存在
  7058. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7059. // drug.Total = drug.Total - advice.PrescribingNumber
  7060. // service.UpdateBaseDrugLib(&drug)
  7061. //
  7062. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7063. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7064. // drug.Total = drug.Total - num
  7065. // service.UpdateBaseDrugLib(&drug)
  7066. // }
  7067. //
  7068. // } else if advice.ID > 0 { //医嘱存在
  7069. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7070. // var num float64
  7071. //
  7072. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7073. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7074. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7075. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7076. // drug.Total = drug.Total + num
  7077. // service.UpdateBaseDrugLib(&drug)
  7078. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7079. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7080. // drug.Total = drug.Total - num
  7081. // service.UpdateBaseDrugLib(&drug)
  7082. // }
  7083. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7084. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7085. // if num2 > advice.PrescribingNumber {
  7086. // num = num2 - advice.PrescribingNumber
  7087. // drug.Total = drug.Total + num
  7088. // service.UpdateBaseDrugLib(&drug)
  7089. // } else if num2 < advice.PrescribingNumber {
  7090. // num = advice.PrescribingNumber - num2
  7091. // drug.Total = drug.Total - num
  7092. // service.UpdateBaseDrugLib(&drug)
  7093. // }
  7094. //
  7095. // }
  7096. //
  7097. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7098. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7099. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7100. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7101. // if num1 > num2 {
  7102. // num = num1 - num2
  7103. // drug.Total = drug.Total + num
  7104. // service.UpdateBaseDrugLib(&drug)
  7105. // } else if num1 < num2 {
  7106. // num = num2 - num1
  7107. // drug.Total = drug.Total - num
  7108. // service.UpdateBaseDrugLib(&drug)
  7109. // }
  7110. //
  7111. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7112. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7113. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7114. // if hisAdvice.PrescribingNumber > num2 {
  7115. // num = hisAdvice.PrescribingNumber - num2
  7116. // drug.Total = drug.Total + num
  7117. // service.UpdateBaseDrugLib(&drug)
  7118. // } else if num2 < advice.PrescribingNumber {
  7119. // num = num2 - hisAdvice.PrescribingNumber
  7120. // drug.Total = drug.Total - num
  7121. // service.UpdateBaseDrugLib(&drug)
  7122. // }
  7123. //
  7124. // }
  7125. // }
  7126. // }
  7127. //}
  7128. //
  7129. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7130. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7131. // advice.ExecutionTime = execution_time
  7132. //}
  7133. //
  7134. //
  7135. //
  7136. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7137. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7138. // advice.ExecutionStaff = execution_staff
  7139. //}
  7140. //
  7141. //
  7142. //
  7143. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7144. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7145. // advice.ExecutionState = execution_state
  7146. //}
  7147. //
  7148. //
  7149. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7150. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7151. // advice.CheckTime = check_time
  7152. //}
  7153. //
  7154. //
  7155. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7156. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7157. // advice.CheckState = check_state
  7158. //}
  7159. //
  7160. //
  7161. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7162. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7163. // advice.Checker = checker
  7164. //}
  7165. //
  7166. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7167. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7168. // advice.StartTime = start_time
  7169. //}
  7170. return 0
  7171. }
  7172. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7173. project.ExecutionStaff = 0
  7174. project.ExecutionState = 2
  7175. project.ExecutionTime = 0
  7176. project.Checker = 0
  7177. project.CheckState = 2
  7178. project.CheckTime = 0
  7179. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7180. id := int64(json["id"].(float64))
  7181. project.ID = id
  7182. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7183. project.ExecutionStaff = temp_project.ExecutionStaff
  7184. project.ExecutionState = temp_project.ExecutionState
  7185. project.ExecutionTime = temp_project.ExecutionTime
  7186. project.Checker = temp_project.Checker
  7187. project.CheckState = temp_project.CheckState
  7188. project.CheckTime = temp_project.CheckTime
  7189. project.TeamId = temp_project.TeamId
  7190. }
  7191. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7192. types := int64(json["type"].(float64))
  7193. project.Type = types
  7194. }
  7195. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7196. project_id := int64(json["project_id"].(float64))
  7197. project.ProjectId = project_id
  7198. }
  7199. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7200. team_id := int64(json["team_id"].(float64))
  7201. project.TeamId = team_id
  7202. }
  7203. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7204. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7205. project.Price = price
  7206. }
  7207. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7208. total, _ := json["total"].(string)
  7209. //totals, _ := strconv.ParseInt(total, 10, 64)
  7210. project.Count = total
  7211. }
  7212. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7213. medical_code, _ := json["medical_code"].(string)
  7214. project.MedListCodg = medical_code
  7215. }
  7216. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7217. single_dose, _ := json["single_dose"].(string)
  7218. project.SingleDose = single_dose
  7219. }
  7220. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7221. delivery_way, _ := json["delivery_way"].(string)
  7222. project.DeliveryWay = delivery_way
  7223. }
  7224. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7225. execution_frequency, _ := json["execution_frequency"].(string)
  7226. project.ExecutionFrequency = execution_frequency
  7227. }
  7228. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7229. remark, _ := json["remark"].(string)
  7230. project.Remark = remark
  7231. }
  7232. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7233. day, _ := json["number_days"].(string)
  7234. project.Day = day
  7235. }
  7236. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7237. unit, _ := json["unit"].(string)
  7238. project.Unit = unit
  7239. }
  7240. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7241. // frequency_type := int64(json["frequency_type"].(float64))
  7242. // project.FrequencyType = frequency_type
  7243. //}
  7244. //
  7245. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7246. // day_count := int64(json["day_count"].(float64))
  7247. // project.DayCount = day_count
  7248. //}
  7249. //
  7250. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7251. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7252. // week_day, _ := json["week_day"].(string)
  7253. // project.WeekDay = week_day
  7254. //}
  7255. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7256. //
  7257. //if project.ID == 0 {
  7258. // if stockConfig.IsOpen == 1 {
  7259. // if project.Type == 3 {
  7260. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7261. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7262. // good.Total = good.Total - f_count
  7263. // service.UpdateGoodInfo(&good)
  7264. // }
  7265. // }
  7266. //
  7267. //} else {
  7268. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7269. //
  7270. // if stockConfig.IsOpen == 1 {
  7271. // if project.Type == 3 {
  7272. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7273. // if project.Count < temp_project.Count {
  7274. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7275. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7276. //
  7277. // other_count := f_count_two - f_count_one
  7278. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7279. // good.Total = good.Total + other_count_two
  7280. // service.UpdateGoodInfo(&good)
  7281. // } else if project.Count > temp_project.Count {
  7282. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7283. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7284. //
  7285. // other_count := f_count_one - f_count_two
  7286. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7287. // good.Total = good.Total - other_count_two
  7288. // service.UpdateGoodInfo(&good)
  7289. // }
  7290. //
  7291. // }
  7292. // }
  7293. //
  7294. //}
  7295. return 0
  7296. }
  7297. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7298. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7299. utils.ErrorLog("drug_name")
  7300. return enums.ErrorCodeParamWrong
  7301. }
  7302. adviceName, _ := json["drug_name"].(string)
  7303. if len(adviceName) == 0 {
  7304. utils.ErrorLog("len(advice_name) == 0")
  7305. return enums.ErrorCodeParamWrong
  7306. }
  7307. advice.AdviceName = adviceName
  7308. adviceDesc, _ := json["advice_desc"].(string)
  7309. advice.AdviceDesc = adviceDesc
  7310. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7311. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7312. advice.DrugSpec = drugSpec
  7313. }
  7314. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7315. remark, _ := json["remark"].(string)
  7316. advice.Remark = remark
  7317. }
  7318. if json["id"] == nil {
  7319. advice.DrugId = 0
  7320. } else {
  7321. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7322. drug_id := int64(json["id"].(float64))
  7323. advice.DrugId = drug_id
  7324. }
  7325. }
  7326. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7327. groupno := int64(json["groupno"].(float64))
  7328. advice.Groupno = groupno
  7329. }
  7330. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7331. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7332. advice.IsSelfDrug = is_self_drug
  7333. }
  7334. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7335. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7336. drug_way_count, _ := json["drug_way_count"].(string)
  7337. advice.DrugWayCount = drug_way_count
  7338. }
  7339. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7340. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7341. advice.HospApprFlag = hosp_appr_flag
  7342. }
  7343. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7344. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7345. advice.PrescribingNumber = prescribingNumber
  7346. }
  7347. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7348. // frequency_type := int64(json["frequency_type"].(float64))
  7349. // advice.FrequencyType = frequency_type
  7350. //}
  7351. //
  7352. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7353. // day_count := int64(json["day_count"].(float64))
  7354. // advice.DayCount = day_count
  7355. //}
  7356. //
  7357. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7358. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7359. // week_day, _ := json["week_day"].(string)
  7360. // advice.WeekDay = week_day
  7361. //}
  7362. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7363. drugSpecUnit, _ := json["min_unit"].(string)
  7364. advice.DrugSpecUnit = drugSpecUnit
  7365. }
  7366. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7367. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7368. advice.SingleDose = singleDose
  7369. }
  7370. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7371. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7372. advice.SingleDoseUnit = singleDoseUnit
  7373. }
  7374. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7375. deliveryWay, _ := json["delivery_way"].(string)
  7376. advice.DeliveryWay = deliveryWay
  7377. }
  7378. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7379. executionFrequency, _ := json["execution_frequency"].(string)
  7380. advice.ExecutionFrequency = executionFrequency
  7381. }
  7382. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7383. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7384. advice.Price = price
  7385. }
  7386. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7387. med_list_codg, _ := json["medical_insurance_number"].(string)
  7388. advice.MedListCodg = med_list_codg
  7389. }
  7390. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7391. day := int64(json["day"].(float64))
  7392. advice.Day = day
  7393. }
  7394. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7395. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7396. advice.PrescribingNumberUnit = prescribingNumberUnit
  7397. }
  7398. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7399. advice_id := int64(json["advice_id"].(float64))
  7400. advice.ID = advice_id
  7401. if advice.ID > 0 {
  7402. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7403. if err == nil {
  7404. if hisAdvice.ID > 0 {
  7405. advice.ExecutionTime = hisAdvice.ExecutionTime
  7406. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7407. advice.ExecutionState = hisAdvice.ExecutionState
  7408. advice.CheckTime = hisAdvice.CheckTime
  7409. advice.Checker = hisAdvice.Checker
  7410. advice.CheckState = hisAdvice.CheckState
  7411. advice.StartTime = hisAdvice.StartTime
  7412. advice.HospApprFlag = hisAdvice.HospApprFlag
  7413. advice.IsMedicine = hisAdvice.IsMedicine
  7414. if hisAdvice.UserOrgId == 10028 {
  7415. 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 {
  7416. advice.ExecutionTime = 0
  7417. advice.ExecutionStaff = 0
  7418. advice.ExecutionState = 2
  7419. advice.CheckTime = 0
  7420. advice.Checker = 0
  7421. advice.CheckState = 2
  7422. }
  7423. } else {
  7424. if hisAdvice.SingleDoseUnit != advice.SingleDoseUnit || hisAdvice.SingleDose != advice.SingleDose || hisAdvice.DeliveryWay != advice.DeliveryWay || hisAdvice.ExecutionFrequency != advice.ExecutionFrequency || hisAdvice.Day != advice.Day || hisAdvice.PrescribingNumber != advice.PrescribingNumber || hisAdvice.Price != advice.Price || hisAdvice.Remark != advice.Remark || hisAdvice.PrescribingNumberUnit != advice.PrescribingNumberUnit {
  7425. advice.ExecutionTime = 0
  7426. advice.ExecutionStaff = 0
  7427. advice.ExecutionState = 2
  7428. advice.CheckTime = 0
  7429. advice.Checker = 0
  7430. advice.CheckState = 2
  7431. //advice.UpdatedTime = time.Now().Unix()
  7432. advice.CreatedTime = hisAdvice.CreatedTime
  7433. advice.UpdatedTime = time.Now().Unix()
  7434. } else {
  7435. advice.CreatedTime = hisAdvice.CreatedTime
  7436. advice.UpdatedTime = hisAdvice.UpdatedTime
  7437. }
  7438. }
  7439. //advice.Groupno = hisAdvice.Groupno
  7440. } else {
  7441. advice.IsMedicine = 0
  7442. ctime := time.Now().Unix()
  7443. advice.CreatedTime = ctime
  7444. advice.UpdatedTime = ctime
  7445. }
  7446. }
  7447. } else {
  7448. advice.IsMedicine = 0
  7449. ctime := time.Now().Unix()
  7450. advice.CreatedTime = ctime
  7451. advice.UpdatedTime = ctime
  7452. }
  7453. }
  7454. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7455. //
  7456. //if drugStockConfig.IsOpen == 1 {
  7457. //
  7458. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7459. // if advice.ID == 0 { //医嘱不存在
  7460. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7461. // drug.Total = drug.Total - advice.PrescribingNumber
  7462. // service.UpdateBaseDrugLib(&drug)
  7463. //
  7464. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7465. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7466. // drug.Total = drug.Total - num
  7467. // service.UpdateBaseDrugLib(&drug)
  7468. // }
  7469. //
  7470. // } else if advice.ID > 0 { //医嘱存在
  7471. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7472. // var num float64
  7473. //
  7474. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7475. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7476. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7477. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7478. // drug.Total = drug.Total + num
  7479. // service.UpdateBaseDrugLib(&drug)
  7480. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7481. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7482. // drug.Total = drug.Total - num
  7483. // service.UpdateBaseDrugLib(&drug)
  7484. // }
  7485. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7486. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7487. // if num2 > advice.PrescribingNumber {
  7488. // num = num2 - advice.PrescribingNumber
  7489. // drug.Total = drug.Total + num
  7490. // service.UpdateBaseDrugLib(&drug)
  7491. // } else if num2 < advice.PrescribingNumber {
  7492. // num = advice.PrescribingNumber - num2
  7493. // drug.Total = drug.Total - num
  7494. // service.UpdateBaseDrugLib(&drug)
  7495. // }
  7496. //
  7497. // }
  7498. //
  7499. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7500. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7501. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7502. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7503. // if num1 > num2 {
  7504. // num = num1 - num2
  7505. // drug.Total = drug.Total + num
  7506. // service.UpdateBaseDrugLib(&drug)
  7507. // } else if num1 < num2 {
  7508. // num = num2 - num1
  7509. // drug.Total = drug.Total - num
  7510. // service.UpdateBaseDrugLib(&drug)
  7511. // }
  7512. //
  7513. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7514. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7515. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7516. // if hisAdvice.PrescribingNumber > num2 {
  7517. // num = hisAdvice.PrescribingNumber - num2
  7518. // drug.Total = drug.Total + num
  7519. // service.UpdateBaseDrugLib(&drug)
  7520. // } else if num2 < advice.PrescribingNumber {
  7521. // num = num2 - hisAdvice.PrescribingNumber
  7522. // drug.Total = drug.Total - num
  7523. // service.UpdateBaseDrugLib(&drug)
  7524. // }
  7525. //
  7526. // }
  7527. // }
  7528. // }
  7529. //}
  7530. //
  7531. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7532. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7533. // advice.ExecutionTime = execution_time
  7534. //}
  7535. //
  7536. //
  7537. //
  7538. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7539. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7540. // advice.ExecutionStaff = execution_staff
  7541. //}
  7542. //
  7543. //
  7544. //
  7545. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7546. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7547. // advice.ExecutionState = execution_state
  7548. //}
  7549. //
  7550. //
  7551. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7552. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7553. // advice.CheckTime = check_time
  7554. //}
  7555. //
  7556. //
  7557. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7558. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7559. // advice.CheckState = check_state
  7560. //}
  7561. //
  7562. //
  7563. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7564. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7565. // advice.Checker = checker
  7566. //}
  7567. //
  7568. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7569. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7570. // advice.StartTime = start_time
  7571. //}
  7572. return 0
  7573. }
  7574. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7575. project.ExecutionStaff = 0
  7576. project.ExecutionState = 2
  7577. project.ExecutionTime = 0
  7578. project.Checker = 0
  7579. project.CheckState = 2
  7580. project.CheckTime = 0
  7581. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7582. id := int64(json["id"].(float64))
  7583. project.ID = id
  7584. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7585. project.ExecutionStaff = temp_project.ExecutionStaff
  7586. project.ExecutionState = temp_project.ExecutionState
  7587. project.ExecutionTime = temp_project.ExecutionTime
  7588. project.Checker = temp_project.Checker
  7589. project.CheckState = temp_project.CheckState
  7590. project.CheckTime = temp_project.CheckTime
  7591. project.TeamId = temp_project.TeamId
  7592. }
  7593. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7594. types := int64(json["type"].(float64))
  7595. project.Type = types
  7596. }
  7597. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7598. project_id := int64(json["project_id"].(float64))
  7599. project.ProjectId = project_id
  7600. }
  7601. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7602. team_id := int64(json["team_id"].(float64))
  7603. project.TeamId = team_id
  7604. }
  7605. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7606. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7607. project.Price = price
  7608. }
  7609. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7610. total, _ := json["total"].(string)
  7611. //totals, _ := strconv.ParseInt(total, 10, 64)
  7612. project.Count = total
  7613. }
  7614. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7615. medical_code, _ := json["medical_code"].(string)
  7616. project.MedListCodg = medical_code
  7617. }
  7618. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7619. single_dose, _ := json["single_dose"].(string)
  7620. project.SingleDose = single_dose
  7621. }
  7622. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7623. delivery_way, _ := json["delivery_way"].(string)
  7624. project.DeliveryWay = delivery_way
  7625. }
  7626. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7627. execution_frequency, _ := json["execution_frequency"].(string)
  7628. project.ExecutionFrequency = execution_frequency
  7629. }
  7630. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7631. remark, _ := json["remark"].(string)
  7632. project.Remark = remark
  7633. }
  7634. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7635. day, _ := json["number_days"].(string)
  7636. project.Day = day
  7637. }
  7638. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7639. unit, _ := json["unit"].(string)
  7640. project.Unit = unit
  7641. }
  7642. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7643. // frequency_type := int64(json["frequency_type"].(float64))
  7644. // project.FrequencyType = frequency_type
  7645. //}
  7646. //
  7647. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7648. // day_count := int64(json["day_count"].(float64))
  7649. // project.DayCount = day_count
  7650. //}
  7651. //
  7652. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7653. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7654. // week_day, _ := json["week_day"].(string)
  7655. // project.WeekDay = week_day
  7656. //}
  7657. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7658. //
  7659. //if project.ID == 0 {
  7660. // if stockConfig.IsOpen == 1 {
  7661. // if project.Type == 3 {
  7662. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7663. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7664. // good.Total = good.Total - f_count
  7665. // service.UpdateGoodInfo(&good)
  7666. // }
  7667. // }
  7668. //
  7669. //} else {
  7670. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7671. //
  7672. // if stockConfig.IsOpen == 1 {
  7673. // if project.Type == 3 {
  7674. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7675. // if project.Count < temp_project.Count {
  7676. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7677. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7678. //
  7679. // other_count := f_count_two - f_count_one
  7680. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7681. // good.Total = good.Total + other_count_two
  7682. // service.UpdateGoodInfo(&good)
  7683. // } else if project.Count > temp_project.Count {
  7684. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7685. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7686. //
  7687. // other_count := f_count_one - f_count_two
  7688. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7689. // good.Total = good.Total - other_count_two
  7690. // service.UpdateGoodInfo(&good)
  7691. // }
  7692. //
  7693. // }
  7694. // }
  7695. //
  7696. //}
  7697. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7698. id := int64(json["id"].(float64))
  7699. if id > 0 {
  7700. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7701. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  7702. fmt.Println("666666")
  7703. project.Mtime = time.Now().Unix()
  7704. project.Ctime = temp_project.Ctime
  7705. } else {
  7706. project.Mtime = temp_project.Mtime
  7707. project.Ctime = temp_project.Ctime
  7708. }
  7709. } else {
  7710. ctime := time.Now().Unix()
  7711. project.Mtime = ctime
  7712. project.Ctime = ctime
  7713. }
  7714. }
  7715. return 0
  7716. }
  7717. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7718. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7719. id := int64(json["id"].(float64))
  7720. additionalCharge.ID = id
  7721. }
  7722. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7723. item_id := int64(json["item_id"].(float64))
  7724. additionalCharge.ItemId = item_id
  7725. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7726. if config.ID > 0 {
  7727. if len(config.Code) > 0 {
  7728. additionalCharge.MedListCodg = config.Code
  7729. }
  7730. }
  7731. }
  7732. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7733. // price := int64(json["price"].(float64))
  7734. // formatInt_price := strconv.FormatInt(price, 10)
  7735. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7736. // additionalCharge.Price = float_price
  7737. // }
  7738. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7739. // price := int64(json["price"].(float64))
  7740. // formatInt_price := strconv.FormatInt(price, 10)
  7741. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7742. // additionalCharge.Price = float_price
  7743. //}
  7744. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7745. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7746. additionalCharge.Price = price
  7747. }
  7748. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  7749. count, _ := json["count"].(string)
  7750. counts, _ := strconv.ParseInt(count, 10, 64)
  7751. additionalCharge.Count = counts
  7752. }
  7753. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  7754. item_name, _ := json["item_name"].(string)
  7755. additionalCharge.ItemName = item_name
  7756. }
  7757. return 0
  7758. }
  7759. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  7760. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7761. utils.ErrorLog("drug_name")
  7762. return enums.ErrorCodeParamWrong
  7763. }
  7764. adviceName, _ := json["drug_name"].(string)
  7765. if len(adviceName) == 0 {
  7766. utils.ErrorLog("len(advice_name) == 0")
  7767. return enums.ErrorCodeParamWrong
  7768. }
  7769. advice.AdviceName = adviceName
  7770. adviceDesc, _ := json["advice_desc"].(string)
  7771. advice.AdviceDesc = adviceDesc
  7772. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7773. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7774. advice.DrugSpec = drugSpec
  7775. }
  7776. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7777. remark, _ := json["remark"].(string)
  7778. advice.Remark = remark
  7779. }
  7780. if json["id"] == nil {
  7781. advice.DrugId = 0
  7782. } else {
  7783. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7784. drug_id := int64(json["id"].(float64))
  7785. advice.DrugId = drug_id
  7786. }
  7787. }
  7788. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7789. groupno := int64(json["groupno"].(float64))
  7790. advice.Groupno = groupno
  7791. }
  7792. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7793. drugSpecUnit, _ := json["min_unit"].(string)
  7794. advice.DrugSpecUnit = drugSpecUnit
  7795. }
  7796. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7797. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7798. advice.SingleDose = singleDose
  7799. }
  7800. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7801. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7802. advice.SingleDoseUnit = singleDoseUnit
  7803. }
  7804. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7805. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7806. advice.PrescribingNumber = prescribingNumber
  7807. }
  7808. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7809. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7810. advice.PrescribingNumberUnit = prescribingNumberUnit
  7811. }
  7812. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7813. deliveryWay, _ := json["delivery_way"].(string)
  7814. advice.DeliveryWay = deliveryWay
  7815. }
  7816. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7817. executionFrequency, _ := json["execution_frequency"].(string)
  7818. advice.ExecutionFrequency = executionFrequency
  7819. }
  7820. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7821. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7822. advice.Price = price
  7823. }
  7824. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7825. med_list_codg, _ := json["medical_insurance_number"].(string)
  7826. advice.MedListCodg = med_list_codg
  7827. }
  7828. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7829. day := int64(json["day"].(float64))
  7830. advice.Day = day
  7831. }
  7832. advice.FrequencyType = 1
  7833. return 0
  7834. }
  7835. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  7836. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7837. types := int64(json["type"].(float64))
  7838. project.Type = types
  7839. }
  7840. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7841. project_id := int64(json["project_id"].(float64))
  7842. project.ProjectId = project_id
  7843. }
  7844. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7845. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7846. project.Price = price
  7847. }
  7848. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7849. total, _ := json["total"].(string)
  7850. //totals, _ := strconv.ParseInt(total, 10, 64)
  7851. project.Count = total
  7852. }
  7853. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7854. medical_code, _ := json["medical_code"].(string)
  7855. project.MedListCodg = medical_code
  7856. }
  7857. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7858. single_dose, _ := json["single_dose"].(string)
  7859. project.SingleDose = single_dose
  7860. }
  7861. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7862. delivery_way, _ := json["delivery_way"].(string)
  7863. project.DeliveryWay = delivery_way
  7864. }
  7865. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7866. execution_frequency, _ := json["execution_frequency"].(string)
  7867. project.ExecutionFrequency = execution_frequency
  7868. }
  7869. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7870. remark, _ := json["remark"].(string)
  7871. project.Remark = remark
  7872. }
  7873. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7874. day, _ := json["number_days"].(string)
  7875. project.Day = day
  7876. }
  7877. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7878. unit, _ := json["unit"].(string)
  7879. project.Unit = unit
  7880. }
  7881. project.FrequencyType = 1
  7882. return 0
  7883. }
  7884. func (c *HisApiController) GetHisOrderListTwo() {
  7885. start_time := c.GetString("start_time")
  7886. end_time := c.GetString("end_time")
  7887. timeLayout := "2006-01-02"
  7888. loc, _ := time.LoadLocation("Local")
  7889. var startTime int64
  7890. if len(start_time) > 0 {
  7891. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7892. if err != nil {
  7893. //fmt.Println(err)
  7894. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7895. return
  7896. }
  7897. startTime = theTime.Unix()
  7898. }
  7899. var endTime int64
  7900. if len(end_time) > 0 {
  7901. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7902. if err != nil {
  7903. utils.ErrorLog(err.Error())
  7904. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7905. return
  7906. }
  7907. endTime = theTime.Unix()
  7908. }
  7909. adminUser := c.GetAdminUserInfo()
  7910. org_id := adminUser.CurrentOrgId
  7911. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  7912. if err == nil {
  7913. c.ServeSuccessJSON(map[string]interface{}{
  7914. "order2": order,
  7915. })
  7916. } else {
  7917. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7918. return
  7919. }
  7920. }
  7921. func (c *HisApiController) GetHisOrderList() {
  7922. page, _ := c.GetInt64("page", -1)
  7923. limit, _ := c.GetInt64("limit", -1)
  7924. start_time := c.GetString("start_time")
  7925. end_time := c.GetString("end_time")
  7926. types, _ := c.GetInt64("type", 0)
  7927. keywords := c.GetString("keywords")
  7928. p_type, _ := c.GetInt64("p_type", 0)
  7929. sort_type, _ := c.GetInt64("sort_type", 0)
  7930. charge_type, _ := c.GetInt64("charge_type", 0)
  7931. sch_type, _ := c.GetInt64("sch_type", 0)
  7932. zone_type, _ := c.GetInt64("zone_type", 0)
  7933. med_type, _ := c.GetInt64("med_type", 0)
  7934. timeLayout := "2006-01-02"
  7935. loc, _ := time.LoadLocation("Local")
  7936. var startTime int64
  7937. if len(start_time) > 0 {
  7938. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7939. if err != nil {
  7940. //fmt.Println(err)
  7941. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7942. return
  7943. }
  7944. startTime = theTime.Unix()
  7945. }
  7946. var endTime int64
  7947. if len(end_time) > 0 {
  7948. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7949. if err != nil {
  7950. utils.ErrorLog(err.Error())
  7951. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7952. return
  7953. }
  7954. endTime = theTime.Unix()
  7955. }
  7956. adminUser := c.GetAdminUserInfo()
  7957. org_id := adminUser.CurrentOrgId
  7958. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time, charge_type, sch_type, zone_type, med_type)
  7959. for _, item := range order {
  7960. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  7961. item.DoctorName = info.Doctor
  7962. item.DepartmentName = info.XtHisDepartment.Name
  7963. }
  7964. if err == nil {
  7965. c.ServeSuccessJSON(map[string]interface{}{
  7966. "order": order,
  7967. "total": total,
  7968. })
  7969. } else {
  7970. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7971. return
  7972. }
  7973. }
  7974. func (c *HisApiController) GetHisOrder() {
  7975. patient_id, _ := c.GetInt64("patient_id", 0)
  7976. number := c.GetString("number")
  7977. adminInfo := c.GetAdminUserInfo()
  7978. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  7979. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  7980. if err == nil {
  7981. c.ServeSuccessJSON(map[string]interface{}{
  7982. "order": order,
  7983. "prescription": prescriptions,
  7984. })
  7985. } else {
  7986. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7987. return
  7988. }
  7989. }
  7990. func (c *HisApiController) GetHisPrescriptionList() {
  7991. record_date := c.GetString("record_date")
  7992. keywords := c.GetString("keywords")
  7993. page, _ := c.GetInt64("page")
  7994. limit, _ := c.GetInt64("limit")
  7995. sch_type, _ := c.GetInt64("sch_type")
  7996. timeLayout := "2006-01-02"
  7997. loc, _ := time.LoadLocation("Local")
  7998. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7999. if err != nil {
  8000. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8001. return
  8002. }
  8003. recordDateTime := theTime.Unix()
  8004. adminInfo := c.GetAdminUserInfo()
  8005. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  8006. //adminInfo := c.GetAdminUserInfo()
  8007. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  8008. //fmt.Println(prescriptionOrder)
  8009. if err == nil {
  8010. c.ServeSuccessJSON(map[string]interface{}{
  8011. "order": prescriptionOrder,
  8012. "total": total,
  8013. })
  8014. } else {
  8015. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8016. return
  8017. }
  8018. }
  8019. func (c *HisApiController) GetHisPrescriptionInfo() {
  8020. id, _ := c.GetInt64("id")
  8021. adminInfo := c.GetAdminUserInfo()
  8022. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  8023. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  8024. if err == nil {
  8025. c.ServeSuccessJSON(map[string]interface{}{
  8026. "order": prescriptionOrder,
  8027. "prescription": prescription,
  8028. })
  8029. } else {
  8030. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8031. return
  8032. }
  8033. }
  8034. func (c *HisApiController) GetMedicalInsuranceConfig() {
  8035. adminUser := c.GetAdminUserInfo()
  8036. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  8037. c.ServeSuccessJSON(map[string]interface{}{
  8038. "config": config,
  8039. })
  8040. }
  8041. type ResultTwo struct {
  8042. ErrMsg interface{} `json:"err_msg"`
  8043. InfRefmsgid string `json:"inf_refmsgid"`
  8044. Infcode int64 `json:"infcode"`
  8045. Output struct {
  8046. Baseinfo struct {
  8047. Age float64 `json:"age"`
  8048. Brdy string `json:"brdy"`
  8049. Certno string `json:"certno"`
  8050. Gend string `json:"gend"`
  8051. Naty string `json:"naty"`
  8052. PsnCertType string `json:"psn_cert_type"`
  8053. PsnName string `json:"psn_name"`
  8054. PsnNo string `json:"psn_no"`
  8055. } `json:"baseinfo"`
  8056. Idetinfo []interface{} `json:"idetinfo"`
  8057. Iinfo []struct {
  8058. Balc float64 `json:"balc"`
  8059. CvlservFlag string `json:"cvlserv_flag"`
  8060. EmpName string `json:"emp_name"`
  8061. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  8062. Insutype string `json:"insutype"`
  8063. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  8064. PausInsuDate interface{} `json:"paus_insu_date"`
  8065. PsnInsuDate string `json:"psn_insu_date"`
  8066. PsnInsuStas string `json:"psn_insu_stas"`
  8067. PsnType string `json:"psn_type"`
  8068. } `json:"insuinfo"`
  8069. } `json:"output"`
  8070. RefmsgTime string `json:"refmsg_time"`
  8071. RespondTime string `json:"respond_time"`
  8072. Signtype interface{} `json:"signtype"`
  8073. WarnInfo interface{} `json:"warn_info"`
  8074. }
  8075. type ResultThree struct {
  8076. Cainfo interface{} `json:"cainfo"`
  8077. ErrMsg interface{} `json:"err_msg"`
  8078. InfRefmsgid string `json:"inf_refmsgid"`
  8079. Infcode int64 `json:"infcode"`
  8080. Output struct {
  8081. Data struct {
  8082. IptOtpNo string `json:"ipt_otp_no"`
  8083. MdtrtID string `json:"mdtrt_id"`
  8084. PsnNo string `json:"psn_no"`
  8085. } `json:"data"`
  8086. } `json:"output"`
  8087. RefmsgTime string `json:"refmsg_time"`
  8088. RespondTime string `json:"respond_time"`
  8089. Signtype interface{} `json:"signtype"`
  8090. WarnMsg interface{} `json:"warn_msg"`
  8091. }
  8092. type ResultFour struct {
  8093. Cainfo string `json:"cainfo"`
  8094. ErrMsg string `json:"err_msg"`
  8095. InfRefmsgid string `json:"inf_refmsgid"`
  8096. Infcode int64 `json:"infcode"`
  8097. Output struct {
  8098. Result []struct {
  8099. BasMednFlag string `json:"bas_medn_flag"`
  8100. ChldMedcFlag string `json:"chld_medc_flag"`
  8101. ChrgitmLv string `json:"chrgitm_lv"`
  8102. Cnt float64 `json:"cnt"`
  8103. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  8104. DrtReimFlag string `json:"drt_reim_flag"`
  8105. FeedetlSn string `json:"feedetl_sn"`
  8106. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8107. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  8108. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8109. ListSpItemFlag string `json:"list_sp_item_flag"`
  8110. LmtUsedFlag string `json:"lmt_used_flag"`
  8111. MedChrgitmType string `json:"med_chrgitm_type"`
  8112. Memo string `json:"memo"`
  8113. OverlmtAmt float64 `json:"overlmt_amt"`
  8114. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8115. Pric float64 `json:"pric"`
  8116. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  8117. SelfpayProp float64 `json:"selfpay_prop"`
  8118. } `json:"result"`
  8119. } `json:"output"`
  8120. RefmsgTime string `json:"refmsg_time"`
  8121. RespondTime string `json:"respond_time"`
  8122. Signtype string `json:"signtype"`
  8123. WarnMsg string `json:"warn_msg"`
  8124. }
  8125. type ResultFive struct {
  8126. Insutype string `json:"insutype"`
  8127. }
  8128. type ResultSix struct {
  8129. Cainfo interface{} `json:"cainfo"`
  8130. ErrMsg interface{} `json:"err_msg"`
  8131. InfRefmsgid string `json:"inf_refmsgid"`
  8132. Infcode int64 `json:"infcode"`
  8133. Output struct {
  8134. } `json:"output"`
  8135. RefmsgTime string `json:"refmsg_time"`
  8136. RespondTime string `json:"respond_time"`
  8137. Signtype interface{} `json:"signtype"`
  8138. WarnMsg interface{} `json:"warn_msg"`
  8139. }
  8140. type ResultSeven struct {
  8141. Cainfo string `json:"cainfo"`
  8142. ErrMsg string `json:"err_msg"`
  8143. InfRefmsgid string `json:"inf_refmsgid"`
  8144. Infcode int64 `json:"infcode"`
  8145. Output struct {
  8146. Setldetail []interface{} `json:"setldetail"`
  8147. Setlinfo struct {
  8148. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8149. AcctPay float64 `json:"acct_pay"`
  8150. ActPayDedc float64 `json:"act_pay_dedc"`
  8151. Age float64 `json:"age"`
  8152. Balc float64 `json:"balc"`
  8153. Brdy string `json:"brdy"`
  8154. Certno string `json:"certno"`
  8155. ClrOptins string `json:"clr_optins"`
  8156. ClrType string `json:"clr_type"`
  8157. ClrWay string `json:"clr_way"`
  8158. CvlservFlag string `json:"cvlserv_flag"`
  8159. CvlservPay float64 `json:"cvlserv_pay"`
  8160. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8161. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8162. Gend string `json:"gend"`
  8163. HifesPay float64 `json:"hifes_pay"`
  8164. HifmiPay float64 `json:"hifmi_pay"`
  8165. HifobPay float64 `json:"hifob_pay"`
  8166. HifpPay float64 `json:"hifp_pay"`
  8167. HospPartAmt float64 `json:"hosp_part_amt"`
  8168. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8169. Insutype string `json:"insutype"`
  8170. MafPay float64 `json:"maf_pay"`
  8171. MdtrtCertType string `json:"mdtrt_cert_type"`
  8172. MdtrtID string `json:"mdtrt_id"`
  8173. MedType string `json:"med_type"`
  8174. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8175. MedinsSetlID string `json:"medins_setl_id"`
  8176. Naty string `json:"naty"`
  8177. OthPay float64 `json:"oth_pay"`
  8178. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8179. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8180. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8181. PsnCashPay float64 `json:"psn_cash_pay"`
  8182. PsnCertType string `json:"psn_cert_type"`
  8183. PsnName string `json:"psn_name"`
  8184. PsnNo string `json:"psn_no"`
  8185. PsnPartAmt float64 `json:"psn_part_amt"`
  8186. PsnType string `json:"psn_type"`
  8187. SetlID string `json:"setl_id"`
  8188. SetlTime string `json:"setl_time"`
  8189. } `json:"setlinfo"`
  8190. } `json:"output"`
  8191. RefmsgTime string `json:"refmsg_time"`
  8192. RespondTime string `json:"respond_time"`
  8193. Signtype interface{} `json:"signtype"`
  8194. WarnMsg interface{} `json:"warn_msg"`
  8195. }
  8196. type ResultEight struct {
  8197. Cainfo string `json:"cainfo"`
  8198. ErrMsg string `json:"err_msg"`
  8199. InfRefmsgid string `json:"inf_refmsgid"`
  8200. Infcode int64 `json:"infcode"`
  8201. Output struct {
  8202. Stmtinfo struct {
  8203. SetlOptins string `json:"setl_optins"`
  8204. StmtRslt string `json:"stmt_rslt"`
  8205. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  8206. } `json:"stmtinfo"`
  8207. } `json:"output"`
  8208. RefmsgTime string `json:"refmsg_time"`
  8209. RespondTime string `json:"respond_time"`
  8210. Signtype interface{} `json:"signtype"`
  8211. WarnMsg interface{} `json:"warn_msg"`
  8212. }
  8213. type ResultNine struct {
  8214. Cainfo string `json:"cainfo"`
  8215. ErrMsg string `json:"err_msg"`
  8216. InfRefmsgid string `json:"inf_refmsgid"`
  8217. Infcode int64 `json:"infcode"`
  8218. Output struct {
  8219. FileQuryNo string `json:"file_qury_no"`
  8220. } `json:"output"`
  8221. RefmsgTime string `json:"refmsg_time"`
  8222. RespondTime string `json:"respond_time"`
  8223. Signtype interface{} `json:"signtype"`
  8224. WarnMsg interface{} `json:"warn_msg"`
  8225. }
  8226. type ResultTen struct {
  8227. Cainfo string `json:"cainfo"`
  8228. ErrMsg string `json:"err_msg"`
  8229. InfRefmsgid string `json:"inf_refmsgid"`
  8230. Infcode int64 `json:"infcode"`
  8231. Output struct {
  8232. DldEndtime string `json:"dld_endtime"`
  8233. FileQuryNo string `json:"file_qury_no"`
  8234. Filename string `json:"filename"`
  8235. } `json:"output"`
  8236. RefmsgTime string `json:"refmsg_time"`
  8237. RespondTime string `json:"respond_time"`
  8238. Signtype interface{} `json:"signtype"`
  8239. WarnMsg interface{} `json:"warn_msg"`
  8240. }
  8241. type ResultEleven struct {
  8242. Cainfo string `json:"cainfo"`
  8243. ErrMsg string `json:"err_msg"`
  8244. InfRefmsgid string `json:"inf_refmsgid"`
  8245. Infcode int64 `json:"infcode"`
  8246. Output struct {
  8247. Setlinfo struct {
  8248. FixmedinsName string `json:"fixmedins_name"`
  8249. FixmedinsCode string `json:"fixmedins_code"`
  8250. PsnNo string `json:"psn_no"`
  8251. PsnName string `json:"psn_name"`
  8252. HifobPay float64 `json:"hifob_pay"`
  8253. Gend string `json:"gend"`
  8254. Brdy string `json:"brdy"`
  8255. PsnCertType string `json:"psn_cert_type"`
  8256. PsnType string `json:"psn_type"`
  8257. EmpName string `json:"emp_name"`
  8258. Certno string `json:"certno"`
  8259. Insutype string `json:"insutype"`
  8260. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8261. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8262. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8263. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8264. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8265. ActPayDedc float64 `json:"act_pay_dedc"`
  8266. HifpPay float64 `json:"hifp_pay"`
  8267. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8268. CvlservPay float64 `json:"cvlserv_pay"`
  8269. HifesPay float64 `json:"hifes_pay"`
  8270. HifmiPay float64 `json:"hifmi_pay"`
  8271. MafPay float64 `json:"maf_pay"`
  8272. OthPay float64 `json:"oth_pay"`
  8273. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8274. PsnPay float64 `json:"psn_pay"`
  8275. AcctPay float64 `json:"acct_pay"`
  8276. CashPayamt float64 `json:"cash_payamt"`
  8277. Balc float64 `json:"balc"`
  8278. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8279. MedinsSetlId string `json:"medins_setl_id"`
  8280. RefdSetlFlag string `json:"refd_setl_flag"`
  8281. SetlTime string `json:"setl_time"`
  8282. MedType string `json:"med_type"`
  8283. } `json:"setlinfo"`
  8284. } `json:"output"`
  8285. RefmsgTime string `json:"refmsg_time"`
  8286. RespondTime string `json:"respond_time"`
  8287. Signtype interface{} `json:"signtype"`
  8288. WarnMsg interface{} `json:"warn_msg"`
  8289. }
  8290. type Custom struct {
  8291. DetItemFeeSumamt string
  8292. Cut string
  8293. FeedetlSn string
  8294. Price string
  8295. MedListCodg string
  8296. Type int64
  8297. AdviceId int64
  8298. ProjectId int64
  8299. ItemId int64
  8300. }
  8301. // 获取个人信息----挂号-----上传就诊信息
  8302. func (c *HisApiController) GetRegisterInfo() {
  8303. id, _ := c.GetInt64("id")
  8304. record_time := c.GetString("record_time")
  8305. settlementValue, _ := c.GetInt64("settlement_value")
  8306. medical_insurance_card := c.GetString("medical_insurance_card")
  8307. name := c.GetString("name")
  8308. id_card_type, _ := c.GetInt64("id_card_type")
  8309. certificates, _ := c.GetInt64("certificates")
  8310. medical_care, _ := c.GetInt64("medical_care")
  8311. birthday := c.GetString("birthday")
  8312. age, _ := c.GetInt64("age")
  8313. id_card := c.GetString("id_card")
  8314. register_type, _ := c.GetInt64("register")
  8315. doctor, _ := c.GetInt64("doctor")
  8316. department, _ := c.GetInt64("department")
  8317. gender, _ := c.GetInt64("sex")
  8318. phone := c.GetString("phone")
  8319. registration_fee, _ := c.GetFloat("registration_fee")
  8320. medical_expenses, _ := c.GetFloat("medical_expenses")
  8321. social_type, _ := c.GetInt64("social_type")
  8322. //diagnosis_id, _ := c.GetInt64("diagnosis")
  8323. diagnosis_ids := c.GetString("diagnosis")
  8324. sick_type, _ := c.GetInt64("sick_type")
  8325. reg_type := c.GetString("p_type")
  8326. timeLayout := "2006-01-02"
  8327. loc, _ := time.LoadLocation("Local")
  8328. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  8329. birthUnix := birthdays.Unix()
  8330. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8331. if err != nil {
  8332. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8333. return
  8334. }
  8335. recordDateTime := theTime.Unix()
  8336. adminInfo := c.GetAdminUserInfo()
  8337. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  8338. if tempPatient.ID == 0 {
  8339. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  8340. return
  8341. }
  8342. var patient service.Patients
  8343. if id == 0 {
  8344. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  8345. } else {
  8346. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  8347. }
  8348. if patient.ID == 0 {
  8349. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  8350. return
  8351. }
  8352. if len(patient.IdCardNo) == 0 {
  8353. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  8354. return
  8355. }
  8356. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  8357. if len(his) >= 1 {
  8358. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  8359. if len(his) >= 1 && order.ID == 0 {
  8360. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  8361. return
  8362. }
  8363. }
  8364. timeStr := time.Now().Format("2006-01-02 15:04:05")
  8365. fmt.Println(timeStr)
  8366. timeArr := strings.Split(timeStr, " ")
  8367. fmt.Println(timeArr)
  8368. timeArrTwo := strings.Split(timeArr[0], "-")
  8369. timeArrThree := strings.Split(timeArr[1], ":")
  8370. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  8371. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  8372. if len(lists) == 0 {
  8373. var hisPatient models.XtHisPatient
  8374. hisPatient = models.XtHisPatient{
  8375. Name: name,
  8376. Age: age,
  8377. Gender: gender,
  8378. Birthday: birthUnix,
  8379. Phone: phone,
  8380. MedicalTreatmentType: medical_care,
  8381. IdType: certificates,
  8382. IdCardNo: id_card,
  8383. BalanceAccountsType: settlementValue,
  8384. SocialType: social_type,
  8385. MedicalInsuranceNumber: medical_insurance_card,
  8386. RegisterType: register_type,
  8387. RegisterCost: registration_fee,
  8388. TreatmentCost: medical_expenses,
  8389. AdminUserId: adminInfo.AdminUser.Id,
  8390. UserOrgId: adminInfo.CurrentOrgId,
  8391. Status: 1,
  8392. RecordDate: recordDateTime,
  8393. IsReturn: 1,
  8394. PatientId: patient.ID,
  8395. Ctime: time.Now().Unix(),
  8396. Mtime: time.Now().Unix(),
  8397. Number: str,
  8398. IdCardType: id_card_type,
  8399. Departments: department,
  8400. Doctor: doctor,
  8401. PType: reg_type,
  8402. Diagnosis: diagnosis_ids,
  8403. SickType: sick_type,
  8404. }
  8405. service.CreateHisPatient(&hisPatient)
  8406. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  8407. c.ServeSuccessJSON(map[string]interface{}{
  8408. "his_info": hisPatient,
  8409. })
  8410. } else {
  8411. //chrgBchno := rand.Intn(1000000) + 10000
  8412. var hisPatient models.XtHisPatient
  8413. hisPatient = models.XtHisPatient{
  8414. Name: name,
  8415. Age: age,
  8416. Gender: gender,
  8417. Birthday: birthUnix,
  8418. Phone: phone,
  8419. MedicalTreatmentType: medical_care,
  8420. IdType: certificates,
  8421. IdCardNo: id_card,
  8422. BalanceAccountsType: settlementValue,
  8423. SocialType: social_type,
  8424. MedicalInsuranceNumber: medical_insurance_card,
  8425. RegisterType: register_type,
  8426. RegisterCost: registration_fee,
  8427. TreatmentCost: medical_expenses,
  8428. AdminUserId: adminInfo.AdminUser.Id,
  8429. UserOrgId: adminInfo.CurrentOrgId,
  8430. Status: 1,
  8431. RecordDate: recordDateTime,
  8432. IsReturn: 1,
  8433. PatientId: patient.ID,
  8434. Ctime: time.Now().Unix(),
  8435. Mtime: time.Now().Unix(),
  8436. Number: str,
  8437. IdCardType: id_card_type,
  8438. Departments: department,
  8439. Doctor: doctor,
  8440. PType: reg_type,
  8441. Diagnosis: diagnosis_ids,
  8442. SickType: sick_type,
  8443. }
  8444. service.CreateHisPatient(&hisPatient)
  8445. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  8446. c.ServeSuccessJSON(map[string]interface{}{
  8447. "his_info": hisPatient,
  8448. })
  8449. }
  8450. }
  8451. // 上传明细----结算
  8452. func (c *HisApiController) GetUploadInfo() {
  8453. id, _ := c.GetInt64("id")
  8454. record_time := c.GetString("record_time")
  8455. his_patient_id, _ := c.GetInt64("his_patient_id")
  8456. oth_desc := c.GetString("oth_desc")
  8457. pay_way, _ := c.GetInt64("pay_way")
  8458. pay_ways := c.GetString("pay_ways")
  8459. pay_price, _ := c.GetFloat("pay_price")
  8460. pay_card_no := c.GetString("pay_card_no")
  8461. discount_price, _ := c.GetFloat("discount_price")
  8462. preferential_price, _ := c.GetFloat("preferential_price")
  8463. reality_price, _ := c.GetFloat("reality_price")
  8464. found_price, _ := c.GetFloat("found_price")
  8465. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  8466. private_price, _ := c.GetFloat("private_price")
  8467. timeLayout := "2006-01-02"
  8468. loc, _ := time.LoadLocation("Local")
  8469. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  8470. fapiao_code := c.GetString("fapiao_code")
  8471. fapiao_number := c.GetString("fapiao_number")
  8472. diagnosis_id := c.GetString("diagnosis")
  8473. sick_type, _ := c.GetInt64("sick_type")
  8474. reg_type, _ := c.GetInt64("p_type")
  8475. order_id, _ := c.GetInt64("order_id")
  8476. cash_pay := c.GetString("cash_pay")
  8477. wechat_pay := c.GetString("wechat_pay")
  8478. ali_pay := c.GetString("ali_pay")
  8479. jifen_pay := c.GetString("jifen_pay")
  8480. band_card_pay := c.GetString("band_card_pay")
  8481. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  8482. tmp_decimal := c.GetString("tmp_decimal")
  8483. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  8484. var decimal float64 //本次使用的押金
  8485. var errmsg error
  8486. tx := service.XTWriteDB().Begin() //开了事务
  8487. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  8488. defer func() {
  8489. if errmsg != nil {
  8490. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  8491. tx.Rollback()
  8492. } else {
  8493. tx.Commit()
  8494. }
  8495. }()
  8496. fmt.Println("dec_way", dec_way)
  8497. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  8498. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  8499. return
  8500. }
  8501. if len(tmp_decimal) > 0 {
  8502. if tmp_decimal[0] == 45 {
  8503. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  8504. return
  8505. }
  8506. }
  8507. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  8508. fmt.Println(errs)
  8509. decimal = tt
  8510. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  8511. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  8512. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8513. if err != nil {
  8514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8515. return
  8516. }
  8517. recordDateTime := theTime.Unix()
  8518. adminUser := c.GetAdminUserInfo()
  8519. var prescriptions []*models.HisPrescription
  8520. var prescriptionsOne []*models.HisPrescription
  8521. var start_time int64
  8522. var end_time int64
  8523. ids_str := c.GetString("ids")
  8524. ids_arr := strings.Split(ids_str, ",")
  8525. if tempOrder.ID == 0 {
  8526. if settle_accounts_type == 1 { //日结
  8527. fmt.Println(reg_type)
  8528. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  8529. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  8530. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  8531. } else {
  8532. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8533. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8534. }
  8535. } else { //月结
  8536. start_time_str := c.GetString("start_time")
  8537. end_time_str := c.GetString("end_time")
  8538. timeLayout := "2006-01-02"
  8539. loc, _ := time.LoadLocation("Local")
  8540. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  8541. if err != nil {
  8542. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8543. return
  8544. }
  8545. recordStartTime := theStartTime.Unix()
  8546. start_time = recordStartTime
  8547. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  8548. if err != nil {
  8549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8550. return
  8551. }
  8552. recordEndTime := theEndTime.Unix()
  8553. end_time = recordEndTime
  8554. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  8555. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8556. }
  8557. var goods []*models.DialysisBeforePrepareGoods
  8558. var newGoods []*models.NewDialysisBeforePrepareGoods
  8559. var oldGoods []*models.OldDialysisBeforePrepareGoods
  8560. var infos []*models.HisDoctorAdviceInfo
  8561. var infoList []*models.HisDoctorAdviceInfo
  8562. var hisAdvice []*models.HisDoctorAdviceInfo
  8563. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  8564. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  8565. //判断库存不足
  8566. //结算出库开关
  8567. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  8568. if settConfig.IsOpen == 1 {
  8569. //判断库存的地方
  8570. for _, info := range prescriptions {
  8571. if info.Type == 1 {
  8572. infos = append(infos, info.HisDoctorAdviceInfo...)
  8573. }
  8574. if info.Type == 2 {
  8575. for _, sumItem := range info.HisPrescriptionProject {
  8576. if sumItem.Type == 3 {
  8577. var good models.DialysisBeforePrepareGoods
  8578. var newGood models.NewDialysisBeforePrepareGoods
  8579. good.GoodId = sumItem.GoodInfo.ID
  8580. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8581. count, _ := strconv.Atoi(sumItem.Count)
  8582. good.Count = int64(count)
  8583. good.StorehouseId = houseConfig.StorehouseOutInfo
  8584. good.ProjectId = sumItem.ID
  8585. goods = append(goods, &good)
  8586. newGood.GoodId = sumItem.GoodInfo.ID
  8587. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8588. count2, _ := strconv.Atoi(sumItem.Count)
  8589. newGood.Count = int64(count2)
  8590. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8591. newGood.ProjectId = sumItem.ID
  8592. newGoods = append(newGoods, &newGood)
  8593. }
  8594. }
  8595. }
  8596. }
  8597. for _, info := range prescriptionsOne {
  8598. if info.Type == 1 {
  8599. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  8600. }
  8601. if info.Type == 2 {
  8602. for _, sumItem := range info.HisPrescriptionProject {
  8603. if sumItem.Type == 3 {
  8604. var newGood models.NewDialysisBeforePrepareGoods
  8605. newGood.GoodId = sumItem.GoodInfo.ID
  8606. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8607. count2, _ := strconv.Atoi(sumItem.Count)
  8608. newGood.Count = int64(count2)
  8609. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8610. newGood.ProjectId = sumItem.ID
  8611. newGoodOne = append(newGoodOne, &newGood)
  8612. }
  8613. }
  8614. }
  8615. }
  8616. //判断
  8617. for _, itemOne := range infos {
  8618. for _, itemTwo := range hisAdvice {
  8619. if itemOne.DrugId == itemTwo.DrugId {
  8620. itemTwo.Child = append(itemTwo.Child, itemOne)
  8621. }
  8622. }
  8623. }
  8624. for _, itemTwo := range hisAdvice {
  8625. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  8626. var sum_out_count int64
  8627. for _, itemThree := range itemTwo.Child {
  8628. var prescribing_number int64
  8629. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8630. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8631. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8632. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8633. }
  8634. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8635. prescribing_number = parseIntPrescribingNumber
  8636. }
  8637. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8638. prescribing_number = parseIntPrescribingNumber
  8639. }
  8640. sum_out_count += prescribing_number
  8641. }
  8642. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  8643. if sum_out_count > drugStockOut.FlushCount {
  8644. c.ServeSuccessJSON(map[string]interface{}{
  8645. "msg": "2",
  8646. "drug": medical,
  8647. })
  8648. return
  8649. }
  8650. }
  8651. for _, itemOne := range newGoods {
  8652. for _, item := range newGoodOne {
  8653. if itemOne.GoodId == item.GoodId {
  8654. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  8655. }
  8656. }
  8657. }
  8658. for _, item := range newGoodOne {
  8659. var sum_out_count_one int64
  8660. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  8661. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  8662. sum_out_count_one += itemOne.Count
  8663. }
  8664. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8665. fmt.Println("sum_out_count_one", sum_out_count_one)
  8666. fmt.Println("list.FlushCount", list.FlushCount)
  8667. if sum_out_count_one > list.FlushCount {
  8668. c.ServeSuccessJSON(map[string]interface{}{
  8669. "msg": "3",
  8670. "good": good,
  8671. })
  8672. return
  8673. }
  8674. }
  8675. }
  8676. timestamp := time.Now().Unix()
  8677. tempTime := time.Unix(timestamp, 0)
  8678. timeFormat := tempTime.Format("20060102150405")
  8679. chrgBchno := rand.Intn(100000) + 10000
  8680. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  8681. strconv.FormatInt(his.PatientId, 10)
  8682. var ids []int64
  8683. for _, item := range prescriptions {
  8684. ids = append(ids, item.ID)
  8685. }
  8686. var total float64
  8687. for _, item := range prescriptions {
  8688. fmt.Println(item)
  8689. if item.Type == 1 { //药品
  8690. for _, subItem := range item.HisDoctorAdviceInfo {
  8691. total = total + (subItem.Price * subItem.PrescribingNumber)
  8692. }
  8693. }
  8694. if item.Type == 2 { //项目
  8695. for _, subItem := range item.HisPrescriptionProject {
  8696. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8697. total = total + (subItem.Price * cnt)
  8698. }
  8699. }
  8700. for _, subItem := range item.HisAdditionalCharge {
  8701. total = total + (subItem.Price * float64(subItem.Count))
  8702. }
  8703. }
  8704. if reg_type == 1111 || reg_type == 1112 {
  8705. reg_type = 11
  8706. }
  8707. tm := time.Unix(time.Now().Unix(), 0)
  8708. allTotal := fmt.Sprintf("%.4f", total)
  8709. totals, _ := strconv.ParseFloat(allTotal, 64)
  8710. order := &models.HisOrder{
  8711. UserOrgId: adminUser.CurrentOrgId,
  8712. HisPatientId: his.ID,
  8713. PatientId: id,
  8714. SettleAccountsDate: recordDateTime,
  8715. Ctime: time.Now().Unix(),
  8716. Mtime: time.Now().Unix(),
  8717. Status: 1,
  8718. OrderStatus: 2,
  8719. MdtrtId: his.Number,
  8720. Number: chrg_bchno,
  8721. MedfeeSumamt: totals,
  8722. PayWay: pay_way,
  8723. PayWays: pay_ways,
  8724. PayPrice: pay_price,
  8725. MedType: strconv.Itoa(int(reg_type)),
  8726. PayCardNo: pay_card_no,
  8727. DiscountPrice: discount_price,
  8728. PreferentialPrice: preferential_price,
  8729. RealityPrice: reality_price,
  8730. FoundPrice: found_price,
  8731. MedicalInsurancePrice: medical_insurance_price,
  8732. PrivatePrice: private_price,
  8733. SettleEndTime: end_time,
  8734. SettleStartTime: start_time,
  8735. PsnPartAmt: totals,
  8736. PsnCashPay: totals,
  8737. SettleType: settle_accounts_type,
  8738. FaPiaoCode: fapiao_code,
  8739. FaPiaoNumber: fapiao_number,
  8740. Diagnosis: diagnosis_id,
  8741. PType: 2,
  8742. SetlTime: tm.Format("2006-01-02 15:04:05"),
  8743. Decimal: decimal,
  8744. OthDesc: oth_desc,
  8745. CashPay: cash_pay,
  8746. WechatPay: wechat_pay,
  8747. AliPay: ali_pay,
  8748. JifenPay: jifen_pay,
  8749. BandCardPay: band_card_pay,
  8750. Creator: adminUser.AdminUser.Id,
  8751. }
  8752. err = service.CreateOrderTX(order, tx)
  8753. if err != nil {
  8754. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8755. return
  8756. }
  8757. var customs []*Custom
  8758. for _, item := range prescriptions {
  8759. if item.Type == 1 { //药品a
  8760. for _, subItem := range item.HisDoctorAdviceInfo {
  8761. cus := &Custom{
  8762. AdviceId: subItem.ID,
  8763. ProjectId: 0,
  8764. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  8765. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  8766. FeedetlSn: subItem.FeedetlSn,
  8767. Price: fmt.Sprintf("%.4f", subItem.Price),
  8768. MedListCodg: subItem.MedListCodg,
  8769. Type: 1,
  8770. }
  8771. customs = append(customs, cus)
  8772. }
  8773. }
  8774. if item.Type == 2 { //项目
  8775. for _, subItem := range item.HisPrescriptionProject {
  8776. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8777. cus := &Custom{
  8778. AdviceId: 0,
  8779. ProjectId: subItem.ID,
  8780. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  8781. Cut: fmt.Sprintf("%.4f", cnt),
  8782. FeedetlSn: subItem.FeedetlSn,
  8783. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  8784. MedListCodg: subItem.MedListCodg,
  8785. Type: 2,
  8786. }
  8787. customs = append(customs, cus)
  8788. }
  8789. }
  8790. for _, item := range item.HisAdditionalCharge {
  8791. cus := &Custom{
  8792. ItemId: item.ID,
  8793. AdviceId: 0,
  8794. ProjectId: 0,
  8795. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  8796. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  8797. FeedetlSn: item.FeedetlSn,
  8798. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  8799. MedListCodg: item.XtHisAddtionConfig.Code,
  8800. Type: 3,
  8801. }
  8802. customs = append(customs, cus)
  8803. }
  8804. }
  8805. for _, item := range customs {
  8806. var advice_id int64 = 0
  8807. var project_id int64 = 0
  8808. var item_id int64 = 0
  8809. var types int64 = 0
  8810. if item.Type == 1 {
  8811. advice_id = item.AdviceId
  8812. project_id = 0
  8813. item_id = 0
  8814. } else if item.Type == 2 {
  8815. advice_id = 0
  8816. item_id = 0
  8817. project_id = item.ProjectId
  8818. } else if item.Type == 3 {
  8819. advice_id = 0
  8820. item_id = item.ItemId
  8821. project_id = 0
  8822. }
  8823. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8824. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8825. pric, _ := strconv.ParseFloat(item.Price, 32)
  8826. info := &models.HisOrderInfo{
  8827. OrderNumber: order.Number,
  8828. UploadDate: time.Now().Unix(),
  8829. AdviceId: advice_id,
  8830. DetItemFeeSumamt: detItemFeeSumamt,
  8831. Cnt: cut,
  8832. Pric: pric,
  8833. PatientId: id,
  8834. Status: 1,
  8835. Mtime: time.Now().Unix(),
  8836. Ctime: time.Now().Unix(),
  8837. UserOrgId: adminUser.CurrentOrgId,
  8838. HisPatientId: his.ID,
  8839. OrderId: order.ID,
  8840. ProjectId: project_id,
  8841. Type: types,
  8842. ItemId: item_id,
  8843. }
  8844. service.CreateOrderInfoTX(info, tx)
  8845. }
  8846. his.Diagnosis = diagnosis_id
  8847. his.SickType = sick_type
  8848. his.RegisterType = reg_type
  8849. his.MedicalTreatmentType = reg_type
  8850. service.UpdataHisPateintTX(&his, tx)
  8851. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  8852. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  8853. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  8854. //判断是否使用了押金
  8855. if dec_way == "true" {
  8856. tmpstring := strconv.FormatInt(order.ID, 10)
  8857. //扣押金
  8858. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  8859. order.Decimal = decimal
  8860. service.UpDateOrderTwo(order, tx)
  8861. if errmsg != nil {
  8862. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  8863. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8864. return
  8865. }
  8866. }
  8867. if err == nil {
  8868. for _, info := range prescriptions {
  8869. if info.Type == 1 {
  8870. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  8871. }
  8872. if info.Type == 2 {
  8873. for _, sumItem := range info.HisPrescriptionProject {
  8874. if sumItem.Type == 3 {
  8875. var good models.DialysisBeforePrepareGoods
  8876. var newGood models.NewDialysisBeforePrepareGoods
  8877. var oldGood models.OldDialysisBeforePrepareGoods
  8878. good.GoodId = sumItem.GoodInfo.ID
  8879. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8880. count, _ := strconv.Atoi(sumItem.Count)
  8881. good.Count = int64(count)
  8882. good.StorehouseId = houseConfig.StorehouseOutInfo
  8883. good.ProjectId = sumItem.ID
  8884. good.PatientId = sumItem.PatientId
  8885. goods = append(goods, &good)
  8886. newGood.GoodId = sumItem.GoodInfo.ID
  8887. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8888. count2, _ := strconv.Atoi(sumItem.Count)
  8889. newGood.Count = int64(count2)
  8890. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8891. newGood.ProjectId = sumItem.ID
  8892. newGood.PatientId = sumItem.HisPatientId
  8893. newGoods = append(newGoods, &newGood)
  8894. oldGood.GoodId = sumItem.GoodInfo.ID
  8895. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8896. count3, _ := strconv.Atoi(sumItem.Count)
  8897. oldGood.Count = int64(count3)
  8898. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  8899. oldGood.ProjectId = sumItem.ID
  8900. oldGood.RecordDate = sumItem.RecordDate
  8901. oldGood.PatientId = sumItem.HisPatientId
  8902. oldGoods = append(oldGoods, &oldGood)
  8903. }
  8904. }
  8905. }
  8906. }
  8907. if settConfig.IsOpen == 1 {
  8908. for _, item := range infoList {
  8909. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8910. if medical.IsUse == 2 {
  8911. //药品出库
  8912. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  8913. //查询默认仓库
  8914. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  8915. //查询默认仓库剩余多少库存
  8916. var sum_count int64
  8917. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8918. for _, its := range stockInfo {
  8919. if its.MaxUnit == medical.MaxUnit {
  8920. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8921. }
  8922. sum_count += its.StockMaxNumber + its.StockMinNumber
  8923. }
  8924. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8925. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8926. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  8927. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  8928. }
  8929. }
  8930. orgId := c.GetAdminUserInfo().CurrentOrgId
  8931. if len(oldGoods) > 0 {
  8932. timeStr := time.Now().Format("2006-01-02")
  8933. timeArr := strings.Split(timeStr, "-")
  8934. total, _ := service.FindAllWarehouseOut(orgId)
  8935. total = total + 1
  8936. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8937. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8938. number = number + total
  8939. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8940. operation_time := time.Now().Unix()
  8941. creater := c.GetAdminUserInfo().AdminUser.Id
  8942. //查询默认出库仓库库存
  8943. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8944. recordDateStr := time.Now().Format("2006-01-02")
  8945. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8946. nowtime := recordDate.Unix()
  8947. warehouseOut := models.WarehouseOut{
  8948. WarehouseOutOrderNumber: warehousing_out_order,
  8949. OperationTime: operation_time,
  8950. OrgId: orgId,
  8951. Creater: creater,
  8952. Ctime: time.Now().Unix(),
  8953. Status: 1,
  8954. WarehouseOutTime: nowtime,
  8955. Type: 1,
  8956. StorehouseId: storeConfig.StorehouseOutInfo,
  8957. IsCheck: 1,
  8958. OrderId: order.ID,
  8959. IsSys: 5,
  8960. }
  8961. //查询是否生成出库单
  8962. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8963. if out.ID == 0 {
  8964. service.AddSigleWarehouseOut(&warehouseOut)
  8965. }
  8966. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8967. for _, item := range oldGoods {
  8968. dialyPrepareOne := models.DialysisBeforePrepare{
  8969. GoodTypeId: item.GoodTypeId,
  8970. GoodId: item.GoodId,
  8971. PatientId: his.PatientId,
  8972. RecordDate: item.RecordDate,
  8973. UserOrgId: adminUser.CurrentOrgId,
  8974. Count: item.Count,
  8975. Ctime: time.Now().Unix(),
  8976. Creater: adminUser.AdminUser.Id,
  8977. CommdityCode: item.CommdityCode,
  8978. Status: 1,
  8979. StorehouseId: houseConfig.StorehouseOutInfo,
  8980. }
  8981. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  8982. //非零用
  8983. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  8984. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8985. //查询剩余库存
  8986. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8987. var sum_count int64
  8988. for _, item := range goodList {
  8989. sum_count += item.StockCount
  8990. }
  8991. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8992. //耗材
  8993. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8994. }
  8995. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  8996. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8997. //查询剩余库存
  8998. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8999. var sum_count int64
  9000. for _, item := range goodList {
  9001. sum_count += item.StockCount
  9002. }
  9003. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9004. //耗材
  9005. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9006. }
  9007. }
  9008. }
  9009. }
  9010. c.ServeSuccessJSON(map[string]interface{}{
  9011. "msg": "结算成功",
  9012. })
  9013. }
  9014. }
  9015. }
  9016. // 退款
  9017. func (c *HisApiController) Refund() {
  9018. order_id, _ := c.GetInt64("order_id")
  9019. order, _ := service.GetHisOrderByID(order_id)
  9020. adminUser := c.GetAdminUserInfo()
  9021. orgid := c.GetAdminUserInfo().CurrentOrgId
  9022. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  9023. if err != nil {
  9024. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9025. return
  9026. }
  9027. tmp := strconv.FormatInt(order.ID, 10)
  9028. //当押金不为零时产生退费记录
  9029. if order.Decimal != 0 {
  9030. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  9031. if err != nil {
  9032. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9033. return
  9034. }
  9035. }
  9036. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  9037. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  9038. var goods []*models.DialysisBeforePrepareGoods
  9039. var newGoods []*models.NewDialysisBeforePrepareGoods
  9040. var infos []*models.HisDoctorAdviceInfo
  9041. for _, info := range orders {
  9042. if info.AdviceId > 0 && info.ProjectId == 0 {
  9043. infos = append(infos, &info.HisDoctorAdviceInfo)
  9044. }
  9045. if info.ProjectId > 0 && info.AdviceId == 0 {
  9046. if info.HisPrescriptionProject.Type == 3 {
  9047. var good models.DialysisBeforePrepareGoods
  9048. var newGood models.NewDialysisBeforePrepareGoods
  9049. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9050. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9051. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9052. good.Count = int64(count)
  9053. good.StorehouseId = houseConfig.StorehouseOutInfo
  9054. good.ProjectId = info.HisPrescriptionProject.ID
  9055. good.PatientId = info.PatientId
  9056. good.OrderId = order_id
  9057. goods = append(goods, &good)
  9058. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9059. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9060. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9061. newGood.Count = int64(count2)
  9062. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9063. newGood.ProjectId = info.HisPrescriptionProject.ID
  9064. newGood.RecordDate = order.SettleAccountsDate
  9065. newGood.UserOrgId = order.UserOrgId
  9066. newGood.PatientId = info.PatientId
  9067. newGood.OrderId = order_id
  9068. newGoods = append(newGoods, &newGood)
  9069. }
  9070. }
  9071. }
  9072. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9073. if settConfig.IsOpen == 1 {
  9074. for _, item := range infos {
  9075. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9076. }
  9077. for _, item := range newGoods {
  9078. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9079. }
  9080. }
  9081. c.ServeSuccessJSON(map[string]interface{}{
  9082. "msg": "退费成功",
  9083. })
  9084. }
  9085. func (c *HisApiController) RefundNumber() {
  9086. his_patient_id, _ := c.GetInt64("id")
  9087. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9088. info.Status = 0
  9089. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  9090. if count > 0 {
  9091. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  9092. return
  9093. }
  9094. err := service.SaveHisPatient(info)
  9095. if err == nil {
  9096. c.ServeSuccessJSON(map[string]interface{}{
  9097. "msg": "退号成功",
  9098. })
  9099. } else {
  9100. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9101. return
  9102. }
  9103. }
  9104. func (this *HisApiController) AdditionalCharge() {
  9105. dataBody := make(map[string]interface{}, 0)
  9106. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  9107. fmt.Println(err)
  9108. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  9109. patient_id := int64(dataBody["patient_id"].(float64))
  9110. medicineData, _ := dataBody["medicineData"].([]interface{})
  9111. adminUserInfo := this.GetAdminUserInfo()
  9112. orgId := adminUserInfo.CurrentOrgId
  9113. admin_user_id := adminUserInfo.AdminUser.Id
  9114. timeStr := time.Now().Format("2006-01-02")
  9115. timeLayout := "2006-01-02 15:04:05"
  9116. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9117. timenow := timeStringToTime.Unix()
  9118. var additionalCharges []*models.HisAdditionalCharge
  9119. for _, item := range medicineData {
  9120. var randNum int
  9121. randNum = rand.Intn(10000) + 1000
  9122. timestamp := time.Now().Unix()
  9123. tempTime := time.Unix(timestamp, 0)
  9124. timeFormat := tempTime.Format("20060102150405")
  9125. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  9126. items := item.(map[string]interface{})
  9127. money := items["price"].(string)
  9128. item_id_str := items["item_id"].(string)
  9129. name := items["name"].(string)
  9130. id_str := items["id"].(string)
  9131. moneys, _ := strconv.ParseInt(money, 10, 64)
  9132. monStr := strconv.FormatInt(moneys, 10)
  9133. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  9134. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  9135. id, _ := strconv.ParseInt(id_str, 10, 64)
  9136. additionalCharge := &models.HisAdditionalCharge{
  9137. ID: id,
  9138. HisPatientId: his_patient_id,
  9139. UserOrgId: orgId,
  9140. PatientId: patient_id,
  9141. RecordDate: timenow,
  9142. Price: monneyStr,
  9143. Status: 1,
  9144. ItemName: name,
  9145. ItemId: item_id,
  9146. AdminUserId: admin_user_id,
  9147. CreatedTime: time.Now().Unix(),
  9148. OrderStatus: 0,
  9149. PrescriptionNumber: "",
  9150. BatchNumber: "",
  9151. FeedetlSn: p_number,
  9152. }
  9153. service.CreateAdditionalCharge(additionalCharge)
  9154. additionalCharges = append(additionalCharges, additionalCharge)
  9155. }
  9156. this.ServeSuccessJSON(map[string]interface{}{
  9157. "msg": "添加成功",
  9158. "additional_charges": additionalCharges,
  9159. })
  9160. }
  9161. func (this *HisApiController) DeleteAddition() {
  9162. id, _ := this.GetInt64("id")
  9163. //TODO 需要判断是否已经结算
  9164. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  9165. if err == nil {
  9166. this.ServeSuccessJSON(map[string]interface{}{
  9167. "msg": "删除成功",
  9168. })
  9169. return
  9170. } else {
  9171. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9172. return
  9173. }
  9174. }
  9175. func (this *HisApiController) GetAdminUsers() {
  9176. adminUser := this.GetAdminUserInfo()
  9177. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  9178. this.ServeSuccessJSON(map[string]interface{}{
  9179. "doctors": doctors,
  9180. })
  9181. }
  9182. func (this *HisApiController) GetLastOrNextHisPrescription() {
  9183. change_type, _ := this.GetInt64("type", 0)
  9184. record_date := this.GetString("record_time")
  9185. patient_id, _ := this.GetInt64("patient_id", 0)
  9186. p_type, _ := this.GetInt64("p_type", 0)
  9187. timeLayout := "2006-01-02"
  9188. loc, _ := time.LoadLocation("Local")
  9189. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  9190. record_time := theAdviceRecordTime.Unix()
  9191. adminUserInfo := this.GetAdminUserInfo()
  9192. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  9193. if adminUserInfo.CurrentOrgId == 10265 {
  9194. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9195. if config.ID > 0 && config.IsOpen == 1 {
  9196. for _, subitems := range prescriptions {
  9197. for _, item := range subitems.VMHisPrescription {
  9198. for _, subItem := range item.HisDoctorAdviceInfo {
  9199. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9200. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9201. if info.RetailPrice > 0 {
  9202. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9203. subItem.Drug.RetailPrice = drug.RetailPrice
  9204. }
  9205. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9206. subItem.Drug.MinPrice = info.RetailPrice
  9207. subItem.Drug.RetailPrice = info.RetailPrice
  9208. }
  9209. }
  9210. }
  9211. }
  9212. }
  9213. }
  9214. if config.ID > 0 && config.IsOpen == 1 {
  9215. for _, subitems := range prescriptions {
  9216. for _, item := range subitems.VMHisPrescription {
  9217. for _, subItem := range item.HisPrescriptionProject {
  9218. if subItem.Type == 3 {
  9219. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9220. if info.Price > 0 {
  9221. subItem.GoodInfo.PackingPrice = info.Price
  9222. }
  9223. }
  9224. }
  9225. }
  9226. }
  9227. }
  9228. }
  9229. if err == nil {
  9230. if len(prescriptions) == 0 {
  9231. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  9232. return
  9233. } else {
  9234. this.ServeSuccessJSON(map[string]interface{}{
  9235. "prescriptions": prescriptions,
  9236. })
  9237. return
  9238. }
  9239. } else {
  9240. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9241. return
  9242. }
  9243. }
  9244. func (this *HisApiController) GetCallHisPrescription() {
  9245. patient_id, _ := this.GetInt64("patient_id", 0)
  9246. timeLayout := "2006-01-02"
  9247. loc, _ := time.LoadLocation("Local")
  9248. start_time := this.GetString("start_time")
  9249. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9250. end_time := this.GetString("end_time")
  9251. p_type, _ := this.GetInt64("p_type")
  9252. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9253. adminUserInfo := this.GetAdminUserInfo()
  9254. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  9255. //if
  9256. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  9257. //
  9258. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  9259. if adminUserInfo.CurrentOrgId == 10265 {
  9260. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9261. if config.ID > 0 && config.IsOpen == 1 {
  9262. for _, subitems := range prescriptions {
  9263. for _, item := range subitems.VMHisPrescription {
  9264. for _, subItem := range item.HisDoctorAdviceInfo {
  9265. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9266. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9267. if info.RetailPrice > 0 {
  9268. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9269. subItem.Drug.RetailPrice = drug.RetailPrice
  9270. }
  9271. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9272. subItem.Drug.MinPrice = info.RetailPrice
  9273. subItem.Drug.RetailPrice = info.RetailPrice
  9274. }
  9275. }
  9276. }
  9277. }
  9278. }
  9279. }
  9280. if config.ID > 0 && config.IsOpen == 1 {
  9281. for _, subitems := range prescriptions {
  9282. for _, item := range subitems.VMHisPrescription {
  9283. for _, subItem := range item.HisPrescriptionProject {
  9284. if subItem.Type == 3 {
  9285. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9286. if info.Price > 0 {
  9287. subItem.GoodInfo.PackingPrice = info.Price
  9288. }
  9289. }
  9290. }
  9291. }
  9292. }
  9293. }
  9294. }
  9295. if err == nil {
  9296. this.ServeSuccessJSON(map[string]interface{}{
  9297. "prescriptions": prescriptions,
  9298. })
  9299. return
  9300. } else {
  9301. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9302. return
  9303. }
  9304. }
  9305. func (this *HisApiController) GetHisDayPrescription() {
  9306. timeLayout := "2006-01-02"
  9307. loc, _ := time.LoadLocation("Local")
  9308. start_time := this.GetString("start_time")
  9309. patient_id, _ := this.GetInt64("patient_id", 0)
  9310. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9311. end_time := this.GetString("end_time")
  9312. p_type, _ := this.GetInt64("p_type")
  9313. order_status, _ := this.GetInt64("type")
  9314. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9315. adminUserInfo := this.GetAdminUserInfo()
  9316. var dayHisPrescription []*models.HisPrescription
  9317. var err error
  9318. if order_status == 1 || order_status == 0 {
  9319. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  9320. } else if order_status == 2 {
  9321. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  9322. }
  9323. var settle_total float64
  9324. for _, item := range dayHisPrescription {
  9325. if len(item.HisPrescriptionProject) > 0 {
  9326. for _, subItem := range item.HisPrescriptionProject {
  9327. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9328. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9329. settle_total = settle_total + total
  9330. }
  9331. }
  9332. if len(item.HisDoctorAdviceInfo) > 0 {
  9333. for _, subItem := range item.HisDoctorAdviceInfo {
  9334. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9335. settle_total = settle_total + total
  9336. }
  9337. }
  9338. }
  9339. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9340. if err == nil {
  9341. this.ServeSuccessJSON(map[string]interface{}{
  9342. "day_prescription": dayHisPrescription,
  9343. "settle_total": settle_total,
  9344. })
  9345. return
  9346. } else {
  9347. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9348. return
  9349. }
  9350. }
  9351. func (c *HisApiController) GetHisChargePatientList() {
  9352. record_date := c.GetString("record_date")
  9353. order_status, _ := c.GetInt64("type")
  9354. sch_type, _ := c.GetInt64("sch_type")
  9355. timeLayout := "2006-01-02"
  9356. loc, _ := time.LoadLocation("Local")
  9357. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9358. if err != nil {
  9359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9360. return
  9361. }
  9362. recordDateTime := theTime.Unix()
  9363. adminInfo := c.GetAdminUserInfo()
  9364. var tempPatients []*service.NewTempPatients
  9365. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  9366. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  9367. if order_status != 2 {
  9368. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9369. } else {
  9370. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9371. }
  9372. } else {
  9373. if order_status != 2 {
  9374. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9375. } else {
  9376. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9377. }
  9378. }
  9379. var patients []*service.NewTempPatients
  9380. var patients_two []*service.NewTempPatients
  9381. for _, item := range tempPatients {
  9382. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  9383. //过滤掉没挂号的和没开处方的
  9384. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  9385. patients = append(patients, item)
  9386. }
  9387. //过滤掉没挂号的
  9388. if len(item.HisPatient) > 0 {
  9389. patients_two = append(patients_two, item)
  9390. }
  9391. } else {
  9392. if len(item.HisPrescription) > 0 {
  9393. patients = append(patients, item)
  9394. }
  9395. }
  9396. }
  9397. c.ServeSuccessJSON(map[string]interface{}{
  9398. "list": patients,
  9399. "list_two": patients_two,
  9400. })
  9401. }
  9402. func (c *HisApiController) GetHisUnRegisterPatientList() {
  9403. record_date := c.GetString("record_date")
  9404. timeLayout := "2006-01-02"
  9405. loc, _ := time.LoadLocation("Local")
  9406. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9407. if err != nil {
  9408. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9409. return
  9410. }
  9411. recordDateTime := theTime.Unix()
  9412. adminUser := c.GetAdminUserInfo()
  9413. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  9414. var patients []*service.Patients
  9415. for _, item := range tempPatients {
  9416. if item.HisPatient.ID == 0 {
  9417. patients = append(patients, item)
  9418. }
  9419. }
  9420. c.ServeSuccessJSON(map[string]interface{}{
  9421. "list": patients,
  9422. //"list_two": patients_two,
  9423. })
  9424. }
  9425. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  9426. newArr = make([]*service.Patients, 0)
  9427. for i := 0; i < len(patient); i++ {
  9428. repeat := false
  9429. for j := i + 1; j < len(patient); j++ {
  9430. if patient[i].ID == patient[j].ID {
  9431. repeat = true
  9432. break
  9433. }
  9434. }
  9435. if !repeat {
  9436. newArr = append(newArr, patient[i])
  9437. }
  9438. }
  9439. return
  9440. }
  9441. func (c *HisApiController) GetHisChargePatientInfo() {
  9442. patient_id, _ := c.GetInt64("patient_id")
  9443. his_patient_id, _ := c.GetInt64("his_patient_id")
  9444. record_date := c.GetString("record_date")
  9445. //start_time := c.GetString("start_time")
  9446. //end_time := c.GetString("end_time")
  9447. order_status, _ := c.GetInt64("type", 0)
  9448. p_type, _ := c.GetInt64("p_type", 0)
  9449. order_id, _ := c.GetInt64("order_id", 0)
  9450. timeLayout := "2006-01-02"
  9451. loc, _ := time.LoadLocation("Local")
  9452. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9453. if err != nil {
  9454. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9455. return
  9456. }
  9457. recordDateTime := theTime.Unix()
  9458. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9459. //if err != nil {
  9460. //
  9461. //}
  9462. //startRecordDateTime := startTime.Unix()
  9463. //
  9464. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9465. //if err != nil {
  9466. //
  9467. //}
  9468. //endRecordDateTime := endTime.Unix()
  9469. admin := c.GetAdminUserInfo()
  9470. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9471. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9472. var prescriptions []*models.HisPrescription
  9473. //var unChargeMonthPrescriptions []*models.HisPrescription
  9474. order, _ := service.GetHisOrderByID(order_id)
  9475. if order_status == 1 || order_status == 0 {
  9476. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  9477. } else if order_status == 2 {
  9478. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  9479. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9480. }
  9481. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9482. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9483. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9484. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9485. //获取所有科室信息
  9486. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9487. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  9488. c.ServeSuccessJSON(map[string]interface{}{
  9489. "his_info": his_patient_info,
  9490. "xt_info": xt_patient_info,
  9491. "prescription": prescriptions,
  9492. "case_history": case_history,
  9493. "info": patientPrescriptionInfo,
  9494. "last_info": lastPatientPrescriptionInfo,
  9495. "order": order,
  9496. "doctors": doctors,
  9497. "department": department,
  9498. "sch": sch,
  9499. })
  9500. return
  9501. }
  9502. func (c *HisApiController) GetAllOrderDetail() {
  9503. order_id, _ := c.GetInt64("id", 0)
  9504. order, _ := service.GetHisOrderByID(order_id)
  9505. if order.ID == 0 {
  9506. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9507. return
  9508. }
  9509. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9510. org_id := c.GetAdminUserInfo().CurrentOrgId
  9511. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9512. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9513. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9514. c.ServeSuccessJSON(map[string]interface{}{
  9515. "order": order,
  9516. "order_info": order_info,
  9517. "patient": patient,
  9518. "admin_info": adminInfo,
  9519. "hospital_record": record,
  9520. })
  9521. return
  9522. }
  9523. func (c *HisApiController) GetAllOrderDetailCollect() {
  9524. order_id, _ := c.GetInt64("id", 0)
  9525. order, _ := service.GetHisOrderByID(order_id)
  9526. if order.ID == 0 {
  9527. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9528. return
  9529. }
  9530. org_id := c.GetAdminUserInfo().CurrentOrgId
  9531. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9532. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9533. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9534. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  9535. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  9536. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9537. var bedCostTotal float64 = 0 //床位总费
  9538. //var bedCostSelfTotal float64 = 0 //床位自费
  9539. var operationCostTotal float64 = 0 //手术费
  9540. //var operationCostSelfTotal float64 = 0 //手术费
  9541. var otherCostTotal float64 = 0 //其他费用
  9542. //var otherCostSelfTotal float64 = 0 //其他费用
  9543. var materialCostTotal float64 = 0 //材料费
  9544. //var materialCostSelfTotal float64 = 0 //材料费
  9545. var westernMedicineCostTotal float64 = 0 //西药费
  9546. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  9547. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9548. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9549. var checkCostTotal float64 = 0 //检查费
  9550. //var checkCostSelfTotal float64 = 0 //检查费
  9551. var laboratoryCostTotal float64 = 0 //化验费
  9552. //var laboratoryCostSelfTotal float64 = 0 //化验费
  9553. var treatCostTotal float64 = 0 //治疗费用
  9554. //var treatCostSelfTotal float64 = 0 //治疗费用
  9555. var zhenChaCostTotal float64 = 0 //其他费用
  9556. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9557. decimal.DivisionPrecision = 2
  9558. var BalanceAccountsType int64
  9559. if his.ID > 0 {
  9560. BalanceAccountsType = his.BalanceAccountsType
  9561. } else {
  9562. BalanceAccountsType = record.BalanceAccountsType
  9563. }
  9564. if BalanceAccountsType != 2 {
  9565. for _, item := range order_info {
  9566. if org_id == 10215 {
  9567. if item.MedChrgitmType == "01" { //床位费
  9568. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9569. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9570. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9571. }
  9572. if item.MedChrgitmType == "02" { //诊察费
  9573. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9574. //zhenChaCostSelfTotal = zhenChaCostTotal
  9575. }
  9576. if item.MedChrgitmType == "03" { //检查费
  9577. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9578. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9579. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9580. }
  9581. //if item.MedChrgitmType == "02" { //检查费
  9582. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9583. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9584. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9585. //}
  9586. if item.MedChrgitmType == "04" { //化验费
  9587. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9588. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9589. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9590. }
  9591. if item.MedChrgitmType == "05" { //治疗费
  9592. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9593. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9594. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9595. }
  9596. if item.MedChrgitmType == "06" { //手术费
  9597. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9598. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9599. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9600. }
  9601. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9602. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9603. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9604. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9605. }
  9606. if item.MedChrgitmType == "09" { //西药费
  9607. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9608. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9609. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9610. }
  9611. if item.MedChrgitmType == "11" { //中成费
  9612. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9613. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9614. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9615. }
  9616. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9617. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9618. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9619. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9620. }
  9621. } else if org_id == 10188 || org_id == 10217 {
  9622. if item.MedChrgitmType == "01" { //床位费
  9623. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9624. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9625. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9626. }
  9627. if item.MedChrgitmType == "02" { //诊察费
  9628. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9629. //zhenChaCostSelfTotal = zhenChaCostTotal
  9630. }
  9631. if item.MedChrgitmType == "03" { //检查费
  9632. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9633. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9634. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9635. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9636. }
  9637. //if item.MedChrgitmType == "02" { //检查费
  9638. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9639. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9640. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9641. //}
  9642. if item.MedChrgitmType == "04" { //化验费
  9643. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9644. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9645. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9646. }
  9647. if item.MedChrgitmType == "05" { //治疗费
  9648. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9649. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9650. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9651. }
  9652. if item.MedChrgitmType == "06" { //手术费
  9653. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9654. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9655. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9656. }
  9657. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9658. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9659. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9660. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9661. }
  9662. if item.MedChrgitmType == "09" { //西药费
  9663. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9664. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9665. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9666. }
  9667. if item.MedChrgitmType == "11" { //中成费
  9668. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9669. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9670. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9671. }
  9672. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9673. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9674. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9675. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9676. }
  9677. } else {
  9678. if item.MedChrgitmType == "01" { //床位费
  9679. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9680. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9681. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9682. }
  9683. //if item.MedChrgitmType == "02" { //诊察费
  9684. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9685. // //zhenChaCostSelfTotal = zhenChaCostTotal
  9686. //}
  9687. if item.MedChrgitmType == "03" { //检查费
  9688. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9689. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9690. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9691. }
  9692. //if item.MedChrgitmType == "02" { //检查费
  9693. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9694. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9695. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9696. //}
  9697. if item.MedChrgitmType == "04" { //化验费
  9698. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9699. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9700. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9701. }
  9702. if item.MedChrgitmType == "05" { //治疗费
  9703. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9704. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9705. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9706. }
  9707. if item.MedChrgitmType == "06" { //手术费
  9708. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9709. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9710. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9711. }
  9712. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9713. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9714. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9715. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9716. }
  9717. if item.MedChrgitmType == "09" { //西药费
  9718. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9719. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9720. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9721. }
  9722. if item.MedChrgitmType == "11" { //中成费
  9723. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9724. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9725. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9726. }
  9727. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9728. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9729. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9730. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9731. }
  9732. }
  9733. }
  9734. c.ServeSuccessJSON(map[string]interface{}{
  9735. "order": order,
  9736. "order_info": order_info,
  9737. "patient": patient,
  9738. "admin_info": adminInfo,
  9739. "his_hospital": record,
  9740. "bedCostTotal": bedCostTotal,
  9741. "operationCostTotal": operationCostTotal,
  9742. "otherCostTotal": otherCostTotal,
  9743. "materialCostTotal": materialCostTotal,
  9744. "westernMedicineCostTotal": westernMedicineCostTotal,
  9745. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9746. "checkCostTotal": checkCostTotal,
  9747. "zhenChaCostTotal": zhenChaCostTotal,
  9748. "laboratoryCostTotal": laboratoryCostTotal,
  9749. "treatCostTotal": treatCostTotal,
  9750. })
  9751. } else {
  9752. for _, item := range order_info {
  9753. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9754. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9755. item.MedChrgitmType = "09"
  9756. }
  9757. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9758. if item.HisPrescriptionProject.Type == 2 {
  9759. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9760. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9761. case 0:
  9762. item.MedChrgitmType = "0"
  9763. break
  9764. case 1:
  9765. item.MedChrgitmType = "14"
  9766. break
  9767. case 2:
  9768. item.MedChrgitmType = "05"
  9769. break
  9770. case 3:
  9771. item.MedChrgitmType = "03"
  9772. break
  9773. case 4:
  9774. item.MedChrgitmType = "03"
  9775. break
  9776. case 5:
  9777. item.MedChrgitmType = "08"
  9778. break
  9779. case 6:
  9780. item.MedChrgitmType = "14"
  9781. break
  9782. case 7:
  9783. item.MedChrgitmType = "14"
  9784. break
  9785. case 8:
  9786. item.MedChrgitmType = "03"
  9787. break
  9788. case 9:
  9789. item.MedChrgitmType = "14"
  9790. break
  9791. case 10:
  9792. item.MedChrgitmType = "14"
  9793. break
  9794. case 11:
  9795. item.MedChrgitmType = "06"
  9796. break
  9797. case 12:
  9798. item.MedChrgitmType = "12"
  9799. break
  9800. case 13:
  9801. item.MedChrgitmType = "01"
  9802. break
  9803. case 14:
  9804. item.MedChrgitmType = "04"
  9805. break
  9806. case 15:
  9807. item.MedChrgitmType = "14"
  9808. break
  9809. }
  9810. } else {
  9811. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9812. case 1:
  9813. item.MedChrgitmType = "14"
  9814. break
  9815. case 2:
  9816. item.MedChrgitmType = "05"
  9817. break
  9818. case 3:
  9819. item.MedChrgitmType = "04"
  9820. break
  9821. case 4:
  9822. item.MedChrgitmType = "14"
  9823. break
  9824. case 5:
  9825. item.MedChrgitmType = "08"
  9826. break
  9827. case 6:
  9828. item.MedChrgitmType = "14"
  9829. break
  9830. case 7:
  9831. item.MedChrgitmType = "14"
  9832. break
  9833. case 8:
  9834. item.MedChrgitmType = "03"
  9835. break
  9836. case 9:
  9837. item.MedChrgitmType = "14"
  9838. break
  9839. }
  9840. }
  9841. } else if item.HisPrescriptionProject.Type == 3 {
  9842. item.MedChrgitmType = "08"
  9843. }
  9844. }
  9845. }
  9846. for _, item := range order_info {
  9847. if org_id == 10215 {
  9848. if item.MedChrgitmType == "01" { //床位费
  9849. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9850. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9851. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9852. }
  9853. if item.MedChrgitmType == "02" { //诊察费
  9854. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9855. //zhenChaCostSelfTotal = zhenChaCostTotal
  9856. }
  9857. if item.MedChrgitmType == "03" { //检查费
  9858. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9859. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9860. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9861. }
  9862. //if item.MedChrgitmType == "02" { //检查费
  9863. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9864. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9865. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9866. //}
  9867. if item.MedChrgitmType == "04" { //化验费
  9868. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9869. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9870. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9871. }
  9872. if item.MedChrgitmType == "05" { //治疗费
  9873. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9874. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9875. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9876. }
  9877. if item.MedChrgitmType == "06" { //手术费
  9878. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9879. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9880. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9881. }
  9882. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9883. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9884. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9885. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9886. }
  9887. if item.MedChrgitmType == "09" { //西药费
  9888. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9889. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9890. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9891. }
  9892. if item.MedChrgitmType == "11" { //中成费
  9893. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9894. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9895. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9896. }
  9897. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9898. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9899. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9900. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9901. }
  9902. } else {
  9903. if item.MedChrgitmType == "01" { //床位费
  9904. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9905. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9906. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9907. }
  9908. //if item.MedChrgitmType == "02" { //诊察费
  9909. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9910. // //zhenChaCostSelfTotal = zhenChaCostTotal
  9911. //}
  9912. if item.MedChrgitmType == "03" { //检查费
  9913. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9914. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9915. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9916. }
  9917. //if item.MedChrgitmType == "02" { //检查费
  9918. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9919. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9920. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9921. //}
  9922. if item.MedChrgitmType == "04" { //化验费
  9923. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9924. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9925. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9926. }
  9927. if item.MedChrgitmType == "05" { //治疗费
  9928. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9929. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9930. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9931. }
  9932. if item.MedChrgitmType == "06" { //手术费
  9933. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9934. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9935. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9936. }
  9937. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9938. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9939. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9940. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9941. }
  9942. if item.MedChrgitmType == "09" { //西药费
  9943. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9944. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9945. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9946. }
  9947. if item.MedChrgitmType == "11" { //中成费
  9948. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9949. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9950. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9951. }
  9952. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9953. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9954. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9955. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9956. }
  9957. }
  9958. }
  9959. c.ServeSuccessJSON(map[string]interface{}{
  9960. "order": order,
  9961. "order_info": order_info,
  9962. "patient": patient,
  9963. "admin_info": adminInfo,
  9964. "his_hospital": record,
  9965. "bedCostTotal": bedCostTotal,
  9966. "operationCostTotal": operationCostTotal,
  9967. "otherCostTotal": otherCostTotal,
  9968. "materialCostTotal": materialCostTotal,
  9969. "westernMedicineCostTotal": westernMedicineCostTotal,
  9970. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9971. "checkCostTotal": checkCostTotal,
  9972. "zhenChaCostTotal": zhenChaCostTotal,
  9973. "laboratoryCostTotal": laboratoryCostTotal,
  9974. "treatCostTotal": treatCostTotal,
  9975. })
  9976. }
  9977. }
  9978. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  9979. page, _ := c.GetInt64("page")
  9980. limit, _ := c.GetInt64("limit")
  9981. keywords := c.GetString("keywords")
  9982. start_time := c.GetString("start_time")
  9983. end_time := c.GetString("end_time")
  9984. //clr_type := c.GetString("clr_type")
  9985. insutype := c.GetString("insutype")
  9986. timeLayout := "2006-01-02"
  9987. loc, _ := time.LoadLocation("Local")
  9988. var theStartTIme int64
  9989. if len(start_time) > 0 {
  9990. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9991. theStartTIme = theTime.Unix()
  9992. }
  9993. var theEndtTIme int64
  9994. if len(end_time) > 0 {
  9995. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9996. theEndtTIme = theTime.Unix()
  9997. }
  9998. if page <= 0 {
  9999. page = 1
  10000. }
  10001. if limit <= 0 {
  10002. limit = 10
  10003. }
  10004. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  10005. c.ServeSuccessJSON(map[string]interface{}{
  10006. "total": total,
  10007. "list": list,
  10008. })
  10009. return
  10010. }
  10011. func (c *HisApiController) GetPutOnRecordList() {
  10012. page, _ := c.GetInt64("page")
  10013. limit, _ := c.GetInt64("limit")
  10014. keywords := c.GetString("keywords")
  10015. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  10016. if page <= 0 {
  10017. page = 1
  10018. }
  10019. if limit <= 0 {
  10020. limit = 10
  10021. }
  10022. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  10023. c.ServeSuccessJSON(map[string]interface{}{
  10024. "total": total,
  10025. "list": list,
  10026. })
  10027. return
  10028. }
  10029. func (c *HisApiController) GetCompareData() {
  10030. start_time := c.GetString("start_time")
  10031. end_time := c.GetString("end_time")
  10032. insutype := c.GetString("insutype")
  10033. clr_type := c.GetString("clr_type")
  10034. timeLayout := "2006-01-02"
  10035. loc, _ := time.LoadLocation("Local")
  10036. var theStartTIme int64
  10037. if len(start_time) > 0 {
  10038. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10039. if err != nil {
  10040. theStartTIme = 0
  10041. }
  10042. theStartTIme = theTime.Unix()
  10043. }
  10044. var theEndtTIme int64
  10045. if len(end_time) > 0 {
  10046. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10047. if err != nil {
  10048. theEndtTIme = 0
  10049. }
  10050. theEndtTIme = theTime.Unix()
  10051. }
  10052. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  10053. fmt.Println(err)
  10054. if err == nil {
  10055. c.ServeSuccessJSON(map[string]interface{}{
  10056. "list": formData,
  10057. })
  10058. } else {
  10059. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10060. return
  10061. }
  10062. }
  10063. func (c *HisApiController) GetFaPiaoData() {
  10064. order_id, _ := c.GetInt64("order_id")
  10065. patient_id, _ := c.GetInt64("patient_id")
  10066. //number := c.GetString("number")
  10067. adminUser := c.GetAdminUserInfo()
  10068. order, _ := service.GetHisOrderByID(order_id)
  10069. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10070. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10071. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10072. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10073. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  10074. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  10075. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10076. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10077. var bedCostTotal float64 = 0 //床位总费
  10078. var bedCostSelfTotal float64 = 0 //床位自费
  10079. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10080. var operationCostTotal float64 = 0 //手术费
  10081. var operationCostSelfTotal float64 = 0 //手术费
  10082. var operationCostPartSelfTotal float64 = 0 //手术费
  10083. var otherCostTotal float64 = 0 //其他费用
  10084. var otherCostSelfTotal float64 = 0 //其他费用
  10085. var otherCostPartSelfTotal float64 = 0 //其他费用
  10086. var materialCostTotal float64 = 0 //材料费
  10087. var materialCostSelfTotal float64 = 0 //材料费
  10088. var materialCostPartSelfTotal float64 = 0 //材料费
  10089. var westernMedicineCostTotal float64 = 0 //西药费
  10090. var westernMedicineCostSelfTotal float64 = 0 //西药费
  10091. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10092. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10093. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10094. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10095. var checkCostTotal float64 = 0 //检查费
  10096. var checkCostSelfTotal float64 = 0 //检查费
  10097. var checkCostPartSelfTotal float64 = 0 //检查费
  10098. var hiliCostTotal float64 = 0 //护理费
  10099. var hiliCostSelfTotal float64 = 0 //护理费
  10100. var hiliCostPartSelfTotal float64 = 0 //护理费
  10101. var laboratoryCostTotal float64 = 0 //化验费
  10102. var laboratoryCostSelfTotal float64 = 0 //化验费
  10103. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10104. var treatCostTotal float64 = 0 //治疗费用
  10105. var treatCostSelfTotal float64 = 0 //治疗费用
  10106. var treatCostPartSelfTotal float64 = 0 //治疗费用
  10107. var zhenChaCostTotal float64 = 0 //其他费用
  10108. var zhenChaCostSelfTotal float64 = 0 //其他费用
  10109. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10110. decimal.DivisionPrecision = 2
  10111. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10112. var balanceAccountsType int64
  10113. if his.ID > 0 {
  10114. balanceAccountsType = his.BalanceAccountsType
  10115. } else {
  10116. balanceAccountsType = his_hospital_record.BalanceAccountsType
  10117. }
  10118. if balanceAccountsType == 2 {
  10119. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10120. for _, item := range orderInfos_two {
  10121. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10122. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10123. item.MedChrgitmType = "09"
  10124. }
  10125. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10126. if item.HisPrescriptionProject.Type == 2 {
  10127. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10128. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10129. case 0:
  10130. item.MedChrgitmType = "0"
  10131. break
  10132. case 1:
  10133. item.MedChrgitmType = "14"
  10134. break
  10135. case 2:
  10136. item.MedChrgitmType = "05"
  10137. break
  10138. case 3:
  10139. item.MedChrgitmType = "03"
  10140. break
  10141. case 4:
  10142. item.MedChrgitmType = "03"
  10143. break
  10144. case 5:
  10145. item.MedChrgitmType = "08"
  10146. break
  10147. case 6:
  10148. item.MedChrgitmType = "14"
  10149. break
  10150. case 7:
  10151. item.MedChrgitmType = "14"
  10152. break
  10153. case 8:
  10154. item.MedChrgitmType = "03"
  10155. break
  10156. case 9:
  10157. item.MedChrgitmType = "14"
  10158. break
  10159. case 10:
  10160. item.MedChrgitmType = "14"
  10161. break
  10162. case 11:
  10163. item.MedChrgitmType = "06"
  10164. break
  10165. case 12:
  10166. item.MedChrgitmType = "12"
  10167. break
  10168. case 13:
  10169. item.MedChrgitmType = "01"
  10170. break
  10171. case 14:
  10172. item.MedChrgitmType = "04"
  10173. break
  10174. case 15:
  10175. item.MedChrgitmType = "02"
  10176. break
  10177. }
  10178. } else {
  10179. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10180. case 1:
  10181. item.MedChrgitmType = "14"
  10182. break
  10183. case 2:
  10184. item.MedChrgitmType = "05"
  10185. break
  10186. case 3:
  10187. item.MedChrgitmType = "04"
  10188. break
  10189. case 4:
  10190. item.MedChrgitmType = "03"
  10191. break
  10192. case 5:
  10193. item.MedChrgitmType = "08"
  10194. break
  10195. case 6:
  10196. item.MedChrgitmType = "14"
  10197. break
  10198. case 7:
  10199. item.MedChrgitmType = "14"
  10200. break
  10201. case 8:
  10202. item.MedChrgitmType = "03"
  10203. break
  10204. case 9:
  10205. item.MedChrgitmType = "14"
  10206. break
  10207. }
  10208. }
  10209. } else if item.HisPrescriptionProject.Type == 3 {
  10210. item.MedChrgitmType = "08"
  10211. }
  10212. }
  10213. }
  10214. for _, item := range orderInfos_two {
  10215. fmt.Println(item.MedChrgitmType)
  10216. if item.MedChrgitmType == "07" { //床位费
  10217. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10218. hiliCostSelfTotal = hiliCostTotal
  10219. }
  10220. if item.MedChrgitmType == "01" { //床位费
  10221. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10222. bedCostSelfTotal = bedCostTotal
  10223. }
  10224. if item.MedChrgitmType == "02" { //诊察费
  10225. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10226. zhenChaCostSelfTotal = zhenChaCostTotal
  10227. }
  10228. if item.MedChrgitmType == "03" { //检查费
  10229. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10230. checkCostSelfTotal = checkCostTotal
  10231. }
  10232. if item.MedChrgitmType == "04" { //化验费
  10233. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10234. laboratoryCostSelfTotal = laboratoryCostTotal
  10235. }
  10236. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10237. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10238. treatCostSelfTotal = treatCostTotal
  10239. }
  10240. if item.MedChrgitmType == "06" { //手术费
  10241. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10242. operationCostSelfTotal = treatCostTotal
  10243. }
  10244. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  10245. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10246. materialCostSelfTotal = materialCostTotal
  10247. }
  10248. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10249. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10250. westernMedicineCostSelfTotal = westernMedicineCostTotal
  10251. }
  10252. if item.MedChrgitmType == "11" { //中成费
  10253. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10254. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10255. }
  10256. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10257. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10258. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10259. otherCostSelfTotal = otherCostTotal
  10260. }
  10261. } else {
  10262. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10263. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10264. otherCostSelfTotal = otherCostTotal
  10265. }
  10266. }
  10267. }
  10268. } else {
  10269. for _, item := range orderInfos {
  10270. if item.MedChrgitmType == "01" { //床位费
  10271. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10272. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10273. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10274. }
  10275. if item.MedChrgitmType == "02" { //诊察费
  10276. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10277. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10278. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10279. }
  10280. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  10281. if item.MedChrgitmType == "03" { //检查费
  10282. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10283. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10284. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10285. }
  10286. } else {
  10287. if item.MedChrgitmType == "03" { //检查费
  10288. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10289. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10290. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10291. }
  10292. }
  10293. if item.MedChrgitmType == "04" { //化验费
  10294. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10295. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10296. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10297. }
  10298. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10299. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10300. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10301. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10302. }
  10303. if item.MedChrgitmType == "06" { //手术费
  10304. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10305. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10306. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10307. }
  10308. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  10309. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10310. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10311. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10312. }
  10313. if item.MedChrgitmType == "07" { //护理
  10314. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10315. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10316. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10317. }
  10318. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10319. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10320. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10321. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10322. }
  10323. if item.MedChrgitmType == "11" { //中成费
  10324. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10325. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10326. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10327. }
  10328. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10329. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10330. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10331. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10332. }
  10333. }
  10334. }
  10335. timeLayout := "2006-01-02"
  10336. loc, _ := time.LoadLocation("Local")
  10337. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  10338. if err != nil {
  10339. }
  10340. startRecordDateTime := startTime.Unix()
  10341. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  10342. if err != nil {
  10343. }
  10344. endRecordDateTime := endTime.Unix()
  10345. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  10346. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  10347. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  10348. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  10349. c.ServeSuccessJSON(map[string]interface{}{
  10350. "charge_admin_name": charge_admin.UserName,
  10351. "order_number": order.Number, //业务流水号
  10352. "id_card_no": his.IdCardNo, //社会保障号
  10353. "patient": patient,
  10354. "department_name": department.Name, //科室
  10355. "number": his.Number, //门诊号
  10356. "date": order.SettleAccountsDate, //结算日期
  10357. "name": order.PsnName, //姓名
  10358. "gender": patient.Gender, //性别
  10359. "psn_cash_money": order.PsnCashPay, //个人支付
  10360. "pay_way": "门诊", //结算方式
  10361. "medfee_sumamt": order.MedfeeSumamt, //总费用
  10362. "admin_user_name": admin.UserName, //收款员
  10363. "order": order,
  10364. "order_info": orderInfos_two,
  10365. "his": his,
  10366. "bedCostTotal": bedCostTotal,
  10367. "bedCostSelfTotal": bedCostSelfTotal,
  10368. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  10369. "operationCostTotal": operationCostTotal,
  10370. "operationCostSelfTotal": operationCostSelfTotal,
  10371. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  10372. "otherCostTotal": otherCostTotal,
  10373. "otherCostSelfTotal": otherCostSelfTotal,
  10374. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  10375. "materialCostTotal": materialCostTotal,
  10376. "materialCostSelfTotal": materialCostSelfTotal,
  10377. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  10378. "westernMedicineCostTotal": westernMedicineCostTotal,
  10379. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  10380. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  10381. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10382. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  10383. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  10384. "checkCostTotal": checkCostTotal,
  10385. "checkCostSelfTotal": checkCostSelfTotal,
  10386. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  10387. "laboratoryCostTotal": laboratoryCostTotal,
  10388. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  10389. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  10390. "treatCostTotal": treatCostTotal,
  10391. "treatCostSelfTotal": treatCostSelfTotal,
  10392. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  10393. "zhenChaCostTotal": zhenChaCostTotal,
  10394. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  10395. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  10396. "his_hospital_record": his_hospital_record,
  10397. "pre_pay_money": pre_pay_money,
  10398. "refund_sum": sum,
  10399. "doctor_info": doctor_info,
  10400. "hiliCostTotal": hiliCostTotal,
  10401. "hiliCostSelfTotal": hiliCostSelfTotal,
  10402. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  10403. })
  10404. }
  10405. //func (c *HisApiController) GetFaPiaoDatas() {
  10406. // order_ids := c.GetString("order_ids")
  10407. // patient_id, _ := c.GetInt64("patient_id")
  10408. // adminUser := c.GetAdminUserInfo()
  10409. //
  10410. // orders := strings.Split(order_ids, ",")
  10411. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10412. //
  10413. // for _, item := range orders {
  10414. // order_id, _ := strconv.ParseInt(item, 10, 64)
  10415. // order, _ := service.GetHisOrderByID(order_id)
  10416. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10417. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10418. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10419. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10420. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10421. //
  10422. // }
  10423. //
  10424. // var bedCostTotal float64 = 0 //床位总费
  10425. // var bedCostSelfTotal float64 = 0 //床位自费
  10426. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10427. //
  10428. // var operationCostTotal float64 = 0 //手术费
  10429. // var operationCostSelfTotal float64 = 0 //手术费
  10430. // var operationCostPartSelfTotal float64 = 0 //手术费
  10431. //
  10432. // var otherCostTotal float64 = 0 //其他费用
  10433. // var otherCostSelfTotal float64 = 0 //其他费用
  10434. // var otherCostPartSelfTotal float64 = 0 //其他费用
  10435. //
  10436. // var materialCostTotal float64 = 0 //材料费
  10437. // var materialCostSelfTotal float64 = 0 //材料费
  10438. // var materialCostPartSelfTotal float64 = 0 //材料费
  10439. //
  10440. // var westernMedicineCostTotal float64 = 0 //西药费
  10441. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  10442. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10443. //
  10444. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10445. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10446. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10447. //
  10448. // var checkCostTotal float64 = 0 //检查费
  10449. // var checkCostSelfTotal float64 = 0 //检查费
  10450. // var checkCostPartSelfTotal float64 = 0 //检查费
  10451. //
  10452. // var laboratoryCostTotal float64 = 0 //化验费
  10453. // var laboratoryCostSelfTotal float64 = 0 //化验费
  10454. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10455. //
  10456. // var treatCostTotal float64 = 0 //治疗费用
  10457. // var treatCostSelfTotal float64 = 0 //治疗费用
  10458. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  10459. //
  10460. // var zhenChaCostTotal float64 = 0 //其他费用
  10461. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  10462. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10463. //
  10464. // decimal.DivisionPrecision = 2
  10465. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10466. //
  10467. // var balanceAccountsType int64
  10468. // if his.ID > 0 {
  10469. // balanceAccountsType = his.BalanceAccountsType
  10470. // } else {
  10471. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  10472. // }
  10473. // if balanceAccountsType == 2 {
  10474. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10475. // for _, item := range orderInfos_two {
  10476. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10477. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10478. // item.MedChrgitmType = "09"
  10479. // }
  10480. //
  10481. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10482. // if item.HisPrescriptionProject.Type == 2 {
  10483. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10484. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10485. // case 0:
  10486. // item.MedChrgitmType = "0"
  10487. // break
  10488. // case 1:
  10489. // item.MedChrgitmType = "14"
  10490. // break
  10491. // case 2:
  10492. // item.MedChrgitmType = "05"
  10493. //
  10494. // break
  10495. // case 3:
  10496. // item.MedChrgitmType = "03"
  10497. //
  10498. // break
  10499. // case 4:
  10500. // item.MedChrgitmType = "03"
  10501. //
  10502. // break
  10503. // case 5:
  10504. // item.MedChrgitmType = "08"
  10505. //
  10506. // break
  10507. // case 6:
  10508. // item.MedChrgitmType = "14"
  10509. //
  10510. // break
  10511. // case 7:
  10512. // item.MedChrgitmType = "14"
  10513. //
  10514. // break
  10515. // case 8:
  10516. // item.MedChrgitmType = "03"
  10517. // break
  10518. // case 9:
  10519. // item.MedChrgitmType = "14"
  10520. // break
  10521. // case 10:
  10522. // item.MedChrgitmType = "14"
  10523. // break
  10524. // case 11:
  10525. // item.MedChrgitmType = "06"
  10526. // break
  10527. // case 12:
  10528. // item.MedChrgitmType = "12"
  10529. // break
  10530. // case 13:
  10531. // item.MedChrgitmType = "01"
  10532. // break
  10533. // case 14:
  10534. // item.MedChrgitmType = "04"
  10535. // break
  10536. // case 15:
  10537. // item.MedChrgitmType = "02"
  10538. // break
  10539. //
  10540. // }
  10541. //
  10542. // } else {
  10543. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10544. //
  10545. // case 1:
  10546. // item.MedChrgitmType = "14"
  10547. // break
  10548. // case 2:
  10549. // item.MedChrgitmType = "05"
  10550. //
  10551. // break
  10552. // case 3:
  10553. // item.MedChrgitmType = "03"
  10554. //
  10555. // break
  10556. // case 4:
  10557. // item.MedChrgitmType = "03"
  10558. //
  10559. // break
  10560. // case 5:
  10561. // item.MedChrgitmType = "08"
  10562. //
  10563. // break
  10564. // case 6:
  10565. // item.MedChrgitmType = "14"
  10566. //
  10567. // break
  10568. // case 7:
  10569. // item.MedChrgitmType = "14"
  10570. //
  10571. // break
  10572. // case 8:
  10573. // item.MedChrgitmType = "03"
  10574. // break
  10575. // case 9:
  10576. // item.MedChrgitmType = "14"
  10577. // break
  10578. //
  10579. // }
  10580. //
  10581. // }
  10582. //
  10583. // } else if item.HisPrescriptionProject.Type == 3 {
  10584. // item.MedChrgitmType = "08"
  10585. // }
  10586. // }
  10587. // }
  10588. //
  10589. // for _, item := range orderInfos_two {
  10590. // fmt.Println(item.MedChrgitmType)
  10591. // if item.MedChrgitmType == "01" { //床位费
  10592. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10593. // bedCostSelfTotal = bedCostTotal
  10594. // }
  10595. //
  10596. // if item.MedChrgitmType == "02" { //诊察费
  10597. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10598. // zhenChaCostSelfTotal = zhenChaCostTotal
  10599. // }
  10600. //
  10601. // if item.MedChrgitmType == "03" { //检查费
  10602. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10603. // checkCostSelfTotal = checkCostTotal
  10604. // }
  10605. //
  10606. // if item.MedChrgitmType == "04" { //化验费
  10607. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10608. // laboratoryCostSelfTotal = laboratoryCostTotal
  10609. // }
  10610. //
  10611. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  10612. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10613. // treatCostSelfTotal = treatCostTotal
  10614. // }
  10615. //
  10616. // if item.MedChrgitmType == "06" { //手术费
  10617. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10618. // operationCostSelfTotal = treatCostTotal
  10619. // }
  10620. //
  10621. // if item.MedChrgitmType == "08" { //材料费
  10622. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10623. // materialCostSelfTotal = materialCostTotal
  10624. // }
  10625. //
  10626. // if item.MedChrgitmType == "09" { //西药费
  10627. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10628. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  10629. // }
  10630. //
  10631. // if item.MedChrgitmType == "11" { //中成费
  10632. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10633. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10634. // }
  10635. //
  10636. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10637. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10638. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10639. // otherCostSelfTotal = otherCostTotal
  10640. // }
  10641. // } else {
  10642. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10643. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10644. // otherCostSelfTotal = otherCostTotal
  10645. // }
  10646. //
  10647. // }
  10648. //
  10649. // }
  10650. //
  10651. // } else {
  10652. // for _, item := range orderInfos {
  10653. // if item.MedChrgitmType == "01" { //床位费
  10654. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10655. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10656. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10657. // }
  10658. //
  10659. // if item.MedChrgitmType == "02" { //诊察费
  10660. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10661. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10662. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10663. // }
  10664. //
  10665. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  10666. // if item.MedChrgitmType == "03" { //检查费
  10667. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10668. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10669. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10670. //
  10671. // }
  10672. // } else {
  10673. // if item.MedChrgitmType == "03" { //检查费
  10674. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10675. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10676. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10677. // }
  10678. //
  10679. // }
  10680. //
  10681. // if item.MedChrgitmType == "04" { //化验费
  10682. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10683. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10684. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10685. //
  10686. // }
  10687. //
  10688. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  10689. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10690. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10691. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10692. //
  10693. // }
  10694. //
  10695. // if item.MedChrgitmType == "06" { //手术费
  10696. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10697. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10698. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10699. // }
  10700. //
  10701. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  10702. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10703. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10704. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10705. // }
  10706. //
  10707. // if item.MedChrgitmType == "09" { //西药费
  10708. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10709. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10710. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10711. // }
  10712. //
  10713. // if item.MedChrgitmType == "11" { //中成费
  10714. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10715. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10716. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10717. // }
  10718. //
  10719. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10720. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10721. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10722. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10723. // }
  10724. //
  10725. // }
  10726. // }
  10727. // timeLayout := "2006-01-02"
  10728. // loc, _ := time.LoadLocation("Local")
  10729. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  10730. // if err != nil {
  10731. // }
  10732. // startRecordDateTime := startTime.Unix()
  10733. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  10734. // if err != nil {
  10735. // }
  10736. // endRecordDateTime := endTime.Unix()
  10737. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  10738. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  10739. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  10740. //
  10741. // c.ServeSuccessJSON(map[string]interface{}{
  10742. // "order_number": order.Number, //业务流水号
  10743. // "id_card_no": his.IdCardNo, //社会保障号
  10744. // "department_name": department.Name, //科室
  10745. // "number": his.Number, //门诊号
  10746. // "date": order.SettleAccountsDate, //结算日期
  10747. // "name": order.PsnName, //姓名
  10748. // "gender": patient.Gender, //性别
  10749. // "psn_cash_money": order.PsnCashPay, //个人支付
  10750. // "pay_way": "门诊", //结算方式
  10751. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  10752. // "admin_user_name": admin.UserName, //收款员
  10753. // "order": order,
  10754. // "order_info": orderInfos_two,
  10755. // "his": his,
  10756. // "bedCostTotal": bedCostTotal,
  10757. // "bedCostSelfTotal": bedCostSelfTotal,
  10758. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  10759. // "operationCostTotal": operationCostTotal,
  10760. // "operationCostSelfTotal": operationCostSelfTotal,
  10761. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  10762. // "otherCostTotal": otherCostTotal,
  10763. // "otherCostSelfTotal": otherCostSelfTotal,
  10764. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  10765. // "materialCostTotal": materialCostTotal,
  10766. // "materialCostSelfTotal": materialCostSelfTotal,
  10767. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  10768. // "westernMedicineCostTotal": westernMedicineCostTotal,
  10769. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  10770. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  10771. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10772. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  10773. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  10774. // "checkCostTotal": checkCostTotal,
  10775. // "checkCostSelfTotal": checkCostSelfTotal,
  10776. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  10777. // "laboratoryCostTotal": laboratoryCostTotal,
  10778. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  10779. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  10780. // "treatCostTotal": treatCostTotal,
  10781. // "treatCostSelfTotal": treatCostSelfTotal,
  10782. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  10783. // "zhenChaCostTotal": zhenChaCostTotal,
  10784. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  10785. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  10786. // "his_hospital_record": his_hospital_record,
  10787. // "pre_pay_money": pre_pay_money,
  10788. // "refund_sum": sum,
  10789. // })
  10790. //
  10791. //}
  10792. func (this *HisApiController) GetIncomeStatisticsData() {
  10793. start_time := this.GetString("start_time")
  10794. end_time := this.GetString("end_time")
  10795. key_words := this.GetString("key_words")
  10796. limit, _ := this.GetInt64("limit")
  10797. page, _ := this.GetInt64("page")
  10798. if page <= 0 {
  10799. page = 1
  10800. }
  10801. if limit <= 0 {
  10802. limit = 10
  10803. }
  10804. statistics_type, _ := this.GetInt64("statistics_type")
  10805. admin := this.GetAdminUserInfo()
  10806. timeLayout := "2006-01-02"
  10807. loc, _ := time.LoadLocation("Local")
  10808. var theStartTIme int64
  10809. if len(start_time) > 0 {
  10810. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10811. if err != nil {
  10812. theStartTIme = 0
  10813. }
  10814. theStartTIme = theTime.Unix()
  10815. }
  10816. var theEndtTIme int64
  10817. if len(end_time) > 0 {
  10818. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10819. if err != nil {
  10820. theEndtTIme = 0
  10821. }
  10822. theEndtTIme = theTime.Unix()
  10823. }
  10824. if statistics_type == 1 {
  10825. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10826. this.ServeSuccessJSON(map[string]interface{}{
  10827. "list": list,
  10828. "total": total,
  10829. })
  10830. } else {
  10831. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10832. this.ServeSuccessJSON(map[string]interface{}{
  10833. "list": list,
  10834. "total": total,
  10835. })
  10836. }
  10837. }
  10838. func (c *HisApiController) PostProjectInformation() {
  10839. adminUser := c.GetAdminUserInfo()
  10840. orgId := adminUser.CurrentOrgId
  10841. dataBody := make(map[string]interface{}, 0)
  10842. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10843. if err != nil {
  10844. utils.ErrorLog(err.Error())
  10845. return
  10846. }
  10847. utils.ErrorLog("%v", dataBody)
  10848. var projectList []*models.HisProject
  10849. var total_goods []interface{}
  10850. tempProjects := dataBody["projects"].([]interface{})
  10851. total_goods = tempProjects
  10852. for index, projectMap := range tempProjects {
  10853. projectM := projectMap.(map[string]interface{})
  10854. var project models.HisProject
  10855. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  10856. utils.ErrorLog("project_name")
  10857. return
  10858. }
  10859. project_name, _ := projectM["project_name"].(string)
  10860. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  10861. err_log := models.ExportErrLog{
  10862. LogType: 6,
  10863. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10864. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  10865. Status: 1,
  10866. CreateTime: time.Now().Unix(),
  10867. UpdateTime: time.Now().Unix(),
  10868. ExportTime: time.Now().Unix(),
  10869. }
  10870. service.CreateExportErrLog(&err_log)
  10871. continue
  10872. }
  10873. project.ProjectName = project_name
  10874. prices := projectM["price"].(string)
  10875. price, _ := strconv.ParseFloat(prices, 64)
  10876. if price <= 0 { //名字为空则生成一条导入错误日志
  10877. err_log := models.ExportErrLog{
  10878. LogType: 6,
  10879. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10880. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  10881. Status: 1,
  10882. CreateTime: time.Now().Unix(),
  10883. UpdateTime: time.Now().Unix(),
  10884. ExportTime: time.Now().Unix(),
  10885. }
  10886. service.CreateExportErrLog(&err_log)
  10887. continue
  10888. }
  10889. project.Price = price
  10890. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  10891. utils.ErrorLog("unit_id")
  10892. return
  10893. }
  10894. unit := projectM["unit"].(string)
  10895. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  10896. err_log := models.ExportErrLog{
  10897. LogType: 6,
  10898. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10899. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  10900. Status: 1,
  10901. CreateTime: time.Now().Unix(),
  10902. UpdateTime: time.Now().Unix(),
  10903. ExportTime: time.Now().Unix(),
  10904. }
  10905. service.CreateExportErrLog(&err_log)
  10906. continue
  10907. }
  10908. project.Unit = unit
  10909. cost_classify := projectM["cost_classify"].(string)
  10910. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  10911. err_log := models.ExportErrLog{
  10912. LogType: 6,
  10913. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10914. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10915. Status: 1,
  10916. CreateTime: time.Now().Unix(),
  10917. UpdateTime: time.Now().Unix(),
  10918. ExportTime: time.Now().Unix(),
  10919. }
  10920. service.CreateExportErrLog(&err_log)
  10921. continue
  10922. }
  10923. var costClassify = "费用类别"
  10924. var cost_classify_id int64
  10925. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  10926. if len(cost_classify) != 0 {
  10927. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  10928. if errcode == gorm.ErrRecordNotFound {
  10929. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  10930. dataconfig := models.DictDataconfig{
  10931. ParentId: costClassifyConfig.ID,
  10932. Module: "system",
  10933. OrgId: orgId,
  10934. Name: cost_classify,
  10935. FieldName: "",
  10936. Value: costConfig.Value + 1,
  10937. CreatedTime: "",
  10938. UpdatedTime: "",
  10939. CreateUserId: adminUser.AdminUser.Id,
  10940. Status: 1,
  10941. Remark: "",
  10942. DeleteIdSystem: 0,
  10943. Title: "",
  10944. Content: "",
  10945. Order: 0,
  10946. Code: "",
  10947. }
  10948. service.CreatedDicConfig(&dataconfig)
  10949. }
  10950. }
  10951. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  10952. for _, it := range costClassList {
  10953. if cost_classify == it.Name {
  10954. cost_classify_id = int64(it.Value)
  10955. }
  10956. }
  10957. project.CostClassify = cost_classify_id
  10958. executive_section := projectM["executive_section"].(string)
  10959. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  10960. err_log := models.ExportErrLog{
  10961. LogType: 6,
  10962. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10963. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  10964. Status: 1,
  10965. CreateTime: time.Now().Unix(),
  10966. UpdateTime: time.Now().Unix(),
  10967. ExportTime: time.Now().Unix(),
  10968. }
  10969. service.CreateExportErrLog(&err_log)
  10970. continue
  10971. }
  10972. if len(executive_section) != 0 {
  10973. //查找科室是否有内容
  10974. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  10975. if errcodedepart == gorm.ErrRecordNotFound {
  10976. department := models.XtHisDepartment{
  10977. Name: executive_section,
  10978. Status: 1,
  10979. UserOrgId: adminUser.CurrentOrgId,
  10980. CreatedTime: time.Now().Unix(),
  10981. }
  10982. service.CreateDePartment(&department)
  10983. }
  10984. }
  10985. var executive_section_id int64
  10986. departMentList, _ := service.GetAllDepartMent(orgId)
  10987. for _, it := range departMentList {
  10988. if executive_section == it.Name {
  10989. executive_section_id = it.ID
  10990. }
  10991. }
  10992. project.ExecutiveSection = executive_section_id
  10993. medical_coverage := projectM["medical_coverage"].(string)
  10994. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  10995. err_log := models.ExportErrLog{
  10996. LogType: 6,
  10997. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10998. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10999. Status: 1,
  11000. CreateTime: time.Now().Unix(),
  11001. UpdateTime: time.Now().Unix(),
  11002. ExportTime: time.Now().Unix(),
  11003. }
  11004. service.CreateExportErrLog(&err_log)
  11005. continue
  11006. }
  11007. var medicalCoverage = "医保等级"
  11008. var medical_coverage_id int64
  11009. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  11010. if len(medical_coverage) != 0 {
  11011. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  11012. if errormedicalcoverage == gorm.ErrRecordNotFound {
  11013. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  11014. dataconfig := models.DictDataconfig{
  11015. ParentId: medicalCoverageConfig.ID,
  11016. Module: "system",
  11017. OrgId: orgId,
  11018. Name: medical_coverage,
  11019. FieldName: "",
  11020. Value: medicalCoverageConfig.Value + 1,
  11021. CreatedTime: "",
  11022. UpdatedTime: "",
  11023. CreateUserId: adminUser.AdminUser.Id,
  11024. Status: 1,
  11025. Remark: "",
  11026. DeleteIdSystem: 0,
  11027. Title: "",
  11028. Content: "",
  11029. Order: 0,
  11030. Code: "",
  11031. }
  11032. service.CreatedDicConfig(&dataconfig)
  11033. }
  11034. }
  11035. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  11036. for _, it := range medicalCoverageList {
  11037. if medical_coverage == it.Name {
  11038. medical_coverage_id = int64(it.Value)
  11039. }
  11040. }
  11041. project.MedicalCoverage = medical_coverage_id
  11042. pinyin := projectM["pinyin"].(string)
  11043. project.Pinyin = pinyin
  11044. wubi := projectM["wubi"].(string)
  11045. project.Wubi = wubi
  11046. statistical_classification := projectM["statistical_classification"].(string)
  11047. var statisticalClassification = "统计分类"
  11048. var statistical_classification_id int64
  11049. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  11050. if len(statistical_classification) != 0 {
  11051. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  11052. if classificationerrcodes == gorm.ErrRecordNotFound {
  11053. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  11054. dataconfig := models.DictDataconfig{
  11055. ParentId: classiFication.ID,
  11056. Module: "system",
  11057. OrgId: orgId,
  11058. Name: statistical_classification,
  11059. FieldName: "",
  11060. Value: classiFicationConfig.Value + 1,
  11061. CreatedTime: "",
  11062. UpdatedTime: "",
  11063. CreateUserId: adminUser.AdminUser.Id,
  11064. Status: 1,
  11065. Remark: "",
  11066. DeleteIdSystem: 0,
  11067. Title: "",
  11068. Content: "",
  11069. Order: 0,
  11070. Code: "",
  11071. }
  11072. service.CreatedDicConfig(&dataconfig)
  11073. }
  11074. }
  11075. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  11076. for _, it := range classiFicationList {
  11077. if statistical_classification == it.Name {
  11078. statistical_classification_id = int64(it.Value)
  11079. }
  11080. }
  11081. project.StatisticalClassification = statistical_classification_id
  11082. disease_directory := int64(projectM["disease_directory"].(float64))
  11083. project.DiseaseDirectory = disease_directory
  11084. is_record := int64(projectM["is_record"].(float64))
  11085. project.IsRecord = is_record
  11086. medical_code := projectM["medical_code"].(string)
  11087. project.MedicalCode = medical_code
  11088. tube_color := projectM["tube_color"].(string)
  11089. var tubeColor = "试管颜色"
  11090. var tube_color_id int64
  11091. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  11092. if len(tube_color) != 0 {
  11093. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  11094. if errcodetube == gorm.ErrRecordNotFound {
  11095. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  11096. dataconfig := models.DictDataconfig{
  11097. ParentId: tubeColorConfig.ID,
  11098. Module: "system",
  11099. OrgId: orgId,
  11100. Name: tube_color,
  11101. FieldName: "",
  11102. Value: tubeConfig.Value + 1,
  11103. CreatedTime: "",
  11104. UpdatedTime: "",
  11105. CreateUserId: adminUser.AdminUser.Id,
  11106. Status: 1,
  11107. Remark: "",
  11108. DeleteIdSystem: 0,
  11109. Title: "",
  11110. Content: "",
  11111. Order: 0,
  11112. Code: "",
  11113. }
  11114. service.CreatedDicConfig(&dataconfig)
  11115. }
  11116. }
  11117. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  11118. for _, it := range tubeColorList {
  11119. if tube_color == it.Name {
  11120. tube_color_id = int64(it.Value)
  11121. }
  11122. }
  11123. project.TubeColor = tube_color_id
  11124. single_dose := projectM["single_dose"].(string)
  11125. project.SingleDose = single_dose
  11126. execution_frequency := projectM["execution_frequency"].(string)
  11127. project.ExecutionFrequency = execution_frequency
  11128. delivery_way := projectM["delivery_way"].(string)
  11129. project.DeliveryWay = delivery_way
  11130. number_days := projectM["number_days"].(string)
  11131. project.NumberDays = number_days
  11132. total := projectM["total"].(string)
  11133. project.Total = total
  11134. medical_status := int64(projectM["medical_status"].(float64))
  11135. project.MedicalStatus = medical_status
  11136. category := int64(projectM["category"].(float64))
  11137. project.Category = category
  11138. specail_project := int64(projectM["specail_project"].(float64))
  11139. project.SpecailProject = specail_project
  11140. social_security_directory_code := projectM["social_security_directory_code"].(string)
  11141. project.SocialSecurityDirectoryCode = social_security_directory_code
  11142. remark := projectM["remark"].(string)
  11143. project.Remark = remark
  11144. record_date := projectM["record_date"].(string)
  11145. timeLayout := "2006-01-02"
  11146. loc, _ := time.LoadLocation("Local")
  11147. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11148. project.RecordDate = theTime.Unix()
  11149. projectList = append(projectList, &project)
  11150. }
  11151. export_time := time.Now().Unix()
  11152. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  11153. if len(projectList) > 0 {
  11154. for _, item := range projectList {
  11155. hans := item.ProjectName // 要转换的汉字字符串
  11156. // 创建一个拼音转换器
  11157. p := pinyin.NewArgs()
  11158. // 将汉字转为拼音
  11159. pinyinSlice := pinyin.Pinyin(hans, p)
  11160. // 输出拼音
  11161. fmt.Println("Pinyin:", pinyinSlice)
  11162. // 获取首字母
  11163. firstLetter := ""
  11164. for _, py := range pinyinSlice {
  11165. if len(py) > 0 {
  11166. firstLetter += string(py[0][0])
  11167. }
  11168. }
  11169. item.FirstLetter = firstLetter
  11170. project := models.HisProject{
  11171. ProjectName: item.ProjectName,
  11172. Price: item.Price,
  11173. Unit: item.Unit,
  11174. CostClassify: item.CostClassify,
  11175. ExecutiveSection: item.ExecutiveSection,
  11176. MedicalCoverage: item.MedicalCoverage,
  11177. UserOrgId: orgId,
  11178. Status: 1,
  11179. CreatedTime: time.Now().Unix(),
  11180. Pinyin: item.Pinyin,
  11181. Wubi: item.Wubi,
  11182. StatisticalClassification: item.StatisticalClassification,
  11183. DiseaseDirectory: item.DiseaseDirectory,
  11184. IsRecord: item.IsRecord,
  11185. MedicalCode: item.MedicalCode,
  11186. TubeColor: item.TubeColor,
  11187. SingleDose: item.SingleDose,
  11188. DeliveryWay: item.DeliveryWay,
  11189. NumberDays: item.NumberDays,
  11190. Total: item.Total,
  11191. Category: item.Category,
  11192. MedicalStatus: item.MedicalStatus,
  11193. SpecailProject: item.SpecailProject,
  11194. RecordDate: item.RecordDate,
  11195. Remark: item.Remark,
  11196. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  11197. ExecutionFrequency: item.ExecutionFrequency,
  11198. FirstLetter: item.FirstLetter,
  11199. }
  11200. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  11201. if errcodeproject == gorm.ErrRecordNotFound {
  11202. service.CreateProjectInfomation(&project)
  11203. } else if errcodeproject == nil {
  11204. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  11205. }
  11206. log := models.ExportLog{
  11207. LogType: 6,
  11208. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11209. TotalNum: int64(len(total_goods)),
  11210. FailNum: int64(len(errLogs)),
  11211. SuccessNum: int64(len(projectList)),
  11212. CreateTime: time.Now().Unix(),
  11213. UpdateTime: time.Now().Unix(),
  11214. ExportTime: export_time,
  11215. Status: 1,
  11216. }
  11217. service.CreateExportLog(&log)
  11218. c.ServeSuccessJSON(map[string]interface{}{
  11219. "msg": "导入成功",
  11220. "total_num": len(total_goods),
  11221. "success_num": len(projectList),
  11222. "fail_num": int64(len(errLogs)),
  11223. })
  11224. }
  11225. } else {
  11226. log := models.ExportLog{
  11227. LogType: 6,
  11228. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11229. TotalNum: int64(len(total_goods)),
  11230. FailNum: int64(len(errLogs)),
  11231. SuccessNum: int64(len(projectList)),
  11232. CreateTime: time.Now().Unix(),
  11233. UpdateTime: time.Now().Unix(),
  11234. ExportTime: export_time,
  11235. Status: 1,
  11236. }
  11237. service.CreateExportLog(&log)
  11238. c.ServeSuccessJSON(map[string]interface{}{
  11239. "msg": "导入成功",
  11240. "total_num": len(total_goods),
  11241. "success_num": len(projectList),
  11242. "fail_num": int64(len(errLogs)),
  11243. })
  11244. }
  11245. }
  11246. //func (this *HisApiController) EditProjectInformation(){
  11247. //
  11248. // id, _ := this.GetInt64("id")
  11249. // project_team := this.GetString("project_team")
  11250. // price := this.GetString("price")
  11251. // price_float, _ := strconv.ParseFloat(price, 64)
  11252. // pinyin := this.GetString("pinyin")
  11253. // wubi := this.GetString("wubi")
  11254. // tube_color, _ := this.GetInt64("tube_color")
  11255. // team_type, _ := this.GetInt64("team_type")
  11256. // remark := this.GetString("remark")
  11257. // ids := this.GetString("ids")
  11258. // item_id := this.GetString("item_id")
  11259. // projectTeam := models.XtHisProjectTeam{
  11260. // ProjectTeam: project_team,
  11261. // Price: price_float,
  11262. // Pinyin: pinyin,
  11263. // Wubi: wubi,
  11264. // TubeColor: tube_color,
  11265. // TeamType: team_type,
  11266. // Remark: remark,
  11267. // ProjectId: ids,
  11268. // ItemId: item_id,
  11269. // }
  11270. //
  11271. //
  11272. // dataBody := make(map[string]interface{}, 0)
  11273. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  11274. // if err != nil {
  11275. // utils.ErrorLog(err.Error())
  11276. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11277. // return
  11278. // }
  11279. //
  11280. // err = service.UpdatedProjectTeam(id, &projectTeam)
  11281. //
  11282. //
  11283. // if err != nil {
  11284. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  11285. // return
  11286. // }
  11287. //
  11288. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  11289. // infos, _ := dataBody["info"].([]interface{})
  11290. // if len(infos) > 0 {
  11291. // var ids []string
  11292. //
  11293. // for _, item := range infos {
  11294. // items := item.(map[string]interface{})
  11295. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  11296. // utils.ErrorLog("id")
  11297. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11298. // return
  11299. // }
  11300. // id := int64(items["id"].(float64))
  11301. //
  11302. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11303. // utils.ErrorLog("type")
  11304. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11305. // return
  11306. // }
  11307. // types := int64(items["type"].(float64))
  11308. //
  11309. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  11310. // utils.ErrorLog("number")
  11311. // }
  11312. //
  11313. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  11314. //
  11315. // projectList := models.XtHisProjectList{
  11316. // Number: number,
  11317. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  11318. // ProjectId: id,
  11319. // Status: 1,
  11320. // CreatedTime: time.Now().Unix(),
  11321. // UpdatedTime: time.Now().Unix(),
  11322. // TeamId: projectTeam.ID,
  11323. // Type: types,
  11324. // }
  11325. // list := projectList
  11326. //
  11327. // service.CreateProjectList(&list)
  11328. //
  11329. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  11330. //
  11331. // }
  11332. // ids_str := strings.Join(ids, ",")
  11333. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  11334. // service.SaveProjectTeam(&projectTeam)
  11335. // this.ServeSuccessJSON(map[string]interface{}{
  11336. // "projectTeam": projectTeam,
  11337. // })
  11338. // }
  11339. // }
  11340. //}
  11341. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  11342. name := c.GetString("name")
  11343. mode_id, _ := c.GetInt64("mode", 0)
  11344. types, _ := c.GetInt64("type", 0)
  11345. patient_id, _ := c.GetInt64("patient_id", 0)
  11346. types = 1
  11347. adminInfo := c.GetAdminUserInfo()
  11348. template := &models.HisPrescriptionTemplate{
  11349. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11350. PatientId: patient_id,
  11351. Type: types,
  11352. Status: 1,
  11353. Ctime: time.Now().Unix(),
  11354. Mtime: time.Now().Unix(),
  11355. Name: name,
  11356. Mode: mode_id,
  11357. }
  11358. dataBody := make(map[string]interface{}, 0)
  11359. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11360. if err != nil {
  11361. utils.ErrorLog(err.Error())
  11362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11363. return
  11364. }
  11365. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  11366. //如果已经存在记录则删除处方
  11367. if template_one.ID > 0 {
  11368. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  11369. var ids []int64
  11370. var org_id int64
  11371. for _, item := range ps {
  11372. org_id = c.GetAdminUserInfo().CurrentOrgId
  11373. ids = append(ids, item.ID)
  11374. }
  11375. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  11376. if err2 == nil {
  11377. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11378. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11379. if len(prescriptions) > 0 {
  11380. for _, item := range prescriptions {
  11381. items := item.(map[string]interface{})
  11382. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11383. utils.ErrorLog("type")
  11384. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11385. return
  11386. }
  11387. types := int64(items["type"].(float64))
  11388. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  11389. utils.ErrorLog("med_type")
  11390. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11391. return
  11392. }
  11393. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  11394. ctime := time.Now().Unix()
  11395. prescription := &models.HisPrescriptionInfoTemplate{
  11396. PatientId: patient_id,
  11397. UserOrgId: adminInfo.CurrentOrgId,
  11398. Ctime: ctime,
  11399. Mtime: ctime,
  11400. Type: types,
  11401. Modifier: adminInfo.AdminUser.Id,
  11402. Creator: adminInfo.AdminUser.Id,
  11403. Status: 1,
  11404. PTemplateId: template_one.ID,
  11405. MedType: med_type,
  11406. }
  11407. service.CreateHisPrescriptionInfoTemplate(prescription)
  11408. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11409. advices := items["advices"].([]interface{})
  11410. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11411. ctime := time.Now().Unix()
  11412. mtime := ctime
  11413. if len(advices) > 0 {
  11414. for _, advice := range advices {
  11415. var s models.HisPrescriptionAdviceTemplate
  11416. s.PrescriptionId = prescription.ID
  11417. s.AdviceType = 2
  11418. s.StopState = 2
  11419. s.ExecutionState = 2
  11420. s.Status = 1
  11421. s.UserOrgId = adminInfo.CurrentOrgId
  11422. s.CreatedTime = ctime
  11423. s.UpdatedTime = mtime
  11424. s.PatientId = patient_id
  11425. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  11426. if errcode > 0 {
  11427. c.ServeFailJSONWithSGJErrorCode(errcode)
  11428. return
  11429. }
  11430. service.CreateHisPrescriptionAdviceTemplate(&s)
  11431. }
  11432. }
  11433. }
  11434. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11435. projects := items["project"].([]interface{})
  11436. if len(projects) > 0 {
  11437. for _, project := range projects {
  11438. var p models.HisPrescriptionProjectTemplate
  11439. p.PrescriptionId = prescription.ID
  11440. p.Ctime = time.Now().Unix()
  11441. p.Mtime = time.Now().Unix()
  11442. p.PatientId = patient_id
  11443. p.UserOrgId = adminInfo.CurrentOrgId
  11444. p.Status = 1
  11445. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  11446. if errcode > 0 {
  11447. c.ServeFailJSONWithSGJErrorCode(errcode)
  11448. return
  11449. }
  11450. service.CreateHisPrescriptionProjectTemplate(&p)
  11451. }
  11452. }
  11453. }
  11454. }
  11455. c.ServeSuccessJSON(map[string]interface{}{
  11456. "msg": "创建成功",
  11457. })
  11458. }
  11459. }
  11460. } else {
  11461. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11462. return
  11463. }
  11464. } else {
  11465. err3 := service.CreateHisPrescriptionTemplate(template)
  11466. if err3 == nil {
  11467. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11468. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11469. if len(prescriptions) > 0 {
  11470. for _, item := range prescriptions {
  11471. items := item.(map[string]interface{})
  11472. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11473. utils.ErrorLog("type")
  11474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11475. return
  11476. }
  11477. types := int64(items["type"].(float64))
  11478. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  11479. utils.ErrorLog("med_type")
  11480. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11481. return
  11482. }
  11483. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  11484. ctime := time.Now().Unix()
  11485. prescription := &models.HisPrescriptionInfoTemplate{
  11486. PatientId: patient_id,
  11487. UserOrgId: adminInfo.CurrentOrgId,
  11488. Ctime: ctime,
  11489. Mtime: ctime,
  11490. Type: types,
  11491. Modifier: adminInfo.AdminUser.Id,
  11492. Creator: adminInfo.AdminUser.Id,
  11493. Status: 1,
  11494. PTemplateId: template.ID,
  11495. MedType: med_type,
  11496. }
  11497. service.CreateHisPrescriptionInfoTemplate(prescription)
  11498. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11499. advices := items["advices"].([]interface{})
  11500. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11501. ctime := time.Now().Unix()
  11502. mtime := ctime
  11503. if len(advices) > 0 {
  11504. for _, advice := range advices {
  11505. var s models.HisPrescriptionAdviceTemplate
  11506. s.PrescriptionId = prescription.ID
  11507. s.AdviceType = 2
  11508. s.StopState = 2
  11509. s.ExecutionState = 2
  11510. s.Status = 1
  11511. s.UserOrgId = adminInfo.CurrentOrgId
  11512. s.CreatedTime = ctime
  11513. s.UpdatedTime = mtime
  11514. s.PatientId = patient_id
  11515. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  11516. if errcode > 0 {
  11517. c.ServeFailJSONWithSGJErrorCode(errcode)
  11518. return
  11519. }
  11520. service.CreateHisPrescriptionAdviceTemplate(&s)
  11521. }
  11522. }
  11523. }
  11524. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11525. projects := items["project"].([]interface{})
  11526. if len(projects) > 0 {
  11527. for _, project := range projects {
  11528. var p models.HisPrescriptionProjectTemplate
  11529. p.PrescriptionId = prescription.ID
  11530. p.Ctime = time.Now().Unix()
  11531. p.Mtime = time.Now().Unix()
  11532. p.PatientId = patient_id
  11533. p.UserOrgId = adminInfo.CurrentOrgId
  11534. p.Status = 1
  11535. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  11536. if errcode > 0 {
  11537. c.ServeFailJSONWithSGJErrorCode(errcode)
  11538. return
  11539. }
  11540. service.CreateHisPrescriptionProjectTemplate(&p)
  11541. }
  11542. }
  11543. }
  11544. }
  11545. c.ServeSuccessJSON(map[string]interface{}{
  11546. "msg": "创建成功",
  11547. })
  11548. }
  11549. }
  11550. } else {
  11551. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11552. return
  11553. }
  11554. }
  11555. }
  11556. func (c *HisApiController) PreSettle() {
  11557. id, _ := c.GetInt64("id")
  11558. record_time := c.GetString("record_time")
  11559. his_patient_id, _ := c.GetInt64("his_patient_id")
  11560. timeLayout := "2006-01-02"
  11561. loc, _ := time.LoadLocation("Local")
  11562. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  11563. diagnosis_id := c.GetString("diagnosis")
  11564. sick_type, _ := c.GetInt64("sick_type")
  11565. reg_type, _ := c.GetInt64("p_type")
  11566. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  11567. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  11568. if err != nil {
  11569. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11570. return
  11571. }
  11572. recordDateTime := theTime.Unix()
  11573. adminUser := c.GetAdminUserInfo()
  11574. var prescriptions []*models.HisPrescription
  11575. var start_time int64
  11576. var end_time int64
  11577. ids_str := c.GetString("ids")
  11578. ids_arr := strings.Split(ids_str, ",")
  11579. fmt.Println(reg_type)
  11580. if settle_accounts_type == 1 { //日结
  11581. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  11582. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  11583. } else {
  11584. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  11585. }
  11586. fmt.Println(prescriptions)
  11587. } else { //月结
  11588. start_time_str := c.GetString("start_time")
  11589. end_time_str := c.GetString("end_time")
  11590. timeLayout := "2006-01-02"
  11591. loc, _ := time.LoadLocation("Local")
  11592. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  11593. if err != nil {
  11594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11595. return
  11596. }
  11597. recordStartTime := theStartTime.Unix()
  11598. start_time = recordStartTime
  11599. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  11600. if err != nil {
  11601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11602. return
  11603. }
  11604. recordEndTime := theEndTime.Unix()
  11605. end_time = recordEndTime
  11606. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  11607. }
  11608. if reg_type == 1111 || reg_type == 1112 {
  11609. reg_type = 11
  11610. }
  11611. timestamp := time.Now().Unix()
  11612. tempTime := time.Unix(timestamp, 0)
  11613. timeFormat := tempTime.Format("20060102150405")
  11614. chrgBchno := rand.Intn(100000) + 10000
  11615. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  11616. strconv.FormatInt(his.PatientId, 10)
  11617. var ids []int64
  11618. for _, item := range prescriptions {
  11619. ids = append(ids, item.ID)
  11620. }
  11621. fmt.Println(ids)
  11622. var total float64
  11623. for _, item := range prescriptions {
  11624. fmt.Println(item)
  11625. if item.Type == 1 { //药品
  11626. for _, subItem := range item.HisDoctorAdviceInfo {
  11627. total = total + (subItem.Price * subItem.PrescribingNumber)
  11628. }
  11629. }
  11630. if item.Type == 2 { //项目
  11631. for _, subItem := range item.HisPrescriptionProject {
  11632. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  11633. total = total + (subItem.Price * cnt)
  11634. }
  11635. }
  11636. for _, subItem := range item.HisAdditionalCharge {
  11637. total = total + (subItem.Price * float64(subItem.Count))
  11638. }
  11639. }
  11640. allTotal := fmt.Sprintf("%.2f", total)
  11641. totals, _ := strconv.ParseFloat(allTotal, 64)
  11642. order := &models.HisOrder{
  11643. UserOrgId: adminUser.CurrentOrgId,
  11644. HisPatientId: his.ID,
  11645. PatientId: id,
  11646. SettleAccountsDate: recordDateTime,
  11647. Ctime: time.Now().Unix(),
  11648. Mtime: time.Now().Unix(),
  11649. Status: 1,
  11650. OrderStatus: 1,
  11651. MdtrtId: his.Number,
  11652. Number: chrg_bchno,
  11653. MedfeeSumamt: totals,
  11654. SettleEndTime: end_time,
  11655. SettleStartTime: start_time,
  11656. SettleType: settle_accounts_type,
  11657. PsnPartAmt: totals,
  11658. PsnCashPay: totals,
  11659. PType: 2,
  11660. IsPre: 1,
  11661. MedType: strconv.Itoa(int(reg_type)),
  11662. Diagnosis: diagnosis_id,
  11663. }
  11664. err = service.CreateOrder(order)
  11665. if err != nil {
  11666. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  11667. return
  11668. }
  11669. var customs []*Custom
  11670. for _, item := range prescriptions {
  11671. fmt.Println(item.Type)
  11672. if item.Type == 1 { //药品
  11673. for _, subItem := range item.HisDoctorAdviceInfo {
  11674. cus := &Custom{
  11675. AdviceId: subItem.ID,
  11676. ProjectId: 0,
  11677. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  11678. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  11679. FeedetlSn: subItem.FeedetlSn,
  11680. Price: fmt.Sprintf("%.2f", subItem.Price),
  11681. MedListCodg: subItem.MedListCodg,
  11682. Type: 1,
  11683. }
  11684. customs = append(customs, cus)
  11685. }
  11686. }
  11687. if item.Type == 2 { //项目
  11688. for _, subItem := range item.HisPrescriptionProject {
  11689. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  11690. cus := &Custom{
  11691. AdviceId: 0,
  11692. ProjectId: subItem.ID,
  11693. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  11694. Cut: fmt.Sprintf("%.2f", cnt),
  11695. FeedetlSn: subItem.FeedetlSn,
  11696. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  11697. MedListCodg: subItem.MedListCodg,
  11698. Type: 2,
  11699. }
  11700. customs = append(customs, cus)
  11701. }
  11702. }
  11703. for _, item := range item.HisAdditionalCharge {
  11704. cus := &Custom{
  11705. ItemId: item.ID,
  11706. AdviceId: 0,
  11707. ProjectId: 0,
  11708. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  11709. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  11710. FeedetlSn: item.FeedetlSn,
  11711. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  11712. MedListCodg: item.XtHisAddtionConfig.Code,
  11713. Type: 3,
  11714. }
  11715. customs = append(customs, cus)
  11716. }
  11717. }
  11718. fmt.Println(customs)
  11719. for _, item := range customs {
  11720. var advice_id int64 = 0
  11721. var project_id int64 = 0
  11722. var item_id int64 = 0
  11723. var types int64 = 0
  11724. if item.Type == 1 {
  11725. advice_id = item.AdviceId
  11726. project_id = 0
  11727. item_id = 0
  11728. } else if item.Type == 2 {
  11729. advice_id = 0
  11730. item_id = 0
  11731. project_id = item.ProjectId
  11732. } else if item.Type == 3 {
  11733. advice_id = 0
  11734. item_id = item.ItemId
  11735. project_id = 0
  11736. }
  11737. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  11738. cut, _ := strconv.ParseFloat(item.Cut, 32)
  11739. pric, _ := strconv.ParseFloat(item.Price, 32)
  11740. info := &models.HisOrderInfo{
  11741. OrderNumber: order.Number,
  11742. UploadDate: time.Now().Unix(),
  11743. AdviceId: advice_id,
  11744. DetItemFeeSumamt: detItemFeeSumamt,
  11745. Cnt: cut,
  11746. Pric: pric,
  11747. PatientId: id,
  11748. Status: 1,
  11749. Mtime: time.Now().Unix(),
  11750. Ctime: time.Now().Unix(),
  11751. UserOrgId: adminUser.CurrentOrgId,
  11752. HisPatientId: his.ID,
  11753. OrderId: order.ID,
  11754. ProjectId: project_id,
  11755. Type: types,
  11756. ItemId: item_id,
  11757. }
  11758. service.CreateOrderInfo(info)
  11759. }
  11760. his.SickType = sick_type
  11761. service.UpdataHisPateint(&his)
  11762. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  11763. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  11764. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  11765. if err == nil {
  11766. c.ServeSuccessJSON(map[string]interface{}{
  11767. "msg": "结算成功",
  11768. })
  11769. }
  11770. }
  11771. type CustomOrderInfo struct {
  11772. Name string
  11773. Spec string
  11774. Unit string
  11775. Count float64
  11776. Price float64
  11777. Total float64
  11778. }
  11779. func (c *HisApiController) GetPrivateExpensesInfo() {
  11780. order_id, _ := c.GetInt64("id", 0)
  11781. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  11782. order, _ := service.GetHisOrderByID(order_id)
  11783. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  11784. if order.ID == 0 {
  11785. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  11786. return
  11787. }
  11788. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  11789. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  11790. org_id := c.GetAdminUserInfo().CurrentOrgId
  11791. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  11792. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  11793. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  11794. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  11795. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  11796. //var orderInfos_four []*models.HisOrderInfoTwo
  11797. //for _, item := range orderInfos_three {
  11798. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  11799. // item.HisPrescriptionProject.IsCheckTeam = 1
  11800. // orderInfos_four = append(orderInfos_four, item)
  11801. //
  11802. // }
  11803. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  11804. // item.HisPrescriptionProject.IsCheckTeam = 2
  11805. // orderInfos_two = append(orderInfos_two, item)
  11806. // }
  11807. //}
  11808. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  11809. //var cus_slice []CustomOrderInfo
  11810. //for _, item := range new_order_info {
  11811. // var cus CustomOrderInfo
  11812. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  11813. // cus.Unit = ""
  11814. // cus.Spec = ""
  11815. // var total float64
  11816. // for _, subItem := range orderInfos_four {
  11817. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  11818. // total = total + subItem.DetItemFeeSumamt
  11819. // fmt.Println(subItem.DetItemFeeSumamt)
  11820. // }
  11821. // }
  11822. // cus.Count = 1
  11823. // cus.Total = total
  11824. // cus_slice = append(cus_slice, cus)
  11825. //}
  11826. orderInfos = append(orderInfos, orderInfos_two...)
  11827. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  11828. //orderInfos = append(orderInfos, orderInfos_three...)
  11829. //}/**/
  11830. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  11831. c.ServeSuccessJSON(map[string]interface{}{
  11832. "order": order,
  11833. "order_info": orderInfos,
  11834. "patient": patient,
  11835. "admin_info": adminInfo,
  11836. "his": his,
  11837. "current_admin": role,
  11838. "org_config": miConfig,
  11839. //"new_order_info": cus_slice,
  11840. })
  11841. }
  11842. func (this *HisApiController) ChangeMedType() {
  11843. med_type := this.GetString("med_type")
  11844. old_med_type := this.GetString("old_med_type")
  11845. ids := this.GetString("ids")
  11846. settle_type, _ := this.GetInt64("settle_type")
  11847. start_time := this.GetString("start_time")
  11848. end_time := this.GetString("end_time")
  11849. ids_arr := strings.Split(ids, ",")
  11850. if settle_type == 1 { //日结
  11851. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  11852. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  11853. prescription.MedType = med_type
  11854. err := service.SaveHisPrescriptionTwo(&prescription)
  11855. if err == nil {
  11856. this.ServeSuccessJSON(map[string]interface{}{
  11857. "msg": "修改成功",
  11858. })
  11859. } else {
  11860. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11861. return
  11862. }
  11863. } else if settle_type == 2 {
  11864. timeLayout := "2006-01-02"
  11865. loc, _ := time.LoadLocation("Local")
  11866. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11867. if err != nil {
  11868. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11869. return
  11870. }
  11871. recordStartTime := theStartTime.Unix()
  11872. start_time_timestamp := recordStartTime
  11873. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  11874. if err != nil {
  11875. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11876. return
  11877. }
  11878. recordEndTime := theEndTime.Unix()
  11879. end_time_timestamp := recordEndTime
  11880. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  11881. if updateErr == nil {
  11882. this.ServeSuccessJSON(map[string]interface{}{
  11883. "msg": "修改成功",
  11884. })
  11885. } else {
  11886. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11887. return
  11888. }
  11889. }
  11890. }
  11891. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  11892. patient_id, _ := c.GetInt64("patient_id")
  11893. his_patient_id, _ := c.GetInt64("his_patient_id")
  11894. record_date := c.GetString("record_date")
  11895. start_time := c.GetString("start_time")
  11896. end_time := c.GetString("end_time")
  11897. order_status, _ := c.GetInt64("type", 0)
  11898. p_type, _ := c.GetInt64("p_type", 0)
  11899. order_id, _ := c.GetInt64("order_id", 0)
  11900. timeLayout := "2006-01-02"
  11901. loc, _ := time.LoadLocation("Local")
  11902. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11903. if err != nil {
  11904. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11905. return
  11906. }
  11907. recordDateTime := theTime.Unix()
  11908. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11909. if err != nil {
  11910. }
  11911. startRecordDateTime := startTime.Unix()
  11912. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11913. if err != nil {
  11914. }
  11915. endRecordDateTime := endTime.Unix()
  11916. admin := c.GetAdminUserInfo()
  11917. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  11918. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11919. order, _ := service.GetHisOrderByID(order_id)
  11920. var monthPrescriptions []*models.HisPrescription
  11921. if order_status == 1 || order_status == 0 {
  11922. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11923. } else if order_status == 2 {
  11924. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  11925. }
  11926. var settle_total float64
  11927. for _, item := range monthPrescriptions {
  11928. if len(item.HisPrescriptionProject) > 0 {
  11929. for _, subItem := range item.HisPrescriptionProject {
  11930. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11931. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11932. settle_total = settle_total + total
  11933. }
  11934. }
  11935. if len(item.HisDoctorAdviceInfo) > 0 {
  11936. for _, subItem := range item.HisDoctorAdviceInfo {
  11937. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11938. settle_total = settle_total + total
  11939. }
  11940. }
  11941. }
  11942. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11943. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11944. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11945. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11946. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11947. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11948. //获取所有科室信息
  11949. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11950. var dia string
  11951. for _, item := range month_p_info {
  11952. if len(dia) == 0 {
  11953. dia = item.Diagnosis
  11954. } else {
  11955. dia = dia + "," + item.Diagnosis
  11956. }
  11957. }
  11958. dia_arr := removeDuplicates(strings.Split(dia, ","))
  11959. dia_arr = removeEmptyStrings(dia_arr)
  11960. c.ServeSuccessJSON(map[string]interface{}{
  11961. "his_info": his_patient_info,
  11962. "xt_info": xt_patient_info,
  11963. "case_history": case_history,
  11964. "info": patientPrescriptionInfo,
  11965. "last_info": lastPatientPrescriptionInfo,
  11966. "month_prescriptions": monthPrescriptions,
  11967. "order": order,
  11968. "doctors": doctors,
  11969. "department": department,
  11970. "settle_total": settle_total,
  11971. "dia_arr": dia_arr,
  11972. })
  11973. return
  11974. }
  11975. func removeEmptyStrings(input []string) []string {
  11976. var output []string
  11977. for _, s := range input {
  11978. if s != "" {
  11979. output = append(output, s)
  11980. }
  11981. }
  11982. return output
  11983. }
  11984. func removeDuplicates(input []string) []string {
  11985. seen := make(map[string]bool)
  11986. output := []string{}
  11987. for _, s := range input {
  11988. if _, exists := seen[s]; !exists {
  11989. seen[s] = true
  11990. output = append(output, s)
  11991. }
  11992. }
  11993. return output
  11994. }
  11995. func (c *HisApiController) GetHisMonthPatientInfo() {
  11996. patient_id, _ := c.GetInt64("patient_id")
  11997. his_patient_id, _ := c.GetInt64("his_patient_id")
  11998. record_date := c.GetString("record_date")
  11999. number := c.GetString("number")
  12000. start_time := c.GetString("start_time")
  12001. end_time := c.GetString("end_time")
  12002. p_type, _ := c.GetInt64("p_type")
  12003. timeLayout := "2006-01-02"
  12004. loc, _ := time.LoadLocation("Local")
  12005. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12006. if err != nil {
  12007. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12008. return
  12009. }
  12010. recordDateTime := theTime.Unix()
  12011. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12012. if err != nil {
  12013. }
  12014. startRecordDateTime := startTime.Unix()
  12015. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12016. if err != nil {
  12017. }
  12018. endRecordDateTime := endTime.Unix()
  12019. admin := c.GetAdminUserInfo()
  12020. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  12021. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12022. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  12023. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12024. var settle_total float64
  12025. for _, item := range monthPrescriptions {
  12026. if len(item.HisPrescriptionProject) > 0 {
  12027. for _, subItem := range item.HisPrescriptionProject {
  12028. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12029. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12030. settle_total = settle_total + total
  12031. }
  12032. }
  12033. if len(item.HisDoctorAdviceInfo) > 0 {
  12034. for _, subItem := range item.HisDoctorAdviceInfo {
  12035. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12036. settle_total = settle_total + total
  12037. }
  12038. }
  12039. }
  12040. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12041. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12042. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12043. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12044. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  12045. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12046. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  12047. //获取所有科室信息
  12048. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12049. c.ServeSuccessJSON(map[string]interface{}{
  12050. "his_info": his_patient_info,
  12051. "xt_info": xt_patient_info,
  12052. "case_history": case_history,
  12053. "info": patientPrescriptionInfo,
  12054. "month_prescriptions": monthPrescriptions,
  12055. "order": order,
  12056. "doctors": doctors,
  12057. "department": department,
  12058. "count": count,
  12059. "drugStockConfig": drugStockConfig,
  12060. "last_info": lastPatientPrescriptionInfo,
  12061. "settle_total": settle_total,
  12062. })
  12063. return
  12064. }
  12065. func (c *HisApiController) GetAllOrder() {
  12066. org_id := c.GetAdminUserInfo().CurrentOrgId
  12067. orders, _ := service.GetNewHisOrderList(org_id)
  12068. c.ServeSuccessJSON(map[string]interface{}{
  12069. "order": orders,
  12070. })
  12071. return
  12072. }
  12073. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  12074. newArr = make([]*models.HisOrderInfoTwo, 0)
  12075. for i := 0; i < len(arr); i++ {
  12076. repeat := false
  12077. for j := i + 1; j < len(arr); j++ {
  12078. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  12079. repeat = true
  12080. break
  12081. }
  12082. }
  12083. if !repeat {
  12084. newArr = append(newArr, arr[i])
  12085. }
  12086. }
  12087. return
  12088. }
  12089. // 修改处方退库操作 参数传修改之前的处方数据
  12090. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  12091. if advice.ExecutionState == 1 {
  12092. //查询该病人该药品是否有库存记录
  12093. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  12094. if errcode == gorm.ErrRecordNotFound {
  12095. } else {
  12096. //退库
  12097. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  12098. if advice.PrescribingNumberUnit == drug.MinUnit {
  12099. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12100. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12101. //退库
  12102. warehouseInfo := models.DrugWarehouseInfo{
  12103. StockMinNumber: prescribingNumber,
  12104. }
  12105. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  12106. operation_time := time.Now().Unix()
  12107. creater := advice.AdviceDoctor
  12108. ctime := time.Now().Unix()
  12109. timeStr := time.Now().Format("2006-01-02")
  12110. timeArr := strings.Split(timeStr, "-")
  12111. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12112. total = total + 1
  12113. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12114. cancelStock := models.DrugCancelStock{
  12115. OrderNumber: orderNumber,
  12116. OperaTime: operation_time,
  12117. OrgId: advice.UserOrgId,
  12118. Creater: creater,
  12119. Ctime: ctime,
  12120. Status: 1,
  12121. ReturnTime: advice.AdviceDate,
  12122. Dealer: info.Dealer,
  12123. Manufacturer: info.Manufacturer,
  12124. Type: 1,
  12125. }
  12126. service.AddSigleDrugCancelStock(&cancelStock)
  12127. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12128. dealer, _ := service.GetDealerById(info.Dealer)
  12129. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12130. cancelStockInfo := models.DrugCancelStockInfo{
  12131. OrderNumber: cancelInfo.OrderNumber,
  12132. CancelStockId: cancelInfo.ID,
  12133. DrugId: info.DrugId,
  12134. Count: info.Count,
  12135. Status: 1,
  12136. Ctime: ctime,
  12137. OrgId: advice.UserOrgId,
  12138. Type: 1,
  12139. Manufacturer: manufactureName.ManufacturerName,
  12140. Dealer: dealer.DealerName,
  12141. Total: 0,
  12142. RetailPrice: info.RetailPrice,
  12143. RetailTotalPrice: info.RetailTotalPrice,
  12144. Price: info.Price,
  12145. RegisterAccount: "",
  12146. Remark: info.Remark,
  12147. BatchNumber: info.BatchNumber,
  12148. MaxUnit: info.CountUnit,
  12149. ProductDate: info.ProductDate,
  12150. ExpiryDate: info.ExpiryDate,
  12151. BatchNumberId: info.WarehouseInfoId,
  12152. }
  12153. flow := models.DrugFlow{
  12154. WarehousingId: 0,
  12155. DrugId: info.DrugId,
  12156. Number: "",
  12157. BatchNumber: info.BatchNumber,
  12158. Count: info.Count,
  12159. UserOrgId: advice.UserOrgId,
  12160. PatientId: 0,
  12161. SystemTime: ctime,
  12162. ConsumableType: 4,
  12163. IsSys: 0,
  12164. WarehousingOrder: "",
  12165. WarehouseOutId: 0,
  12166. WarehouseOutOrderNumber: "",
  12167. IsEdit: 0,
  12168. CancelStockId: cancelStock.ID,
  12169. CancelOrderNumber: cancelStock.OrderNumber,
  12170. Manufacturer: info.Manufacturer,
  12171. Dealer: info.Dealer,
  12172. Creator: advice.UserOrgId,
  12173. UpdateCreator: 0,
  12174. Status: 1,
  12175. Ctime: time.Now().Unix(),
  12176. Mtime: 0,
  12177. Price: info.Price,
  12178. WarehousingDetailId: 0,
  12179. WarehouseOutDetailId: 0,
  12180. CancelOutDetailId: 0,
  12181. ExpireDate: info.ExpiryDate,
  12182. ProductDate: info.ProductDate,
  12183. MaxUnit: info.CountUnit,
  12184. MinUnit: "",
  12185. }
  12186. service.CreatedCancelStock(cancelStockInfo)
  12187. service.CreateDrugFlowOne(flow)
  12188. } else {
  12189. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12190. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12191. if advice.PrescribingNumberUnit == drug.MaxUnit {
  12192. warehouseInfo := models.DrugWarehouseInfo{
  12193. StockMinNumber: prescribingNumber,
  12194. }
  12195. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  12196. }
  12197. operation_time := time.Now().Unix()
  12198. creater := advice.AdviceDoctor
  12199. ctime := time.Now().Unix()
  12200. timeStr := time.Now().Format("2006-01-02")
  12201. timeArr := strings.Split(timeStr, "-")
  12202. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12203. total = total + 1
  12204. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12205. cancelStock := models.DrugCancelStock{
  12206. OrderNumber: orderNumber,
  12207. OperaTime: operation_time,
  12208. OrgId: advice.UserOrgId,
  12209. Creater: creater,
  12210. Ctime: ctime,
  12211. Status: 1,
  12212. ReturnTime: advice.AdviceDate,
  12213. Dealer: info.Dealer,
  12214. Manufacturer: info.Manufacturer,
  12215. Type: 1,
  12216. }
  12217. service.AddSigleDrugCancelStock(&cancelStock)
  12218. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12219. dealer, _ := service.GetDealerById(info.Dealer)
  12220. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12221. cancelStockInfo := models.DrugCancelStockInfo{
  12222. OrderNumber: cancelInfo.OrderNumber,
  12223. CancelStockId: cancelInfo.ID,
  12224. DrugId: info.DrugId,
  12225. Count: info.Count,
  12226. Status: 1,
  12227. Ctime: ctime,
  12228. OrgId: advice.UserOrgId,
  12229. Type: 1,
  12230. Manufacturer: manufactureName.ManufacturerName,
  12231. Dealer: dealer.DealerName,
  12232. Total: 0,
  12233. RetailPrice: info.RetailPrice,
  12234. RetailTotalPrice: info.RetailTotalPrice,
  12235. Price: info.Price,
  12236. RegisterAccount: "",
  12237. Remark: info.Remark,
  12238. BatchNumber: info.BatchNumber,
  12239. MaxUnit: info.CountUnit,
  12240. ProductDate: info.ProductDate,
  12241. ExpiryDate: info.ExpiryDate,
  12242. BatchNumberId: info.WarehouseInfoId,
  12243. }
  12244. flow := models.DrugFlow{
  12245. WarehousingId: 0,
  12246. DrugId: info.DrugId,
  12247. Number: "",
  12248. BatchNumber: info.BatchNumber,
  12249. Count: info.Count,
  12250. UserOrgId: advice.UserOrgId,
  12251. PatientId: 0,
  12252. SystemTime: ctime,
  12253. ConsumableType: 4,
  12254. IsSys: 0,
  12255. WarehousingOrder: "",
  12256. WarehouseOutId: 0,
  12257. WarehouseOutOrderNumber: "",
  12258. IsEdit: 0,
  12259. CancelStockId: cancelStock.ID,
  12260. CancelOrderNumber: cancelStock.OrderNumber,
  12261. Manufacturer: info.Manufacturer,
  12262. Dealer: info.Dealer,
  12263. Creator: advice.AdviceDoctor,
  12264. UpdateCreator: 0,
  12265. Status: 1,
  12266. Ctime: time.Now().Unix(),
  12267. Mtime: 0,
  12268. Price: info.Price,
  12269. WarehousingDetailId: 0,
  12270. WarehouseOutDetailId: 0,
  12271. CancelOutDetailId: 0,
  12272. ExpireDate: info.ExpiryDate,
  12273. ProductDate: info.ProductDate,
  12274. MaxUnit: info.CountUnit,
  12275. MinUnit: "",
  12276. }
  12277. service.CreatedCancelStock(cancelStockInfo)
  12278. service.CreateDrugFlowOne(flow)
  12279. }
  12280. }
  12281. }
  12282. return err
  12283. }
  12284. func (this *HisApiController) DeleteNCDS() {
  12285. id, _ := this.GetInt64("id", 0)
  12286. if id > 0 {
  12287. service.DeletePsnNCDSRecordById(id)
  12288. this.ServeSuccessJSON(map[string]interface{}{
  12289. "msg": "删除成功",
  12290. })
  12291. } else {
  12292. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  12293. return
  12294. }
  12295. }
  12296. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  12297. id, _ := c.GetInt64("id")
  12298. advice, _ := service.GetHisDoctorAdviceInfo(id)
  12299. c.ServeSuccessJSON(map[string]interface{}{
  12300. "advice": advice,
  12301. })
  12302. return
  12303. }
  12304. func (c *HisApiController) GetHisMonthChargePatientList() {
  12305. record_date := c.GetString("record_date")
  12306. start_time := c.GetString("start_time")
  12307. end_time := c.GetString("end_time")
  12308. timeLayout := "2006-01-02"
  12309. loc, _ := time.LoadLocation("Local")
  12310. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12311. if err != nil {
  12312. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12313. return
  12314. }
  12315. if err != nil {
  12316. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12317. return
  12318. }
  12319. recordDateTime := theTime.Unix()
  12320. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12321. if err != nil {
  12322. }
  12323. startRecordDateTime := startTime.Unix()
  12324. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12325. if err != nil {
  12326. }
  12327. endRecordDateTime := endTime.Unix()
  12328. adminInfo := c.GetAdminUserInfo()
  12329. var tempMonthChargePatients []*service.MonthChargePatients
  12330. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  12331. for _, item := range tempPatients {
  12332. //过滤没有处方的
  12333. if len(item.HisPrescription) == 0 {
  12334. tempMonthChargePatients = append(tempMonthChargePatients, item)
  12335. }
  12336. }
  12337. c.ServeSuccessJSON(map[string]interface{}{
  12338. "list": tempMonthChargePatients,
  12339. })
  12340. }
  12341. // PrescriptionDifference 医嘱数量差值结构体
  12342. type PrescriptionDrugDifference struct {
  12343. DrugID int64 //基础库药品id
  12344. ID int64 //医嘱id
  12345. Difference float64 //差值
  12346. Unit string //单位
  12347. }
  12348. type PrescriptionGoodDifference struct {
  12349. GoodID int64 //基础库项目耗材id
  12350. ID int64 //医嘱id
  12351. Difference int64 //差值
  12352. Unit string //单位
  12353. Type int64 //类型
  12354. }
  12355. type EditCustomData struct {
  12356. adviceList []*models.HisDoctorAdviceInfo
  12357. projectList []*models.HisPrescriptionProject
  12358. }
  12359. type SrcCustomData struct {
  12360. adviceList []*models.HisDoctorAdviceInfo
  12361. projectList []*models.HisPrescriptionProject
  12362. }
  12363. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  12364. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  12365. differences := make([]*PrescriptionDrugDifference, 0)
  12366. // 创建一个 map 来存储第一个切片中的药品信息
  12367. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  12368. for _, advice := range firstPrescription {
  12369. firstMap[advice.DrugId] = advice
  12370. }
  12371. // 遍历第二个切片中的药品信息,并比较数量差值
  12372. for _, advice := range secondPrescription {
  12373. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  12374. diff := &PrescriptionDrugDifference{
  12375. DrugID: advice.DrugId,
  12376. ID: firstAdvice.ID,
  12377. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  12378. Unit: firstAdvice.PrescribingNumberUnit,
  12379. }
  12380. differences = append(differences, diff)
  12381. }
  12382. }
  12383. return differences
  12384. }
  12385. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  12386. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  12387. differences := make([]*PrescriptionGoodDifference, 0)
  12388. // 创建一个 map 来存储第一个切片中的耗材信息
  12389. firstMap := make(map[int64]*models.HisPrescriptionProject)
  12390. for _, good := range firstPrescription {
  12391. firstMap[good.ProjectId] = good
  12392. }
  12393. // 遍历第二个切片中的耗材信息,并比较数量差值
  12394. for _, good := range secondPrescription {
  12395. if firstGood, ok := firstMap[good.ProjectId]; ok {
  12396. count, _ := strconv.ParseInt(good.Count, 10, 64)
  12397. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  12398. diff := &PrescriptionGoodDifference{
  12399. GoodID: good.ProjectId,
  12400. ID: firstGood.ID,
  12401. Difference: count - firstCount,
  12402. Unit: firstGood.Unit,
  12403. Type: firstGood.Type,
  12404. }
  12405. differences = append(differences, diff)
  12406. }
  12407. }
  12408. return differences
  12409. }
  12410. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  12411. var adviceList []*models.HisDoctorAdviceInfo
  12412. var projectList []*models.HisPrescriptionProject
  12413. var advice_ids []int64
  12414. var project_ids []int64
  12415. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12416. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12417. //var tempPrescription *models.HisPrescriptionProjectscription
  12418. if len(prescriptions) > 0 {
  12419. for _, item := range prescriptions {
  12420. items := item.(map[string]interface{})
  12421. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12422. advices := items["advices"].([]interface{})
  12423. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12424. groupNo := int64(0)
  12425. ctime := time.Now().Unix()
  12426. mtime := ctime
  12427. if len(advices) > 0 {
  12428. for _, advice := range advices {
  12429. var s models.HisDoctorAdviceInfo
  12430. s.AdviceType = 2
  12431. s.StopState = 2
  12432. s.ExecutionState = 2
  12433. s.Status = 1
  12434. s.Groupno = groupNo
  12435. s.CreatedTime = ctime
  12436. s.UpdatedTime = mtime
  12437. s.IsSettle = 2
  12438. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  12439. //存储切片中
  12440. if s.ID > 0 {
  12441. advice_ids = append(advice_ids, s.ID)
  12442. adviceList = append(adviceList, &s)
  12443. }
  12444. }
  12445. }
  12446. }
  12447. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12448. projects := items["project"].([]interface{})
  12449. if len(projects) > 0 {
  12450. for _, project := range projects {
  12451. var p models.HisPrescriptionProject
  12452. p.Ctime = time.Now().Unix()
  12453. p.Mtime = time.Now().Unix()
  12454. p.Status = 1
  12455. SetProjectWithJSON(&p, project.(map[string]interface{}))
  12456. if p.ID > 0 {
  12457. project_ids = append(project_ids, p.ID)
  12458. projectList = append(projectList, &p)
  12459. }
  12460. }
  12461. }
  12462. }
  12463. }
  12464. }
  12465. }
  12466. editCustomData.projectList = projectList
  12467. editCustomData.adviceList = adviceList
  12468. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  12469. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  12470. srcCustomData.adviceList = list
  12471. srcCustomData.projectList = list2
  12472. return
  12473. }