his_api_controller.go 551KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math/rand"
  6. "reflect"
  7. "strconv"
  8. "strings"
  9. "syscall"
  10. "time"
  11. "unsafe"
  12. "XT_New/enums"
  13. "XT_New/models"
  14. "XT_New/service"
  15. "XT_New/utils"
  16. "github.com/astaxie/beego"
  17. "github.com/jinzhu/gorm"
  18. "github.com/mozillazg/go-pinyin"
  19. "github.com/shopspring/decimal"
  20. )
  21. type HisApiController struct {
  22. BaseAuthAPIController
  23. }
  24. func HisManagerApiRegistRouters() {
  25. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  26. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  27. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  28. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  29. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  30. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  31. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  32. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  33. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  34. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  35. //beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  36. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  37. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  41. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  42. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  43. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  44. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  45. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  46. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  47. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  48. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  49. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  50. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  51. //新增附加费用
  52. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  53. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  54. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  55. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  56. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  57. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  58. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  59. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  60. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  61. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  62. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  63. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  64. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  65. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  66. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  67. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  86. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  87. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  88. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  89. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  90. beego.Router("/api/getallgoodinforlist", &HisApiController{}, "Get:GetAllGoodInforList")
  91. }
  92. func (c *HisApiController) CheckHisPatient() {
  93. record_date := c.GetString("record_date")
  94. patient_id, _ := c.GetInt64("patient_id")
  95. timeLayout := "2006-01-02"
  96. loc, _ := time.LoadLocation("Local")
  97. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  98. if err != nil {
  99. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  100. return
  101. }
  102. recordDateTime := theTime.Unix()
  103. adminInfo := c.GetAdminUserInfo()
  104. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  105. if len(patients) > 1 {
  106. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  107. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  108. c.ServeSuccessJSON(map[string]interface{}{
  109. "status": 1,
  110. "msg": "关联",
  111. "ps": ps,
  112. "his_patient_id": patients[len(patients)-1].ID,
  113. "patient_id": patients[len(patients)-1].PatientId,
  114. })
  115. } else {
  116. c.ServeSuccessJSON(map[string]interface{}{
  117. "status": 0,
  118. "msg": "无需关联",
  119. })
  120. }
  121. } else {
  122. c.ServeSuccessJSON(map[string]interface{}{
  123. "status": 0,
  124. "msg": "无需关联",
  125. })
  126. return
  127. }
  128. }
  129. func (c *HisApiController) AssociationHisPrescription() {
  130. record_date := c.GetString("record_date")
  131. his_patient_id, _ := c.GetInt64("his_patient_id")
  132. patient_id, _ := c.GetInt64("patient_id")
  133. p_ids := c.GetString("p_ids")
  134. p_ids_arr := strings.Split(p_ids, ",")
  135. timeLayout := "2006-01-02"
  136. loc, _ := time.LoadLocation("Local")
  137. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  138. if err != nil {
  139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  140. return
  141. }
  142. recordDateTime := theTime.Unix()
  143. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  144. if his_patient_id == 0 || his_patient.ID == 0 {
  145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  146. return
  147. }
  148. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  149. if err == nil {
  150. c.ServeSuccessJSON(map[string]interface{}{
  151. "msg": "关联处方成功",
  152. })
  153. return
  154. } else {
  155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  156. return
  157. }
  158. }
  159. //func (c *HisApiController) AssociationHisPrescription() {
  160. // record_date, _ := c.GetInt64("record_date")
  161. // his_patient_id, _ := c.GetInt64("his_patient_id")
  162. // patient_id, _ := c.GetInt64("patient_id")
  163. // p_ids := c.GetString("p_ids")
  164. // p_ids_arr := strings.Split(p_ids, ",")
  165. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  166. // if his_patient_id == 0 || his_patient.ID == 0 {
  167. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  168. // return
  169. // }
  170. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  171. // if err == nil {
  172. // c.ServeSuccessJSON(map[string]interface{}{
  173. // "msg": "关联处方成功",
  174. // })
  175. // return
  176. // } else {
  177. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  178. // return
  179. // }
  180. //}
  181. func (c *HisApiController) GetFaPiaoNumber() {
  182. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  183. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  184. fmt.Println(count)
  185. var zero string
  186. number := count + 1
  187. //if number >= 1000 {
  188. // zero = "0000" + strconv.FormatInt(number, 10)
  189. //} else if number >= 10000 {
  190. // zero = "000" + strconv.FormatInt(number, 10)
  191. //} else if number >= 100000 {
  192. // zero = "00" + strconv.FormatInt(number, 10)
  193. //} else if number >= 1000000 {
  194. // zero = "0" + strconv.FormatInt(number, 10)
  195. //} else {
  196. zero = "0" + strconv.FormatInt(number, 10)
  197. //}
  198. c.ServeSuccessJSON(map[string]interface{}{
  199. "fapiao_number": zero,
  200. })
  201. return
  202. }
  203. func (c *HisApiController) ChangeOrderDesc() {
  204. id, _ := c.GetInt64("id")
  205. desc := c.GetString("desc")
  206. change_type := c.GetString("change_type")
  207. order, _ := service.GetHisOrderByID(id)
  208. if order.ID == 0 {
  209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  210. return
  211. }
  212. switch change_type {
  213. case "oth_desc":
  214. order.OthDesc = desc
  215. break
  216. case "cash_pay":
  217. order.CashPay = desc
  218. break
  219. case "jifen_pay":
  220. order.JifenPay = desc
  221. break
  222. case "band_card_pay":
  223. order.BandCardPay = desc
  224. break
  225. case "ali_pay":
  226. order.AliPay = desc
  227. break
  228. case "wechat_pay":
  229. order.WechatPay = desc
  230. break
  231. case "fa_piao_number":
  232. order.FaPiaoNumber = desc
  233. break
  234. case "fa_piao_code":
  235. order.FaPiaoCode = desc
  236. break
  237. }
  238. err := service.SaveHisOrder(&order)
  239. if err == nil {
  240. c.ServeSuccessJSON(map[string]interface{}{
  241. "msg": "修改成功",
  242. })
  243. return
  244. } else {
  245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  246. return
  247. }
  248. }
  249. func (c *HisApiController) GetMonthHisPatient() {
  250. record_date := c.GetString("record_date")
  251. //order_status, _ := c.GetInt64("type")
  252. timeLayout := "2006-01-02"
  253. loc, _ := time.LoadLocation("Local")
  254. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  255. if err != nil {
  256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  257. return
  258. }
  259. recordDateTime := theTime.Unix()
  260. adminInfo := c.GetAdminUserInfo()
  261. var tempPatients []service.NewTempPatients
  262. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  263. // 获取当前时间
  264. now := time.Now()
  265. // 获取本月的第一天
  266. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  267. // 获取下个月的第一天
  268. nextMonth := firstDay.AddDate(0, 1, 0)
  269. // 获取本月的最后一天
  270. lastDay := nextMonth.Add(-time.Nanosecond)
  271. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  272. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  273. var patients []service.NewTempPatients
  274. var patients_two []service.NewTempPatients
  275. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  276. for _, item := range tempPatients {
  277. //过滤掉没挂号的和没开处方的
  278. if len(item.HisPrescription) > 0 {
  279. patients = append(patients, item)
  280. patients_two = append(patients_two, item)
  281. }
  282. ////过滤掉没挂号的
  283. //if len(item.HisPatient) > 0 {
  284. //}
  285. }
  286. } else {
  287. for _, item := range tempPatients {
  288. //过滤掉没挂号的和没开处方的
  289. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  290. patients = append(patients, item)
  291. }
  292. ////过滤掉没挂号的
  293. //if len(item.HisPatient) > 0 {
  294. // patients_two = append(patients_two, item)
  295. //}
  296. }
  297. }
  298. c.ServeSuccessJSON(map[string]interface{}{
  299. "list": patients,
  300. "list_two": patients_two,
  301. "chargePatients": chargePatients,
  302. })
  303. }
  304. func (c *HisApiController) GetBatchSettleAccounts() {
  305. order_ids := c.GetString("order_ids")
  306. admin_user_id, _ := c.GetInt64("admin_user_id")
  307. adminUser := c.GetAdminUserInfo()
  308. orders := strings.Split(order_ids, ",")
  309. var newOrders []models.Orders
  310. for _, item := range orders {
  311. order, _ := service.GetHisOrderByIDTenOne(item)
  312. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  313. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  314. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  315. orderInfos = append(orderInfos, orderInfos_two...)
  316. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  317. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  318. var diagnosis_ids []string
  319. if his.ID > 0 {
  320. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  321. } else {
  322. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  323. }
  324. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  325. var dia_config []*models.HisXtDiagnoseConfig
  326. var name string
  327. for _, item := range diagnosis_ids {
  328. id, _ := strconv.ParseInt(item, 10, 64)
  329. diagnosisConfig, _ := service.FindDiagnoseById(id)
  330. dia_config = append(dia_config, diagnosisConfig)
  331. if len(name) == 0 {
  332. name = diagnosisConfig.ClassName
  333. } else {
  334. name = name + "," + diagnosisConfig.ClassName
  335. }
  336. }
  337. var bedCostTotal float64 = 0 //床位总费
  338. var bedCostSelfTotal float64 = 0 //床位自费
  339. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  340. var bedSelfTotal float64 = 0 //床位部分项目自费
  341. var bedInscpTotal float64 = 0 //床位部分项目自费
  342. var operationCostTotal float64 = 0 //手术费
  343. var operationCostSelfTotal float64 = 0 //手术费
  344. var operationCostPartSelfTotal float64 = 0 //手术费
  345. var operationSelfTotal float64 = 0 //床位部分项目自费
  346. var operationInscpTotal float64 = 0 //床位部分项目自费
  347. var otherCostTotal float64 = 0 //其他费用
  348. var otherCostSelfTotal float64 = 0 //其他费用
  349. var otherCostPartSelfTotal float64 = 0 //其他费用
  350. var otherSelfTotal float64 = 0 //床位部分项目自费
  351. var otherInscpTotal float64 = 0 //床位部分项目自费
  352. var materialCostTotal float64 = 0 //材料费
  353. var materialCostSelfTotal float64 = 0 //材料费
  354. var materialCostPartSelfTotal float64 = 0 //材料费
  355. var materialSelfTotal float64 = 0 //床位部分项目自费
  356. var materialInscpTotal float64 = 0 //床位部分项目自费
  357. var westernMedicineCostTotal float64 = 0 //西药费
  358. var westernMedicineCostSelfTotal float64 = 0 //西药费
  359. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  360. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  361. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  362. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  363. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  364. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  365. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  366. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  367. var checkCostTotal float64 = 0 //检查费
  368. var checkCostSelfTotal float64 = 0 //检查费
  369. var checkCostPartSelfTotal float64 = 0 //检查费
  370. var checkSelfTotal float64 = 0 //床位部分项目自费
  371. var checkInscpTotal float64 = 0 //床位部分项目自费
  372. var laboratoryCostTotal float64 = 0 //化验费
  373. var laboratoryCostSelfTotal float64 = 0 //化验费
  374. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  375. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  376. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  377. var treatCostTotal float64 = 0 //治疗费用
  378. var treatCostSelfTotal float64 = 0 //治疗费用
  379. var treatCostPartSelfTotal float64 = 0 //治疗费用
  380. var treatSelfTotal float64 = 0 //床位部分项目自费
  381. var treatInscpTotal float64 = 0 //床位部分项目自费
  382. decimal.DivisionPrecision = 2
  383. for _, item := range orderInfos {
  384. if item.MedChrgitmType == "01" { //床位费
  385. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  386. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  387. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  388. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  389. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  390. }
  391. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  392. if item.MedChrgitmType == "03" { //检查费
  393. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  394. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  395. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  396. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  397. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  398. }
  399. } else {
  400. if item.MedChrgitmType == "03" { //检查费
  401. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  402. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  403. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  404. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  405. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  406. }
  407. }
  408. if item.MedChrgitmType == "04" { //化验费
  409. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  410. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  411. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  412. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  413. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  414. }
  415. if item.MedChrgitmType == "05" { //治疗费
  416. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  417. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  418. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  419. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  420. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  421. }
  422. if item.MedChrgitmType == "06" { //手术费
  423. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  424. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  425. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  426. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  427. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  428. }
  429. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  430. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  431. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  432. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  433. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  434. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  435. }
  436. if item.MedChrgitmType == "09" { //西药费
  437. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  438. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  439. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  440. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  441. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  442. }
  443. if item.MedChrgitmType == "11" { //中成费
  444. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  445. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  446. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  447. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  448. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  449. }
  450. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  451. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  452. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  453. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  454. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  455. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  456. }
  457. }
  458. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  459. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  460. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  461. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  462. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  463. var doctor_name string
  464. if roles.ID == 0 {
  465. doctor_name = "管理员"
  466. } else {
  467. doctor_name = roles.UserName
  468. }
  469. yiliao_leibie := ""
  470. switch order.MedType {
  471. case "11":
  472. yiliao_leibie = "普通门诊"
  473. break
  474. case "12":
  475. yiliao_leibie = "门诊挂号"
  476. break
  477. case "13":
  478. yiliao_leibie = "急诊"
  479. break
  480. case "14":
  481. yiliao_leibie = "门诊特殊病"
  482. break
  483. case "15":
  484. yiliao_leibie = "门诊统筹"
  485. break
  486. case "16":
  487. yiliao_leibie = "门诊慢性病"
  488. break
  489. case "21":
  490. yiliao_leibie = "普通住院"
  491. break
  492. }
  493. var newOrder models.Orders
  494. newOrder.Diagnosis = name
  495. newOrder.OrderInfos = orderInfos
  496. newOrder.Number = order.MdtrtId
  497. newOrder.Date = order.SettleAccountsDate
  498. newOrder.ChargeAdmin = charge_admin
  499. newOrder.PrintorAdmin = printor_admin
  500. newOrder.Order = order
  501. newOrder.BedCostTotal = bedCostTotal
  502. newOrder.BedCostSelfTotal = bedCostSelfTotal
  503. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  504. newOrder.BedSelfTotal = bedSelfTotal
  505. newOrder.BedInscpTotal = bedInscpTotal
  506. newOrder.OperationCostTotal = operationCostTotal
  507. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  508. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  509. newOrder.OperationSelfTotal = operationSelfTotal
  510. newOrder.OperationInscpTotal = operationInscpTotal
  511. newOrder.OtherCostTotal = otherCostTotal
  512. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  513. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  514. newOrder.OtherSelfTotal = otherSelfTotal
  515. newOrder.OtherInscpTotal = otherInscpTotal
  516. newOrder.MaterialCostTotal = materialCostTotal
  517. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  518. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  519. newOrder.MaterialSelfTotal = materialSelfTotal
  520. newOrder.MaterialInscpTotal = materialInscpTotal
  521. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  522. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  523. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  524. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  525. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  526. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  527. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  528. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  529. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  530. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  531. newOrder.CheckCostTotal = checkCostTotal
  532. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  533. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  534. newOrder.CheckSelfTotal = checkSelfTotal
  535. newOrder.CheckInscpTotal = checkInscpTotal
  536. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  537. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  538. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  539. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  540. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  541. newOrder.TreatCostTotal = treatCostTotal
  542. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  543. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  544. newOrder.TreatSelfTotal = treatSelfTotal
  545. newOrder.TreatInscpTotal = treatInscpTotal
  546. newOrder.DoctorInfo = doctor_info
  547. newOrder.DoctorName = doctor_name
  548. newOrder.HealthCardNo = order.PsnNo
  549. newOrder.YiliaoLeibie = yiliao_leibie
  550. newOrder.Patient = patient
  551. newOrder.OrgName = miConfig.OrgName
  552. newOrder.OrgCode = miConfig.Code
  553. newOrder.OrderNumber = order.Number
  554. newOrder.HisPatient = his
  555. newOrder.DiaConfig = dia_config
  556. newOrders = append(newOrders, newOrder)
  557. }
  558. c.ServeSuccessJSON(map[string]interface{}{
  559. "orders": newOrders,
  560. })
  561. }
  562. func (c *HisApiController) GetTestOrder() {
  563. order_id, _ := c.GetInt64("order_id")
  564. admin_user_id, _ := c.GetInt64("admin_user_id")
  565. adminUser := c.GetAdminUserInfo()
  566. order, _ := service.GetHisOrderByID(order_id)
  567. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  568. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  569. orderInfos = append(orderInfos, orderInfos_two...)
  570. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  571. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  572. var dia_config []*models.HisXtDiagnoseConfig
  573. var name string
  574. var bedCostTotal float64 = 0 //床位总费
  575. var bedCostSelfTotal float64 = 0 //床位自费
  576. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  577. var bedSelfTotal float64 = 0 //床位部分项目自费
  578. var bedInscpTotal float64 = 0 //床位部分项目自费
  579. var operationCostTotal float64 = 0 //手术费
  580. var operationCostSelfTotal float64 = 0 //手术费
  581. var operationCostPartSelfTotal float64 = 0 //手术费
  582. var operationSelfTotal float64 = 0 //床位部分项目自费
  583. var operationInscpTotal float64 = 0 //床位部分项目自费
  584. var otherCostTotal float64 = 0 //其他费用
  585. var otherCostSelfTotal float64 = 0 //其他费用
  586. var otherCostPartSelfTotal float64 = 0 //其他费用
  587. var otherSelfTotal float64 = 0 //床位部分项目自费
  588. var otherInscpTotal float64 = 0 //床位部分项目自费
  589. var materialCostTotal float64 = 0 //材料费
  590. var materialCostSelfTotal float64 = 0 //材料费
  591. var materialCostPartSelfTotal float64 = 0 //材料费
  592. var materialSelfTotal float64 = 0 //床位部分项目自费
  593. var materialInscpTotal float64 = 0 //床位部分项目自费
  594. var westernMedicineCostTotal float64 = 0 //西药费
  595. var westernMedicineCostSelfTotal float64 = 0 //西药费
  596. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  597. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  598. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  599. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  600. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  601. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  602. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  603. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  604. var checkCostTotal float64 = 0 //检查费
  605. var checkCostSelfTotal float64 = 0 //检查费
  606. var checkCostPartSelfTotal float64 = 0 //检查费
  607. var checkSelfTotal float64 = 0 //床位部分项目自费
  608. var checkInscpTotal float64 = 0 //床位部分项目自费
  609. var laboratoryCostTotal float64 = 0 //化验费
  610. var laboratoryCostSelfTotal float64 = 0 //化验费
  611. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  612. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  613. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  614. var treatCostTotal float64 = 0 //治疗费用
  615. var treatCostSelfTotal float64 = 0 //治疗费用
  616. var treatCostPartSelfTotal float64 = 0 //治疗费用
  617. var treatSelfTotal float64 = 0 //床位部分项目自费
  618. var treatInscpTotal float64 = 0 //床位部分项目自费
  619. decimal.DivisionPrecision = 2
  620. for _, item := range orderInfos {
  621. if item.MedChrgitmType == "01" { //床位费
  622. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  623. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  624. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  625. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  626. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  627. }
  628. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  629. if item.MedChrgitmType == "03" { //检查费
  630. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  631. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  632. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  633. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  634. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  635. }
  636. } else {
  637. if item.MedChrgitmType == "03" { //检查费
  638. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  639. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  640. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  641. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  642. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  643. }
  644. }
  645. if item.MedChrgitmType == "04" { //化验费
  646. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  647. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  648. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  649. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  650. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  651. }
  652. if item.MedChrgitmType == "05" { //治疗费
  653. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  654. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  655. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  656. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  657. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  658. }
  659. if item.MedChrgitmType == "06" { //手术费
  660. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  661. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  662. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  663. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  664. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  665. }
  666. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  667. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  668. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  669. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  670. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  671. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  672. }
  673. if item.MedChrgitmType == "09" { //西药费
  674. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  675. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  676. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  677. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  678. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  679. }
  680. if item.MedChrgitmType == "11" { //中成费
  681. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  682. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  683. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  684. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  685. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  686. }
  687. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  688. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  689. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  690. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  691. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  692. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  693. }
  694. }
  695. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  696. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  697. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  698. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  699. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  700. var doctor_name string
  701. if roles.ID == 0 {
  702. doctor_name = "管理员"
  703. } else {
  704. doctor_name = roles.UserName
  705. }
  706. yiliao_leibie := ""
  707. switch order.MedType {
  708. case "11":
  709. yiliao_leibie = "普通门诊"
  710. break
  711. case "12":
  712. yiliao_leibie = "门诊挂号"
  713. break
  714. case "13":
  715. yiliao_leibie = "急诊"
  716. break
  717. case "14":
  718. yiliao_leibie = "门诊特殊病"
  719. break
  720. case "15":
  721. yiliao_leibie = "门诊统筹"
  722. break
  723. case "16":
  724. yiliao_leibie = "门诊慢性病"
  725. break
  726. case "21":
  727. yiliao_leibie = "普通住院"
  728. break
  729. }
  730. c.ServeSuccessJSON(map[string]interface{}{
  731. "diagnosis": name,
  732. "order_infos": orderInfos,
  733. "number": order.MdtrtId,
  734. "date": order.SettleAccountsDate,
  735. "charge_admin": charge_admin,
  736. "printor_admin": printor_admin,
  737. "info": order,
  738. "order": order,
  739. "bedCostTotal": bedCostTotal,
  740. "bedCostSelfTotal": bedCostSelfTotal,
  741. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  742. "bedSelfTotal": bedSelfTotal,
  743. "bedInscpTotal": bedInscpTotal,
  744. "operationCostTotal": operationCostTotal,
  745. "operationCostSelfTotal": operationCostSelfTotal,
  746. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  747. "operationSelfTotal": operationSelfTotal,
  748. "operationInscpTotal": operationInscpTotal,
  749. "otherCostTotal": otherCostTotal,
  750. "otherCostSelfTotal": otherCostSelfTotal,
  751. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  752. "otherSelfTotal": otherSelfTotal,
  753. "otherInscpTotal": otherInscpTotal,
  754. "materialCostTotal": materialCostTotal,
  755. "materialCostSelfTotal": materialCostSelfTotal,
  756. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  757. "materialSelfTotal": materialSelfTotal,
  758. "materialInscpTotal": materialInscpTotal,
  759. "westernMedicineCostTotal": westernMedicineCostTotal,
  760. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  761. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  762. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  763. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  764. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  765. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  766. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  767. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  768. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  769. "checkCostTotal": checkCostTotal,
  770. "checkCostSelfTotal": checkCostSelfTotal,
  771. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  772. "checkSelfTotal": checkSelfTotal,
  773. "checkInscpTotal": checkInscpTotal,
  774. "laboratoryCostTotal": laboratoryCostTotal,
  775. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  776. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  777. "laboratorySelfTotal": laboratorySelfTotal,
  778. "laboratoryInscpTotal": laboratoryInscpTotal,
  779. "treatCostTotal": treatCostTotal,
  780. "treatCostSelfTotal": treatCostSelfTotal,
  781. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  782. "treatSelfTotal": treatSelfTotal,
  783. "treatInscpTotal": treatInscpTotal,
  784. "doctor_info": doctor_info,
  785. "doctor_name": doctor_name,
  786. "health_card_no": order.PsnNo,
  787. "yiliao_leibie": yiliao_leibie,
  788. "patient": patient,
  789. "org_name": miConfig.OrgName,
  790. "org_code": miConfig.Code,
  791. "order_number": order.Number,
  792. "his_hospital": his_hospital,
  793. "dia_config": dia_config,
  794. })
  795. }
  796. type CustomFundPay struct {
  797. FundPayType string `json:"fund_pay_type"`
  798. FundPayamt float64 `json:"fund_payamt"`
  799. InscpScpAmt float64 `json:"inscp_scp_amt"`
  800. }
  801. func (c *PublicApiController) GetBaiLinExportData() {
  802. data := service.GetBaiLinOrderData()
  803. fmt.Println(len(data))
  804. var new_data []*models.NewCustomHisOrder
  805. for _, item := range data {
  806. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  807. new_data = append(new_data, item)
  808. }
  809. }
  810. fmt.Println(len(new_data))
  811. c.ServeSuccessJSON(map[string]interface{}{
  812. "list": new_data,
  813. })
  814. }
  815. func (c *HisApiController) GetHisUnChargePatientList() {
  816. record_date := c.GetString("record_date")
  817. sch_type, _ := c.GetInt64("sch_type")
  818. timeLayout := "2006-01-02"
  819. loc, _ := time.LoadLocation("Local")
  820. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  821. if err != nil {
  822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  823. return
  824. }
  825. recordDateTime := theTime.Unix()
  826. adminInfo := c.GetAdminUserInfo()
  827. var tempPatients []*service.NewTempPatients
  828. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  829. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  830. var patients []*service.NewTempPatients
  831. var patients_two []*service.NewTempPatients
  832. for _, item := range tempPatients {
  833. //过滤掉没挂号的和没开处方的
  834. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  835. patients = append(patients, item)
  836. }
  837. //过滤掉没挂号的
  838. if len(item.HisPatient) > 0 {
  839. patients_two = append(patients_two, item)
  840. }
  841. }
  842. c.ServeSuccessJSON(map[string]interface{}{
  843. "list": patients,
  844. "list_two": patients_two,
  845. })
  846. }
  847. func (c *HisApiController) GetPrivateExpensesOrder() {
  848. //id, _ := c.GetInt64("id")
  849. //record_time := c.GetString("record_time")
  850. order_id, _ := c.GetInt64("order_id")
  851. admin_user_id, _ := c.GetInt64("admin_user_id")
  852. //timeLayout := "2006-01-02"
  853. //loc, _ := time.LoadLocation("Local")
  854. //
  855. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  856. //if err != nil {
  857. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  858. // return
  859. //}
  860. //recordDateTime := theTime.Unix()
  861. adminUser := c.GetAdminUserInfo()
  862. order, _ := service.GetHisOrderByID(order_id)
  863. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  864. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  865. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  866. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  867. //var config []*models.HisXtDiagnoseConfig
  868. var name string
  869. if order.PType == 1 {
  870. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  871. for _, item := range diagnosis_ids {
  872. id, _ := strconv.ParseInt(item, 10, 64)
  873. diagnosisConfig, _ := service.FindDiagnoseById(id)
  874. if len(name) == 0 {
  875. name = diagnosisConfig.ClassName
  876. } else {
  877. name = name + "," + diagnosisConfig.ClassName
  878. }
  879. }
  880. } else {
  881. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  882. for _, item := range diagnosis_ids {
  883. id, _ := strconv.ParseInt(item, 10, 64)
  884. diagnosisConfig, _ := service.FindDiagnoseById(id)
  885. if len(name) == 0 {
  886. name = diagnosisConfig.ClassName
  887. } else {
  888. name = name + "," + diagnosisConfig.ClassName
  889. }
  890. }
  891. }
  892. var bedCostTotal float64 = 0 //床位总费
  893. //var bedCostSelfTotal float64 = 0 //床位自费
  894. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  895. var operationCostTotal float64 = 0 //手术费
  896. //var operationCostSelfTotal float64 = 0 //手术费
  897. var operationCostPartSelfTotal float64 = 0 //手术费
  898. var otherCostTotal float64 = 0 //其他费用
  899. //var otherCostSelfTotal float64 = 0 //其他费用
  900. var otherCostPartSelfTotal float64 = 0 //其他费用
  901. var materialCostTotal float64 = 0 //材料费
  902. //var materialCostSelfTotal float64 = 0 //材料费
  903. var materialCostPartSelfTotal float64 = 0 //材料费
  904. var westernMedicineCostTotal float64 = 0 //西药费
  905. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  906. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  907. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  908. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  909. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  910. var checkCostTotal float64 = 0 //检查费
  911. //var checkCostSelfTotal float64 = 0 //检查费
  912. var checkCostPartSelfTotal float64 = 0 //检查费
  913. var laboratoryCostTotal float64 = 0 //化验费
  914. //var laboratoryCostSelfTotal float64 = 0 //化验费
  915. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  916. var treatCostTotal float64 = 0 //治疗费用
  917. //var treatCostSelfTotal float64 = 0 //治疗费用
  918. var treatCostPartSelfTotal float64 = 0 //治疗费用
  919. var zhenChaCostTotal float64 = 0 //其他费用
  920. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  921. decimal.DivisionPrecision = 2
  922. for _, item := range orderInfos {
  923. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  924. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  925. item.MedChrgitmType = "09"
  926. }
  927. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  928. if item.HisPrescriptionProject.Type == 2 {
  929. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  930. fmt.Println("CostClassify")
  931. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  932. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  933. case 0:
  934. item.MedChrgitmType = "0"
  935. break
  936. case 1:
  937. item.MedChrgitmType = "14"
  938. break
  939. case 2:
  940. item.MedChrgitmType = "05"
  941. break
  942. case 3:
  943. item.MedChrgitmType = "03"
  944. break
  945. case 4:
  946. item.MedChrgitmType = "03"
  947. break
  948. case 5:
  949. item.MedChrgitmType = "08"
  950. break
  951. case 6:
  952. item.MedChrgitmType = "14"
  953. break
  954. case 7:
  955. item.MedChrgitmType = "14"
  956. break
  957. case 8:
  958. item.MedChrgitmType = "03"
  959. break
  960. case 9:
  961. item.MedChrgitmType = "14"
  962. break
  963. case 10:
  964. item.MedChrgitmType = "14"
  965. break
  966. case 11:
  967. item.MedChrgitmType = "06"
  968. break
  969. case 12:
  970. item.MedChrgitmType = "12"
  971. break
  972. case 13:
  973. item.MedChrgitmType = "01"
  974. break
  975. case 14:
  976. item.MedChrgitmType = "04"
  977. break
  978. case 15:
  979. item.MedChrgitmType = "14"
  980. break
  981. }
  982. } else {
  983. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  984. case 1:
  985. item.MedChrgitmType = "14"
  986. break
  987. case 2:
  988. item.MedChrgitmType = "05"
  989. break
  990. case 3:
  991. item.MedChrgitmType = "04"
  992. break
  993. case 4:
  994. item.MedChrgitmType = "14"
  995. break
  996. case 5:
  997. item.MedChrgitmType = "08"
  998. break
  999. case 6:
  1000. item.MedChrgitmType = "14"
  1001. break
  1002. case 7:
  1003. item.MedChrgitmType = "14"
  1004. break
  1005. case 8:
  1006. item.MedChrgitmType = "03"
  1007. break
  1008. case 9:
  1009. item.MedChrgitmType = "14"
  1010. break
  1011. default:
  1012. item.MedChrgitmType = "14"
  1013. break
  1014. }
  1015. }
  1016. } else if item.HisPrescriptionProject.Type == 3 {
  1017. item.MedChrgitmType = "08"
  1018. }
  1019. }
  1020. }
  1021. if order.IsMedicineInsurance != 1 {
  1022. order.PsnCashPay = order.MedfeeSumamt
  1023. }
  1024. for _, item := range orderInfos {
  1025. if item.MedChrgitmType == "01" { //床位费
  1026. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1027. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1028. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1029. }
  1030. if item.MedChrgitmType == "02" { //诊察费
  1031. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1032. //zhenChaCostSelfTotal = zhenChaCostTotal
  1033. }
  1034. if item.MedChrgitmType == "03" { //检查费
  1035. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1036. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1037. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1038. }
  1039. if item.MedChrgitmType == "02" { //检查费
  1040. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1041. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1042. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1043. }
  1044. if item.MedChrgitmType == "04" { //化验费
  1045. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1046. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1047. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1048. }
  1049. if item.MedChrgitmType == "05" { //治疗费
  1050. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1051. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1052. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1053. }
  1054. if item.MedChrgitmType == "06" { //手术费
  1055. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1056. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1057. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1058. }
  1059. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1060. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1061. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1062. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1063. }
  1064. if item.MedChrgitmType == "09" { //西药费
  1065. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1066. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1067. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1068. }
  1069. if item.MedChrgitmType == "11" { //中成费
  1070. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1071. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1072. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1073. }
  1074. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1075. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1076. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1077. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1078. }
  1079. }
  1080. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1081. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1082. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1083. var dia_config []*models.HisXtDiagnoseConfig
  1084. var diagnosis_ids []string
  1085. if his.ID > 0 {
  1086. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1087. } else {
  1088. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1089. }
  1090. for _, item := range diagnosis_ids {
  1091. id, _ := strconv.ParseInt(item, 10, 64)
  1092. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1093. dia_config = append(dia_config, diagnosisConfig)
  1094. }
  1095. var rf []CustomFundPay
  1096. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1097. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1098. c.ServeSuccessJSON(map[string]interface{}{
  1099. "patient": patient,
  1100. "order_infos": orderInfos,
  1101. "diagnosis": name,
  1102. "bedCostTotal": bedCostTotal,
  1103. "bedCostSelfTotal": bedCostTotal,
  1104. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1105. "operationCostTotal": operationCostTotal,
  1106. "operationCostSelfTotal": operationCostTotal,
  1107. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1108. "otherCostTotal": otherCostTotal,
  1109. "otherCostSelfTotal": otherCostTotal,
  1110. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1111. "materialCostTotal": materialCostTotal,
  1112. "materialCostSelfTotal": materialCostTotal,
  1113. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1114. "westernMedicineCostTotal": westernMedicineCostTotal,
  1115. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1116. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1117. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1118. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1119. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1120. "checkCostTotal": checkCostTotal,
  1121. "checkCostSelfTotal": checkCostTotal,
  1122. "zhenChaCostTotal": zhenChaCostTotal,
  1123. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1124. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1125. "laboratoryCostTotal": laboratoryCostTotal,
  1126. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1127. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1128. "treatCostTotal": treatCostTotal,
  1129. "treatCostSelfTotal": treatCostTotal,
  1130. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1131. "charge_admin": charge_admin,
  1132. "printor_admin": printor_admin,
  1133. "org_name": org.OrgName,
  1134. "org_code": miConfig.Code,
  1135. "name": patient.Name,
  1136. "number": order.MdtrtId,
  1137. "date": order.SettleAccountsDate,
  1138. "info": order,
  1139. "new_order": order,
  1140. "his_hospital": his_hospital,
  1141. "his": his,
  1142. "funds": rf,
  1143. "dia_config": dia_config,
  1144. })
  1145. }
  1146. func (c *HisApiController) RefudDetail() {
  1147. order_id, _ := c.GetInt64("order_id")
  1148. order, _ := service.GetHisOrderByID(order_id)
  1149. adminUser := c.GetAdminUserInfo()
  1150. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1151. c.ServeSuccessJSON(map[string]interface{}{
  1152. "msg": "撤销成功",
  1153. })
  1154. }
  1155. func (c *HisApiController) Sscard() {
  1156. //r := CardInit()
  1157. //if r == 0 {
  1158. // GetBaseInfo()
  1159. //}
  1160. //c.ServeSuccessJSON(map[string]interface{}{
  1161. // "list": "11",
  1162. //})
  1163. }
  1164. func GetBaseInfo() error {
  1165. //handle := syscall.MustLoadDLL("SSCard.dll")
  1166. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1167. //
  1168. //str := make([]byte, 256)
  1169. //str1 := make([]byte, 256)
  1170. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1171. //if ferr != nil {
  1172. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1173. // return ferr
  1174. //}
  1175. //
  1176. //fmt.Println(string(str))
  1177. //
  1178. //fmt.Println(r)
  1179. return nil
  1180. }
  1181. func CardInit() int {
  1182. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1183. //add := DllTestDef.MustFindProc("Init")
  1184. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1185. //if err != nil {
  1186. // fmt.Println("SSCard的运算结果为:", ret)
  1187. //}
  1188. //result := int(ret)
  1189. return 0
  1190. }
  1191. func IntPtr(n int) uintptr {
  1192. return uintptr(n)
  1193. }
  1194. func StrPtr(s string) uintptr {
  1195. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1196. }
  1197. func (c *HisApiController) GetHisPatientList() {
  1198. //types, _ := c.GetInt64("type", 0)
  1199. record_date := c.GetString("record_date")
  1200. sch_type, _ := c.GetInt64("sch_type")
  1201. timeLayout := "2006-01-02"
  1202. loc, _ := time.LoadLocation("Local")
  1203. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1204. if err != nil {
  1205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1206. return
  1207. }
  1208. recordDateTime := theTime.Unix()
  1209. adminInfo := c.GetAdminUserInfo()
  1210. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1211. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1212. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1213. //patient_three, _ := service.GetNewHisPatientListTwo(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1214. //patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1215. //获取当前用户的信息
  1216. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1217. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1218. //获取所有科室信息
  1219. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1220. //var aa []service.PatientThree
  1221. noElementsSlice := make([]service.PatientThree, 0)
  1222. c.ServeSuccessJSON(map[string]interface{}{
  1223. "list": patients,
  1224. "list_two": patients_two,
  1225. "list_three": noElementsSlice,
  1226. "info": adminUserInfo,
  1227. "doctors": doctors,
  1228. "department": department,
  1229. })
  1230. }
  1231. type CustomTemplate struct {
  1232. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1233. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1234. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1235. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1236. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1237. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1238. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1239. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1240. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1241. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1242. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1243. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1244. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1245. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1246. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1247. }
  1248. func (c *HisApiController) GetHisPatientInfo() {
  1249. patient_id, _ := c.GetInt64("patient_id")
  1250. his_patient_id, _ := c.GetInt64("his_patient_id")
  1251. record_date := c.GetString("record_date")
  1252. number := c.GetString("number")
  1253. //start_time := c.GetString("start_time")
  1254. //end_time := c.GetString("end_time")
  1255. p_type, _ := c.GetInt64("p_type")
  1256. timeLayout := "2006-01-02"
  1257. loc, _ := time.LoadLocation("Local")
  1258. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1259. if err != nil {
  1260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1261. return
  1262. }
  1263. recordDateTime := theTime.Unix()
  1264. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1265. //if err != nil {
  1266. //
  1267. //}
  1268. //startRecordDateTime := startTime.Unix()
  1269. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1270. //if err != nil {
  1271. //
  1272. //}
  1273. //endRecordDateTime := endTime.Unix()
  1274. admin := c.GetAdminUserInfo()
  1275. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1276. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1277. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1278. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1279. var prescriptions []*models.HisPrescription
  1280. var last_prescriptions []*models.HisPrescription
  1281. var sch_prescriptions []CustomTemplate
  1282. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1283. if p_type == 1 { //住院
  1284. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1285. for _, item := range prescriptions {
  1286. for _, subItem := range item.HisDoctorAdviceInfo {
  1287. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1288. if info.RetailPrice > 0 {
  1289. subItem.Drug.MinPrice = info.RetailPrice
  1290. }
  1291. }
  1292. }
  1293. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1294. } else { //门诊
  1295. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1296. for _, item := range prescriptions {
  1297. for _, subItem := range item.HisDoctorAdviceInfo {
  1298. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1299. if info.RetailPrice > 0 {
  1300. subItem.Drug.MinPrice = info.RetailPrice
  1301. }
  1302. }
  1303. }
  1304. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1305. }
  1306. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1307. if sch.ID > 0 {
  1308. var week string
  1309. t := time.Now()
  1310. switch t.Weekday().String() {
  1311. case "Monday":
  1312. week = "周一"
  1313. break
  1314. case "Tuesday":
  1315. week = "周二"
  1316. break
  1317. case "Wednesday":
  1318. week = "周三"
  1319. break
  1320. case "Thursday":
  1321. week = "周四"
  1322. break
  1323. case "Friday":
  1324. week = "周五"
  1325. break
  1326. case "Saturday":
  1327. week = "周六"
  1328. break
  1329. case "Sunday":
  1330. week = "周日"
  1331. break
  1332. }
  1333. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1334. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1335. //根据推送频率组装新的数组
  1336. for _, item := range temp_sch_prescriptions {
  1337. var cus CustomTemplate
  1338. cus.ID = item.ID
  1339. cus.UserOrgId = item.UserOrgId
  1340. cus.PatientId = item.PatientId
  1341. cus.MedType = item.MedType
  1342. cus.RecordDate = item.RecordDate
  1343. cus.Type = item.Type
  1344. cus.PType = item.PType
  1345. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1346. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1347. if subItem.FrequencyType == 1 { //每次必推
  1348. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1349. }
  1350. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1351. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1352. }
  1353. if subItem.FrequencyType == 2 { //按照天数频率
  1354. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1355. now := p.Unix()
  1356. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1357. dayStr2 := "-" + dayStr
  1358. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1359. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1360. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1361. if len(advices) == 0 {
  1362. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1363. }
  1364. }
  1365. }
  1366. }
  1367. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1368. if subItem.Type == 2 {
  1369. if subItem.XtHisProject.MedicalStatus != 1 {
  1370. if subItem.FrequencyType == 1 {
  1371. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1372. }
  1373. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1374. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1375. }
  1376. if subItem.FrequencyType == 2 {
  1377. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1378. now := p.Unix()
  1379. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1380. dayStr2 := "-" + dayStr
  1381. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1382. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1383. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1384. if len(projects) == 0 {
  1385. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1386. }
  1387. }
  1388. }
  1389. } else if subItem.Type == 3 {
  1390. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1391. if subItem.FrequencyType == 1 {
  1392. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1393. }
  1394. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1395. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1396. }
  1397. if subItem.FrequencyType == 2 {
  1398. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1399. now := p.Unix()
  1400. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1401. dayStr2 := "-" + dayStr
  1402. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1403. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1404. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1405. if len(projects) == 0 {
  1406. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1407. }
  1408. }
  1409. }
  1410. }
  1411. }
  1412. sch_prescriptions = append(sch_prescriptions, cus)
  1413. }
  1414. for _, item := range sch_prescriptions {
  1415. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1416. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1417. }
  1418. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1419. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1420. }
  1421. }
  1422. }
  1423. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1424. if config.ID > 0 && config.IsOpen == 1 {
  1425. for _, item := range sch_prescriptions {
  1426. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1427. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1428. if info.RetailPrice > 0 {
  1429. subItem.Drug.MinPrice = info.RetailPrice
  1430. if admin.CurrentOrgId != 10598 {
  1431. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1432. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1433. }
  1434. }
  1435. }
  1436. }
  1437. }
  1438. if config.ID > 0 && config.IsOpen == 1 {
  1439. for _, item := range sch_prescriptions {
  1440. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1441. if subItem.Type == 3 {
  1442. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1443. if info.Price > 0 {
  1444. subItem.GoodInfo.PackingPrice = info.Price
  1445. if admin.CurrentOrgId != 10598 {
  1446. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1447. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1448. }
  1449. }
  1450. }
  1451. }
  1452. }
  1453. }
  1454. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1455. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1456. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1457. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1458. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1459. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1460. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1461. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1462. //获取所有科室信息
  1463. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1464. beforThrity, _ := service.GetAssessmentBeforThrity(admin.CurrentOrgId, patient_id, recordDateTime)
  1465. LastCaseHistory, _ := service.GetLastHisPatientCaseHistory(admin.CurrentOrgId, patient_id)
  1466. prescriptionInfo, _ := service.GetDialysisPresriptionById(admin.CurrentOrgId, patient_id, recordDateTime)
  1467. c.ServeSuccessJSON(map[string]interface{}{
  1468. "his_info": his_patient_info,
  1469. "xt_info": xt_patient_info,
  1470. "prescription": prescriptions,
  1471. "case_history": case_history,
  1472. "info": patientPrescriptionInfo,
  1473. //"month_prescriptions": monthPrescriptions,
  1474. "order": order,
  1475. "doctors": doctors,
  1476. "department": department,
  1477. "sch_prescriptions": sch_prescriptions,
  1478. "last_prescriptions": last_prescriptions,
  1479. "schedule": sch,
  1480. "count": count,
  1481. "drugStockConfig": drugStockConfig,
  1482. "last_info": lastPatientPrescriptionInfo,
  1483. "befor": beforThrity,
  1484. "LastCaseHistory": LastCaseHistory,
  1485. "prescriptionInfo": prescriptionInfo,
  1486. })
  1487. return
  1488. }
  1489. func (c *HisApiController) GetHisPrescriptionConfig() {
  1490. adminInfo := c.GetAdminUserInfo()
  1491. //获取医嘱模版
  1492. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1493. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1494. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1495. //获取所有基础药
  1496. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1497. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1498. if config.ID > 0 && config.IsOpen == 1 {
  1499. for _, item := range drugs {
  1500. var index = 0
  1501. for _, subItem := range item.OtherDrugWarehouseInfo {
  1502. if index == 0 {
  1503. index = index + 1
  1504. if subItem.RetailPrice > 0 {
  1505. item.MinPrice = subItem.RetailPrice
  1506. }
  1507. }
  1508. }
  1509. }
  1510. }
  1511. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1512. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1513. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1514. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1515. //获取所有科室信息
  1516. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1517. //获取诊断信息
  1518. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1519. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1520. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1521. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1522. //获取是否开启保存耗材出库的开关
  1523. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1524. c.ServeSuccessJSON(map[string]interface{}{
  1525. "drugs": drugs,
  1526. "advices_template": advices,
  1527. "drugways": drugways,
  1528. "efs": efs,
  1529. "doctors": doctors,
  1530. "department": department,
  1531. "sick": sick,
  1532. "additions": additions,
  1533. "diagnose": diagnose,
  1534. "manufacturers": manufacturers,
  1535. "goodOutOpen": goodOutOpen,
  1536. "patientDiagnose": patientDiagnose,
  1537. })
  1538. }
  1539. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1540. //获取所有基础药
  1541. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1542. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1543. if config.ID > 0 && config.IsOpen == 1 {
  1544. for _, item := range drugs {
  1545. var index = 0
  1546. for _, subItem := range item.OtherDrugWarehouseInfo {
  1547. if index == 0 {
  1548. index = index + 1
  1549. if subItem.RetailPrice > 0 {
  1550. item.MinPrice = subItem.RetailPrice
  1551. }
  1552. }
  1553. }
  1554. }
  1555. }
  1556. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1557. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1558. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1559. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1560. //获取所有科室信息
  1561. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1562. //获取诊断信息
  1563. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1564. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1565. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1566. //获取是否开启保存耗材出库的开关
  1567. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1568. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1569. c.ServeSuccessJSON(map[string]interface{}{
  1570. "drugs": drugs,
  1571. "advices_template": advices,
  1572. "drugways": drugways,
  1573. "efs": efs,
  1574. "doctors": doctors,
  1575. "department": department,
  1576. "sick": sick,
  1577. "additions": additions,
  1578. "diagnose": diagnose,
  1579. "manufacturers": manufacturers,
  1580. "goodOutOpen": goodOutOpen,
  1581. "patientDiagnose": patientDiagnose,
  1582. })
  1583. }
  1584. }
  1585. func (c *HisApiController) CreateHisPrescription() {
  1586. record_date := c.GetString("record_date")
  1587. patient_id, _ := c.GetInt64("patient_id")
  1588. reg_type, _ := c.GetInt64("reg_type")
  1589. diagnose := c.GetString("diagnose")
  1590. sick_type, _ := c.GetInt64("sick_type")
  1591. sick_history := c.GetString("sick_history")
  1592. doctor_id, _ := c.GetInt64("doctor", 0)
  1593. department, _ := c.GetInt64("department", 0)
  1594. his_patient_id, _ := c.GetInt64("his_patient_id")
  1595. p_type, _ := c.GetInt64("p_type")
  1596. patient_diagnose := c.GetString("patient_diagnose")
  1597. dataBody := make(map[string]interface{}, 0)
  1598. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1599. if err != nil {
  1600. utils.ErrorLog(err.Error())
  1601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1602. return
  1603. }
  1604. //edit, src := GetCompareData(dataBody)
  1605. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1606. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1607. //fmt.Println(drugResult)
  1608. //fmt.Println(goodResult)
  1609. timeLayout := "2006-01-02"
  1610. loc, _ := time.LoadLocation("Local")
  1611. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1612. if err != nil {
  1613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1614. return
  1615. }
  1616. adminInfo := c.GetAdminUserInfo()
  1617. recordDateTime := theTime.Unix()
  1618. //查询默认出库仓库库存
  1619. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1620. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1621. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1622. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1623. if len(lists) == 1 {
  1624. his_patient_id = lists[0].ID
  1625. }
  1626. }
  1627. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1628. //自动出库的开关开启
  1629. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1630. //自动出库
  1631. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1632. //耗材保存处方出库
  1633. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1634. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1635. //已发药和已收费限制逻辑
  1636. isMidicine := false
  1637. isCharge := false
  1638. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1639. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1640. if len(prescriptions) > 0 {
  1641. for _, item := range prescriptions {
  1642. items := item.(map[string]interface{})
  1643. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1644. utils.ErrorLog("id")
  1645. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1646. return
  1647. }
  1648. id := int64(items["id"].(float64))
  1649. if id > 0 {
  1650. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1651. if err != nil {
  1652. if new_prescription.OrderStatus == 4 {
  1653. isCharge = true
  1654. }
  1655. }
  1656. }
  1657. }
  1658. }
  1659. }
  1660. if isMidicine == true {
  1661. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1662. return
  1663. }
  1664. if isCharge == true {
  1665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1666. return
  1667. }
  1668. // 开始主事务
  1669. db := service.XTWriteDB()
  1670. tx := db.Begin()
  1671. // 在函数结束时处理事务回滚
  1672. defer func() {
  1673. if r := recover(); r != nil {
  1674. tx.Rollback()
  1675. }
  1676. }()
  1677. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1678. //药品发药出库
  1679. if pharmacyConfig.IsOpen == 1 {
  1680. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1681. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1682. if len(prescriptions) > 0 {
  1683. for _, item := range prescriptions {
  1684. items := item.(map[string]interface{})
  1685. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1686. advices := items["advices"].([]interface{})
  1687. if len(advices) > 0 {
  1688. for _, advice := range advices {
  1689. var drug_id int64
  1690. var prescribing_number float64
  1691. var prescribingNumberUnit string
  1692. var adviceId int64
  1693. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1694. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1695. }
  1696. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1697. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1698. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1699. }
  1700. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1701. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1702. }
  1703. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1704. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1705. }
  1706. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1707. if drug.ID == 0 {
  1708. tx.Rollback()
  1709. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1710. return
  1711. }
  1712. //查询药品的所有库存
  1713. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1714. var total_count int64
  1715. for _, it := range list {
  1716. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1717. }
  1718. totals := strconv.FormatInt(total_count, 10)
  1719. //查询该药品是否存在开药记录
  1720. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1721. //新增处方盘点库存是否充足
  1722. if advicelist.ID == 0 {
  1723. all_count, _ := strconv.ParseFloat(totals, 64)
  1724. if prescribingNumberUnit == drug.MinUnit {
  1725. if drug.IsUse != 1 {
  1726. if drug.IsProject == 0 || drug.IsProject == 2 {
  1727. if all_count == 0 {
  1728. tx.Rollback()
  1729. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1730. return
  1731. }
  1732. if prescribing_number > all_count {
  1733. tx.Rollback()
  1734. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1735. return
  1736. }
  1737. }
  1738. }
  1739. }
  1740. if prescribingNumberUnit == drug.MaxUnit {
  1741. num := prescribing_number * float64(drug.MinNumber)
  1742. if drug.IsUse != 1 {
  1743. if drug.IsProject == 0 || drug.IsProject == 2 {
  1744. if all_count == 0 {
  1745. tx.Rollback()
  1746. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1747. return
  1748. }
  1749. if num > all_count {
  1750. tx.Rollback()
  1751. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1752. return
  1753. }
  1754. }
  1755. }
  1756. }
  1757. }
  1758. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1759. //不使用保存处方出库
  1760. if drugOutConfig.IsOpen != 1 {
  1761. //修改处方
  1762. for _, advice := range advices {
  1763. var drug_id int64
  1764. var prescribing_number float64
  1765. var prescribingNumberUnit string
  1766. var prescribingNumber string
  1767. var adviceId int64
  1768. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1769. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1770. }
  1771. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1772. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1773. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1774. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1775. }
  1776. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1777. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1778. }
  1779. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1780. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1781. }
  1782. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1783. if drug.ID == 0 {
  1784. tx.Rollback()
  1785. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1786. return
  1787. }
  1788. //查询药品的所有库存
  1789. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1790. var total_count int64
  1791. for _, it := range list {
  1792. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1793. }
  1794. totals := strconv.FormatInt(total_count, 10)
  1795. //查询该药品是否存在开药记录
  1796. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1797. //新增处方
  1798. if advicelist.ID == 0 {
  1799. all_count, _ := strconv.ParseFloat(totals, 64)
  1800. if prescribingNumberUnit == drug.MinUnit {
  1801. if drug.IsUse != 1 {
  1802. if drug.IsProject == 0 || drug.IsProject == 2 {
  1803. if all_count == 0 {
  1804. tx.Rollback()
  1805. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1806. return
  1807. }
  1808. if prescribing_number > all_count {
  1809. tx.Rollback()
  1810. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1811. return
  1812. }
  1813. }
  1814. }
  1815. } else {
  1816. if prescribingNumberUnit == drug.MaxUnit {
  1817. num := prescribing_number * float64(drug.MinNumber)
  1818. if drug.IsUse != 1 {
  1819. if drug.IsProject == 0 || drug.IsProject == 2 {
  1820. if all_count == 0 {
  1821. tx.Rollback()
  1822. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1823. return
  1824. }
  1825. if num > all_count {
  1826. tx.Rollback()
  1827. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1828. return
  1829. }
  1830. }
  1831. }
  1832. }
  1833. }
  1834. }
  1835. //修改处方
  1836. if advicelist.ID > 0 {
  1837. var device_number int64
  1838. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1839. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1840. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1841. device_number = prescribingNumberInt * drug.MinNumber
  1842. }
  1843. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1844. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1845. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1846. device_number = prescribingNumberInt
  1847. }
  1848. var number_count int64
  1849. if prescribingNumberUnit == drug.MaxUnit {
  1850. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1851. number_count = prescribingNumberInt * drug.MinNumber
  1852. }
  1853. if prescribingNumberUnit == drug.MinUnit {
  1854. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1855. number_count = prescribingNumberInt
  1856. }
  1857. //如果修改的数量大于之前修改的数量
  1858. if (number_count - device_number) > 0 {
  1859. //如果修改的差数量 大于库存数量
  1860. if drug.IsUse != 1 {
  1861. if (number_count - device_number) > total_count {
  1862. tx.Rollback()
  1863. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1864. return
  1865. }
  1866. }
  1867. }
  1868. }
  1869. }
  1870. }
  1871. }
  1872. }
  1873. }
  1874. }
  1875. }
  1876. }
  1877. }
  1878. //已发药和已收费限制逻辑
  1879. //执行出库的逻辑
  1880. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1881. //校验库存总量
  1882. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1883. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1884. if len(prescriptions) > 0 {
  1885. for _, item := range prescriptions {
  1886. items := item.(map[string]interface{})
  1887. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1888. advices := items["advices"].([]interface{})
  1889. if len(advices) > 0 {
  1890. for _, advice := range advices {
  1891. var drug_id int64
  1892. var prescribing_number float64
  1893. var prescribingNumberUnit string
  1894. var adviceId int64
  1895. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1896. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1897. }
  1898. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1899. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1900. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1901. }
  1902. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1903. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1904. }
  1905. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1906. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1907. }
  1908. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1909. if drug.ID == 0 {
  1910. tx.Rollback()
  1911. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1912. return
  1913. }
  1914. //查询药品的所有库存
  1915. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1916. var total_count int64
  1917. for _, it := range list {
  1918. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1919. }
  1920. totals := strconv.FormatInt(total_count, 10)
  1921. //查询该药品是否存在开药记录
  1922. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1923. //查询最新批次库存
  1924. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1925. var batch_number_count int64
  1926. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1927. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1928. //新增处方
  1929. if advicelist.ID == 0 {
  1930. all_count, _ := strconv.ParseFloat(totals, 64)
  1931. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1932. if prescribingNumberUnit == drug.MinUnit {
  1933. if drug.IsUse != 1 {
  1934. if drug.IsProject == 0 || drug.IsProject == 2 {
  1935. if all_count == 0 {
  1936. tx.Rollback()
  1937. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1938. return
  1939. }
  1940. if prescribing_number > all_count {
  1941. tx.Rollback()
  1942. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1943. return
  1944. }
  1945. }
  1946. if adminInfo.CurrentOrgId == 10215 {
  1947. if prescribing_number > batch_number_all_count {
  1948. tx.Rollback()
  1949. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1950. return
  1951. }
  1952. }
  1953. }
  1954. }
  1955. if prescribingNumberUnit == drug.MaxUnit {
  1956. num := prescribing_number * float64(drug.MinNumber)
  1957. if drug.IsUse != 1 {
  1958. if drug.IsProject == 0 || drug.IsProject == 2 {
  1959. if all_count == 0 {
  1960. tx.Rollback()
  1961. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1962. return
  1963. }
  1964. if num > all_count {
  1965. tx.Rollback()
  1966. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1967. return
  1968. }
  1969. }
  1970. if adminInfo.CurrentOrgId == 10215 {
  1971. if num > batch_number_all_count {
  1972. tx.Rollback()
  1973. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1974. return
  1975. }
  1976. }
  1977. }
  1978. }
  1979. }
  1980. //不是保存处方出库
  1981. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1982. if drugOutConfig.IsOpen != 1 {
  1983. //修改处方
  1984. for _, advice := range advices {
  1985. var drug_id int64
  1986. var prescribing_number float64
  1987. var prescribingNumberUnit string
  1988. var prescribingNumber string
  1989. var adviceId int64
  1990. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1991. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1992. }
  1993. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1994. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1995. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1996. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1997. }
  1998. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1999. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2000. }
  2001. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2002. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2003. }
  2004. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2005. if drug.ID == 0 {
  2006. tx.Rollback()
  2007. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2008. return
  2009. }
  2010. //查询药品的所有库存
  2011. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2012. var total_count int64
  2013. for _, it := range list {
  2014. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2015. }
  2016. totals := strconv.FormatInt(total_count, 10)
  2017. //查询该药品是否存在开药记录
  2018. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2019. //新增处方
  2020. if advicelist.ID == 0 {
  2021. //查询最新批次库存
  2022. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2023. var batch_number_count int64
  2024. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2025. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2026. all_count, _ := strconv.ParseFloat(totals, 64)
  2027. if all_count == 0 {
  2028. tx.Rollback()
  2029. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2030. return
  2031. }
  2032. if prescribingNumberUnit == drug.MinUnit {
  2033. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2034. if drug.IsUse != 1 {
  2035. if drug.IsProject == 0 || drug.IsProject == 2 {
  2036. if all_count == 0 {
  2037. tx.Rollback()
  2038. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2039. return
  2040. }
  2041. if prescribing_number > all_count {
  2042. tx.Rollback()
  2043. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2044. return
  2045. }
  2046. }
  2047. if adminInfo.CurrentOrgId == 10215 {
  2048. if prescribing_number > batch_number_all_count {
  2049. tx.Rollback()
  2050. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2051. return
  2052. }
  2053. }
  2054. }
  2055. } else {
  2056. if prescribingNumberUnit == drug.MaxUnit {
  2057. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2058. num := prescribing_number * float64(drug.MinNumber)
  2059. if drug.IsUse != 1 {
  2060. if drug.IsProject == 0 || drug.IsProject == 2 {
  2061. if all_count == 0 {
  2062. tx.Rollback()
  2063. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2064. return
  2065. }
  2066. if num > all_count {
  2067. tx.Rollback()
  2068. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2069. return
  2070. }
  2071. }
  2072. if adminInfo.CurrentOrgId == 10215 {
  2073. if prescribing_number > batch_number_all_count {
  2074. tx.Rollback()
  2075. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2076. return
  2077. }
  2078. }
  2079. }
  2080. }
  2081. }
  2082. }
  2083. //修改处方
  2084. if advicelist.ID > 0 {
  2085. //查询最新批次库存
  2086. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2087. var batch_number_count int64
  2088. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2089. var device_number int64
  2090. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2091. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2092. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2093. device_number = prescribingNumberInt * drug.MinNumber
  2094. }
  2095. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2096. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2097. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2098. device_number = prescribingNumberInt
  2099. //回退库存
  2100. }
  2101. var number_count int64
  2102. if prescribingNumberUnit == drug.MaxUnit {
  2103. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2104. number_count = prescribingNumberInt * drug.MinNumber
  2105. //回退库存
  2106. }
  2107. if prescribingNumberUnit == drug.MinUnit {
  2108. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2109. number_count = prescribingNumberInt
  2110. //回退库存
  2111. }
  2112. //如果修改的数量大于之前修改的数量
  2113. if (number_count - device_number) > 0 {
  2114. //如果修改的差数量 大于库存数量
  2115. if drug.IsUse != 1 {
  2116. if drug.IsProject == 0 || drug.IsProject == 2 {
  2117. if total_count == 0 {
  2118. tx.Rollback()
  2119. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2120. return
  2121. }
  2122. if (number_count - device_number) > total_count {
  2123. tx.Rollback()
  2124. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2125. return
  2126. }
  2127. if (number_count - device_number) > batch_number_count {
  2128. tx.Rollback()
  2129. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2130. return
  2131. }
  2132. }
  2133. if adminInfo.CurrentOrgId == 10215 {
  2134. // 查询该药品最后一次出库记录
  2135. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2136. var out_count int64
  2137. var in_count int64
  2138. var stock_max_number int64
  2139. var stock_min_number int64
  2140. for _, it := range outInfo {
  2141. if it.CountUnit == drug.MaxUnit {
  2142. it.Count = it.Count * drug.MinNumber
  2143. }
  2144. out_count += it.Count
  2145. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2146. stock_max_number = warehouseInfoList.StockMaxNumber
  2147. stock_min_number = warehouseInfoList.StockMinNumber
  2148. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2149. }
  2150. if out_count > 0 {
  2151. if (number_count - device_number) > in_count {
  2152. tx.Rollback()
  2153. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2154. return
  2155. }
  2156. }
  2157. // 未出库
  2158. if out_count == 0 {
  2159. var sum_in_count int64
  2160. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2161. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2162. //如果修改的数量大于有库存的第一个批次
  2163. if number_count > sum_in_count {
  2164. tx.Rollback()
  2165. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2166. return
  2167. }
  2168. }
  2169. }
  2170. }
  2171. }
  2172. //药品发药
  2173. //pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2174. //不使用药品发药的功能
  2175. //if pharmacyConfig.IsOpen != 1 {
  2176. // if device_number != number_count {
  2177. //
  2178. // //查询该药品的出库记录
  2179. // outListExport, _ := service.GetWarehouseOutListExport(drug_id, patient_id, recordDateTime, adviceId)
  2180. // if len(outListExport) > 0 {
  2181. // //
  2182. // for _, item := range outListExport {
  2183. // //回退库存
  2184. // if item.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2185. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, number_count)
  2186. // }
  2187. // if item.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2188. // var stock_max_number int64
  2189. // var stock_min_number int64
  2190. //
  2191. // if number_count >= drug.MinNumber {
  2192. //
  2193. // stock_max_number = device_number / drug.MinNumber
  2194. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, stock_max_number)
  2195. //
  2196. // stock_min_number = device_number % drug.MinNumber
  2197. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, stock_min_number)
  2198. //
  2199. // } else {
  2200. //
  2201. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, device_number)
  2202. //
  2203. // }
  2204. // }
  2205. //
  2206. // if item.CountUnit == drug.MaxUnit && item.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2207. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, device_number)
  2208. // }
  2209. // }
  2210. // }
  2211. //
  2212. // service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2213. // var sum_count int64
  2214. // orgId := c.GetAdminUserInfo().CurrentOrgId
  2215. // stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgId, drug_id)
  2216. // for _, its := range stockInfo {
  2217. // if its.MaxUnit == drug.MaxUnit {
  2218. // its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2219. // }
  2220. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2221. // }
  2222. // //更新字典里面的库存
  2223. // service.UpdateBaseDrugSumTwo(drug_id, sum_count, orgId)
  2224. //
  2225. // //剩余库存
  2226. // service.UpdateDrugStockCount(drug_id, orgId, storeConfig.DrugStorehouseOut, sum_count)
  2227. //
  2228. // over, _ := service.FindOverCount(drug_id, orgId, storeConfig.DrugStorehouseOut)
  2229. // //减少出库数量
  2230. // service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2231. //
  2232. // }
  2233. //}
  2234. }
  2235. }
  2236. }
  2237. //保存处方开药
  2238. if drugOutConfig.IsOpen == 1 {
  2239. //修改处方
  2240. for _, advice := range advices {
  2241. var drug_id int64
  2242. var prescribing_number float64
  2243. var prescribingNumberUnit string
  2244. var prescribingNumber string
  2245. var adviceId int64
  2246. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2247. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2248. }
  2249. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2250. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2251. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2252. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2253. }
  2254. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2255. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2256. }
  2257. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2258. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2259. }
  2260. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2261. if drug.ID == 0 {
  2262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2263. return
  2264. }
  2265. //查询药品的所有库存
  2266. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2267. var total_count int64
  2268. for _, it := range list {
  2269. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2270. }
  2271. totals := strconv.FormatInt(total_count, 10)
  2272. //查询该药品是否存在开药记录
  2273. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2274. //新增处方
  2275. if advicelist.ID == 0 {
  2276. //查询最新批次库存
  2277. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2278. var batch_number_count int64
  2279. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2280. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2281. all_count, _ := strconv.ParseFloat(totals, 64)
  2282. if prescribingNumberUnit == drug.MinUnit {
  2283. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2284. if drug.IsUse != 1 {
  2285. if drug.IsProject == 0 || drug.IsProject == 2 {
  2286. if all_count == 0 {
  2287. tx.Rollback()
  2288. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2289. return
  2290. }
  2291. if prescribing_number > all_count {
  2292. tx.Rollback()
  2293. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2294. return
  2295. }
  2296. }
  2297. if adminInfo.CurrentOrgId == 10215 {
  2298. if prescribing_number > batch_number_all_count {
  2299. tx.Rollback()
  2300. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2301. return
  2302. }
  2303. }
  2304. }
  2305. } else {
  2306. if prescribingNumberUnit == drug.MaxUnit {
  2307. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2308. num := prescribing_number * float64(drug.MinNumber)
  2309. if drug.IsUse != 1 {
  2310. if drug.IsProject == 0 || drug.IsProject == 2 {
  2311. if all_count == 0 {
  2312. tx.Rollback()
  2313. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2314. return
  2315. }
  2316. if num > all_count {
  2317. tx.Rollback()
  2318. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2319. return
  2320. }
  2321. }
  2322. if adminInfo.CurrentOrgId == 10215 {
  2323. if prescribing_number > batch_number_all_count {
  2324. tx.Rollback()
  2325. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2326. return
  2327. }
  2328. }
  2329. }
  2330. }
  2331. }
  2332. }
  2333. //修改处方
  2334. if advicelist.ID > 0 {
  2335. //查询最新批次库存
  2336. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2337. var batch_number_count int64
  2338. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2339. var device_number int64
  2340. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2341. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2342. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2343. device_number = prescribingNumberInt * drug.MinNumber
  2344. }
  2345. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2346. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2347. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2348. device_number = prescribingNumberInt
  2349. }
  2350. var number_count int64
  2351. if prescribingNumberUnit == drug.MaxUnit {
  2352. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2353. number_count = prescribingNumberInt * drug.MinNumber
  2354. }
  2355. if prescribingNumberUnit == drug.MinUnit {
  2356. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2357. number_count = prescribingNumberInt
  2358. }
  2359. //如果修改的数量大于之前修改的数量
  2360. if (number_count - device_number) > 0 {
  2361. //如果修改的差数量 大于库存数量
  2362. if drug.IsUse != 1 {
  2363. if drug.IsProject == 0 || drug.IsProject == 2 {
  2364. if total_count == 0 {
  2365. tx.Rollback()
  2366. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2367. return
  2368. }
  2369. if (number_count - device_number) > total_count {
  2370. tx.Rollback()
  2371. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2372. return
  2373. }
  2374. }
  2375. if adminInfo.CurrentOrgId == 10215 {
  2376. if (number_count - device_number) > batch_number_count {
  2377. tx.Rollback()
  2378. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2379. return
  2380. }
  2381. }
  2382. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2383. //查询历史出库数据总批次
  2384. // 查询该药品最后一次出库记录
  2385. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2386. var out_count int64
  2387. var in_count int64
  2388. var stock_max_number int64
  2389. var stock_min_number int64
  2390. for _, it := range outInfo {
  2391. if it.CountUnit == drug.MaxUnit {
  2392. it.Count = it.Count * drug.MinNumber
  2393. }
  2394. out_count += it.Count
  2395. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2396. stock_max_number = warehouseInfoList.StockMaxNumber
  2397. stock_min_number = warehouseInfoList.StockMinNumber
  2398. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2399. }
  2400. if out_count > 0 {
  2401. if (number_count - device_number) > in_count {
  2402. tx.Rollback()
  2403. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2404. return
  2405. }
  2406. }
  2407. // 未出库
  2408. if out_count == 0 {
  2409. var sum_in_count int64
  2410. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2411. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2412. if sum_in_count == 0 {
  2413. tx.Rollback()
  2414. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2415. return
  2416. }
  2417. //如果修改的数量大于有库存的第一个批次
  2418. if number_count > sum_in_count {
  2419. tx.Rollback()
  2420. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2421. return
  2422. }
  2423. }
  2424. }
  2425. }
  2426. }
  2427. }
  2428. }
  2429. }
  2430. }
  2431. }
  2432. }
  2433. }
  2434. }
  2435. }
  2436. }
  2437. //校验耗材库存
  2438. if goodOutConfig.IsOpen == 1 {
  2439. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2440. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2441. if len(prescriptions) > 0 {
  2442. for _, item := range prescriptions {
  2443. items := item.(map[string]interface{})
  2444. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2445. projects := items["project"].([]interface{})
  2446. if len(projects) > 0 {
  2447. for _, project := range projects {
  2448. var project_id int64
  2449. var project_type int64
  2450. var totals float64
  2451. var project_name string
  2452. var parsetotal int64
  2453. var id int64
  2454. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2455. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2456. }
  2457. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2458. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2459. }
  2460. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2461. total, _ := project.(map[string]interface{})["total"].(string)
  2462. totals, _ = strconv.ParseFloat(total, 64)
  2463. }
  2464. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2465. project_name = project.(map[string]interface{})["project_name"].(string)
  2466. }
  2467. if project_type == 3 {
  2468. //查找该耗材的出库记录
  2469. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2470. if len(goodWarehouseInfo) == 0 {
  2471. //查询耗材库存
  2472. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2473. var stock_count int64
  2474. for _, it := range list {
  2475. stock_count += it.StockCount
  2476. }
  2477. stock_counts := strconv.FormatInt(stock_count, 10)
  2478. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2479. if stock_total_count == 0 {
  2480. tx.Rollback()
  2481. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2482. return
  2483. }
  2484. if totals > stock_total_count {
  2485. tx.Rollback()
  2486. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2487. return
  2488. }
  2489. }
  2490. if len(goodWarehouseInfo) > 0 {
  2491. //查询该患者耗材的历史数据
  2492. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2493. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2494. //数量发生改变
  2495. if parsetotal != count {
  2496. //如果现在的数量大于历史数量,就要看库存是否足够
  2497. if parsetotal > count {
  2498. //查询耗材所有库存
  2499. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2500. var stock_count int64
  2501. for _, it := range list {
  2502. stock_count += it.StockCount
  2503. }
  2504. //库存不足
  2505. if stock_count == 0 {
  2506. tx.Rollback()
  2507. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2508. return
  2509. }
  2510. if (parsetotal - count) > stock_count {
  2511. tx.Rollback()
  2512. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2513. return
  2514. }
  2515. }
  2516. }
  2517. }
  2518. }
  2519. }
  2520. }
  2521. }
  2522. }
  2523. }
  2524. }
  2525. }
  2526. //不使用耗材保存处方出库
  2527. if goodOutConfig.IsOpen != 1 {
  2528. if stockConfig.IsOpen == 1 {
  2529. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2530. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2531. if len(prescriptions) > 0 {
  2532. for _, item := range prescriptions {
  2533. items := item.(map[string]interface{})
  2534. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2535. projects := items["project"].([]interface{})
  2536. if len(projects) > 0 {
  2537. for _, project := range projects {
  2538. var project_id int64
  2539. var project_type int64
  2540. var totals float64
  2541. var project_name string
  2542. var parsetotal int64
  2543. var id int64
  2544. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2545. id = int64(project.(map[string]interface{})["id"].(float64))
  2546. }
  2547. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2548. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2549. }
  2550. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2551. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2552. }
  2553. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2554. total, _ := project.(map[string]interface{})["total"].(string)
  2555. totals, _ = strconv.ParseFloat(total, 64)
  2556. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2557. }
  2558. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2559. project_name = project.(map[string]interface{})["project_name"].(string)
  2560. }
  2561. if project_type == 3 {
  2562. //查找该耗材的出库记录
  2563. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2564. //没有出库记录
  2565. if len(goodWarehouseInfo) == 0 {
  2566. //查询耗材库存
  2567. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2568. var stock_count int64
  2569. for _, it := range list {
  2570. stock_count += it.StockCount
  2571. }
  2572. stock_counts := strconv.FormatInt(stock_count, 10)
  2573. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2574. if stock_total_count == 0 {
  2575. tx.Rollback()
  2576. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2577. return
  2578. }
  2579. if totals > stock_total_count {
  2580. tx.Rollback()
  2581. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2582. return
  2583. }
  2584. //查找今日该患者已经出库的所有耗材
  2585. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2586. for _, item := range goodList {
  2587. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2588. var flush_count int64
  2589. for _, it := range goodListSix {
  2590. flush_count += it.StockCount
  2591. }
  2592. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2593. creater := adminInfo.AdminUser.Id
  2594. if errs != nil {
  2595. goodErrcode := models.XtGoodErrcode{
  2596. UserOrgId: item.OrgId,
  2597. Errcode: "手动出库更新剩余出库失败",
  2598. GoodId: item.GoodId,
  2599. Status: 1,
  2600. Ctime: time.Now().Unix(),
  2601. Mtime: 0,
  2602. Count: 0,
  2603. StockCount: 0,
  2604. Creater: creater,
  2605. BatchNumberId: 0,
  2606. WarehouseOutId: 0,
  2607. }
  2608. service.CreateGoodErrcode(goodErrcode)
  2609. }
  2610. }
  2611. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2612. }
  2613. //有出库记录
  2614. if len(goodWarehouseInfo) > 0 {
  2615. //查询该患者耗材的历史数据
  2616. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2617. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2618. //数量发生改变
  2619. if parsetotal != count {
  2620. //查找今日该患者已经出库的所有耗材
  2621. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2622. for _, item := range goodList {
  2623. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2624. var flush_count int64
  2625. for _, it := range goodListSix {
  2626. flush_count += it.StockCount
  2627. }
  2628. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2629. //减少出库数量
  2630. creater := adminInfo.AdminUser.Id
  2631. if errs != nil {
  2632. goodErrcode := models.XtGoodErrcode{
  2633. UserOrgId: item.OrgId,
  2634. Errcode: "手动出库更新剩余出库失败",
  2635. GoodId: item.GoodId,
  2636. Status: 1,
  2637. Ctime: time.Now().Unix(),
  2638. Mtime: 0,
  2639. Count: 0,
  2640. StockCount: 0,
  2641. Creater: creater,
  2642. BatchNumberId: 0,
  2643. WarehouseOutId: 0,
  2644. }
  2645. service.CreateGoodErrcode(goodErrcode)
  2646. }
  2647. //查询默认仓库
  2648. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2649. var total_count int64
  2650. for _, it := range stockList {
  2651. total_count += it.StockCount
  2652. }
  2653. //基础库插入数据
  2654. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2655. }
  2656. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2657. }
  2658. }
  2659. }
  2660. }
  2661. }
  2662. }
  2663. }
  2664. }
  2665. }
  2666. }
  2667. }
  2668. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2669. var hpInfo models.HisPrescriptionInfo
  2670. if info.ID == 0 {
  2671. var randNum int
  2672. randNum = rand.Intn(10000) + 1000
  2673. timestamp := time.Now().Unix()
  2674. tempTime := time.Unix(timestamp, 0)
  2675. timeFormat := tempTime.Format("20060102150405")
  2676. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2677. hpInfo = models.HisPrescriptionInfo{
  2678. HisPatientId: his_patient_id,
  2679. UserOrgId: adminInfo.CurrentOrgId,
  2680. RecordDate: theTime.Unix(),
  2681. PatientId: patient_id,
  2682. Status: 1,
  2683. Ctime: time.Now().Unix(),
  2684. Mtime: time.Now().Unix(),
  2685. Creator: adminInfo.AdminUser.Id,
  2686. Modifier: adminInfo.AdminUser.Id,
  2687. Diagnosis: diagnose,
  2688. SickHistory: sick_history,
  2689. Departments: department,
  2690. RegisterType: reg_type,
  2691. PrescriptionNumber: p_number,
  2692. PrescriptionStatus: 1,
  2693. Doctor: role.UserName,
  2694. DoctorId: doctor_id,
  2695. SickType: sick_type,
  2696. PType: p_type,
  2697. PatientDiagnosis: patient_diagnose,
  2698. }
  2699. service.SavePatientPrescriptionInfo(hpInfo)
  2700. //创建步骤表
  2701. finish := models.XtDialysisFinish{
  2702. IsFinish: 1,
  2703. UserOrgId: adminInfo.CurrentOrgId,
  2704. Status: 1,
  2705. Ctime: time.Now().Unix(),
  2706. Mtime: 0,
  2707. Module: 4,
  2708. RecordDate: theTime.Unix(),
  2709. Sourse: 1,
  2710. PatientId: patient_id,
  2711. }
  2712. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2713. if dialysisFinish.ID == 0 {
  2714. service.CreateDialysisFinish(finish)
  2715. }
  2716. redis := service.RedisClient()
  2717. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2718. redis.Set(key, "", time.Second)
  2719. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2720. redis.Set(keyOne, "", time.Second)
  2721. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2722. redis.Set(keySeven, "", time.Second)
  2723. defer redis.Close()
  2724. } else {
  2725. hpInfo = models.HisPrescriptionInfo{
  2726. ID: info.ID,
  2727. UserOrgId: adminInfo.CurrentOrgId,
  2728. RecordDate: info.RecordDate,
  2729. PatientId: info.PatientId,
  2730. Status: 1,
  2731. Ctime: info.Ctime,
  2732. Mtime: time.Now().Unix(),
  2733. Creator: info.Creator,
  2734. Modifier: adminInfo.AdminUser.Id,
  2735. Diagnosis: diagnose,
  2736. SickHistory: sick_history,
  2737. Departments: department,
  2738. RegisterType: reg_type,
  2739. PrescriptionNumber: info.PrescriptionNumber,
  2740. Doctor: role.UserName,
  2741. PrescriptionStatus: info.PrescriptionStatus,
  2742. DoctorId: doctor_id,
  2743. SickType: sick_type,
  2744. PType: info.PType,
  2745. HisPatientId: info.HisPatientId,
  2746. PatientDiagnosis: patient_diagnose,
  2747. }
  2748. service.SavePatientPrescriptionInfo(hpInfo)
  2749. //创建步骤表
  2750. finish := models.XtDialysisFinish{
  2751. IsFinish: 1,
  2752. UserOrgId: adminInfo.CurrentOrgId,
  2753. Status: 1,
  2754. Ctime: time.Now().Unix(),
  2755. Mtime: 0,
  2756. Module: 4,
  2757. RecordDate: info.RecordDate,
  2758. Sourse: 1,
  2759. PatientId: info.PatientId,
  2760. }
  2761. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2762. if dialysisFinish.ID == 0 {
  2763. service.CreateDialysisFinish(finish)
  2764. }
  2765. redis := service.RedisClient()
  2766. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2767. redis.Set(key, "", time.Second)
  2768. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2769. redis.Set(keyOne, "", time.Second)
  2770. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2771. redis.Set(keySeven, "", time.Second)
  2772. defer redis.Close()
  2773. }
  2774. //定义切片
  2775. var adviceList []models.HisDoctorAdviceInfo
  2776. var projectList []models.HisPrescriptionProject
  2777. if adminInfo.CurrentOrgId == 10489 || adminInfo.CurrentOrgId == 10510 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 10478 || adminInfo.CurrentOrgId == 10318 || adminInfo.CurrentOrgId == 10480 || adminInfo.CurrentOrgId == 10633 || adminInfo.CurrentOrgId == 10610 || adminInfo.CurrentOrgId == 10402 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10537 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10644 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 10598 || adminInfo.CurrentOrgId == 10028 {
  2778. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2779. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2780. var tempPrescription *models.HisPrescription
  2781. if len(prescriptions) > 0 {
  2782. for _, item := range prescriptions {
  2783. // 开始外部循环的事务
  2784. tx := db.Begin()
  2785. // 在函数结束时处理事务回滚
  2786. defer func() {
  2787. if r := recover(); r != nil {
  2788. tx.Rollback()
  2789. }
  2790. }()
  2791. items := item.(map[string]interface{})
  2792. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2793. utils.ErrorLog("id")
  2794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2795. return
  2796. }
  2797. id := int64(items["id"].(float64))
  2798. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2799. tempPrescription = &new_prescription
  2800. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2801. utils.ErrorLog("type")
  2802. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2803. return
  2804. }
  2805. types := int64(items["type"].(float64))
  2806. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2807. utils.ErrorLog("med_type")
  2808. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2809. return
  2810. }
  2811. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2812. if med_type == "0" {
  2813. med_type = "14"
  2814. }
  2815. //if order_status == 0 {
  2816. // order_status = 1
  2817. //}
  2818. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2819. utils.ErrorLog("pre_time")
  2820. }
  2821. preTime, _ := items["pre_time"].(string)
  2822. fmt.Println("preTime", preTime)
  2823. timeLayout := "2006-01-02"
  2824. loc, _ := time.LoadLocation("Local")
  2825. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2826. //result := strings.Split(preTime, " ")
  2827. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  2828. if err != nil {
  2829. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2830. return
  2831. }
  2832. pTime := theTime2.Unix()
  2833. ctime := time.Now().Unix()
  2834. if tempPrescription.ID == 0 {
  2835. prescription := &models.HisPrescription{
  2836. ID: 0,
  2837. PatientId: patient_id,
  2838. UserOrgId: adminInfo.CurrentOrgId,
  2839. RecordDate: recordDateTime,
  2840. Ctime: ctime,
  2841. Mtime: ctime,
  2842. Type: types,
  2843. Modifier: adminInfo.AdminUser.Id,
  2844. Creator: adminInfo.AdminUser.Id,
  2845. Status: 1,
  2846. Doctor: role.UserName,
  2847. HisPatientId: his_patient_id,
  2848. OrderStatus: 1,
  2849. BatchNumber: "",
  2850. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2851. PreTime: pTime,
  2852. PType: p_type,
  2853. MedType: med_type,
  2854. }
  2855. tempPrescription = prescription
  2856. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2857. redis := service.RedisClient()
  2858. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2859. redis.Set(key, "", time.Second)
  2860. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2861. redis.Set(keyOne, "", time.Second)
  2862. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2863. redis.Set(keySeven, "", time.Second)
  2864. defer redis.Close()
  2865. } else {
  2866. tempPrescription.ID = id
  2867. tempPrescription.Type = types
  2868. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2869. tempPrescription.Mtime = time.Now().Unix()
  2870. tempPrescription.Doctor = role.UserName
  2871. //tempPrescription.OrderStatus = order_status
  2872. tempPrescription.PreTime = pTime
  2873. tempPrescription.MedType = med_type
  2874. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2875. redis := service.RedisClient()
  2876. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2877. redis.Set(key, "", time.Second)
  2878. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2879. redis.Set(keyOne, "", time.Second)
  2880. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2881. redis.Set(keySeven, "", time.Second)
  2882. defer redis.Close()
  2883. }
  2884. //service.SaveHisPrescription(prescription)
  2885. //更改患者挂号状态
  2886. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2887. fmt.Println("更改失败", err2)
  2888. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2889. advices := items["advices"].([]interface{})
  2890. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2891. groupNo := int64(0)
  2892. if len(advices) > 0 {
  2893. for _, advice := range advices {
  2894. tx := db.Begin()
  2895. // 在函数结束时处理事务回滚
  2896. defer func() {
  2897. if r := recover(); r != nil {
  2898. tx.Rollback()
  2899. }
  2900. }()
  2901. var s models.HisDoctorAdviceInfo
  2902. s.PrescriptionId = tempPrescription.ID
  2903. s.AdviceType = 2
  2904. s.AdviceDoctor = doctor_id
  2905. s.StopState = 2
  2906. s.ExecutionState = 2
  2907. s.AdviceDate = theTime3.Unix()
  2908. s.Status = 1
  2909. s.UserOrgId = adminInfo.CurrentOrgId
  2910. s.RecordDate = theTime3.Unix()
  2911. s.StartTime = tempPrescription.PreTime
  2912. s.Groupno = groupNo
  2913. s.PatientId = patient_id
  2914. s.HisPatientId = his_patient_id
  2915. s.StartTime = pTime
  2916. s.IsSettle = 2
  2917. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2918. if errcode > 0 {
  2919. c.ServeFailJSONWithSGJErrorCode(errcode)
  2920. return
  2921. }
  2922. s.StartTime = pTime
  2923. var total_count int64 //处方总库存
  2924. //查询改药品信息
  2925. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2926. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2927. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2928. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2929. total_count += prescribingNumberSeven * medical.MinNumber
  2930. }
  2931. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2932. total_count += prescribingNumberSeven
  2933. }
  2934. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2935. total_count += prescribingNumberSeven
  2936. }
  2937. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2938. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2939. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2940. if s.Price != lastWarehouse.RetailPrice {
  2941. s.Price = lastWarehouse.RetailPrice
  2942. }
  2943. if s.Price == 0 {
  2944. if lastWarehouse.ID == 0 {
  2945. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  2946. s.Price = lastWarehouseTwo.RetailPrice
  2947. }
  2948. }
  2949. }
  2950. //查询保存处方出库开关是否打开
  2951. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2952. if s.PatientId != 30038 {
  2953. if drugOutConfig.IsOpen == 1 {
  2954. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  2955. // 查询该药品最后一次出库记录
  2956. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  2957. var is_user_total int64
  2958. var no_user_total int64
  2959. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2960. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2961. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2962. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  2963. }
  2964. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2965. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2966. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2967. no_user_total += prescribingNumberSevenTy
  2968. }
  2969. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2970. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2971. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2972. no_user_total += prescribingNumberSevenTy
  2973. }
  2974. if len(druginfo) > 0 {
  2975. for _, it := range druginfo {
  2976. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2977. it.Count = it.Count * drug.MinNumber
  2978. is_user_total += it.Count
  2979. }
  2980. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2981. is_user_total += it.Count
  2982. }
  2983. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2984. is_user_total += it.Count
  2985. }
  2986. }
  2987. }
  2988. //fmt.Println("药品名称----------------------", drug.DrugName)
  2989. //fmt.Println("药品名称----------------------", drug.IsUse)
  2990. //fmt.Println("is_user_total-------------------------", is_user_total)
  2991. //fmt.Println("no_user_total-------------------------", no_user_total)
  2992. if is_user_total != no_user_total {
  2993. //出库
  2994. if drug.IsUse == 2 {
  2995. creater := adminInfo.AdminUser.Id
  2996. newadviceInfo := &models.HisDoctorAdviceInfo{
  2997. ID: s.ID,
  2998. UserOrgId: s.UserOrgId,
  2999. PatientId: s.PatientId,
  3000. HisPatientId: s.HisPatientId,
  3001. AdviceType: s.AdviceType,
  3002. AdviceDate: s.AdviceDate,
  3003. StartTime: s.StartTime,
  3004. AdviceName: s.AdviceName,
  3005. AdviceDesc: s.AdviceDesc,
  3006. ReminderDate: s.ReminderDate,
  3007. SingleDose: s.SingleDose,
  3008. SingleDoseUnit: s.SingleDoseUnit,
  3009. PrescribingNumber: s.PrescribingNumber,
  3010. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3011. DeliveryWay: s.DeliveryWay,
  3012. ExecutionFrequency: s.ExecutionFrequency,
  3013. AdviceDoctor: s.AdviceDoctor,
  3014. Status: s.Status,
  3015. CreatedTime: s.CreatedTime,
  3016. UpdatedTime: s.UpdatedTime,
  3017. AdviceAffirm: s.AdviceAffirm,
  3018. Remark: s.Remark,
  3019. StopTime: s.StopTime,
  3020. StopReason: s.StopReason,
  3021. StopDoctor: s.StopDoctor,
  3022. StopState: s.StopState,
  3023. ParentId: s.ParentId,
  3024. ExecutionTime: s.ExecutionTime,
  3025. ExecutionStaff: s.ExecutionStaff,
  3026. ExecutionState: s.ExecutionState,
  3027. Checker: s.Checker,
  3028. RecordDate: s.RecordDate,
  3029. DialysisOrderId: s.DialysisOrderId,
  3030. CheckTime: s.CheckTime,
  3031. CheckState: s.CheckState,
  3032. DrugSpec: s.DrugSpec,
  3033. DrugSpecUnit: s.DrugSpecUnit,
  3034. Groupno: s.Groupno,
  3035. RemindType: s.RemindType,
  3036. FrequencyType: s.FrequencyType,
  3037. DayCount: s.DayCount,
  3038. WeekDay: s.WeekDay,
  3039. TemplateId: s.TemplateId,
  3040. Modifier: s.Modifier,
  3041. DrugId: s.DrugId,
  3042. Price: s.Price,
  3043. PrescriptionId: s.PrescriptionId,
  3044. MedListCodg: s.MedListCodg,
  3045. FeedetlSn: s.FeedetlSn,
  3046. Day: s.DayCount,
  3047. ChildDoctorAdvice: nil,
  3048. Drug: models.Drug{},
  3049. Diagnosis: s.Diagnosis,
  3050. Way: s.Way,
  3051. HospApprFlag: s.HospApprFlag,
  3052. LmtUsedFlag: s.LmtUsedFlag,
  3053. HisOrderInfo: models.HisOrderInfo{},
  3054. IsMedicine: s.IsMedicine,
  3055. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3056. Child: nil,
  3057. IsSettle: s.IsSettle,
  3058. IsMobile: s.IsMobile,
  3059. IsSelfDrug: s.IsSelfDrug,
  3060. DrugWayCount: s.DrugWayCount,
  3061. }
  3062. var history_count int64
  3063. var local_count int64
  3064. //查找已经开过的医嘱信息
  3065. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3066. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3067. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3068. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3069. local_count += prescribingNumberSevenTy * drug.MinNumber
  3070. }
  3071. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3072. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3073. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3074. local_count += prescribingNumberSevenTy
  3075. }
  3076. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3077. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3078. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3079. local_count += prescribingNumberSevenTy
  3080. }
  3081. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3082. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3083. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3084. history_count += prescribingNumberSevenTy * drug.MinNumber
  3085. }
  3086. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3087. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3088. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3089. history_count += prescribingNumberSevenTy
  3090. }
  3091. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3092. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3093. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3094. history_count += prescribingNumberSevenTy
  3095. }
  3096. //如果当前出库数量大于历史出库数量则需要出库
  3097. if local_count > history_count {
  3098. //按最小单位出库
  3099. var cha_count = local_count - history_count
  3100. newadviceInfo.PrescribingNumber = float64(cha_count)
  3101. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3102. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3103. }
  3104. //如果当前出库数量小于历史出库数量则需要退库
  3105. if local_count < history_count {
  3106. var cha_count = history_count - local_count
  3107. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3108. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3109. }
  3110. if local_count == history_count {
  3111. if is_user_total == 0 {
  3112. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3113. }
  3114. }
  3115. }
  3116. //更新字典里面的库存
  3117. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3118. var sum_count int64
  3119. for _, its := range stockInfo {
  3120. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3121. if its.MaxUnit == baseDrug.MaxUnit {
  3122. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3123. }
  3124. sum_count += its.StockMaxNumber + its.StockMinNumber
  3125. }
  3126. //更新基础库存
  3127. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3128. //剩余库存
  3129. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3130. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3131. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3132. //创建医嘱
  3133. service.CreateHisDoctorAdviceOne(&s, tx)
  3134. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3135. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3136. if len(outInfoTwo) > 0 {
  3137. for _, item := range outInfoTwo {
  3138. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3139. }
  3140. }
  3141. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3142. if len(drugAutoDetail) > 0 {
  3143. for _, item := range drugAutoDetail {
  3144. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3145. }
  3146. }
  3147. }
  3148. }
  3149. }
  3150. //记录日志
  3151. byterequest, _ := json.Marshal(s)
  3152. adviceLog := models.XtDoctorAdviceLog{
  3153. UserOrgId: s.UserOrgId,
  3154. PatientId: s.PatientId,
  3155. AdminUserId: adminInfo.AdminUser.Id,
  3156. Module: 1,
  3157. ErrLog: string(byterequest),
  3158. Status: 1,
  3159. Ctime: time.Now().Unix(),
  3160. Mtime: 0,
  3161. Source: "电脑端新建his医嘱",
  3162. RecordDate: s.AdviceDate,
  3163. }
  3164. service.CreateDoctorAdviceLog(adviceLog)
  3165. //存储切片中
  3166. adviceList = append(adviceList, s)
  3167. redis := service.RedisClient()
  3168. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3169. redis.Set(key, "", time.Second)
  3170. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3171. redis.Set(keyOne, "", time.Second)
  3172. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3173. redis.Set(keySeven, "", time.Second)
  3174. var randNum int
  3175. randNum = rand.Intn(10000) + 1000
  3176. timestamp := time.Now().Unix()
  3177. tempTime := time.Unix(timestamp, 0)
  3178. timeFormat := tempTime.Format("20060102150405")
  3179. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3180. if s.UserOrgId != 10206 {
  3181. if s.ID == 0 {
  3182. //查询改药品是否已经停用
  3183. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3184. if base.ID > 0 {
  3185. tx.Rollback()
  3186. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3187. return
  3188. }
  3189. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3190. if drugMedical.SumCount == 0 {
  3191. tx.Rollback()
  3192. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3193. return
  3194. }
  3195. }
  3196. }
  3197. //赤峰
  3198. if adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3199. drug, _ := service.FindNewBaseDrugLibRecord(adminInfo.CurrentOrgId, s.DrugId, tx)
  3200. info, _ := service.FindNewLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut, tx)
  3201. if info.RetailPrice > 0 {
  3202. if s.DeliveryWay == "口服" {
  3203. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3204. s.Price = drug.RetailPrice
  3205. }
  3206. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3207. s.Price = info.RetailPrice
  3208. }
  3209. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3210. s.Price = info.RetailPrice
  3211. }
  3212. }
  3213. }
  3214. }
  3215. service.CreateHisDoctorAdviceOne(&s, tx)
  3216. tx.Commit()
  3217. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3218. redis.Set(keySix, "", time.Second)
  3219. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3220. redis.Set(keyFive, "", time.Second)
  3221. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3222. redis.Set(keyEight, "", time.Second)
  3223. defer redis.Close()
  3224. }
  3225. }
  3226. }
  3227. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3228. projects := items["project"].([]interface{})
  3229. if len(projects) > 0 {
  3230. for _, project := range projects {
  3231. tx := db.Begin()
  3232. // 在函数结束时处理事务回滚
  3233. defer func() {
  3234. if r := recover(); r != nil {
  3235. tx.Rollback()
  3236. }
  3237. }()
  3238. var p models.HisPrescriptionProject
  3239. p.PrescriptionId = tempPrescription.ID
  3240. p.PatientId = patient_id
  3241. p.RecordDate = theTime3.Unix()
  3242. p.Doctor = doctor_id
  3243. p.UserOrgId = adminInfo.CurrentOrgId
  3244. p.HisPatientId = his_patient_id
  3245. p.Status = 1
  3246. p.StartTime = pTime
  3247. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3248. if errcode > 0 {
  3249. tx.Rollback()
  3250. c.ServeFailJSONWithSGJErrorCode(errcode)
  3251. return
  3252. }
  3253. if p.ID == 0 {
  3254. p.IsOut = 2
  3255. }
  3256. if p.ID > 0 {
  3257. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3258. p.IsOut = projectDetail.IsOut
  3259. }
  3260. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3261. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3262. if p.Type == 3 {
  3263. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3264. if p.Price != lastWarehouse.PackingPrice {
  3265. p.Price = lastWarehouse.PackingPrice
  3266. }
  3267. if p.Price == 0 {
  3268. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3269. p.Price = lastWarehouseTwo.PackingPrice
  3270. }
  3271. if p.Unit == "" {
  3272. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3273. p.Unit = goodInfoOne.PackingUnit
  3274. }
  3275. }
  3276. }
  3277. if adminInfo.CurrentOrgId != 10206 {
  3278. if p.Type == 3 {
  3279. if p.ID == 0 {
  3280. //查询该耗材是否停用
  3281. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3282. //表示该耗材已经停用,不能保存
  3283. if goodInfoSeven.ID == 0 {
  3284. tx.Rollback()
  3285. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3286. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3287. return
  3288. }
  3289. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3290. if goodInfoOne.SumCount == 0 {
  3291. tx.Rollback()
  3292. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3293. return
  3294. }
  3295. }
  3296. }
  3297. }
  3298. //查询保存耗材出库开关是否打开
  3299. if p.PatientId != 30038 {
  3300. if goodOutConfig.IsOpen == 1 {
  3301. //耗材出库
  3302. if p.Type == 3 {
  3303. //对比当前数据和历史出库数据
  3304. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3305. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3306. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3307. //fmt.Println("p----------------------------------------------------", p.ProjectId)
  3308. //fmt.Println("p----------------------------------------------------", nowCount)
  3309. //fmt.Println("p----------------------------------------------------", historyCount)
  3310. //如果当前处方数量大于历史数据,则需要出库
  3311. if nowCount > historyCount {
  3312. var cha_count int64
  3313. cha_count = nowCount - historyCount
  3314. timeStr := time.Now().Format("2006-01-02")
  3315. timeArr := strings.Split(timeStr, "-")
  3316. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3317. total = total + 1
  3318. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3319. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3320. number = number + total
  3321. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3322. operation_time := time.Now().Unix()
  3323. creater := c.GetAdminUserInfo().AdminUser.Id
  3324. recordDateStr := time.Now().Format("2006-01-02")
  3325. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3326. nowtime := recordDate.Unix()
  3327. warehouseOut := models.WarehouseOut{
  3328. WarehouseOutOrderNumber: warehousing_out_order,
  3329. OperationTime: operation_time,
  3330. OrgId: adminInfo.CurrentOrgId,
  3331. Creater: creater,
  3332. Ctime: time.Now().Unix(),
  3333. Status: 1,
  3334. WarehouseOutTime: nowtime,
  3335. Type: 1,
  3336. StorehouseId: storeConfig.StorehouseOutInfo,
  3337. IsCheck: 1,
  3338. IsSys: 1,
  3339. }
  3340. //查询是否生成出库单
  3341. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3342. if out.ID == 0 {
  3343. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3344. }
  3345. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3346. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3347. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3348. dialyPrepareOne := models.DialysisBeforePrepare{
  3349. GoodTypeId: goodObj.GoodTypeId,
  3350. GoodId: p.ProjectId,
  3351. PatientId: p.PatientId,
  3352. RecordDate: p.RecordDate,
  3353. UserOrgId: adminInfo.CurrentOrgId,
  3354. Count: cha_count,
  3355. Ctime: time.Now().Unix(),
  3356. Creater: creater,
  3357. Status: 1,
  3358. StorehouseId: houseConfig.StorehouseOutInfo,
  3359. ProjectId: p.ID,
  3360. }
  3361. //出库
  3362. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3363. }
  3364. //如果当前处方数量小于历史数据,怎需要退库
  3365. if nowCount < historyCount {
  3366. var cha_count int64
  3367. cha_count = historyCount - nowCount
  3368. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3369. creater := c.GetAdminUserInfo().AdminUser.Id
  3370. newPrescriptionProject := &models.HisPrescriptionProject{
  3371. ID: p.ID,
  3372. ProjectId: p.ProjectId,
  3373. Price: p.Price,
  3374. UserOrgId: p.UserOrgId,
  3375. Status: 1,
  3376. Ctime: time.Now().Unix(),
  3377. Mtime: time.Now().Unix(),
  3378. PatientId: p.PatientId,
  3379. HisPatientId: p.HisPatientId,
  3380. RecordDate: p.RecordDate,
  3381. PrescriptionId: p.PrescriptionId,
  3382. Count: p.Count,
  3383. FeedetlSn: p.FeedetlSn,
  3384. MedListCodg: p.MedListCodg,
  3385. SingleDose: p.SingleDose,
  3386. DeliveryWay: p.DeliveryWay,
  3387. ExecutionFrequency: p.ExecutionFrequency,
  3388. Day: p.Day,
  3389. HisProject: models.HisProject{},
  3390. GoodInfo: models.GoodInfo{},
  3391. Remark: p.Remark,
  3392. Unit: p.Unit,
  3393. Type: p.Type,
  3394. Doctor: p.Doctor,
  3395. ExecutionTime: p.ExecutionTime,
  3396. ExecutionStaff: p.ExecutionStaff,
  3397. ExecutionState: p.ExecutionState,
  3398. CheckTime: p.CheckTime,
  3399. CheckState: p.CheckState,
  3400. Checker: p.Checker,
  3401. StartTime: p.StartTime,
  3402. TeamId: p.TeamId,
  3403. XtHisProjectTeam: models.XtHisProjectTeam{},
  3404. FrequencyType: p.FrequencyType,
  3405. DayCount: p.DayCount,
  3406. WeekDay: p.WeekDay,
  3407. IsCheckTeam: p.IsCheckTeam,
  3408. HisOrderInfo: models.HisOrderInfo{},
  3409. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3410. IsOut: p.IsOut,
  3411. YbSyncStatus: p.YbSyncStatus,
  3412. }
  3413. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3414. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3415. }
  3416. if nowCount == historyCount {
  3417. if historyCount == 0 {
  3418. recordDateStr := time.Now().Format("2006-01-02")
  3419. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3420. nowtime := recordDate.Unix()
  3421. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3422. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3423. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3424. creater := c.GetAdminUserInfo().AdminUser.Id
  3425. dialyPrepareOne := models.DialysisBeforePrepare{
  3426. GoodTypeId: goodObj.GoodTypeId,
  3427. GoodId: p.ProjectId,
  3428. PatientId: p.PatientId,
  3429. RecordDate: p.RecordDate,
  3430. UserOrgId: adminInfo.CurrentOrgId,
  3431. Count: nowCount,
  3432. Ctime: time.Now().Unix(),
  3433. Creater: creater,
  3434. Status: 1,
  3435. StorehouseId: houseConfig.StorehouseOutInfo,
  3436. ProjectId: p.ID,
  3437. }
  3438. //出库
  3439. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3440. }
  3441. }
  3442. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3443. //查询历史出库数据
  3444. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3445. var out_count_five int64
  3446. for _, item := range flowGood {
  3447. out_count_five += item.Count
  3448. }
  3449. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3450. //fmt.Println("p.ProjectId-----------------", p.ProjectId)
  3451. //fmt.Println("out_count_five===============", out_count_five)
  3452. //fmt.Println("parseIntCount===============", parseIntCount)
  3453. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3454. if out_count_five != parseIntCount {
  3455. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3456. detail := models.AutomaticReduceDetail{
  3457. WarehouseOutId: 0,
  3458. WarehouseOutOrderNumber: "",
  3459. PatientId: p.PatientId,
  3460. Ctime: time.Now().Unix(),
  3461. Mtime: 0,
  3462. Status: 1,
  3463. RecordTime: p.RecordDate,
  3464. OrgId: p.UserOrgId,
  3465. GoodId: p.ProjectId,
  3466. GoodTypeId: 0,
  3467. Count: parseIntCount,
  3468. Type: 0,
  3469. ProjectId: lastHisProject.ID,
  3470. StorehouseId: 0,
  3471. }
  3472. service.CreateNewAutoDetail(detail, tx)
  3473. }
  3474. // //查询耗材最后一次出库记录
  3475. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3476. // //查询默认出库仓库库存
  3477. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3478. // if len(wareOut) > 0 {
  3479. //
  3480. // for _, it := range wareOut {
  3481. // //回退库存
  3482. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3483. //
  3484. // //删除出库记录
  3485. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3486. //
  3487. // }
  3488. // }
  3489. //
  3490. // timeStr := time.Now().Format("2006-01-02")
  3491. // timeArr := strings.Split(timeStr, "-")
  3492. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3493. //
  3494. // total = total + 1
  3495. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3496. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3497. // number = number + total
  3498. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3499. //
  3500. // operation_time := time.Now().Unix()
  3501. // creater := c.GetAdminUserInfo().AdminUser.Id
  3502. //
  3503. // recordDateStr := time.Now().Format("2006-01-02")
  3504. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3505. // nowtime := recordDate.Unix()
  3506. // warehouseOut := models.WarehouseOut{
  3507. // WarehouseOutOrderNumber: warehousing_out_order,
  3508. // OperationTime: operation_time,
  3509. // OrgId: adminInfo.CurrentOrgId,
  3510. // Creater: creater,
  3511. // Ctime: time.Now().Unix(),
  3512. // Status: 1,
  3513. // WarehouseOutTime: nowtime,
  3514. // Type: 1,
  3515. // StorehouseId: storeConfig.StorehouseOutInfo,
  3516. // IsCheck: 1,
  3517. // IsSys: 1,
  3518. // }
  3519. // //查询是否生成出库单
  3520. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3521. // if out.ID == 0 {
  3522. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3523. // }
  3524. //
  3525. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3526. //
  3527. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3528. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3529. //
  3530. // dialyPrepareOne := models.DialysisBeforePrepare{
  3531. // GoodTypeId: goodObj.GoodTypeId,
  3532. // GoodId: p.ProjectId,
  3533. // PatientId: p.PatientId,
  3534. // RecordDate: p.RecordDate,
  3535. // UserOrgId: adminInfo.CurrentOrgId,
  3536. // Count: parseIntCount,
  3537. // Ctime: time.Now().Unix(),
  3538. // Creater: creater,
  3539. // Status: 1,
  3540. // StorehouseId: houseConfig.StorehouseOutInfo,
  3541. // ProjectId: lastHisProject.ID,
  3542. // }
  3543. // //判断是否是零用耗材(非零用)
  3544. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3545. //
  3546. // //查询历史出库数据
  3547. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3548. // var out_count int64
  3549. // for _, item := range flowGood {
  3550. // out_count += item.Count
  3551. // }
  3552. // //如果历史数和当前数据不想等才进行退库出库
  3553. // if out_count != parseIntCount {
  3554. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3555. //
  3556. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3557. // detail := models.AutomaticReduceDetail{
  3558. // WarehouseOutId: 0,
  3559. // WarehouseOutOrderNumber: "",
  3560. // PatientId: p.PatientId,
  3561. // Ctime: time.Now().Unix(),
  3562. // Mtime: 0,
  3563. // Status: 1,
  3564. // RecordTime: p.RecordDate,
  3565. // OrgId: p.UserOrgId,
  3566. // GoodId: p.ProjectId,
  3567. // GoodTypeId: 0,
  3568. // Count: parseIntCount,
  3569. // Type: 0,
  3570. // ProjectId: lastHisProject.ID,
  3571. // StorehouseId: 0,
  3572. // }
  3573. //
  3574. // service.CreateNewAutoDetail(detail, tx)
  3575. //
  3576. // //查询剩余库存
  3577. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3578. // var sum_count int64
  3579. // for _, item := range goodList {
  3580. // sum_count += item.StockCount
  3581. // }
  3582. //
  3583. // //更新剩余库存
  3584. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3585. //
  3586. // //耗材
  3587. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3588. //
  3589. // }
  3590. // //判断是否是零用耗材(零用但是是出库耗材)
  3591. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3592. //
  3593. // //查询历史出库数据
  3594. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3595. // var out_count int64
  3596. // for _, item := range flowGood {
  3597. // out_count += item.Count
  3598. // }
  3599. // //如果历史数和当前数据不想等才进行退库出库
  3600. // if out_count != parseIntCount {
  3601. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3602. //
  3603. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3604. // detail := models.AutomaticReduceDetail{
  3605. // WarehouseOutId: 0,
  3606. // WarehouseOutOrderNumber: "",
  3607. // PatientId: p.PatientId,
  3608. // Ctime: time.Now().Unix(),
  3609. // Mtime: 0,
  3610. // Status: 1,
  3611. // RecordTime: p.RecordDate,
  3612. // OrgId: p.UserOrgId,
  3613. // GoodId: p.ProjectId,
  3614. // GoodTypeId: 0,
  3615. // Count: parseIntCount,
  3616. // Type: 0,
  3617. // ProjectId: p.ID,
  3618. // StorehouseId: 0,
  3619. // }
  3620. //
  3621. // service.CreateNewAutoDetail(detail, tx)
  3622. //
  3623. // //查询剩余库存
  3624. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3625. // var sum_count int64
  3626. // for _, item := range goodList {
  3627. // sum_count += item.StockCount
  3628. // }
  3629. //
  3630. // //更新剩余库存
  3631. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3632. //
  3633. // //耗材
  3634. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3635. // }
  3636. //
  3637. // }
  3638. //
  3639. // }
  3640. //
  3641. //}
  3642. //记录日志
  3643. byterequest, _ := json.Marshal(p)
  3644. adviceLog := models.XtDoctorAdviceLog{
  3645. UserOrgId: p.UserOrgId,
  3646. PatientId: p.PatientId,
  3647. AdminUserId: adminInfo.AdminUser.Id,
  3648. Module: 1,
  3649. ErrLog: string(byterequest),
  3650. Status: 1,
  3651. Ctime: time.Now().Unix(),
  3652. Mtime: 0,
  3653. Source: "电脑端新建his项目",
  3654. RecordDate: p.RecordDate,
  3655. }
  3656. service.CreateDoctorAdviceLog(adviceLog)
  3657. projectList = append(projectList, p)
  3658. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3659. //新增或者编辑项目,修改对应的标签数据
  3660. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3661. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3662. var label models.HisLabelPrintInfo
  3663. project, _ := service.GetProjectDetail(p.ProjectId)
  3664. if project.CostClassify == 3 { //类别为检验检查
  3665. if p.TeamId > 0 { //检验检查组套
  3666. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3667. if tempLabel.ID == 0 {
  3668. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3669. label.Number = tempPrescription.PrescriptionNumber
  3670. label.ProjectId = project.ID
  3671. label.Status = 1
  3672. label.IsPrint = 2
  3673. label.DoctorId = info.DoctorId
  3674. label.UserOrgId = p.UserOrgId
  3675. label.PatientId = patient_id
  3676. label.RecordDate = recordDateTime
  3677. label.Ctime = time.Now().Unix()
  3678. label.Mtime = time.Now().Unix()
  3679. label.ItemId = p.TeamId
  3680. label.FeedetlSn = p.FeedetlSn
  3681. label.PProjectId = p.ID
  3682. label.ProjectName = team.ProjectTeam
  3683. label.PatientName = patient.Name
  3684. service.CreateNewHisLabelRecord(&label, tx)
  3685. }
  3686. } else { //单条检验检查项目
  3687. label.Number = tempPrescription.PrescriptionNumber
  3688. label.ProjectId = project.ID
  3689. label.Status = 1
  3690. label.DoctorId = info.DoctorId
  3691. label.UserOrgId = p.UserOrgId
  3692. label.PatientId = patient_id
  3693. label.RecordDate = recordDateTime
  3694. label.IsPrint = 2
  3695. label.Ctime = time.Now().Unix()
  3696. label.Mtime = time.Now().Unix()
  3697. label.FeedetlSn = p.FeedetlSn
  3698. label.PProjectId = p.ID
  3699. label.ItemId = p.TeamId
  3700. label.ProjectName = project.ProjectName
  3701. label.PatientName = patient.Name
  3702. service.CreateNewHisLabelRecord(&label, tx)
  3703. }
  3704. }
  3705. }
  3706. }
  3707. }
  3708. }
  3709. }
  3710. //插入检验数据
  3711. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3712. //新增或者编辑项目,修改对应的标签数据
  3713. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3714. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3715. var label models.HisLabelPrintInfo
  3716. project, _ := service.GetProjectDetail(p.ProjectId)
  3717. if project.CostClassify == 3 { //类别为检验检查
  3718. if p.TeamId > 0 { //检验检查组套
  3719. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3720. if tempLabel.ID == 0 {
  3721. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3722. label.Number = tempPrescription.PrescriptionNumber
  3723. label.ProjectId = project.ID
  3724. label.Status = 1
  3725. label.IsPrint = 2
  3726. label.DoctorId = info.DoctorId
  3727. label.UserOrgId = p.UserOrgId
  3728. label.PatientId = patient_id
  3729. label.RecordDate = recordDateTime
  3730. label.Ctime = time.Now().Unix()
  3731. label.Mtime = time.Now().Unix()
  3732. label.ItemId = p.TeamId
  3733. label.FeedetlSn = p.FeedetlSn
  3734. label.PProjectId = p.ID
  3735. label.ProjectName = team.ProjectTeam
  3736. label.PatientName = patient.Name
  3737. service.CreateHisLabelRecord(&label)
  3738. }
  3739. } else { //单条检验检查项目
  3740. label.Number = tempPrescription.PrescriptionNumber
  3741. label.ProjectId = project.ID
  3742. label.Status = 1
  3743. label.DoctorId = info.DoctorId
  3744. label.UserOrgId = p.UserOrgId
  3745. label.PatientId = patient_id
  3746. label.RecordDate = recordDateTime
  3747. label.IsPrint = 2
  3748. label.Ctime = time.Now().Unix()
  3749. label.Mtime = time.Now().Unix()
  3750. label.FeedetlSn = p.FeedetlSn
  3751. label.PProjectId = p.ID
  3752. label.ItemId = p.TeamId
  3753. label.ProjectName = project.ProjectName
  3754. label.PatientName = patient.Name
  3755. service.CreateHisLabelRecord(&label)
  3756. }
  3757. }
  3758. }
  3759. }
  3760. service.CreateNewHisProjectTwo(&p, tx)
  3761. var randNum int
  3762. randNum = rand.Intn(10000) + 1000
  3763. timestamp := time.Now().Unix()
  3764. tempTime := time.Unix(timestamp, 0)
  3765. timeFormat := tempTime.Format("20060102150405")
  3766. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3767. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  3768. if goodBase.ID > 0 {
  3769. tx.Rollback()
  3770. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  3771. return
  3772. }
  3773. service.CreateNewHisProjectTwo(&p, tx)
  3774. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3775. //查询剩余库存
  3776. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3777. var sum_count int64
  3778. for _, item := range goodList {
  3779. sum_count += item.StockCount
  3780. }
  3781. //更新剩余库存
  3782. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3783. //耗材
  3784. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3785. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3786. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3787. if len(outInfoTwo) > 0 {
  3788. for _, item := range outInfoTwo {
  3789. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3790. }
  3791. }
  3792. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3793. if len(drugAutoDetail) > 0 {
  3794. for _, item := range drugAutoDetail {
  3795. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  3796. }
  3797. }
  3798. tx.Commit()
  3799. }
  3800. }
  3801. }
  3802. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3803. // addition := items["addition"].([]interface{})
  3804. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3805. // ctime := time.Now().Unix()
  3806. // mtime := ctime
  3807. // if len(addition) > 0 {
  3808. // for _, item := range addition {
  3809. // var s models.HisAdditionalCharge
  3810. // s.PrescriptionId = tempPrescription.ID
  3811. // s.Status = 1
  3812. // s.UserOrgId = adminInfo.CurrentOrgId
  3813. // s.RecordDate = recordDateTime
  3814. // s.CreatedTime = ctime
  3815. // s.UpdatedTime = mtime
  3816. // s.PatientId = patient_id
  3817. // s.HisPatientId = his_patient_id
  3818. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3819. // if errcode > 0 {
  3820. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3821. // return
  3822. // }
  3823. // service.CreateAdditionalCharge(&s)
  3824. // var randNum int
  3825. // randNum = rand.Intn(10000) + 1000
  3826. // timestamp := time.Now().Unix()
  3827. // tempTime := time.Unix(timestamp, 0)
  3828. // timeFormat := tempTime.Format("20060102150405")
  3829. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3830. // service.CreateAdditionalCharge(&s)
  3831. //
  3832. // }
  3833. // }
  3834. //}
  3835. }
  3836. }
  3837. }
  3838. tx.Commit()
  3839. if err == nil {
  3840. c.ServeSuccessJSON(map[string]interface{}{
  3841. "msg": "保存成功",
  3842. })
  3843. return
  3844. } else {
  3845. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3846. return
  3847. }
  3848. } else {
  3849. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3850. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3851. var tempPrescription *models.HisPrescription
  3852. if len(prescriptions) > 0 {
  3853. for _, item := range prescriptions {
  3854. items := item.(map[string]interface{})
  3855. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3856. utils.ErrorLog("id")
  3857. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3858. return
  3859. }
  3860. id := int64(items["id"].(float64))
  3861. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3862. tempPrescription = &new_prescription
  3863. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3864. utils.ErrorLog("type")
  3865. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3866. return
  3867. }
  3868. types := int64(items["type"].(float64))
  3869. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3870. utils.ErrorLog("med_type")
  3871. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3872. return
  3873. }
  3874. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3875. if med_type == "0" {
  3876. med_type = "14"
  3877. }
  3878. //if order_status == 0 {
  3879. // order_status = 1
  3880. //}
  3881. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3882. utils.ErrorLog("pre_time")
  3883. }
  3884. preTime, _ := items["pre_time"].(string)
  3885. timeLayout := "2006-01-02"
  3886. loc, _ := time.LoadLocation("Local")
  3887. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3888. //result := strings.Split(preTime, " ")
  3889. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3890. if err != nil {
  3891. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3892. return
  3893. }
  3894. pTime := theTime2.Unix()
  3895. ctime := time.Now().Unix()
  3896. if tempPrescription.ID == 0 {
  3897. prescription := &models.HisPrescription{
  3898. ID: 0,
  3899. PatientId: patient_id,
  3900. UserOrgId: adminInfo.CurrentOrgId,
  3901. RecordDate: recordDateTime,
  3902. Ctime: ctime,
  3903. Mtime: ctime,
  3904. Type: types,
  3905. Modifier: adminInfo.AdminUser.Id,
  3906. Creator: adminInfo.AdminUser.Id,
  3907. Status: 1,
  3908. Doctor: role.UserName,
  3909. HisPatientId: his_patient_id,
  3910. OrderStatus: 1,
  3911. BatchNumber: "",
  3912. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3913. PreTime: pTime,
  3914. PType: p_type,
  3915. MedType: med_type,
  3916. }
  3917. tempPrescription = prescription
  3918. service.SaveHisPrescription(tempPrescription)
  3919. redis := service.RedisClient()
  3920. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3921. redis.Set(key, "", time.Second)
  3922. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3923. redis.Set(keyOne, "", time.Second)
  3924. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3925. redis.Set(keySeven, "", time.Second)
  3926. defer redis.Close()
  3927. } else {
  3928. tempPrescription.ID = id
  3929. tempPrescription.Type = types
  3930. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3931. tempPrescription.Mtime = time.Now().Unix()
  3932. tempPrescription.Doctor = role.UserName
  3933. //tempPrescription.OrderStatus = order_status
  3934. tempPrescription.PreTime = pTime
  3935. tempPrescription.MedType = med_type
  3936. service.SaveHisPrescription(tempPrescription)
  3937. redis := service.RedisClient()
  3938. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3939. redis.Set(key, "", time.Second)
  3940. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3941. redis.Set(keyOne, "", time.Second)
  3942. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3943. redis.Set(keySeven, "", time.Second)
  3944. defer redis.Close()
  3945. }
  3946. //service.SaveHisPrescription(prescription)
  3947. //更改患者挂号状态
  3948. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3949. fmt.Println("更改失败", err2)
  3950. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3951. advices := items["advices"].([]interface{})
  3952. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3953. groupNo := int64(0)
  3954. if len(advices) > 0 {
  3955. for _, advice := range advices {
  3956. var s models.HisDoctorAdviceInfo
  3957. s.PrescriptionId = tempPrescription.ID
  3958. s.AdviceType = 2
  3959. s.AdviceDoctor = doctor_id
  3960. s.StopState = 2
  3961. s.ExecutionState = 2
  3962. s.AdviceDate = theTime3.Unix()
  3963. s.Status = 1
  3964. s.UserOrgId = adminInfo.CurrentOrgId
  3965. s.RecordDate = theTime3.Unix()
  3966. s.StartTime = tempPrescription.PreTime
  3967. s.Groupno = groupNo
  3968. s.PatientId = patient_id
  3969. s.HisPatientId = his_patient_id
  3970. s.StartTime = pTime
  3971. s.IsSettle = 2
  3972. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3973. if errcode > 0 {
  3974. c.ServeFailJSONWithSGJErrorCode(errcode)
  3975. return
  3976. }
  3977. s.StartTime = pTime
  3978. var total_count int64 //处方总库存
  3979. //查询改药品信息
  3980. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3981. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3982. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3983. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3984. total_count += prescribingNumberSeven * medical.MinNumber
  3985. }
  3986. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3987. total_count += prescribingNumberSeven
  3988. }
  3989. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3990. total_count += prescribingNumberSeven
  3991. }
  3992. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3993. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3994. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3995. if s.Price != lastWarehouse.RetailPrice {
  3996. s.Price = lastWarehouse.RetailPrice
  3997. }
  3998. if s.Price == 0 {
  3999. if lastWarehouse.ID == 0 {
  4000. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  4001. s.Price = lastWarehouseTwo.RetailPrice
  4002. }
  4003. }
  4004. }
  4005. if adminInfo.CurrentOrgId != 10206 {
  4006. if s.ID == 0 {
  4007. //查询改药品是否已经停用
  4008. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  4009. if base.ID > 0 {
  4010. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  4011. return
  4012. }
  4013. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  4014. if drugMedical.SumCount == 0 {
  4015. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  4016. return
  4017. }
  4018. }
  4019. }
  4020. //赤峰
  4021. if s.UserOrgId == 10265 || s.UserOrgId == 10489 {
  4022. drug, _ := service.GetDrugByGoodId(s.DrugId)
  4023. info, _ := service.GetWarehoseInfoByDrugId(s.DrugId, s.UserOrgId)
  4024. if info.RetailPrice > 0 {
  4025. if s.DeliveryWay == "口服" {
  4026. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4027. s.Price = drug.RetailPrice
  4028. }
  4029. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4030. s.Price = info.RetailPrice
  4031. }
  4032. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4033. s.Price = info.RetailPrice
  4034. }
  4035. }
  4036. }
  4037. }
  4038. service.CreateHisDoctorAdvice(&s)
  4039. //记录日志
  4040. byterequest, _ := json.Marshal(s)
  4041. adviceLog := models.XtDoctorAdviceLog{
  4042. UserOrgId: s.UserOrgId,
  4043. PatientId: s.PatientId,
  4044. AdminUserId: adminInfo.AdminUser.Id,
  4045. Module: 1,
  4046. ErrLog: string(byterequest),
  4047. Status: 1,
  4048. Ctime: time.Now().Unix(),
  4049. Mtime: 0,
  4050. Source: "电脑端新建his医嘱",
  4051. RecordDate: s.AdviceDate,
  4052. }
  4053. service.CreateDoctorAdviceLog(adviceLog)
  4054. //存储切片中
  4055. adviceList = append(adviceList, s)
  4056. redis := service.RedisClient()
  4057. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4058. redis.Set(key, "", time.Second)
  4059. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4060. redis.Set(keyOne, "", time.Second)
  4061. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4062. redis.Set(keySeven, "", time.Second)
  4063. var randNum int
  4064. randNum = rand.Intn(10000) + 1000
  4065. timestamp := time.Now().Unix()
  4066. tempTime := time.Unix(timestamp, 0)
  4067. timeFormat := tempTime.Format("20060102150405")
  4068. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  4069. service.CreateHisDoctorAdvice(&s)
  4070. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4071. redis.Set(keySix, "", time.Second)
  4072. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4073. redis.Set(keyFive, "", time.Second)
  4074. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4075. redis.Set(keyEight, "", time.Second)
  4076. defer redis.Close()
  4077. }
  4078. }
  4079. }
  4080. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4081. projects := items["project"].([]interface{})
  4082. if len(projects) > 0 {
  4083. for _, project := range projects {
  4084. var p models.HisPrescriptionProject
  4085. p.PrescriptionId = tempPrescription.ID
  4086. p.PatientId = patient_id
  4087. p.RecordDate = theTime3.Unix()
  4088. p.Doctor = doctor_id
  4089. p.UserOrgId = adminInfo.CurrentOrgId
  4090. p.HisPatientId = his_patient_id
  4091. p.Status = 1
  4092. p.StartTime = pTime
  4093. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  4094. if errcode > 0 {
  4095. c.ServeFailJSONWithSGJErrorCode(errcode)
  4096. return
  4097. }
  4098. if p.ID == 0 {
  4099. p.IsOut = 2
  4100. }
  4101. if p.ID > 0 {
  4102. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  4103. p.IsOut = projectDetail.IsOut
  4104. }
  4105. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4106. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4107. if p.Type == 3 {
  4108. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  4109. if p.Price != lastWarehouse.PackingPrice {
  4110. p.Price = lastWarehouse.PackingPrice
  4111. }
  4112. if p.Price == 0 {
  4113. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  4114. p.Price = lastWarehouseTwo.PackingPrice
  4115. }
  4116. if p.Unit == "" {
  4117. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4118. p.Unit = goodInfoOne.PackingUnit
  4119. }
  4120. }
  4121. }
  4122. if adminInfo.CurrentOrgId != 10206 {
  4123. if p.Type == 3 {
  4124. if p.ID == 0 {
  4125. //查询该耗材是否停用
  4126. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  4127. //表示该耗材已经停用,不能保存
  4128. if goodInfoSeven.ID == 0 {
  4129. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4130. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  4131. return
  4132. }
  4133. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4134. if goodInfoOne.SumCount == 0 {
  4135. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  4136. return
  4137. }
  4138. }
  4139. }
  4140. }
  4141. service.CreateHisProjectTwo(&p)
  4142. //记录日志
  4143. byterequest, _ := json.Marshal(p)
  4144. adviceLog := models.XtDoctorAdviceLog{
  4145. UserOrgId: p.UserOrgId,
  4146. PatientId: p.PatientId,
  4147. AdminUserId: adminInfo.AdminUser.Id,
  4148. Module: 1,
  4149. ErrLog: string(byterequest),
  4150. Status: 1,
  4151. Ctime: time.Now().Unix(),
  4152. Mtime: 0,
  4153. Source: "电脑端新建his项目",
  4154. RecordDate: p.RecordDate,
  4155. }
  4156. service.CreateDoctorAdviceLog(adviceLog)
  4157. projectList = append(projectList, p)
  4158. var randNum int
  4159. randNum = rand.Intn(10000) + 1000
  4160. timestamp := time.Now().Unix()
  4161. tempTime := time.Unix(timestamp, 0)
  4162. timeFormat := tempTime.Format("20060102150405")
  4163. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4164. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4165. //新增或者编辑项目,修改对应的标签数据
  4166. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4167. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4168. var label models.HisLabelPrintInfo
  4169. project, _ := service.GetProjectDetail(p.ProjectId)
  4170. if project.CostClassify == 3 { //类别为检验检查
  4171. if p.TeamId > 0 { //检验检查组套
  4172. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4173. if tempLabel.ID == 0 {
  4174. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4175. label.Number = tempPrescription.PrescriptionNumber
  4176. label.ProjectId = project.ID
  4177. label.Status = 1
  4178. label.IsPrint = 2
  4179. label.DoctorId = info.DoctorId
  4180. label.UserOrgId = p.UserOrgId
  4181. label.PatientId = patient_id
  4182. label.RecordDate = recordDateTime
  4183. label.Ctime = time.Now().Unix()
  4184. label.Mtime = time.Now().Unix()
  4185. label.ItemId = p.TeamId
  4186. label.FeedetlSn = p.FeedetlSn
  4187. label.PProjectId = p.ID
  4188. label.ProjectName = team.ProjectTeam
  4189. label.PatientName = patient.Name
  4190. service.CreateHisLabelRecord(&label)
  4191. }
  4192. } else { //单条检验检查项目
  4193. label.Number = tempPrescription.PrescriptionNumber
  4194. label.ProjectId = project.ID
  4195. label.Status = 1
  4196. label.DoctorId = info.DoctorId
  4197. label.UserOrgId = p.UserOrgId
  4198. label.PatientId = patient_id
  4199. label.RecordDate = recordDateTime
  4200. label.IsPrint = 2
  4201. label.Ctime = time.Now().Unix()
  4202. label.Mtime = time.Now().Unix()
  4203. label.FeedetlSn = p.FeedetlSn
  4204. label.PProjectId = p.ID
  4205. label.ItemId = p.TeamId
  4206. label.ProjectName = project.ProjectName
  4207. label.PatientName = patient.Name
  4208. service.CreateHisLabelRecord(&label)
  4209. }
  4210. }
  4211. }
  4212. }
  4213. service.SaveHisProjectTwo(&p)
  4214. }
  4215. }
  4216. }
  4217. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4218. // addition := items["addition"].([]interface{})
  4219. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4220. // ctime := time.Now().Unix()
  4221. // mtime := ctime
  4222. // if len(addition) > 0 {
  4223. // for _, item := range addition {
  4224. // var s models.HisAdditionalCharge
  4225. // s.PrescriptionId = tempPrescription.ID
  4226. // s.Status = 1
  4227. // s.UserOrgId = adminInfo.CurrentOrgId
  4228. // s.RecordDate = recordDateTime
  4229. // s.CreatedTime = ctime
  4230. // s.UpdatedTime = mtime
  4231. // s.PatientId = patient_id
  4232. // s.HisPatientId = his_patient_id
  4233. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4234. // if errcode > 0 {
  4235. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4236. // return
  4237. // }
  4238. // service.CreateAdditionalCharge(&s)
  4239. // var randNum int
  4240. // randNum = rand.Intn(10000) + 1000
  4241. // timestamp := time.Now().Unix()
  4242. // tempTime := time.Unix(timestamp, 0)
  4243. // timeFormat := tempTime.Format("20060102150405")
  4244. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4245. // service.CreateAdditionalCharge(&s)
  4246. //
  4247. // }
  4248. // }
  4249. //}
  4250. }
  4251. }
  4252. //查询今日该患者开的药品处方
  4253. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4254. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  4255. //药品出库
  4256. if drugOutConfig.IsOpen == 1 {
  4257. for _, item := range hisdoctorlist {
  4258. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  4259. // 查询该药品最后一次出库记录
  4260. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  4261. if len(druginfo) > 0 {
  4262. //回退库存
  4263. for _, it := range druginfo {
  4264. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4265. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4266. }
  4267. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4268. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4269. }
  4270. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4271. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4272. }
  4273. }
  4274. }
  4275. //删除记录
  4276. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4277. //查询最后一次数据
  4278. if drugOutConfig.IsOpen == 1 {
  4279. //出库
  4280. if drug.IsUse == 2 {
  4281. creater := adminInfo.AdminUser.Id
  4282. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4283. }
  4284. //更新字典里面的库存
  4285. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4286. var sum_count int64
  4287. for _, its := range stockInfo {
  4288. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4289. if its.MaxUnit == baseDrug.MaxUnit {
  4290. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4291. }
  4292. sum_count += its.StockMaxNumber + its.StockMinNumber
  4293. }
  4294. //更新基础库存
  4295. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4296. //剩余库存
  4297. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4298. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4299. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4300. }
  4301. }
  4302. }
  4303. //耗材保存处方出库
  4304. if goodOutConfig.IsOpen == 1 {
  4305. //查询今日耗材出库数量
  4306. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4307. for _, item := range hisgoodlist {
  4308. //查询历史出库数据
  4309. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4310. var out_count_five int64
  4311. for _, item := range flowGood {
  4312. out_count_five += item.Count
  4313. }
  4314. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  4315. if out_count_five != parseIntCount {
  4316. //查询耗材最后一次出库记录
  4317. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  4318. //查询默认出库仓库库存
  4319. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4320. if len(wareOut) > 0 {
  4321. for _, it := range wareOut {
  4322. //回退库存
  4323. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4324. //删除出库记录
  4325. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4326. }
  4327. }
  4328. timeStr := time.Now().Format("2006-01-02")
  4329. timeArr := strings.Split(timeStr, "-")
  4330. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4331. total = total + 1
  4332. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4333. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4334. number = number + total
  4335. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4336. operation_time := time.Now().Unix()
  4337. creater := c.GetAdminUserInfo().AdminUser.Id
  4338. recordDateStr := time.Now().Format("2006-01-02")
  4339. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4340. nowtime := recordDate.Unix()
  4341. warehouseOut := models.WarehouseOut{
  4342. WarehouseOutOrderNumber: warehousing_out_order,
  4343. OperationTime: operation_time,
  4344. OrgId: adminInfo.CurrentOrgId,
  4345. Creater: creater,
  4346. Ctime: time.Now().Unix(),
  4347. Status: 1,
  4348. WarehouseOutTime: nowtime,
  4349. Type: 1,
  4350. StorehouseId: storeConfig.StorehouseOutInfo,
  4351. IsCheck: 1,
  4352. IsSys: 1,
  4353. }
  4354. //查询是否生成出库单
  4355. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4356. if out.ID == 0 {
  4357. service.AddSigleWarehouseOut(&warehouseOut)
  4358. }
  4359. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4360. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4361. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4362. dialyPrepareOne := models.DialysisBeforePrepare{
  4363. GoodTypeId: goodObj.GoodTypeId,
  4364. GoodId: item.ProjectId,
  4365. PatientId: item.PatientId,
  4366. RecordDate: item.RecordDate,
  4367. UserOrgId: adminInfo.CurrentOrgId,
  4368. Count: parseIntCount,
  4369. Ctime: time.Now().Unix(),
  4370. Creater: creater,
  4371. Status: 1,
  4372. StorehouseId: houseConfig.StorehouseOutInfo,
  4373. ProjectId: item.ID,
  4374. }
  4375. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4376. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  4377. //查询历史出库数据
  4378. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4379. var out_count int64
  4380. for _, item := range flowGood {
  4381. out_count += item.Count
  4382. }
  4383. //如果历史数和当前数据不想等才进行退库出库
  4384. if out_count != parseIntCount {
  4385. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4386. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4387. detail := models.AutomaticReduceDetail{
  4388. WarehouseOutId: 0,
  4389. WarehouseOutOrderNumber: "",
  4390. PatientId: item.PatientId,
  4391. Ctime: time.Now().Unix(),
  4392. Mtime: 0,
  4393. Status: 1,
  4394. RecordTime: item.RecordDate,
  4395. OrgId: item.UserOrgId,
  4396. GoodId: item.ProjectId,
  4397. GoodTypeId: 0,
  4398. Count: parseIntCount,
  4399. Type: 0,
  4400. ProjectId: item.ID,
  4401. StorehouseId: 0,
  4402. }
  4403. service.CreateAutoDetail(detail)
  4404. //查询剩余库存
  4405. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4406. var sum_count int64
  4407. for _, item := range goodList {
  4408. sum_count += item.StockCount
  4409. }
  4410. //更新剩余库存
  4411. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4412. //耗材
  4413. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4414. }
  4415. }
  4416. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  4417. //查询历史出库数据
  4418. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4419. var out_count int64
  4420. for _, item := range flowGood {
  4421. out_count += item.Count
  4422. }
  4423. //如果历史数和当前数据不想等才进行退库出库
  4424. if out_count != parseIntCount {
  4425. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4426. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4427. detail := models.AutomaticReduceDetail{
  4428. WarehouseOutId: 0,
  4429. WarehouseOutOrderNumber: "",
  4430. PatientId: item.PatientId,
  4431. Ctime: time.Now().Unix(),
  4432. Mtime: 0,
  4433. Status: 1,
  4434. RecordTime: item.RecordDate,
  4435. OrgId: item.UserOrgId,
  4436. GoodId: item.ProjectId,
  4437. GoodTypeId: 0,
  4438. Count: parseIntCount,
  4439. Type: 0,
  4440. ProjectId: item.ID,
  4441. StorehouseId: 0,
  4442. }
  4443. service.CreateAutoDetail(detail)
  4444. //查询剩余库存
  4445. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4446. var sum_count int64
  4447. for _, item := range goodList {
  4448. sum_count += item.StockCount
  4449. }
  4450. //更新剩余库存
  4451. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4452. //耗材
  4453. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4454. }
  4455. }
  4456. }
  4457. }
  4458. }
  4459. ////同步到自备药
  4460. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  4461. if selfPrescriptionOpen.IsOpen == 1 {
  4462. timeStr := time.Now().Format("2006-01-02")
  4463. timeArr := strings.Split(timeStr, "-")
  4464. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  4465. total = total + 1
  4466. operation_time := time.Now().Unix()
  4467. creater := adminInfo.AdminUser.Id
  4468. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4469. warehousing := models.XtSelfDrugWarehouse{
  4470. WarehousingOrder: warehousing_order,
  4471. OperationTime: operation_time,
  4472. OrgId: adminInfo.CurrentOrgId,
  4473. Creater: creater,
  4474. Ctime: time.Now().Unix(),
  4475. Status: 1,
  4476. WarehousingTime: recordDateTime,
  4477. Type: 0,
  4478. StorehouseId: 0,
  4479. IsCheck: 1,
  4480. PatientId: patient_id,
  4481. IsSys: 1,
  4482. }
  4483. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  4484. if selfDrugWarehouse.ID == 0 {
  4485. service.AddSelfDrugWarehouse(&warehousing, tx)
  4486. }
  4487. if selfDrugWarehouse.ID > 0 {
  4488. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  4489. }
  4490. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  4491. fmt.Println(info)
  4492. for _, item := range hisdoctorlist {
  4493. //查询该病人的该药品是否已经入库
  4494. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  4495. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  4496. var in_count int64
  4497. if len(selfdruginfo) > 0 {
  4498. for _, item := range selfdruginfo {
  4499. var in_count_one int64
  4500. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4501. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  4502. }
  4503. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4504. in_count_one = item.WarehousingCount
  4505. }
  4506. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4507. in_count_one = item.WarehousingCount
  4508. }
  4509. in_count += in_count_one
  4510. }
  4511. }
  4512. if selfBasedrug.IsSelfDrug == 1 {
  4513. var total_count int64
  4514. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  4515. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  4516. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4517. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  4518. }
  4519. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4520. total_count += prescribingNumberSeven
  4521. }
  4522. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4523. total_count += prescribingNumberSeven
  4524. }
  4525. //入库
  4526. if total_count > in_count {
  4527. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  4528. WarehousingOrder: warehousing_order,
  4529. WarehousingId: info.ID,
  4530. DrugId: item.DrugId,
  4531. Number: "",
  4532. ProductDate: 0,
  4533. ExpiryDate: 0,
  4534. WarehousingCount: total_count - in_count,
  4535. WarehouseingUnit: selfBasedrug.MinUnit,
  4536. Price: 0,
  4537. TotalPrice: 0,
  4538. Status: 1,
  4539. Ctime: time.Now().Unix(),
  4540. Remark: "",
  4541. OrgId: adminInfo.CurrentOrgId,
  4542. Type: 0,
  4543. Manufacturer: selfBasedrug.Manufacturer,
  4544. Dealer: selfBasedrug.Dealer,
  4545. StockMaxNumber: total_count - in_count,
  4546. RetailTotalPrice: 0,
  4547. BatchNumber: "",
  4548. MaxUnit: selfBasedrug.MinUnit,
  4549. MinUnit: selfBasedrug.MinUnit,
  4550. RetailPrice: 0,
  4551. StorehouseId: 0,
  4552. IsCheck: 1,
  4553. StockMinNumber: 0,
  4554. PatientId: patient_id,
  4555. IsSys: 1,
  4556. RecordDate: item.RecordDate,
  4557. AdviceId: item.ID,
  4558. }
  4559. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  4560. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  4561. Creator := adminInfo.AdminUser.Id
  4562. //查询默认仓库剩余多少库存
  4563. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  4564. var sum_count int64
  4565. for _, it := range list {
  4566. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  4567. if it.MaxUnit == baseDrug.MaxUnit {
  4568. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  4569. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  4570. }
  4571. sum_count += it.StockMaxNumber + it.StockMinNumber
  4572. }
  4573. flow := &models.XtSelfDrugFlow{
  4574. WarehousingId: info.ID,
  4575. DrugId: item.DrugId,
  4576. Number: "",
  4577. BatchNumber: "",
  4578. Count: total_count - in_count,
  4579. UserOrgId: adminInfo.CurrentOrgId,
  4580. PatientId: item.PatientId,
  4581. SystemTime: time.Now().Unix(),
  4582. ConsumableType: 1,
  4583. IsSys: 1,
  4584. WarehousingOrder: warehousing_order,
  4585. WarehouseOutId: 0,
  4586. WarehouseOutOrderNumber: "",
  4587. IsEdit: 0,
  4588. CancelStockId: 0,
  4589. CancelOrderNumber: "",
  4590. Manufacturer: selfBasedrug.Manufacturer,
  4591. Dealer: selfBasedrug.Dealer,
  4592. Creator: Creator,
  4593. UpdateCreator: Creator,
  4594. Status: 1,
  4595. Ctime: item.AdviceDate,
  4596. Mtime: 0,
  4597. Price: item.Price,
  4598. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  4599. WarehouseOutDetailId: 0,
  4600. CancelOutDetailId: 0,
  4601. ExpireDate: 0,
  4602. ProductDate: 0,
  4603. MaxUnit: selfBasedrug.MinUnit,
  4604. MinUnit: selfBasedrug.MinUnit,
  4605. StorehouseId: 0,
  4606. OverCount: sum_count,
  4607. OperateTime: time.Now().Unix(),
  4608. AdviceId: item.ID,
  4609. }
  4610. service.CreateSelfDrugFlow(flow, tx)
  4611. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  4612. var total_count int64 // 入库总数量
  4613. var over_count int64 //剩余库存
  4614. for _, it := range drugInfolist {
  4615. if it.MaxUnit == selfBasedrug.MaxUnit {
  4616. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  4617. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  4618. }
  4619. }
  4620. for _, it := range drugInfolist {
  4621. total_count += it.WarehousingCount
  4622. over_count += it.StockMaxNumber + it.StockMinNumber
  4623. }
  4624. //查询该仓库是否有默认数据
  4625. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  4626. if selfDrugStock.ID == 0 {
  4627. drugStock := models.XtSelfDrugStockCount{
  4628. UserOrgId: item.UserOrgId,
  4629. PatientId: item.PatientId,
  4630. SumInCount: total_count,
  4631. SumOutCount: 0,
  4632. SumCancelCount: 0,
  4633. DrugId: item.DrugId,
  4634. Ctime: time.Now().Unix(),
  4635. Mtime: 0,
  4636. Status: 1,
  4637. FlushCount: over_count,
  4638. SumActOutCount: 0,
  4639. }
  4640. service.CreateSelfDrugStockSum(drugStock, tx)
  4641. }
  4642. if selfDrugStock.ID > 0 {
  4643. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  4644. }
  4645. }
  4646. //查询这个单据的出库数量
  4647. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  4648. var his_out_count int64
  4649. for _, item := range drugFlowList {
  4650. his_out_count += item.Count
  4651. }
  4652. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  4653. if (total_count + his_out_count) <= in_count {
  4654. // 出库
  4655. if total_count < in_count {
  4656. var cha_count int64
  4657. cha_count = in_count - total_count
  4658. var stock_number int64 = 0
  4659. //查询库存是否充足
  4660. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  4661. // 将该批次的剩余库存数量转换为拆零数量
  4662. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4663. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  4664. }
  4665. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4666. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  4667. }
  4668. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4669. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  4670. }
  4671. if stock_number >= cha_count {
  4672. var maxNumber int64 = 0
  4673. var minNumber int64 = 0
  4674. maxNumber = cha_count / selfBasedrug.MinNumber
  4675. minNumber = cha_count % selfBasedrug.MinNumber
  4676. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4677. minNumber = maxNumber
  4678. }
  4679. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4680. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  4681. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4682. return
  4683. }
  4684. }
  4685. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4686. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  4687. }
  4688. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4689. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  4690. }
  4691. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4692. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  4693. }
  4694. if warehouse.StockMaxNumber < 0 {
  4695. warehouse.StockMaxNumber = 0
  4696. }
  4697. if warehouse.StockMinNumber < 0 {
  4698. warehouse.StockMinNumber = 0
  4699. }
  4700. warehouse.Mtime = time.Now().Unix()
  4701. if warehouse.StockMinNumber < minNumber {
  4702. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  4703. if warehouse.MaxUnit != warehouse.MinUnit {
  4704. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  4705. }
  4706. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  4707. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  4708. }
  4709. } else {
  4710. if minNumber > 0 {
  4711. if (warehouse.StockMinNumber - minNumber) >= 0 {
  4712. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  4713. }
  4714. }
  4715. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  4716. if warehouse.StockMinNumber > 0 {
  4717. if warehouse.StockMinNumber-cha_count >= 0 {
  4718. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  4719. }
  4720. }
  4721. }
  4722. }
  4723. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  4724. if (warehouse.StockMinNumber - cha_count) >= 0 {
  4725. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  4726. }
  4727. }
  4728. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4729. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  4730. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4731. return
  4732. }
  4733. }
  4734. if warehouse.StockMinNumber <= 0 {
  4735. warehouse.StockMinNumber = 0
  4736. }
  4737. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  4738. //查询该药品剩余库存
  4739. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  4740. var over_count int64
  4741. for _, its := range infolist {
  4742. if its.MaxUnit == selfBasedrug.MaxUnit {
  4743. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  4744. }
  4745. over_count += its.StockMaxNumber + its.StockMinNumber
  4746. }
  4747. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  4748. drugflow := models.XtSelfDrugFlow{
  4749. WarehouseOutId: 0,
  4750. WarehouseOutOrderNumber: warehousing_order,
  4751. WarehousingOrder: warehousing_order,
  4752. DrugId: item.DrugId,
  4753. Number: warehouse.Number,
  4754. ProductDate: warehouse.ProductDate,
  4755. ExpireDate: warehouse.ExpiryDate,
  4756. Count: cha_count,
  4757. Price: warehouse.RetailPrice,
  4758. Status: 1,
  4759. Ctime: item.AdviceDate,
  4760. Mtime: time.Now().Unix(),
  4761. UserOrgId: item.UserOrgId,
  4762. Manufacturer: warehouse.Manufacturer,
  4763. Dealer: warehouse.Dealer,
  4764. BatchNumber: warehouse.BatchNumber,
  4765. MaxUnit: selfBasedrug.MinUnit,
  4766. ConsumableType: 20,
  4767. IsEdit: 1,
  4768. Creator: 0,
  4769. IsSys: 3,
  4770. WarehouseOutDetailId: drugWareInfo.ID,
  4771. AdviceId: item.ID,
  4772. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  4773. StorehouseId: 0,
  4774. AdminUserId: creater,
  4775. LastPrice: warehouse.Price,
  4776. StockCount: "",
  4777. WarehousingDetailId: 0,
  4778. OverCount: over_count,
  4779. RetailPrice: item.Price, //手动出库出库价格
  4780. WarehousingId: warehouse.ID,
  4781. SystemTime: item.AdviceDate,
  4782. PatientId: item.PatientId,
  4783. Remark: "保存处方入库数据差",
  4784. OperateTime: time.Now().Unix(),
  4785. }
  4786. if warehouse.RetailPrice == 0 {
  4787. drugflow.Price = item.Price
  4788. }
  4789. service.CreateSelfDrugFlowOne(drugflow, tx)
  4790. var out_count int64
  4791. out_count = in_count - total_count
  4792. //
  4793. //fmt.Println("in_count------------------", in_count)
  4794. //fmt.Println("total_count------------------", total_count)
  4795. //添加出库数量
  4796. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  4797. //查询剩余库存
  4798. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  4799. var sum_count int64
  4800. for _, its := range stockInfo {
  4801. if its.MaxUnit == selfBasedrug.MaxUnit {
  4802. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  4803. }
  4804. sum_count += its.StockMaxNumber + its.StockMinNumber
  4805. }
  4806. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  4807. } else {
  4808. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4809. return
  4810. }
  4811. }
  4812. }
  4813. }
  4814. }
  4815. }
  4816. }
  4817. tx.Commit()
  4818. if err == nil {
  4819. c.ServeSuccessJSON(map[string]interface{}{
  4820. "msg": "保存成功",
  4821. })
  4822. return
  4823. } else {
  4824. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4825. return
  4826. }
  4827. }
  4828. }
  4829. //func (c *HisApiController) EditHisPrescription() {
  4830. // record_date := c.GetString("record_date")
  4831. // patient_id, _ := c.GetInt64("patient_id")
  4832. // reg_type, _ := c.GetInt64("reg_type")
  4833. // //diagnose, _ := c.GetInt64("diagnose", 0)
  4834. // diagnose := c.GetString("diagnose")
  4835. // sick_type, _ := c.GetInt64("sick_type")
  4836. // sick_history := c.GetString("sick_history")
  4837. // doctor_id, _ := c.GetInt64("doctor", 0)
  4838. // department, _ := c.GetInt64("department", 0)
  4839. // his_patient_id, _ := c.GetInt64("his_patient_id")
  4840. // p_type, _ := c.GetInt64("p_type")
  4841. //
  4842. // dataBody := make(map[string]interface{}, 0)
  4843. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4844. // if err != nil {
  4845. // utils.ErrorLog(err.Error())
  4846. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4847. // return
  4848. // }
  4849. //
  4850. // timeLayout := "2006-01-02"
  4851. // loc, _ := time.LoadLocation("Local")
  4852. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4853. // if err != nil {
  4854. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4855. // return
  4856. // }
  4857. // adminInfo := c.GetAdminUserInfo()
  4858. // recordDateTime := theTime.Unix()
  4859. //
  4860. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  4861. //
  4862. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4863. // var hpInfo models.HisPrescriptionInfo
  4864. // if info.ID == 0 {
  4865. // var randNum int
  4866. // randNum = rand.Intn(10000) + 1000
  4867. // timestamp := time.Now().Unix()
  4868. // tempTime := time.Unix(timestamp, 0)
  4869. // timeFormat := tempTime.Format("20060102150405")
  4870. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4871. //
  4872. // hpInfo = models.HisPrescriptionInfo{
  4873. // UserOrgId: adminInfo.CurrentOrgId,
  4874. // RecordDate: theTime.Unix(),
  4875. // PatientId: patient_id,
  4876. // Status: 1,
  4877. // Ctime: time.Now().Unix(),
  4878. // Mtime: time.Now().Unix(),
  4879. // Creator: adminInfo.AdminUser.Id,
  4880. // Modifier: adminInfo.AdminUser.Id,
  4881. // Diagnosis: diagnose,
  4882. // SickHistory: sick_history,
  4883. // Departments: department,
  4884. // RegisterType: reg_type,
  4885. // PrescriptionNumber: p_number,
  4886. // PrescriptionStatus: 1,
  4887. // Doctor: role.UserName,
  4888. // DoctorId: doctor_id,
  4889. // SickType: sick_type,
  4890. // PType: p_type,
  4891. // }
  4892. // service.SavePatientPrescriptionInfo(hpInfo)
  4893. //
  4894. // } else {
  4895. // hpInfo = models.HisPrescriptionInfo{
  4896. // ID: info.ID,
  4897. // UserOrgId: adminInfo.CurrentOrgId,
  4898. // RecordDate: info.RecordDate,
  4899. // PatientId: info.PatientId,
  4900. // Status: 1,
  4901. // Ctime: info.Ctime,
  4902. // Mtime: time.Now().Unix(),
  4903. // Creator: info.Creator,
  4904. // Modifier: adminInfo.AdminUser.Id,
  4905. // Diagnosis: diagnose,
  4906. // SickHistory: sick_history,
  4907. // Departments: department,
  4908. // RegisterType: reg_type,
  4909. // PrescriptionNumber: info.PrescriptionNumber,
  4910. // Doctor: role.UserName,
  4911. // PrescriptionStatus: info.PrescriptionStatus,
  4912. // DoctorId: doctor_id,
  4913. // SickType: sick_type,
  4914. // PType: info.PType,
  4915. // }
  4916. // service.SavePatientPrescriptionInfo(hpInfo)
  4917. // }
  4918. //
  4919. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4920. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4921. //
  4922. // if len(prescriptions) > 0 {
  4923. // for _, item := range prescriptions {
  4924. // items := item.(map[string]interface{})
  4925. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4926. // utils.ErrorLog("id")
  4927. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4928. // return
  4929. // }
  4930. // id := int64(items["id"].(float64))
  4931. //
  4932. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4933. // utils.ErrorLog("type")
  4934. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4935. // return
  4936. // }
  4937. // types := int64(items["type"].(float64))
  4938. //
  4939. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4940. // utils.ErrorLog("med_type")
  4941. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4942. // return
  4943. // }
  4944. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4945. //
  4946. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  4947. //
  4948. // ctime := time.Now().Unix()
  4949. //
  4950. // prescription := &models.HisPrescription{
  4951. // ID: id,
  4952. // PatientId: patient_id,
  4953. // UserOrgId: adminInfo.CurrentOrgId,
  4954. // RecordDate: recordDateTime,
  4955. // Ctime: ctime,
  4956. // Mtime: ctime,
  4957. // Type: types,
  4958. // Modifier: adminInfo.AdminUser.Id,
  4959. // Creator: adminInfo.AdminUser.Id,
  4960. // Status: 1,
  4961. // Doctor: role.UserName,
  4962. // HisPatientId: his_patient_id,
  4963. // OrderStatus: 1,
  4964. // BatchNumber: "",
  4965. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  4966. // PType: hpInfo.PType,
  4967. // MedType: med_type,
  4968. // }
  4969. //
  4970. // if historyPrescription.ID > 0 {
  4971. // prescription.PreTime = historyPrescription.PreTime
  4972. //
  4973. // }
  4974. //
  4975. // service.SaveHisPrescription(prescription)
  4976. //
  4977. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4978. // advices := items["advices"].([]interface{})
  4979. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4980. // groupNo := int64(0)
  4981. // ctime := time.Now().Unix()
  4982. // mtime := ctime
  4983. // if len(advices) > 0 {
  4984. // for _, advice := range advices {
  4985. // var s models.HisDoctorAdviceInfo
  4986. // s.PrescriptionId = prescription.ID
  4987. // s.AdviceType = 2
  4988. // s.AdviceDoctor = adminInfo.AdminUser.Id
  4989. // s.StopState = 2
  4990. // s.ExecutionState = 2
  4991. // s.AdviceDate = recordDateTime
  4992. // s.Status = 1
  4993. // s.UserOrgId = adminInfo.CurrentOrgId
  4994. // s.RecordDate = recordDateTime
  4995. // s.StartTime = prescription.PreTime
  4996. // s.Groupno = groupNo
  4997. // s.CreatedTime = ctime
  4998. // s.UpdatedTime = mtime
  4999. // s.PatientId = patient_id
  5000. // s.HisPatientId = his_patient_id
  5001. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  5002. // if errcode > 0 {
  5003. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5004. // return
  5005. // }
  5006. //
  5007. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5008. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5009. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  5010. // if s.Price == 0 {
  5011. // s.Price = lastWarehouse.RetailPrice
  5012. // }
  5013. // }
  5014. //
  5015. // service.CreateHisDoctorAdvice(&s)
  5016. // //记录日志
  5017. // byterequest, _ := json.Marshal(s)
  5018. // adviceLog := models.XtDoctorAdviceLog{
  5019. // UserOrgId: s.UserOrgId,
  5020. // PatientId: s.PatientId,
  5021. // AdminUserId: adminInfo.AdminUser.Id,
  5022. // Module: 1,
  5023. // ErrLog: string(byterequest),
  5024. // Status: 1,
  5025. // Ctime: time.Now().Unix(),
  5026. // Mtime: 0,
  5027. // Source: "电脑端his医嘱修改",
  5028. // RecordDate: s.AdviceDate,
  5029. // }
  5030. // service.CreateDoctorAdviceLog(adviceLog)
  5031. // redis := service.RedisClient()
  5032. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5033. // redis.Set(key, "", time.Second)
  5034. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5035. // fmt.Println("keyOne", keyOne)
  5036. // redis.Set(keyOne, "", time.Second)
  5037. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5038. // redis.Set(keySeven, "", time.Second)
  5039. // redis.Close()
  5040. //
  5041. // }
  5042. // }
  5043. // }
  5044. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5045. // projects := items["project"].([]interface{})
  5046. // if len(projects) > 0 {
  5047. // for _, project := range projects {
  5048. // var p models.HisPrescriptionProject
  5049. // p.PrescriptionId = prescription.ID
  5050. // p.Ctime = time.Now().Unix()
  5051. // p.Mtime = time.Now().Unix()
  5052. // p.PatientId = patient_id
  5053. // p.RecordDate = recordDateTime
  5054. // p.UserOrgId = adminInfo.CurrentOrgId
  5055. // p.HisPatientId = his_patient_id
  5056. // p.Status = 1
  5057. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  5058. // if errcode > 0 {
  5059. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5060. // return
  5061. // }
  5062. // service.CreateHisProjectTwo(&p)
  5063. //
  5064. // //记录日志
  5065. // byterequest, _ := json.Marshal(p)
  5066. // adviceLog := models.XtDoctorAdviceLog{
  5067. // UserOrgId: p.UserOrgId,
  5068. // PatientId: p.PatientId,
  5069. // AdminUserId: adminInfo.AdminUser.Id,
  5070. // Module: 1,
  5071. // ErrLog: string(byterequest),
  5072. // Status: 1,
  5073. // Ctime: time.Now().Unix(),
  5074. // Mtime: 0,
  5075. // Source: "电脑端his项目修改",
  5076. // RecordDate: p.RecordDate,
  5077. // }
  5078. // service.CreateDoctorAdviceLog(adviceLog)
  5079. // }
  5080. // }
  5081. // }
  5082. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  5083. // addition := items["addition"].([]interface{})
  5084. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5085. // ctime := time.Now().Unix()
  5086. // mtime := ctime
  5087. // if len(addition) > 0 {
  5088. // for _, item := range addition {
  5089. // var s models.HisAdditionalCharge
  5090. // s.PrescriptionId = prescription.ID
  5091. // s.Status = 1
  5092. // s.UserOrgId = adminInfo.CurrentOrgId
  5093. // s.RecordDate = recordDateTime
  5094. // s.CreatedTime = ctime
  5095. // s.UpdatedTime = mtime
  5096. // s.PatientId = patient_id
  5097. // s.HisPatientId = his_patient_id
  5098. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5099. // if errcode > 0 {
  5100. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5101. // return
  5102. // }
  5103. // service.CreateAdditionalCharge(&s)
  5104. // }
  5105. // }
  5106. // }
  5107. //
  5108. // }
  5109. // }
  5110. // }
  5111. // if err == nil {
  5112. // c.ServeSuccessJSON(map[string]interface{}{
  5113. // "msg": "保存成功",
  5114. // })
  5115. // return
  5116. //
  5117. // } else {
  5118. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5119. // return
  5120. // }
  5121. //}
  5122. func (c *HisApiController) DeletePrescription() {
  5123. prescription_id, _ := c.GetInt64("id")
  5124. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  5125. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  5126. ////同步到自备药
  5127. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  5128. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  5129. if selfPrescriptionOpen.IsOpen == 1 {
  5130. // 在函数结束时处理事务回滚
  5131. db := service.XTWriteDB()
  5132. tx := db.Begin()
  5133. defer func() {
  5134. if r := recover(); r != nil {
  5135. tx.Rollback()
  5136. } else {
  5137. tx.Commit()
  5138. }
  5139. }()
  5140. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  5141. for _, item := range advicesList {
  5142. timeStr := time.Now().Format("2006-01-02")
  5143. timeArr := strings.Split(timeStr, "-")
  5144. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5145. total = total + 1
  5146. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5147. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5148. number = number + total
  5149. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5150. operation_time := time.Now().Unix()
  5151. creater := c.GetAdminUserInfo().AdminUser.Id
  5152. //创建一个出库单
  5153. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5154. WarehouseOutOrderNumber: warehousing_out_order,
  5155. OperationTime: operation_time,
  5156. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5157. Creater: creater,
  5158. Ctime: time.Now().Unix(),
  5159. Status: 1,
  5160. WarehouseOutTime: item.AdviceDate,
  5161. Type: 0,
  5162. PatientId: item.PatientId,
  5163. IsCheck: 1,
  5164. }
  5165. //查询今日是否有出库数据
  5166. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  5167. fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
  5168. if lastWarehouseOut.ID == 0 {
  5169. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5170. }
  5171. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5172. var total_count int64
  5173. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5174. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5175. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5176. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5177. }
  5178. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5179. total_count += prescribingNumberSeven
  5180. }
  5181. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5182. total_count += prescribingNumberSeven
  5183. }
  5184. //出库
  5185. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5186. WarehouseOutOrderNumber: warehousing_out_order,
  5187. WarehouseOutId: lastWarehouseOut.ID,
  5188. DrugId: item.DrugId,
  5189. Count: total_count,
  5190. Price: 0,
  5191. TotalPrice: 0,
  5192. Status: 1,
  5193. Ctime: item.AdviceDate,
  5194. Mtime: item.AdviceDate,
  5195. Remark: "",
  5196. OrgId: item.UserOrgId,
  5197. Type: 0,
  5198. Manufacturer: selfBasedrug.Manufacturer,
  5199. Dealer: selfBasedrug.Dealer,
  5200. RetailPrice: 0,
  5201. RetailTotalPrice: 0,
  5202. CountUnit: selfBasedrug.MinUnit,
  5203. ExpiryDate: 0,
  5204. ProductDate: 0,
  5205. Number: "",
  5206. BatchNumber: "",
  5207. IsSys: 1,
  5208. WarehouseInfoId: 0,
  5209. AdminUserId: 0,
  5210. StockCount: "",
  5211. IsCheck: 1,
  5212. SysRecordTime: item.AdviceDate,
  5213. PatientId: item.PatientId,
  5214. ClassType: "",
  5215. AdviceId: item.ID,
  5216. }
  5217. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5218. }
  5219. fmt.Println("长度-------------------------------", warehousingOutInfo)
  5220. for _, it := range warehousingOutInfo {
  5221. //查询今日是否有出库数据
  5222. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  5223. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5224. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5225. //出库逻辑
  5226. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  5227. //查询剩余库存
  5228. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5229. var sum_count int64
  5230. for _, its := range stockInfo {
  5231. if its.MaxUnit == medical.MaxUnit {
  5232. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5233. }
  5234. sum_count += its.StockMaxNumber + its.StockMinNumber
  5235. }
  5236. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5237. }
  5238. }
  5239. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5240. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5241. //耗材保存处方出库
  5242. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5243. //已收费和已发药限制逻辑
  5244. isCharge := false
  5245. isMedicine := false
  5246. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5247. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5248. if new_prescription.IsMedicine == 1 {
  5249. isMedicine = true
  5250. }
  5251. for _, item := range new_prescriptions {
  5252. if item.OrderStatus == 4 {
  5253. isCharge = true
  5254. }
  5255. }
  5256. if p_err != nil {
  5257. if new_prescription.ID > 0 {
  5258. if new_prescription.OrderStatus == 2 {
  5259. isCharge = true
  5260. }
  5261. }
  5262. }
  5263. for _, item := range advices {
  5264. if item.IsMedicine == 1 {
  5265. isMedicine = true
  5266. }
  5267. }
  5268. if isCharge {
  5269. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5270. return
  5271. }
  5272. if isMedicine {
  5273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5274. return
  5275. }
  5276. //已收费和已发药限制逻辑
  5277. if len(projects) > 0 {
  5278. for _, item := range projects {
  5279. service.DeletePrintInfo(item.ID) //删除打印信息
  5280. if goodOutConfig.IsOpen != 1 {
  5281. if stockConfig.IsOpen == 1 {
  5282. if item.Type == 3 && item.IsOut == 1 {
  5283. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5284. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5285. good.Total = good.Total + f_count
  5286. service.UpdateGoodInfo(&good)
  5287. operation_time := time.Now().Unix()
  5288. creater := c.GetAdminUserInfo().AdminUser.Id
  5289. //创建退库单
  5290. timeStr := time.Now().Format("2006-01-02")
  5291. timeArr := strings.Split(timeStr, "-")
  5292. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5293. total = total + 1
  5294. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5295. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5296. cancelStock := models.CancelStock{
  5297. OrderNumber: orderNumber,
  5298. OperaTime: operation_time,
  5299. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5300. Creater: creater,
  5301. Ctime: time.Now().Unix(),
  5302. Status: 1,
  5303. ReturnTime: item.RecordDate,
  5304. Type: 1,
  5305. StorehouseId: houseConfig.StorehouseOutInfo,
  5306. IsCheck: 1,
  5307. }
  5308. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5309. if msgerrkonde == gorm.ErrRecordNotFound {
  5310. service.AddSigleCancelStock(&cancelStock)
  5311. }
  5312. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5313. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5314. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5315. //查询该耗材是否出库
  5316. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5317. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5318. deaerler, _ := service.GetDealerById(info.Dealer)
  5319. var total_count int64
  5320. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5321. total_count += count
  5322. if info.ID > 0 {
  5323. if info.Count >= total_count {
  5324. //回退库存
  5325. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5326. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5327. var flush_count int64
  5328. for _, it := range goodList {
  5329. flush_count += it.StockCount
  5330. }
  5331. cancelStockInfo := models.CancelStockInfo{
  5332. GoodId: item.ProjectId,
  5333. CancelStockId: cancel.ID,
  5334. GoodTypeId: good.GoodTypeId,
  5335. Count: prescribingNumber,
  5336. Price: info.Price,
  5337. Total: 0,
  5338. ProductDate: info.ProductDate,
  5339. ExpiryDate: info.ExpiryDate,
  5340. Ctime: time.Now().Unix(),
  5341. Status: 1,
  5342. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5343. OrderNumber: cancel.OrderNumber,
  5344. Type: 0,
  5345. Dealer: deaerler.DealerName,
  5346. Manufacturer: manufacturer.ManufacturerName,
  5347. Number: info.Number,
  5348. RegisterAccount: "",
  5349. Remark: "",
  5350. WarehouseInfoId: info.WarehouseInfotId,
  5351. PatientId: info.PatientId,
  5352. RecordDate: info.SysRecordTime,
  5353. StorehouseId: houseConfig.StorehouseOutInfo,
  5354. IsCheck: 1,
  5355. }
  5356. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5357. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5358. flow := models.VmStockFlow{
  5359. WarehousingId: info.WarehouseInfotId,
  5360. GoodId: item.ProjectId,
  5361. Number: info.Number,
  5362. LicenseNumber: info.LicenseNumber,
  5363. Count: prescribingNumber,
  5364. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5365. PatientId: item.PatientId,
  5366. SystemTime: info.SysRecordTime,
  5367. ConsumableType: 7,
  5368. IsSys: 0,
  5369. WarehousingOrder: "",
  5370. WarehouseOutId: info.WarehouseOutId,
  5371. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5372. IsEdit: 0,
  5373. CancelStockId: cancel.ID,
  5374. CancelOrderNumber: cancel.OrderNumber,
  5375. Manufacturer: manufacturer.ID,
  5376. Dealer: 0,
  5377. Creator: c.GetAdminUserInfo().CurrentOrgId,
  5378. UpdateCreator: 0,
  5379. Status: 1,
  5380. Ctime: time.Now().Unix(),
  5381. Mtime: 0,
  5382. Price: info.Price,
  5383. WarehousingDetailId: info.WarehouseInfotId,
  5384. WarehouseOutDetailId: info.ID,
  5385. CancelOutDetailId: cancelInfo.ID,
  5386. ProductDate: info.ProductDate,
  5387. ExpireDate: info.ExpiryDate,
  5388. StorehouseId: houseConfig.StorehouseOutInfo,
  5389. OverCount: flush_count,
  5390. OperateTime: time.Now().Unix(),
  5391. }
  5392. service.CreateStockFlowOne(flow)
  5393. //退库数量增加
  5394. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  5395. //出库数量减少
  5396. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  5397. }
  5398. if info.Count < total_count {
  5399. //回退库存
  5400. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5401. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5402. var flush_count int64
  5403. for _, it := range goodList {
  5404. flush_count += it.StockCount
  5405. }
  5406. cancelStockInfo := models.CancelStockInfo{
  5407. GoodId: item.ProjectId,
  5408. CancelStockId: cancel.ID,
  5409. GoodTypeId: good.GoodTypeId,
  5410. Count: info.Count,
  5411. Price: info.Price,
  5412. Total: 0,
  5413. ProductDate: info.ProductDate,
  5414. ExpiryDate: info.ExpiryDate,
  5415. Ctime: time.Now().Unix(),
  5416. Status: 1,
  5417. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5418. OrderNumber: cancel.OrderNumber,
  5419. Type: 0,
  5420. Dealer: deaerler.DealerName,
  5421. Manufacturer: manufacturer.ManufacturerName,
  5422. Number: info.Number,
  5423. RegisterAccount: "",
  5424. Remark: "",
  5425. WarehouseInfoId: info.WarehouseInfotId,
  5426. PatientId: info.PatientId,
  5427. RecordDate: info.SysRecordTime,
  5428. StorehouseId: houseConfig.StorehouseOutInfo,
  5429. IsCheck: 1,
  5430. }
  5431. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5432. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5433. flow := models.VmStockFlow{
  5434. WarehousingId: info.WarehouseInfotId,
  5435. GoodId: item.ProjectId,
  5436. Number: info.Number,
  5437. LicenseNumber: info.LicenseNumber,
  5438. Count: info.Count,
  5439. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5440. PatientId: item.PatientId,
  5441. SystemTime: info.SysRecordTime,
  5442. ConsumableType: 7,
  5443. IsSys: 0,
  5444. WarehousingOrder: "",
  5445. WarehouseOutId: info.WarehouseOutId,
  5446. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5447. IsEdit: 0,
  5448. CancelStockId: cancel.ID,
  5449. CancelOrderNumber: cancel.OrderNumber,
  5450. Manufacturer: manufacturer.ID,
  5451. Dealer: 0,
  5452. Creator: c.GetAdminUserInfo().CurrentOrgId,
  5453. UpdateCreator: 0,
  5454. Status: 1,
  5455. Ctime: time.Now().Unix(),
  5456. Mtime: 0,
  5457. Price: info.Price,
  5458. WarehousingDetailId: info.WarehouseInfotId,
  5459. WarehouseOutDetailId: info.ID,
  5460. CancelOutDetailId: cancelInfo.ID,
  5461. ProductDate: info.ProductDate,
  5462. ExpireDate: info.ExpiryDate,
  5463. StorehouseId: houseConfig.StorehouseOutInfo,
  5464. OverCount: flush_count,
  5465. OperateTime: time.Now().Unix(),
  5466. }
  5467. service.CreateStockFlowOne(flow)
  5468. //退库数量增加
  5469. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  5470. //出库数量减少
  5471. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  5472. }
  5473. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5474. var flush_count int64
  5475. for _, it := range goodList {
  5476. flush_count += it.StockCount
  5477. }
  5478. //查询已出库数量
  5479. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  5480. if prescribingNumber < dialysisInfo.Count {
  5481. //改变数量
  5482. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  5483. }
  5484. if prescribingNumber >= dialysisInfo.Count {
  5485. //删除出库表
  5486. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  5487. }
  5488. //更新库存
  5489. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  5490. //更新基础库库存
  5491. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  5492. }
  5493. }
  5494. }
  5495. }
  5496. //保存耗材出库
  5497. if goodOutConfig.IsOpen == 1 {
  5498. if item.Type == 3 {
  5499. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5500. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5501. good.Total = good.Total + f_count
  5502. service.UpdateGoodInfo(&good)
  5503. operation_time := time.Now().Unix()
  5504. creater := c.GetAdminUserInfo().AdminUser.Id
  5505. //创建退库单
  5506. timeStr := time.Now().Format("2006-01-02")
  5507. timeArr := strings.Split(timeStr, "-")
  5508. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5509. total = total + 1
  5510. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5511. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5512. cancelStock := models.CancelStock{
  5513. OrderNumber: orderNumber,
  5514. OperaTime: operation_time,
  5515. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5516. Creater: creater,
  5517. Ctime: time.Now().Unix(),
  5518. Status: 1,
  5519. ReturnTime: item.RecordDate,
  5520. Type: 1,
  5521. StorehouseId: houseConfig.StorehouseOutInfo,
  5522. IsCheck: 1,
  5523. }
  5524. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5525. if msgerrkonde == gorm.ErrRecordNotFound {
  5526. service.AddSigleCancelStock(&cancelStock)
  5527. }
  5528. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5529. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5530. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5531. //查询该耗材是否出库
  5532. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5533. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5534. deaerler, _ := service.GetDealerById(info.Dealer)
  5535. var total_count int64
  5536. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5537. total_count += count
  5538. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5539. var flush_count int64
  5540. for _, it := range goodList {
  5541. flush_count += it.StockCount
  5542. }
  5543. fmt.Println("历史出库数据", info.Count)
  5544. fmt.Println("出库数量", total_count)
  5545. if info.ID > 0 {
  5546. cancelStockInfo := models.CancelStockInfo{
  5547. GoodId: item.ProjectId,
  5548. CancelStockId: cancel.ID,
  5549. GoodTypeId: good.GoodTypeId,
  5550. Count: prescribingNumber,
  5551. Price: info.Price,
  5552. Total: 0,
  5553. ProductDate: info.ProductDate,
  5554. ExpiryDate: info.ExpiryDate,
  5555. Ctime: time.Now().Unix(),
  5556. Status: 1,
  5557. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5558. OrderNumber: cancel.OrderNumber,
  5559. Type: 0,
  5560. Dealer: deaerler.DealerName,
  5561. Manufacturer: manufacturer.ManufacturerName,
  5562. Number: info.Number,
  5563. RegisterAccount: "",
  5564. Remark: "",
  5565. WarehouseInfoId: info.WarehouseInfotId,
  5566. PatientId: info.PatientId,
  5567. RecordDate: info.SysRecordTime,
  5568. StorehouseId: houseConfig.StorehouseOutInfo,
  5569. IsCheck: 1,
  5570. }
  5571. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5572. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5573. //查询出库数量
  5574. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  5575. //出库数据 大于 退库数量
  5576. if len(list) > 0 {
  5577. for _, it := range list {
  5578. //回退库存
  5579. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  5580. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5581. var flush_count_one int64
  5582. for _, it := range goodList {
  5583. flush_count_one += it.StockCount
  5584. }
  5585. //查询该批次是否有退库数据
  5586. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  5587. creater := c.GetAdminUserInfo().AdminUser.Id
  5588. flow := models.VmStockFlow{
  5589. WarehousingId: it.WarehouseInfotId,
  5590. GoodId: it.GoodId,
  5591. Number: it.Number,
  5592. LicenseNumber: it.LicenseNumber,
  5593. Count: it.Count,
  5594. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5595. PatientId: it.PatientId,
  5596. SystemTime: it.SysRecordTime,
  5597. ConsumableType: 7,
  5598. IsSys: 0,
  5599. WarehousingOrder: "",
  5600. WarehouseOutId: it.WarehouseOutId,
  5601. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  5602. IsEdit: 0,
  5603. CancelStockId: cancel.ID,
  5604. CancelOrderNumber: cancel.OrderNumber,
  5605. Manufacturer: manufacturer.ID,
  5606. Dealer: 0,
  5607. Creator: creater,
  5608. UpdateCreator: 0,
  5609. Status: 1,
  5610. Ctime: time.Now().Unix(),
  5611. Mtime: 0,
  5612. Price: it.Price,
  5613. WarehousingDetailId: it.WarehouseInfotId,
  5614. WarehouseOutDetailId: it.ID,
  5615. CancelOutDetailId: cancelInfo.ID,
  5616. ProductDate: it.ProductDate,
  5617. ExpireDate: it.ExpiryDate,
  5618. StorehouseId: houseConfig.StorehouseOutInfo,
  5619. OverCount: flush_count_one,
  5620. }
  5621. service.CreateStockFlowOne(flow)
  5622. //if flow.ID > 0 {
  5623. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  5624. //}
  5625. }
  5626. }
  5627. //flow := models.VmStockFlow{
  5628. // WarehousingId: info.WarehouseInfotId,
  5629. // GoodId: item.ProjectId,
  5630. // Number: info.Number,
  5631. // LicenseNumber: info.LicenseNumber,
  5632. // Count: prescribingNumber,
  5633. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5634. // PatientId: item.PatientId,
  5635. // SystemTime: info.SysRecordTime,
  5636. // ConsumableType: 7,
  5637. // IsSys: 0,
  5638. // WarehousingOrder: "",
  5639. // WarehouseOutId: info.WarehouseOutId,
  5640. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5641. // IsEdit: 0,
  5642. // CancelStockId: cancel.ID,
  5643. // CancelOrderNumber: cancel.OrderNumber,
  5644. // Manufacturer: manufacturer.ID,
  5645. // Dealer: 0,
  5646. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  5647. // UpdateCreator: 0,
  5648. // Status: 1,
  5649. // Ctime: time.Now().Unix(),
  5650. // Mtime: 0,
  5651. // Price: info.Price,
  5652. // WarehousingDetailId: info.WarehouseInfotId,
  5653. // WarehouseOutDetailId: info.ID,
  5654. // CancelOutDetailId: cancelInfo.ID,
  5655. // ProductDate: info.ProductDate,
  5656. // ExpireDate: info.ExpiryDate,
  5657. // StorehouseId: houseConfig.StorehouseOutInfo,
  5658. // OverCount: flush_count,
  5659. //}
  5660. //service.CreateStockFlowOne(flow)
  5661. //退库数量增加
  5662. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  5663. //出库数量减少
  5664. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  5665. //查询已出库数量
  5666. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  5667. if prescribingNumber < dialysisInfo.Count {
  5668. //改变数量
  5669. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  5670. }
  5671. if prescribingNumber >= dialysisInfo.Count {
  5672. //删除出库表
  5673. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  5674. }
  5675. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5676. var flush_count_one int64
  5677. for _, it := range goodList {
  5678. flush_count_one += it.StockCount
  5679. }
  5680. //更新库存
  5681. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  5682. fmt.Println("msgerrkonde23332323", msgerrkonde)
  5683. //更新基础库库存
  5684. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  5685. }
  5686. }
  5687. }
  5688. }
  5689. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5690. fmt.Println(err)
  5691. }
  5692. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5693. fmt.Println(err)
  5694. if len(advices) > 0 {
  5695. for _, item := range advices {
  5696. redis := service.RedisClient()
  5697. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5698. redis.Set(keyFive, "", time.Second)
  5699. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5700. redis.Set(keyOne, "", time.Second)
  5701. redis.Close()
  5702. }
  5703. }
  5704. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5705. if len(advices) > 0 {
  5706. for _, item := range advices {
  5707. creater := c.GetAdminUserInfo().AdminUser.Id
  5708. service.DrugAutoAddCancelInfo(item, creater)
  5709. }
  5710. }
  5711. } else {
  5712. if drugOutConfig.IsOpen == 1 {
  5713. if len(advices) > 0 {
  5714. for _, item := range advices {
  5715. creater := c.GetAdminUserInfo().AdminUser.Id
  5716. service.DrugAutoAddCancelInfo(item, creater)
  5717. }
  5718. }
  5719. } else {
  5720. if len(advices) > 0 {
  5721. for _, item := range advices {
  5722. creater := c.GetAdminUserInfo().AdminUser.Id
  5723. service.DrugAutoAddCancelInfo(item, creater)
  5724. }
  5725. }
  5726. }
  5727. }
  5728. c.ServeSuccessJSON(map[string]interface{}{
  5729. "msg": "删除成功",
  5730. })
  5731. return
  5732. }
  5733. func (c *HisApiController) DeleteDoctorAdvice() {
  5734. id, _ := c.GetInt64("id")
  5735. advice, _ := service.GetHisDoctorAdvicesById(id)
  5736. ////同步到自备药
  5737. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  5738. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  5739. if selfPrescriptionOpen.IsOpen == 1 {
  5740. db := service.XTWriteDB()
  5741. tx := db.Begin()
  5742. defer func() {
  5743. if r := recover(); r != nil {
  5744. tx.Rollback()
  5745. } else {
  5746. tx.Commit()
  5747. }
  5748. }()
  5749. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  5750. var total_count int64
  5751. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  5752. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5753. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5754. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5755. }
  5756. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5757. total_count += prescribingNumberSeven
  5758. }
  5759. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5760. total_count += prescribingNumberSeven
  5761. }
  5762. timeStr := time.Now().Format("2006-01-02")
  5763. timeArr := strings.Split(timeStr, "-")
  5764. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5765. total = total + 1
  5766. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5767. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5768. number = number + total
  5769. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5770. operation_time := time.Now().Unix()
  5771. creater := c.GetAdminUserInfo().AdminUser.Id
  5772. //创建一个出库单
  5773. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5774. WarehouseOutOrderNumber: warehousing_out_order,
  5775. OperationTime: operation_time,
  5776. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5777. Creater: creater,
  5778. Ctime: time.Now().Unix(),
  5779. Status: 1,
  5780. WarehouseOutTime: advice.AdviceDate,
  5781. Type: 0,
  5782. PatientId: advice.PatientId,
  5783. IsCheck: 1,
  5784. }
  5785. //查询今日是否有出库数据
  5786. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  5787. if lastWarehouseOut.ID == 0 {
  5788. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5789. }
  5790. //出库
  5791. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5792. WarehouseOutId: lastWarehouseOut.ID,
  5793. WarehouseOutOrderNumber: warehousing_out_order,
  5794. DrugId: advice.DrugId,
  5795. Count: total_count,
  5796. Price: 0,
  5797. TotalPrice: 0,
  5798. Status: 1,
  5799. Ctime: advice.AdviceDate,
  5800. Mtime: advice.AdviceDate,
  5801. Remark: "",
  5802. OrgId: advice.UserOrgId,
  5803. Type: 0,
  5804. Manufacturer: selfBasedrug.Manufacturer,
  5805. Dealer: selfBasedrug.Dealer,
  5806. RetailPrice: 0,
  5807. RetailTotalPrice: 0,
  5808. CountUnit: advice.PrescribingNumberUnit,
  5809. ExpiryDate: 0,
  5810. ProductDate: 0,
  5811. Number: "",
  5812. BatchNumber: "",
  5813. IsSys: 0,
  5814. WarehouseInfoId: 0,
  5815. AdminUserId: 0,
  5816. StockCount: "",
  5817. IsCheck: 1,
  5818. SysRecordTime: advice.AdviceDate,
  5819. PatientId: advice.PatientId,
  5820. AdviceId: advice.ID,
  5821. ClassType: "",
  5822. }
  5823. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5824. for _, it := range warehousingOutInfo {
  5825. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5826. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5827. //出库逻辑
  5828. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  5829. //查询剩余库存
  5830. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5831. var sum_count int64
  5832. for _, its := range stockInfo {
  5833. if its.MaxUnit == medical.MaxUnit {
  5834. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5835. }
  5836. sum_count += its.StockMaxNumber + its.StockMinNumber
  5837. }
  5838. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5839. }
  5840. }
  5841. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5842. //已收费和已发药的限制逻辑
  5843. isCharge := false
  5844. isMedicine := false
  5845. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5846. //获取今天该患者所有处方,判断是否发药或者收费
  5847. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5848. //for _, item := range new_prescriptions {
  5849. if new_prescription.IsMedicine == 1 {
  5850. isMedicine = true
  5851. }
  5852. //}
  5853. for _, item := range new_prescriptions {
  5854. if item.OrderStatus == 4 {
  5855. isCharge = true
  5856. }
  5857. }
  5858. if isMedicine {
  5859. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5860. return
  5861. }
  5862. if isCharge {
  5863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5864. return
  5865. }
  5866. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  5867. for _, item := range advices {
  5868. if item.IsMedicine == 1 {
  5869. isMedicine = true
  5870. }
  5871. }
  5872. if isMedicine {
  5873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  5874. return
  5875. }
  5876. if new_prescription.ID > 0 {
  5877. if new_prescription.OrderStatus == 2 {
  5878. isCharge = true
  5879. }
  5880. }
  5881. if isCharge {
  5882. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5883. return
  5884. }
  5885. //已收费和已发药的限制逻辑
  5886. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  5887. redis := service.RedisClient()
  5888. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  5889. redis.Set(keyFive, "", time.Second)
  5890. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  5891. redis.Set(keyOne, "", time.Second)
  5892. defer redis.Close()
  5893. if err == nil {
  5894. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5895. //查询是否在处方中出库
  5896. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5897. if openConfig.IsOpen != 1 {
  5898. //判断该医嘱是否执行了
  5899. if advice.ExecutionState == 1 {
  5900. creater := c.GetAdminUserInfo().AdminUser.Id
  5901. service.DrugAutoAddCancelInfo(&advice, creater)
  5902. }
  5903. }
  5904. //开启保存处方扣减功能
  5905. if openConfig.IsOpen == 1 {
  5906. creater := c.GetAdminUserInfo().AdminUser.Id
  5907. service.DrugAutoAddCancelInfo(&advice, creater)
  5908. }
  5909. } else {
  5910. if drugOutConfig.IsOpen == 1 {
  5911. //查询是否在处方中出库
  5912. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5913. if openConfig.IsOpen != 1 {
  5914. //判断该医嘱是否执行了
  5915. if advice.ExecutionState == 1 {
  5916. creater := c.GetAdminUserInfo().AdminUser.Id
  5917. service.DrugAutoAddCancelInfo(&advice, creater)
  5918. }
  5919. }
  5920. //开启保存处方扣减功能
  5921. if openConfig.IsOpen == 1 {
  5922. creater := c.GetAdminUserInfo().AdminUser.Id
  5923. service.DrugAutoAddCancelInfo(&advice, creater)
  5924. }
  5925. } else {
  5926. //判断该医嘱是否执行了
  5927. if advice.ExecutionState == 1 {
  5928. creater := c.GetAdminUserInfo().AdminUser.Id
  5929. service.DrugAutoAddCancelInfo(&advice, creater)
  5930. }
  5931. }
  5932. }
  5933. c.ServeSuccessJSON(map[string]interface{}{
  5934. "msg": "删除成功",
  5935. })
  5936. return
  5937. } else {
  5938. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5939. return
  5940. }
  5941. }
  5942. func (c *HisApiController) DeleteProject() {
  5943. id, _ := c.GetInt64("id")
  5944. adminInfo := c.GetAdminUserInfo()
  5945. project, _ := service.GetHisProjectByID(id)
  5946. // var consumable models.DialysisBeforePrepare
  5947. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5948. //耗材保存处方出库
  5949. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5950. isCharge := false
  5951. isMedicine := false
  5952. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5953. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5954. for _, item := range new_prescriptions {
  5955. if item.IsMedicine == 1 {
  5956. isMedicine = true
  5957. }
  5958. }
  5959. for _, item := range new_prescriptions {
  5960. if item.OrderStatus == 4 {
  5961. isCharge = true
  5962. }
  5963. }
  5964. if isMedicine {
  5965. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5966. return
  5967. }
  5968. if isCharge {
  5969. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5970. return
  5971. }
  5972. if new_prescription.ID > 0 {
  5973. if new_prescription.OrderStatus == 2 {
  5974. isCharge = true
  5975. }
  5976. }
  5977. if isCharge {
  5978. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5979. return
  5980. }
  5981. service.DeletePrintInfo(id)
  5982. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  5983. label.Status = 0
  5984. service.CreateHisLabelRecordTwo(&label)
  5985. fmt.Println(goodOutConfig.IsOpen)
  5986. if goodOutConfig.IsOpen != 1 {
  5987. if stockConfig.IsOpen == 1 {
  5988. if project.Type == 2 {
  5989. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5990. fmt.Println(err)
  5991. }
  5992. if project.Type == 3 && project.IsOut == 1 {
  5993. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5994. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5995. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5996. operation_time := time.Now().Unix()
  5997. creater := adminInfo.AdminUser.Id
  5998. //创建退库单
  5999. timeStr := time.Now().Format("2006-01-02")
  6000. timeArr := strings.Split(timeStr, "-")
  6001. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6002. total = total + 1
  6003. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6004. cancelStock := models.CancelStock{
  6005. OrderNumber: orderNumber,
  6006. OperaTime: operation_time,
  6007. OrgId: adminInfo.CurrentOrgId,
  6008. Creater: creater,
  6009. Ctime: time.Now().Unix(),
  6010. Status: 1,
  6011. ReturnTime: project.RecordDate,
  6012. Type: 1,
  6013. StorehouseId: houseConfig.StorehouseOutInfo,
  6014. IsCheck: 1,
  6015. }
  6016. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6017. if msgerrkonde == gorm.ErrRecordNotFound {
  6018. service.AddSigleCancelStock(&cancelStock)
  6019. }
  6020. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6021. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6022. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6023. //查询是否有出库
  6024. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6025. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6026. deaerler, _ := service.GetDealerById(info.Dealer)
  6027. if info.ID > 0 {
  6028. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6029. if info.Count >= prescribingNumber {
  6030. cancelStockInfo := models.CancelStockInfo{
  6031. GoodId: project.ProjectId,
  6032. CancelStockId: cancel.ID,
  6033. GoodTypeId: good.GoodTypeId,
  6034. Count: prescribingNumber,
  6035. Price: info.Price,
  6036. Total: 0,
  6037. ProductDate: info.ProductDate,
  6038. ExpiryDate: info.ExpiryDate,
  6039. Ctime: time.Now().Unix(),
  6040. Status: 1,
  6041. OrgId: adminInfo.CurrentOrgId,
  6042. OrderNumber: cancel.OrderNumber,
  6043. Type: 0,
  6044. Dealer: deaerler.DealerName,
  6045. Manufacturer: manufacturer.ManufacturerName,
  6046. Number: info.Number,
  6047. RegisterAccount: "",
  6048. Remark: "",
  6049. WarehouseInfoId: info.WarehouseInfotId,
  6050. PatientId: info.PatientId,
  6051. RecordDate: info.SysRecordTime,
  6052. StorehouseId: houseConfig.StorehouseOutInfo,
  6053. IsCheck: 1,
  6054. }
  6055. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6056. //回退库存
  6057. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  6058. //退库数量增加
  6059. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6060. //出库数量减少
  6061. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6062. }
  6063. if info.Count < prescribingNumber {
  6064. cancelStockInfo := models.CancelStockInfo{
  6065. GoodId: project.ProjectId,
  6066. CancelStockId: cancel.ID,
  6067. GoodTypeId: good.GoodTypeId,
  6068. Count: info.Count,
  6069. Price: info.Price,
  6070. Total: 0,
  6071. ProductDate: info.ProductDate,
  6072. ExpiryDate: info.ExpiryDate,
  6073. Ctime: time.Now().Unix(),
  6074. Status: 1,
  6075. OrgId: adminInfo.CurrentOrgId,
  6076. OrderNumber: cancel.OrderNumber,
  6077. Type: 0,
  6078. Dealer: deaerler.DealerName,
  6079. Manufacturer: manufacturer.ManufacturerName,
  6080. Number: info.Number,
  6081. RegisterAccount: "",
  6082. Remark: "",
  6083. WarehouseInfoId: info.WarehouseInfotId,
  6084. PatientId: info.PatientId,
  6085. RecordDate: info.SysRecordTime,
  6086. StorehouseId: houseConfig.StorehouseOutInfo,
  6087. IsCheck: 1,
  6088. }
  6089. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6090. //回退库存
  6091. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6092. //退库数量增加
  6093. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6094. //出库数量减少
  6095. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  6096. }
  6097. //查询剩余库存
  6098. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6099. var over_count int64
  6100. for _, it := range goodList {
  6101. over_count += it.StockCount
  6102. }
  6103. //出库数据 大于 退库数量
  6104. if info.Count >= prescribingNumber {
  6105. flow := models.VmStockFlow{
  6106. WarehousingId: info.WarehouseInfotId,
  6107. GoodId: project.ProjectId,
  6108. Number: info.Number,
  6109. LicenseNumber: info.LicenseNumber,
  6110. Count: prescribingNumber,
  6111. UserOrgId: adminInfo.CurrentOrgId,
  6112. PatientId: project.PatientId,
  6113. SystemTime: info.SysRecordTime,
  6114. ConsumableType: 7,
  6115. IsSys: 0,
  6116. WarehousingOrder: "",
  6117. WarehouseOutId: info.WarehouseOutId,
  6118. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6119. IsEdit: 0,
  6120. CancelStockId: cancel.ID,
  6121. CancelOrderNumber: cancel.OrderNumber,
  6122. Manufacturer: manufacturer.ID,
  6123. Dealer: 0,
  6124. Creator: adminInfo.AdminUser.Id,
  6125. UpdateCreator: 0,
  6126. Status: 1,
  6127. Ctime: time.Now().Unix(),
  6128. Mtime: 0,
  6129. Price: info.Price,
  6130. WarehousingDetailId: info.WarehouseInfotId,
  6131. WarehouseOutDetailId: info.ID,
  6132. CancelOutDetailId: cancelInfo.ID,
  6133. ProductDate: info.ProductDate,
  6134. ExpireDate: info.ExpiryDate,
  6135. StorehouseId: houseConfig.StorehouseOutInfo,
  6136. OverCount: over_count,
  6137. OperateTime: time.Now().Unix(),
  6138. }
  6139. service.CreateStockFlowOne(flow)
  6140. }
  6141. //出库数据小于退库数据
  6142. if info.Count < prescribingNumber {
  6143. flow := models.VmStockFlow{
  6144. WarehousingId: info.WarehouseInfotId,
  6145. GoodId: project.ProjectId,
  6146. Number: info.Number,
  6147. LicenseNumber: info.LicenseNumber,
  6148. Count: info.Count,
  6149. UserOrgId: adminInfo.CurrentOrgId,
  6150. PatientId: project.PatientId,
  6151. SystemTime: info.SysRecordTime,
  6152. ConsumableType: 7,
  6153. IsSys: 0,
  6154. WarehousingOrder: "",
  6155. WarehouseOutId: info.WarehouseOutId,
  6156. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6157. IsEdit: 0,
  6158. CancelStockId: cancel.ID,
  6159. CancelOrderNumber: cancel.OrderNumber,
  6160. Manufacturer: manufacturer.ID,
  6161. Dealer: 0,
  6162. Creator: adminInfo.AdminUser.Id,
  6163. UpdateCreator: 0,
  6164. Status: 1,
  6165. Ctime: time.Now().Unix(),
  6166. Mtime: 0,
  6167. Price: info.Price,
  6168. WarehousingDetailId: info.WarehouseInfotId,
  6169. WarehouseOutDetailId: info.ID,
  6170. CancelOutDetailId: cancelInfo.ID,
  6171. ProductDate: info.ProductDate,
  6172. ExpireDate: info.ExpiryDate,
  6173. StorehouseId: houseConfig.StorehouseOutInfo,
  6174. OverCount: over_count,
  6175. OperateTime: time.Now().Unix(),
  6176. }
  6177. service.CreateStockFlowOne(flow)
  6178. }
  6179. //查询已出库数量
  6180. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6181. //fmt.Println("aiwohonguo --------------------", prescribingNumber)
  6182. //fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  6183. if prescribingNumber < dialysisInfo.Count {
  6184. //改变数量
  6185. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6186. }
  6187. if prescribingNumber >= dialysisInfo.Count {
  6188. //删除出库表
  6189. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6190. }
  6191. //更新剩余库存
  6192. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6193. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6194. var total_count_one int64
  6195. for _, it := range stockList {
  6196. total_count_one += it.StockCount
  6197. }
  6198. //基础库插入数据
  6199. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6200. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6201. var flush_count int64
  6202. for _, it := range goodListOne {
  6203. flush_count += it.StockCount
  6204. }
  6205. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6206. if errs != nil {
  6207. goodErrcode := models.XtGoodErrcode{
  6208. UserOrgId: project.UserOrgId,
  6209. Errcode: "手动出库更新剩余出库失败",
  6210. GoodId: project.ProjectId,
  6211. Status: 1,
  6212. Ctime: time.Now().Unix(),
  6213. Mtime: 0,
  6214. Count: 0,
  6215. StockCount: 0,
  6216. Creater: creater,
  6217. BatchNumberId: 0,
  6218. WarehouseOutId: 0,
  6219. }
  6220. service.CreateGoodErrcode(goodErrcode)
  6221. }
  6222. }
  6223. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6224. fmt.Println(err)
  6225. } else {
  6226. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6227. fmt.Println(err)
  6228. }
  6229. } else {
  6230. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6231. fmt.Println(err)
  6232. }
  6233. }
  6234. //保存处方出库
  6235. if goodOutConfig.IsOpen == 1 {
  6236. if project.Type == 3 {
  6237. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6238. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6239. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6240. operation_time := time.Now().Unix()
  6241. creater := adminInfo.AdminUser.Id
  6242. //创建退库单
  6243. timeStr := time.Now().Format("2006-01-02")
  6244. timeArr := strings.Split(timeStr, "-")
  6245. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6246. total = total + 1
  6247. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6248. cancelStock := models.CancelStock{
  6249. OrderNumber: orderNumber,
  6250. OperaTime: operation_time,
  6251. OrgId: adminInfo.CurrentOrgId,
  6252. Creater: creater,
  6253. Ctime: time.Now().Unix(),
  6254. Status: 1,
  6255. ReturnTime: project.RecordDate,
  6256. Type: 1,
  6257. StorehouseId: houseConfig.StorehouseOutInfo,
  6258. IsCheck: 1,
  6259. }
  6260. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6261. if msgerrkonde == gorm.ErrRecordNotFound {
  6262. service.AddSigleCancelStock(&cancelStock)
  6263. }
  6264. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6265. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6266. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6267. //获取出库数据
  6268. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6269. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6270. deaerler, _ := service.GetDealerById(info.Dealer)
  6271. if info.ID > 0 {
  6272. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6273. if info.Count >= prescribingNumber {
  6274. cancelStockInfo := models.CancelStockInfo{
  6275. GoodId: project.ProjectId,
  6276. CancelStockId: cancel.ID,
  6277. GoodTypeId: good.GoodTypeId,
  6278. Count: prescribingNumber,
  6279. Price: info.Price,
  6280. Total: 0,
  6281. ProductDate: info.ProductDate,
  6282. ExpiryDate: info.ExpiryDate,
  6283. Ctime: time.Now().Unix(),
  6284. Status: 1,
  6285. OrgId: adminInfo.CurrentOrgId,
  6286. OrderNumber: cancel.OrderNumber,
  6287. Type: 0,
  6288. Dealer: deaerler.DealerName,
  6289. Manufacturer: manufacturer.ManufacturerName,
  6290. Number: info.Number,
  6291. RegisterAccount: "",
  6292. Remark: "",
  6293. WarehouseInfoId: info.WarehouseInfotId,
  6294. PatientId: info.PatientId,
  6295. RecordDate: info.SysRecordTime,
  6296. StorehouseId: houseConfig.StorehouseOutInfo,
  6297. IsCheck: 1,
  6298. }
  6299. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6300. //退库数量增加
  6301. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6302. //出库数量减少
  6303. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6304. }
  6305. if info.Count < prescribingNumber {
  6306. cancelStockInfo := models.CancelStockInfo{
  6307. GoodId: project.ProjectId,
  6308. CancelStockId: cancel.ID,
  6309. GoodTypeId: good.GoodTypeId,
  6310. Count: prescribingNumber,
  6311. Price: info.Price,
  6312. Total: 0,
  6313. ProductDate: info.ProductDate,
  6314. ExpiryDate: info.ExpiryDate,
  6315. Ctime: time.Now().Unix(),
  6316. Status: 1,
  6317. OrgId: adminInfo.CurrentOrgId,
  6318. OrderNumber: cancel.OrderNumber,
  6319. Type: 0,
  6320. Dealer: deaerler.DealerName,
  6321. Manufacturer: manufacturer.ManufacturerName,
  6322. Number: info.Number,
  6323. RegisterAccount: "",
  6324. Remark: "",
  6325. WarehouseInfoId: info.WarehouseInfotId,
  6326. PatientId: info.PatientId,
  6327. RecordDate: info.SysRecordTime,
  6328. StorehouseId: houseConfig.StorehouseOutInfo,
  6329. IsCheck: 1,
  6330. }
  6331. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6332. //回退库存
  6333. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6334. }
  6335. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6336. var over_count int64
  6337. for _, it := range goodList {
  6338. over_count += it.StockCount
  6339. }
  6340. //查询出库数量
  6341. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  6342. //出库数据 大于 退库数量
  6343. if len(list) > 0 {
  6344. for _, it := range list {
  6345. //回退库存
  6346. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6347. //退库数量增加
  6348. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  6349. //出库数量减少
  6350. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  6351. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6352. var over_count_one int64
  6353. for _, it := range goodList {
  6354. over_count_one += it.StockCount
  6355. }
  6356. //查询该批次是否有退库数据
  6357. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  6358. flow := models.VmStockFlow{
  6359. WarehousingId: it.WarehouseInfotId,
  6360. GoodId: it.GoodId,
  6361. Number: it.Number,
  6362. LicenseNumber: it.LicenseNumber,
  6363. Count: it.Count,
  6364. UserOrgId: adminInfo.CurrentOrgId,
  6365. PatientId: it.PatientId,
  6366. SystemTime: it.SysRecordTime,
  6367. ConsumableType: 7,
  6368. IsSys: 0,
  6369. WarehousingOrder: "",
  6370. WarehouseOutId: it.WarehouseOutId,
  6371. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6372. IsEdit: 0,
  6373. CancelStockId: cancel.ID,
  6374. CancelOrderNumber: cancel.OrderNumber,
  6375. Manufacturer: manufacturer.ID,
  6376. Dealer: 0,
  6377. Creator: adminInfo.AdminUser.Id,
  6378. UpdateCreator: 0,
  6379. Status: 1,
  6380. Ctime: time.Now().Unix(),
  6381. Mtime: 0,
  6382. Price: it.Price,
  6383. WarehousingDetailId: it.WarehouseInfotId,
  6384. WarehouseOutDetailId: it.ID,
  6385. CancelOutDetailId: cancelInfo.ID,
  6386. ProductDate: it.ProductDate,
  6387. ExpireDate: it.ExpiryDate,
  6388. StorehouseId: houseConfig.StorehouseOutInfo,
  6389. OverCount: over_count_one,
  6390. OperateTime: time.Now().Unix(),
  6391. }
  6392. service.CreateStockFlowOne(flow)
  6393. }
  6394. }
  6395. //查询已出库数量
  6396. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6397. if prescribingNumber < dialysisInfo.Count {
  6398. //改变数量
  6399. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6400. }
  6401. if prescribingNumber >= dialysisInfo.Count {
  6402. //删除出库表
  6403. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6404. }
  6405. //更新剩余库存
  6406. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6407. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6408. var total_count_one int64
  6409. for _, it := range stockList {
  6410. total_count_one += it.StockCount
  6411. }
  6412. //基础库插入数据
  6413. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6414. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6415. var flush_count int64
  6416. for _, it := range goodListOne {
  6417. flush_count += it.StockCount
  6418. }
  6419. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6420. if errs != nil {
  6421. goodErrcode := models.XtGoodErrcode{
  6422. UserOrgId: project.UserOrgId,
  6423. Errcode: "手动出库更新剩余出库失败",
  6424. GoodId: project.ProjectId,
  6425. Status: 1,
  6426. Ctime: time.Now().Unix(),
  6427. Mtime: 0,
  6428. Count: 0,
  6429. StockCount: 0,
  6430. Creater: creater,
  6431. BatchNumberId: 0,
  6432. WarehouseOutId: 0,
  6433. }
  6434. service.CreateGoodErrcode(goodErrcode)
  6435. }
  6436. }
  6437. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6438. fmt.Println(err)
  6439. } else {
  6440. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6441. fmt.Println(err)
  6442. }
  6443. }
  6444. c.ServeSuccessJSON(map[string]interface{}{
  6445. "msg": "删除成功",
  6446. })
  6447. return
  6448. }
  6449. func (c *HisApiController) CreateHisAdditionalCharge() {
  6450. his_patient_id, _ := c.GetInt64("his_patient_id")
  6451. patient_id, _ := c.GetInt64("patient_id")
  6452. record_date := c.GetString("record_date")
  6453. timeLayout := "2006-01-02"
  6454. loc, _ := time.LoadLocation("Local")
  6455. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6456. if err != nil {
  6457. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6458. return
  6459. }
  6460. adminInfo := c.GetAdminUserInfo()
  6461. recordDateTime := theTime.Unix()
  6462. dataBody := make(map[string]interface{}, 0)
  6463. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6464. if err != nil {
  6465. utils.ErrorLog(err.Error())
  6466. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6467. return
  6468. }
  6469. var additions []*models.HisAdditionalCharge
  6470. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  6471. additions, _ := dataBody["addition"].([]interface{})
  6472. if len(additions) > 0 {
  6473. for _, item := range additions {
  6474. items := item.(map[string]interface{})
  6475. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  6476. utils.ErrorLog("item_id")
  6477. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6478. return
  6479. }
  6480. item_id := int64(items["item_id"].(float64))
  6481. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  6482. utils.ErrorLog("item_name")
  6483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6484. return
  6485. }
  6486. item_name := items["item_name"].(string)
  6487. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  6488. utils.ErrorLog("price")
  6489. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6490. return
  6491. }
  6492. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  6493. ctime := time.Now().Unix()
  6494. additional := &models.HisAdditionalCharge{
  6495. PatientId: patient_id,
  6496. HisPatientId: his_patient_id,
  6497. UserOrgId: adminInfo.CurrentOrgId,
  6498. RecordDate: recordDateTime,
  6499. CreatedTime: ctime,
  6500. UpdatedTime: ctime,
  6501. Modifier: adminInfo.AdminUser.Id,
  6502. Creator: adminInfo.AdminUser.Id,
  6503. Price: price,
  6504. ItemName: item_name,
  6505. ItemId: item_id,
  6506. Status: 1,
  6507. }
  6508. additions = append(additions, additional)
  6509. }
  6510. }
  6511. }
  6512. for _, item := range additions {
  6513. service.CreateAddtionalCharge(item)
  6514. }
  6515. c.ServeSuccessJSON(map[string]interface{}{
  6516. "msg": "创建成功",
  6517. })
  6518. }
  6519. func (c *HisApiController) CreateHisPatientCaseHistory() {
  6520. blood_fat := c.GetString("blood_fat")
  6521. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  6522. blood_sugar := c.GetString("blood_sugar")
  6523. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  6524. chief_conplaint := c.GetString("chief_conplaint")
  6525. dbp := c.GetString("dbp")
  6526. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  6527. delivery_way, _ := c.GetInt64("delivery_way")
  6528. diagnostic := c.GetString("diagnostic")
  6529. family_history := c.GetString("family_history")
  6530. height := c.GetString("height")
  6531. history_of_present_illness := c.GetString("history_of_present_illness")
  6532. is_infect, _ := c.GetInt64("is_infect")
  6533. past_history := c.GetString("past_history")
  6534. patient_id, _ := c.GetInt64("patient_id")
  6535. his_patient_id, _ := c.GetInt64("his_patient_id")
  6536. personal_history := c.GetString("personal_history")
  6537. pulse := c.GetString("pulse")
  6538. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  6539. sbp := c.GetString("sbp")
  6540. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  6541. heightfloat, _ := strconv.ParseFloat(height, 64)
  6542. sicktype := c.GetString("sick_type")
  6543. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  6544. symptom := c.GetString("symptom")
  6545. sick_date := c.GetString("sick_date")
  6546. temperatures := c.GetString("temperature")
  6547. temperature, _ := strconv.ParseFloat(temperatures, 64)
  6548. record_date := c.GetString("record_date")
  6549. breathing := c.GetString("breathing")
  6550. doctor_advice := c.GetString("doctor_advice")
  6551. remark := c.GetString("remark")
  6552. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  6553. sick, _ := c.GetInt64("sick")
  6554. diagnose, _ := c.GetInt64("diagnose")
  6555. //id, _ := c.GetInt64("id")
  6556. timeLayout := "2006-01-02"
  6557. loc, _ := time.LoadLocation("Local")
  6558. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6559. allergic_history := c.GetString("allergic_history")
  6560. if err != nil {
  6561. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6562. return
  6563. }
  6564. recordDateTime := theTime.Unix()
  6565. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  6566. if err != nil {
  6567. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6568. return
  6569. }
  6570. sickTimes := sickTime.Unix()
  6571. ctime := time.Now().Unix()
  6572. primary_disease := c.GetString("primary_disease")
  6573. confirm_failure_date := c.GetString("confirm_failure_date")
  6574. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  6575. drug_allergy_history := c.GetString("drug_allergy_history")
  6576. physical_examination := c.GetString("physical_examination")
  6577. special_inspection := c.GetString("special_inspection")
  6578. lab_apparatus := c.GetString("lab_apparatus")
  6579. caseHistory := models.HisPatientCaseHistory{
  6580. HisPatientId: his_patient_id,
  6581. PatientId: patient_id,
  6582. Temperature: temperature,
  6583. BloodSugar: bloodsugarfloat,
  6584. Pulse: pulsefloat,
  6585. Sbp: sbpfloat,
  6586. Dbp: dbpfloat,
  6587. Height: heightfloat,
  6588. BloodFat: bloodfatfloat,
  6589. SickType: sick_type,
  6590. Symptom: symptom,
  6591. SickDate: sickTimes,
  6592. IsInfect: is_infect,
  6593. HistoryOfPresentIllness: history_of_present_illness,
  6594. PastHistory: past_history,
  6595. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  6596. ChiefConplaint: chief_conplaint,
  6597. PersonalHistory: personal_history,
  6598. FamilyHistory: family_history,
  6599. Diagnostic: diagnostic,
  6600. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6601. Status: 1,
  6602. Ctime: ctime,
  6603. Mtime: ctime,
  6604. RecordDate: recordDateTime,
  6605. DeliveryWay: delivery_way,
  6606. Breathing: breathingfloat,
  6607. DoctorAdvice: doctor_advice,
  6608. Remark: remark,
  6609. Sick: sick,
  6610. Diagnose: diagnose,
  6611. AllergicHistory: allergic_history,
  6612. PrimaryDisease: primary_disease,
  6613. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  6614. DrugAllergyHistory: drug_allergy_history,
  6615. PhysicalExamination: physical_examination,
  6616. SpecialInspection: special_inspection,
  6617. LabApparatus: lab_apparatus,
  6618. }
  6619. //查询该患者是否有病历
  6620. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  6621. if errcodes == gorm.ErrRecordNotFound {
  6622. err = service.SaveHisPatientCaseHistory(&caseHistory)
  6623. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  6624. if err != nil {
  6625. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6626. return
  6627. }
  6628. c.ServeSuccessJSON(map[string]interface{}{
  6629. "caseHistory": caseHistory,
  6630. "historyInfo": historyInfo,
  6631. })
  6632. return
  6633. } else if errcodes == nil {
  6634. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  6635. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  6636. if err != nil {
  6637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6638. return
  6639. }
  6640. c.ServeSuccessJSON(map[string]interface{}{
  6641. "caseHistory": caseHistory,
  6642. "historyInfo": historyInfo,
  6643. })
  6644. }
  6645. //查询该患者是否有病历
  6646. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  6647. //if errcode == gorm.ErrRecordNotFound {
  6648. // err = service.SaveHisPatientCaseHistory(caseHistory)
  6649. // if err != nil {
  6650. // c.ServeSuccessJSON(map[string]interface{}{
  6651. // "msg": "保存成功",
  6652. // })
  6653. // }
  6654. //} else if errcode == nil {
  6655. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6656. // return
  6657. //}
  6658. }
  6659. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  6660. patient_id, _ := c.GetInt64("patient_id", 0)
  6661. adminUser := c.GetAdminUserInfo()
  6662. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  6663. c.ServeSuccessJSON(map[string]interface{}{
  6664. "list": caseHistorys,
  6665. })
  6666. }
  6667. func (c *HisApiController) GetHisPatientCaseHistory() {
  6668. record_date, _ := c.GetInt64("record_date", 0)
  6669. patient_id, _ := c.GetInt64("patient_id", 0)
  6670. admin := c.GetAdminUserInfo()
  6671. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  6672. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  6673. c.ServeSuccessJSON(map[string]interface{}{
  6674. "info": info,
  6675. "case_history": case_history,
  6676. })
  6677. }
  6678. func (c *HisApiController) CreateCaseHistoryTemplate() {
  6679. template_name := c.GetString("template_name")
  6680. template_remark := c.GetString("template_remark")
  6681. doctor := c.GetAdminUserInfo().AdminUser.Id
  6682. diagnostic := c.GetString("diagnostic")
  6683. chief_conplaint := c.GetString("chief_conplain")
  6684. history_of_present_illness := c.GetString("history_of_present_illness")
  6685. past_history := c.GetString("past_history")
  6686. personal_history := c.GetString("personal_history")
  6687. family_history := c.GetString("family_history")
  6688. user_name := c.GetString("user_name")
  6689. doctor_advice := c.GetString("doctor_advice")
  6690. remark := c.GetString("remark")
  6691. //record_date := c.GetString("record_date")
  6692. //fmt.Println("record_date--------",record_date)
  6693. //timeLayout := "2006-01-02"
  6694. //loc, _ := time.LoadLocation("Local")
  6695. //
  6696. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6697. //if err != nil {
  6698. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6699. // return
  6700. //}
  6701. //recordDateTime := theTime.Unix()
  6702. ctime := time.Now().Unix()
  6703. template := models.HisCaseHistoryTemplate{
  6704. HistoryOfPresentIllness: history_of_present_illness,
  6705. PastHistory: past_history,
  6706. ChiefConplaint: chief_conplaint,
  6707. PersonalHistory: personal_history,
  6708. FamilyHistory: family_history,
  6709. Diagnostic: diagnostic,
  6710. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6711. Status: 1,
  6712. Ctime: ctime,
  6713. Mtime: ctime,
  6714. RecordDate: time.Now().Unix(),
  6715. TemplateName: template_name,
  6716. TemplateRemark: template_remark,
  6717. Creator: doctor,
  6718. Modifier: doctor,
  6719. UserName: user_name,
  6720. DoctorAdvice: doctor_advice,
  6721. Remark: remark,
  6722. }
  6723. err := service.SaveHisPatientCaseHistoryTemplate(template)
  6724. if err == nil {
  6725. c.ServeSuccessJSON(map[string]interface{}{
  6726. "msg": "保存成功",
  6727. })
  6728. } else {
  6729. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6730. return
  6731. }
  6732. }
  6733. func (c *HisApiController) GetCaseHistoryTemplate() {
  6734. timeLayout := "2006-01-02"
  6735. loc, _ := time.LoadLocation("Local")
  6736. keyword := c.GetString("keyword")
  6737. start_time := c.GetString("start_time")
  6738. end_time := c.GetString("end_time")
  6739. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6740. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6741. admin := c.GetAdminUserInfo()
  6742. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  6743. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  6744. c.ServeSuccessJSON(map[string]interface{}{
  6745. "template": template,
  6746. //"history": history,
  6747. })
  6748. }
  6749. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6750. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6751. utils.ErrorLog("drug_name")
  6752. return enums.ErrorCodeParamWrong
  6753. }
  6754. adviceName, _ := json["drug_name"].(string)
  6755. if len(adviceName) == 0 {
  6756. utils.ErrorLog("len(advice_name) == 0")
  6757. return enums.ErrorCodeParamWrong
  6758. }
  6759. advice.AdviceName = adviceName
  6760. adviceDesc, _ := json["advice_desc"].(string)
  6761. advice.AdviceDesc = adviceDesc
  6762. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6763. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6764. advice.DrugSpec = drugSpec
  6765. }
  6766. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6767. remark, _ := json["remark"].(string)
  6768. advice.Remark = remark
  6769. }
  6770. if json["id"] == nil {
  6771. advice.DrugId = 0
  6772. } else {
  6773. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6774. drug_id := int64(json["id"].(float64))
  6775. advice.DrugId = drug_id
  6776. }
  6777. }
  6778. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6779. advice_id := int64(json["advice_id"].(float64))
  6780. advice.ID = advice_id
  6781. if advice.ID > 0 {
  6782. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6783. if err == nil {
  6784. if hisAdvice.ID > 0 {
  6785. advice.ExecutionTime = hisAdvice.ExecutionTime
  6786. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6787. advice.ExecutionState = hisAdvice.ExecutionState
  6788. advice.CheckTime = hisAdvice.CheckTime
  6789. advice.Checker = hisAdvice.Checker
  6790. advice.CheckState = hisAdvice.CheckState
  6791. advice.StartTime = hisAdvice.StartTime
  6792. advice.FeedetlSn = hisAdvice.FeedetlSn
  6793. }
  6794. }
  6795. }
  6796. }
  6797. //
  6798. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6799. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6800. // advice.ExecutionTime = execution_time
  6801. //}
  6802. //
  6803. //
  6804. //
  6805. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6806. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6807. // advice.ExecutionStaff = execution_staff
  6808. //}
  6809. //
  6810. //
  6811. //
  6812. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6813. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6814. // advice.ExecutionState = execution_state
  6815. //}
  6816. //
  6817. //
  6818. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6819. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6820. // advice.CheckTime = check_time
  6821. //}
  6822. //
  6823. //
  6824. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6825. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6826. // advice.CheckState = check_state
  6827. //}
  6828. //
  6829. //
  6830. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6831. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6832. // advice.Checker = checker
  6833. //}
  6834. //
  6835. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6836. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6837. // advice.StartTime = start_time
  6838. //}
  6839. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6840. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6841. advice.IsSelfDrug = is_self_drug
  6842. }
  6843. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6844. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6845. drug_way_count, _ := json["drug_way_count"].(string)
  6846. advice.DrugWayCount = drug_way_count
  6847. }
  6848. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6849. drugSpecUnit, _ := json["min_unit"].(string)
  6850. advice.DrugSpecUnit = drugSpecUnit
  6851. }
  6852. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6853. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6854. advice.SingleDose = singleDose
  6855. }
  6856. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6857. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6858. advice.SingleDoseUnit = singleDoseUnit
  6859. }
  6860. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6861. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6862. advice.PrescribingNumber = prescribingNumber
  6863. }
  6864. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6865. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6866. advice.PrescribingNumberUnit = prescribingNumberUnit
  6867. }
  6868. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6869. deliveryWay, _ := json["delivery_way"].(string)
  6870. advice.DeliveryWay = deliveryWay
  6871. }
  6872. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6873. executionFrequency, _ := json["execution_frequency"].(string)
  6874. advice.ExecutionFrequency = executionFrequency
  6875. }
  6876. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6877. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6878. advice.Price = price
  6879. }
  6880. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6881. med_list_codg, _ := json["medical_insurance_number"].(string)
  6882. advice.MedListCodg = med_list_codg
  6883. }
  6884. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6885. day := int64(json["day"].(float64))
  6886. advice.Day = day
  6887. }
  6888. return 0
  6889. }
  6890. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6891. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6892. id := int64(json["id"].(float64))
  6893. project.ID = id
  6894. historyProject, _ := service.GetHisProjectByID(id)
  6895. project.FeedetlSn = historyProject.FeedetlSn
  6896. }
  6897. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6898. project_id := int64(json["project_id"].(float64))
  6899. project.ProjectId = project_id
  6900. }
  6901. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6902. // price := int64(json["price"].(float64))
  6903. // formatInt_price := strconv.FormatInt(price, 10)
  6904. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6905. // project.Price = float_price
  6906. // }
  6907. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6908. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6909. project.Price = price
  6910. }
  6911. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6912. total, _ := json["total"].(string)
  6913. project.Count = total
  6914. }
  6915. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6916. medical_code, _ := json["medical_code"].(string)
  6917. project.MedListCodg = medical_code
  6918. }
  6919. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6920. single_dose, _ := json["single_dose"].(string)
  6921. project.SingleDose = single_dose
  6922. }
  6923. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6924. delivery_way, _ := json["delivery_way"].(string)
  6925. project.DeliveryWay = delivery_way
  6926. }
  6927. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6928. execution_frequency, _ := json["execution_frequency"].(string)
  6929. project.ExecutionFrequency = execution_frequency
  6930. }
  6931. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6932. remark, _ := json["remark"].(string)
  6933. project.Remark = remark
  6934. }
  6935. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6936. day, _ := json["number_days"].(string)
  6937. project.Day = day
  6938. }
  6939. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6940. unit, _ := json["unit"].(string)
  6941. project.Unit = unit
  6942. }
  6943. return 0
  6944. }
  6945. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6946. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6947. id := int64(json["id"].(float64))
  6948. historyAddtions, _ := service.GetHisAdditionByID(id)
  6949. additionalCharge.ID = id
  6950. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  6951. }
  6952. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6953. item_id := int64(json["item_id"].(float64))
  6954. additionalCharge.ItemId = item_id
  6955. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6956. if config.ID > 0 {
  6957. if len(config.Code) > 0 {
  6958. additionalCharge.MedListCodg = config.Code
  6959. }
  6960. }
  6961. }
  6962. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6963. // price := int64(json["price"].(float64))
  6964. // formatInt_price := strconv.FormatInt(price, 10)
  6965. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6966. // additionalCharge.Price = float_price
  6967. // }
  6968. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6969. // price := int64(json["price"].(float64))
  6970. // formatInt_price := strconv.FormatInt(price, 10)
  6971. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6972. // additionalCharge.Price = float_price
  6973. //}
  6974. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6975. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6976. additionalCharge.Price = price
  6977. }
  6978. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6979. count, _ := json["count"].(string)
  6980. counts, _ := strconv.ParseInt(count, 10, 64)
  6981. additionalCharge.Count = counts
  6982. }
  6983. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6984. item_name, _ := json["item_name"].(string)
  6985. additionalCharge.ItemName = item_name
  6986. }
  6987. return 0
  6988. }
  6989. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6990. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6991. utils.ErrorLog("drug_name")
  6992. return enums.ErrorCodeParamWrong
  6993. }
  6994. adviceName, _ := json["drug_name"].(string)
  6995. if len(adviceName) == 0 {
  6996. utils.ErrorLog("len(advice_name) == 0")
  6997. return enums.ErrorCodeParamWrong
  6998. }
  6999. advice.AdviceName = adviceName
  7000. adviceDesc, _ := json["advice_desc"].(string)
  7001. advice.AdviceDesc = adviceDesc
  7002. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7003. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7004. advice.DrugSpec = drugSpec
  7005. }
  7006. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7007. remark, _ := json["remark"].(string)
  7008. advice.Remark = remark
  7009. }
  7010. if json["id"] == nil {
  7011. advice.DrugId = 0
  7012. } else {
  7013. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7014. drug_id := int64(json["id"].(float64))
  7015. advice.DrugId = drug_id
  7016. }
  7017. }
  7018. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7019. groupno := int64(json["groupno"].(float64))
  7020. advice.Groupno = groupno
  7021. }
  7022. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7023. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7024. advice.IsSelfDrug = is_self_drug
  7025. }
  7026. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7027. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7028. drug_way_count, _ := json["drug_way_count"].(string)
  7029. advice.DrugWayCount = drug_way_count
  7030. }
  7031. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7032. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7033. advice.HospApprFlag = hosp_appr_flag
  7034. }
  7035. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7036. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7037. advice.PrescribingNumber = prescribingNumber
  7038. }
  7039. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7040. // frequency_type := int64(json["frequency_type"].(float64))
  7041. // advice.FrequencyType = frequency_type
  7042. //}
  7043. //
  7044. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7045. // day_count := int64(json["day_count"].(float64))
  7046. // advice.DayCount = day_count
  7047. //}
  7048. //
  7049. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7050. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7051. // week_day, _ := json["week_day"].(string)
  7052. // advice.WeekDay = week_day
  7053. //}
  7054. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7055. drugSpecUnit, _ := json["min_unit"].(string)
  7056. advice.DrugSpecUnit = drugSpecUnit
  7057. }
  7058. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7059. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7060. advice.SingleDose = singleDose
  7061. }
  7062. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7063. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7064. advice.SingleDoseUnit = singleDoseUnit
  7065. }
  7066. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7067. deliveryWay, _ := json["delivery_way"].(string)
  7068. advice.DeliveryWay = deliveryWay
  7069. }
  7070. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7071. executionFrequency, _ := json["execution_frequency"].(string)
  7072. advice.ExecutionFrequency = executionFrequency
  7073. }
  7074. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7075. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7076. advice.Price = price
  7077. }
  7078. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7079. med_list_codg, _ := json["medical_insurance_number"].(string)
  7080. advice.MedListCodg = med_list_codg
  7081. }
  7082. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7083. day := int64(json["day"].(float64))
  7084. advice.Day = day
  7085. }
  7086. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7087. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7088. advice.PrescribingNumberUnit = prescribingNumberUnit
  7089. }
  7090. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7091. advice_id := int64(json["advice_id"].(float64))
  7092. advice.ID = advice_id
  7093. if advice.ID > 0 {
  7094. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7095. if err == nil {
  7096. if hisAdvice.ID > 0 {
  7097. advice.ExecutionTime = hisAdvice.ExecutionTime
  7098. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7099. advice.ExecutionState = hisAdvice.ExecutionState
  7100. advice.CheckTime = hisAdvice.CheckTime
  7101. advice.Checker = hisAdvice.Checker
  7102. advice.CheckState = hisAdvice.CheckState
  7103. advice.StartTime = hisAdvice.StartTime
  7104. advice.HospApprFlag = hisAdvice.HospApprFlag
  7105. advice.IsMedicine = hisAdvice.IsMedicine
  7106. if hisAdvice.UserOrgId == 10028 {
  7107. 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 {
  7108. advice.ExecutionTime = 0
  7109. advice.ExecutionStaff = 0
  7110. advice.ExecutionState = 2
  7111. advice.CheckTime = 0
  7112. advice.Checker = 0
  7113. advice.CheckState = 2
  7114. }
  7115. } else {
  7116. 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 {
  7117. advice.ExecutionTime = 0
  7118. advice.ExecutionStaff = 0
  7119. advice.ExecutionState = 2
  7120. advice.CheckTime = 0
  7121. advice.Checker = 0
  7122. advice.CheckState = 2
  7123. advice.UpdatedTime = time.Now().Unix()
  7124. }
  7125. }
  7126. //advice.Groupno = hisAdvice.Groupno
  7127. }
  7128. }
  7129. }
  7130. }
  7131. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7132. //
  7133. //if drugStockConfig.IsOpen == 1 {
  7134. //
  7135. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7136. // if advice.ID == 0 { //医嘱不存在
  7137. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7138. // drug.Total = drug.Total - advice.PrescribingNumber
  7139. // service.UpdateBaseDrugLib(&drug)
  7140. //
  7141. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7142. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7143. // drug.Total = drug.Total - num
  7144. // service.UpdateBaseDrugLib(&drug)
  7145. // }
  7146. //
  7147. // } else if advice.ID > 0 { //医嘱存在
  7148. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7149. // var num float64
  7150. //
  7151. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7152. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7153. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7154. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7155. // drug.Total = drug.Total + num
  7156. // service.UpdateBaseDrugLib(&drug)
  7157. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7158. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7159. // drug.Total = drug.Total - num
  7160. // service.UpdateBaseDrugLib(&drug)
  7161. // }
  7162. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7163. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7164. // if num2 > advice.PrescribingNumber {
  7165. // num = num2 - advice.PrescribingNumber
  7166. // drug.Total = drug.Total + num
  7167. // service.UpdateBaseDrugLib(&drug)
  7168. // } else if num2 < advice.PrescribingNumber {
  7169. // num = advice.PrescribingNumber - num2
  7170. // drug.Total = drug.Total - num
  7171. // service.UpdateBaseDrugLib(&drug)
  7172. // }
  7173. //
  7174. // }
  7175. //
  7176. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7177. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7178. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7179. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7180. // if num1 > num2 {
  7181. // num = num1 - num2
  7182. // drug.Total = drug.Total + num
  7183. // service.UpdateBaseDrugLib(&drug)
  7184. // } else if num1 < num2 {
  7185. // num = num2 - num1
  7186. // drug.Total = drug.Total - num
  7187. // service.UpdateBaseDrugLib(&drug)
  7188. // }
  7189. //
  7190. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7191. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7192. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7193. // if hisAdvice.PrescribingNumber > num2 {
  7194. // num = hisAdvice.PrescribingNumber - num2
  7195. // drug.Total = drug.Total + num
  7196. // service.UpdateBaseDrugLib(&drug)
  7197. // } else if num2 < advice.PrescribingNumber {
  7198. // num = num2 - hisAdvice.PrescribingNumber
  7199. // drug.Total = drug.Total - num
  7200. // service.UpdateBaseDrugLib(&drug)
  7201. // }
  7202. //
  7203. // }
  7204. // }
  7205. // }
  7206. //}
  7207. //
  7208. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7209. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7210. // advice.ExecutionTime = execution_time
  7211. //}
  7212. //
  7213. //
  7214. //
  7215. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7216. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7217. // advice.ExecutionStaff = execution_staff
  7218. //}
  7219. //
  7220. //
  7221. //
  7222. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7223. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7224. // advice.ExecutionState = execution_state
  7225. //}
  7226. //
  7227. //
  7228. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7229. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7230. // advice.CheckTime = check_time
  7231. //}
  7232. //
  7233. //
  7234. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7235. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7236. // advice.CheckState = check_state
  7237. //}
  7238. //
  7239. //
  7240. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7241. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7242. // advice.Checker = checker
  7243. //}
  7244. //
  7245. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7246. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7247. // advice.StartTime = start_time
  7248. //}
  7249. return 0
  7250. }
  7251. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7252. project.ExecutionStaff = 0
  7253. project.ExecutionState = 2
  7254. project.ExecutionTime = 0
  7255. project.Checker = 0
  7256. project.CheckState = 2
  7257. project.CheckTime = 0
  7258. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7259. id := int64(json["id"].(float64))
  7260. project.ID = id
  7261. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7262. project.ExecutionStaff = temp_project.ExecutionStaff
  7263. project.ExecutionState = temp_project.ExecutionState
  7264. project.ExecutionTime = temp_project.ExecutionTime
  7265. project.Checker = temp_project.Checker
  7266. project.CheckState = temp_project.CheckState
  7267. project.CheckTime = temp_project.CheckTime
  7268. project.TeamId = temp_project.TeamId
  7269. }
  7270. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7271. types := int64(json["type"].(float64))
  7272. project.Type = types
  7273. }
  7274. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7275. project_id := int64(json["project_id"].(float64))
  7276. project.ProjectId = project_id
  7277. }
  7278. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7279. team_id := int64(json["team_id"].(float64))
  7280. project.TeamId = team_id
  7281. }
  7282. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7283. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7284. project.Price = price
  7285. }
  7286. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7287. total, _ := json["total"].(string)
  7288. //totals, _ := strconv.ParseInt(total, 10, 64)
  7289. project.Count = total
  7290. }
  7291. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7292. medical_code, _ := json["medical_code"].(string)
  7293. project.MedListCodg = medical_code
  7294. }
  7295. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7296. single_dose, _ := json["single_dose"].(string)
  7297. project.SingleDose = single_dose
  7298. }
  7299. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7300. delivery_way, _ := json["delivery_way"].(string)
  7301. project.DeliveryWay = delivery_way
  7302. }
  7303. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7304. execution_frequency, _ := json["execution_frequency"].(string)
  7305. project.ExecutionFrequency = execution_frequency
  7306. }
  7307. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7308. remark, _ := json["remark"].(string)
  7309. project.Remark = remark
  7310. }
  7311. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7312. day, _ := json["number_days"].(string)
  7313. project.Day = day
  7314. }
  7315. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7316. unit, _ := json["unit"].(string)
  7317. project.Unit = unit
  7318. }
  7319. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7320. // frequency_type := int64(json["frequency_type"].(float64))
  7321. // project.FrequencyType = frequency_type
  7322. //}
  7323. //
  7324. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7325. // day_count := int64(json["day_count"].(float64))
  7326. // project.DayCount = day_count
  7327. //}
  7328. //
  7329. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7330. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7331. // week_day, _ := json["week_day"].(string)
  7332. // project.WeekDay = week_day
  7333. //}
  7334. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7335. //
  7336. //if project.ID == 0 {
  7337. // if stockConfig.IsOpen == 1 {
  7338. // if project.Type == 3 {
  7339. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7340. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7341. // good.Total = good.Total - f_count
  7342. // service.UpdateGoodInfo(&good)
  7343. // }
  7344. // }
  7345. //
  7346. //} else {
  7347. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7348. //
  7349. // if stockConfig.IsOpen == 1 {
  7350. // if project.Type == 3 {
  7351. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7352. // if project.Count < temp_project.Count {
  7353. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7354. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7355. //
  7356. // other_count := f_count_two - f_count_one
  7357. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7358. // good.Total = good.Total + other_count_two
  7359. // service.UpdateGoodInfo(&good)
  7360. // } else if project.Count > temp_project.Count {
  7361. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7362. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7363. //
  7364. // other_count := f_count_one - f_count_two
  7365. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7366. // good.Total = good.Total - other_count_two
  7367. // service.UpdateGoodInfo(&good)
  7368. // }
  7369. //
  7370. // }
  7371. // }
  7372. //
  7373. //}
  7374. return 0
  7375. }
  7376. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7377. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7378. utils.ErrorLog("drug_name")
  7379. return enums.ErrorCodeParamWrong
  7380. }
  7381. adviceName, _ := json["drug_name"].(string)
  7382. if len(adviceName) == 0 {
  7383. utils.ErrorLog("len(advice_name) == 0")
  7384. return enums.ErrorCodeParamWrong
  7385. }
  7386. advice.AdviceName = adviceName
  7387. adviceDesc, _ := json["advice_desc"].(string)
  7388. advice.AdviceDesc = adviceDesc
  7389. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7390. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7391. advice.DrugSpec = drugSpec
  7392. }
  7393. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7394. remark, _ := json["remark"].(string)
  7395. advice.Remark = remark
  7396. }
  7397. if json["id"] == nil {
  7398. advice.DrugId = 0
  7399. } else {
  7400. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7401. drug_id := int64(json["id"].(float64))
  7402. advice.DrugId = drug_id
  7403. }
  7404. }
  7405. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7406. groupno := int64(json["groupno"].(float64))
  7407. advice.Groupno = groupno
  7408. }
  7409. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7410. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7411. advice.IsSelfDrug = is_self_drug
  7412. }
  7413. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7414. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7415. drug_way_count, _ := json["drug_way_count"].(string)
  7416. advice.DrugWayCount = drug_way_count
  7417. }
  7418. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7419. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7420. advice.HospApprFlag = hosp_appr_flag
  7421. }
  7422. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7423. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7424. advice.PrescribingNumber = prescribingNumber
  7425. }
  7426. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7427. // frequency_type := int64(json["frequency_type"].(float64))
  7428. // advice.FrequencyType = frequency_type
  7429. //}
  7430. //
  7431. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7432. // day_count := int64(json["day_count"].(float64))
  7433. // advice.DayCount = day_count
  7434. //}
  7435. //
  7436. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7437. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7438. // week_day, _ := json["week_day"].(string)
  7439. // advice.WeekDay = week_day
  7440. //}
  7441. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7442. drugSpecUnit, _ := json["min_unit"].(string)
  7443. advice.DrugSpecUnit = drugSpecUnit
  7444. }
  7445. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7446. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7447. advice.SingleDose = singleDose
  7448. }
  7449. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7450. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7451. advice.SingleDoseUnit = singleDoseUnit
  7452. }
  7453. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7454. deliveryWay, _ := json["delivery_way"].(string)
  7455. advice.DeliveryWay = deliveryWay
  7456. }
  7457. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7458. executionFrequency, _ := json["execution_frequency"].(string)
  7459. advice.ExecutionFrequency = executionFrequency
  7460. }
  7461. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7462. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7463. advice.Price = price
  7464. }
  7465. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7466. med_list_codg, _ := json["medical_insurance_number"].(string)
  7467. advice.MedListCodg = med_list_codg
  7468. }
  7469. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7470. day := int64(json["day"].(float64))
  7471. advice.Day = day
  7472. }
  7473. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7474. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7475. advice.PrescribingNumberUnit = prescribingNumberUnit
  7476. }
  7477. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7478. advice_id := int64(json["advice_id"].(float64))
  7479. advice.ID = advice_id
  7480. if advice.ID > 0 {
  7481. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7482. if err == nil {
  7483. if hisAdvice.ID > 0 {
  7484. advice.ExecutionTime = hisAdvice.ExecutionTime
  7485. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7486. advice.ExecutionState = hisAdvice.ExecutionState
  7487. advice.CheckTime = hisAdvice.CheckTime
  7488. advice.Checker = hisAdvice.Checker
  7489. advice.DrugCode = hisAdvice.DrugCode
  7490. advice.CheckState = hisAdvice.CheckState
  7491. advice.StartTime = hisAdvice.StartTime
  7492. advice.HospApprFlag = hisAdvice.HospApprFlag
  7493. advice.IsMedicine = hisAdvice.IsMedicine
  7494. if hisAdvice.UserOrgId == 10028 {
  7495. 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 {
  7496. advice.ExecutionTime = 0
  7497. advice.ExecutionStaff = 0
  7498. advice.ExecutionState = 2
  7499. advice.CheckTime = 0
  7500. advice.Checker = 0
  7501. advice.CheckState = 2
  7502. }
  7503. } else {
  7504. 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 {
  7505. advice.ExecutionTime = 0
  7506. advice.ExecutionStaff = 0
  7507. advice.ExecutionState = 2
  7508. advice.CheckTime = 0
  7509. advice.Checker = 0
  7510. advice.CheckState = 2
  7511. //advice.UpdatedTime = time.Now().Unix()
  7512. advice.CreatedTime = hisAdvice.CreatedTime
  7513. advice.UpdatedTime = time.Now().Unix()
  7514. } else {
  7515. advice.CreatedTime = hisAdvice.CreatedTime
  7516. advice.UpdatedTime = hisAdvice.UpdatedTime
  7517. }
  7518. }
  7519. //advice.Groupno = hisAdvice.Groupno
  7520. } else {
  7521. advice.IsMedicine = 0
  7522. ctime := time.Now().Unix()
  7523. advice.CreatedTime = ctime
  7524. advice.UpdatedTime = ctime
  7525. }
  7526. }
  7527. } else {
  7528. advice.IsMedicine = 0
  7529. ctime := time.Now().Unix()
  7530. advice.CreatedTime = ctime
  7531. advice.UpdatedTime = ctime
  7532. }
  7533. }
  7534. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7535. //
  7536. //if drugStockConfig.IsOpen == 1 {
  7537. //
  7538. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7539. // if advice.ID == 0 { //医嘱不存在
  7540. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7541. // drug.Total = drug.Total - advice.PrescribingNumber
  7542. // service.UpdateBaseDrugLib(&drug)
  7543. //
  7544. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7545. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7546. // drug.Total = drug.Total - num
  7547. // service.UpdateBaseDrugLib(&drug)
  7548. // }
  7549. //
  7550. // } else if advice.ID > 0 { //医嘱存在
  7551. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7552. // var num float64
  7553. //
  7554. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7555. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7556. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7557. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7558. // drug.Total = drug.Total + num
  7559. // service.UpdateBaseDrugLib(&drug)
  7560. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7561. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7562. // drug.Total = drug.Total - num
  7563. // service.UpdateBaseDrugLib(&drug)
  7564. // }
  7565. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7566. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7567. // if num2 > advice.PrescribingNumber {
  7568. // num = num2 - advice.PrescribingNumber
  7569. // drug.Total = drug.Total + num
  7570. // service.UpdateBaseDrugLib(&drug)
  7571. // } else if num2 < advice.PrescribingNumber {
  7572. // num = advice.PrescribingNumber - num2
  7573. // drug.Total = drug.Total - num
  7574. // service.UpdateBaseDrugLib(&drug)
  7575. // }
  7576. //
  7577. // }
  7578. //
  7579. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7580. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7581. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7582. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7583. // if num1 > num2 {
  7584. // num = num1 - num2
  7585. // drug.Total = drug.Total + num
  7586. // service.UpdateBaseDrugLib(&drug)
  7587. // } else if num1 < num2 {
  7588. // num = num2 - num1
  7589. // drug.Total = drug.Total - num
  7590. // service.UpdateBaseDrugLib(&drug)
  7591. // }
  7592. //
  7593. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7594. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7595. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7596. // if hisAdvice.PrescribingNumber > num2 {
  7597. // num = hisAdvice.PrescribingNumber - num2
  7598. // drug.Total = drug.Total + num
  7599. // service.UpdateBaseDrugLib(&drug)
  7600. // } else if num2 < advice.PrescribingNumber {
  7601. // num = num2 - hisAdvice.PrescribingNumber
  7602. // drug.Total = drug.Total - num
  7603. // service.UpdateBaseDrugLib(&drug)
  7604. // }
  7605. //
  7606. // }
  7607. // }
  7608. // }
  7609. //}
  7610. //
  7611. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7612. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7613. // advice.ExecutionTime = execution_time
  7614. //}
  7615. //
  7616. //
  7617. //
  7618. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7619. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7620. // advice.ExecutionStaff = execution_staff
  7621. //}
  7622. //
  7623. //
  7624. //
  7625. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7626. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7627. // advice.ExecutionState = execution_state
  7628. //}
  7629. //
  7630. //
  7631. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7632. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7633. // advice.CheckTime = check_time
  7634. //}
  7635. //
  7636. //
  7637. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7638. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7639. // advice.CheckState = check_state
  7640. //}
  7641. //
  7642. //
  7643. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7644. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7645. // advice.Checker = checker
  7646. //}
  7647. //
  7648. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7649. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7650. // advice.StartTime = start_time
  7651. //}
  7652. return 0
  7653. }
  7654. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7655. project.ExecutionStaff = 0
  7656. project.ExecutionState = 2
  7657. project.ExecutionTime = 0
  7658. project.Checker = 0
  7659. project.CheckState = 2
  7660. project.CheckTime = 0
  7661. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7662. id := int64(json["id"].(float64))
  7663. project.ID = id
  7664. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7665. project.ExecutionStaff = temp_project.ExecutionStaff
  7666. project.ExecutionState = temp_project.ExecutionState
  7667. project.ExecutionTime = temp_project.ExecutionTime
  7668. project.Checker = temp_project.Checker
  7669. project.CheckState = temp_project.CheckState
  7670. project.CheckTime = temp_project.CheckTime
  7671. project.TeamId = temp_project.TeamId
  7672. }
  7673. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7674. types := int64(json["type"].(float64))
  7675. project.Type = types
  7676. }
  7677. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7678. project_id := int64(json["project_id"].(float64))
  7679. project.ProjectId = project_id
  7680. }
  7681. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7682. team_id := int64(json["team_id"].(float64))
  7683. project.TeamId = team_id
  7684. }
  7685. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7686. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7687. project.Price = price
  7688. }
  7689. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7690. total, _ := json["total"].(string)
  7691. //totals, _ := strconv.ParseInt(total, 10, 64)
  7692. project.Count = total
  7693. }
  7694. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7695. medical_code, _ := json["medical_code"].(string)
  7696. project.MedListCodg = medical_code
  7697. }
  7698. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7699. single_dose, _ := json["single_dose"].(string)
  7700. project.SingleDose = single_dose
  7701. }
  7702. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7703. delivery_way, _ := json["delivery_way"].(string)
  7704. project.DeliveryWay = delivery_way
  7705. }
  7706. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7707. execution_frequency, _ := json["execution_frequency"].(string)
  7708. project.ExecutionFrequency = execution_frequency
  7709. }
  7710. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7711. remark, _ := json["remark"].(string)
  7712. project.Remark = remark
  7713. }
  7714. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7715. day, _ := json["number_days"].(string)
  7716. project.Day = day
  7717. }
  7718. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7719. unit, _ := json["unit"].(string)
  7720. project.Unit = unit
  7721. }
  7722. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7723. // frequency_type := int64(json["frequency_type"].(float64))
  7724. // project.FrequencyType = frequency_type
  7725. //}
  7726. //
  7727. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7728. // day_count := int64(json["day_count"].(float64))
  7729. // project.DayCount = day_count
  7730. //}
  7731. //
  7732. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7733. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7734. // week_day, _ := json["week_day"].(string)
  7735. // project.WeekDay = week_day
  7736. //}
  7737. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7738. //
  7739. //if project.ID == 0 {
  7740. // if stockConfig.IsOpen == 1 {
  7741. // if project.Type == 3 {
  7742. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7743. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7744. // good.Total = good.Total - f_count
  7745. // service.UpdateGoodInfo(&good)
  7746. // }
  7747. // }
  7748. //
  7749. //} else {
  7750. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7751. //
  7752. // if stockConfig.IsOpen == 1 {
  7753. // if project.Type == 3 {
  7754. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7755. // if project.Count < temp_project.Count {
  7756. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7757. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7758. //
  7759. // other_count := f_count_two - f_count_one
  7760. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7761. // good.Total = good.Total + other_count_two
  7762. // service.UpdateGoodInfo(&good)
  7763. // } else if project.Count > temp_project.Count {
  7764. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7765. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7766. //
  7767. // other_count := f_count_one - f_count_two
  7768. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7769. // good.Total = good.Total - other_count_two
  7770. // service.UpdateGoodInfo(&good)
  7771. // }
  7772. //
  7773. // }
  7774. // }
  7775. //
  7776. //}
  7777. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7778. id := int64(json["id"].(float64))
  7779. if id > 0 {
  7780. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7781. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  7782. fmt.Println("666666")
  7783. project.Mtime = time.Now().Unix()
  7784. project.Ctime = temp_project.Ctime
  7785. } else {
  7786. project.Mtime = temp_project.Mtime
  7787. project.Ctime = temp_project.Ctime
  7788. }
  7789. } else {
  7790. ctime := time.Now().Unix()
  7791. project.Mtime = ctime
  7792. project.Ctime = ctime
  7793. }
  7794. }
  7795. return 0
  7796. }
  7797. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7798. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7799. id := int64(json["id"].(float64))
  7800. additionalCharge.ID = id
  7801. }
  7802. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7803. item_id := int64(json["item_id"].(float64))
  7804. additionalCharge.ItemId = item_id
  7805. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7806. if config.ID > 0 {
  7807. if len(config.Code) > 0 {
  7808. additionalCharge.MedListCodg = config.Code
  7809. }
  7810. }
  7811. }
  7812. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7813. // price := int64(json["price"].(float64))
  7814. // formatInt_price := strconv.FormatInt(price, 10)
  7815. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7816. // additionalCharge.Price = float_price
  7817. // }
  7818. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7819. // price := int64(json["price"].(float64))
  7820. // formatInt_price := strconv.FormatInt(price, 10)
  7821. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7822. // additionalCharge.Price = float_price
  7823. //}
  7824. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7825. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7826. additionalCharge.Price = price
  7827. }
  7828. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  7829. count, _ := json["count"].(string)
  7830. counts, _ := strconv.ParseInt(count, 10, 64)
  7831. additionalCharge.Count = counts
  7832. }
  7833. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  7834. item_name, _ := json["item_name"].(string)
  7835. additionalCharge.ItemName = item_name
  7836. }
  7837. return 0
  7838. }
  7839. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  7840. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7841. utils.ErrorLog("drug_name")
  7842. return enums.ErrorCodeParamWrong
  7843. }
  7844. adviceName, _ := json["drug_name"].(string)
  7845. if len(adviceName) == 0 {
  7846. utils.ErrorLog("len(advice_name) == 0")
  7847. return enums.ErrorCodeParamWrong
  7848. }
  7849. advice.AdviceName = adviceName
  7850. adviceDesc, _ := json["advice_desc"].(string)
  7851. advice.AdviceDesc = adviceDesc
  7852. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7853. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7854. advice.DrugSpec = drugSpec
  7855. }
  7856. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7857. remark, _ := json["remark"].(string)
  7858. advice.Remark = remark
  7859. }
  7860. if json["id"] == nil {
  7861. advice.DrugId = 0
  7862. } else {
  7863. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7864. drug_id := int64(json["id"].(float64))
  7865. advice.DrugId = drug_id
  7866. }
  7867. }
  7868. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7869. groupno := int64(json["groupno"].(float64))
  7870. advice.Groupno = groupno
  7871. }
  7872. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7873. drugSpecUnit, _ := json["min_unit"].(string)
  7874. advice.DrugSpecUnit = drugSpecUnit
  7875. }
  7876. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7877. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7878. advice.SingleDose = singleDose
  7879. }
  7880. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7881. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7882. advice.SingleDoseUnit = singleDoseUnit
  7883. }
  7884. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7885. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7886. advice.PrescribingNumber = prescribingNumber
  7887. }
  7888. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7889. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7890. advice.PrescribingNumberUnit = prescribingNumberUnit
  7891. }
  7892. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7893. deliveryWay, _ := json["delivery_way"].(string)
  7894. advice.DeliveryWay = deliveryWay
  7895. }
  7896. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7897. executionFrequency, _ := json["execution_frequency"].(string)
  7898. advice.ExecutionFrequency = executionFrequency
  7899. }
  7900. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7901. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7902. advice.Price = price
  7903. }
  7904. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7905. med_list_codg, _ := json["medical_insurance_number"].(string)
  7906. advice.MedListCodg = med_list_codg
  7907. }
  7908. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7909. day := int64(json["day"].(float64))
  7910. advice.Day = day
  7911. }
  7912. advice.FrequencyType = 1
  7913. return 0
  7914. }
  7915. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  7916. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7917. types := int64(json["type"].(float64))
  7918. project.Type = types
  7919. }
  7920. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7921. project_id := int64(json["project_id"].(float64))
  7922. project.ProjectId = project_id
  7923. }
  7924. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7925. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7926. project.Price = price
  7927. }
  7928. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7929. total, _ := json["total"].(string)
  7930. //totals, _ := strconv.ParseInt(total, 10, 64)
  7931. project.Count = total
  7932. }
  7933. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7934. medical_code, _ := json["medical_code"].(string)
  7935. project.MedListCodg = medical_code
  7936. }
  7937. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7938. single_dose, _ := json["single_dose"].(string)
  7939. project.SingleDose = single_dose
  7940. }
  7941. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7942. delivery_way, _ := json["delivery_way"].(string)
  7943. project.DeliveryWay = delivery_way
  7944. }
  7945. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7946. execution_frequency, _ := json["execution_frequency"].(string)
  7947. project.ExecutionFrequency = execution_frequency
  7948. }
  7949. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7950. remark, _ := json["remark"].(string)
  7951. project.Remark = remark
  7952. }
  7953. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7954. day, _ := json["number_days"].(string)
  7955. project.Day = day
  7956. }
  7957. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7958. unit, _ := json["unit"].(string)
  7959. project.Unit = unit
  7960. }
  7961. project.FrequencyType = 1
  7962. return 0
  7963. }
  7964. func (c *HisApiController) GetHisOrderListTwo() {
  7965. start_time := c.GetString("start_time")
  7966. end_time := c.GetString("end_time")
  7967. timeLayout := "2006-01-02"
  7968. loc, _ := time.LoadLocation("Local")
  7969. var startTime int64
  7970. if len(start_time) > 0 {
  7971. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7972. if err != nil {
  7973. //fmt.Println(err)
  7974. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7975. return
  7976. }
  7977. startTime = theTime.Unix()
  7978. }
  7979. var endTime int64
  7980. if len(end_time) > 0 {
  7981. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7982. if err != nil {
  7983. utils.ErrorLog(err.Error())
  7984. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7985. return
  7986. }
  7987. endTime = theTime.Unix()
  7988. }
  7989. adminUser := c.GetAdminUserInfo()
  7990. org_id := adminUser.CurrentOrgId
  7991. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  7992. if err == nil {
  7993. c.ServeSuccessJSON(map[string]interface{}{
  7994. "order2": order,
  7995. })
  7996. } else {
  7997. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7998. return
  7999. }
  8000. }
  8001. func (c *HisApiController) GetHisOrderList() {
  8002. page, _ := c.GetInt64("page", -1)
  8003. limit, _ := c.GetInt64("limit", -1)
  8004. start_time := c.GetString("start_time")
  8005. end_time := c.GetString("end_time")
  8006. types, _ := c.GetInt64("type", 0)
  8007. keywords := c.GetString("keywords")
  8008. p_type, _ := c.GetInt64("p_type", 0)
  8009. sort_type, _ := c.GetInt64("sort_type", 0)
  8010. charge_type, _ := c.GetInt64("charge_type", 0)
  8011. sch_type, _ := c.GetInt64("sch_type", 0)
  8012. zone_type, _ := c.GetInt64("zone_type", 0)
  8013. med_type, _ := c.GetInt64("med_type", 0)
  8014. timeLayout := "2006-01-02"
  8015. loc, _ := time.LoadLocation("Local")
  8016. var startTime int64
  8017. if len(start_time) > 0 {
  8018. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8019. if err != nil {
  8020. //fmt.Println(err)
  8021. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8022. return
  8023. }
  8024. startTime = theTime.Unix()
  8025. }
  8026. var endTime int64
  8027. if len(end_time) > 0 {
  8028. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8029. if err != nil {
  8030. utils.ErrorLog(err.Error())
  8031. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8032. return
  8033. }
  8034. endTime = theTime.Unix()
  8035. }
  8036. adminUser := c.GetAdminUserInfo()
  8037. org_id := adminUser.CurrentOrgId
  8038. 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)
  8039. for _, item := range order {
  8040. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  8041. item.DoctorName = info.Doctor
  8042. item.DepartmentName = info.XtHisDepartment.Name
  8043. }
  8044. if err == nil {
  8045. c.ServeSuccessJSON(map[string]interface{}{
  8046. "order": order,
  8047. "total": total,
  8048. })
  8049. } else {
  8050. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8051. return
  8052. }
  8053. }
  8054. func (c *HisApiController) GetHisOrder() {
  8055. patient_id, _ := c.GetInt64("patient_id", 0)
  8056. number := c.GetString("number")
  8057. adminInfo := c.GetAdminUserInfo()
  8058. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  8059. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  8060. if err == nil {
  8061. c.ServeSuccessJSON(map[string]interface{}{
  8062. "order": order,
  8063. "prescription": prescriptions,
  8064. })
  8065. } else {
  8066. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8067. return
  8068. }
  8069. }
  8070. func (c *HisApiController) GetHisPrescriptionList() {
  8071. record_date := c.GetString("record_date")
  8072. keywords := c.GetString("keywords")
  8073. page, _ := c.GetInt64("page")
  8074. limit, _ := c.GetInt64("limit")
  8075. sch_type, _ := c.GetInt64("sch_type")
  8076. timeLayout := "2006-01-02"
  8077. loc, _ := time.LoadLocation("Local")
  8078. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8079. if err != nil {
  8080. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8081. return
  8082. }
  8083. recordDateTime := theTime.Unix()
  8084. adminInfo := c.GetAdminUserInfo()
  8085. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  8086. //adminInfo := c.GetAdminUserInfo()
  8087. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  8088. //fmt.Println(prescriptionOrder)
  8089. if err == nil {
  8090. c.ServeSuccessJSON(map[string]interface{}{
  8091. "order": prescriptionOrder,
  8092. "total": total,
  8093. })
  8094. } else {
  8095. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8096. return
  8097. }
  8098. }
  8099. func (c *HisApiController) GetHisPrescriptionInfo() {
  8100. id, _ := c.GetInt64("id")
  8101. adminInfo := c.GetAdminUserInfo()
  8102. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  8103. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  8104. if err == nil {
  8105. c.ServeSuccessJSON(map[string]interface{}{
  8106. "order": prescriptionOrder,
  8107. "prescription": prescription,
  8108. })
  8109. } else {
  8110. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8111. return
  8112. }
  8113. }
  8114. func (c *HisApiController) GetMedicalInsuranceConfig() {
  8115. adminUser := c.GetAdminUserInfo()
  8116. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  8117. c.ServeSuccessJSON(map[string]interface{}{
  8118. "config": config,
  8119. })
  8120. }
  8121. type ResultTwo struct {
  8122. ErrMsg interface{} `json:"err_msg"`
  8123. InfRefmsgid string `json:"inf_refmsgid"`
  8124. Infcode int64 `json:"infcode"`
  8125. Output struct {
  8126. Baseinfo struct {
  8127. Age float64 `json:"age"`
  8128. Brdy string `json:"brdy"`
  8129. Certno string `json:"certno"`
  8130. Gend string `json:"gend"`
  8131. Naty string `json:"naty"`
  8132. PsnCertType string `json:"psn_cert_type"`
  8133. PsnName string `json:"psn_name"`
  8134. PsnNo string `json:"psn_no"`
  8135. } `json:"baseinfo"`
  8136. Idetinfo []interface{} `json:"idetinfo"`
  8137. Iinfo []struct {
  8138. Balc float64 `json:"balc"`
  8139. CvlservFlag string `json:"cvlserv_flag"`
  8140. EmpName string `json:"emp_name"`
  8141. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  8142. Insutype string `json:"insutype"`
  8143. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  8144. PausInsuDate interface{} `json:"paus_insu_date"`
  8145. PsnInsuDate string `json:"psn_insu_date"`
  8146. PsnInsuStas string `json:"psn_insu_stas"`
  8147. PsnType string `json:"psn_type"`
  8148. } `json:"insuinfo"`
  8149. } `json:"output"`
  8150. RefmsgTime string `json:"refmsg_time"`
  8151. RespondTime string `json:"respond_time"`
  8152. Signtype interface{} `json:"signtype"`
  8153. WarnInfo interface{} `json:"warn_info"`
  8154. }
  8155. type ResultThree struct {
  8156. Cainfo interface{} `json:"cainfo"`
  8157. ErrMsg interface{} `json:"err_msg"`
  8158. InfRefmsgid string `json:"inf_refmsgid"`
  8159. Infcode int64 `json:"infcode"`
  8160. Output struct {
  8161. Data struct {
  8162. IptOtpNo string `json:"ipt_otp_no"`
  8163. MdtrtID string `json:"mdtrt_id"`
  8164. PsnNo string `json:"psn_no"`
  8165. } `json:"data"`
  8166. } `json:"output"`
  8167. RefmsgTime string `json:"refmsg_time"`
  8168. RespondTime string `json:"respond_time"`
  8169. Signtype interface{} `json:"signtype"`
  8170. WarnMsg interface{} `json:"warn_msg"`
  8171. }
  8172. type ResultFour struct {
  8173. Cainfo string `json:"cainfo"`
  8174. ErrMsg string `json:"err_msg"`
  8175. InfRefmsgid string `json:"inf_refmsgid"`
  8176. Infcode int64 `json:"infcode"`
  8177. Output struct {
  8178. Result []struct {
  8179. BasMednFlag string `json:"bas_medn_flag"`
  8180. ChldMedcFlag string `json:"chld_medc_flag"`
  8181. ChrgitmLv string `json:"chrgitm_lv"`
  8182. Cnt float64 `json:"cnt"`
  8183. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  8184. DrtReimFlag string `json:"drt_reim_flag"`
  8185. FeedetlSn string `json:"feedetl_sn"`
  8186. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8187. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  8188. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8189. ListSpItemFlag string `json:"list_sp_item_flag"`
  8190. LmtUsedFlag string `json:"lmt_used_flag"`
  8191. MedChrgitmType string `json:"med_chrgitm_type"`
  8192. Memo string `json:"memo"`
  8193. OverlmtAmt float64 `json:"overlmt_amt"`
  8194. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8195. Pric float64 `json:"pric"`
  8196. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  8197. SelfpayProp float64 `json:"selfpay_prop"`
  8198. } `json:"result"`
  8199. } `json:"output"`
  8200. RefmsgTime string `json:"refmsg_time"`
  8201. RespondTime string `json:"respond_time"`
  8202. Signtype string `json:"signtype"`
  8203. WarnMsg string `json:"warn_msg"`
  8204. }
  8205. type ResultFive struct {
  8206. Insutype string `json:"insutype"`
  8207. }
  8208. type ResultSix struct {
  8209. Cainfo interface{} `json:"cainfo"`
  8210. ErrMsg interface{} `json:"err_msg"`
  8211. InfRefmsgid string `json:"inf_refmsgid"`
  8212. Infcode int64 `json:"infcode"`
  8213. Output struct {
  8214. } `json:"output"`
  8215. RefmsgTime string `json:"refmsg_time"`
  8216. RespondTime string `json:"respond_time"`
  8217. Signtype interface{} `json:"signtype"`
  8218. WarnMsg interface{} `json:"warn_msg"`
  8219. }
  8220. type ResultSeven struct {
  8221. Cainfo string `json:"cainfo"`
  8222. ErrMsg string `json:"err_msg"`
  8223. InfRefmsgid string `json:"inf_refmsgid"`
  8224. Infcode int64 `json:"infcode"`
  8225. Output struct {
  8226. Setldetail []interface{} `json:"setldetail"`
  8227. Setlinfo struct {
  8228. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8229. AcctPay float64 `json:"acct_pay"`
  8230. ActPayDedc float64 `json:"act_pay_dedc"`
  8231. Age float64 `json:"age"`
  8232. Balc float64 `json:"balc"`
  8233. Brdy string `json:"brdy"`
  8234. Certno string `json:"certno"`
  8235. ClrOptins string `json:"clr_optins"`
  8236. ClrType string `json:"clr_type"`
  8237. ClrWay string `json:"clr_way"`
  8238. CvlservFlag string `json:"cvlserv_flag"`
  8239. CvlservPay float64 `json:"cvlserv_pay"`
  8240. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8241. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8242. Gend string `json:"gend"`
  8243. HifesPay float64 `json:"hifes_pay"`
  8244. HifmiPay float64 `json:"hifmi_pay"`
  8245. HifobPay float64 `json:"hifob_pay"`
  8246. HifpPay float64 `json:"hifp_pay"`
  8247. HospPartAmt float64 `json:"hosp_part_amt"`
  8248. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8249. Insutype string `json:"insutype"`
  8250. MafPay float64 `json:"maf_pay"`
  8251. MdtrtCertType string `json:"mdtrt_cert_type"`
  8252. MdtrtID string `json:"mdtrt_id"`
  8253. MedType string `json:"med_type"`
  8254. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8255. MedinsSetlID string `json:"medins_setl_id"`
  8256. Naty string `json:"naty"`
  8257. OthPay float64 `json:"oth_pay"`
  8258. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8259. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8260. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8261. PsnCashPay float64 `json:"psn_cash_pay"`
  8262. PsnCertType string `json:"psn_cert_type"`
  8263. PsnName string `json:"psn_name"`
  8264. PsnNo string `json:"psn_no"`
  8265. PsnPartAmt float64 `json:"psn_part_amt"`
  8266. PsnType string `json:"psn_type"`
  8267. SetlID string `json:"setl_id"`
  8268. SetlTime string `json:"setl_time"`
  8269. } `json:"setlinfo"`
  8270. } `json:"output"`
  8271. RefmsgTime string `json:"refmsg_time"`
  8272. RespondTime string `json:"respond_time"`
  8273. Signtype interface{} `json:"signtype"`
  8274. WarnMsg interface{} `json:"warn_msg"`
  8275. }
  8276. type ResultEight struct {
  8277. Cainfo string `json:"cainfo"`
  8278. ErrMsg string `json:"err_msg"`
  8279. InfRefmsgid string `json:"inf_refmsgid"`
  8280. Infcode int64 `json:"infcode"`
  8281. Output struct {
  8282. Stmtinfo struct {
  8283. SetlOptins string `json:"setl_optins"`
  8284. StmtRslt string `json:"stmt_rslt"`
  8285. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  8286. } `json:"stmtinfo"`
  8287. } `json:"output"`
  8288. RefmsgTime string `json:"refmsg_time"`
  8289. RespondTime string `json:"respond_time"`
  8290. Signtype interface{} `json:"signtype"`
  8291. WarnMsg interface{} `json:"warn_msg"`
  8292. }
  8293. type ResultNine struct {
  8294. Cainfo string `json:"cainfo"`
  8295. ErrMsg string `json:"err_msg"`
  8296. InfRefmsgid string `json:"inf_refmsgid"`
  8297. Infcode int64 `json:"infcode"`
  8298. Output struct {
  8299. FileQuryNo string `json:"file_qury_no"`
  8300. } `json:"output"`
  8301. RefmsgTime string `json:"refmsg_time"`
  8302. RespondTime string `json:"respond_time"`
  8303. Signtype interface{} `json:"signtype"`
  8304. WarnMsg interface{} `json:"warn_msg"`
  8305. }
  8306. type ResultTen struct {
  8307. Cainfo string `json:"cainfo"`
  8308. ErrMsg string `json:"err_msg"`
  8309. InfRefmsgid string `json:"inf_refmsgid"`
  8310. Infcode int64 `json:"infcode"`
  8311. Output struct {
  8312. DldEndtime string `json:"dld_endtime"`
  8313. FileQuryNo string `json:"file_qury_no"`
  8314. Filename string `json:"filename"`
  8315. } `json:"output"`
  8316. RefmsgTime string `json:"refmsg_time"`
  8317. RespondTime string `json:"respond_time"`
  8318. Signtype interface{} `json:"signtype"`
  8319. WarnMsg interface{} `json:"warn_msg"`
  8320. }
  8321. type ResultEleven struct {
  8322. Cainfo string `json:"cainfo"`
  8323. ErrMsg string `json:"err_msg"`
  8324. InfRefmsgid string `json:"inf_refmsgid"`
  8325. Infcode int64 `json:"infcode"`
  8326. Output struct {
  8327. Setlinfo struct {
  8328. FixmedinsName string `json:"fixmedins_name"`
  8329. FixmedinsCode string `json:"fixmedins_code"`
  8330. PsnNo string `json:"psn_no"`
  8331. PsnName string `json:"psn_name"`
  8332. HifobPay float64 `json:"hifob_pay"`
  8333. Gend string `json:"gend"`
  8334. Brdy string `json:"brdy"`
  8335. PsnCertType string `json:"psn_cert_type"`
  8336. PsnType string `json:"psn_type"`
  8337. EmpName string `json:"emp_name"`
  8338. Certno string `json:"certno"`
  8339. Insutype string `json:"insutype"`
  8340. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8341. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8342. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8343. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8344. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8345. ActPayDedc float64 `json:"act_pay_dedc"`
  8346. HifpPay float64 `json:"hifp_pay"`
  8347. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8348. CvlservPay float64 `json:"cvlserv_pay"`
  8349. HifesPay float64 `json:"hifes_pay"`
  8350. HifmiPay float64 `json:"hifmi_pay"`
  8351. MafPay float64 `json:"maf_pay"`
  8352. OthPay float64 `json:"oth_pay"`
  8353. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8354. PsnPay float64 `json:"psn_pay"`
  8355. AcctPay float64 `json:"acct_pay"`
  8356. CashPayamt float64 `json:"cash_payamt"`
  8357. Balc float64 `json:"balc"`
  8358. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8359. MedinsSetlId string `json:"medins_setl_id"`
  8360. RefdSetlFlag string `json:"refd_setl_flag"`
  8361. SetlTime string `json:"setl_time"`
  8362. MedType string `json:"med_type"`
  8363. } `json:"setlinfo"`
  8364. } `json:"output"`
  8365. RefmsgTime string `json:"refmsg_time"`
  8366. RespondTime string `json:"respond_time"`
  8367. Signtype interface{} `json:"signtype"`
  8368. WarnMsg interface{} `json:"warn_msg"`
  8369. }
  8370. type Custom struct {
  8371. DetItemFeeSumamt string
  8372. Cut string
  8373. FeedetlSn string
  8374. Price string
  8375. MedListCodg string
  8376. Type int64
  8377. AdviceId int64
  8378. ProjectId int64
  8379. ItemId int64
  8380. CostType int64
  8381. }
  8382. // 获取个人信息----挂号-----上传就诊信息
  8383. func (c *HisApiController) GetRegisterInfo() {
  8384. id, _ := c.GetInt64("id")
  8385. record_time := c.GetString("record_time")
  8386. settlementValue, _ := c.GetInt64("settlement_value")
  8387. medical_insurance_card := c.GetString("medical_insurance_card")
  8388. name := c.GetString("name")
  8389. id_card_type, _ := c.GetInt64("id_card_type")
  8390. certificates, _ := c.GetInt64("certificates")
  8391. medical_care, _ := c.GetInt64("medical_care")
  8392. birthday := c.GetString("birthday")
  8393. age, _ := c.GetInt64("age")
  8394. id_card := c.GetString("id_card")
  8395. register_type, _ := c.GetInt64("register")
  8396. doctor, _ := c.GetInt64("doctor")
  8397. department, _ := c.GetInt64("department")
  8398. gender, _ := c.GetInt64("sex")
  8399. phone := c.GetString("phone")
  8400. registration_fee, _ := c.GetFloat("registration_fee")
  8401. medical_expenses, _ := c.GetFloat("medical_expenses")
  8402. social_type, _ := c.GetInt64("social_type")
  8403. //diagnosis_id, _ := c.GetInt64("diagnosis")
  8404. diagnosis_ids := c.GetString("diagnosis")
  8405. sick_type, _ := c.GetInt64("sick_type")
  8406. reg_type := c.GetString("p_type")
  8407. timeLayout := "2006-01-02"
  8408. loc, _ := time.LoadLocation("Local")
  8409. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  8410. birthUnix := birthdays.Unix()
  8411. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8412. if err != nil {
  8413. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8414. return
  8415. }
  8416. recordDateTime := theTime.Unix()
  8417. adminInfo := c.GetAdminUserInfo()
  8418. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  8419. if tempPatient.ID == 0 {
  8420. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  8421. return
  8422. }
  8423. var patient service.Patients
  8424. if id == 0 {
  8425. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  8426. } else {
  8427. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  8428. }
  8429. if patient.ID == 0 {
  8430. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  8431. return
  8432. }
  8433. if len(patient.IdCardNo) == 0 {
  8434. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  8435. return
  8436. }
  8437. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  8438. if len(his) >= 1 {
  8439. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  8440. if len(his) >= 1 && order.ID == 0 {
  8441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  8442. return
  8443. }
  8444. }
  8445. timeStr := time.Now().Format("2006-01-02 15:04:05")
  8446. fmt.Println(timeStr)
  8447. timeArr := strings.Split(timeStr, " ")
  8448. fmt.Println(timeArr)
  8449. timeArrTwo := strings.Split(timeArr[0], "-")
  8450. timeArrThree := strings.Split(timeArr[1], ":")
  8451. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  8452. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  8453. if len(lists) == 0 {
  8454. var hisPatient models.XtHisPatient
  8455. hisPatient = models.XtHisPatient{
  8456. Name: name,
  8457. Age: age,
  8458. Gender: gender,
  8459. Birthday: birthUnix,
  8460. Phone: phone,
  8461. MedicalTreatmentType: medical_care,
  8462. IdType: certificates,
  8463. IdCardNo: id_card,
  8464. BalanceAccountsType: settlementValue,
  8465. SocialType: social_type,
  8466. MedicalInsuranceNumber: medical_insurance_card,
  8467. RegisterType: register_type,
  8468. RegisterCost: registration_fee,
  8469. TreatmentCost: medical_expenses,
  8470. AdminUserId: adminInfo.AdminUser.Id,
  8471. UserOrgId: adminInfo.CurrentOrgId,
  8472. Status: 1,
  8473. RecordDate: recordDateTime,
  8474. IsReturn: 1,
  8475. PatientId: patient.ID,
  8476. Ctime: time.Now().Unix(),
  8477. Mtime: time.Now().Unix(),
  8478. Number: str,
  8479. IdCardType: id_card_type,
  8480. Departments: department,
  8481. Doctor: doctor,
  8482. PType: reg_type,
  8483. Diagnosis: diagnosis_ids,
  8484. SickType: sick_type,
  8485. }
  8486. service.CreateHisPatient(&hisPatient)
  8487. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  8488. c.ServeSuccessJSON(map[string]interface{}{
  8489. "his_info": hisPatient,
  8490. })
  8491. } else {
  8492. //chrgBchno := rand.Intn(1000000) + 10000
  8493. var hisPatient models.XtHisPatient
  8494. hisPatient = models.XtHisPatient{
  8495. Name: name,
  8496. Age: age,
  8497. Gender: gender,
  8498. Birthday: birthUnix,
  8499. Phone: phone,
  8500. MedicalTreatmentType: medical_care,
  8501. IdType: certificates,
  8502. IdCardNo: id_card,
  8503. BalanceAccountsType: settlementValue,
  8504. SocialType: social_type,
  8505. MedicalInsuranceNumber: medical_insurance_card,
  8506. RegisterType: register_type,
  8507. RegisterCost: registration_fee,
  8508. TreatmentCost: medical_expenses,
  8509. AdminUserId: adminInfo.AdminUser.Id,
  8510. UserOrgId: adminInfo.CurrentOrgId,
  8511. Status: 1,
  8512. RecordDate: recordDateTime,
  8513. IsReturn: 1,
  8514. PatientId: patient.ID,
  8515. Ctime: time.Now().Unix(),
  8516. Mtime: time.Now().Unix(),
  8517. Number: str,
  8518. IdCardType: id_card_type,
  8519. Departments: department,
  8520. Doctor: doctor,
  8521. PType: reg_type,
  8522. Diagnosis: diagnosis_ids,
  8523. SickType: sick_type,
  8524. }
  8525. service.CreateHisPatient(&hisPatient)
  8526. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  8527. c.ServeSuccessJSON(map[string]interface{}{
  8528. "his_info": hisPatient,
  8529. })
  8530. }
  8531. }
  8532. // 上传明细----结算
  8533. func (c *HisApiController) GetUploadInfo() {
  8534. id, _ := c.GetInt64("id")
  8535. record_time := c.GetString("record_time")
  8536. his_patient_id, _ := c.GetInt64("his_patient_id")
  8537. oth_desc := c.GetString("oth_desc")
  8538. pay_way, _ := c.GetInt64("pay_way")
  8539. pay_ways := c.GetString("pay_ways")
  8540. pay_price, _ := c.GetFloat("pay_price")
  8541. pay_card_no := c.GetString("pay_card_no")
  8542. discount_price, _ := c.GetFloat("discount_price")
  8543. preferential_price, _ := c.GetFloat("preferential_price")
  8544. reality_price, _ := c.GetFloat("reality_price")
  8545. found_price, _ := c.GetFloat("found_price")
  8546. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  8547. private_price, _ := c.GetFloat("private_price")
  8548. timeLayout := "2006-01-02"
  8549. loc, _ := time.LoadLocation("Local")
  8550. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  8551. fapiao_code := c.GetString("fapiao_code")
  8552. fapiao_number := c.GetString("fapiao_number")
  8553. diagnosis_id := c.GetString("diagnosis")
  8554. sick_type, _ := c.GetInt64("sick_type")
  8555. reg_type, _ := c.GetInt64("p_type")
  8556. order_id, _ := c.GetInt64("order_id")
  8557. cash_pay := c.GetString("cash_pay")
  8558. wechat_pay := c.GetString("wechat_pay")
  8559. ali_pay := c.GetString("ali_pay")
  8560. jifen_pay := c.GetString("jifen_pay")
  8561. band_card_pay := c.GetString("band_card_pay")
  8562. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  8563. tmp_decimal := c.GetString("tmp_decimal")
  8564. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  8565. var decimal float64 //本次使用的押金
  8566. var errmsg error
  8567. tx := service.XTWriteDB().Begin() //开了事务
  8568. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  8569. defer func() {
  8570. if errmsg != nil {
  8571. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  8572. tx.Rollback()
  8573. } else {
  8574. tx.Commit()
  8575. }
  8576. }()
  8577. fmt.Println("dec_way", dec_way)
  8578. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  8579. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  8580. return
  8581. }
  8582. if len(tmp_decimal) > 0 {
  8583. if tmp_decimal[0] == 45 {
  8584. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  8585. return
  8586. }
  8587. }
  8588. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  8589. fmt.Println(errs)
  8590. decimal = tt
  8591. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  8592. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  8593. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8594. if err != nil {
  8595. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8596. return
  8597. }
  8598. recordDateTime := theTime.Unix()
  8599. adminUser := c.GetAdminUserInfo()
  8600. var prescriptions []*models.HisPrescription
  8601. var prescriptionsOne []*models.HisPrescription
  8602. var start_time int64
  8603. var end_time int64
  8604. ids_str := c.GetString("ids")
  8605. ids_arr := strings.Split(ids_str, ",")
  8606. if tempOrder.ID == 0 {
  8607. if settle_accounts_type == 1 { //日结
  8608. fmt.Println(reg_type)
  8609. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  8610. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  8611. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  8612. } else {
  8613. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8614. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8615. }
  8616. } else { //月结
  8617. start_time_str := c.GetString("start_time")
  8618. end_time_str := c.GetString("end_time")
  8619. timeLayout := "2006-01-02"
  8620. loc, _ := time.LoadLocation("Local")
  8621. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  8622. if err != nil {
  8623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8624. return
  8625. }
  8626. recordStartTime := theStartTime.Unix()
  8627. start_time = recordStartTime
  8628. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  8629. if err != nil {
  8630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8631. return
  8632. }
  8633. recordEndTime := theEndTime.Unix()
  8634. end_time = recordEndTime
  8635. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  8636. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8637. }
  8638. var goods []*models.DialysisBeforePrepareGoods
  8639. var newGoods []*models.NewDialysisBeforePrepareGoods
  8640. var oldGoods []*models.OldDialysisBeforePrepareGoods
  8641. var infos []*models.HisDoctorAdviceInfo
  8642. var infoList []*models.HisDoctorAdviceInfo
  8643. var hisAdvice []*models.HisDoctorAdviceInfo
  8644. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  8645. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  8646. //判断库存不足
  8647. //结算出库开关
  8648. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  8649. if settConfig.IsOpen == 1 {
  8650. //判断库存的地方
  8651. for _, info := range prescriptions {
  8652. if info.Type == 1 {
  8653. infos = append(infos, info.HisDoctorAdviceInfo...)
  8654. }
  8655. if info.Type == 2 {
  8656. for _, sumItem := range info.HisPrescriptionProject {
  8657. if sumItem.Type == 3 {
  8658. var good models.DialysisBeforePrepareGoods
  8659. var newGood models.NewDialysisBeforePrepareGoods
  8660. good.GoodId = sumItem.GoodInfo.ID
  8661. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8662. count, _ := strconv.Atoi(sumItem.Count)
  8663. good.Count = int64(count)
  8664. good.StorehouseId = houseConfig.StorehouseOutInfo
  8665. good.ProjectId = sumItem.ID
  8666. goods = append(goods, &good)
  8667. newGood.GoodId = sumItem.GoodInfo.ID
  8668. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8669. count2, _ := strconv.Atoi(sumItem.Count)
  8670. newGood.Count = int64(count2)
  8671. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8672. newGood.ProjectId = sumItem.ID
  8673. newGoods = append(newGoods, &newGood)
  8674. }
  8675. }
  8676. }
  8677. }
  8678. for _, info := range prescriptionsOne {
  8679. if info.Type == 1 {
  8680. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  8681. }
  8682. if info.Type == 2 {
  8683. for _, sumItem := range info.HisPrescriptionProject {
  8684. if sumItem.Type == 3 {
  8685. var newGood models.NewDialysisBeforePrepareGoods
  8686. newGood.GoodId = sumItem.GoodInfo.ID
  8687. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8688. count2, _ := strconv.Atoi(sumItem.Count)
  8689. newGood.Count = int64(count2)
  8690. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8691. newGood.ProjectId = sumItem.ID
  8692. newGoodOne = append(newGoodOne, &newGood)
  8693. }
  8694. }
  8695. }
  8696. }
  8697. //判断
  8698. for _, itemOne := range infos {
  8699. for _, itemTwo := range hisAdvice {
  8700. if itemOne.DrugId == itemTwo.DrugId {
  8701. itemTwo.Child = append(itemTwo.Child, itemOne)
  8702. }
  8703. }
  8704. }
  8705. for _, itemTwo := range hisAdvice {
  8706. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  8707. var sum_out_count int64
  8708. for _, itemThree := range itemTwo.Child {
  8709. var prescribing_number int64
  8710. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8711. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8712. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8713. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8714. }
  8715. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8716. prescribing_number = parseIntPrescribingNumber
  8717. }
  8718. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8719. prescribing_number = parseIntPrescribingNumber
  8720. }
  8721. sum_out_count += prescribing_number
  8722. }
  8723. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  8724. if sum_out_count > drugStockOut.FlushCount {
  8725. c.ServeSuccessJSON(map[string]interface{}{
  8726. "msg": "2",
  8727. "drug": medical,
  8728. })
  8729. return
  8730. }
  8731. }
  8732. for _, itemOne := range newGoods {
  8733. for _, item := range newGoodOne {
  8734. if itemOne.GoodId == item.GoodId {
  8735. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  8736. }
  8737. }
  8738. }
  8739. for _, item := range newGoodOne {
  8740. var sum_out_count_one int64
  8741. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  8742. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  8743. sum_out_count_one += itemOne.Count
  8744. }
  8745. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8746. fmt.Println("sum_out_count_one", sum_out_count_one)
  8747. fmt.Println("list.FlushCount", list.FlushCount)
  8748. if sum_out_count_one > list.FlushCount {
  8749. c.ServeSuccessJSON(map[string]interface{}{
  8750. "msg": "3",
  8751. "good": good,
  8752. })
  8753. return
  8754. }
  8755. }
  8756. }
  8757. timestamp := time.Now().Unix()
  8758. tempTime := time.Unix(timestamp, 0)
  8759. timeFormat := tempTime.Format("20060102150405")
  8760. chrgBchno := rand.Intn(100000) + 10000
  8761. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  8762. strconv.FormatInt(his.PatientId, 10)
  8763. var ids []int64
  8764. for _, item := range prescriptions {
  8765. ids = append(ids, item.ID)
  8766. }
  8767. var total float64
  8768. for _, item := range prescriptions {
  8769. fmt.Println(item)
  8770. if item.Type == 1 { //药品
  8771. for _, subItem := range item.HisDoctorAdviceInfo {
  8772. total = total + (subItem.Price * subItem.PrescribingNumber)
  8773. }
  8774. }
  8775. if item.Type == 2 { //项目
  8776. for _, subItem := range item.HisPrescriptionProject {
  8777. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8778. total = total + (subItem.Price * cnt)
  8779. }
  8780. }
  8781. for _, subItem := range item.HisAdditionalCharge {
  8782. total = total + (subItem.Price * float64(subItem.Count))
  8783. }
  8784. }
  8785. if reg_type == 1111 || reg_type == 1112 {
  8786. reg_type = 11
  8787. }
  8788. tm := time.Unix(time.Now().Unix(), 0)
  8789. allTotal := fmt.Sprintf("%.4f", total)
  8790. totals, _ := strconv.ParseFloat(allTotal, 64)
  8791. order := &models.HisOrder{
  8792. UserOrgId: adminUser.CurrentOrgId,
  8793. HisPatientId: his.ID,
  8794. PatientId: id,
  8795. SettleAccountsDate: recordDateTime,
  8796. Ctime: time.Now().Unix(),
  8797. Mtime: time.Now().Unix(),
  8798. Status: 1,
  8799. OrderStatus: 2,
  8800. MdtrtId: his.Number,
  8801. Number: chrg_bchno,
  8802. MedfeeSumamt: totals,
  8803. PayWay: pay_way,
  8804. PayWays: pay_ways,
  8805. PayPrice: pay_price,
  8806. MedType: strconv.Itoa(int(reg_type)),
  8807. PayCardNo: pay_card_no,
  8808. DiscountPrice: discount_price,
  8809. PreferentialPrice: preferential_price,
  8810. RealityPrice: reality_price,
  8811. FoundPrice: found_price,
  8812. MedicalInsurancePrice: medical_insurance_price,
  8813. PrivatePrice: private_price,
  8814. SettleEndTime: end_time,
  8815. SettleStartTime: start_time,
  8816. PsnPartAmt: totals,
  8817. PsnCashPay: totals,
  8818. SettleType: settle_accounts_type,
  8819. FaPiaoCode: fapiao_code,
  8820. FaPiaoNumber: fapiao_number,
  8821. Diagnosis: diagnosis_id,
  8822. PType: 2,
  8823. SetlTime: tm.Format("2006-01-02 15:04:05"),
  8824. Decimal: decimal,
  8825. OthDesc: oth_desc,
  8826. CashPay: cash_pay,
  8827. WechatPay: wechat_pay,
  8828. AliPay: ali_pay,
  8829. JifenPay: jifen_pay,
  8830. BandCardPay: band_card_pay,
  8831. Creator: adminUser.AdminUser.Id,
  8832. }
  8833. err = service.CreateOrderTX(order, tx)
  8834. if err != nil {
  8835. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8836. return
  8837. }
  8838. var customs []*Custom
  8839. for _, item := range prescriptions {
  8840. if item.Type == 1 { //药品a
  8841. for _, subItem := range item.HisDoctorAdviceInfo {
  8842. cus := &Custom{
  8843. AdviceId: subItem.ID,
  8844. ProjectId: 0,
  8845. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  8846. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  8847. FeedetlSn: subItem.FeedetlSn,
  8848. Price: fmt.Sprintf("%.4f", subItem.Price),
  8849. MedListCodg: subItem.MedListCodg,
  8850. Type: 1,
  8851. CostType: 9,
  8852. }
  8853. customs = append(customs, cus)
  8854. }
  8855. }
  8856. if item.Type == 2 { //项目
  8857. for _, subItem := range item.HisPrescriptionProject {
  8858. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8859. cus := &Custom{
  8860. AdviceId: 0,
  8861. ProjectId: subItem.ID,
  8862. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  8863. Cut: fmt.Sprintf("%.4f", cnt),
  8864. FeedetlSn: subItem.FeedetlSn,
  8865. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  8866. MedListCodg: subItem.MedListCodg,
  8867. Type: 2,
  8868. CostType: subItem.HisProject.CostClassify,
  8869. }
  8870. customs = append(customs, cus)
  8871. }
  8872. }
  8873. for _, item := range item.HisAdditionalCharge {
  8874. cus := &Custom{
  8875. ItemId: item.ID,
  8876. AdviceId: 0,
  8877. ProjectId: 0,
  8878. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  8879. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  8880. FeedetlSn: item.FeedetlSn,
  8881. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  8882. MedListCodg: item.XtHisAddtionConfig.Code,
  8883. Type: 3,
  8884. CostType: 5,
  8885. }
  8886. customs = append(customs, cus)
  8887. }
  8888. }
  8889. for _, item := range customs {
  8890. var advice_id int64 = 0
  8891. var project_id int64 = 0
  8892. var item_id int64 = 0
  8893. var types int64 = 0
  8894. var med_chrgitm_type string
  8895. if item.Type == 1 {
  8896. advice_id = item.AdviceId
  8897. project_id = 0
  8898. item_id = 0
  8899. med_chrgitm_type = "09"
  8900. } else if item.Type == 2 {
  8901. med_chrgitm_type = "05"
  8902. if item.CostType == 3 {
  8903. med_chrgitm_type = "04"
  8904. }
  8905. if item.CostType == 8 {
  8906. med_chrgitm_type = "03"
  8907. }
  8908. advice_id = 0
  8909. item_id = 0
  8910. project_id = item.ProjectId
  8911. } else if item.Type == 3 {
  8912. advice_id = 0
  8913. item_id = item.ItemId
  8914. project_id = 0
  8915. med_chrgitm_type = "08"
  8916. }
  8917. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8918. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8919. pric, _ := strconv.ParseFloat(item.Price, 32)
  8920. info := &models.HisOrderInfo{
  8921. OrderNumber: order.Number,
  8922. UploadDate: time.Now().Unix(),
  8923. AdviceId: advice_id,
  8924. DetItemFeeSumamt: detItemFeeSumamt,
  8925. MedChrgitmType: med_chrgitm_type,
  8926. Cnt: cut,
  8927. Pric: pric,
  8928. PatientId: id,
  8929. Status: 1,
  8930. Mtime: time.Now().Unix(),
  8931. Ctime: time.Now().Unix(),
  8932. UserOrgId: adminUser.CurrentOrgId,
  8933. HisPatientId: his.ID,
  8934. OrderId: order.ID,
  8935. ProjectId: project_id,
  8936. Type: types,
  8937. ItemId: item_id,
  8938. }
  8939. service.CreateOrderInfoTX(info, tx)
  8940. }
  8941. his.Diagnosis = diagnosis_id
  8942. his.SickType = sick_type
  8943. his.RegisterType = reg_type
  8944. his.MedicalTreatmentType = reg_type
  8945. service.UpdataHisPateintTX(&his, tx)
  8946. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  8947. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  8948. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  8949. //判断是否使用了押金
  8950. if dec_way == "true" {
  8951. tmpstring := strconv.FormatInt(order.ID, 10)
  8952. //扣押金
  8953. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  8954. order.Decimal = decimal
  8955. service.UpDateOrderTwo(order, tx)
  8956. if errmsg != nil {
  8957. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  8958. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8959. return
  8960. }
  8961. }
  8962. if err == nil {
  8963. for _, info := range prescriptions {
  8964. if info.Type == 1 {
  8965. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  8966. }
  8967. if info.Type == 2 {
  8968. for _, sumItem := range info.HisPrescriptionProject {
  8969. if sumItem.Type == 3 {
  8970. var good models.DialysisBeforePrepareGoods
  8971. var newGood models.NewDialysisBeforePrepareGoods
  8972. var oldGood models.OldDialysisBeforePrepareGoods
  8973. good.GoodId = sumItem.GoodInfo.ID
  8974. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8975. count, _ := strconv.Atoi(sumItem.Count)
  8976. good.Count = int64(count)
  8977. good.StorehouseId = houseConfig.StorehouseOutInfo
  8978. good.ProjectId = sumItem.ID
  8979. good.PatientId = sumItem.PatientId
  8980. goods = append(goods, &good)
  8981. newGood.GoodId = sumItem.GoodInfo.ID
  8982. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8983. count2, _ := strconv.Atoi(sumItem.Count)
  8984. newGood.Count = int64(count2)
  8985. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8986. newGood.ProjectId = sumItem.ID
  8987. newGood.PatientId = sumItem.HisPatientId
  8988. newGoods = append(newGoods, &newGood)
  8989. oldGood.GoodId = sumItem.GoodInfo.ID
  8990. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8991. count3, _ := strconv.Atoi(sumItem.Count)
  8992. oldGood.Count = int64(count3)
  8993. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  8994. oldGood.ProjectId = sumItem.ID
  8995. oldGood.RecordDate = sumItem.RecordDate
  8996. oldGood.PatientId = sumItem.HisPatientId
  8997. oldGoods = append(oldGoods, &oldGood)
  8998. }
  8999. }
  9000. }
  9001. }
  9002. if settConfig.IsOpen == 1 {
  9003. for _, item := range infoList {
  9004. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9005. if medical.IsUse == 2 {
  9006. //药品出库
  9007. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  9008. //查询默认仓库
  9009. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  9010. //查询默认仓库剩余多少库存
  9011. var sum_count int64
  9012. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9013. for _, its := range stockInfo {
  9014. if its.MaxUnit == medical.MaxUnit {
  9015. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9016. }
  9017. sum_count += its.StockMaxNumber + its.StockMinNumber
  9018. }
  9019. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9020. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9021. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  9022. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  9023. }
  9024. }
  9025. orgId := c.GetAdminUserInfo().CurrentOrgId
  9026. if len(oldGoods) > 0 {
  9027. timeStr := time.Now().Format("2006-01-02")
  9028. timeArr := strings.Split(timeStr, "-")
  9029. total, _ := service.FindAllWarehouseOut(orgId)
  9030. total = total + 1
  9031. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  9032. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  9033. number = number + total
  9034. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  9035. operation_time := time.Now().Unix()
  9036. creater := c.GetAdminUserInfo().AdminUser.Id
  9037. //查询默认出库仓库库存
  9038. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9039. recordDateStr := time.Now().Format("2006-01-02")
  9040. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9041. nowtime := recordDate.Unix()
  9042. warehouseOut := models.WarehouseOut{
  9043. WarehouseOutOrderNumber: warehousing_out_order,
  9044. OperationTime: operation_time,
  9045. OrgId: orgId,
  9046. Creater: creater,
  9047. Ctime: time.Now().Unix(),
  9048. Status: 1,
  9049. WarehouseOutTime: nowtime,
  9050. Type: 1,
  9051. StorehouseId: storeConfig.StorehouseOutInfo,
  9052. IsCheck: 1,
  9053. OrderId: order.ID,
  9054. IsSys: 5,
  9055. }
  9056. //查询是否生成出库单
  9057. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9058. if out.ID == 0 {
  9059. service.AddSigleWarehouseOut(&warehouseOut)
  9060. }
  9061. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9062. for _, item := range oldGoods {
  9063. dialyPrepareOne := models.DialysisBeforePrepare{
  9064. GoodTypeId: item.GoodTypeId,
  9065. GoodId: item.GoodId,
  9066. PatientId: his.PatientId,
  9067. RecordDate: item.RecordDate,
  9068. UserOrgId: adminUser.CurrentOrgId,
  9069. Count: item.Count,
  9070. Ctime: time.Now().Unix(),
  9071. Creater: adminUser.AdminUser.Id,
  9072. CommdityCode: item.CommdityCode,
  9073. Status: 1,
  9074. StorehouseId: houseConfig.StorehouseOutInfo,
  9075. }
  9076. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  9077. //非零用
  9078. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  9079. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9080. //查询剩余库存
  9081. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9082. var sum_count int64
  9083. for _, item := range goodList {
  9084. sum_count += item.StockCount
  9085. }
  9086. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9087. //耗材
  9088. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9089. }
  9090. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  9091. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9092. //查询剩余库存
  9093. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9094. var sum_count int64
  9095. for _, item := range goodList {
  9096. sum_count += item.StockCount
  9097. }
  9098. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9099. //耗材
  9100. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9101. }
  9102. }
  9103. }
  9104. }
  9105. c.ServeSuccessJSON(map[string]interface{}{
  9106. "msg": "结算成功",
  9107. })
  9108. }
  9109. }
  9110. }
  9111. // 退款
  9112. func (c *HisApiController) Refund() {
  9113. order_id, _ := c.GetInt64("order_id")
  9114. order, _ := service.GetHisOrderByID(order_id)
  9115. adminUser := c.GetAdminUserInfo()
  9116. orgid := c.GetAdminUserInfo().CurrentOrgId
  9117. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  9118. if err != nil {
  9119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9120. return
  9121. }
  9122. tmp := strconv.FormatInt(order.ID, 10)
  9123. //当押金不为零时产生退费记录
  9124. if order.Decimal != 0 {
  9125. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  9126. if err != nil {
  9127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9128. return
  9129. }
  9130. }
  9131. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  9132. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  9133. var goods []*models.DialysisBeforePrepareGoods
  9134. var newGoods []*models.NewDialysisBeforePrepareGoods
  9135. var infos []*models.HisDoctorAdviceInfo
  9136. for _, info := range orders {
  9137. if info.AdviceId > 0 && info.ProjectId == 0 {
  9138. infos = append(infos, &info.HisDoctorAdviceInfo)
  9139. }
  9140. if info.ProjectId > 0 && info.AdviceId == 0 {
  9141. if info.HisPrescriptionProject.Type == 3 {
  9142. var good models.DialysisBeforePrepareGoods
  9143. var newGood models.NewDialysisBeforePrepareGoods
  9144. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9145. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9146. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9147. good.Count = int64(count)
  9148. good.StorehouseId = houseConfig.StorehouseOutInfo
  9149. good.ProjectId = info.HisPrescriptionProject.ID
  9150. good.PatientId = info.PatientId
  9151. good.OrderId = order_id
  9152. goods = append(goods, &good)
  9153. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9154. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9155. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9156. newGood.Count = int64(count2)
  9157. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9158. newGood.ProjectId = info.HisPrescriptionProject.ID
  9159. newGood.RecordDate = order.SettleAccountsDate
  9160. newGood.UserOrgId = order.UserOrgId
  9161. newGood.PatientId = info.PatientId
  9162. newGood.OrderId = order_id
  9163. newGoods = append(newGoods, &newGood)
  9164. }
  9165. }
  9166. }
  9167. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9168. if settConfig.IsOpen == 1 {
  9169. for _, item := range infos {
  9170. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9171. }
  9172. for _, item := range newGoods {
  9173. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9174. }
  9175. }
  9176. c.ServeSuccessJSON(map[string]interface{}{
  9177. "msg": "退费成功",
  9178. })
  9179. }
  9180. func (c *HisApiController) RefundNumber() {
  9181. his_patient_id, _ := c.GetInt64("id")
  9182. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9183. info.Status = 0
  9184. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  9185. if count > 0 {
  9186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  9187. return
  9188. }
  9189. err := service.SaveHisPatient(info)
  9190. if err == nil {
  9191. c.ServeSuccessJSON(map[string]interface{}{
  9192. "msg": "退号成功",
  9193. })
  9194. } else {
  9195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9196. return
  9197. }
  9198. }
  9199. func (this *HisApiController) AdditionalCharge() {
  9200. dataBody := make(map[string]interface{}, 0)
  9201. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  9202. fmt.Println(err)
  9203. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  9204. patient_id := int64(dataBody["patient_id"].(float64))
  9205. medicineData, _ := dataBody["medicineData"].([]interface{})
  9206. adminUserInfo := this.GetAdminUserInfo()
  9207. orgId := adminUserInfo.CurrentOrgId
  9208. admin_user_id := adminUserInfo.AdminUser.Id
  9209. timeStr := time.Now().Format("2006-01-02")
  9210. timeLayout := "2006-01-02 15:04:05"
  9211. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9212. timenow := timeStringToTime.Unix()
  9213. var additionalCharges []*models.HisAdditionalCharge
  9214. for _, item := range medicineData {
  9215. var randNum int
  9216. randNum = rand.Intn(10000) + 1000
  9217. timestamp := time.Now().Unix()
  9218. tempTime := time.Unix(timestamp, 0)
  9219. timeFormat := tempTime.Format("20060102150405")
  9220. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  9221. items := item.(map[string]interface{})
  9222. money := items["price"].(string)
  9223. item_id_str := items["item_id"].(string)
  9224. name := items["name"].(string)
  9225. id_str := items["id"].(string)
  9226. moneys, _ := strconv.ParseInt(money, 10, 64)
  9227. monStr := strconv.FormatInt(moneys, 10)
  9228. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  9229. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  9230. id, _ := strconv.ParseInt(id_str, 10, 64)
  9231. additionalCharge := &models.HisAdditionalCharge{
  9232. ID: id,
  9233. HisPatientId: his_patient_id,
  9234. UserOrgId: orgId,
  9235. PatientId: patient_id,
  9236. RecordDate: timenow,
  9237. Price: monneyStr,
  9238. Status: 1,
  9239. ItemName: name,
  9240. ItemId: item_id,
  9241. AdminUserId: admin_user_id,
  9242. CreatedTime: time.Now().Unix(),
  9243. OrderStatus: 0,
  9244. PrescriptionNumber: "",
  9245. BatchNumber: "",
  9246. FeedetlSn: p_number,
  9247. }
  9248. service.CreateAdditionalCharge(additionalCharge)
  9249. additionalCharges = append(additionalCharges, additionalCharge)
  9250. }
  9251. this.ServeSuccessJSON(map[string]interface{}{
  9252. "msg": "添加成功",
  9253. "additional_charges": additionalCharges,
  9254. })
  9255. }
  9256. func (this *HisApiController) DeleteAddition() {
  9257. id, _ := this.GetInt64("id")
  9258. //TODO 需要判断是否已经结算
  9259. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  9260. if err == nil {
  9261. this.ServeSuccessJSON(map[string]interface{}{
  9262. "msg": "删除成功",
  9263. })
  9264. return
  9265. } else {
  9266. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9267. return
  9268. }
  9269. }
  9270. func (this *HisApiController) GetAdminUsers() {
  9271. adminUser := this.GetAdminUserInfo()
  9272. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  9273. this.ServeSuccessJSON(map[string]interface{}{
  9274. "doctors": doctors,
  9275. })
  9276. }
  9277. func (this *HisApiController) GetLastOrNextHisPrescription() {
  9278. change_type, _ := this.GetInt64("type", 0)
  9279. record_date := this.GetString("record_time")
  9280. patient_id, _ := this.GetInt64("patient_id", 0)
  9281. p_type, _ := this.GetInt64("p_type", 0)
  9282. timeLayout := "2006-01-02"
  9283. loc, _ := time.LoadLocation("Local")
  9284. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  9285. record_time := theAdviceRecordTime.Unix()
  9286. adminUserInfo := this.GetAdminUserInfo()
  9287. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  9288. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  9289. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9290. if config.ID > 0 && config.IsOpen == 1 {
  9291. for _, subitems := range prescriptions {
  9292. for _, item := range subitems.VMHisPrescription {
  9293. for _, subItem := range item.HisDoctorAdviceInfo {
  9294. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9295. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9296. if info.RetailPrice > 0 {
  9297. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9298. subItem.Drug.RetailPrice = drug.RetailPrice
  9299. }
  9300. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9301. subItem.Drug.MinPrice = info.RetailPrice
  9302. subItem.Drug.RetailPrice = info.RetailPrice
  9303. }
  9304. }
  9305. }
  9306. }
  9307. }
  9308. }
  9309. if config.ID > 0 && config.IsOpen == 1 {
  9310. for _, subitems := range prescriptions {
  9311. for _, item := range subitems.VMHisPrescription {
  9312. for _, subItem := range item.HisPrescriptionProject {
  9313. if subItem.Type == 3 {
  9314. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9315. if info.Price > 0 {
  9316. subItem.GoodInfo.PackingPrice = info.Price
  9317. }
  9318. }
  9319. }
  9320. }
  9321. }
  9322. }
  9323. }
  9324. if err == nil {
  9325. if len(prescriptions) == 0 {
  9326. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  9327. return
  9328. } else {
  9329. this.ServeSuccessJSON(map[string]interface{}{
  9330. "prescriptions": prescriptions,
  9331. })
  9332. return
  9333. }
  9334. } else {
  9335. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9336. return
  9337. }
  9338. }
  9339. func (this *HisApiController) GetCallHisPrescription() {
  9340. patient_id, _ := this.GetInt64("patient_id", 0)
  9341. timeLayout := "2006-01-02"
  9342. loc, _ := time.LoadLocation("Local")
  9343. start_time := this.GetString("start_time")
  9344. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9345. end_time := this.GetString("end_time")
  9346. p_type, _ := this.GetInt64("p_type")
  9347. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9348. adminUserInfo := this.GetAdminUserInfo()
  9349. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  9350. //if
  9351. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  9352. //
  9353. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  9354. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  9355. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9356. if config.ID > 0 && config.IsOpen == 1 {
  9357. for _, subitems := range prescriptions {
  9358. for _, item := range subitems.VMHisPrescription {
  9359. for _, subItem := range item.HisDoctorAdviceInfo {
  9360. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9361. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9362. if info.RetailPrice > 0 {
  9363. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9364. subItem.Drug.RetailPrice = drug.RetailPrice
  9365. }
  9366. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9367. subItem.Drug.MinPrice = info.RetailPrice
  9368. subItem.Drug.RetailPrice = info.RetailPrice
  9369. }
  9370. }
  9371. }
  9372. }
  9373. }
  9374. }
  9375. if config.ID > 0 && config.IsOpen == 1 {
  9376. for _, subitems := range prescriptions {
  9377. for _, item := range subitems.VMHisPrescription {
  9378. for _, subItem := range item.HisPrescriptionProject {
  9379. if subItem.Type == 3 {
  9380. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9381. if info.Price > 0 {
  9382. subItem.GoodInfo.PackingPrice = info.Price
  9383. }
  9384. }
  9385. }
  9386. }
  9387. }
  9388. }
  9389. }
  9390. if err == nil {
  9391. this.ServeSuccessJSON(map[string]interface{}{
  9392. "prescriptions": prescriptions,
  9393. })
  9394. return
  9395. } else {
  9396. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9397. return
  9398. }
  9399. }
  9400. func (this *HisApiController) GetHisDayPrescription() {
  9401. timeLayout := "2006-01-02"
  9402. loc, _ := time.LoadLocation("Local")
  9403. start_time := this.GetString("start_time")
  9404. patient_id, _ := this.GetInt64("patient_id", 0)
  9405. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9406. end_time := this.GetString("end_time")
  9407. p_type, _ := this.GetInt64("p_type")
  9408. order_status, _ := this.GetInt64("type")
  9409. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9410. adminUserInfo := this.GetAdminUserInfo()
  9411. var dayHisPrescription []*models.HisPrescription
  9412. var err error
  9413. if order_status == 1 || order_status == 0 {
  9414. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  9415. } else if order_status == 2 {
  9416. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  9417. }
  9418. var settle_total float64
  9419. for _, item := range dayHisPrescription {
  9420. if len(item.HisPrescriptionProject) > 0 {
  9421. for _, subItem := range item.HisPrescriptionProject {
  9422. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9423. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9424. settle_total = settle_total + total
  9425. }
  9426. }
  9427. if len(item.HisDoctorAdviceInfo) > 0 {
  9428. for _, subItem := range item.HisDoctorAdviceInfo {
  9429. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9430. settle_total = settle_total + total
  9431. }
  9432. }
  9433. }
  9434. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9435. if err == nil {
  9436. this.ServeSuccessJSON(map[string]interface{}{
  9437. "day_prescription": dayHisPrescription,
  9438. "settle_total": settle_total,
  9439. })
  9440. return
  9441. } else {
  9442. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9443. return
  9444. }
  9445. }
  9446. func (c *HisApiController) GetHisChargePatientList() {
  9447. record_date := c.GetString("record_date")
  9448. order_status, _ := c.GetInt64("type")
  9449. sch_type, _ := c.GetInt64("sch_type")
  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. adminInfo := c.GetAdminUserInfo()
  9459. var tempPatients []*service.NewTempPatients
  9460. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  9461. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  9462. if order_status != 2 {
  9463. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9464. } else {
  9465. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9466. }
  9467. } else {
  9468. if order_status != 2 {
  9469. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9470. } else {
  9471. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9472. }
  9473. }
  9474. var patients []*service.NewTempPatients
  9475. var patients_two []*service.NewTempPatients
  9476. for _, item := range tempPatients {
  9477. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  9478. //过滤掉没挂号的和没开处方的
  9479. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  9480. patients = append(patients, item)
  9481. }
  9482. //过滤掉没挂号的
  9483. if len(item.HisPatient) > 0 {
  9484. patients_two = append(patients_two, item)
  9485. }
  9486. } else {
  9487. if len(item.HisPrescription) > 0 {
  9488. patients = append(patients, item)
  9489. }
  9490. }
  9491. }
  9492. c.ServeSuccessJSON(map[string]interface{}{
  9493. "list": patients,
  9494. "list_two": patients_two,
  9495. })
  9496. }
  9497. func (c *HisApiController) GetHisUnRegisterPatientList() {
  9498. record_date := c.GetString("record_date")
  9499. timeLayout := "2006-01-02"
  9500. loc, _ := time.LoadLocation("Local")
  9501. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9502. if err != nil {
  9503. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9504. return
  9505. }
  9506. recordDateTime := theTime.Unix()
  9507. adminUser := c.GetAdminUserInfo()
  9508. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  9509. var patients []*service.Patients
  9510. for _, item := range tempPatients {
  9511. if item.HisPatient.ID == 0 {
  9512. patients = append(patients, item)
  9513. }
  9514. }
  9515. c.ServeSuccessJSON(map[string]interface{}{
  9516. "list": patients,
  9517. //"list_two": patients_two,
  9518. })
  9519. }
  9520. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  9521. newArr = make([]*service.Patients, 0)
  9522. for i := 0; i < len(patient); i++ {
  9523. repeat := false
  9524. for j := i + 1; j < len(patient); j++ {
  9525. if patient[i].ID == patient[j].ID {
  9526. repeat = true
  9527. break
  9528. }
  9529. }
  9530. if !repeat {
  9531. newArr = append(newArr, patient[i])
  9532. }
  9533. }
  9534. return
  9535. }
  9536. func (c *HisApiController) GetHisChargePatientInfo() {
  9537. patient_id, _ := c.GetInt64("patient_id")
  9538. his_patient_id, _ := c.GetInt64("his_patient_id")
  9539. record_date := c.GetString("record_date")
  9540. //start_time := c.GetString("start_time")
  9541. //end_time := c.GetString("end_time")
  9542. order_status, _ := c.GetInt64("type", 0)
  9543. p_type, _ := c.GetInt64("p_type", 0)
  9544. order_id, _ := c.GetInt64("order_id", 0)
  9545. timeLayout := "2006-01-02"
  9546. loc, _ := time.LoadLocation("Local")
  9547. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9548. if err != nil {
  9549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9550. return
  9551. }
  9552. recordDateTime := theTime.Unix()
  9553. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9554. //if err != nil {
  9555. //
  9556. //}
  9557. //startRecordDateTime := startTime.Unix()
  9558. //
  9559. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9560. //if err != nil {
  9561. //
  9562. //}
  9563. //endRecordDateTime := endTime.Unix()
  9564. admin := c.GetAdminUserInfo()
  9565. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9566. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9567. var prescriptions []*models.HisPrescription
  9568. //var unChargeMonthPrescriptions []*models.HisPrescription
  9569. order, _ := service.GetHisOrderByID(order_id)
  9570. if order_status == 1 || order_status == 0 {
  9571. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  9572. } else if order_status == 2 {
  9573. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  9574. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9575. }
  9576. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9577. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9578. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9579. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9580. //获取所有科室信息
  9581. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9582. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  9583. c.ServeSuccessJSON(map[string]interface{}{
  9584. "his_info": his_patient_info,
  9585. "xt_info": xt_patient_info,
  9586. "prescription": prescriptions,
  9587. "case_history": case_history,
  9588. "info": patientPrescriptionInfo,
  9589. "last_info": lastPatientPrescriptionInfo,
  9590. "order": order,
  9591. "doctors": doctors,
  9592. "department": department,
  9593. "sch": sch,
  9594. })
  9595. return
  9596. }
  9597. func (c *HisApiController) GetAllOrderDetail() {
  9598. order_id, _ := c.GetInt64("id", 0)
  9599. order, _ := service.GetHisOrderByID(order_id)
  9600. if order.ID == 0 {
  9601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9602. return
  9603. }
  9604. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9605. org_id := c.GetAdminUserInfo().CurrentOrgId
  9606. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9607. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9608. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9609. c.ServeSuccessJSON(map[string]interface{}{
  9610. "order": order,
  9611. "order_info": order_info,
  9612. "patient": patient,
  9613. "admin_info": adminInfo,
  9614. "hospital_record": record,
  9615. })
  9616. return
  9617. }
  9618. func (c *HisApiController) GetAllOrderDetailCollect() {
  9619. order_id, _ := c.GetInt64("id", 0)
  9620. order, _ := service.GetHisOrderByID(order_id)
  9621. if order.ID == 0 {
  9622. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9623. return
  9624. }
  9625. org_id := c.GetAdminUserInfo().CurrentOrgId
  9626. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9627. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9628. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9629. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  9630. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  9631. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9632. var bedCostTotal float64 = 0 //床位总费
  9633. //var bedCostSelfTotal float64 = 0 //床位自费
  9634. var operationCostTotal float64 = 0 //手术费
  9635. //var operationCostSelfTotal float64 = 0 //手术费
  9636. var otherCostTotal float64 = 0 //其他费用
  9637. //var otherCostSelfTotal float64 = 0 //其他费用
  9638. var materialCostTotal float64 = 0 //材料费
  9639. //var materialCostSelfTotal float64 = 0 //材料费
  9640. var westernMedicineCostTotal float64 = 0 //西药费
  9641. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  9642. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9643. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9644. var checkCostTotal float64 = 0 //检查费
  9645. //var checkCostSelfTotal float64 = 0 //检查费
  9646. var laboratoryCostTotal float64 = 0 //化验费
  9647. //var laboratoryCostSelfTotal float64 = 0 //化验费
  9648. var treatCostTotal float64 = 0 //治疗费用
  9649. //var treatCostSelfTotal float64 = 0 //治疗费用
  9650. var zhenChaCostTotal float64 = 0 //其他费用
  9651. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9652. decimal.DivisionPrecision = 2
  9653. var BalanceAccountsType int64
  9654. if his.ID > 0 {
  9655. BalanceAccountsType = his.BalanceAccountsType
  9656. } else {
  9657. BalanceAccountsType = record.BalanceAccountsType
  9658. }
  9659. if BalanceAccountsType != 2 {
  9660. for _, item := range order_info {
  9661. if org_id == 10215 {
  9662. if item.MedChrgitmType == "01" { //床位费
  9663. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9664. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9665. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9666. }
  9667. if item.MedChrgitmType == "02" { //诊察费
  9668. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9669. //zhenChaCostSelfTotal = zhenChaCostTotal
  9670. }
  9671. if item.MedChrgitmType == "03" { //检查费
  9672. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9673. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9674. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9675. }
  9676. //if item.MedChrgitmType == "02" { //检查费
  9677. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9678. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9679. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9680. //}
  9681. if item.MedChrgitmType == "04" { //化验费
  9682. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9683. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9684. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9685. }
  9686. if item.MedChrgitmType == "05" { //治疗费
  9687. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9688. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9689. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9690. }
  9691. if item.MedChrgitmType == "06" { //手术费
  9692. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9693. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9694. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9695. }
  9696. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9697. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9698. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9699. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9700. }
  9701. if item.MedChrgitmType == "09" { //西药费
  9702. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9703. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9704. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9705. }
  9706. if item.MedChrgitmType == "11" { //中成费
  9707. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9708. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9709. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9710. }
  9711. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9712. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9713. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9714. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9715. }
  9716. } else if org_id == 10188 || org_id == 10217 {
  9717. if item.MedChrgitmType == "01" { //床位费
  9718. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9719. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9720. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9721. }
  9722. if item.MedChrgitmType == "02" { //诊察费
  9723. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9724. //zhenChaCostSelfTotal = zhenChaCostTotal
  9725. }
  9726. if item.MedChrgitmType == "03" { //检查费
  9727. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9728. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9729. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9730. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9731. }
  9732. //if item.MedChrgitmType == "02" { //检查费
  9733. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9734. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9735. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9736. //}
  9737. if item.MedChrgitmType == "04" { //化验费
  9738. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9739. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9740. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9741. }
  9742. if item.MedChrgitmType == "05" { //治疗费
  9743. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9744. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9745. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9746. }
  9747. if item.MedChrgitmType == "06" { //手术费
  9748. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9749. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9750. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9751. }
  9752. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9753. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9754. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9755. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9756. }
  9757. if item.MedChrgitmType == "09" { //西药费
  9758. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9759. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9760. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9761. }
  9762. if item.MedChrgitmType == "11" { //中成费
  9763. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9764. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9765. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9766. }
  9767. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9768. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9769. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9770. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9771. }
  9772. } else {
  9773. if item.MedChrgitmType == "01" { //床位费
  9774. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9775. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9776. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9777. }
  9778. //if item.MedChrgitmType == "02" { //诊察费
  9779. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9780. // //zhenChaCostSelfTotal = zhenChaCostTotal
  9781. //}
  9782. if item.MedChrgitmType == "03" { //检查费
  9783. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9784. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9785. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9786. }
  9787. //if item.MedChrgitmType == "02" { //检查费
  9788. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9789. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9790. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9791. //}
  9792. if item.MedChrgitmType == "04" { //化验费
  9793. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9794. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9795. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9796. }
  9797. if item.MedChrgitmType == "05" { //治疗费
  9798. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9799. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9800. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9801. }
  9802. if item.MedChrgitmType == "06" { //手术费
  9803. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9804. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9805. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9806. }
  9807. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9808. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9809. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9810. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9811. }
  9812. if item.MedChrgitmType == "09" { //西药费
  9813. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9814. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9815. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9816. }
  9817. if item.MedChrgitmType == "11" { //中成费
  9818. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9819. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9820. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9821. }
  9822. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9823. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9824. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9825. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9826. }
  9827. }
  9828. }
  9829. c.ServeSuccessJSON(map[string]interface{}{
  9830. "order": order,
  9831. "order_info": order_info,
  9832. "patient": patient,
  9833. "admin_info": adminInfo,
  9834. "his_hospital": record,
  9835. "bedCostTotal": bedCostTotal,
  9836. "operationCostTotal": operationCostTotal,
  9837. "otherCostTotal": otherCostTotal,
  9838. "materialCostTotal": materialCostTotal,
  9839. "westernMedicineCostTotal": westernMedicineCostTotal,
  9840. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9841. "checkCostTotal": checkCostTotal,
  9842. "zhenChaCostTotal": zhenChaCostTotal,
  9843. "laboratoryCostTotal": laboratoryCostTotal,
  9844. "treatCostTotal": treatCostTotal,
  9845. })
  9846. } else {
  9847. for _, item := range order_info {
  9848. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9849. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9850. item.MedChrgitmType = "09"
  9851. }
  9852. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9853. if item.HisPrescriptionProject.Type == 2 {
  9854. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9855. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9856. case 0:
  9857. item.MedChrgitmType = "0"
  9858. break
  9859. case 1:
  9860. item.MedChrgitmType = "14"
  9861. break
  9862. case 2:
  9863. item.MedChrgitmType = "05"
  9864. break
  9865. case 3:
  9866. item.MedChrgitmType = "03"
  9867. break
  9868. case 4:
  9869. item.MedChrgitmType = "03"
  9870. break
  9871. case 5:
  9872. item.MedChrgitmType = "08"
  9873. break
  9874. case 6:
  9875. item.MedChrgitmType = "14"
  9876. break
  9877. case 7:
  9878. item.MedChrgitmType = "14"
  9879. break
  9880. case 8:
  9881. item.MedChrgitmType = "03"
  9882. break
  9883. case 9:
  9884. item.MedChrgitmType = "14"
  9885. break
  9886. case 10:
  9887. item.MedChrgitmType = "14"
  9888. break
  9889. case 11:
  9890. item.MedChrgitmType = "06"
  9891. break
  9892. case 12:
  9893. item.MedChrgitmType = "12"
  9894. break
  9895. case 13:
  9896. item.MedChrgitmType = "01"
  9897. break
  9898. case 14:
  9899. item.MedChrgitmType = "04"
  9900. break
  9901. case 15:
  9902. item.MedChrgitmType = "14"
  9903. break
  9904. }
  9905. } else {
  9906. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9907. case 1:
  9908. item.MedChrgitmType = "14"
  9909. break
  9910. case 2:
  9911. item.MedChrgitmType = "05"
  9912. break
  9913. case 3:
  9914. item.MedChrgitmType = "04"
  9915. break
  9916. case 4:
  9917. item.MedChrgitmType = "14"
  9918. break
  9919. case 5:
  9920. item.MedChrgitmType = "08"
  9921. break
  9922. case 6:
  9923. item.MedChrgitmType = "14"
  9924. break
  9925. case 7:
  9926. item.MedChrgitmType = "14"
  9927. break
  9928. case 8:
  9929. item.MedChrgitmType = "03"
  9930. break
  9931. case 9:
  9932. item.MedChrgitmType = "14"
  9933. break
  9934. }
  9935. }
  9936. } else if item.HisPrescriptionProject.Type == 3 {
  9937. item.MedChrgitmType = "08"
  9938. }
  9939. }
  9940. }
  9941. for _, item := range order_info {
  9942. if org_id == 10215 {
  9943. if item.MedChrgitmType == "01" { //床位费
  9944. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9945. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9946. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9947. }
  9948. if item.MedChrgitmType == "02" { //诊察费
  9949. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9950. //zhenChaCostSelfTotal = zhenChaCostTotal
  9951. }
  9952. if item.MedChrgitmType == "03" { //检查费
  9953. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9954. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9955. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9956. }
  9957. //if item.MedChrgitmType == "02" { //检查费
  9958. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9959. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9960. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9961. //}
  9962. if item.MedChrgitmType == "04" { //化验费
  9963. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9964. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9965. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9966. }
  9967. if item.MedChrgitmType == "05" { //治疗费
  9968. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9969. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9970. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9971. }
  9972. if item.MedChrgitmType == "06" { //手术费
  9973. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9974. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9975. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9976. }
  9977. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9978. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9979. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9980. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9981. }
  9982. if item.MedChrgitmType == "09" { //西药费
  9983. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9984. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9985. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9986. }
  9987. if item.MedChrgitmType == "11" { //中成费
  9988. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9989. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9990. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9991. }
  9992. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9993. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9994. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9995. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9996. }
  9997. } else {
  9998. if item.MedChrgitmType == "01" { //床位费
  9999. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10000. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10001. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10002. }
  10003. //if item.MedChrgitmType == "02" { //诊察费
  10004. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10005. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10006. //}
  10007. if item.MedChrgitmType == "03" { //检查费
  10008. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10009. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10010. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10011. }
  10012. //if item.MedChrgitmType == "02" { //检查费
  10013. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10014. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10015. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10016. //}
  10017. if item.MedChrgitmType == "04" { //化验费
  10018. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10019. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10020. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10021. }
  10022. if item.MedChrgitmType == "05" { //治疗费
  10023. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10024. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10025. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10026. }
  10027. if item.MedChrgitmType == "06" { //手术费
  10028. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10029. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10030. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10031. }
  10032. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10033. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10034. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10035. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10036. }
  10037. if item.MedChrgitmType == "09" { //西药费
  10038. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10039. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10040. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10041. }
  10042. if item.MedChrgitmType == "11" { //中成费
  10043. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10044. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10045. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10046. }
  10047. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10048. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10049. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10050. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10051. }
  10052. }
  10053. }
  10054. c.ServeSuccessJSON(map[string]interface{}{
  10055. "order": order,
  10056. "order_info": order_info,
  10057. "patient": patient,
  10058. "admin_info": adminInfo,
  10059. "his_hospital": record,
  10060. "bedCostTotal": bedCostTotal,
  10061. "operationCostTotal": operationCostTotal,
  10062. "otherCostTotal": otherCostTotal,
  10063. "materialCostTotal": materialCostTotal,
  10064. "westernMedicineCostTotal": westernMedicineCostTotal,
  10065. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10066. "checkCostTotal": checkCostTotal,
  10067. "zhenChaCostTotal": zhenChaCostTotal,
  10068. "laboratoryCostTotal": laboratoryCostTotal,
  10069. "treatCostTotal": treatCostTotal,
  10070. })
  10071. }
  10072. }
  10073. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  10074. page, _ := c.GetInt64("page")
  10075. limit, _ := c.GetInt64("limit")
  10076. keywords := c.GetString("keywords")
  10077. start_time := c.GetString("start_time")
  10078. end_time := c.GetString("end_time")
  10079. //clr_type := c.GetString("clr_type")
  10080. insutype := c.GetString("insutype")
  10081. timeLayout := "2006-01-02"
  10082. loc, _ := time.LoadLocation("Local")
  10083. var theStartTIme int64
  10084. if len(start_time) > 0 {
  10085. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10086. theStartTIme = theTime.Unix()
  10087. }
  10088. var theEndtTIme int64
  10089. if len(end_time) > 0 {
  10090. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10091. theEndtTIme = theTime.Unix()
  10092. }
  10093. if page <= 0 {
  10094. page = 1
  10095. }
  10096. if limit <= 0 {
  10097. limit = 10
  10098. }
  10099. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  10100. c.ServeSuccessJSON(map[string]interface{}{
  10101. "total": total,
  10102. "list": list,
  10103. })
  10104. return
  10105. }
  10106. func (c *HisApiController) GetPutOnRecordList() {
  10107. page, _ := c.GetInt64("page")
  10108. limit, _ := c.GetInt64("limit")
  10109. keywords := c.GetString("keywords")
  10110. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  10111. if page <= 0 {
  10112. page = 1
  10113. }
  10114. if limit <= 0 {
  10115. limit = 10
  10116. }
  10117. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  10118. c.ServeSuccessJSON(map[string]interface{}{
  10119. "total": total,
  10120. "list": list,
  10121. })
  10122. return
  10123. }
  10124. func (c *HisApiController) GetCompareData() {
  10125. start_time := c.GetString("start_time")
  10126. end_time := c.GetString("end_time")
  10127. insutype := c.GetString("insutype")
  10128. clr_type := c.GetString("clr_type")
  10129. timeLayout := "2006-01-02"
  10130. loc, _ := time.LoadLocation("Local")
  10131. var theStartTIme int64
  10132. if len(start_time) > 0 {
  10133. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10134. if err != nil {
  10135. theStartTIme = 0
  10136. }
  10137. theStartTIme = theTime.Unix()
  10138. }
  10139. var theEndtTIme int64
  10140. if len(end_time) > 0 {
  10141. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10142. if err != nil {
  10143. theEndtTIme = 0
  10144. }
  10145. theEndtTIme = theTime.Unix()
  10146. }
  10147. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  10148. fmt.Println(err)
  10149. if err == nil {
  10150. c.ServeSuccessJSON(map[string]interface{}{
  10151. "list": formData,
  10152. })
  10153. } else {
  10154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10155. return
  10156. }
  10157. }
  10158. func (c *HisApiController) GetFaPiaoData() {
  10159. order_id, _ := c.GetInt64("order_id")
  10160. patient_id, _ := c.GetInt64("patient_id")
  10161. //number := c.GetString("number")
  10162. adminUser := c.GetAdminUserInfo()
  10163. order, _ := service.GetHisOrderByID(order_id)
  10164. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10165. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10166. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10167. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10168. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  10169. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  10170. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10171. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10172. var bedCostTotal float64 = 0 //床位总费
  10173. var bedCostSelfTotal float64 = 0 //床位自费
  10174. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10175. var operationCostTotal float64 = 0 //手术费
  10176. var operationCostSelfTotal float64 = 0 //手术费
  10177. var operationCostPartSelfTotal float64 = 0 //手术费
  10178. var otherCostTotal float64 = 0 //其他费用
  10179. var otherCostSelfTotal float64 = 0 //其他费用
  10180. var otherCostPartSelfTotal float64 = 0 //其他费用
  10181. var materialCostTotal float64 = 0 //材料费
  10182. var materialCostSelfTotal float64 = 0 //材料费
  10183. var materialCostPartSelfTotal float64 = 0 //材料费
  10184. var westernMedicineCostTotal float64 = 0 //西药费
  10185. var westernMedicineCostSelfTotal float64 = 0 //西药费
  10186. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10187. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10188. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10189. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10190. var checkCostTotal float64 = 0 //检查费
  10191. var checkCostSelfTotal float64 = 0 //检查费
  10192. var checkCostPartSelfTotal float64 = 0 //检查费
  10193. var hiliCostTotal float64 = 0 //护理费
  10194. var hiliCostSelfTotal float64 = 0 //护理费
  10195. var hiliCostPartSelfTotal float64 = 0 //护理费
  10196. var laboratoryCostTotal float64 = 0 //化验费
  10197. var laboratoryCostSelfTotal float64 = 0 //化验费
  10198. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10199. var treatCostTotal float64 = 0 //治疗费用
  10200. var treatCostSelfTotal float64 = 0 //治疗费用
  10201. var treatCostPartSelfTotal float64 = 0 //治疗费用
  10202. var zhenChaCostTotal float64 = 0 //其他费用
  10203. var zhenChaCostSelfTotal float64 = 0 //其他费用
  10204. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10205. decimal.DivisionPrecision = 2
  10206. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10207. var balanceAccountsType int64
  10208. if his.ID > 0 {
  10209. balanceAccountsType = his.BalanceAccountsType
  10210. } else {
  10211. balanceAccountsType = his_hospital_record.BalanceAccountsType
  10212. }
  10213. if balanceAccountsType == 2 {
  10214. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10215. for _, item := range orderInfos_two {
  10216. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10217. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10218. item.MedChrgitmType = "09"
  10219. }
  10220. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10221. if item.HisPrescriptionProject.Type == 2 {
  10222. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10223. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10224. case 0:
  10225. item.MedChrgitmType = "0"
  10226. break
  10227. case 1:
  10228. item.MedChrgitmType = "14"
  10229. break
  10230. case 2:
  10231. item.MedChrgitmType = "05"
  10232. break
  10233. case 3:
  10234. item.MedChrgitmType = "03"
  10235. break
  10236. case 4:
  10237. item.MedChrgitmType = "03"
  10238. break
  10239. case 5:
  10240. item.MedChrgitmType = "08"
  10241. break
  10242. case 6:
  10243. item.MedChrgitmType = "14"
  10244. break
  10245. case 7:
  10246. item.MedChrgitmType = "14"
  10247. break
  10248. case 8:
  10249. item.MedChrgitmType = "03"
  10250. break
  10251. case 9:
  10252. item.MedChrgitmType = "14"
  10253. break
  10254. case 10:
  10255. item.MedChrgitmType = "14"
  10256. break
  10257. case 11:
  10258. item.MedChrgitmType = "06"
  10259. break
  10260. case 12:
  10261. item.MedChrgitmType = "12"
  10262. break
  10263. case 13:
  10264. item.MedChrgitmType = "01"
  10265. break
  10266. case 14:
  10267. item.MedChrgitmType = "04"
  10268. break
  10269. case 15:
  10270. item.MedChrgitmType = "02"
  10271. break
  10272. }
  10273. } else {
  10274. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10275. case 1:
  10276. item.MedChrgitmType = "14"
  10277. break
  10278. case 2:
  10279. item.MedChrgitmType = "05"
  10280. break
  10281. case 3:
  10282. item.MedChrgitmType = "04"
  10283. break
  10284. case 4:
  10285. item.MedChrgitmType = "03"
  10286. break
  10287. case 5:
  10288. item.MedChrgitmType = "08"
  10289. break
  10290. case 6:
  10291. item.MedChrgitmType = "14"
  10292. break
  10293. case 7:
  10294. item.MedChrgitmType = "14"
  10295. break
  10296. case 8:
  10297. item.MedChrgitmType = "03"
  10298. break
  10299. case 9:
  10300. item.MedChrgitmType = "14"
  10301. break
  10302. }
  10303. }
  10304. } else if item.HisPrescriptionProject.Type == 3 {
  10305. item.MedChrgitmType = "08"
  10306. }
  10307. }
  10308. }
  10309. for _, item := range orderInfos_two {
  10310. fmt.Println(item.MedChrgitmType)
  10311. if item.MedChrgitmType == "07" { //床位费
  10312. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10313. hiliCostSelfTotal = hiliCostTotal
  10314. }
  10315. if item.MedChrgitmType == "01" { //床位费
  10316. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10317. bedCostSelfTotal = bedCostTotal
  10318. }
  10319. if item.MedChrgitmType == "02" { //诊察费
  10320. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10321. zhenChaCostSelfTotal = zhenChaCostTotal
  10322. }
  10323. if item.MedChrgitmType == "03" { //检查费
  10324. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10325. checkCostSelfTotal = checkCostTotal
  10326. }
  10327. if item.MedChrgitmType == "04" { //化验费
  10328. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10329. laboratoryCostSelfTotal = laboratoryCostTotal
  10330. }
  10331. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10332. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10333. treatCostSelfTotal = treatCostTotal
  10334. }
  10335. if item.MedChrgitmType == "06" { //手术费
  10336. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10337. operationCostSelfTotal = treatCostTotal
  10338. }
  10339. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  10340. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10341. materialCostSelfTotal = materialCostTotal
  10342. }
  10343. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10344. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10345. westernMedicineCostSelfTotal = westernMedicineCostTotal
  10346. }
  10347. if item.MedChrgitmType == "11" { //中成费
  10348. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10349. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10350. }
  10351. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10352. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10353. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10354. otherCostSelfTotal = otherCostTotal
  10355. }
  10356. } else {
  10357. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10358. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10359. otherCostSelfTotal = otherCostTotal
  10360. }
  10361. }
  10362. }
  10363. } else {
  10364. for _, item := range orderInfos {
  10365. if item.MedChrgitmType == "01" { //床位费
  10366. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10367. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10368. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10369. }
  10370. if item.MedChrgitmType == "02" { //诊察费
  10371. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10372. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10373. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10374. }
  10375. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  10376. if item.MedChrgitmType == "03" { //检查费
  10377. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10378. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10379. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10380. }
  10381. } else {
  10382. if item.MedChrgitmType == "03" { //检查费
  10383. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10384. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10385. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10386. }
  10387. }
  10388. if item.MedChrgitmType == "04" { //化验费
  10389. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10390. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10391. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10392. }
  10393. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10394. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10395. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10396. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10397. }
  10398. if item.MedChrgitmType == "06" { //手术费
  10399. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10400. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10401. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10402. }
  10403. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  10404. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10405. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10406. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10407. }
  10408. if item.MedChrgitmType == "07" { //护理
  10409. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10410. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10411. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10412. }
  10413. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10414. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10415. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10416. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10417. }
  10418. if item.MedChrgitmType == "11" { //中成费
  10419. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10420. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10421. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10422. }
  10423. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10424. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10425. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10426. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10427. }
  10428. }
  10429. }
  10430. timeLayout := "2006-01-02"
  10431. loc, _ := time.LoadLocation("Local")
  10432. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  10433. if err != nil {
  10434. }
  10435. startRecordDateTime := startTime.Unix()
  10436. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  10437. if err != nil {
  10438. }
  10439. endRecordDateTime := endTime.Unix()
  10440. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  10441. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  10442. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  10443. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  10444. c.ServeSuccessJSON(map[string]interface{}{
  10445. "charge_admin_name": charge_admin.UserName,
  10446. "order_number": order.Number, //业务流水号
  10447. "id_card_no": his.IdCardNo, //社会保障号
  10448. "patient": patient,
  10449. "department_name": department.Name, //科室
  10450. "number": his.Number, //门诊号
  10451. "date": order.SettleAccountsDate, //结算日期
  10452. "name": order.PsnName, //姓名
  10453. "gender": patient.Gender, //性别
  10454. "psn_cash_money": order.PsnCashPay, //个人支付
  10455. "pay_way": "门诊", //结算方式
  10456. "medfee_sumamt": order.MedfeeSumamt, //总费用
  10457. "admin_user_name": admin.UserName, //收款员
  10458. "order": order,
  10459. "order_info": orderInfos_two,
  10460. "his": his,
  10461. "bedCostTotal": bedCostTotal,
  10462. "bedCostSelfTotal": bedCostSelfTotal,
  10463. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  10464. "operationCostTotal": operationCostTotal,
  10465. "operationCostSelfTotal": operationCostSelfTotal,
  10466. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  10467. "otherCostTotal": otherCostTotal,
  10468. "otherCostSelfTotal": otherCostSelfTotal,
  10469. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  10470. "materialCostTotal": materialCostTotal,
  10471. "materialCostSelfTotal": materialCostSelfTotal,
  10472. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  10473. "westernMedicineCostTotal": westernMedicineCostTotal,
  10474. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  10475. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  10476. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10477. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  10478. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  10479. "checkCostTotal": checkCostTotal,
  10480. "checkCostSelfTotal": checkCostSelfTotal,
  10481. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  10482. "laboratoryCostTotal": laboratoryCostTotal,
  10483. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  10484. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  10485. "treatCostTotal": treatCostTotal,
  10486. "treatCostSelfTotal": treatCostSelfTotal,
  10487. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  10488. "zhenChaCostTotal": zhenChaCostTotal,
  10489. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  10490. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  10491. "his_hospital_record": his_hospital_record,
  10492. "pre_pay_money": pre_pay_money,
  10493. "refund_sum": sum,
  10494. "doctor_info": doctor_info,
  10495. "hiliCostTotal": hiliCostTotal,
  10496. "hiliCostSelfTotal": hiliCostSelfTotal,
  10497. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  10498. })
  10499. }
  10500. //func (c *HisApiController) GetFaPiaoDatas() {
  10501. // order_ids := c.GetString("order_ids")
  10502. // patient_id, _ := c.GetInt64("patient_id")
  10503. // adminUser := c.GetAdminUserInfo()
  10504. //
  10505. // orders := strings.Split(order_ids, ",")
  10506. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10507. //
  10508. // for _, item := range orders {
  10509. // order_id, _ := strconv.ParseInt(item, 10, 64)
  10510. // order, _ := service.GetHisOrderByID(order_id)
  10511. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10512. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10513. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10514. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10515. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10516. //
  10517. // }
  10518. //
  10519. // var bedCostTotal float64 = 0 //床位总费
  10520. // var bedCostSelfTotal float64 = 0 //床位自费
  10521. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10522. //
  10523. // var operationCostTotal float64 = 0 //手术费
  10524. // var operationCostSelfTotal float64 = 0 //手术费
  10525. // var operationCostPartSelfTotal float64 = 0 //手术费
  10526. //
  10527. // var otherCostTotal float64 = 0 //其他费用
  10528. // var otherCostSelfTotal float64 = 0 //其他费用
  10529. // var otherCostPartSelfTotal float64 = 0 //其他费用
  10530. //
  10531. // var materialCostTotal float64 = 0 //材料费
  10532. // var materialCostSelfTotal float64 = 0 //材料费
  10533. // var materialCostPartSelfTotal float64 = 0 //材料费
  10534. //
  10535. // var westernMedicineCostTotal float64 = 0 //西药费
  10536. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  10537. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10538. //
  10539. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10540. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10541. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10542. //
  10543. // var checkCostTotal float64 = 0 //检查费
  10544. // var checkCostSelfTotal float64 = 0 //检查费
  10545. // var checkCostPartSelfTotal float64 = 0 //检查费
  10546. //
  10547. // var laboratoryCostTotal float64 = 0 //化验费
  10548. // var laboratoryCostSelfTotal float64 = 0 //化验费
  10549. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10550. //
  10551. // var treatCostTotal float64 = 0 //治疗费用
  10552. // var treatCostSelfTotal float64 = 0 //治疗费用
  10553. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  10554. //
  10555. // var zhenChaCostTotal float64 = 0 //其他费用
  10556. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  10557. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10558. //
  10559. // decimal.DivisionPrecision = 2
  10560. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10561. //
  10562. // var balanceAccountsType int64
  10563. // if his.ID > 0 {
  10564. // balanceAccountsType = his.BalanceAccountsType
  10565. // } else {
  10566. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  10567. // }
  10568. // if balanceAccountsType == 2 {
  10569. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10570. // for _, item := range orderInfos_two {
  10571. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10572. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10573. // item.MedChrgitmType = "09"
  10574. // }
  10575. //
  10576. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10577. // if item.HisPrescriptionProject.Type == 2 {
  10578. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10579. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10580. // case 0:
  10581. // item.MedChrgitmType = "0"
  10582. // break
  10583. // case 1:
  10584. // item.MedChrgitmType = "14"
  10585. // break
  10586. // case 2:
  10587. // item.MedChrgitmType = "05"
  10588. //
  10589. // break
  10590. // case 3:
  10591. // item.MedChrgitmType = "03"
  10592. //
  10593. // break
  10594. // case 4:
  10595. // item.MedChrgitmType = "03"
  10596. //
  10597. // break
  10598. // case 5:
  10599. // item.MedChrgitmType = "08"
  10600. //
  10601. // break
  10602. // case 6:
  10603. // item.MedChrgitmType = "14"
  10604. //
  10605. // break
  10606. // case 7:
  10607. // item.MedChrgitmType = "14"
  10608. //
  10609. // break
  10610. // case 8:
  10611. // item.MedChrgitmType = "03"
  10612. // break
  10613. // case 9:
  10614. // item.MedChrgitmType = "14"
  10615. // break
  10616. // case 10:
  10617. // item.MedChrgitmType = "14"
  10618. // break
  10619. // case 11:
  10620. // item.MedChrgitmType = "06"
  10621. // break
  10622. // case 12:
  10623. // item.MedChrgitmType = "12"
  10624. // break
  10625. // case 13:
  10626. // item.MedChrgitmType = "01"
  10627. // break
  10628. // case 14:
  10629. // item.MedChrgitmType = "04"
  10630. // break
  10631. // case 15:
  10632. // item.MedChrgitmType = "02"
  10633. // break
  10634. //
  10635. // }
  10636. //
  10637. // } else {
  10638. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10639. //
  10640. // case 1:
  10641. // item.MedChrgitmType = "14"
  10642. // break
  10643. // case 2:
  10644. // item.MedChrgitmType = "05"
  10645. //
  10646. // break
  10647. // case 3:
  10648. // item.MedChrgitmType = "03"
  10649. //
  10650. // break
  10651. // case 4:
  10652. // item.MedChrgitmType = "03"
  10653. //
  10654. // break
  10655. // case 5:
  10656. // item.MedChrgitmType = "08"
  10657. //
  10658. // break
  10659. // case 6:
  10660. // item.MedChrgitmType = "14"
  10661. //
  10662. // break
  10663. // case 7:
  10664. // item.MedChrgitmType = "14"
  10665. //
  10666. // break
  10667. // case 8:
  10668. // item.MedChrgitmType = "03"
  10669. // break
  10670. // case 9:
  10671. // item.MedChrgitmType = "14"
  10672. // break
  10673. //
  10674. // }
  10675. //
  10676. // }
  10677. //
  10678. // } else if item.HisPrescriptionProject.Type == 3 {
  10679. // item.MedChrgitmType = "08"
  10680. // }
  10681. // }
  10682. // }
  10683. //
  10684. // for _, item := range orderInfos_two {
  10685. // fmt.Println(item.MedChrgitmType)
  10686. // if item.MedChrgitmType == "01" { //床位费
  10687. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10688. // bedCostSelfTotal = bedCostTotal
  10689. // }
  10690. //
  10691. // if item.MedChrgitmType == "02" { //诊察费
  10692. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10693. // zhenChaCostSelfTotal = zhenChaCostTotal
  10694. // }
  10695. //
  10696. // if item.MedChrgitmType == "03" { //检查费
  10697. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10698. // checkCostSelfTotal = checkCostTotal
  10699. // }
  10700. //
  10701. // if item.MedChrgitmType == "04" { //化验费
  10702. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10703. // laboratoryCostSelfTotal = laboratoryCostTotal
  10704. // }
  10705. //
  10706. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  10707. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10708. // treatCostSelfTotal = treatCostTotal
  10709. // }
  10710. //
  10711. // if item.MedChrgitmType == "06" { //手术费
  10712. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10713. // operationCostSelfTotal = treatCostTotal
  10714. // }
  10715. //
  10716. // if item.MedChrgitmType == "08" { //材料费
  10717. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10718. // materialCostSelfTotal = materialCostTotal
  10719. // }
  10720. //
  10721. // if item.MedChrgitmType == "09" { //西药费
  10722. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10723. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  10724. // }
  10725. //
  10726. // if item.MedChrgitmType == "11" { //中成费
  10727. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10728. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10729. // }
  10730. //
  10731. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10732. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10733. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10734. // otherCostSelfTotal = otherCostTotal
  10735. // }
  10736. // } else {
  10737. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10738. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10739. // otherCostSelfTotal = otherCostTotal
  10740. // }
  10741. //
  10742. // }
  10743. //
  10744. // }
  10745. //
  10746. // } else {
  10747. // for _, item := range orderInfos {
  10748. // if item.MedChrgitmType == "01" { //床位费
  10749. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10750. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10751. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10752. // }
  10753. //
  10754. // if item.MedChrgitmType == "02" { //诊察费
  10755. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10756. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10757. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10758. // }
  10759. //
  10760. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  10761. // if item.MedChrgitmType == "03" { //检查费
  10762. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10763. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10764. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10765. //
  10766. // }
  10767. // } else {
  10768. // if item.MedChrgitmType == "03" { //检查费
  10769. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10770. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10771. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10772. // }
  10773. //
  10774. // }
  10775. //
  10776. // if item.MedChrgitmType == "04" { //化验费
  10777. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10778. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10779. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10780. //
  10781. // }
  10782. //
  10783. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  10784. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10785. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10786. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10787. //
  10788. // }
  10789. //
  10790. // if item.MedChrgitmType == "06" { //手术费
  10791. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10792. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10793. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10794. // }
  10795. //
  10796. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  10797. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10798. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10799. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10800. // }
  10801. //
  10802. // if item.MedChrgitmType == "09" { //西药费
  10803. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10804. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10805. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10806. // }
  10807. //
  10808. // if item.MedChrgitmType == "11" { //中成费
  10809. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10810. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10811. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10812. // }
  10813. //
  10814. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10815. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10816. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10817. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10818. // }
  10819. //
  10820. // }
  10821. // }
  10822. // timeLayout := "2006-01-02"
  10823. // loc, _ := time.LoadLocation("Local")
  10824. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  10825. // if err != nil {
  10826. // }
  10827. // startRecordDateTime := startTime.Unix()
  10828. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  10829. // if err != nil {
  10830. // }
  10831. // endRecordDateTime := endTime.Unix()
  10832. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  10833. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  10834. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  10835. //
  10836. // c.ServeSuccessJSON(map[string]interface{}{
  10837. // "order_number": order.Number, //业务流水号
  10838. // "id_card_no": his.IdCardNo, //社会保障号
  10839. // "department_name": department.Name, //科室
  10840. // "number": his.Number, //门诊号
  10841. // "date": order.SettleAccountsDate, //结算日期
  10842. // "name": order.PsnName, //姓名
  10843. // "gender": patient.Gender, //性别
  10844. // "psn_cash_money": order.PsnCashPay, //个人支付
  10845. // "pay_way": "门诊", //结算方式
  10846. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  10847. // "admin_user_name": admin.UserName, //收款员
  10848. // "order": order,
  10849. // "order_info": orderInfos_two,
  10850. // "his": his,
  10851. // "bedCostTotal": bedCostTotal,
  10852. // "bedCostSelfTotal": bedCostSelfTotal,
  10853. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  10854. // "operationCostTotal": operationCostTotal,
  10855. // "operationCostSelfTotal": operationCostSelfTotal,
  10856. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  10857. // "otherCostTotal": otherCostTotal,
  10858. // "otherCostSelfTotal": otherCostSelfTotal,
  10859. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  10860. // "materialCostTotal": materialCostTotal,
  10861. // "materialCostSelfTotal": materialCostSelfTotal,
  10862. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  10863. // "westernMedicineCostTotal": westernMedicineCostTotal,
  10864. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  10865. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  10866. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10867. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  10868. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  10869. // "checkCostTotal": checkCostTotal,
  10870. // "checkCostSelfTotal": checkCostSelfTotal,
  10871. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  10872. // "laboratoryCostTotal": laboratoryCostTotal,
  10873. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  10874. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  10875. // "treatCostTotal": treatCostTotal,
  10876. // "treatCostSelfTotal": treatCostSelfTotal,
  10877. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  10878. // "zhenChaCostTotal": zhenChaCostTotal,
  10879. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  10880. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  10881. // "his_hospital_record": his_hospital_record,
  10882. // "pre_pay_money": pre_pay_money,
  10883. // "refund_sum": sum,
  10884. // })
  10885. //
  10886. //}
  10887. func (this *HisApiController) GetIncomeStatisticsData() {
  10888. start_time := this.GetString("start_time")
  10889. end_time := this.GetString("end_time")
  10890. key_words := this.GetString("key_words")
  10891. limit, _ := this.GetInt64("limit")
  10892. page, _ := this.GetInt64("page")
  10893. if page <= 0 {
  10894. page = 1
  10895. }
  10896. if limit <= 0 {
  10897. limit = 10
  10898. }
  10899. statistics_type, _ := this.GetInt64("statistics_type")
  10900. admin := this.GetAdminUserInfo()
  10901. timeLayout := "2006-01-02"
  10902. loc, _ := time.LoadLocation("Local")
  10903. var theStartTIme int64
  10904. if len(start_time) > 0 {
  10905. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10906. if err != nil {
  10907. theStartTIme = 0
  10908. }
  10909. theStartTIme = theTime.Unix()
  10910. }
  10911. var theEndtTIme int64
  10912. if len(end_time) > 0 {
  10913. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10914. if err != nil {
  10915. theEndtTIme = 0
  10916. }
  10917. theEndtTIme = theTime.Unix()
  10918. }
  10919. if statistics_type == 1 {
  10920. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10921. this.ServeSuccessJSON(map[string]interface{}{
  10922. "list": list,
  10923. "total": total,
  10924. })
  10925. } else {
  10926. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10927. this.ServeSuccessJSON(map[string]interface{}{
  10928. "list": list,
  10929. "total": total,
  10930. })
  10931. }
  10932. }
  10933. func (c *HisApiController) PostProjectInformation() {
  10934. adminUser := c.GetAdminUserInfo()
  10935. orgId := adminUser.CurrentOrgId
  10936. dataBody := make(map[string]interface{}, 0)
  10937. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10938. if err != nil {
  10939. utils.ErrorLog(err.Error())
  10940. return
  10941. }
  10942. utils.ErrorLog("%v", dataBody)
  10943. var projectList []*models.HisProject
  10944. var total_goods []interface{}
  10945. tempProjects := dataBody["projects"].([]interface{})
  10946. total_goods = tempProjects
  10947. for index, projectMap := range tempProjects {
  10948. projectM := projectMap.(map[string]interface{})
  10949. var project models.HisProject
  10950. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  10951. utils.ErrorLog("project_name")
  10952. return
  10953. }
  10954. project_name, _ := projectM["project_name"].(string)
  10955. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  10956. err_log := models.ExportErrLog{
  10957. LogType: 6,
  10958. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10959. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  10960. Status: 1,
  10961. CreateTime: time.Now().Unix(),
  10962. UpdateTime: time.Now().Unix(),
  10963. ExportTime: time.Now().Unix(),
  10964. }
  10965. service.CreateExportErrLog(&err_log)
  10966. continue
  10967. }
  10968. project.ProjectName = project_name
  10969. prices := projectM["price"].(string)
  10970. price, _ := strconv.ParseFloat(prices, 64)
  10971. if price <= 0 { //名字为空则生成一条导入错误日志
  10972. err_log := models.ExportErrLog{
  10973. LogType: 6,
  10974. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10975. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  10976. Status: 1,
  10977. CreateTime: time.Now().Unix(),
  10978. UpdateTime: time.Now().Unix(),
  10979. ExportTime: time.Now().Unix(),
  10980. }
  10981. service.CreateExportErrLog(&err_log)
  10982. continue
  10983. }
  10984. project.Price = price
  10985. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  10986. utils.ErrorLog("unit_id")
  10987. return
  10988. }
  10989. unit := projectM["unit"].(string)
  10990. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  10991. err_log := models.ExportErrLog{
  10992. LogType: 6,
  10993. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10994. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  10995. Status: 1,
  10996. CreateTime: time.Now().Unix(),
  10997. UpdateTime: time.Now().Unix(),
  10998. ExportTime: time.Now().Unix(),
  10999. }
  11000. service.CreateExportErrLog(&err_log)
  11001. continue
  11002. }
  11003. project.Unit = unit
  11004. cost_classify := projectM["cost_classify"].(string)
  11005. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  11006. err_log := models.ExportErrLog{
  11007. LogType: 6,
  11008. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11009. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11010. Status: 1,
  11011. CreateTime: time.Now().Unix(),
  11012. UpdateTime: time.Now().Unix(),
  11013. ExportTime: time.Now().Unix(),
  11014. }
  11015. service.CreateExportErrLog(&err_log)
  11016. continue
  11017. }
  11018. var costClassify = "费用类别"
  11019. var cost_classify_id int64
  11020. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  11021. if len(cost_classify) != 0 {
  11022. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  11023. if errcode == gorm.ErrRecordNotFound {
  11024. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  11025. dataconfig := models.DictDataconfig{
  11026. ParentId: costClassifyConfig.ID,
  11027. Module: "system",
  11028. OrgId: orgId,
  11029. Name: cost_classify,
  11030. FieldName: "",
  11031. Value: costConfig.Value + 1,
  11032. CreatedTime: "",
  11033. UpdatedTime: "",
  11034. CreateUserId: adminUser.AdminUser.Id,
  11035. Status: 1,
  11036. Remark: "",
  11037. DeleteIdSystem: 0,
  11038. Title: "",
  11039. Content: "",
  11040. Order: 0,
  11041. Code: "",
  11042. }
  11043. service.CreatedDicConfig(&dataconfig)
  11044. }
  11045. }
  11046. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  11047. for _, it := range costClassList {
  11048. if cost_classify == it.Name {
  11049. cost_classify_id = int64(it.Value)
  11050. }
  11051. }
  11052. project.CostClassify = cost_classify_id
  11053. executive_section := projectM["executive_section"].(string)
  11054. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  11055. err_log := models.ExportErrLog{
  11056. LogType: 6,
  11057. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11058. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  11059. Status: 1,
  11060. CreateTime: time.Now().Unix(),
  11061. UpdateTime: time.Now().Unix(),
  11062. ExportTime: time.Now().Unix(),
  11063. }
  11064. service.CreateExportErrLog(&err_log)
  11065. continue
  11066. }
  11067. if len(executive_section) != 0 {
  11068. //查找科室是否有内容
  11069. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  11070. if errcodedepart == gorm.ErrRecordNotFound {
  11071. department := models.XtHisDepartment{
  11072. Name: executive_section,
  11073. Status: 1,
  11074. UserOrgId: adminUser.CurrentOrgId,
  11075. CreatedTime: time.Now().Unix(),
  11076. }
  11077. service.CreateDePartment(&department)
  11078. }
  11079. }
  11080. var executive_section_id int64
  11081. departMentList, _ := service.GetAllDepartMent(orgId)
  11082. for _, it := range departMentList {
  11083. if executive_section == it.Name {
  11084. executive_section_id = it.ID
  11085. }
  11086. }
  11087. project.ExecutiveSection = executive_section_id
  11088. medical_coverage := projectM["medical_coverage"].(string)
  11089. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  11090. err_log := models.ExportErrLog{
  11091. LogType: 6,
  11092. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11093. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11094. Status: 1,
  11095. CreateTime: time.Now().Unix(),
  11096. UpdateTime: time.Now().Unix(),
  11097. ExportTime: time.Now().Unix(),
  11098. }
  11099. service.CreateExportErrLog(&err_log)
  11100. continue
  11101. }
  11102. var medicalCoverage = "医保等级"
  11103. var medical_coverage_id int64
  11104. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  11105. if len(medical_coverage) != 0 {
  11106. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  11107. if errormedicalcoverage == gorm.ErrRecordNotFound {
  11108. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  11109. dataconfig := models.DictDataconfig{
  11110. ParentId: medicalCoverageConfig.ID,
  11111. Module: "system",
  11112. OrgId: orgId,
  11113. Name: medical_coverage,
  11114. FieldName: "",
  11115. Value: medicalCoverageConfig.Value + 1,
  11116. CreatedTime: "",
  11117. UpdatedTime: "",
  11118. CreateUserId: adminUser.AdminUser.Id,
  11119. Status: 1,
  11120. Remark: "",
  11121. DeleteIdSystem: 0,
  11122. Title: "",
  11123. Content: "",
  11124. Order: 0,
  11125. Code: "",
  11126. }
  11127. service.CreatedDicConfig(&dataconfig)
  11128. }
  11129. }
  11130. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  11131. for _, it := range medicalCoverageList {
  11132. if medical_coverage == it.Name {
  11133. medical_coverage_id = int64(it.Value)
  11134. }
  11135. }
  11136. project.MedicalCoverage = medical_coverage_id
  11137. pinyin := projectM["pinyin"].(string)
  11138. project.Pinyin = pinyin
  11139. wubi := projectM["wubi"].(string)
  11140. project.Wubi = wubi
  11141. statistical_classification := projectM["statistical_classification"].(string)
  11142. var statisticalClassification = "统计分类"
  11143. var statistical_classification_id int64
  11144. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  11145. if len(statistical_classification) != 0 {
  11146. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  11147. if classificationerrcodes == gorm.ErrRecordNotFound {
  11148. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  11149. dataconfig := models.DictDataconfig{
  11150. ParentId: classiFication.ID,
  11151. Module: "system",
  11152. OrgId: orgId,
  11153. Name: statistical_classification,
  11154. FieldName: "",
  11155. Value: classiFicationConfig.Value + 1,
  11156. CreatedTime: "",
  11157. UpdatedTime: "",
  11158. CreateUserId: adminUser.AdminUser.Id,
  11159. Status: 1,
  11160. Remark: "",
  11161. DeleteIdSystem: 0,
  11162. Title: "",
  11163. Content: "",
  11164. Order: 0,
  11165. Code: "",
  11166. }
  11167. service.CreatedDicConfig(&dataconfig)
  11168. }
  11169. }
  11170. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  11171. for _, it := range classiFicationList {
  11172. if statistical_classification == it.Name {
  11173. statistical_classification_id = int64(it.Value)
  11174. }
  11175. }
  11176. project.StatisticalClassification = statistical_classification_id
  11177. disease_directory := int64(projectM["disease_directory"].(float64))
  11178. project.DiseaseDirectory = disease_directory
  11179. is_record := int64(projectM["is_record"].(float64))
  11180. project.IsRecord = is_record
  11181. medical_code := projectM["medical_code"].(string)
  11182. project.MedicalCode = medical_code
  11183. tube_color := projectM["tube_color"].(string)
  11184. var tubeColor = "试管颜色"
  11185. var tube_color_id int64
  11186. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  11187. if len(tube_color) != 0 {
  11188. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  11189. if errcodetube == gorm.ErrRecordNotFound {
  11190. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  11191. dataconfig := models.DictDataconfig{
  11192. ParentId: tubeColorConfig.ID,
  11193. Module: "system",
  11194. OrgId: orgId,
  11195. Name: tube_color,
  11196. FieldName: "",
  11197. Value: tubeConfig.Value + 1,
  11198. CreatedTime: "",
  11199. UpdatedTime: "",
  11200. CreateUserId: adminUser.AdminUser.Id,
  11201. Status: 1,
  11202. Remark: "",
  11203. DeleteIdSystem: 0,
  11204. Title: "",
  11205. Content: "",
  11206. Order: 0,
  11207. Code: "",
  11208. }
  11209. service.CreatedDicConfig(&dataconfig)
  11210. }
  11211. }
  11212. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  11213. for _, it := range tubeColorList {
  11214. if tube_color == it.Name {
  11215. tube_color_id = int64(it.Value)
  11216. }
  11217. }
  11218. project.TubeColor = tube_color_id
  11219. single_dose := projectM["single_dose"].(string)
  11220. project.SingleDose = single_dose
  11221. execution_frequency := projectM["execution_frequency"].(string)
  11222. project.ExecutionFrequency = execution_frequency
  11223. delivery_way := projectM["delivery_way"].(string)
  11224. project.DeliveryWay = delivery_way
  11225. number_days := projectM["number_days"].(string)
  11226. project.NumberDays = number_days
  11227. total := projectM["total"].(string)
  11228. project.Total = total
  11229. medical_status := int64(projectM["medical_status"].(float64))
  11230. project.MedicalStatus = medical_status
  11231. category := int64(projectM["category"].(float64))
  11232. project.Category = category
  11233. specail_project := int64(projectM["specail_project"].(float64))
  11234. project.SpecailProject = specail_project
  11235. social_security_directory_code := projectM["social_security_directory_code"].(string)
  11236. project.SocialSecurityDirectoryCode = social_security_directory_code
  11237. remark := projectM["remark"].(string)
  11238. project.Remark = remark
  11239. record_date := projectM["record_date"].(string)
  11240. timeLayout := "2006-01-02"
  11241. loc, _ := time.LoadLocation("Local")
  11242. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11243. project.RecordDate = theTime.Unix()
  11244. projectList = append(projectList, &project)
  11245. }
  11246. export_time := time.Now().Unix()
  11247. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  11248. if len(projectList) > 0 {
  11249. for _, item := range projectList {
  11250. hans := item.ProjectName // 要转换的汉字字符串
  11251. // 创建一个拼音转换器
  11252. p := pinyin.NewArgs()
  11253. // 将汉字转为拼音
  11254. pinyinSlice := pinyin.Pinyin(hans, p)
  11255. // 输出拼音
  11256. fmt.Println("Pinyin:", pinyinSlice)
  11257. // 获取首字母
  11258. firstLetter := ""
  11259. for _, py := range pinyinSlice {
  11260. if len(py) > 0 {
  11261. firstLetter += string(py[0][0])
  11262. }
  11263. }
  11264. item.FirstLetter = firstLetter
  11265. project := models.HisProject{
  11266. ProjectName: item.ProjectName,
  11267. Price: item.Price,
  11268. Unit: item.Unit,
  11269. CostClassify: item.CostClassify,
  11270. ExecutiveSection: item.ExecutiveSection,
  11271. MedicalCoverage: item.MedicalCoverage,
  11272. UserOrgId: orgId,
  11273. Status: 1,
  11274. CreatedTime: time.Now().Unix(),
  11275. Pinyin: item.Pinyin,
  11276. Wubi: item.Wubi,
  11277. StatisticalClassification: item.StatisticalClassification,
  11278. DiseaseDirectory: item.DiseaseDirectory,
  11279. IsRecord: item.IsRecord,
  11280. MedicalCode: item.MedicalCode,
  11281. TubeColor: item.TubeColor,
  11282. SingleDose: item.SingleDose,
  11283. DeliveryWay: item.DeliveryWay,
  11284. NumberDays: item.NumberDays,
  11285. Total: item.Total,
  11286. Category: item.Category,
  11287. MedicalStatus: item.MedicalStatus,
  11288. SpecailProject: item.SpecailProject,
  11289. RecordDate: item.RecordDate,
  11290. Remark: item.Remark,
  11291. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  11292. ExecutionFrequency: item.ExecutionFrequency,
  11293. FirstLetter: item.FirstLetter,
  11294. }
  11295. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  11296. if errcodeproject == gorm.ErrRecordNotFound {
  11297. service.CreateProjectInfomation(&project)
  11298. } else if errcodeproject == nil {
  11299. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  11300. }
  11301. log := models.ExportLog{
  11302. LogType: 6,
  11303. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11304. TotalNum: int64(len(total_goods)),
  11305. FailNum: int64(len(errLogs)),
  11306. SuccessNum: int64(len(projectList)),
  11307. CreateTime: time.Now().Unix(),
  11308. UpdateTime: time.Now().Unix(),
  11309. ExportTime: export_time,
  11310. Status: 1,
  11311. }
  11312. service.CreateExportLog(&log)
  11313. c.ServeSuccessJSON(map[string]interface{}{
  11314. "msg": "导入成功",
  11315. "total_num": len(total_goods),
  11316. "success_num": len(projectList),
  11317. "fail_num": int64(len(errLogs)),
  11318. })
  11319. }
  11320. } else {
  11321. log := models.ExportLog{
  11322. LogType: 6,
  11323. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11324. TotalNum: int64(len(total_goods)),
  11325. FailNum: int64(len(errLogs)),
  11326. SuccessNum: int64(len(projectList)),
  11327. CreateTime: time.Now().Unix(),
  11328. UpdateTime: time.Now().Unix(),
  11329. ExportTime: export_time,
  11330. Status: 1,
  11331. }
  11332. service.CreateExportLog(&log)
  11333. c.ServeSuccessJSON(map[string]interface{}{
  11334. "msg": "导入成功",
  11335. "total_num": len(total_goods),
  11336. "success_num": len(projectList),
  11337. "fail_num": int64(len(errLogs)),
  11338. })
  11339. }
  11340. }
  11341. //func (this *HisApiController) EditProjectInformation(){
  11342. //
  11343. // id, _ := this.GetInt64("id")
  11344. // project_team := this.GetString("project_team")
  11345. // price := this.GetString("price")
  11346. // price_float, _ := strconv.ParseFloat(price, 64)
  11347. // pinyin := this.GetString("pinyin")
  11348. // wubi := this.GetString("wubi")
  11349. // tube_color, _ := this.GetInt64("tube_color")
  11350. // team_type, _ := this.GetInt64("team_type")
  11351. // remark := this.GetString("remark")
  11352. // ids := this.GetString("ids")
  11353. // item_id := this.GetString("item_id")
  11354. // projectTeam := models.XtHisProjectTeam{
  11355. // ProjectTeam: project_team,
  11356. // Price: price_float,
  11357. // Pinyin: pinyin,
  11358. // Wubi: wubi,
  11359. // TubeColor: tube_color,
  11360. // TeamType: team_type,
  11361. // Remark: remark,
  11362. // ProjectId: ids,
  11363. // ItemId: item_id,
  11364. // }
  11365. //
  11366. //
  11367. // dataBody := make(map[string]interface{}, 0)
  11368. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  11369. // if err != nil {
  11370. // utils.ErrorLog(err.Error())
  11371. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11372. // return
  11373. // }
  11374. //
  11375. // err = service.UpdatedProjectTeam(id, &projectTeam)
  11376. //
  11377. //
  11378. // if err != nil {
  11379. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  11380. // return
  11381. // }
  11382. //
  11383. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  11384. // infos, _ := dataBody["info"].([]interface{})
  11385. // if len(infos) > 0 {
  11386. // var ids []string
  11387. //
  11388. // for _, item := range infos {
  11389. // items := item.(map[string]interface{})
  11390. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  11391. // utils.ErrorLog("id")
  11392. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11393. // return
  11394. // }
  11395. // id := int64(items["id"].(float64))
  11396. //
  11397. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11398. // utils.ErrorLog("type")
  11399. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11400. // return
  11401. // }
  11402. // types := int64(items["type"].(float64))
  11403. //
  11404. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  11405. // utils.ErrorLog("number")
  11406. // }
  11407. //
  11408. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  11409. //
  11410. // projectList := models.XtHisProjectList{
  11411. // Number: number,
  11412. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  11413. // ProjectId: id,
  11414. // Status: 1,
  11415. // CreatedTime: time.Now().Unix(),
  11416. // UpdatedTime: time.Now().Unix(),
  11417. // TeamId: projectTeam.ID,
  11418. // Type: types,
  11419. // }
  11420. // list := projectList
  11421. //
  11422. // service.CreateProjectList(&list)
  11423. //
  11424. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  11425. //
  11426. // }
  11427. // ids_str := strings.Join(ids, ",")
  11428. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  11429. // service.SaveProjectTeam(&projectTeam)
  11430. // this.ServeSuccessJSON(map[string]interface{}{
  11431. // "projectTeam": projectTeam,
  11432. // })
  11433. // }
  11434. // }
  11435. //}
  11436. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  11437. name := c.GetString("name")
  11438. mode_id, _ := c.GetInt64("mode", 0)
  11439. types, _ := c.GetInt64("type", 0)
  11440. patient_id, _ := c.GetInt64("patient_id", 0)
  11441. types = 1
  11442. adminInfo := c.GetAdminUserInfo()
  11443. template := &models.HisPrescriptionTemplate{
  11444. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11445. PatientId: patient_id,
  11446. Type: types,
  11447. Status: 1,
  11448. Ctime: time.Now().Unix(),
  11449. Mtime: time.Now().Unix(),
  11450. Name: name,
  11451. Mode: mode_id,
  11452. }
  11453. dataBody := make(map[string]interface{}, 0)
  11454. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11455. if err != nil {
  11456. utils.ErrorLog(err.Error())
  11457. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11458. return
  11459. }
  11460. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  11461. //如果已经存在记录则删除处方
  11462. if template_one.ID > 0 {
  11463. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  11464. var ids []int64
  11465. var org_id int64
  11466. for _, item := range ps {
  11467. org_id = c.GetAdminUserInfo().CurrentOrgId
  11468. ids = append(ids, item.ID)
  11469. }
  11470. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  11471. if err2 == nil {
  11472. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11473. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11474. if len(prescriptions) > 0 {
  11475. for _, item := range prescriptions {
  11476. items := item.(map[string]interface{})
  11477. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11478. utils.ErrorLog("type")
  11479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11480. return
  11481. }
  11482. types := int64(items["type"].(float64))
  11483. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  11484. utils.ErrorLog("med_type")
  11485. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11486. return
  11487. }
  11488. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  11489. ctime := time.Now().Unix()
  11490. prescription := &models.HisPrescriptionInfoTemplate{
  11491. PatientId: patient_id,
  11492. UserOrgId: adminInfo.CurrentOrgId,
  11493. Ctime: ctime,
  11494. Mtime: ctime,
  11495. Type: types,
  11496. Modifier: adminInfo.AdminUser.Id,
  11497. Creator: adminInfo.AdminUser.Id,
  11498. Status: 1,
  11499. PTemplateId: template_one.ID,
  11500. MedType: med_type,
  11501. }
  11502. service.CreateHisPrescriptionInfoTemplate(prescription)
  11503. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11504. advices := items["advices"].([]interface{})
  11505. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11506. ctime := time.Now().Unix()
  11507. mtime := ctime
  11508. if len(advices) > 0 {
  11509. for _, advice := range advices {
  11510. var s models.HisPrescriptionAdviceTemplate
  11511. s.PrescriptionId = prescription.ID
  11512. s.AdviceType = 2
  11513. s.StopState = 2
  11514. s.ExecutionState = 2
  11515. s.Status = 1
  11516. s.UserOrgId = adminInfo.CurrentOrgId
  11517. s.CreatedTime = ctime
  11518. s.UpdatedTime = mtime
  11519. s.PatientId = patient_id
  11520. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  11521. if errcode > 0 {
  11522. c.ServeFailJSONWithSGJErrorCode(errcode)
  11523. return
  11524. }
  11525. service.CreateHisPrescriptionAdviceTemplate(&s)
  11526. }
  11527. }
  11528. }
  11529. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11530. projects := items["project"].([]interface{})
  11531. if len(projects) > 0 {
  11532. for _, project := range projects {
  11533. var p models.HisPrescriptionProjectTemplate
  11534. p.PrescriptionId = prescription.ID
  11535. p.Ctime = time.Now().Unix()
  11536. p.Mtime = time.Now().Unix()
  11537. p.PatientId = patient_id
  11538. p.UserOrgId = adminInfo.CurrentOrgId
  11539. p.Status = 1
  11540. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  11541. if errcode > 0 {
  11542. c.ServeFailJSONWithSGJErrorCode(errcode)
  11543. return
  11544. }
  11545. service.CreateHisPrescriptionProjectTemplate(&p)
  11546. }
  11547. }
  11548. }
  11549. }
  11550. c.ServeSuccessJSON(map[string]interface{}{
  11551. "msg": "创建成功",
  11552. })
  11553. }
  11554. }
  11555. } else {
  11556. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11557. return
  11558. }
  11559. } else {
  11560. err3 := service.CreateHisPrescriptionTemplate(template)
  11561. if err3 == nil {
  11562. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11563. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11564. if len(prescriptions) > 0 {
  11565. for _, item := range prescriptions {
  11566. items := item.(map[string]interface{})
  11567. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11568. utils.ErrorLog("type")
  11569. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11570. return
  11571. }
  11572. types := int64(items["type"].(float64))
  11573. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  11574. utils.ErrorLog("med_type")
  11575. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11576. return
  11577. }
  11578. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  11579. ctime := time.Now().Unix()
  11580. prescription := &models.HisPrescriptionInfoTemplate{
  11581. PatientId: patient_id,
  11582. UserOrgId: adminInfo.CurrentOrgId,
  11583. Ctime: ctime,
  11584. Mtime: ctime,
  11585. Type: types,
  11586. Modifier: adminInfo.AdminUser.Id,
  11587. Creator: adminInfo.AdminUser.Id,
  11588. Status: 1,
  11589. PTemplateId: template.ID,
  11590. MedType: med_type,
  11591. }
  11592. service.CreateHisPrescriptionInfoTemplate(prescription)
  11593. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11594. advices := items["advices"].([]interface{})
  11595. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11596. ctime := time.Now().Unix()
  11597. mtime := ctime
  11598. if len(advices) > 0 {
  11599. for _, advice := range advices {
  11600. var s models.HisPrescriptionAdviceTemplate
  11601. s.PrescriptionId = prescription.ID
  11602. s.AdviceType = 2
  11603. s.StopState = 2
  11604. s.ExecutionState = 2
  11605. s.Status = 1
  11606. s.UserOrgId = adminInfo.CurrentOrgId
  11607. s.CreatedTime = ctime
  11608. s.UpdatedTime = mtime
  11609. s.PatientId = patient_id
  11610. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  11611. if errcode > 0 {
  11612. c.ServeFailJSONWithSGJErrorCode(errcode)
  11613. return
  11614. }
  11615. service.CreateHisPrescriptionAdviceTemplate(&s)
  11616. }
  11617. }
  11618. }
  11619. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11620. projects := items["project"].([]interface{})
  11621. if len(projects) > 0 {
  11622. for _, project := range projects {
  11623. var p models.HisPrescriptionProjectTemplate
  11624. p.PrescriptionId = prescription.ID
  11625. p.Ctime = time.Now().Unix()
  11626. p.Mtime = time.Now().Unix()
  11627. p.PatientId = patient_id
  11628. p.UserOrgId = adminInfo.CurrentOrgId
  11629. p.Status = 1
  11630. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  11631. if errcode > 0 {
  11632. c.ServeFailJSONWithSGJErrorCode(errcode)
  11633. return
  11634. }
  11635. service.CreateHisPrescriptionProjectTemplate(&p)
  11636. }
  11637. }
  11638. }
  11639. }
  11640. c.ServeSuccessJSON(map[string]interface{}{
  11641. "msg": "创建成功",
  11642. })
  11643. }
  11644. }
  11645. } else {
  11646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11647. return
  11648. }
  11649. }
  11650. }
  11651. func (c *HisApiController) PreSettle() {
  11652. id, _ := c.GetInt64("id")
  11653. record_time := c.GetString("record_time")
  11654. his_patient_id, _ := c.GetInt64("his_patient_id")
  11655. timeLayout := "2006-01-02"
  11656. loc, _ := time.LoadLocation("Local")
  11657. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  11658. diagnosis_id := c.GetString("diagnosis")
  11659. sick_type, _ := c.GetInt64("sick_type")
  11660. reg_type, _ := c.GetInt64("p_type")
  11661. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  11662. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  11663. if err != nil {
  11664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11665. return
  11666. }
  11667. recordDateTime := theTime.Unix()
  11668. adminUser := c.GetAdminUserInfo()
  11669. var prescriptions []*models.HisPrescription
  11670. var start_time int64
  11671. var end_time int64
  11672. ids_str := c.GetString("ids")
  11673. ids_arr := strings.Split(ids_str, ",")
  11674. fmt.Println(reg_type)
  11675. if settle_accounts_type == 1 { //日结
  11676. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  11677. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  11678. } else {
  11679. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  11680. }
  11681. fmt.Println(prescriptions)
  11682. } else { //月结
  11683. start_time_str := c.GetString("start_time")
  11684. end_time_str := c.GetString("end_time")
  11685. timeLayout := "2006-01-02"
  11686. loc, _ := time.LoadLocation("Local")
  11687. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  11688. if err != nil {
  11689. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11690. return
  11691. }
  11692. recordStartTime := theStartTime.Unix()
  11693. start_time = recordStartTime
  11694. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  11695. if err != nil {
  11696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11697. return
  11698. }
  11699. recordEndTime := theEndTime.Unix()
  11700. end_time = recordEndTime
  11701. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  11702. }
  11703. if reg_type == 1111 || reg_type == 1112 {
  11704. reg_type = 11
  11705. }
  11706. timestamp := time.Now().Unix()
  11707. tempTime := time.Unix(timestamp, 0)
  11708. timeFormat := tempTime.Format("20060102150405")
  11709. chrgBchno := rand.Intn(100000) + 10000
  11710. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  11711. strconv.FormatInt(his.PatientId, 10)
  11712. var ids []int64
  11713. for _, item := range prescriptions {
  11714. ids = append(ids, item.ID)
  11715. }
  11716. fmt.Println(ids)
  11717. var total float64
  11718. for _, item := range prescriptions {
  11719. fmt.Println(item)
  11720. if item.Type == 1 { //药品
  11721. for _, subItem := range item.HisDoctorAdviceInfo {
  11722. total = total + (subItem.Price * subItem.PrescribingNumber)
  11723. }
  11724. }
  11725. if item.Type == 2 { //项目
  11726. for _, subItem := range item.HisPrescriptionProject {
  11727. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  11728. total = total + (subItem.Price * cnt)
  11729. }
  11730. }
  11731. for _, subItem := range item.HisAdditionalCharge {
  11732. total = total + (subItem.Price * float64(subItem.Count))
  11733. }
  11734. }
  11735. allTotal := fmt.Sprintf("%.2f", total)
  11736. totals, _ := strconv.ParseFloat(allTotal, 64)
  11737. order := &models.HisOrder{
  11738. UserOrgId: adminUser.CurrentOrgId,
  11739. HisPatientId: his.ID,
  11740. PatientId: id,
  11741. SettleAccountsDate: recordDateTime,
  11742. Ctime: time.Now().Unix(),
  11743. Mtime: time.Now().Unix(),
  11744. Status: 1,
  11745. OrderStatus: 1,
  11746. MdtrtId: his.Number,
  11747. Number: chrg_bchno,
  11748. MedfeeSumamt: totals,
  11749. SettleEndTime: end_time,
  11750. SettleStartTime: start_time,
  11751. SettleType: settle_accounts_type,
  11752. PsnPartAmt: totals,
  11753. PsnCashPay: totals,
  11754. PType: 2,
  11755. IsPre: 1,
  11756. MedType: strconv.Itoa(int(reg_type)),
  11757. Diagnosis: diagnosis_id,
  11758. }
  11759. err = service.CreateOrder(order)
  11760. if err != nil {
  11761. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  11762. return
  11763. }
  11764. var customs []*Custom
  11765. for _, item := range prescriptions {
  11766. fmt.Println(item.Type)
  11767. if item.Type == 1 { //药品
  11768. for _, subItem := range item.HisDoctorAdviceInfo {
  11769. cus := &Custom{
  11770. AdviceId: subItem.ID,
  11771. ProjectId: 0,
  11772. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  11773. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  11774. FeedetlSn: subItem.FeedetlSn,
  11775. Price: fmt.Sprintf("%.2f", subItem.Price),
  11776. MedListCodg: subItem.MedListCodg,
  11777. Type: 1,
  11778. }
  11779. customs = append(customs, cus)
  11780. }
  11781. }
  11782. if item.Type == 2 { //项目
  11783. for _, subItem := range item.HisPrescriptionProject {
  11784. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  11785. cus := &Custom{
  11786. AdviceId: 0,
  11787. ProjectId: subItem.ID,
  11788. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  11789. Cut: fmt.Sprintf("%.2f", cnt),
  11790. FeedetlSn: subItem.FeedetlSn,
  11791. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  11792. MedListCodg: subItem.MedListCodg,
  11793. Type: 2,
  11794. }
  11795. customs = append(customs, cus)
  11796. }
  11797. }
  11798. for _, item := range item.HisAdditionalCharge {
  11799. cus := &Custom{
  11800. ItemId: item.ID,
  11801. AdviceId: 0,
  11802. ProjectId: 0,
  11803. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  11804. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  11805. FeedetlSn: item.FeedetlSn,
  11806. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  11807. MedListCodg: item.XtHisAddtionConfig.Code,
  11808. Type: 3,
  11809. }
  11810. customs = append(customs, cus)
  11811. }
  11812. }
  11813. fmt.Println(customs)
  11814. for _, item := range customs {
  11815. var advice_id int64 = 0
  11816. var project_id int64 = 0
  11817. var item_id int64 = 0
  11818. var types int64 = 0
  11819. if item.Type == 1 {
  11820. advice_id = item.AdviceId
  11821. project_id = 0
  11822. item_id = 0
  11823. } else if item.Type == 2 {
  11824. advice_id = 0
  11825. item_id = 0
  11826. project_id = item.ProjectId
  11827. } else if item.Type == 3 {
  11828. advice_id = 0
  11829. item_id = item.ItemId
  11830. project_id = 0
  11831. }
  11832. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  11833. cut, _ := strconv.ParseFloat(item.Cut, 32)
  11834. pric, _ := strconv.ParseFloat(item.Price, 32)
  11835. info := &models.HisOrderInfo{
  11836. OrderNumber: order.Number,
  11837. UploadDate: time.Now().Unix(),
  11838. AdviceId: advice_id,
  11839. DetItemFeeSumamt: detItemFeeSumamt,
  11840. Cnt: cut,
  11841. Pric: pric,
  11842. PatientId: id,
  11843. Status: 1,
  11844. Mtime: time.Now().Unix(),
  11845. Ctime: time.Now().Unix(),
  11846. UserOrgId: adminUser.CurrentOrgId,
  11847. HisPatientId: his.ID,
  11848. OrderId: order.ID,
  11849. ProjectId: project_id,
  11850. Type: types,
  11851. ItemId: item_id,
  11852. }
  11853. service.CreateOrderInfo(info)
  11854. }
  11855. his.SickType = sick_type
  11856. service.UpdataHisPateint(&his)
  11857. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  11858. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  11859. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  11860. if err == nil {
  11861. c.ServeSuccessJSON(map[string]interface{}{
  11862. "msg": "结算成功",
  11863. })
  11864. }
  11865. }
  11866. type CustomOrderInfo struct {
  11867. Name string
  11868. Spec string
  11869. Unit string
  11870. Count float64
  11871. Price float64
  11872. Total float64
  11873. }
  11874. func (c *HisApiController) GetPrivateExpensesInfo() {
  11875. order_id, _ := c.GetInt64("id", 0)
  11876. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  11877. order, _ := service.GetHisOrderByID(order_id)
  11878. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  11879. if order.ID == 0 {
  11880. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  11881. return
  11882. }
  11883. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  11884. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  11885. org_id := c.GetAdminUserInfo().CurrentOrgId
  11886. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  11887. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  11888. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  11889. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  11890. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  11891. //var orderInfos_four []*models.HisOrderInfoTwo
  11892. //for _, item := range orderInfos_three {
  11893. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  11894. // item.HisPrescriptionProject.IsCheckTeam = 1
  11895. // orderInfos_four = append(orderInfos_four, item)
  11896. //
  11897. // }
  11898. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  11899. // item.HisPrescriptionProject.IsCheckTeam = 2
  11900. // orderInfos_two = append(orderInfos_two, item)
  11901. // }
  11902. //}
  11903. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  11904. //var cus_slice []CustomOrderInfo
  11905. //for _, item := range new_order_info {
  11906. // var cus CustomOrderInfo
  11907. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  11908. // cus.Unit = ""
  11909. // cus.Spec = ""
  11910. // var total float64
  11911. // for _, subItem := range orderInfos_four {
  11912. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  11913. // total = total + subItem.DetItemFeeSumamt
  11914. // fmt.Println(subItem.DetItemFeeSumamt)
  11915. // }
  11916. // }
  11917. // cus.Count = 1
  11918. // cus.Total = total
  11919. // cus_slice = append(cus_slice, cus)
  11920. //}
  11921. orderInfos = append(orderInfos, orderInfos_two...)
  11922. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  11923. //orderInfos = append(orderInfos, orderInfos_three...)
  11924. //}/**/
  11925. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  11926. c.ServeSuccessJSON(map[string]interface{}{
  11927. "order": order,
  11928. "order_info": orderInfos,
  11929. "patient": patient,
  11930. "admin_info": adminInfo,
  11931. "his": his,
  11932. "current_admin": role,
  11933. "org_config": miConfig,
  11934. //"new_order_info": cus_slice,
  11935. })
  11936. }
  11937. func (this *HisApiController) ChangeMedType() {
  11938. med_type := this.GetString("med_type")
  11939. old_med_type := this.GetString("old_med_type")
  11940. ids := this.GetString("ids")
  11941. settle_type, _ := this.GetInt64("settle_type")
  11942. start_time := this.GetString("start_time")
  11943. end_time := this.GetString("end_time")
  11944. ids_arr := strings.Split(ids, ",")
  11945. if settle_type == 1 { //日结
  11946. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  11947. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  11948. prescription.MedType = med_type
  11949. err := service.SaveHisPrescriptionTwo(&prescription)
  11950. if err == nil {
  11951. this.ServeSuccessJSON(map[string]interface{}{
  11952. "msg": "修改成功",
  11953. })
  11954. } else {
  11955. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11956. return
  11957. }
  11958. } else if settle_type == 2 {
  11959. timeLayout := "2006-01-02"
  11960. loc, _ := time.LoadLocation("Local")
  11961. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11962. if err != nil {
  11963. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11964. return
  11965. }
  11966. recordStartTime := theStartTime.Unix()
  11967. start_time_timestamp := recordStartTime
  11968. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  11969. if err != nil {
  11970. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11971. return
  11972. }
  11973. recordEndTime := theEndTime.Unix()
  11974. end_time_timestamp := recordEndTime
  11975. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  11976. if updateErr == nil {
  11977. this.ServeSuccessJSON(map[string]interface{}{
  11978. "msg": "修改成功",
  11979. })
  11980. } else {
  11981. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11982. return
  11983. }
  11984. }
  11985. }
  11986. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  11987. patient_id, _ := c.GetInt64("patient_id")
  11988. his_patient_id, _ := c.GetInt64("his_patient_id")
  11989. record_date := c.GetString("record_date")
  11990. start_time := c.GetString("start_time")
  11991. end_time := c.GetString("end_time")
  11992. order_status, _ := c.GetInt64("type", 0)
  11993. p_type, _ := c.GetInt64("p_type", 0)
  11994. order_id, _ := c.GetInt64("order_id", 0)
  11995. timeLayout := "2006-01-02"
  11996. loc, _ := time.LoadLocation("Local")
  11997. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11998. if err != nil {
  11999. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12000. return
  12001. }
  12002. recordDateTime := theTime.Unix()
  12003. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12004. if err != nil {
  12005. }
  12006. startRecordDateTime := startTime.Unix()
  12007. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12008. if err != nil {
  12009. }
  12010. endRecordDateTime := endTime.Unix()
  12011. admin := c.GetAdminUserInfo()
  12012. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  12013. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12014. order, _ := service.GetHisOrderByID(order_id)
  12015. var monthPrescriptions []*models.HisPrescription
  12016. if order_status == 1 || order_status == 0 {
  12017. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12018. } else if order_status == 2 {
  12019. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  12020. }
  12021. var settle_total float64
  12022. for _, item := range monthPrescriptions {
  12023. if len(item.HisPrescriptionProject) > 0 {
  12024. for _, subItem := range item.HisPrescriptionProject {
  12025. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12026. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12027. settle_total = settle_total + total
  12028. }
  12029. }
  12030. if len(item.HisDoctorAdviceInfo) > 0 {
  12031. for _, subItem := range item.HisDoctorAdviceInfo {
  12032. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12033. settle_total = settle_total + total
  12034. }
  12035. }
  12036. }
  12037. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12038. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12039. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12040. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12041. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12042. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12043. //获取所有科室信息
  12044. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12045. var dia string
  12046. for _, item := range month_p_info {
  12047. if len(dia) == 0 {
  12048. dia = item.Diagnosis
  12049. } else {
  12050. dia = dia + "," + item.Diagnosis
  12051. }
  12052. }
  12053. dia_arr := removeDuplicates(strings.Split(dia, ","))
  12054. dia_arr = removeEmptyStrings(dia_arr)
  12055. c.ServeSuccessJSON(map[string]interface{}{
  12056. "his_info": his_patient_info,
  12057. "xt_info": xt_patient_info,
  12058. "case_history": case_history,
  12059. "info": patientPrescriptionInfo,
  12060. "last_info": lastPatientPrescriptionInfo,
  12061. "month_prescriptions": monthPrescriptions,
  12062. "order": order,
  12063. "doctors": doctors,
  12064. "department": department,
  12065. "settle_total": settle_total,
  12066. "dia_arr": dia_arr,
  12067. })
  12068. return
  12069. }
  12070. func removeEmptyStrings(input []string) []string {
  12071. var output []string
  12072. for _, s := range input {
  12073. if s != "" {
  12074. output = append(output, s)
  12075. }
  12076. }
  12077. return output
  12078. }
  12079. func removeDuplicates(input []string) []string {
  12080. seen := make(map[string]bool)
  12081. output := []string{}
  12082. for _, s := range input {
  12083. if _, exists := seen[s]; !exists {
  12084. seen[s] = true
  12085. output = append(output, s)
  12086. }
  12087. }
  12088. return output
  12089. }
  12090. func (c *HisApiController) GetHisMonthPatientInfo() {
  12091. patient_id, _ := c.GetInt64("patient_id")
  12092. his_patient_id, _ := c.GetInt64("his_patient_id")
  12093. record_date := c.GetString("record_date")
  12094. number := c.GetString("number")
  12095. start_time := c.GetString("start_time")
  12096. end_time := c.GetString("end_time")
  12097. p_type, _ := c.GetInt64("p_type")
  12098. timeLayout := "2006-01-02"
  12099. loc, _ := time.LoadLocation("Local")
  12100. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12101. if err != nil {
  12102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12103. return
  12104. }
  12105. recordDateTime := theTime.Unix()
  12106. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12107. if err != nil {
  12108. }
  12109. startRecordDateTime := startTime.Unix()
  12110. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12111. if err != nil {
  12112. }
  12113. endRecordDateTime := endTime.Unix()
  12114. admin := c.GetAdminUserInfo()
  12115. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  12116. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12117. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  12118. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12119. var settle_total float64
  12120. for _, item := range monthPrescriptions {
  12121. if len(item.HisPrescriptionProject) > 0 {
  12122. for _, subItem := range item.HisPrescriptionProject {
  12123. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12124. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12125. settle_total = settle_total + total
  12126. }
  12127. }
  12128. if len(item.HisDoctorAdviceInfo) > 0 {
  12129. for _, subItem := range item.HisDoctorAdviceInfo {
  12130. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12131. settle_total = settle_total + total
  12132. }
  12133. }
  12134. }
  12135. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12136. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12137. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12138. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12139. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  12140. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12141. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  12142. //获取所有科室信息
  12143. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12144. c.ServeSuccessJSON(map[string]interface{}{
  12145. "his_info": his_patient_info,
  12146. "xt_info": xt_patient_info,
  12147. "case_history": case_history,
  12148. "info": patientPrescriptionInfo,
  12149. "month_prescriptions": monthPrescriptions,
  12150. "order": order,
  12151. "doctors": doctors,
  12152. "department": department,
  12153. "count": count,
  12154. "drugStockConfig": drugStockConfig,
  12155. "last_info": lastPatientPrescriptionInfo,
  12156. "settle_total": settle_total,
  12157. })
  12158. return
  12159. }
  12160. func (c *HisApiController) GetAllOrder() {
  12161. org_id := c.GetAdminUserInfo().CurrentOrgId
  12162. orders, _ := service.GetNewHisOrderList(org_id)
  12163. c.ServeSuccessJSON(map[string]interface{}{
  12164. "order": orders,
  12165. })
  12166. return
  12167. }
  12168. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  12169. newArr = make([]*models.HisOrderInfoTwo, 0)
  12170. for i := 0; i < len(arr); i++ {
  12171. repeat := false
  12172. for j := i + 1; j < len(arr); j++ {
  12173. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  12174. repeat = true
  12175. break
  12176. }
  12177. }
  12178. if !repeat {
  12179. newArr = append(newArr, arr[i])
  12180. }
  12181. }
  12182. return
  12183. }
  12184. // 修改处方退库操作 参数传修改之前的处方数据
  12185. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  12186. if advice.ExecutionState == 1 {
  12187. //查询该病人该药品是否有库存记录
  12188. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  12189. if errcode == gorm.ErrRecordNotFound {
  12190. } else {
  12191. //退库
  12192. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  12193. if advice.PrescribingNumberUnit == drug.MinUnit {
  12194. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12195. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12196. //退库
  12197. warehouseInfo := models.DrugWarehouseInfo{
  12198. StockMinNumber: prescribingNumber,
  12199. }
  12200. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  12201. operation_time := time.Now().Unix()
  12202. creater := advice.AdviceDoctor
  12203. ctime := time.Now().Unix()
  12204. timeStr := time.Now().Format("2006-01-02")
  12205. timeArr := strings.Split(timeStr, "-")
  12206. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12207. total = total + 1
  12208. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12209. cancelStock := models.DrugCancelStock{
  12210. OrderNumber: orderNumber,
  12211. OperaTime: operation_time,
  12212. OrgId: advice.UserOrgId,
  12213. Creater: creater,
  12214. Ctime: ctime,
  12215. Status: 1,
  12216. ReturnTime: advice.AdviceDate,
  12217. Dealer: info.Dealer,
  12218. Manufacturer: info.Manufacturer,
  12219. Type: 1,
  12220. }
  12221. service.AddSigleDrugCancelStock(&cancelStock)
  12222. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12223. dealer, _ := service.GetDealerById(info.Dealer)
  12224. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12225. cancelStockInfo := models.DrugCancelStockInfo{
  12226. OrderNumber: cancelInfo.OrderNumber,
  12227. CancelStockId: cancelInfo.ID,
  12228. DrugId: info.DrugId,
  12229. Count: info.Count,
  12230. Status: 1,
  12231. Ctime: ctime,
  12232. OrgId: advice.UserOrgId,
  12233. Type: 1,
  12234. Manufacturer: manufactureName.ManufacturerName,
  12235. Dealer: dealer.DealerName,
  12236. Total: 0,
  12237. RetailPrice: info.RetailPrice,
  12238. RetailTotalPrice: info.RetailTotalPrice,
  12239. Price: info.Price,
  12240. RegisterAccount: "",
  12241. Remark: info.Remark,
  12242. BatchNumber: info.BatchNumber,
  12243. MaxUnit: info.CountUnit,
  12244. ProductDate: info.ProductDate,
  12245. ExpiryDate: info.ExpiryDate,
  12246. BatchNumberId: info.WarehouseInfoId,
  12247. }
  12248. flow := models.DrugFlow{
  12249. WarehousingId: 0,
  12250. DrugId: info.DrugId,
  12251. Number: "",
  12252. BatchNumber: info.BatchNumber,
  12253. Count: info.Count,
  12254. UserOrgId: advice.UserOrgId,
  12255. PatientId: 0,
  12256. SystemTime: ctime,
  12257. ConsumableType: 4,
  12258. IsSys: 0,
  12259. WarehousingOrder: "",
  12260. WarehouseOutId: 0,
  12261. WarehouseOutOrderNumber: "",
  12262. IsEdit: 0,
  12263. CancelStockId: cancelStock.ID,
  12264. CancelOrderNumber: cancelStock.OrderNumber,
  12265. Manufacturer: info.Manufacturer,
  12266. Dealer: info.Dealer,
  12267. Creator: advice.UserOrgId,
  12268. UpdateCreator: 0,
  12269. Status: 1,
  12270. Ctime: time.Now().Unix(),
  12271. Mtime: 0,
  12272. Price: info.Price,
  12273. WarehousingDetailId: 0,
  12274. WarehouseOutDetailId: 0,
  12275. CancelOutDetailId: 0,
  12276. ExpireDate: info.ExpiryDate,
  12277. ProductDate: info.ProductDate,
  12278. MaxUnit: info.CountUnit,
  12279. MinUnit: "",
  12280. }
  12281. service.CreatedCancelStock(cancelStockInfo)
  12282. service.CreateDrugFlowOne(flow)
  12283. } else {
  12284. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12285. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12286. if advice.PrescribingNumberUnit == drug.MaxUnit {
  12287. warehouseInfo := models.DrugWarehouseInfo{
  12288. StockMinNumber: prescribingNumber,
  12289. }
  12290. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  12291. }
  12292. operation_time := time.Now().Unix()
  12293. creater := advice.AdviceDoctor
  12294. ctime := time.Now().Unix()
  12295. timeStr := time.Now().Format("2006-01-02")
  12296. timeArr := strings.Split(timeStr, "-")
  12297. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12298. total = total + 1
  12299. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12300. cancelStock := models.DrugCancelStock{
  12301. OrderNumber: orderNumber,
  12302. OperaTime: operation_time,
  12303. OrgId: advice.UserOrgId,
  12304. Creater: creater,
  12305. Ctime: ctime,
  12306. Status: 1,
  12307. ReturnTime: advice.AdviceDate,
  12308. Dealer: info.Dealer,
  12309. Manufacturer: info.Manufacturer,
  12310. Type: 1,
  12311. }
  12312. service.AddSigleDrugCancelStock(&cancelStock)
  12313. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12314. dealer, _ := service.GetDealerById(info.Dealer)
  12315. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12316. cancelStockInfo := models.DrugCancelStockInfo{
  12317. OrderNumber: cancelInfo.OrderNumber,
  12318. CancelStockId: cancelInfo.ID,
  12319. DrugId: info.DrugId,
  12320. Count: info.Count,
  12321. Status: 1,
  12322. Ctime: ctime,
  12323. OrgId: advice.UserOrgId,
  12324. Type: 1,
  12325. Manufacturer: manufactureName.ManufacturerName,
  12326. Dealer: dealer.DealerName,
  12327. Total: 0,
  12328. RetailPrice: info.RetailPrice,
  12329. RetailTotalPrice: info.RetailTotalPrice,
  12330. Price: info.Price,
  12331. RegisterAccount: "",
  12332. Remark: info.Remark,
  12333. BatchNumber: info.BatchNumber,
  12334. MaxUnit: info.CountUnit,
  12335. ProductDate: info.ProductDate,
  12336. ExpiryDate: info.ExpiryDate,
  12337. BatchNumberId: info.WarehouseInfoId,
  12338. }
  12339. flow := models.DrugFlow{
  12340. WarehousingId: 0,
  12341. DrugId: info.DrugId,
  12342. Number: "",
  12343. BatchNumber: info.BatchNumber,
  12344. Count: info.Count,
  12345. UserOrgId: advice.UserOrgId,
  12346. PatientId: 0,
  12347. SystemTime: ctime,
  12348. ConsumableType: 4,
  12349. IsSys: 0,
  12350. WarehousingOrder: "",
  12351. WarehouseOutId: 0,
  12352. WarehouseOutOrderNumber: "",
  12353. IsEdit: 0,
  12354. CancelStockId: cancelStock.ID,
  12355. CancelOrderNumber: cancelStock.OrderNumber,
  12356. Manufacturer: info.Manufacturer,
  12357. Dealer: info.Dealer,
  12358. Creator: advice.AdviceDoctor,
  12359. UpdateCreator: 0,
  12360. Status: 1,
  12361. Ctime: time.Now().Unix(),
  12362. Mtime: 0,
  12363. Price: info.Price,
  12364. WarehousingDetailId: 0,
  12365. WarehouseOutDetailId: 0,
  12366. CancelOutDetailId: 0,
  12367. ExpireDate: info.ExpiryDate,
  12368. ProductDate: info.ProductDate,
  12369. MaxUnit: info.CountUnit,
  12370. MinUnit: "",
  12371. }
  12372. service.CreatedCancelStock(cancelStockInfo)
  12373. service.CreateDrugFlowOne(flow)
  12374. }
  12375. }
  12376. }
  12377. return err
  12378. }
  12379. func (this *HisApiController) DeleteNCDS() {
  12380. id, _ := this.GetInt64("id", 0)
  12381. if id > 0 {
  12382. service.DeletePsnNCDSRecordById(id)
  12383. this.ServeSuccessJSON(map[string]interface{}{
  12384. "msg": "删除成功",
  12385. })
  12386. } else {
  12387. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  12388. return
  12389. }
  12390. }
  12391. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  12392. id, _ := c.GetInt64("id")
  12393. advice, _ := service.GetHisDoctorAdviceInfo(id)
  12394. c.ServeSuccessJSON(map[string]interface{}{
  12395. "advice": advice,
  12396. })
  12397. return
  12398. }
  12399. func (c *HisApiController) GetHisMonthChargePatientList() {
  12400. record_date := c.GetString("record_date")
  12401. start_time := c.GetString("start_time")
  12402. end_time := c.GetString("end_time")
  12403. timeLayout := "2006-01-02"
  12404. loc, _ := time.LoadLocation("Local")
  12405. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12406. if err != nil {
  12407. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12408. return
  12409. }
  12410. if err != nil {
  12411. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12412. return
  12413. }
  12414. recordDateTime := theTime.Unix()
  12415. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12416. if err != nil {
  12417. }
  12418. startRecordDateTime := startTime.Unix()
  12419. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12420. if err != nil {
  12421. }
  12422. endRecordDateTime := endTime.Unix()
  12423. adminInfo := c.GetAdminUserInfo()
  12424. var tempMonthChargePatients []*service.MonthChargePatients
  12425. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  12426. for _, item := range tempPatients {
  12427. //过滤没有处方的
  12428. if len(item.HisPrescription) == 0 {
  12429. tempMonthChargePatients = append(tempMonthChargePatients, item)
  12430. }
  12431. }
  12432. c.ServeSuccessJSON(map[string]interface{}{
  12433. "list": tempMonthChargePatients,
  12434. })
  12435. }
  12436. // PrescriptionDifference 医嘱数量差值结构体
  12437. type PrescriptionDrugDifference struct {
  12438. DrugID int64 //基础库药品id
  12439. ID int64 //医嘱id
  12440. Difference float64 //差值
  12441. Unit string //单位
  12442. }
  12443. type PrescriptionGoodDifference struct {
  12444. GoodID int64 //基础库项目耗材id
  12445. ID int64 //医嘱id
  12446. Difference int64 //差值
  12447. Unit string //单位
  12448. Type int64 //类型
  12449. }
  12450. type EditCustomData struct {
  12451. adviceList []*models.HisDoctorAdviceInfo
  12452. projectList []*models.HisPrescriptionProject
  12453. }
  12454. type SrcCustomData struct {
  12455. adviceList []*models.HisDoctorAdviceInfo
  12456. projectList []*models.HisPrescriptionProject
  12457. }
  12458. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  12459. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  12460. differences := make([]*PrescriptionDrugDifference, 0)
  12461. // 创建一个 map 来存储第一个切片中的药品信息
  12462. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  12463. for _, advice := range firstPrescription {
  12464. firstMap[advice.DrugId] = advice
  12465. }
  12466. // 遍历第二个切片中的药品信息,并比较数量差值
  12467. for _, advice := range secondPrescription {
  12468. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  12469. diff := &PrescriptionDrugDifference{
  12470. DrugID: advice.DrugId,
  12471. ID: firstAdvice.ID,
  12472. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  12473. Unit: firstAdvice.PrescribingNumberUnit,
  12474. }
  12475. differences = append(differences, diff)
  12476. }
  12477. }
  12478. return differences
  12479. }
  12480. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  12481. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  12482. differences := make([]*PrescriptionGoodDifference, 0)
  12483. // 创建一个 map 来存储第一个切片中的耗材信息
  12484. firstMap := make(map[int64]*models.HisPrescriptionProject)
  12485. for _, good := range firstPrescription {
  12486. firstMap[good.ProjectId] = good
  12487. }
  12488. // 遍历第二个切片中的耗材信息,并比较数量差值
  12489. for _, good := range secondPrescription {
  12490. if firstGood, ok := firstMap[good.ProjectId]; ok {
  12491. count, _ := strconv.ParseInt(good.Count, 10, 64)
  12492. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  12493. diff := &PrescriptionGoodDifference{
  12494. GoodID: good.ProjectId,
  12495. ID: firstGood.ID,
  12496. Difference: count - firstCount,
  12497. Unit: firstGood.Unit,
  12498. Type: firstGood.Type,
  12499. }
  12500. differences = append(differences, diff)
  12501. }
  12502. }
  12503. return differences
  12504. }
  12505. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  12506. var adviceList []*models.HisDoctorAdviceInfo
  12507. var projectList []*models.HisPrescriptionProject
  12508. var advice_ids []int64
  12509. var project_ids []int64
  12510. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12511. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12512. //var tempPrescription *models.HisPrescriptionProjectscription
  12513. if len(prescriptions) > 0 {
  12514. for _, item := range prescriptions {
  12515. items := item.(map[string]interface{})
  12516. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12517. advices := items["advices"].([]interface{})
  12518. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12519. groupNo := int64(0)
  12520. ctime := time.Now().Unix()
  12521. mtime := ctime
  12522. if len(advices) > 0 {
  12523. for _, advice := range advices {
  12524. var s models.HisDoctorAdviceInfo
  12525. s.AdviceType = 2
  12526. s.StopState = 2
  12527. s.ExecutionState = 2
  12528. s.Status = 1
  12529. s.Groupno = groupNo
  12530. s.CreatedTime = ctime
  12531. s.UpdatedTime = mtime
  12532. s.IsSettle = 2
  12533. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  12534. //存储切片中
  12535. if s.ID > 0 {
  12536. advice_ids = append(advice_ids, s.ID)
  12537. adviceList = append(adviceList, &s)
  12538. }
  12539. }
  12540. }
  12541. }
  12542. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12543. projects := items["project"].([]interface{})
  12544. if len(projects) > 0 {
  12545. for _, project := range projects {
  12546. var p models.HisPrescriptionProject
  12547. p.Ctime = time.Now().Unix()
  12548. p.Mtime = time.Now().Unix()
  12549. p.Status = 1
  12550. SetProjectWithJSON(&p, project.(map[string]interface{}))
  12551. if p.ID > 0 {
  12552. project_ids = append(project_ids, p.ID)
  12553. projectList = append(projectList, &p)
  12554. }
  12555. }
  12556. }
  12557. }
  12558. }
  12559. }
  12560. }
  12561. editCustomData.projectList = projectList
  12562. editCustomData.adviceList = adviceList
  12563. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  12564. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  12565. srcCustomData.adviceList = list
  12566. srcCustomData.projectList = list2
  12567. return
  12568. }
  12569. func (c *HisApiController) GetAllGoodInforList() {
  12570. orgId := c.GetAdminUserInfo().CurrentOrgId
  12571. goodList, _ := service.GetAllGoodList(orgId)
  12572. c.ServeSuccessJSON(map[string]interface{}{
  12573. "goodList": goodList,
  12574. })
  12575. return
  12576. }