his_api_controller.go 549KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math/rand"
  6. "reflect"
  7. "strconv"
  8. "strings"
  9. "syscall"
  10. "time"
  11. "unsafe"
  12. "XT_New/enums"
  13. "XT_New/models"
  14. "XT_New/service"
  15. "XT_New/utils"
  16. "github.com/astaxie/beego"
  17. "github.com/jinzhu/gorm"
  18. "github.com/mozillazg/go-pinyin"
  19. "github.com/shopspring/decimal"
  20. )
  21. type HisApiController struct {
  22. BaseAuthAPIController
  23. }
  24. func HisManagerApiRegistRouters() {
  25. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  26. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  27. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  28. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  29. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  30. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  31. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  32. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  33. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  34. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  35. //beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  36. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  37. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  41. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  42. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  43. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  44. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  45. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  46. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  47. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  48. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  49. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  50. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  51. //新增附加费用
  52. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  53. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  54. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  55. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  56. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  57. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  58. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  59. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  60. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  61. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  62. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  63. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  64. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  65. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  66. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  67. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  86. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  87. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  88. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  89. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  90. }
  91. func (c *HisApiController) CheckHisPatient() {
  92. record_date := c.GetString("record_date")
  93. patient_id, _ := c.GetInt64("patient_id")
  94. timeLayout := "2006-01-02"
  95. loc, _ := time.LoadLocation("Local")
  96. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  97. if err != nil {
  98. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  99. return
  100. }
  101. recordDateTime := theTime.Unix()
  102. adminInfo := c.GetAdminUserInfo()
  103. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  104. if len(patients) > 1 {
  105. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  106. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  107. c.ServeSuccessJSON(map[string]interface{}{
  108. "status": 1,
  109. "msg": "关联",
  110. "ps": ps,
  111. "his_patient_id": patients[len(patients)-1].ID,
  112. "patient_id": patients[len(patients)-1].PatientId,
  113. })
  114. } else {
  115. c.ServeSuccessJSON(map[string]interface{}{
  116. "status": 0,
  117. "msg": "无需关联",
  118. })
  119. }
  120. } else {
  121. c.ServeSuccessJSON(map[string]interface{}{
  122. "status": 0,
  123. "msg": "无需关联",
  124. })
  125. return
  126. }
  127. }
  128. func (c *HisApiController) AssociationHisPrescription() {
  129. record_date := c.GetString("record_date")
  130. his_patient_id, _ := c.GetInt64("his_patient_id")
  131. patient_id, _ := c.GetInt64("patient_id")
  132. p_ids := c.GetString("p_ids")
  133. p_ids_arr := strings.Split(p_ids, ",")
  134. timeLayout := "2006-01-02"
  135. loc, _ := time.LoadLocation("Local")
  136. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  137. if err != nil {
  138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  139. return
  140. }
  141. recordDateTime := theTime.Unix()
  142. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  143. if his_patient_id == 0 || his_patient.ID == 0 {
  144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  145. return
  146. }
  147. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  148. if err == nil {
  149. c.ServeSuccessJSON(map[string]interface{}{
  150. "msg": "关联处方成功",
  151. })
  152. return
  153. } else {
  154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  155. return
  156. }
  157. }
  158. //func (c *HisApiController) AssociationHisPrescription() {
  159. // record_date, _ := c.GetInt64("record_date")
  160. // his_patient_id, _ := c.GetInt64("his_patient_id")
  161. // patient_id, _ := c.GetInt64("patient_id")
  162. // p_ids := c.GetString("p_ids")
  163. // p_ids_arr := strings.Split(p_ids, ",")
  164. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  165. // if his_patient_id == 0 || his_patient.ID == 0 {
  166. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  167. // return
  168. // }
  169. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  170. // if err == nil {
  171. // c.ServeSuccessJSON(map[string]interface{}{
  172. // "msg": "关联处方成功",
  173. // })
  174. // return
  175. // } else {
  176. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  177. // return
  178. // }
  179. //}
  180. func (c *HisApiController) GetFaPiaoNumber() {
  181. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  182. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  183. fmt.Println(count)
  184. var zero string
  185. number := count + 1
  186. //if number >= 1000 {
  187. // zero = "0000" + strconv.FormatInt(number, 10)
  188. //} else if number >= 10000 {
  189. // zero = "000" + strconv.FormatInt(number, 10)
  190. //} else if number >= 100000 {
  191. // zero = "00" + strconv.FormatInt(number, 10)
  192. //} else if number >= 1000000 {
  193. // zero = "0" + strconv.FormatInt(number, 10)
  194. //} else {
  195. zero = "0" + strconv.FormatInt(number, 10)
  196. //}
  197. c.ServeSuccessJSON(map[string]interface{}{
  198. "fapiao_number": zero,
  199. })
  200. return
  201. }
  202. func (c *HisApiController) ChangeOrderDesc() {
  203. id, _ := c.GetInt64("id")
  204. desc := c.GetString("desc")
  205. change_type := c.GetString("change_type")
  206. order, _ := service.GetHisOrderByID(id)
  207. if order.ID == 0 {
  208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  209. return
  210. }
  211. switch change_type {
  212. case "oth_desc":
  213. order.OthDesc = desc
  214. break
  215. case "cash_pay":
  216. order.CashPay = desc
  217. break
  218. case "jifen_pay":
  219. order.JifenPay = desc
  220. break
  221. case "band_card_pay":
  222. order.BandCardPay = desc
  223. break
  224. case "ali_pay":
  225. order.AliPay = desc
  226. break
  227. case "wechat_pay":
  228. order.WechatPay = desc
  229. break
  230. case "fa_piao_number":
  231. order.FaPiaoNumber = desc
  232. break
  233. case "fa_piao_code":
  234. order.FaPiaoCode = desc
  235. break
  236. }
  237. err := service.SaveHisOrder(&order)
  238. if err == nil {
  239. c.ServeSuccessJSON(map[string]interface{}{
  240. "msg": "修改成功",
  241. })
  242. return
  243. } else {
  244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  245. return
  246. }
  247. }
  248. func (c *HisApiController) GetMonthHisPatient() {
  249. record_date := c.GetString("record_date")
  250. //order_status, _ := c.GetInt64("type")
  251. timeLayout := "2006-01-02"
  252. loc, _ := time.LoadLocation("Local")
  253. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  254. if err != nil {
  255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  256. return
  257. }
  258. recordDateTime := theTime.Unix()
  259. adminInfo := c.GetAdminUserInfo()
  260. var tempPatients []service.NewTempPatients
  261. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  262. // 获取当前时间
  263. now := time.Now()
  264. // 获取本月的第一天
  265. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  266. // 获取下个月的第一天
  267. nextMonth := firstDay.AddDate(0, 1, 0)
  268. // 获取本月的最后一天
  269. lastDay := nextMonth.Add(-time.Nanosecond)
  270. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  271. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  272. var patients []service.NewTempPatients
  273. var patients_two []service.NewTempPatients
  274. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  275. for _, item := range tempPatients {
  276. //过滤掉没挂号的和没开处方的
  277. if len(item.HisPrescription) > 0 {
  278. patients = append(patients, item)
  279. patients_two = append(patients_two, item)
  280. }
  281. ////过滤掉没挂号的
  282. //if len(item.HisPatient) > 0 {
  283. //}
  284. }
  285. } else {
  286. for _, item := range tempPatients {
  287. //过滤掉没挂号的和没开处方的
  288. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  289. patients = append(patients, item)
  290. }
  291. ////过滤掉没挂号的
  292. //if len(item.HisPatient) > 0 {
  293. // patients_two = append(patients_two, item)
  294. //}
  295. }
  296. }
  297. c.ServeSuccessJSON(map[string]interface{}{
  298. "list": patients,
  299. "list_two": patients_two,
  300. "chargePatients": chargePatients,
  301. })
  302. }
  303. func (c *HisApiController) GetBatchSettleAccounts() {
  304. order_ids := c.GetString("order_ids")
  305. admin_user_id, _ := c.GetInt64("admin_user_id")
  306. adminUser := c.GetAdminUserInfo()
  307. orders := strings.Split(order_ids, ",")
  308. var newOrders []models.Orders
  309. for _, item := range orders {
  310. order, _ := service.GetHisOrderByIDTenOne(item)
  311. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  312. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  313. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  314. orderInfos = append(orderInfos, orderInfos_two...)
  315. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  316. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  317. var diagnosis_ids []string
  318. if his.ID > 0 {
  319. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  320. } else {
  321. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  322. }
  323. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  324. var dia_config []*models.HisXtDiagnoseConfig
  325. var name string
  326. for _, item := range diagnosis_ids {
  327. id, _ := strconv.ParseInt(item, 10, 64)
  328. diagnosisConfig, _ := service.FindDiagnoseById(id)
  329. dia_config = append(dia_config, diagnosisConfig)
  330. if len(name) == 0 {
  331. name = diagnosisConfig.ClassName
  332. } else {
  333. name = name + "," + diagnosisConfig.ClassName
  334. }
  335. }
  336. var bedCostTotal float64 = 0 //床位总费
  337. var bedCostSelfTotal float64 = 0 //床位自费
  338. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  339. var bedSelfTotal float64 = 0 //床位部分项目自费
  340. var bedInscpTotal float64 = 0 //床位部分项目自费
  341. var operationCostTotal float64 = 0 //手术费
  342. var operationCostSelfTotal float64 = 0 //手术费
  343. var operationCostPartSelfTotal float64 = 0 //手术费
  344. var operationSelfTotal float64 = 0 //床位部分项目自费
  345. var operationInscpTotal float64 = 0 //床位部分项目自费
  346. var otherCostTotal float64 = 0 //其他费用
  347. var otherCostSelfTotal float64 = 0 //其他费用
  348. var otherCostPartSelfTotal float64 = 0 //其他费用
  349. var otherSelfTotal float64 = 0 //床位部分项目自费
  350. var otherInscpTotal float64 = 0 //床位部分项目自费
  351. var materialCostTotal float64 = 0 //材料费
  352. var materialCostSelfTotal float64 = 0 //材料费
  353. var materialCostPartSelfTotal float64 = 0 //材料费
  354. var materialSelfTotal float64 = 0 //床位部分项目自费
  355. var materialInscpTotal float64 = 0 //床位部分项目自费
  356. var westernMedicineCostTotal float64 = 0 //西药费
  357. var westernMedicineCostSelfTotal float64 = 0 //西药费
  358. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  359. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  360. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  361. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  362. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  363. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  364. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  365. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  366. var checkCostTotal float64 = 0 //检查费
  367. var checkCostSelfTotal float64 = 0 //检查费
  368. var checkCostPartSelfTotal float64 = 0 //检查费
  369. var checkSelfTotal float64 = 0 //床位部分项目自费
  370. var checkInscpTotal float64 = 0 //床位部分项目自费
  371. var laboratoryCostTotal float64 = 0 //化验费
  372. var laboratoryCostSelfTotal float64 = 0 //化验费
  373. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  374. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  375. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  376. var treatCostTotal float64 = 0 //治疗费用
  377. var treatCostSelfTotal float64 = 0 //治疗费用
  378. var treatCostPartSelfTotal float64 = 0 //治疗费用
  379. var treatSelfTotal float64 = 0 //床位部分项目自费
  380. var treatInscpTotal float64 = 0 //床位部分项目自费
  381. decimal.DivisionPrecision = 2
  382. for _, item := range orderInfos {
  383. if item.MedChrgitmType == "01" { //床位费
  384. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  385. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  386. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  387. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  388. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  389. }
  390. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  391. if item.MedChrgitmType == "03" { //检查费
  392. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  393. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  394. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  395. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  396. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  397. }
  398. } else {
  399. if item.MedChrgitmType == "03" { //检查费
  400. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  401. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  402. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  403. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  404. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  405. }
  406. }
  407. if item.MedChrgitmType == "04" { //化验费
  408. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  409. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  410. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  411. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  412. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  413. }
  414. if item.MedChrgitmType == "05" { //治疗费
  415. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  416. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  417. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  418. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  419. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  420. }
  421. if item.MedChrgitmType == "06" { //手术费
  422. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  423. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  424. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  425. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  426. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  427. }
  428. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  429. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  430. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  431. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  432. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  433. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  434. }
  435. if item.MedChrgitmType == "09" { //西药费
  436. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  437. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  438. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  439. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  440. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  441. }
  442. if item.MedChrgitmType == "11" { //中成费
  443. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  444. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  445. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  446. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  447. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  448. }
  449. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  450. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  451. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  452. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  453. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  454. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  455. }
  456. }
  457. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  458. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  459. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  460. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  461. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  462. var doctor_name string
  463. if roles.ID == 0 {
  464. doctor_name = "管理员"
  465. } else {
  466. doctor_name = roles.UserName
  467. }
  468. yiliao_leibie := ""
  469. switch order.MedType {
  470. case "11":
  471. yiliao_leibie = "普通门诊"
  472. break
  473. case "12":
  474. yiliao_leibie = "门诊挂号"
  475. break
  476. case "13":
  477. yiliao_leibie = "急诊"
  478. break
  479. case "14":
  480. yiliao_leibie = "门诊特殊病"
  481. break
  482. case "15":
  483. yiliao_leibie = "门诊统筹"
  484. break
  485. case "16":
  486. yiliao_leibie = "门诊慢性病"
  487. break
  488. case "21":
  489. yiliao_leibie = "普通住院"
  490. break
  491. }
  492. var newOrder models.Orders
  493. newOrder.Diagnosis = name
  494. newOrder.OrderInfos = orderInfos
  495. newOrder.Number = order.MdtrtId
  496. newOrder.Date = order.SettleAccountsDate
  497. newOrder.ChargeAdmin = charge_admin
  498. newOrder.PrintorAdmin = printor_admin
  499. newOrder.Order = order
  500. newOrder.BedCostTotal = bedCostTotal
  501. newOrder.BedCostSelfTotal = bedCostSelfTotal
  502. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  503. newOrder.BedSelfTotal = bedSelfTotal
  504. newOrder.BedInscpTotal = bedInscpTotal
  505. newOrder.OperationCostTotal = operationCostTotal
  506. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  507. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  508. newOrder.OperationSelfTotal = operationSelfTotal
  509. newOrder.OperationInscpTotal = operationInscpTotal
  510. newOrder.OtherCostTotal = otherCostTotal
  511. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  512. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  513. newOrder.OtherSelfTotal = otherSelfTotal
  514. newOrder.OtherInscpTotal = otherInscpTotal
  515. newOrder.MaterialCostTotal = materialCostTotal
  516. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  517. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  518. newOrder.MaterialSelfTotal = materialSelfTotal
  519. newOrder.MaterialInscpTotal = materialInscpTotal
  520. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  521. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  522. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  523. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  524. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  525. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  526. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  527. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  528. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  529. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  530. newOrder.CheckCostTotal = checkCostTotal
  531. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  532. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  533. newOrder.CheckSelfTotal = checkSelfTotal
  534. newOrder.CheckInscpTotal = checkInscpTotal
  535. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  536. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  537. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  538. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  539. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  540. newOrder.TreatCostTotal = treatCostTotal
  541. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  542. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  543. newOrder.TreatSelfTotal = treatSelfTotal
  544. newOrder.TreatInscpTotal = treatInscpTotal
  545. newOrder.DoctorInfo = doctor_info
  546. newOrder.DoctorName = doctor_name
  547. newOrder.HealthCardNo = order.PsnNo
  548. newOrder.YiliaoLeibie = yiliao_leibie
  549. newOrder.Patient = patient
  550. newOrder.OrgName = miConfig.OrgName
  551. newOrder.OrgCode = miConfig.Code
  552. newOrder.OrderNumber = order.Number
  553. newOrder.HisPatient = his
  554. newOrder.DiaConfig = dia_config
  555. newOrders = append(newOrders, newOrder)
  556. }
  557. c.ServeSuccessJSON(map[string]interface{}{
  558. "orders": newOrders,
  559. })
  560. }
  561. func (c *HisApiController) GetTestOrder() {
  562. order_id, _ := c.GetInt64("order_id")
  563. admin_user_id, _ := c.GetInt64("admin_user_id")
  564. adminUser := c.GetAdminUserInfo()
  565. order, _ := service.GetHisOrderByID(order_id)
  566. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  567. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  568. orderInfos = append(orderInfos, orderInfos_two...)
  569. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  570. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  571. var dia_config []*models.HisXtDiagnoseConfig
  572. var name string
  573. var bedCostTotal float64 = 0 //床位总费
  574. var bedCostSelfTotal float64 = 0 //床位自费
  575. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  576. var bedSelfTotal float64 = 0 //床位部分项目自费
  577. var bedInscpTotal float64 = 0 //床位部分项目自费
  578. var operationCostTotal float64 = 0 //手术费
  579. var operationCostSelfTotal float64 = 0 //手术费
  580. var operationCostPartSelfTotal float64 = 0 //手术费
  581. var operationSelfTotal float64 = 0 //床位部分项目自费
  582. var operationInscpTotal float64 = 0 //床位部分项目自费
  583. var otherCostTotal float64 = 0 //其他费用
  584. var otherCostSelfTotal float64 = 0 //其他费用
  585. var otherCostPartSelfTotal float64 = 0 //其他费用
  586. var otherSelfTotal float64 = 0 //床位部分项目自费
  587. var otherInscpTotal float64 = 0 //床位部分项目自费
  588. var materialCostTotal float64 = 0 //材料费
  589. var materialCostSelfTotal float64 = 0 //材料费
  590. var materialCostPartSelfTotal float64 = 0 //材料费
  591. var materialSelfTotal float64 = 0 //床位部分项目自费
  592. var materialInscpTotal float64 = 0 //床位部分项目自费
  593. var westernMedicineCostTotal float64 = 0 //西药费
  594. var westernMedicineCostSelfTotal float64 = 0 //西药费
  595. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  596. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  597. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  598. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  599. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  600. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  601. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  602. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  603. var checkCostTotal float64 = 0 //检查费
  604. var checkCostSelfTotal float64 = 0 //检查费
  605. var checkCostPartSelfTotal float64 = 0 //检查费
  606. var checkSelfTotal float64 = 0 //床位部分项目自费
  607. var checkInscpTotal float64 = 0 //床位部分项目自费
  608. var laboratoryCostTotal float64 = 0 //化验费
  609. var laboratoryCostSelfTotal float64 = 0 //化验费
  610. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  611. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  612. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  613. var treatCostTotal float64 = 0 //治疗费用
  614. var treatCostSelfTotal float64 = 0 //治疗费用
  615. var treatCostPartSelfTotal float64 = 0 //治疗费用
  616. var treatSelfTotal float64 = 0 //床位部分项目自费
  617. var treatInscpTotal float64 = 0 //床位部分项目自费
  618. decimal.DivisionPrecision = 2
  619. for _, item := range orderInfos {
  620. if item.MedChrgitmType == "01" { //床位费
  621. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  622. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  623. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  624. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  625. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  626. }
  627. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  628. if item.MedChrgitmType == "03" { //检查费
  629. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  630. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  631. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  632. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  633. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  634. }
  635. } else {
  636. if item.MedChrgitmType == "03" { //检查费
  637. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  638. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  639. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  640. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  641. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  642. }
  643. }
  644. if item.MedChrgitmType == "04" { //化验费
  645. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  646. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  647. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  648. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  649. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  650. }
  651. if item.MedChrgitmType == "05" { //治疗费
  652. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  653. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  654. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  655. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  656. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  657. }
  658. if item.MedChrgitmType == "06" { //手术费
  659. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  660. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  661. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  662. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  663. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  664. }
  665. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  666. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  667. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  668. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  669. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  670. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  671. }
  672. if item.MedChrgitmType == "09" { //西药费
  673. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  674. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  675. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  676. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  677. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  678. }
  679. if item.MedChrgitmType == "11" { //中成费
  680. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  681. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  682. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  683. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  684. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  685. }
  686. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  687. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  688. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  689. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  690. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  691. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  692. }
  693. }
  694. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  695. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  696. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  697. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  698. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  699. var doctor_name string
  700. if roles.ID == 0 {
  701. doctor_name = "管理员"
  702. } else {
  703. doctor_name = roles.UserName
  704. }
  705. yiliao_leibie := ""
  706. switch order.MedType {
  707. case "11":
  708. yiliao_leibie = "普通门诊"
  709. break
  710. case "12":
  711. yiliao_leibie = "门诊挂号"
  712. break
  713. case "13":
  714. yiliao_leibie = "急诊"
  715. break
  716. case "14":
  717. yiliao_leibie = "门诊特殊病"
  718. break
  719. case "15":
  720. yiliao_leibie = "门诊统筹"
  721. break
  722. case "16":
  723. yiliao_leibie = "门诊慢性病"
  724. break
  725. case "21":
  726. yiliao_leibie = "普通住院"
  727. break
  728. }
  729. c.ServeSuccessJSON(map[string]interface{}{
  730. "diagnosis": name,
  731. "order_infos": orderInfos,
  732. "number": order.MdtrtId,
  733. "date": order.SettleAccountsDate,
  734. "charge_admin": charge_admin,
  735. "printor_admin": printor_admin,
  736. "info": order,
  737. "order": order,
  738. "bedCostTotal": bedCostTotal,
  739. "bedCostSelfTotal": bedCostSelfTotal,
  740. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  741. "bedSelfTotal": bedSelfTotal,
  742. "bedInscpTotal": bedInscpTotal,
  743. "operationCostTotal": operationCostTotal,
  744. "operationCostSelfTotal": operationCostSelfTotal,
  745. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  746. "operationSelfTotal": operationSelfTotal,
  747. "operationInscpTotal": operationInscpTotal,
  748. "otherCostTotal": otherCostTotal,
  749. "otherCostSelfTotal": otherCostSelfTotal,
  750. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  751. "otherSelfTotal": otherSelfTotal,
  752. "otherInscpTotal": otherInscpTotal,
  753. "materialCostTotal": materialCostTotal,
  754. "materialCostSelfTotal": materialCostSelfTotal,
  755. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  756. "materialSelfTotal": materialSelfTotal,
  757. "materialInscpTotal": materialInscpTotal,
  758. "westernMedicineCostTotal": westernMedicineCostTotal,
  759. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  760. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  761. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  762. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  763. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  764. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  765. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  766. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  767. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  768. "checkCostTotal": checkCostTotal,
  769. "checkCostSelfTotal": checkCostSelfTotal,
  770. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  771. "checkSelfTotal": checkSelfTotal,
  772. "checkInscpTotal": checkInscpTotal,
  773. "laboratoryCostTotal": laboratoryCostTotal,
  774. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  775. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  776. "laboratorySelfTotal": laboratorySelfTotal,
  777. "laboratoryInscpTotal": laboratoryInscpTotal,
  778. "treatCostTotal": treatCostTotal,
  779. "treatCostSelfTotal": treatCostSelfTotal,
  780. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  781. "treatSelfTotal": treatSelfTotal,
  782. "treatInscpTotal": treatInscpTotal,
  783. "doctor_info": doctor_info,
  784. "doctor_name": doctor_name,
  785. "health_card_no": order.PsnNo,
  786. "yiliao_leibie": yiliao_leibie,
  787. "patient": patient,
  788. "org_name": miConfig.OrgName,
  789. "org_code": miConfig.Code,
  790. "order_number": order.Number,
  791. "his_hospital": his_hospital,
  792. "dia_config": dia_config,
  793. })
  794. }
  795. type CustomFundPay struct {
  796. FundPayType string `json:"fund_pay_type"`
  797. FundPayamt float64 `json:"fund_payamt"`
  798. InscpScpAmt float64 `json:"inscp_scp_amt"`
  799. }
  800. func (c *PublicApiController) GetBaiLinExportData() {
  801. data := service.GetBaiLinOrderData()
  802. fmt.Println(len(data))
  803. var new_data []*models.NewCustomHisOrder
  804. for _, item := range data {
  805. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  806. new_data = append(new_data, item)
  807. }
  808. }
  809. fmt.Println(len(new_data))
  810. c.ServeSuccessJSON(map[string]interface{}{
  811. "list": new_data,
  812. })
  813. }
  814. func (c *HisApiController) GetHisUnChargePatientList() {
  815. record_date := c.GetString("record_date")
  816. sch_type, _ := c.GetInt64("sch_type")
  817. timeLayout := "2006-01-02"
  818. loc, _ := time.LoadLocation("Local")
  819. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  820. if err != nil {
  821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  822. return
  823. }
  824. recordDateTime := theTime.Unix()
  825. adminInfo := c.GetAdminUserInfo()
  826. var tempPatients []*service.NewTempPatients
  827. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  828. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  829. var patients []*service.NewTempPatients
  830. var patients_two []*service.NewTempPatients
  831. for _, item := range tempPatients {
  832. //过滤掉没挂号的和没开处方的
  833. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  834. patients = append(patients, item)
  835. }
  836. //过滤掉没挂号的
  837. if len(item.HisPatient) > 0 {
  838. patients_two = append(patients_two, item)
  839. }
  840. }
  841. c.ServeSuccessJSON(map[string]interface{}{
  842. "list": patients,
  843. "list_two": patients_two,
  844. })
  845. }
  846. func (c *HisApiController) GetPrivateExpensesOrder() {
  847. //id, _ := c.GetInt64("id")
  848. //record_time := c.GetString("record_time")
  849. order_id, _ := c.GetInt64("order_id")
  850. admin_user_id, _ := c.GetInt64("admin_user_id")
  851. //timeLayout := "2006-01-02"
  852. //loc, _ := time.LoadLocation("Local")
  853. //
  854. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  855. //if err != nil {
  856. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  857. // return
  858. //}
  859. //recordDateTime := theTime.Unix()
  860. adminUser := c.GetAdminUserInfo()
  861. order, _ := service.GetHisOrderByID(order_id)
  862. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  863. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  864. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  865. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  866. //var config []*models.HisXtDiagnoseConfig
  867. var name string
  868. if order.PType == 1 {
  869. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  870. for _, item := range diagnosis_ids {
  871. id, _ := strconv.ParseInt(item, 10, 64)
  872. diagnosisConfig, _ := service.FindDiagnoseById(id)
  873. if len(name) == 0 {
  874. name = diagnosisConfig.ClassName
  875. } else {
  876. name = name + "," + diagnosisConfig.ClassName
  877. }
  878. }
  879. } else {
  880. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  881. for _, item := range diagnosis_ids {
  882. id, _ := strconv.ParseInt(item, 10, 64)
  883. diagnosisConfig, _ := service.FindDiagnoseById(id)
  884. if len(name) == 0 {
  885. name = diagnosisConfig.ClassName
  886. } else {
  887. name = name + "," + diagnosisConfig.ClassName
  888. }
  889. }
  890. }
  891. var bedCostTotal float64 = 0 //床位总费
  892. //var bedCostSelfTotal float64 = 0 //床位自费
  893. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  894. var operationCostTotal float64 = 0 //手术费
  895. //var operationCostSelfTotal float64 = 0 //手术费
  896. var operationCostPartSelfTotal float64 = 0 //手术费
  897. var otherCostTotal float64 = 0 //其他费用
  898. //var otherCostSelfTotal float64 = 0 //其他费用
  899. var otherCostPartSelfTotal float64 = 0 //其他费用
  900. var materialCostTotal float64 = 0 //材料费
  901. //var materialCostSelfTotal float64 = 0 //材料费
  902. var materialCostPartSelfTotal float64 = 0 //材料费
  903. var westernMedicineCostTotal float64 = 0 //西药费
  904. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  905. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  906. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  907. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  908. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  909. var checkCostTotal float64 = 0 //检查费
  910. //var checkCostSelfTotal float64 = 0 //检查费
  911. var checkCostPartSelfTotal float64 = 0 //检查费
  912. var laboratoryCostTotal float64 = 0 //化验费
  913. //var laboratoryCostSelfTotal float64 = 0 //化验费
  914. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  915. var treatCostTotal float64 = 0 //治疗费用
  916. //var treatCostSelfTotal float64 = 0 //治疗费用
  917. var treatCostPartSelfTotal float64 = 0 //治疗费用
  918. var zhenChaCostTotal float64 = 0 //其他费用
  919. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  920. decimal.DivisionPrecision = 2
  921. for _, item := range orderInfos {
  922. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  923. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  924. item.MedChrgitmType = "09"
  925. }
  926. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  927. if item.HisPrescriptionProject.Type == 2 {
  928. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  929. fmt.Println("CostClassify")
  930. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  931. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  932. case 0:
  933. item.MedChrgitmType = "0"
  934. break
  935. case 1:
  936. item.MedChrgitmType = "14"
  937. break
  938. case 2:
  939. item.MedChrgitmType = "05"
  940. break
  941. case 3:
  942. item.MedChrgitmType = "03"
  943. break
  944. case 4:
  945. item.MedChrgitmType = "03"
  946. break
  947. case 5:
  948. item.MedChrgitmType = "08"
  949. break
  950. case 6:
  951. item.MedChrgitmType = "14"
  952. break
  953. case 7:
  954. item.MedChrgitmType = "14"
  955. break
  956. case 8:
  957. item.MedChrgitmType = "03"
  958. break
  959. case 9:
  960. item.MedChrgitmType = "14"
  961. break
  962. case 10:
  963. item.MedChrgitmType = "14"
  964. break
  965. case 11:
  966. item.MedChrgitmType = "06"
  967. break
  968. case 12:
  969. item.MedChrgitmType = "12"
  970. break
  971. case 13:
  972. item.MedChrgitmType = "01"
  973. break
  974. case 14:
  975. item.MedChrgitmType = "04"
  976. break
  977. case 15:
  978. item.MedChrgitmType = "14"
  979. break
  980. }
  981. } else {
  982. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  983. case 1:
  984. item.MedChrgitmType = "14"
  985. break
  986. case 2:
  987. item.MedChrgitmType = "05"
  988. break
  989. case 3:
  990. item.MedChrgitmType = "04"
  991. break
  992. case 4:
  993. item.MedChrgitmType = "14"
  994. break
  995. case 5:
  996. item.MedChrgitmType = "08"
  997. break
  998. case 6:
  999. item.MedChrgitmType = "14"
  1000. break
  1001. case 7:
  1002. item.MedChrgitmType = "14"
  1003. break
  1004. case 8:
  1005. item.MedChrgitmType = "03"
  1006. break
  1007. case 9:
  1008. item.MedChrgitmType = "14"
  1009. break
  1010. default:
  1011. item.MedChrgitmType = "14"
  1012. break
  1013. }
  1014. }
  1015. } else if item.HisPrescriptionProject.Type == 3 {
  1016. item.MedChrgitmType = "08"
  1017. }
  1018. }
  1019. }
  1020. if order.IsMedicineInsurance != 1 {
  1021. order.PsnCashPay = order.MedfeeSumamt
  1022. }
  1023. for _, item := range orderInfos {
  1024. if item.MedChrgitmType == "01" { //床位费
  1025. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1026. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1027. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1028. }
  1029. if item.MedChrgitmType == "02" { //诊察费
  1030. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1031. //zhenChaCostSelfTotal = zhenChaCostTotal
  1032. }
  1033. if item.MedChrgitmType == "03" { //检查费
  1034. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1035. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1036. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1037. }
  1038. if item.MedChrgitmType == "02" { //检查费
  1039. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1040. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1041. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1042. }
  1043. if item.MedChrgitmType == "04" { //化验费
  1044. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1045. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1046. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1047. }
  1048. if item.MedChrgitmType == "05" { //治疗费
  1049. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1050. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1051. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1052. }
  1053. if item.MedChrgitmType == "06" { //手术费
  1054. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1055. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1056. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1057. }
  1058. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1059. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1060. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1061. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1062. }
  1063. if item.MedChrgitmType == "09" { //西药费
  1064. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1065. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1066. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1067. }
  1068. if item.MedChrgitmType == "11" { //中成费
  1069. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1070. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1071. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1072. }
  1073. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1074. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1075. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1076. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1077. }
  1078. }
  1079. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1080. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1081. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1082. var dia_config []*models.HisXtDiagnoseConfig
  1083. var diagnosis_ids []string
  1084. if his.ID > 0 {
  1085. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1086. } else {
  1087. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1088. }
  1089. for _, item := range diagnosis_ids {
  1090. id, _ := strconv.ParseInt(item, 10, 64)
  1091. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1092. dia_config = append(dia_config, diagnosisConfig)
  1093. }
  1094. var rf []CustomFundPay
  1095. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1096. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1097. c.ServeSuccessJSON(map[string]interface{}{
  1098. "patient": patient,
  1099. "order_infos": orderInfos,
  1100. "diagnosis": name,
  1101. "bedCostTotal": bedCostTotal,
  1102. "bedCostSelfTotal": bedCostTotal,
  1103. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1104. "operationCostTotal": operationCostTotal,
  1105. "operationCostSelfTotal": operationCostTotal,
  1106. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1107. "otherCostTotal": otherCostTotal,
  1108. "otherCostSelfTotal": otherCostTotal,
  1109. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1110. "materialCostTotal": materialCostTotal,
  1111. "materialCostSelfTotal": materialCostTotal,
  1112. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1113. "westernMedicineCostTotal": westernMedicineCostTotal,
  1114. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1115. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1116. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1117. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1118. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1119. "checkCostTotal": checkCostTotal,
  1120. "checkCostSelfTotal": checkCostTotal,
  1121. "zhenChaCostTotal": zhenChaCostTotal,
  1122. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1123. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1124. "laboratoryCostTotal": laboratoryCostTotal,
  1125. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1126. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1127. "treatCostTotal": treatCostTotal,
  1128. "treatCostSelfTotal": treatCostTotal,
  1129. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1130. "charge_admin": charge_admin,
  1131. "printor_admin": printor_admin,
  1132. "org_name": org.OrgName,
  1133. "org_code": miConfig.Code,
  1134. "name": patient.Name,
  1135. "number": order.MdtrtId,
  1136. "date": order.SettleAccountsDate,
  1137. "info": order,
  1138. "new_order": order,
  1139. "his_hospital": his_hospital,
  1140. "his": his,
  1141. "funds": rf,
  1142. "dia_config": dia_config,
  1143. })
  1144. }
  1145. func (c *HisApiController) RefudDetail() {
  1146. order_id, _ := c.GetInt64("order_id")
  1147. order, _ := service.GetHisOrderByID(order_id)
  1148. adminUser := c.GetAdminUserInfo()
  1149. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1150. c.ServeSuccessJSON(map[string]interface{}{
  1151. "msg": "撤销成功",
  1152. })
  1153. }
  1154. func (c *HisApiController) Sscard() {
  1155. //r := CardInit()
  1156. //if r == 0 {
  1157. // GetBaseInfo()
  1158. //}
  1159. //c.ServeSuccessJSON(map[string]interface{}{
  1160. // "list": "11",
  1161. //})
  1162. }
  1163. func GetBaseInfo() error {
  1164. //handle := syscall.MustLoadDLL("SSCard.dll")
  1165. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1166. //
  1167. //str := make([]byte, 256)
  1168. //str1 := make([]byte, 256)
  1169. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1170. //if ferr != nil {
  1171. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1172. // return ferr
  1173. //}
  1174. //
  1175. //fmt.Println(string(str))
  1176. //
  1177. //fmt.Println(r)
  1178. return nil
  1179. }
  1180. func CardInit() int {
  1181. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1182. //add := DllTestDef.MustFindProc("Init")
  1183. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1184. //if err != nil {
  1185. // fmt.Println("SSCard的运算结果为:", ret)
  1186. //}
  1187. //result := int(ret)
  1188. return 0
  1189. }
  1190. func IntPtr(n int) uintptr {
  1191. return uintptr(n)
  1192. }
  1193. func StrPtr(s string) uintptr {
  1194. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1195. }
  1196. func (c *HisApiController) GetHisPatientList() {
  1197. //types, _ := c.GetInt64("type", 0)
  1198. record_date := c.GetString("record_date")
  1199. sch_type, _ := c.GetInt64("sch_type")
  1200. timeLayout := "2006-01-02"
  1201. loc, _ := time.LoadLocation("Local")
  1202. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1203. if err != nil {
  1204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1205. return
  1206. }
  1207. recordDateTime := theTime.Unix()
  1208. adminInfo := c.GetAdminUserInfo()
  1209. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1210. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1211. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1212. //patient_three, _ := service.GetNewHisPatientListTwo(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1213. //patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1214. //获取当前用户的信息
  1215. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1216. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1217. //获取所有科室信息
  1218. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1219. //var aa []service.PatientThree
  1220. noElementsSlice := make([]service.PatientThree, 0)
  1221. c.ServeSuccessJSON(map[string]interface{}{
  1222. "list": patients,
  1223. "list_two": patients_two,
  1224. "list_three": noElementsSlice,
  1225. "info": adminUserInfo,
  1226. "doctors": doctors,
  1227. "department": department,
  1228. })
  1229. }
  1230. type CustomTemplate struct {
  1231. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1232. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1233. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1234. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1235. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1236. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1237. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1238. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1239. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1240. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1241. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1242. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1243. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1244. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1245. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1246. }
  1247. func (c *HisApiController) GetHisPatientInfo() {
  1248. patient_id, _ := c.GetInt64("patient_id")
  1249. his_patient_id, _ := c.GetInt64("his_patient_id")
  1250. record_date := c.GetString("record_date")
  1251. number := c.GetString("number")
  1252. //start_time := c.GetString("start_time")
  1253. //end_time := c.GetString("end_time")
  1254. p_type, _ := c.GetInt64("p_type")
  1255. timeLayout := "2006-01-02"
  1256. loc, _ := time.LoadLocation("Local")
  1257. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1258. if err != nil {
  1259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1260. return
  1261. }
  1262. recordDateTime := theTime.Unix()
  1263. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1264. //if err != nil {
  1265. //
  1266. //}
  1267. //startRecordDateTime := startTime.Unix()
  1268. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1269. //if err != nil {
  1270. //
  1271. //}
  1272. //endRecordDateTime := endTime.Unix()
  1273. admin := c.GetAdminUserInfo()
  1274. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1275. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1276. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1277. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1278. var prescriptions []*models.HisPrescription
  1279. var last_prescriptions []*models.HisPrescription
  1280. var sch_prescriptions []CustomTemplate
  1281. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1282. if p_type == 1 { //住院
  1283. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1284. for _, item := range prescriptions {
  1285. for _, subItem := range item.HisDoctorAdviceInfo {
  1286. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1287. if info.RetailPrice > 0 {
  1288. subItem.Drug.MinPrice = info.RetailPrice
  1289. }
  1290. }
  1291. }
  1292. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1293. } else { //门诊
  1294. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1295. for _, item := range prescriptions {
  1296. for _, subItem := range item.HisDoctorAdviceInfo {
  1297. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1298. if info.RetailPrice > 0 {
  1299. subItem.Drug.MinPrice = info.RetailPrice
  1300. }
  1301. }
  1302. }
  1303. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1304. }
  1305. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1306. if sch.ID > 0 {
  1307. var week string
  1308. t := time.Now()
  1309. switch t.Weekday().String() {
  1310. case "Monday":
  1311. week = "周一"
  1312. break
  1313. case "Tuesday":
  1314. week = "周二"
  1315. break
  1316. case "Wednesday":
  1317. week = "周三"
  1318. break
  1319. case "Thursday":
  1320. week = "周四"
  1321. break
  1322. case "Friday":
  1323. week = "周五"
  1324. break
  1325. case "Saturday":
  1326. week = "周六"
  1327. break
  1328. case "Sunday":
  1329. week = "周日"
  1330. break
  1331. }
  1332. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1333. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1334. //根据推送频率组装新的数组
  1335. for _, item := range temp_sch_prescriptions {
  1336. var cus CustomTemplate
  1337. cus.ID = item.ID
  1338. cus.UserOrgId = item.UserOrgId
  1339. cus.PatientId = item.PatientId
  1340. cus.MedType = item.MedType
  1341. cus.RecordDate = item.RecordDate
  1342. cus.Type = item.Type
  1343. cus.PType = item.PType
  1344. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1345. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1346. if subItem.FrequencyType == 1 { //每次必推
  1347. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1348. }
  1349. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1350. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1351. }
  1352. if subItem.FrequencyType == 2 { //按照天数频率
  1353. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1354. now := p.Unix()
  1355. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1356. dayStr2 := "-" + dayStr
  1357. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1358. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1359. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1360. if len(advices) == 0 {
  1361. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1362. }
  1363. }
  1364. }
  1365. }
  1366. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1367. if subItem.Type == 2 {
  1368. if subItem.XtHisProject.MedicalStatus != 1 {
  1369. if subItem.FrequencyType == 1 {
  1370. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1371. }
  1372. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1373. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1374. }
  1375. if subItem.FrequencyType == 2 {
  1376. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1377. now := p.Unix()
  1378. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1379. dayStr2 := "-" + dayStr
  1380. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1381. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1382. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1383. if len(projects) == 0 {
  1384. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1385. }
  1386. }
  1387. }
  1388. } else if subItem.Type == 3 {
  1389. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1390. if subItem.FrequencyType == 1 {
  1391. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1392. }
  1393. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1394. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1395. }
  1396. if subItem.FrequencyType == 2 {
  1397. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1398. now := p.Unix()
  1399. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1400. dayStr2 := "-" + dayStr
  1401. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1402. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1403. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1404. if len(projects) == 0 {
  1405. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1406. }
  1407. }
  1408. }
  1409. }
  1410. }
  1411. sch_prescriptions = append(sch_prescriptions, cus)
  1412. }
  1413. for _, item := range sch_prescriptions {
  1414. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1415. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1416. }
  1417. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1418. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1419. }
  1420. }
  1421. }
  1422. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1423. if config.ID > 0 && config.IsOpen == 1 {
  1424. for _, item := range sch_prescriptions {
  1425. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1426. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1427. if info.RetailPrice > 0 {
  1428. subItem.Drug.MinPrice = info.RetailPrice
  1429. if admin.CurrentOrgId != 10598 {
  1430. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1431. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1432. }
  1433. }
  1434. }
  1435. }
  1436. }
  1437. if config.ID > 0 && config.IsOpen == 1 {
  1438. for _, item := range sch_prescriptions {
  1439. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1440. if subItem.Type == 3 {
  1441. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1442. if info.Price > 0 {
  1443. subItem.GoodInfo.PackingPrice = info.Price
  1444. if admin.CurrentOrgId != 10598 {
  1445. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1446. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1447. }
  1448. }
  1449. }
  1450. }
  1451. }
  1452. }
  1453. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1454. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1455. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1456. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1457. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1458. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1459. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1460. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1461. //获取所有科室信息
  1462. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1463. beforThrity, _ := service.GetAssessmentBeforThrity(admin.CurrentOrgId, patient_id, recordDateTime)
  1464. LastCaseHistory, _ := service.GetLastHisPatientCaseHistory(admin.CurrentOrgId, patient_id)
  1465. prescriptionInfo, _ := service.GetDialysisPresriptionById(admin.CurrentOrgId, patient_id, recordDateTime)
  1466. c.ServeSuccessJSON(map[string]interface{}{
  1467. "his_info": his_patient_info,
  1468. "xt_info": xt_patient_info,
  1469. "prescription": prescriptions,
  1470. "case_history": case_history,
  1471. "info": patientPrescriptionInfo,
  1472. //"month_prescriptions": monthPrescriptions,
  1473. "order": order,
  1474. "doctors": doctors,
  1475. "department": department,
  1476. "sch_prescriptions": sch_prescriptions,
  1477. "last_prescriptions": last_prescriptions,
  1478. "schedule": sch,
  1479. "count": count,
  1480. "drugStockConfig": drugStockConfig,
  1481. "last_info": lastPatientPrescriptionInfo,
  1482. "befor": beforThrity,
  1483. "LastCaseHistory": LastCaseHistory,
  1484. "prescriptionInfo": prescriptionInfo,
  1485. })
  1486. return
  1487. }
  1488. func (c *HisApiController) GetHisPrescriptionConfig() {
  1489. adminInfo := c.GetAdminUserInfo()
  1490. //获取医嘱模版
  1491. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1492. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1493. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1494. //获取所有基础药
  1495. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1496. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1497. if config.ID > 0 && config.IsOpen == 1 {
  1498. for _, item := range drugs {
  1499. var index = 0
  1500. for _, subItem := range item.OtherDrugWarehouseInfo {
  1501. if index == 0 {
  1502. index = index + 1
  1503. if subItem.RetailPrice > 0 {
  1504. item.MinPrice = subItem.RetailPrice
  1505. }
  1506. }
  1507. }
  1508. }
  1509. }
  1510. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1511. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1512. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1513. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1514. //获取所有科室信息
  1515. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1516. //获取诊断信息
  1517. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1518. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1519. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1520. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1521. //获取是否开启保存耗材出库的开关
  1522. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1523. c.ServeSuccessJSON(map[string]interface{}{
  1524. "drugs": drugs,
  1525. "advices_template": advices,
  1526. "drugways": drugways,
  1527. "efs": efs,
  1528. "doctors": doctors,
  1529. "department": department,
  1530. "sick": sick,
  1531. "additions": additions,
  1532. "diagnose": diagnose,
  1533. "manufacturers": manufacturers,
  1534. "goodOutOpen": goodOutOpen,
  1535. "patientDiagnose": patientDiagnose,
  1536. })
  1537. }
  1538. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1539. //获取所有基础药
  1540. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1541. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1542. if config.ID > 0 && config.IsOpen == 1 {
  1543. for _, item := range drugs {
  1544. var index = 0
  1545. for _, subItem := range item.OtherDrugWarehouseInfo {
  1546. if index == 0 {
  1547. index = index + 1
  1548. if subItem.RetailPrice > 0 {
  1549. item.MinPrice = subItem.RetailPrice
  1550. }
  1551. }
  1552. }
  1553. }
  1554. }
  1555. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1556. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1557. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1558. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1559. //获取所有科室信息
  1560. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1561. //获取诊断信息
  1562. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1563. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1564. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1565. //获取是否开启保存耗材出库的开关
  1566. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1567. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1568. c.ServeSuccessJSON(map[string]interface{}{
  1569. "drugs": drugs,
  1570. "advices_template": advices,
  1571. "drugways": drugways,
  1572. "efs": efs,
  1573. "doctors": doctors,
  1574. "department": department,
  1575. "sick": sick,
  1576. "additions": additions,
  1577. "diagnose": diagnose,
  1578. "manufacturers": manufacturers,
  1579. "goodOutOpen": goodOutOpen,
  1580. "patientDiagnose": patientDiagnose,
  1581. })
  1582. }
  1583. }
  1584. func (c *HisApiController) CreateHisPrescription() {
  1585. record_date := c.GetString("record_date")
  1586. patient_id, _ := c.GetInt64("patient_id")
  1587. reg_type, _ := c.GetInt64("reg_type")
  1588. diagnose := c.GetString("diagnose")
  1589. sick_type, _ := c.GetInt64("sick_type")
  1590. sick_history := c.GetString("sick_history")
  1591. doctor_id, _ := c.GetInt64("doctor", 0)
  1592. department, _ := c.GetInt64("department", 0)
  1593. his_patient_id, _ := c.GetInt64("his_patient_id")
  1594. p_type, _ := c.GetInt64("p_type")
  1595. patient_diagnose := c.GetString("patient_diagnose")
  1596. dataBody := make(map[string]interface{}, 0)
  1597. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1598. if err != nil {
  1599. utils.ErrorLog(err.Error())
  1600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1601. return
  1602. }
  1603. //edit, src := GetCompareData(dataBody)
  1604. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1605. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1606. //fmt.Println(drugResult)
  1607. //fmt.Println(goodResult)
  1608. timeLayout := "2006-01-02"
  1609. loc, _ := time.LoadLocation("Local")
  1610. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1611. if err != nil {
  1612. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1613. return
  1614. }
  1615. adminInfo := c.GetAdminUserInfo()
  1616. recordDateTime := theTime.Unix()
  1617. //查询默认出库仓库库存
  1618. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1619. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1620. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1621. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1622. if len(lists) == 1 {
  1623. his_patient_id = lists[0].ID
  1624. }
  1625. }
  1626. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1627. //自动出库的开关开启
  1628. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1629. //自动出库
  1630. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1631. //耗材保存处方出库
  1632. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1633. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1634. //已发药和已收费限制逻辑
  1635. isMidicine := false
  1636. isCharge := false
  1637. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1638. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1639. if len(prescriptions) > 0 {
  1640. for _, item := range prescriptions {
  1641. items := item.(map[string]interface{})
  1642. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1643. utils.ErrorLog("id")
  1644. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1645. return
  1646. }
  1647. id := int64(items["id"].(float64))
  1648. if id > 0 {
  1649. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1650. if err != nil {
  1651. if new_prescription.OrderStatus == 4 {
  1652. isCharge = true
  1653. }
  1654. }
  1655. }
  1656. }
  1657. }
  1658. }
  1659. if isMidicine == true {
  1660. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1661. return
  1662. }
  1663. if isCharge == true {
  1664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1665. return
  1666. }
  1667. // 开始主事务
  1668. db := service.XTWriteDB()
  1669. tx := db.Begin()
  1670. // 在函数结束时处理事务回滚
  1671. defer func() {
  1672. if r := recover(); r != nil {
  1673. tx.Rollback()
  1674. }
  1675. }()
  1676. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1677. //药品发药出库
  1678. if pharmacyConfig.IsOpen == 1 {
  1679. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1680. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1681. if len(prescriptions) > 0 {
  1682. for _, item := range prescriptions {
  1683. items := item.(map[string]interface{})
  1684. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1685. advices := items["advices"].([]interface{})
  1686. if len(advices) > 0 {
  1687. for _, advice := range advices {
  1688. var drug_id int64
  1689. var prescribing_number float64
  1690. var prescribingNumberUnit string
  1691. var adviceId int64
  1692. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1693. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1694. }
  1695. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1696. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1697. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1698. }
  1699. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1700. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1701. }
  1702. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1703. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1704. }
  1705. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1706. if drug.ID == 0 {
  1707. tx.Rollback()
  1708. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1709. return
  1710. }
  1711. //查询药品的所有库存
  1712. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1713. var total_count int64
  1714. for _, it := range list {
  1715. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1716. }
  1717. totals := strconv.FormatInt(total_count, 10)
  1718. //查询该药品是否存在开药记录
  1719. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1720. //新增处方盘点库存是否充足
  1721. if advicelist.ID == 0 {
  1722. all_count, _ := strconv.ParseFloat(totals, 64)
  1723. if prescribingNumberUnit == drug.MinUnit {
  1724. if drug.IsUse != 1 {
  1725. if drug.IsProject == 0 || drug.IsProject == 2 {
  1726. if all_count == 0 {
  1727. tx.Rollback()
  1728. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1729. return
  1730. }
  1731. if prescribing_number > all_count {
  1732. tx.Rollback()
  1733. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1734. return
  1735. }
  1736. }
  1737. }
  1738. }
  1739. if prescribingNumberUnit == drug.MaxUnit {
  1740. num := prescribing_number * float64(drug.MinNumber)
  1741. if drug.IsUse != 1 {
  1742. if drug.IsProject == 0 || drug.IsProject == 2 {
  1743. if all_count == 0 {
  1744. tx.Rollback()
  1745. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1746. return
  1747. }
  1748. if num > all_count {
  1749. tx.Rollback()
  1750. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1751. return
  1752. }
  1753. }
  1754. }
  1755. }
  1756. }
  1757. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1758. //不使用保存处方出库
  1759. if drugOutConfig.IsOpen != 1 {
  1760. //修改处方
  1761. for _, advice := range advices {
  1762. var drug_id int64
  1763. var prescribing_number float64
  1764. var prescribingNumberUnit string
  1765. var prescribingNumber string
  1766. var adviceId int64
  1767. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1768. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1769. }
  1770. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1771. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1772. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1773. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1774. }
  1775. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1776. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1777. }
  1778. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1779. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1780. }
  1781. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1782. if drug.ID == 0 {
  1783. tx.Rollback()
  1784. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1785. return
  1786. }
  1787. //查询药品的所有库存
  1788. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1789. var total_count int64
  1790. for _, it := range list {
  1791. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1792. }
  1793. totals := strconv.FormatInt(total_count, 10)
  1794. //查询该药品是否存在开药记录
  1795. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1796. //新增处方
  1797. if advicelist.ID == 0 {
  1798. all_count, _ := strconv.ParseFloat(totals, 64)
  1799. if prescribingNumberUnit == drug.MinUnit {
  1800. if drug.IsUse != 1 {
  1801. if drug.IsProject == 0 || drug.IsProject == 2 {
  1802. if all_count == 0 {
  1803. tx.Rollback()
  1804. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1805. return
  1806. }
  1807. if prescribing_number > all_count {
  1808. tx.Rollback()
  1809. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1810. return
  1811. }
  1812. }
  1813. }
  1814. } else {
  1815. if prescribingNumberUnit == drug.MaxUnit {
  1816. num := prescribing_number * float64(drug.MinNumber)
  1817. if drug.IsUse != 1 {
  1818. if drug.IsProject == 0 || drug.IsProject == 2 {
  1819. if all_count == 0 {
  1820. tx.Rollback()
  1821. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1822. return
  1823. }
  1824. if num > all_count {
  1825. tx.Rollback()
  1826. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1827. return
  1828. }
  1829. }
  1830. }
  1831. }
  1832. }
  1833. }
  1834. //修改处方
  1835. if advicelist.ID > 0 {
  1836. var device_number int64
  1837. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1838. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1839. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1840. device_number = prescribingNumberInt * drug.MinNumber
  1841. }
  1842. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1843. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1844. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1845. device_number = prescribingNumberInt
  1846. }
  1847. var number_count int64
  1848. if prescribingNumberUnit == drug.MaxUnit {
  1849. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1850. number_count = prescribingNumberInt * drug.MinNumber
  1851. }
  1852. if prescribingNumberUnit == drug.MinUnit {
  1853. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1854. number_count = prescribingNumberInt
  1855. }
  1856. //如果修改的数量大于之前修改的数量
  1857. if (number_count - device_number) > 0 {
  1858. //如果修改的差数量 大于库存数量
  1859. if drug.IsUse != 1 {
  1860. if (number_count - device_number) > total_count {
  1861. tx.Rollback()
  1862. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1863. return
  1864. }
  1865. }
  1866. }
  1867. }
  1868. }
  1869. }
  1870. }
  1871. }
  1872. }
  1873. }
  1874. }
  1875. }
  1876. }
  1877. //已发药和已收费限制逻辑
  1878. //执行出库的逻辑
  1879. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1880. //校验库存总量
  1881. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1882. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1883. if len(prescriptions) > 0 {
  1884. for _, item := range prescriptions {
  1885. items := item.(map[string]interface{})
  1886. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1887. advices := items["advices"].([]interface{})
  1888. if len(advices) > 0 {
  1889. for _, advice := range advices {
  1890. var drug_id int64
  1891. var prescribing_number float64
  1892. var prescribingNumberUnit string
  1893. var adviceId int64
  1894. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1895. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1896. }
  1897. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1898. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1899. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1900. }
  1901. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1902. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1903. }
  1904. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1905. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1906. }
  1907. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1908. if drug.ID == 0 {
  1909. tx.Rollback()
  1910. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1911. return
  1912. }
  1913. //查询药品的所有库存
  1914. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1915. var total_count int64
  1916. for _, it := range list {
  1917. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1918. }
  1919. totals := strconv.FormatInt(total_count, 10)
  1920. //查询该药品是否存在开药记录
  1921. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1922. //查询最新批次库存
  1923. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1924. var batch_number_count int64
  1925. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1926. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1927. //新增处方
  1928. if advicelist.ID == 0 {
  1929. all_count, _ := strconv.ParseFloat(totals, 64)
  1930. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1931. if prescribingNumberUnit == drug.MinUnit {
  1932. if drug.IsUse != 1 {
  1933. if drug.IsProject == 0 || drug.IsProject == 2 {
  1934. if all_count == 0 {
  1935. tx.Rollback()
  1936. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1937. return
  1938. }
  1939. if prescribing_number > all_count {
  1940. tx.Rollback()
  1941. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1942. return
  1943. }
  1944. }
  1945. if adminInfo.CurrentOrgId == 10215 {
  1946. if prescribing_number > batch_number_all_count {
  1947. tx.Rollback()
  1948. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1949. return
  1950. }
  1951. }
  1952. }
  1953. }
  1954. if prescribingNumberUnit == drug.MaxUnit {
  1955. num := prescribing_number * float64(drug.MinNumber)
  1956. if drug.IsUse != 1 {
  1957. if drug.IsProject == 0 || drug.IsProject == 2 {
  1958. if all_count == 0 {
  1959. tx.Rollback()
  1960. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1961. return
  1962. }
  1963. if num > all_count {
  1964. tx.Rollback()
  1965. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1966. return
  1967. }
  1968. }
  1969. if adminInfo.CurrentOrgId == 10215 {
  1970. if num > batch_number_all_count {
  1971. tx.Rollback()
  1972. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1973. return
  1974. }
  1975. }
  1976. }
  1977. }
  1978. }
  1979. //不是保存处方出库
  1980. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1981. if drugOutConfig.IsOpen != 1 {
  1982. //修改处方
  1983. for _, advice := range advices {
  1984. var drug_id int64
  1985. var prescribing_number float64
  1986. var prescribingNumberUnit string
  1987. var prescribingNumber string
  1988. var adviceId int64
  1989. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1990. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1991. }
  1992. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1993. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1994. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1995. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1996. }
  1997. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1998. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1999. }
  2000. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2001. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2002. }
  2003. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2004. if drug.ID == 0 {
  2005. tx.Rollback()
  2006. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2007. return
  2008. }
  2009. //查询药品的所有库存
  2010. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2011. var total_count int64
  2012. for _, it := range list {
  2013. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2014. }
  2015. totals := strconv.FormatInt(total_count, 10)
  2016. //查询该药品是否存在开药记录
  2017. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2018. //新增处方
  2019. if advicelist.ID == 0 {
  2020. //查询最新批次库存
  2021. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2022. var batch_number_count int64
  2023. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2024. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2025. all_count, _ := strconv.ParseFloat(totals, 64)
  2026. if all_count == 0 {
  2027. tx.Rollback()
  2028. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2029. return
  2030. }
  2031. if prescribingNumberUnit == drug.MinUnit {
  2032. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2033. if drug.IsUse != 1 {
  2034. if drug.IsProject == 0 || drug.IsProject == 2 {
  2035. if all_count == 0 {
  2036. tx.Rollback()
  2037. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2038. return
  2039. }
  2040. if prescribing_number > all_count {
  2041. tx.Rollback()
  2042. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2043. return
  2044. }
  2045. }
  2046. if adminInfo.CurrentOrgId == 10215 {
  2047. if prescribing_number > batch_number_all_count {
  2048. tx.Rollback()
  2049. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2050. return
  2051. }
  2052. }
  2053. }
  2054. } else {
  2055. if prescribingNumberUnit == drug.MaxUnit {
  2056. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2057. num := prescribing_number * float64(drug.MinNumber)
  2058. if drug.IsUse != 1 {
  2059. if drug.IsProject == 0 || drug.IsProject == 2 {
  2060. if all_count == 0 {
  2061. tx.Rollback()
  2062. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2063. return
  2064. }
  2065. if num > all_count {
  2066. tx.Rollback()
  2067. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2068. return
  2069. }
  2070. }
  2071. if adminInfo.CurrentOrgId == 10215 {
  2072. if prescribing_number > batch_number_all_count {
  2073. tx.Rollback()
  2074. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2075. return
  2076. }
  2077. }
  2078. }
  2079. }
  2080. }
  2081. }
  2082. //修改处方
  2083. if advicelist.ID > 0 {
  2084. //查询最新批次库存
  2085. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2086. var batch_number_count int64
  2087. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2088. var device_number int64
  2089. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2090. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2091. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2092. device_number = prescribingNumberInt * drug.MinNumber
  2093. }
  2094. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2095. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2096. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2097. device_number = prescribingNumberInt
  2098. //回退库存
  2099. }
  2100. var number_count int64
  2101. if prescribingNumberUnit == drug.MaxUnit {
  2102. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2103. number_count = prescribingNumberInt * drug.MinNumber
  2104. //回退库存
  2105. }
  2106. if prescribingNumberUnit == drug.MinUnit {
  2107. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2108. number_count = prescribingNumberInt
  2109. //回退库存
  2110. }
  2111. //如果修改的数量大于之前修改的数量
  2112. if (number_count - device_number) > 0 {
  2113. //如果修改的差数量 大于库存数量
  2114. if drug.IsUse != 1 {
  2115. if drug.IsProject == 0 || drug.IsProject == 2 {
  2116. if total_count == 0 {
  2117. tx.Rollback()
  2118. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2119. return
  2120. }
  2121. if (number_count - device_number) > total_count {
  2122. tx.Rollback()
  2123. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2124. return
  2125. }
  2126. if (number_count - device_number) > batch_number_count {
  2127. tx.Rollback()
  2128. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2129. return
  2130. }
  2131. }
  2132. if adminInfo.CurrentOrgId == 10215 {
  2133. // 查询该药品最后一次出库记录
  2134. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2135. var out_count int64
  2136. var in_count int64
  2137. var stock_max_number int64
  2138. var stock_min_number int64
  2139. for _, it := range outInfo {
  2140. if it.CountUnit == drug.MaxUnit {
  2141. it.Count = it.Count * drug.MinNumber
  2142. }
  2143. out_count += it.Count
  2144. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2145. stock_max_number = warehouseInfoList.StockMaxNumber
  2146. stock_min_number = warehouseInfoList.StockMinNumber
  2147. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2148. }
  2149. if out_count > 0 {
  2150. if (number_count - device_number) > in_count {
  2151. tx.Rollback()
  2152. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2153. return
  2154. }
  2155. }
  2156. // 未出库
  2157. if out_count == 0 {
  2158. var sum_in_count int64
  2159. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2160. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2161. //如果修改的数量大于有库存的第一个批次
  2162. if number_count > sum_in_count {
  2163. tx.Rollback()
  2164. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2165. return
  2166. }
  2167. }
  2168. }
  2169. }
  2170. }
  2171. //药品发药
  2172. //pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2173. //不使用药品发药的功能
  2174. //if pharmacyConfig.IsOpen != 1 {
  2175. // if device_number != number_count {
  2176. //
  2177. // //查询该药品的出库记录
  2178. // outListExport, _ := service.GetWarehouseOutListExport(drug_id, patient_id, recordDateTime, adviceId)
  2179. // if len(outListExport) > 0 {
  2180. // //
  2181. // for _, item := range outListExport {
  2182. // //回退库存
  2183. // if item.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2184. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, number_count)
  2185. // }
  2186. // if item.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2187. // var stock_max_number int64
  2188. // var stock_min_number int64
  2189. //
  2190. // if number_count >= drug.MinNumber {
  2191. //
  2192. // stock_max_number = device_number / drug.MinNumber
  2193. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, stock_max_number)
  2194. //
  2195. // stock_min_number = device_number % drug.MinNumber
  2196. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, stock_min_number)
  2197. //
  2198. // } else {
  2199. //
  2200. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, device_number)
  2201. //
  2202. // }
  2203. // }
  2204. //
  2205. // if item.CountUnit == drug.MaxUnit && item.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2206. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, device_number)
  2207. // }
  2208. // }
  2209. // }
  2210. //
  2211. // service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2212. // var sum_count int64
  2213. // orgId := c.GetAdminUserInfo().CurrentOrgId
  2214. // stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgId, drug_id)
  2215. // for _, its := range stockInfo {
  2216. // if its.MaxUnit == drug.MaxUnit {
  2217. // its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2218. // }
  2219. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2220. // }
  2221. // //更新字典里面的库存
  2222. // service.UpdateBaseDrugSumTwo(drug_id, sum_count, orgId)
  2223. //
  2224. // //剩余库存
  2225. // service.UpdateDrugStockCount(drug_id, orgId, storeConfig.DrugStorehouseOut, sum_count)
  2226. //
  2227. // over, _ := service.FindOverCount(drug_id, orgId, storeConfig.DrugStorehouseOut)
  2228. // //减少出库数量
  2229. // service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2230. //
  2231. // }
  2232. //}
  2233. }
  2234. }
  2235. }
  2236. //保存处方开药
  2237. if drugOutConfig.IsOpen == 1 {
  2238. //修改处方
  2239. for _, advice := range advices {
  2240. var drug_id int64
  2241. var prescribing_number float64
  2242. var prescribingNumberUnit string
  2243. var prescribingNumber string
  2244. var adviceId int64
  2245. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2246. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2247. }
  2248. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2249. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2250. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2251. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2252. }
  2253. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2254. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2255. }
  2256. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2257. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2258. }
  2259. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2260. if drug.ID == 0 {
  2261. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2262. return
  2263. }
  2264. //查询药品的所有库存
  2265. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2266. var total_count int64
  2267. for _, it := range list {
  2268. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2269. }
  2270. totals := strconv.FormatInt(total_count, 10)
  2271. //查询该药品是否存在开药记录
  2272. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2273. //新增处方
  2274. if advicelist.ID == 0 {
  2275. //查询最新批次库存
  2276. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2277. var batch_number_count int64
  2278. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2279. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2280. all_count, _ := strconv.ParseFloat(totals, 64)
  2281. if prescribingNumberUnit == drug.MinUnit {
  2282. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2283. if drug.IsUse != 1 {
  2284. if drug.IsProject == 0 || drug.IsProject == 2 {
  2285. if all_count == 0 {
  2286. tx.Rollback()
  2287. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2288. return
  2289. }
  2290. if prescribing_number > all_count {
  2291. tx.Rollback()
  2292. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2293. return
  2294. }
  2295. }
  2296. if adminInfo.CurrentOrgId == 10215 {
  2297. if prescribing_number > batch_number_all_count {
  2298. tx.Rollback()
  2299. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2300. return
  2301. }
  2302. }
  2303. }
  2304. } else {
  2305. if prescribingNumberUnit == drug.MaxUnit {
  2306. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2307. num := prescribing_number * float64(drug.MinNumber)
  2308. if drug.IsUse != 1 {
  2309. if drug.IsProject == 0 || drug.IsProject == 2 {
  2310. if all_count == 0 {
  2311. tx.Rollback()
  2312. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2313. return
  2314. }
  2315. if num > all_count {
  2316. tx.Rollback()
  2317. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2318. return
  2319. }
  2320. }
  2321. if adminInfo.CurrentOrgId == 10215 {
  2322. if prescribing_number > batch_number_all_count {
  2323. tx.Rollback()
  2324. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2325. return
  2326. }
  2327. }
  2328. }
  2329. }
  2330. }
  2331. }
  2332. //修改处方
  2333. if advicelist.ID > 0 {
  2334. //查询最新批次库存
  2335. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2336. var batch_number_count int64
  2337. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2338. var device_number int64
  2339. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2340. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2341. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2342. device_number = prescribingNumberInt * drug.MinNumber
  2343. }
  2344. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2345. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2346. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2347. device_number = prescribingNumberInt
  2348. }
  2349. var number_count int64
  2350. if prescribingNumberUnit == drug.MaxUnit {
  2351. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2352. number_count = prescribingNumberInt * drug.MinNumber
  2353. }
  2354. if prescribingNumberUnit == drug.MinUnit {
  2355. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2356. number_count = prescribingNumberInt
  2357. }
  2358. //如果修改的数量大于之前修改的数量
  2359. if (number_count - device_number) > 0 {
  2360. //如果修改的差数量 大于库存数量
  2361. if drug.IsUse != 1 {
  2362. if drug.IsProject == 0 || drug.IsProject == 2 {
  2363. if total_count == 0 {
  2364. tx.Rollback()
  2365. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2366. return
  2367. }
  2368. if (number_count - device_number) > total_count {
  2369. tx.Rollback()
  2370. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2371. return
  2372. }
  2373. }
  2374. if adminInfo.CurrentOrgId == 10215 {
  2375. if (number_count - device_number) > batch_number_count {
  2376. tx.Rollback()
  2377. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2378. return
  2379. }
  2380. }
  2381. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2382. //查询历史出库数据总批次
  2383. // 查询该药品最后一次出库记录
  2384. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2385. var out_count int64
  2386. var in_count int64
  2387. var stock_max_number int64
  2388. var stock_min_number int64
  2389. for _, it := range outInfo {
  2390. if it.CountUnit == drug.MaxUnit {
  2391. it.Count = it.Count * drug.MinNumber
  2392. }
  2393. out_count += it.Count
  2394. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2395. stock_max_number = warehouseInfoList.StockMaxNumber
  2396. stock_min_number = warehouseInfoList.StockMinNumber
  2397. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2398. }
  2399. if out_count > 0 {
  2400. if (number_count - device_number) > in_count {
  2401. tx.Rollback()
  2402. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2403. return
  2404. }
  2405. }
  2406. // 未出库
  2407. if out_count == 0 {
  2408. var sum_in_count int64
  2409. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2410. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2411. if sum_in_count == 0 {
  2412. tx.Rollback()
  2413. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2414. return
  2415. }
  2416. //如果修改的数量大于有库存的第一个批次
  2417. if number_count > sum_in_count {
  2418. tx.Rollback()
  2419. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2420. return
  2421. }
  2422. }
  2423. }
  2424. }
  2425. }
  2426. }
  2427. }
  2428. }
  2429. }
  2430. }
  2431. }
  2432. }
  2433. }
  2434. }
  2435. }
  2436. //校验耗材库存
  2437. if goodOutConfig.IsOpen == 1 {
  2438. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2439. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2440. if len(prescriptions) > 0 {
  2441. for _, item := range prescriptions {
  2442. items := item.(map[string]interface{})
  2443. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2444. projects := items["project"].([]interface{})
  2445. if len(projects) > 0 {
  2446. for _, project := range projects {
  2447. var project_id int64
  2448. var project_type int64
  2449. var totals float64
  2450. var project_name string
  2451. var parsetotal int64
  2452. var id int64
  2453. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2454. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2455. }
  2456. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2457. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2458. }
  2459. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2460. total, _ := project.(map[string]interface{})["total"].(string)
  2461. totals, _ = strconv.ParseFloat(total, 64)
  2462. }
  2463. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2464. project_name = project.(map[string]interface{})["project_name"].(string)
  2465. }
  2466. if project_type == 3 {
  2467. //查找该耗材的出库记录
  2468. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2469. if len(goodWarehouseInfo) == 0 {
  2470. //查询耗材库存
  2471. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2472. var stock_count int64
  2473. for _, it := range list {
  2474. stock_count += it.StockCount
  2475. }
  2476. stock_counts := strconv.FormatInt(stock_count, 10)
  2477. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2478. if stock_total_count == 0 {
  2479. tx.Rollback()
  2480. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2481. return
  2482. }
  2483. if totals > stock_total_count {
  2484. tx.Rollback()
  2485. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2486. return
  2487. }
  2488. }
  2489. if len(goodWarehouseInfo) > 0 {
  2490. //查询该患者耗材的历史数据
  2491. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2492. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2493. //数量发生改变
  2494. if parsetotal != count {
  2495. //如果现在的数量大于历史数量,就要看库存是否足够
  2496. if parsetotal > count {
  2497. //查询耗材所有库存
  2498. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2499. var stock_count int64
  2500. for _, it := range list {
  2501. stock_count += it.StockCount
  2502. }
  2503. //库存不足
  2504. if stock_count == 0 {
  2505. tx.Rollback()
  2506. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2507. return
  2508. }
  2509. if (parsetotal - count) > stock_count {
  2510. tx.Rollback()
  2511. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2512. return
  2513. }
  2514. }
  2515. }
  2516. }
  2517. }
  2518. }
  2519. }
  2520. }
  2521. }
  2522. }
  2523. }
  2524. }
  2525. //不使用耗材保存处方出库
  2526. if goodOutConfig.IsOpen != 1 {
  2527. if stockConfig.IsOpen == 1 {
  2528. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2529. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2530. if len(prescriptions) > 0 {
  2531. for _, item := range prescriptions {
  2532. items := item.(map[string]interface{})
  2533. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2534. projects := items["project"].([]interface{})
  2535. if len(projects) > 0 {
  2536. for _, project := range projects {
  2537. var project_id int64
  2538. var project_type int64
  2539. var totals float64
  2540. var project_name string
  2541. var parsetotal int64
  2542. var id int64
  2543. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2544. id = int64(project.(map[string]interface{})["id"].(float64))
  2545. }
  2546. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2547. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2548. }
  2549. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2550. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2551. }
  2552. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2553. total, _ := project.(map[string]interface{})["total"].(string)
  2554. totals, _ = strconv.ParseFloat(total, 64)
  2555. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2556. }
  2557. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2558. project_name = project.(map[string]interface{})["project_name"].(string)
  2559. }
  2560. if project_type == 3 {
  2561. //查找该耗材的出库记录
  2562. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2563. //没有出库记录
  2564. if len(goodWarehouseInfo) == 0 {
  2565. //查询耗材库存
  2566. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2567. var stock_count int64
  2568. for _, it := range list {
  2569. stock_count += it.StockCount
  2570. }
  2571. stock_counts := strconv.FormatInt(stock_count, 10)
  2572. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2573. if stock_total_count == 0 {
  2574. tx.Rollback()
  2575. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2576. return
  2577. }
  2578. if totals > stock_total_count {
  2579. tx.Rollback()
  2580. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2581. return
  2582. }
  2583. //查找今日该患者已经出库的所有耗材
  2584. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2585. for _, item := range goodList {
  2586. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2587. var flush_count int64
  2588. for _, it := range goodListSix {
  2589. flush_count += it.StockCount
  2590. }
  2591. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2592. creater := adminInfo.AdminUser.Id
  2593. if errs != nil {
  2594. goodErrcode := models.XtGoodErrcode{
  2595. UserOrgId: item.OrgId,
  2596. Errcode: "手动出库更新剩余出库失败",
  2597. GoodId: item.GoodId,
  2598. Status: 1,
  2599. Ctime: time.Now().Unix(),
  2600. Mtime: 0,
  2601. Count: 0,
  2602. StockCount: 0,
  2603. Creater: creater,
  2604. BatchNumberId: 0,
  2605. WarehouseOutId: 0,
  2606. }
  2607. service.CreateGoodErrcode(goodErrcode)
  2608. }
  2609. }
  2610. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2611. }
  2612. //有出库记录
  2613. if len(goodWarehouseInfo) > 0 {
  2614. //查询该患者耗材的历史数据
  2615. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2616. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2617. //数量发生改变
  2618. if parsetotal != count {
  2619. //查找今日该患者已经出库的所有耗材
  2620. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2621. for _, item := range goodList {
  2622. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2623. var flush_count int64
  2624. for _, it := range goodListSix {
  2625. flush_count += it.StockCount
  2626. }
  2627. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2628. //减少出库数量
  2629. creater := adminInfo.AdminUser.Id
  2630. if errs != nil {
  2631. goodErrcode := models.XtGoodErrcode{
  2632. UserOrgId: item.OrgId,
  2633. Errcode: "手动出库更新剩余出库失败",
  2634. GoodId: item.GoodId,
  2635. Status: 1,
  2636. Ctime: time.Now().Unix(),
  2637. Mtime: 0,
  2638. Count: 0,
  2639. StockCount: 0,
  2640. Creater: creater,
  2641. BatchNumberId: 0,
  2642. WarehouseOutId: 0,
  2643. }
  2644. service.CreateGoodErrcode(goodErrcode)
  2645. }
  2646. //查询默认仓库
  2647. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2648. var total_count int64
  2649. for _, it := range stockList {
  2650. total_count += it.StockCount
  2651. }
  2652. //基础库插入数据
  2653. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2654. }
  2655. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2656. }
  2657. }
  2658. }
  2659. }
  2660. }
  2661. }
  2662. }
  2663. }
  2664. }
  2665. }
  2666. }
  2667. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2668. var hpInfo models.HisPrescriptionInfo
  2669. if info.ID == 0 {
  2670. var randNum int
  2671. randNum = rand.Intn(10000) + 1000
  2672. timestamp := time.Now().Unix()
  2673. tempTime := time.Unix(timestamp, 0)
  2674. timeFormat := tempTime.Format("20060102150405")
  2675. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2676. hpInfo = models.HisPrescriptionInfo{
  2677. HisPatientId: his_patient_id,
  2678. UserOrgId: adminInfo.CurrentOrgId,
  2679. RecordDate: theTime.Unix(),
  2680. PatientId: patient_id,
  2681. Status: 1,
  2682. Ctime: time.Now().Unix(),
  2683. Mtime: time.Now().Unix(),
  2684. Creator: adminInfo.AdminUser.Id,
  2685. Modifier: adminInfo.AdminUser.Id,
  2686. Diagnosis: diagnose,
  2687. SickHistory: sick_history,
  2688. Departments: department,
  2689. RegisterType: reg_type,
  2690. PrescriptionNumber: p_number,
  2691. PrescriptionStatus: 1,
  2692. Doctor: role.UserName,
  2693. DoctorId: doctor_id,
  2694. SickType: sick_type,
  2695. PType: p_type,
  2696. PatientDiagnosis: patient_diagnose,
  2697. }
  2698. service.SavePatientPrescriptionInfo(hpInfo)
  2699. //创建步骤表
  2700. finish := models.XtDialysisFinish{
  2701. IsFinish: 1,
  2702. UserOrgId: adminInfo.CurrentOrgId,
  2703. Status: 1,
  2704. Ctime: time.Now().Unix(),
  2705. Mtime: 0,
  2706. Module: 4,
  2707. RecordDate: theTime.Unix(),
  2708. Sourse: 1,
  2709. PatientId: patient_id,
  2710. }
  2711. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2712. if dialysisFinish.ID == 0 {
  2713. service.CreateDialysisFinish(finish)
  2714. }
  2715. redis := service.RedisClient()
  2716. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2717. redis.Set(key, "", time.Second)
  2718. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2719. redis.Set(keyOne, "", time.Second)
  2720. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2721. redis.Set(keySeven, "", time.Second)
  2722. defer redis.Close()
  2723. } else {
  2724. hpInfo = models.HisPrescriptionInfo{
  2725. ID: info.ID,
  2726. UserOrgId: adminInfo.CurrentOrgId,
  2727. RecordDate: info.RecordDate,
  2728. PatientId: info.PatientId,
  2729. Status: 1,
  2730. Ctime: info.Ctime,
  2731. Mtime: time.Now().Unix(),
  2732. Creator: info.Creator,
  2733. Modifier: adminInfo.AdminUser.Id,
  2734. Diagnosis: diagnose,
  2735. SickHistory: sick_history,
  2736. Departments: department,
  2737. RegisterType: reg_type,
  2738. PrescriptionNumber: info.PrescriptionNumber,
  2739. Doctor: role.UserName,
  2740. PrescriptionStatus: info.PrescriptionStatus,
  2741. DoctorId: doctor_id,
  2742. SickType: sick_type,
  2743. PType: info.PType,
  2744. HisPatientId: info.HisPatientId,
  2745. PatientDiagnosis: patient_diagnose,
  2746. }
  2747. service.SavePatientPrescriptionInfo(hpInfo)
  2748. //创建步骤表
  2749. finish := models.XtDialysisFinish{
  2750. IsFinish: 1,
  2751. UserOrgId: adminInfo.CurrentOrgId,
  2752. Status: 1,
  2753. Ctime: time.Now().Unix(),
  2754. Mtime: 0,
  2755. Module: 4,
  2756. RecordDate: info.RecordDate,
  2757. Sourse: 1,
  2758. PatientId: info.PatientId,
  2759. }
  2760. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2761. if dialysisFinish.ID == 0 {
  2762. service.CreateDialysisFinish(finish)
  2763. }
  2764. redis := service.RedisClient()
  2765. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2766. redis.Set(key, "", time.Second)
  2767. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2768. redis.Set(keyOne, "", time.Second)
  2769. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2770. redis.Set(keySeven, "", time.Second)
  2771. defer redis.Close()
  2772. }
  2773. //定义切片
  2774. var adviceList []models.HisDoctorAdviceInfo
  2775. var projectList []models.HisPrescriptionProject
  2776. 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 {
  2777. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2778. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2779. var tempPrescription *models.HisPrescription
  2780. if len(prescriptions) > 0 {
  2781. for _, item := range prescriptions {
  2782. // 开始外部循环的事务
  2783. tx := db.Begin()
  2784. // 在函数结束时处理事务回滚
  2785. defer func() {
  2786. if r := recover(); r != nil {
  2787. tx.Rollback()
  2788. }
  2789. }()
  2790. items := item.(map[string]interface{})
  2791. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2792. utils.ErrorLog("id")
  2793. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2794. return
  2795. }
  2796. id := int64(items["id"].(float64))
  2797. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2798. tempPrescription = &new_prescription
  2799. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2800. utils.ErrorLog("type")
  2801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2802. return
  2803. }
  2804. types := int64(items["type"].(float64))
  2805. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2806. utils.ErrorLog("med_type")
  2807. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2808. return
  2809. }
  2810. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2811. if med_type == "0" {
  2812. med_type = "14"
  2813. }
  2814. //if order_status == 0 {
  2815. // order_status = 1
  2816. //}
  2817. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2818. utils.ErrorLog("pre_time")
  2819. }
  2820. preTime, _ := items["pre_time"].(string)
  2821. fmt.Println("preTime", preTime)
  2822. timeLayout := "2006-01-02"
  2823. loc, _ := time.LoadLocation("Local")
  2824. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2825. //result := strings.Split(preTime, " ")
  2826. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  2827. if err != nil {
  2828. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2829. return
  2830. }
  2831. pTime := theTime2.Unix()
  2832. ctime := time.Now().Unix()
  2833. if tempPrescription.ID == 0 {
  2834. prescription := &models.HisPrescription{
  2835. ID: 0,
  2836. PatientId: patient_id,
  2837. UserOrgId: adminInfo.CurrentOrgId,
  2838. RecordDate: recordDateTime,
  2839. Ctime: ctime,
  2840. Mtime: ctime,
  2841. Type: types,
  2842. Modifier: adminInfo.AdminUser.Id,
  2843. Creator: adminInfo.AdminUser.Id,
  2844. Status: 1,
  2845. Doctor: role.UserName,
  2846. HisPatientId: his_patient_id,
  2847. OrderStatus: 1,
  2848. BatchNumber: "",
  2849. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2850. PreTime: pTime,
  2851. PType: p_type,
  2852. MedType: med_type,
  2853. }
  2854. tempPrescription = prescription
  2855. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2856. redis := service.RedisClient()
  2857. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2858. redis.Set(key, "", time.Second)
  2859. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2860. redis.Set(keyOne, "", time.Second)
  2861. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2862. redis.Set(keySeven, "", time.Second)
  2863. defer redis.Close()
  2864. } else {
  2865. tempPrescription.ID = id
  2866. tempPrescription.Type = types
  2867. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2868. tempPrescription.Mtime = time.Now().Unix()
  2869. tempPrescription.Doctor = role.UserName
  2870. //tempPrescription.OrderStatus = order_status
  2871. tempPrescription.PreTime = pTime
  2872. tempPrescription.MedType = med_type
  2873. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2874. redis := service.RedisClient()
  2875. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2876. redis.Set(key, "", time.Second)
  2877. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2878. redis.Set(keyOne, "", time.Second)
  2879. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2880. redis.Set(keySeven, "", time.Second)
  2881. defer redis.Close()
  2882. }
  2883. //service.SaveHisPrescription(prescription)
  2884. //更改患者挂号状态
  2885. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2886. fmt.Println("更改失败", err2)
  2887. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2888. advices := items["advices"].([]interface{})
  2889. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2890. groupNo := int64(0)
  2891. if len(advices) > 0 {
  2892. for _, advice := range advices {
  2893. tx := db.Begin()
  2894. // 在函数结束时处理事务回滚
  2895. defer func() {
  2896. if r := recover(); r != nil {
  2897. tx.Rollback()
  2898. }
  2899. }()
  2900. var s models.HisDoctorAdviceInfo
  2901. s.PrescriptionId = tempPrescription.ID
  2902. s.AdviceType = 2
  2903. s.AdviceDoctor = doctor_id
  2904. s.StopState = 2
  2905. s.ExecutionState = 2
  2906. s.AdviceDate = theTime3.Unix()
  2907. s.Status = 1
  2908. s.UserOrgId = adminInfo.CurrentOrgId
  2909. s.RecordDate = theTime3.Unix()
  2910. s.StartTime = tempPrescription.PreTime
  2911. s.Groupno = groupNo
  2912. s.PatientId = patient_id
  2913. s.HisPatientId = his_patient_id
  2914. s.StartTime = pTime
  2915. s.IsSettle = 2
  2916. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2917. if errcode > 0 {
  2918. c.ServeFailJSONWithSGJErrorCode(errcode)
  2919. return
  2920. }
  2921. s.StartTime = pTime
  2922. var total_count int64 //处方总库存
  2923. //查询改药品信息
  2924. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2925. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2926. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2927. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2928. total_count += prescribingNumberSeven * medical.MinNumber
  2929. }
  2930. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2931. total_count += prescribingNumberSeven
  2932. }
  2933. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2934. total_count += prescribingNumberSeven
  2935. }
  2936. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2937. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2938. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2939. if s.Price != lastWarehouse.RetailPrice {
  2940. s.Price = lastWarehouse.RetailPrice
  2941. }
  2942. if s.Price == 0 {
  2943. if lastWarehouse.ID == 0 {
  2944. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  2945. s.Price = lastWarehouseTwo.RetailPrice
  2946. }
  2947. }
  2948. }
  2949. //查询保存处方出库开关是否打开
  2950. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2951. if s.PatientId != 30038 {
  2952. if drugOutConfig.IsOpen == 1 {
  2953. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  2954. // 查询该药品最后一次出库记录
  2955. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  2956. var is_user_total int64
  2957. var no_user_total int64
  2958. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2959. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2960. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2961. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  2962. }
  2963. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2964. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2965. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2966. no_user_total += prescribingNumberSevenTy
  2967. }
  2968. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2969. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2970. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2971. no_user_total += prescribingNumberSevenTy
  2972. }
  2973. if len(druginfo) > 0 {
  2974. for _, it := range druginfo {
  2975. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2976. it.Count = it.Count * drug.MinNumber
  2977. is_user_total += it.Count
  2978. }
  2979. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2980. is_user_total += it.Count
  2981. }
  2982. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2983. is_user_total += it.Count
  2984. }
  2985. }
  2986. }
  2987. //fmt.Println("药品名称----------------------", drug.DrugName)
  2988. //fmt.Println("药品名称----------------------", drug.IsUse)
  2989. //fmt.Println("is_user_total-------------------------", is_user_total)
  2990. //fmt.Println("no_user_total-------------------------", no_user_total)
  2991. if is_user_total != no_user_total {
  2992. //出库
  2993. if drug.IsUse == 2 {
  2994. creater := adminInfo.AdminUser.Id
  2995. newadviceInfo := &models.HisDoctorAdviceInfo{
  2996. ID: s.ID,
  2997. UserOrgId: s.UserOrgId,
  2998. PatientId: s.PatientId,
  2999. HisPatientId: s.HisPatientId,
  3000. AdviceType: s.AdviceType,
  3001. AdviceDate: s.AdviceDate,
  3002. StartTime: s.StartTime,
  3003. AdviceName: s.AdviceName,
  3004. AdviceDesc: s.AdviceDesc,
  3005. ReminderDate: s.ReminderDate,
  3006. SingleDose: s.SingleDose,
  3007. SingleDoseUnit: s.SingleDoseUnit,
  3008. PrescribingNumber: s.PrescribingNumber,
  3009. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3010. DeliveryWay: s.DeliveryWay,
  3011. ExecutionFrequency: s.ExecutionFrequency,
  3012. AdviceDoctor: s.AdviceDoctor,
  3013. Status: s.Status,
  3014. CreatedTime: s.CreatedTime,
  3015. UpdatedTime: s.UpdatedTime,
  3016. AdviceAffirm: s.AdviceAffirm,
  3017. Remark: s.Remark,
  3018. StopTime: s.StopTime,
  3019. StopReason: s.StopReason,
  3020. StopDoctor: s.StopDoctor,
  3021. StopState: s.StopState,
  3022. ParentId: s.ParentId,
  3023. ExecutionTime: s.ExecutionTime,
  3024. ExecutionStaff: s.ExecutionStaff,
  3025. ExecutionState: s.ExecutionState,
  3026. Checker: s.Checker,
  3027. RecordDate: s.RecordDate,
  3028. DialysisOrderId: s.DialysisOrderId,
  3029. CheckTime: s.CheckTime,
  3030. CheckState: s.CheckState,
  3031. DrugSpec: s.DrugSpec,
  3032. DrugSpecUnit: s.DrugSpecUnit,
  3033. Groupno: s.Groupno,
  3034. RemindType: s.RemindType,
  3035. FrequencyType: s.FrequencyType,
  3036. DayCount: s.DayCount,
  3037. WeekDay: s.WeekDay,
  3038. TemplateId: s.TemplateId,
  3039. Modifier: s.Modifier,
  3040. DrugId: s.DrugId,
  3041. Price: s.Price,
  3042. PrescriptionId: s.PrescriptionId,
  3043. MedListCodg: s.MedListCodg,
  3044. FeedetlSn: s.FeedetlSn,
  3045. Day: s.DayCount,
  3046. ChildDoctorAdvice: nil,
  3047. Drug: models.Drug{},
  3048. Diagnosis: s.Diagnosis,
  3049. Way: s.Way,
  3050. HospApprFlag: s.HospApprFlag,
  3051. LmtUsedFlag: s.LmtUsedFlag,
  3052. HisOrderInfo: models.HisOrderInfo{},
  3053. IsMedicine: s.IsMedicine,
  3054. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3055. Child: nil,
  3056. IsSettle: s.IsSettle,
  3057. IsMobile: s.IsMobile,
  3058. IsSelfDrug: s.IsSelfDrug,
  3059. DrugWayCount: s.DrugWayCount,
  3060. }
  3061. var history_count int64
  3062. var local_count int64
  3063. //查找已经开过的医嘱信息
  3064. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3065. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3066. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3067. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3068. local_count += prescribingNumberSevenTy * drug.MinNumber
  3069. }
  3070. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3071. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3072. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3073. local_count += prescribingNumberSevenTy
  3074. }
  3075. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3076. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3077. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3078. local_count += prescribingNumberSevenTy
  3079. }
  3080. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3081. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3082. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3083. history_count += prescribingNumberSevenTy * drug.MinNumber
  3084. }
  3085. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3086. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3087. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3088. history_count += prescribingNumberSevenTy
  3089. }
  3090. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3091. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3092. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3093. history_count += prescribingNumberSevenTy
  3094. }
  3095. //如果当前出库数量大于历史出库数量则需要出库
  3096. if local_count > history_count {
  3097. //按最小单位出库
  3098. var cha_count = local_count - history_count
  3099. newadviceInfo.PrescribingNumber = float64(cha_count)
  3100. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3101. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3102. }
  3103. //如果当前出库数量小于历史出库数量则需要退库
  3104. if local_count < history_count {
  3105. var cha_count = history_count - local_count
  3106. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3107. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3108. }
  3109. if local_count == history_count {
  3110. if is_user_total == 0 {
  3111. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3112. }
  3113. }
  3114. }
  3115. //更新字典里面的库存
  3116. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3117. var sum_count int64
  3118. for _, its := range stockInfo {
  3119. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3120. if its.MaxUnit == baseDrug.MaxUnit {
  3121. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3122. }
  3123. sum_count += its.StockMaxNumber + its.StockMinNumber
  3124. }
  3125. //更新基础库存
  3126. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3127. //剩余库存
  3128. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3129. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3130. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3131. //创建医嘱
  3132. service.CreateHisDoctorAdviceOne(&s, tx)
  3133. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3134. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3135. if len(outInfoTwo) > 0 {
  3136. for _, item := range outInfoTwo {
  3137. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3138. }
  3139. }
  3140. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3141. if len(drugAutoDetail) > 0 {
  3142. for _, item := range drugAutoDetail {
  3143. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3144. }
  3145. }
  3146. }
  3147. }
  3148. }
  3149. //记录日志
  3150. byterequest, _ := json.Marshal(s)
  3151. adviceLog := models.XtDoctorAdviceLog{
  3152. UserOrgId: s.UserOrgId,
  3153. PatientId: s.PatientId,
  3154. AdminUserId: adminInfo.AdminUser.Id,
  3155. Module: 1,
  3156. ErrLog: string(byterequest),
  3157. Status: 1,
  3158. Ctime: time.Now().Unix(),
  3159. Mtime: 0,
  3160. Source: "电脑端新建his医嘱",
  3161. RecordDate: s.AdviceDate,
  3162. }
  3163. service.CreateDoctorAdviceLog(adviceLog)
  3164. //存储切片中
  3165. adviceList = append(adviceList, s)
  3166. redis := service.RedisClient()
  3167. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3168. redis.Set(key, "", time.Second)
  3169. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3170. redis.Set(keyOne, "", time.Second)
  3171. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3172. redis.Set(keySeven, "", time.Second)
  3173. var randNum int
  3174. randNum = rand.Intn(10000) + 1000
  3175. timestamp := time.Now().Unix()
  3176. tempTime := time.Unix(timestamp, 0)
  3177. timeFormat := tempTime.Format("20060102150405")
  3178. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3179. if s.UserOrgId != 10206 {
  3180. if s.ID == 0 {
  3181. //查询改药品是否已经停用
  3182. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3183. if base.ID > 0 {
  3184. tx.Rollback()
  3185. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3186. return
  3187. }
  3188. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3189. if drugMedical.SumCount == 0 {
  3190. tx.Rollback()
  3191. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3192. return
  3193. }
  3194. }
  3195. }
  3196. //赤峰
  3197. if adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3198. drug, _ := service.FindNewBaseDrugLibRecord(adminInfo.CurrentOrgId, s.DrugId, tx)
  3199. info, _ := service.FindNewLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut, tx)
  3200. if info.RetailPrice > 0 {
  3201. if s.DeliveryWay == "口服" {
  3202. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3203. s.Price = drug.RetailPrice
  3204. }
  3205. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3206. s.Price = info.RetailPrice
  3207. }
  3208. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3209. s.Price = info.RetailPrice
  3210. }
  3211. }
  3212. }
  3213. }
  3214. service.CreateHisDoctorAdviceOne(&s, tx)
  3215. tx.Commit()
  3216. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3217. redis.Set(keySix, "", time.Second)
  3218. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3219. redis.Set(keyFive, "", time.Second)
  3220. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3221. redis.Set(keyEight, "", time.Second)
  3222. defer redis.Close()
  3223. }
  3224. }
  3225. }
  3226. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3227. projects := items["project"].([]interface{})
  3228. if len(projects) > 0 {
  3229. for _, project := range projects {
  3230. tx := db.Begin()
  3231. // 在函数结束时处理事务回滚
  3232. defer func() {
  3233. if r := recover(); r != nil {
  3234. tx.Rollback()
  3235. }
  3236. }()
  3237. var p models.HisPrescriptionProject
  3238. p.PrescriptionId = tempPrescription.ID
  3239. p.PatientId = patient_id
  3240. p.RecordDate = theTime3.Unix()
  3241. p.Doctor = doctor_id
  3242. p.UserOrgId = adminInfo.CurrentOrgId
  3243. p.HisPatientId = his_patient_id
  3244. p.Status = 1
  3245. p.StartTime = pTime
  3246. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3247. if errcode > 0 {
  3248. c.ServeFailJSONWithSGJErrorCode(errcode)
  3249. return
  3250. }
  3251. if p.ID == 0 {
  3252. p.IsOut = 2
  3253. }
  3254. if p.ID > 0 {
  3255. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3256. p.IsOut = projectDetail.IsOut
  3257. }
  3258. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3259. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3260. if p.Type == 3 {
  3261. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3262. if p.Price != lastWarehouse.PackingPrice {
  3263. p.Price = lastWarehouse.PackingPrice
  3264. }
  3265. if p.Price == 0 {
  3266. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3267. p.Price = lastWarehouseTwo.PackingPrice
  3268. }
  3269. if p.Unit == "" {
  3270. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3271. p.Unit = goodInfoOne.PackingUnit
  3272. }
  3273. }
  3274. }
  3275. if adminInfo.CurrentOrgId != 10206 {
  3276. if p.Type == 3 {
  3277. if p.ID == 0 {
  3278. //查询该耗材是否停用
  3279. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3280. //表示该耗材已经停用,不能保存
  3281. if goodInfoSeven.ID == 0 {
  3282. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3283. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3284. return
  3285. }
  3286. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3287. if goodInfoOne.SumCount == 0 {
  3288. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3289. return
  3290. }
  3291. }
  3292. }
  3293. }
  3294. //查询保存耗材出库开关是否打开
  3295. if p.PatientId != 30038 {
  3296. if goodOutConfig.IsOpen == 1 {
  3297. //耗材出库
  3298. if p.Type == 3 {
  3299. //对比当前数据和历史出库数据
  3300. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3301. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3302. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3303. //如果当前处方数量大于历史数据,则需要出库
  3304. if nowCount > historyCount {
  3305. var cha_count int64
  3306. cha_count = nowCount - historyCount
  3307. timeStr := time.Now().Format("2006-01-02")
  3308. timeArr := strings.Split(timeStr, "-")
  3309. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3310. total = total + 1
  3311. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3312. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3313. number = number + total
  3314. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3315. operation_time := time.Now().Unix()
  3316. creater := c.GetAdminUserInfo().AdminUser.Id
  3317. recordDateStr := time.Now().Format("2006-01-02")
  3318. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3319. nowtime := recordDate.Unix()
  3320. warehouseOut := models.WarehouseOut{
  3321. WarehouseOutOrderNumber: warehousing_out_order,
  3322. OperationTime: operation_time,
  3323. OrgId: adminInfo.CurrentOrgId,
  3324. Creater: creater,
  3325. Ctime: time.Now().Unix(),
  3326. Status: 1,
  3327. WarehouseOutTime: nowtime,
  3328. Type: 1,
  3329. StorehouseId: storeConfig.StorehouseOutInfo,
  3330. IsCheck: 1,
  3331. IsSys: 1,
  3332. }
  3333. //查询是否生成出库单
  3334. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3335. if out.ID == 0 {
  3336. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3337. }
  3338. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3339. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3340. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3341. dialyPrepareOne := models.DialysisBeforePrepare{
  3342. GoodTypeId: goodObj.GoodTypeId,
  3343. GoodId: p.ProjectId,
  3344. PatientId: p.PatientId,
  3345. RecordDate: p.RecordDate,
  3346. UserOrgId: adminInfo.CurrentOrgId,
  3347. Count: cha_count,
  3348. Ctime: time.Now().Unix(),
  3349. Creater: creater,
  3350. Status: 1,
  3351. StorehouseId: houseConfig.StorehouseOutInfo,
  3352. ProjectId: p.ID,
  3353. }
  3354. //出库
  3355. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3356. }
  3357. //如果当前处方数量小于历史数据,怎需要退库
  3358. if nowCount < historyCount {
  3359. var cha_count int64
  3360. cha_count = historyCount - nowCount
  3361. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3362. creater := c.GetAdminUserInfo().AdminUser.Id
  3363. newPrescriptionProject := &models.HisPrescriptionProject{
  3364. ID: p.ID,
  3365. ProjectId: p.ProjectId,
  3366. Price: p.Price,
  3367. UserOrgId: p.UserOrgId,
  3368. Status: 1,
  3369. Ctime: time.Now().Unix(),
  3370. Mtime: time.Now().Unix(),
  3371. PatientId: p.PatientId,
  3372. HisPatientId: p.HisPatientId,
  3373. RecordDate: p.RecordDate,
  3374. PrescriptionId: p.PrescriptionId,
  3375. Count: p.Count,
  3376. FeedetlSn: p.FeedetlSn,
  3377. MedListCodg: p.MedListCodg,
  3378. SingleDose: p.SingleDose,
  3379. DeliveryWay: p.DeliveryWay,
  3380. ExecutionFrequency: p.ExecutionFrequency,
  3381. Day: p.Day,
  3382. HisProject: models.HisProject{},
  3383. GoodInfo: models.GoodInfo{},
  3384. Remark: p.Remark,
  3385. Unit: p.Unit,
  3386. Type: p.Type,
  3387. Doctor: p.Doctor,
  3388. ExecutionTime: p.ExecutionTime,
  3389. ExecutionStaff: p.ExecutionStaff,
  3390. ExecutionState: p.ExecutionState,
  3391. CheckTime: p.CheckTime,
  3392. CheckState: p.CheckState,
  3393. Checker: p.Checker,
  3394. StartTime: p.StartTime,
  3395. TeamId: p.TeamId,
  3396. XtHisProjectTeam: models.XtHisProjectTeam{},
  3397. FrequencyType: p.FrequencyType,
  3398. DayCount: p.DayCount,
  3399. WeekDay: p.WeekDay,
  3400. IsCheckTeam: p.IsCheckTeam,
  3401. HisOrderInfo: models.HisOrderInfo{},
  3402. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3403. IsOut: p.IsOut,
  3404. YbSyncStatus: p.YbSyncStatus,
  3405. }
  3406. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3407. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3408. }
  3409. if nowCount == historyCount {
  3410. if historyCount == 0 {
  3411. recordDateStr := time.Now().Format("2006-01-02")
  3412. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3413. nowtime := recordDate.Unix()
  3414. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3415. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3416. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3417. creater := c.GetAdminUserInfo().AdminUser.Id
  3418. dialyPrepareOne := models.DialysisBeforePrepare{
  3419. GoodTypeId: goodObj.GoodTypeId,
  3420. GoodId: p.ProjectId,
  3421. PatientId: p.PatientId,
  3422. RecordDate: p.RecordDate,
  3423. UserOrgId: adminInfo.CurrentOrgId,
  3424. Count: nowCount,
  3425. Ctime: time.Now().Unix(),
  3426. Creater: creater,
  3427. Status: 1,
  3428. StorehouseId: houseConfig.StorehouseOutInfo,
  3429. ProjectId: p.ID,
  3430. }
  3431. //出库
  3432. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3433. }
  3434. }
  3435. //lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3436. ////查询历史出库数据
  3437. //flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3438. //
  3439. //var out_count_five int64
  3440. //for _, item := range flowGood {
  3441. // out_count_five += item.Count
  3442. //}
  3443. //parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3444. //
  3445. ////如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3446. //if out_count_five != parseIntCount {
  3447. // //查询耗材最后一次出库记录
  3448. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3449. // //查询默认出库仓库库存
  3450. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3451. // if len(wareOut) > 0 {
  3452. //
  3453. // for _, it := range wareOut {
  3454. // //回退库存
  3455. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3456. //
  3457. // //删除出库记录
  3458. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3459. //
  3460. // }
  3461. // }
  3462. //
  3463. // timeStr := time.Now().Format("2006-01-02")
  3464. // timeArr := strings.Split(timeStr, "-")
  3465. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3466. //
  3467. // total = total + 1
  3468. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3469. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3470. // number = number + total
  3471. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3472. //
  3473. // operation_time := time.Now().Unix()
  3474. // creater := c.GetAdminUserInfo().AdminUser.Id
  3475. //
  3476. // recordDateStr := time.Now().Format("2006-01-02")
  3477. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3478. // nowtime := recordDate.Unix()
  3479. // warehouseOut := models.WarehouseOut{
  3480. // WarehouseOutOrderNumber: warehousing_out_order,
  3481. // OperationTime: operation_time,
  3482. // OrgId: adminInfo.CurrentOrgId,
  3483. // Creater: creater,
  3484. // Ctime: time.Now().Unix(),
  3485. // Status: 1,
  3486. // WarehouseOutTime: nowtime,
  3487. // Type: 1,
  3488. // StorehouseId: storeConfig.StorehouseOutInfo,
  3489. // IsCheck: 1,
  3490. // IsSys: 1,
  3491. // }
  3492. // //查询是否生成出库单
  3493. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3494. // if out.ID == 0 {
  3495. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3496. // }
  3497. //
  3498. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3499. //
  3500. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3501. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3502. //
  3503. // dialyPrepareOne := models.DialysisBeforePrepare{
  3504. // GoodTypeId: goodObj.GoodTypeId,
  3505. // GoodId: p.ProjectId,
  3506. // PatientId: p.PatientId,
  3507. // RecordDate: p.RecordDate,
  3508. // UserOrgId: adminInfo.CurrentOrgId,
  3509. // Count: parseIntCount,
  3510. // Ctime: time.Now().Unix(),
  3511. // Creater: creater,
  3512. // Status: 1,
  3513. // StorehouseId: houseConfig.StorehouseOutInfo,
  3514. // ProjectId: lastHisProject.ID,
  3515. // }
  3516. // //判断是否是零用耗材(非零用)
  3517. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3518. //
  3519. // //查询历史出库数据
  3520. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3521. // var out_count int64
  3522. // for _, item := range flowGood {
  3523. // out_count += item.Count
  3524. // }
  3525. // //如果历史数和当前数据不想等才进行退库出库
  3526. // if out_count != parseIntCount {
  3527. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3528. //
  3529. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3530. // detail := models.AutomaticReduceDetail{
  3531. // WarehouseOutId: 0,
  3532. // WarehouseOutOrderNumber: "",
  3533. // PatientId: p.PatientId,
  3534. // Ctime: time.Now().Unix(),
  3535. // Mtime: 0,
  3536. // Status: 1,
  3537. // RecordTime: p.RecordDate,
  3538. // OrgId: p.UserOrgId,
  3539. // GoodId: p.ProjectId,
  3540. // GoodTypeId: 0,
  3541. // Count: parseIntCount,
  3542. // Type: 0,
  3543. // ProjectId: lastHisProject.ID,
  3544. // StorehouseId: 0,
  3545. // }
  3546. //
  3547. // service.CreateNewAutoDetail(detail, tx)
  3548. //
  3549. // //查询剩余库存
  3550. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3551. // var sum_count int64
  3552. // for _, item := range goodList {
  3553. // sum_count += item.StockCount
  3554. // }
  3555. //
  3556. // //更新剩余库存
  3557. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3558. //
  3559. // //耗材
  3560. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3561. //
  3562. // }
  3563. // //判断是否是零用耗材(零用但是是出库耗材)
  3564. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3565. //
  3566. // //查询历史出库数据
  3567. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3568. // var out_count int64
  3569. // for _, item := range flowGood {
  3570. // out_count += item.Count
  3571. // }
  3572. // //如果历史数和当前数据不想等才进行退库出库
  3573. // if out_count != parseIntCount {
  3574. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3575. //
  3576. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3577. // detail := models.AutomaticReduceDetail{
  3578. // WarehouseOutId: 0,
  3579. // WarehouseOutOrderNumber: "",
  3580. // PatientId: p.PatientId,
  3581. // Ctime: time.Now().Unix(),
  3582. // Mtime: 0,
  3583. // Status: 1,
  3584. // RecordTime: p.RecordDate,
  3585. // OrgId: p.UserOrgId,
  3586. // GoodId: p.ProjectId,
  3587. // GoodTypeId: 0,
  3588. // Count: parseIntCount,
  3589. // Type: 0,
  3590. // ProjectId: p.ID,
  3591. // StorehouseId: 0,
  3592. // }
  3593. //
  3594. // service.CreateNewAutoDetail(detail, tx)
  3595. //
  3596. // //查询剩余库存
  3597. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3598. // var sum_count int64
  3599. // for _, item := range goodList {
  3600. // sum_count += item.StockCount
  3601. // }
  3602. //
  3603. // //更新剩余库存
  3604. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3605. //
  3606. // //耗材
  3607. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3608. // }
  3609. //
  3610. // }
  3611. //
  3612. // }
  3613. //
  3614. //}
  3615. //记录日志
  3616. byterequest, _ := json.Marshal(p)
  3617. adviceLog := models.XtDoctorAdviceLog{
  3618. UserOrgId: p.UserOrgId,
  3619. PatientId: p.PatientId,
  3620. AdminUserId: adminInfo.AdminUser.Id,
  3621. Module: 1,
  3622. ErrLog: string(byterequest),
  3623. Status: 1,
  3624. Ctime: time.Now().Unix(),
  3625. Mtime: 0,
  3626. Source: "电脑端新建his项目",
  3627. RecordDate: p.RecordDate,
  3628. }
  3629. service.CreateDoctorAdviceLog(adviceLog)
  3630. projectList = append(projectList, p)
  3631. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3632. //新增或者编辑项目,修改对应的标签数据
  3633. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3634. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3635. var label models.HisLabelPrintInfo
  3636. project, _ := service.GetProjectDetail(p.ProjectId)
  3637. if project.CostClassify == 3 { //类别为检验检查
  3638. if p.TeamId > 0 { //检验检查组套
  3639. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3640. if tempLabel.ID == 0 {
  3641. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3642. label.Number = tempPrescription.PrescriptionNumber
  3643. label.ProjectId = project.ID
  3644. label.Status = 1
  3645. label.IsPrint = 2
  3646. label.DoctorId = info.DoctorId
  3647. label.UserOrgId = p.UserOrgId
  3648. label.PatientId = patient_id
  3649. label.RecordDate = recordDateTime
  3650. label.Ctime = time.Now().Unix()
  3651. label.Mtime = time.Now().Unix()
  3652. label.ItemId = p.TeamId
  3653. label.FeedetlSn = p.FeedetlSn
  3654. label.PProjectId = p.ID
  3655. label.ProjectName = team.ProjectTeam
  3656. label.PatientName = patient.Name
  3657. service.CreateNewHisLabelRecord(&label, tx)
  3658. }
  3659. } else { //单条检验检查项目
  3660. label.Number = tempPrescription.PrescriptionNumber
  3661. label.ProjectId = project.ID
  3662. label.Status = 1
  3663. label.DoctorId = info.DoctorId
  3664. label.UserOrgId = p.UserOrgId
  3665. label.PatientId = patient_id
  3666. label.RecordDate = recordDateTime
  3667. label.IsPrint = 2
  3668. label.Ctime = time.Now().Unix()
  3669. label.Mtime = time.Now().Unix()
  3670. label.FeedetlSn = p.FeedetlSn
  3671. label.PProjectId = p.ID
  3672. label.ItemId = p.TeamId
  3673. label.ProjectName = project.ProjectName
  3674. label.PatientName = patient.Name
  3675. service.CreateNewHisLabelRecord(&label, tx)
  3676. }
  3677. }
  3678. }
  3679. }
  3680. }
  3681. }
  3682. }
  3683. //插入检验数据
  3684. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3685. //新增或者编辑项目,修改对应的标签数据
  3686. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3687. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3688. var label models.HisLabelPrintInfo
  3689. project, _ := service.GetProjectDetail(p.ProjectId)
  3690. if project.CostClassify == 3 { //类别为检验检查
  3691. if p.TeamId > 0 { //检验检查组套
  3692. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3693. if tempLabel.ID == 0 {
  3694. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3695. label.Number = tempPrescription.PrescriptionNumber
  3696. label.ProjectId = project.ID
  3697. label.Status = 1
  3698. label.IsPrint = 2
  3699. label.DoctorId = info.DoctorId
  3700. label.UserOrgId = p.UserOrgId
  3701. label.PatientId = patient_id
  3702. label.RecordDate = recordDateTime
  3703. label.Ctime = time.Now().Unix()
  3704. label.Mtime = time.Now().Unix()
  3705. label.ItemId = p.TeamId
  3706. label.FeedetlSn = p.FeedetlSn
  3707. label.PProjectId = p.ID
  3708. label.ProjectName = team.ProjectTeam
  3709. label.PatientName = patient.Name
  3710. service.CreateHisLabelRecord(&label)
  3711. }
  3712. } else { //单条检验检查项目
  3713. label.Number = tempPrescription.PrescriptionNumber
  3714. label.ProjectId = project.ID
  3715. label.Status = 1
  3716. label.DoctorId = info.DoctorId
  3717. label.UserOrgId = p.UserOrgId
  3718. label.PatientId = patient_id
  3719. label.RecordDate = recordDateTime
  3720. label.IsPrint = 2
  3721. label.Ctime = time.Now().Unix()
  3722. label.Mtime = time.Now().Unix()
  3723. label.FeedetlSn = p.FeedetlSn
  3724. label.PProjectId = p.ID
  3725. label.ItemId = p.TeamId
  3726. label.ProjectName = project.ProjectName
  3727. label.PatientName = patient.Name
  3728. service.CreateHisLabelRecord(&label)
  3729. }
  3730. }
  3731. }
  3732. }
  3733. service.CreateNewHisProjectTwo(&p, tx)
  3734. var randNum int
  3735. randNum = rand.Intn(10000) + 1000
  3736. timestamp := time.Now().Unix()
  3737. tempTime := time.Unix(timestamp, 0)
  3738. timeFormat := tempTime.Format("20060102150405")
  3739. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3740. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  3741. if goodBase.ID > 0 {
  3742. tx.Rollback()
  3743. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  3744. return
  3745. }
  3746. service.CreateNewHisProjectTwo(&p, tx)
  3747. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3748. //查询剩余库存
  3749. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3750. var sum_count int64
  3751. for _, item := range goodList {
  3752. sum_count += item.StockCount
  3753. }
  3754. //更新剩余库存
  3755. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3756. //耗材
  3757. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3758. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3759. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3760. if len(outInfoTwo) > 0 {
  3761. for _, item := range outInfoTwo {
  3762. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3763. }
  3764. }
  3765. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3766. if len(drugAutoDetail) > 0 {
  3767. for _, item := range drugAutoDetail {
  3768. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  3769. }
  3770. }
  3771. tx.Commit()
  3772. }
  3773. }
  3774. }
  3775. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3776. // addition := items["addition"].([]interface{})
  3777. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3778. // ctime := time.Now().Unix()
  3779. // mtime := ctime
  3780. // if len(addition) > 0 {
  3781. // for _, item := range addition {
  3782. // var s models.HisAdditionalCharge
  3783. // s.PrescriptionId = tempPrescription.ID
  3784. // s.Status = 1
  3785. // s.UserOrgId = adminInfo.CurrentOrgId
  3786. // s.RecordDate = recordDateTime
  3787. // s.CreatedTime = ctime
  3788. // s.UpdatedTime = mtime
  3789. // s.PatientId = patient_id
  3790. // s.HisPatientId = his_patient_id
  3791. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3792. // if errcode > 0 {
  3793. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3794. // return
  3795. // }
  3796. // service.CreateAdditionalCharge(&s)
  3797. // var randNum int
  3798. // randNum = rand.Intn(10000) + 1000
  3799. // timestamp := time.Now().Unix()
  3800. // tempTime := time.Unix(timestamp, 0)
  3801. // timeFormat := tempTime.Format("20060102150405")
  3802. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3803. // service.CreateAdditionalCharge(&s)
  3804. //
  3805. // }
  3806. // }
  3807. //}
  3808. }
  3809. }
  3810. }
  3811. tx.Commit()
  3812. if err == nil {
  3813. c.ServeSuccessJSON(map[string]interface{}{
  3814. "msg": "保存成功",
  3815. })
  3816. return
  3817. } else {
  3818. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3819. return
  3820. }
  3821. } else {
  3822. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3823. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3824. var tempPrescription *models.HisPrescription
  3825. if len(prescriptions) > 0 {
  3826. for _, item := range prescriptions {
  3827. items := item.(map[string]interface{})
  3828. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3829. utils.ErrorLog("id")
  3830. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3831. return
  3832. }
  3833. id := int64(items["id"].(float64))
  3834. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3835. tempPrescription = &new_prescription
  3836. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3837. utils.ErrorLog("type")
  3838. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3839. return
  3840. }
  3841. types := int64(items["type"].(float64))
  3842. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3843. utils.ErrorLog("med_type")
  3844. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3845. return
  3846. }
  3847. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3848. if med_type == "0" {
  3849. med_type = "14"
  3850. }
  3851. //if order_status == 0 {
  3852. // order_status = 1
  3853. //}
  3854. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3855. utils.ErrorLog("pre_time")
  3856. }
  3857. preTime, _ := items["pre_time"].(string)
  3858. timeLayout := "2006-01-02"
  3859. loc, _ := time.LoadLocation("Local")
  3860. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3861. //result := strings.Split(preTime, " ")
  3862. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3863. if err != nil {
  3864. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3865. return
  3866. }
  3867. pTime := theTime2.Unix()
  3868. ctime := time.Now().Unix()
  3869. if tempPrescription.ID == 0 {
  3870. prescription := &models.HisPrescription{
  3871. ID: 0,
  3872. PatientId: patient_id,
  3873. UserOrgId: adminInfo.CurrentOrgId,
  3874. RecordDate: recordDateTime,
  3875. Ctime: ctime,
  3876. Mtime: ctime,
  3877. Type: types,
  3878. Modifier: adminInfo.AdminUser.Id,
  3879. Creator: adminInfo.AdminUser.Id,
  3880. Status: 1,
  3881. Doctor: role.UserName,
  3882. HisPatientId: his_patient_id,
  3883. OrderStatus: 1,
  3884. BatchNumber: "",
  3885. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3886. PreTime: pTime,
  3887. PType: p_type,
  3888. MedType: med_type,
  3889. }
  3890. tempPrescription = prescription
  3891. service.SaveHisPrescription(tempPrescription)
  3892. redis := service.RedisClient()
  3893. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3894. redis.Set(key, "", time.Second)
  3895. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3896. redis.Set(keyOne, "", time.Second)
  3897. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3898. redis.Set(keySeven, "", time.Second)
  3899. defer redis.Close()
  3900. } else {
  3901. tempPrescription.ID = id
  3902. tempPrescription.Type = types
  3903. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3904. tempPrescription.Mtime = time.Now().Unix()
  3905. tempPrescription.Doctor = role.UserName
  3906. //tempPrescription.OrderStatus = order_status
  3907. tempPrescription.PreTime = pTime
  3908. tempPrescription.MedType = med_type
  3909. service.SaveHisPrescription(tempPrescription)
  3910. redis := service.RedisClient()
  3911. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3912. redis.Set(key, "", time.Second)
  3913. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3914. redis.Set(keyOne, "", time.Second)
  3915. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3916. redis.Set(keySeven, "", time.Second)
  3917. defer redis.Close()
  3918. }
  3919. //service.SaveHisPrescription(prescription)
  3920. //更改患者挂号状态
  3921. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3922. fmt.Println("更改失败", err2)
  3923. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3924. advices := items["advices"].([]interface{})
  3925. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3926. groupNo := int64(0)
  3927. if len(advices) > 0 {
  3928. for _, advice := range advices {
  3929. var s models.HisDoctorAdviceInfo
  3930. s.PrescriptionId = tempPrescription.ID
  3931. s.AdviceType = 2
  3932. s.AdviceDoctor = doctor_id
  3933. s.StopState = 2
  3934. s.ExecutionState = 2
  3935. s.AdviceDate = theTime3.Unix()
  3936. s.Status = 1
  3937. s.UserOrgId = adminInfo.CurrentOrgId
  3938. s.RecordDate = theTime3.Unix()
  3939. s.StartTime = tempPrescription.PreTime
  3940. s.Groupno = groupNo
  3941. s.PatientId = patient_id
  3942. s.HisPatientId = his_patient_id
  3943. s.StartTime = pTime
  3944. s.IsSettle = 2
  3945. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3946. if errcode > 0 {
  3947. c.ServeFailJSONWithSGJErrorCode(errcode)
  3948. return
  3949. }
  3950. s.StartTime = pTime
  3951. var total_count int64 //处方总库存
  3952. //查询改药品信息
  3953. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3954. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3955. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3956. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3957. total_count += prescribingNumberSeven * medical.MinNumber
  3958. }
  3959. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3960. total_count += prescribingNumberSeven
  3961. }
  3962. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3963. total_count += prescribingNumberSeven
  3964. }
  3965. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3966. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3967. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3968. if s.Price != lastWarehouse.RetailPrice {
  3969. s.Price = lastWarehouse.RetailPrice
  3970. }
  3971. if s.Price == 0 {
  3972. if lastWarehouse.ID == 0 {
  3973. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  3974. s.Price = lastWarehouseTwo.RetailPrice
  3975. }
  3976. }
  3977. }
  3978. if adminInfo.CurrentOrgId != 10206 {
  3979. if s.ID == 0 {
  3980. //查询改药品是否已经停用
  3981. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3982. if base.ID > 0 {
  3983. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3984. return
  3985. }
  3986. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3987. if drugMedical.SumCount == 0 {
  3988. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3989. return
  3990. }
  3991. }
  3992. }
  3993. //赤峰
  3994. if s.UserOrgId == 10265 || s.UserOrgId == 10489 {
  3995. drug, _ := service.GetDrugByGoodId(s.DrugId)
  3996. info, _ := service.GetWarehoseInfoByDrugId(s.DrugId, s.UserOrgId)
  3997. if info.RetailPrice > 0 {
  3998. if s.DeliveryWay == "口服" {
  3999. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4000. s.Price = drug.RetailPrice
  4001. }
  4002. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4003. s.Price = info.RetailPrice
  4004. }
  4005. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4006. s.Price = info.RetailPrice
  4007. }
  4008. }
  4009. }
  4010. }
  4011. service.CreateHisDoctorAdvice(&s)
  4012. //记录日志
  4013. byterequest, _ := json.Marshal(s)
  4014. adviceLog := models.XtDoctorAdviceLog{
  4015. UserOrgId: s.UserOrgId,
  4016. PatientId: s.PatientId,
  4017. AdminUserId: adminInfo.AdminUser.Id,
  4018. Module: 1,
  4019. ErrLog: string(byterequest),
  4020. Status: 1,
  4021. Ctime: time.Now().Unix(),
  4022. Mtime: 0,
  4023. Source: "电脑端新建his医嘱",
  4024. RecordDate: s.AdviceDate,
  4025. }
  4026. service.CreateDoctorAdviceLog(adviceLog)
  4027. //存储切片中
  4028. adviceList = append(adviceList, s)
  4029. redis := service.RedisClient()
  4030. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4031. redis.Set(key, "", time.Second)
  4032. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4033. redis.Set(keyOne, "", time.Second)
  4034. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4035. redis.Set(keySeven, "", time.Second)
  4036. var randNum int
  4037. randNum = rand.Intn(10000) + 1000
  4038. timestamp := time.Now().Unix()
  4039. tempTime := time.Unix(timestamp, 0)
  4040. timeFormat := tempTime.Format("20060102150405")
  4041. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  4042. service.CreateHisDoctorAdvice(&s)
  4043. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4044. redis.Set(keySix, "", time.Second)
  4045. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4046. redis.Set(keyFive, "", time.Second)
  4047. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4048. redis.Set(keyEight, "", time.Second)
  4049. defer redis.Close()
  4050. }
  4051. }
  4052. }
  4053. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4054. projects := items["project"].([]interface{})
  4055. if len(projects) > 0 {
  4056. for _, project := range projects {
  4057. var p models.HisPrescriptionProject
  4058. p.PrescriptionId = tempPrescription.ID
  4059. p.PatientId = patient_id
  4060. p.RecordDate = theTime3.Unix()
  4061. p.Doctor = doctor_id
  4062. p.UserOrgId = adminInfo.CurrentOrgId
  4063. p.HisPatientId = his_patient_id
  4064. p.Status = 1
  4065. p.StartTime = pTime
  4066. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  4067. if errcode > 0 {
  4068. c.ServeFailJSONWithSGJErrorCode(errcode)
  4069. return
  4070. }
  4071. if p.ID == 0 {
  4072. p.IsOut = 2
  4073. }
  4074. if p.ID > 0 {
  4075. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  4076. p.IsOut = projectDetail.IsOut
  4077. }
  4078. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4079. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4080. if p.Type == 3 {
  4081. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  4082. if p.Price != lastWarehouse.PackingPrice {
  4083. p.Price = lastWarehouse.PackingPrice
  4084. }
  4085. if p.Price == 0 {
  4086. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  4087. p.Price = lastWarehouseTwo.PackingPrice
  4088. }
  4089. if p.Unit == "" {
  4090. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4091. p.Unit = goodInfoOne.PackingUnit
  4092. }
  4093. }
  4094. }
  4095. if adminInfo.CurrentOrgId != 10206 {
  4096. if p.Type == 3 {
  4097. if p.ID == 0 {
  4098. //查询该耗材是否停用
  4099. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  4100. //表示该耗材已经停用,不能保存
  4101. if goodInfoSeven.ID == 0 {
  4102. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4103. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  4104. return
  4105. }
  4106. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4107. if goodInfoOne.SumCount == 0 {
  4108. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  4109. return
  4110. }
  4111. }
  4112. }
  4113. }
  4114. service.CreateHisProjectTwo(&p)
  4115. //记录日志
  4116. byterequest, _ := json.Marshal(p)
  4117. adviceLog := models.XtDoctorAdviceLog{
  4118. UserOrgId: p.UserOrgId,
  4119. PatientId: p.PatientId,
  4120. AdminUserId: adminInfo.AdminUser.Id,
  4121. Module: 1,
  4122. ErrLog: string(byterequest),
  4123. Status: 1,
  4124. Ctime: time.Now().Unix(),
  4125. Mtime: 0,
  4126. Source: "电脑端新建his项目",
  4127. RecordDate: p.RecordDate,
  4128. }
  4129. service.CreateDoctorAdviceLog(adviceLog)
  4130. projectList = append(projectList, p)
  4131. var randNum int
  4132. randNum = rand.Intn(10000) + 1000
  4133. timestamp := time.Now().Unix()
  4134. tempTime := time.Unix(timestamp, 0)
  4135. timeFormat := tempTime.Format("20060102150405")
  4136. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4137. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4138. //新增或者编辑项目,修改对应的标签数据
  4139. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4140. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4141. var label models.HisLabelPrintInfo
  4142. project, _ := service.GetProjectDetail(p.ProjectId)
  4143. if project.CostClassify == 3 { //类别为检验检查
  4144. if p.TeamId > 0 { //检验检查组套
  4145. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4146. if tempLabel.ID == 0 {
  4147. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4148. label.Number = tempPrescription.PrescriptionNumber
  4149. label.ProjectId = project.ID
  4150. label.Status = 1
  4151. label.IsPrint = 2
  4152. label.DoctorId = info.DoctorId
  4153. label.UserOrgId = p.UserOrgId
  4154. label.PatientId = patient_id
  4155. label.RecordDate = recordDateTime
  4156. label.Ctime = time.Now().Unix()
  4157. label.Mtime = time.Now().Unix()
  4158. label.ItemId = p.TeamId
  4159. label.FeedetlSn = p.FeedetlSn
  4160. label.PProjectId = p.ID
  4161. label.ProjectName = team.ProjectTeam
  4162. label.PatientName = patient.Name
  4163. service.CreateHisLabelRecord(&label)
  4164. }
  4165. } else { //单条检验检查项目
  4166. label.Number = tempPrescription.PrescriptionNumber
  4167. label.ProjectId = project.ID
  4168. label.Status = 1
  4169. label.DoctorId = info.DoctorId
  4170. label.UserOrgId = p.UserOrgId
  4171. label.PatientId = patient_id
  4172. label.RecordDate = recordDateTime
  4173. label.IsPrint = 2
  4174. label.Ctime = time.Now().Unix()
  4175. label.Mtime = time.Now().Unix()
  4176. label.FeedetlSn = p.FeedetlSn
  4177. label.PProjectId = p.ID
  4178. label.ItemId = p.TeamId
  4179. label.ProjectName = project.ProjectName
  4180. label.PatientName = patient.Name
  4181. service.CreateHisLabelRecord(&label)
  4182. }
  4183. }
  4184. }
  4185. }
  4186. service.SaveHisProjectTwo(&p)
  4187. }
  4188. }
  4189. }
  4190. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4191. // addition := items["addition"].([]interface{})
  4192. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4193. // ctime := time.Now().Unix()
  4194. // mtime := ctime
  4195. // if len(addition) > 0 {
  4196. // for _, item := range addition {
  4197. // var s models.HisAdditionalCharge
  4198. // s.PrescriptionId = tempPrescription.ID
  4199. // s.Status = 1
  4200. // s.UserOrgId = adminInfo.CurrentOrgId
  4201. // s.RecordDate = recordDateTime
  4202. // s.CreatedTime = ctime
  4203. // s.UpdatedTime = mtime
  4204. // s.PatientId = patient_id
  4205. // s.HisPatientId = his_patient_id
  4206. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4207. // if errcode > 0 {
  4208. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4209. // return
  4210. // }
  4211. // service.CreateAdditionalCharge(&s)
  4212. // var randNum int
  4213. // randNum = rand.Intn(10000) + 1000
  4214. // timestamp := time.Now().Unix()
  4215. // tempTime := time.Unix(timestamp, 0)
  4216. // timeFormat := tempTime.Format("20060102150405")
  4217. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4218. // service.CreateAdditionalCharge(&s)
  4219. //
  4220. // }
  4221. // }
  4222. //}
  4223. }
  4224. }
  4225. //查询今日该患者开的药品处方
  4226. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4227. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  4228. //药品出库
  4229. if drugOutConfig.IsOpen == 1 {
  4230. for _, item := range hisdoctorlist {
  4231. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  4232. // 查询该药品最后一次出库记录
  4233. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  4234. if len(druginfo) > 0 {
  4235. //回退库存
  4236. for _, it := range druginfo {
  4237. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4238. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4239. }
  4240. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4241. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4242. }
  4243. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4244. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4245. }
  4246. }
  4247. }
  4248. //删除记录
  4249. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4250. //查询最后一次数据
  4251. if drugOutConfig.IsOpen == 1 {
  4252. //出库
  4253. if drug.IsUse == 2 {
  4254. creater := adminInfo.AdminUser.Id
  4255. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4256. }
  4257. //更新字典里面的库存
  4258. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4259. var sum_count int64
  4260. for _, its := range stockInfo {
  4261. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4262. if its.MaxUnit == baseDrug.MaxUnit {
  4263. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4264. }
  4265. sum_count += its.StockMaxNumber + its.StockMinNumber
  4266. }
  4267. //更新基础库存
  4268. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4269. //剩余库存
  4270. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4271. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4272. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4273. }
  4274. }
  4275. }
  4276. //耗材保存处方出库
  4277. if goodOutConfig.IsOpen == 1 {
  4278. //查询今日耗材出库数量
  4279. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4280. for _, item := range hisgoodlist {
  4281. //查询历史出库数据
  4282. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4283. var out_count_five int64
  4284. for _, item := range flowGood {
  4285. out_count_five += item.Count
  4286. }
  4287. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  4288. if out_count_five != parseIntCount {
  4289. //查询耗材最后一次出库记录
  4290. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  4291. //查询默认出库仓库库存
  4292. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4293. if len(wareOut) > 0 {
  4294. for _, it := range wareOut {
  4295. //回退库存
  4296. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4297. //删除出库记录
  4298. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4299. }
  4300. }
  4301. timeStr := time.Now().Format("2006-01-02")
  4302. timeArr := strings.Split(timeStr, "-")
  4303. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4304. total = total + 1
  4305. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4306. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4307. number = number + total
  4308. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4309. operation_time := time.Now().Unix()
  4310. creater := c.GetAdminUserInfo().AdminUser.Id
  4311. recordDateStr := time.Now().Format("2006-01-02")
  4312. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4313. nowtime := recordDate.Unix()
  4314. warehouseOut := models.WarehouseOut{
  4315. WarehouseOutOrderNumber: warehousing_out_order,
  4316. OperationTime: operation_time,
  4317. OrgId: adminInfo.CurrentOrgId,
  4318. Creater: creater,
  4319. Ctime: time.Now().Unix(),
  4320. Status: 1,
  4321. WarehouseOutTime: nowtime,
  4322. Type: 1,
  4323. StorehouseId: storeConfig.StorehouseOutInfo,
  4324. IsCheck: 1,
  4325. IsSys: 1,
  4326. }
  4327. //查询是否生成出库单
  4328. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4329. if out.ID == 0 {
  4330. service.AddSigleWarehouseOut(&warehouseOut)
  4331. }
  4332. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4333. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4334. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4335. dialyPrepareOne := models.DialysisBeforePrepare{
  4336. GoodTypeId: goodObj.GoodTypeId,
  4337. GoodId: item.ProjectId,
  4338. PatientId: item.PatientId,
  4339. RecordDate: item.RecordDate,
  4340. UserOrgId: adminInfo.CurrentOrgId,
  4341. Count: parseIntCount,
  4342. Ctime: time.Now().Unix(),
  4343. Creater: creater,
  4344. Status: 1,
  4345. StorehouseId: houseConfig.StorehouseOutInfo,
  4346. ProjectId: item.ID,
  4347. }
  4348. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4349. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  4350. //查询历史出库数据
  4351. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4352. var out_count int64
  4353. for _, item := range flowGood {
  4354. out_count += item.Count
  4355. }
  4356. //如果历史数和当前数据不想等才进行退库出库
  4357. if out_count != parseIntCount {
  4358. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4359. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4360. detail := models.AutomaticReduceDetail{
  4361. WarehouseOutId: 0,
  4362. WarehouseOutOrderNumber: "",
  4363. PatientId: item.PatientId,
  4364. Ctime: time.Now().Unix(),
  4365. Mtime: 0,
  4366. Status: 1,
  4367. RecordTime: item.RecordDate,
  4368. OrgId: item.UserOrgId,
  4369. GoodId: item.ProjectId,
  4370. GoodTypeId: 0,
  4371. Count: parseIntCount,
  4372. Type: 0,
  4373. ProjectId: item.ID,
  4374. StorehouseId: 0,
  4375. }
  4376. service.CreateAutoDetail(detail)
  4377. //查询剩余库存
  4378. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4379. var sum_count int64
  4380. for _, item := range goodList {
  4381. sum_count += item.StockCount
  4382. }
  4383. //更新剩余库存
  4384. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4385. //耗材
  4386. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4387. }
  4388. }
  4389. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  4390. //查询历史出库数据
  4391. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4392. var out_count int64
  4393. for _, item := range flowGood {
  4394. out_count += item.Count
  4395. }
  4396. //如果历史数和当前数据不想等才进行退库出库
  4397. if out_count != parseIntCount {
  4398. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4399. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4400. detail := models.AutomaticReduceDetail{
  4401. WarehouseOutId: 0,
  4402. WarehouseOutOrderNumber: "",
  4403. PatientId: item.PatientId,
  4404. Ctime: time.Now().Unix(),
  4405. Mtime: 0,
  4406. Status: 1,
  4407. RecordTime: item.RecordDate,
  4408. OrgId: item.UserOrgId,
  4409. GoodId: item.ProjectId,
  4410. GoodTypeId: 0,
  4411. Count: parseIntCount,
  4412. Type: 0,
  4413. ProjectId: item.ID,
  4414. StorehouseId: 0,
  4415. }
  4416. service.CreateAutoDetail(detail)
  4417. //查询剩余库存
  4418. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4419. var sum_count int64
  4420. for _, item := range goodList {
  4421. sum_count += item.StockCount
  4422. }
  4423. //更新剩余库存
  4424. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4425. //耗材
  4426. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4427. }
  4428. }
  4429. }
  4430. }
  4431. }
  4432. ////同步到自备药
  4433. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  4434. if selfPrescriptionOpen.IsOpen == 1 {
  4435. timeStr := time.Now().Format("2006-01-02")
  4436. timeArr := strings.Split(timeStr, "-")
  4437. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  4438. total = total + 1
  4439. operation_time := time.Now().Unix()
  4440. creater := adminInfo.AdminUser.Id
  4441. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4442. warehousing := models.XtSelfDrugWarehouse{
  4443. WarehousingOrder: warehousing_order,
  4444. OperationTime: operation_time,
  4445. OrgId: adminInfo.CurrentOrgId,
  4446. Creater: creater,
  4447. Ctime: time.Now().Unix(),
  4448. Status: 1,
  4449. WarehousingTime: recordDateTime,
  4450. Type: 0,
  4451. StorehouseId: 0,
  4452. IsCheck: 1,
  4453. PatientId: patient_id,
  4454. IsSys: 1,
  4455. }
  4456. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  4457. if selfDrugWarehouse.ID == 0 {
  4458. service.AddSelfDrugWarehouse(&warehousing, tx)
  4459. }
  4460. if selfDrugWarehouse.ID > 0 {
  4461. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  4462. }
  4463. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  4464. fmt.Println(info)
  4465. for _, item := range hisdoctorlist {
  4466. //查询该病人的该药品是否已经入库
  4467. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  4468. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  4469. var in_count int64
  4470. if len(selfdruginfo) > 0 {
  4471. for _, item := range selfdruginfo {
  4472. var in_count_one int64
  4473. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4474. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  4475. }
  4476. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4477. in_count_one = item.WarehousingCount
  4478. }
  4479. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4480. in_count_one = item.WarehousingCount
  4481. }
  4482. in_count += in_count_one
  4483. }
  4484. }
  4485. if selfBasedrug.IsSelfDrug == 1 {
  4486. var total_count int64
  4487. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  4488. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  4489. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4490. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  4491. }
  4492. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4493. total_count += prescribingNumberSeven
  4494. }
  4495. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4496. total_count += prescribingNumberSeven
  4497. }
  4498. //入库
  4499. if total_count > in_count {
  4500. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  4501. WarehousingOrder: warehousing_order,
  4502. WarehousingId: info.ID,
  4503. DrugId: item.DrugId,
  4504. Number: "",
  4505. ProductDate: 0,
  4506. ExpiryDate: 0,
  4507. WarehousingCount: total_count - in_count,
  4508. WarehouseingUnit: selfBasedrug.MinUnit,
  4509. Price: 0,
  4510. TotalPrice: 0,
  4511. Status: 1,
  4512. Ctime: time.Now().Unix(),
  4513. Remark: "",
  4514. OrgId: adminInfo.CurrentOrgId,
  4515. Type: 0,
  4516. Manufacturer: selfBasedrug.Manufacturer,
  4517. Dealer: selfBasedrug.Dealer,
  4518. StockMaxNumber: total_count - in_count,
  4519. RetailTotalPrice: 0,
  4520. BatchNumber: "",
  4521. MaxUnit: selfBasedrug.MinUnit,
  4522. MinUnit: selfBasedrug.MinUnit,
  4523. RetailPrice: 0,
  4524. StorehouseId: 0,
  4525. IsCheck: 1,
  4526. StockMinNumber: 0,
  4527. PatientId: patient_id,
  4528. IsSys: 1,
  4529. RecordDate: item.RecordDate,
  4530. AdviceId: item.ID,
  4531. }
  4532. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  4533. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  4534. Creator := adminInfo.AdminUser.Id
  4535. //查询默认仓库剩余多少库存
  4536. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  4537. var sum_count int64
  4538. for _, it := range list {
  4539. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  4540. if it.MaxUnit == baseDrug.MaxUnit {
  4541. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  4542. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  4543. }
  4544. sum_count += it.StockMaxNumber + it.StockMinNumber
  4545. }
  4546. flow := &models.XtSelfDrugFlow{
  4547. WarehousingId: info.ID,
  4548. DrugId: item.DrugId,
  4549. Number: "",
  4550. BatchNumber: "",
  4551. Count: total_count - in_count,
  4552. UserOrgId: adminInfo.CurrentOrgId,
  4553. PatientId: item.PatientId,
  4554. SystemTime: time.Now().Unix(),
  4555. ConsumableType: 1,
  4556. IsSys: 1,
  4557. WarehousingOrder: warehousing_order,
  4558. WarehouseOutId: 0,
  4559. WarehouseOutOrderNumber: "",
  4560. IsEdit: 0,
  4561. CancelStockId: 0,
  4562. CancelOrderNumber: "",
  4563. Manufacturer: selfBasedrug.Manufacturer,
  4564. Dealer: selfBasedrug.Dealer,
  4565. Creator: Creator,
  4566. UpdateCreator: Creator,
  4567. Status: 1,
  4568. Ctime: item.AdviceDate,
  4569. Mtime: 0,
  4570. Price: item.Price,
  4571. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  4572. WarehouseOutDetailId: 0,
  4573. CancelOutDetailId: 0,
  4574. ExpireDate: 0,
  4575. ProductDate: 0,
  4576. MaxUnit: selfBasedrug.MinUnit,
  4577. MinUnit: selfBasedrug.MinUnit,
  4578. StorehouseId: 0,
  4579. OverCount: sum_count,
  4580. OperateTime: time.Now().Unix(),
  4581. AdviceId: item.ID,
  4582. }
  4583. service.CreateSelfDrugFlow(flow, tx)
  4584. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  4585. var total_count int64 // 入库总数量
  4586. var over_count int64 //剩余库存
  4587. for _, it := range drugInfolist {
  4588. if it.MaxUnit == selfBasedrug.MaxUnit {
  4589. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  4590. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  4591. }
  4592. }
  4593. for _, it := range drugInfolist {
  4594. total_count += it.WarehousingCount
  4595. over_count += it.StockMaxNumber + it.StockMinNumber
  4596. }
  4597. //查询该仓库是否有默认数据
  4598. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  4599. if selfDrugStock.ID == 0 {
  4600. drugStock := models.XtSelfDrugStockCount{
  4601. UserOrgId: item.UserOrgId,
  4602. PatientId: item.PatientId,
  4603. SumInCount: total_count,
  4604. SumOutCount: 0,
  4605. SumCancelCount: 0,
  4606. DrugId: item.DrugId,
  4607. Ctime: time.Now().Unix(),
  4608. Mtime: 0,
  4609. Status: 1,
  4610. FlushCount: over_count,
  4611. SumActOutCount: 0,
  4612. }
  4613. service.CreateSelfDrugStockSum(drugStock, tx)
  4614. }
  4615. if selfDrugStock.ID > 0 {
  4616. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  4617. }
  4618. }
  4619. //查询这个单据的出库数量
  4620. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  4621. var his_out_count int64
  4622. for _, item := range drugFlowList {
  4623. his_out_count += item.Count
  4624. }
  4625. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  4626. if (total_count + his_out_count) <= in_count {
  4627. // 出库
  4628. if total_count < in_count {
  4629. var cha_count int64
  4630. cha_count = in_count - total_count
  4631. var stock_number int64 = 0
  4632. //查询库存是否充足
  4633. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  4634. // 将该批次的剩余库存数量转换为拆零数量
  4635. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4636. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  4637. }
  4638. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4639. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  4640. }
  4641. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4642. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  4643. }
  4644. if stock_number >= cha_count {
  4645. var maxNumber int64 = 0
  4646. var minNumber int64 = 0
  4647. maxNumber = cha_count / selfBasedrug.MinNumber
  4648. minNumber = cha_count % selfBasedrug.MinNumber
  4649. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4650. minNumber = maxNumber
  4651. }
  4652. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4653. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  4654. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4655. return
  4656. }
  4657. }
  4658. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4659. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  4660. }
  4661. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4662. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  4663. }
  4664. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4665. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  4666. }
  4667. if warehouse.StockMaxNumber < 0 {
  4668. warehouse.StockMaxNumber = 0
  4669. }
  4670. if warehouse.StockMinNumber < 0 {
  4671. warehouse.StockMinNumber = 0
  4672. }
  4673. warehouse.Mtime = time.Now().Unix()
  4674. if warehouse.StockMinNumber < minNumber {
  4675. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  4676. if warehouse.MaxUnit != warehouse.MinUnit {
  4677. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  4678. }
  4679. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  4680. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  4681. }
  4682. } else {
  4683. if minNumber > 0 {
  4684. if (warehouse.StockMinNumber - minNumber) >= 0 {
  4685. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  4686. }
  4687. }
  4688. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  4689. if warehouse.StockMinNumber > 0 {
  4690. if warehouse.StockMinNumber-cha_count >= 0 {
  4691. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  4692. }
  4693. }
  4694. }
  4695. }
  4696. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  4697. if (warehouse.StockMinNumber - cha_count) >= 0 {
  4698. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  4699. }
  4700. }
  4701. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4702. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  4703. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4704. return
  4705. }
  4706. }
  4707. if warehouse.StockMinNumber <= 0 {
  4708. warehouse.StockMinNumber = 0
  4709. }
  4710. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  4711. //查询该药品剩余库存
  4712. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  4713. var over_count int64
  4714. for _, its := range infolist {
  4715. if its.MaxUnit == selfBasedrug.MaxUnit {
  4716. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  4717. }
  4718. over_count += its.StockMaxNumber + its.StockMinNumber
  4719. }
  4720. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  4721. drugflow := models.XtSelfDrugFlow{
  4722. WarehouseOutId: 0,
  4723. WarehouseOutOrderNumber: warehousing_order,
  4724. WarehousingOrder: warehousing_order,
  4725. DrugId: item.DrugId,
  4726. Number: warehouse.Number,
  4727. ProductDate: warehouse.ProductDate,
  4728. ExpireDate: warehouse.ExpiryDate,
  4729. Count: cha_count,
  4730. Price: warehouse.RetailPrice,
  4731. Status: 1,
  4732. Ctime: item.AdviceDate,
  4733. Mtime: time.Now().Unix(),
  4734. UserOrgId: item.UserOrgId,
  4735. Manufacturer: warehouse.Manufacturer,
  4736. Dealer: warehouse.Dealer,
  4737. BatchNumber: warehouse.BatchNumber,
  4738. MaxUnit: selfBasedrug.MinUnit,
  4739. ConsumableType: 20,
  4740. IsEdit: 1,
  4741. Creator: 0,
  4742. IsSys: 3,
  4743. WarehouseOutDetailId: drugWareInfo.ID,
  4744. AdviceId: item.ID,
  4745. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  4746. StorehouseId: 0,
  4747. AdminUserId: creater,
  4748. LastPrice: warehouse.Price,
  4749. StockCount: "",
  4750. WarehousingDetailId: 0,
  4751. OverCount: over_count,
  4752. RetailPrice: item.Price, //手动出库出库价格
  4753. WarehousingId: warehouse.ID,
  4754. SystemTime: item.AdviceDate,
  4755. PatientId: item.PatientId,
  4756. Remark: "保存处方入库数据差",
  4757. OperateTime: time.Now().Unix(),
  4758. }
  4759. if warehouse.RetailPrice == 0 {
  4760. drugflow.Price = item.Price
  4761. }
  4762. service.CreateSelfDrugFlowOne(drugflow, tx)
  4763. var out_count int64
  4764. out_count = in_count - total_count
  4765. //
  4766. //fmt.Println("in_count------------------", in_count)
  4767. //fmt.Println("total_count------------------", total_count)
  4768. //添加出库数量
  4769. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  4770. //查询剩余库存
  4771. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  4772. var sum_count int64
  4773. for _, its := range stockInfo {
  4774. if its.MaxUnit == selfBasedrug.MaxUnit {
  4775. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  4776. }
  4777. sum_count += its.StockMaxNumber + its.StockMinNumber
  4778. }
  4779. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  4780. } else {
  4781. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4782. return
  4783. }
  4784. }
  4785. }
  4786. }
  4787. }
  4788. }
  4789. }
  4790. tx.Commit()
  4791. if err == nil {
  4792. c.ServeSuccessJSON(map[string]interface{}{
  4793. "msg": "保存成功",
  4794. })
  4795. return
  4796. } else {
  4797. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4798. return
  4799. }
  4800. }
  4801. }
  4802. //func (c *HisApiController) EditHisPrescription() {
  4803. // record_date := c.GetString("record_date")
  4804. // patient_id, _ := c.GetInt64("patient_id")
  4805. // reg_type, _ := c.GetInt64("reg_type")
  4806. // //diagnose, _ := c.GetInt64("diagnose", 0)
  4807. // diagnose := c.GetString("diagnose")
  4808. // sick_type, _ := c.GetInt64("sick_type")
  4809. // sick_history := c.GetString("sick_history")
  4810. // doctor_id, _ := c.GetInt64("doctor", 0)
  4811. // department, _ := c.GetInt64("department", 0)
  4812. // his_patient_id, _ := c.GetInt64("his_patient_id")
  4813. // p_type, _ := c.GetInt64("p_type")
  4814. //
  4815. // dataBody := make(map[string]interface{}, 0)
  4816. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4817. // if err != nil {
  4818. // utils.ErrorLog(err.Error())
  4819. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4820. // return
  4821. // }
  4822. //
  4823. // timeLayout := "2006-01-02"
  4824. // loc, _ := time.LoadLocation("Local")
  4825. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4826. // if err != nil {
  4827. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4828. // return
  4829. // }
  4830. // adminInfo := c.GetAdminUserInfo()
  4831. // recordDateTime := theTime.Unix()
  4832. //
  4833. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  4834. //
  4835. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4836. // var hpInfo models.HisPrescriptionInfo
  4837. // if info.ID == 0 {
  4838. // var randNum int
  4839. // randNum = rand.Intn(10000) + 1000
  4840. // timestamp := time.Now().Unix()
  4841. // tempTime := time.Unix(timestamp, 0)
  4842. // timeFormat := tempTime.Format("20060102150405")
  4843. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4844. //
  4845. // hpInfo = models.HisPrescriptionInfo{
  4846. // UserOrgId: adminInfo.CurrentOrgId,
  4847. // RecordDate: theTime.Unix(),
  4848. // PatientId: patient_id,
  4849. // Status: 1,
  4850. // Ctime: time.Now().Unix(),
  4851. // Mtime: time.Now().Unix(),
  4852. // Creator: adminInfo.AdminUser.Id,
  4853. // Modifier: adminInfo.AdminUser.Id,
  4854. // Diagnosis: diagnose,
  4855. // SickHistory: sick_history,
  4856. // Departments: department,
  4857. // RegisterType: reg_type,
  4858. // PrescriptionNumber: p_number,
  4859. // PrescriptionStatus: 1,
  4860. // Doctor: role.UserName,
  4861. // DoctorId: doctor_id,
  4862. // SickType: sick_type,
  4863. // PType: p_type,
  4864. // }
  4865. // service.SavePatientPrescriptionInfo(hpInfo)
  4866. //
  4867. // } else {
  4868. // hpInfo = models.HisPrescriptionInfo{
  4869. // ID: info.ID,
  4870. // UserOrgId: adminInfo.CurrentOrgId,
  4871. // RecordDate: info.RecordDate,
  4872. // PatientId: info.PatientId,
  4873. // Status: 1,
  4874. // Ctime: info.Ctime,
  4875. // Mtime: time.Now().Unix(),
  4876. // Creator: info.Creator,
  4877. // Modifier: adminInfo.AdminUser.Id,
  4878. // Diagnosis: diagnose,
  4879. // SickHistory: sick_history,
  4880. // Departments: department,
  4881. // RegisterType: reg_type,
  4882. // PrescriptionNumber: info.PrescriptionNumber,
  4883. // Doctor: role.UserName,
  4884. // PrescriptionStatus: info.PrescriptionStatus,
  4885. // DoctorId: doctor_id,
  4886. // SickType: sick_type,
  4887. // PType: info.PType,
  4888. // }
  4889. // service.SavePatientPrescriptionInfo(hpInfo)
  4890. // }
  4891. //
  4892. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4893. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4894. //
  4895. // if len(prescriptions) > 0 {
  4896. // for _, item := range prescriptions {
  4897. // items := item.(map[string]interface{})
  4898. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4899. // utils.ErrorLog("id")
  4900. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4901. // return
  4902. // }
  4903. // id := int64(items["id"].(float64))
  4904. //
  4905. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4906. // utils.ErrorLog("type")
  4907. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4908. // return
  4909. // }
  4910. // types := int64(items["type"].(float64))
  4911. //
  4912. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4913. // utils.ErrorLog("med_type")
  4914. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4915. // return
  4916. // }
  4917. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4918. //
  4919. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  4920. //
  4921. // ctime := time.Now().Unix()
  4922. //
  4923. // prescription := &models.HisPrescription{
  4924. // ID: id,
  4925. // PatientId: patient_id,
  4926. // UserOrgId: adminInfo.CurrentOrgId,
  4927. // RecordDate: recordDateTime,
  4928. // Ctime: ctime,
  4929. // Mtime: ctime,
  4930. // Type: types,
  4931. // Modifier: adminInfo.AdminUser.Id,
  4932. // Creator: adminInfo.AdminUser.Id,
  4933. // Status: 1,
  4934. // Doctor: role.UserName,
  4935. // HisPatientId: his_patient_id,
  4936. // OrderStatus: 1,
  4937. // BatchNumber: "",
  4938. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  4939. // PType: hpInfo.PType,
  4940. // MedType: med_type,
  4941. // }
  4942. //
  4943. // if historyPrescription.ID > 0 {
  4944. // prescription.PreTime = historyPrescription.PreTime
  4945. //
  4946. // }
  4947. //
  4948. // service.SaveHisPrescription(prescription)
  4949. //
  4950. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4951. // advices := items["advices"].([]interface{})
  4952. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4953. // groupNo := int64(0)
  4954. // ctime := time.Now().Unix()
  4955. // mtime := ctime
  4956. // if len(advices) > 0 {
  4957. // for _, advice := range advices {
  4958. // var s models.HisDoctorAdviceInfo
  4959. // s.PrescriptionId = prescription.ID
  4960. // s.AdviceType = 2
  4961. // s.AdviceDoctor = adminInfo.AdminUser.Id
  4962. // s.StopState = 2
  4963. // s.ExecutionState = 2
  4964. // s.AdviceDate = recordDateTime
  4965. // s.Status = 1
  4966. // s.UserOrgId = adminInfo.CurrentOrgId
  4967. // s.RecordDate = recordDateTime
  4968. // s.StartTime = prescription.PreTime
  4969. // s.Groupno = groupNo
  4970. // s.CreatedTime = ctime
  4971. // s.UpdatedTime = mtime
  4972. // s.PatientId = patient_id
  4973. // s.HisPatientId = his_patient_id
  4974. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  4975. // if errcode > 0 {
  4976. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4977. // return
  4978. // }
  4979. //
  4980. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4981. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4982. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4983. // if s.Price == 0 {
  4984. // s.Price = lastWarehouse.RetailPrice
  4985. // }
  4986. // }
  4987. //
  4988. // service.CreateHisDoctorAdvice(&s)
  4989. // //记录日志
  4990. // byterequest, _ := json.Marshal(s)
  4991. // adviceLog := models.XtDoctorAdviceLog{
  4992. // UserOrgId: s.UserOrgId,
  4993. // PatientId: s.PatientId,
  4994. // AdminUserId: adminInfo.AdminUser.Id,
  4995. // Module: 1,
  4996. // ErrLog: string(byterequest),
  4997. // Status: 1,
  4998. // Ctime: time.Now().Unix(),
  4999. // Mtime: 0,
  5000. // Source: "电脑端his医嘱修改",
  5001. // RecordDate: s.AdviceDate,
  5002. // }
  5003. // service.CreateDoctorAdviceLog(adviceLog)
  5004. // redis := service.RedisClient()
  5005. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5006. // redis.Set(key, "", time.Second)
  5007. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5008. // fmt.Println("keyOne", keyOne)
  5009. // redis.Set(keyOne, "", time.Second)
  5010. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5011. // redis.Set(keySeven, "", time.Second)
  5012. // redis.Close()
  5013. //
  5014. // }
  5015. // }
  5016. // }
  5017. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5018. // projects := items["project"].([]interface{})
  5019. // if len(projects) > 0 {
  5020. // for _, project := range projects {
  5021. // var p models.HisPrescriptionProject
  5022. // p.PrescriptionId = prescription.ID
  5023. // p.Ctime = time.Now().Unix()
  5024. // p.Mtime = time.Now().Unix()
  5025. // p.PatientId = patient_id
  5026. // p.RecordDate = recordDateTime
  5027. // p.UserOrgId = adminInfo.CurrentOrgId
  5028. // p.HisPatientId = his_patient_id
  5029. // p.Status = 1
  5030. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  5031. // if errcode > 0 {
  5032. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5033. // return
  5034. // }
  5035. // service.CreateHisProjectTwo(&p)
  5036. //
  5037. // //记录日志
  5038. // byterequest, _ := json.Marshal(p)
  5039. // adviceLog := models.XtDoctorAdviceLog{
  5040. // UserOrgId: p.UserOrgId,
  5041. // PatientId: p.PatientId,
  5042. // AdminUserId: adminInfo.AdminUser.Id,
  5043. // Module: 1,
  5044. // ErrLog: string(byterequest),
  5045. // Status: 1,
  5046. // Ctime: time.Now().Unix(),
  5047. // Mtime: 0,
  5048. // Source: "电脑端his项目修改",
  5049. // RecordDate: p.RecordDate,
  5050. // }
  5051. // service.CreateDoctorAdviceLog(adviceLog)
  5052. // }
  5053. // }
  5054. // }
  5055. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  5056. // addition := items["addition"].([]interface{})
  5057. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5058. // ctime := time.Now().Unix()
  5059. // mtime := ctime
  5060. // if len(addition) > 0 {
  5061. // for _, item := range addition {
  5062. // var s models.HisAdditionalCharge
  5063. // s.PrescriptionId = prescription.ID
  5064. // s.Status = 1
  5065. // s.UserOrgId = adminInfo.CurrentOrgId
  5066. // s.RecordDate = recordDateTime
  5067. // s.CreatedTime = ctime
  5068. // s.UpdatedTime = mtime
  5069. // s.PatientId = patient_id
  5070. // s.HisPatientId = his_patient_id
  5071. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5072. // if errcode > 0 {
  5073. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5074. // return
  5075. // }
  5076. // service.CreateAdditionalCharge(&s)
  5077. // }
  5078. // }
  5079. // }
  5080. //
  5081. // }
  5082. // }
  5083. // }
  5084. // if err == nil {
  5085. // c.ServeSuccessJSON(map[string]interface{}{
  5086. // "msg": "保存成功",
  5087. // })
  5088. // return
  5089. //
  5090. // } else {
  5091. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5092. // return
  5093. // }
  5094. //}
  5095. func (c *HisApiController) DeletePrescription() {
  5096. prescription_id, _ := c.GetInt64("id")
  5097. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  5098. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  5099. ////同步到自备药
  5100. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  5101. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  5102. if selfPrescriptionOpen.IsOpen == 1 {
  5103. // 在函数结束时处理事务回滚
  5104. db := service.XTWriteDB()
  5105. tx := db.Begin()
  5106. defer func() {
  5107. if r := recover(); r != nil {
  5108. tx.Rollback()
  5109. } else {
  5110. tx.Commit()
  5111. }
  5112. }()
  5113. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  5114. for _, item := range advicesList {
  5115. timeStr := time.Now().Format("2006-01-02")
  5116. timeArr := strings.Split(timeStr, "-")
  5117. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5118. total = total + 1
  5119. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5120. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5121. number = number + total
  5122. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5123. operation_time := time.Now().Unix()
  5124. creater := c.GetAdminUserInfo().AdminUser.Id
  5125. //创建一个出库单
  5126. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5127. WarehouseOutOrderNumber: warehousing_out_order,
  5128. OperationTime: operation_time,
  5129. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5130. Creater: creater,
  5131. Ctime: time.Now().Unix(),
  5132. Status: 1,
  5133. WarehouseOutTime: item.AdviceDate,
  5134. Type: 0,
  5135. PatientId: item.PatientId,
  5136. IsCheck: 1,
  5137. }
  5138. //查询今日是否有出库数据
  5139. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  5140. fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
  5141. if lastWarehouseOut.ID == 0 {
  5142. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5143. }
  5144. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5145. var total_count int64
  5146. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5147. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5148. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5149. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5150. }
  5151. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5152. total_count += prescribingNumberSeven
  5153. }
  5154. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5155. total_count += prescribingNumberSeven
  5156. }
  5157. //出库
  5158. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5159. WarehouseOutOrderNumber: warehousing_out_order,
  5160. WarehouseOutId: lastWarehouseOut.ID,
  5161. DrugId: item.DrugId,
  5162. Count: total_count,
  5163. Price: 0,
  5164. TotalPrice: 0,
  5165. Status: 1,
  5166. Ctime: item.AdviceDate,
  5167. Mtime: item.AdviceDate,
  5168. Remark: "",
  5169. OrgId: item.UserOrgId,
  5170. Type: 0,
  5171. Manufacturer: selfBasedrug.Manufacturer,
  5172. Dealer: selfBasedrug.Dealer,
  5173. RetailPrice: 0,
  5174. RetailTotalPrice: 0,
  5175. CountUnit: selfBasedrug.MinUnit,
  5176. ExpiryDate: 0,
  5177. ProductDate: 0,
  5178. Number: "",
  5179. BatchNumber: "",
  5180. IsSys: 1,
  5181. WarehouseInfoId: 0,
  5182. AdminUserId: 0,
  5183. StockCount: "",
  5184. IsCheck: 1,
  5185. SysRecordTime: item.AdviceDate,
  5186. PatientId: item.PatientId,
  5187. ClassType: "",
  5188. AdviceId: item.ID,
  5189. }
  5190. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5191. }
  5192. fmt.Println("长度-------------------------------", warehousingOutInfo)
  5193. for _, it := range warehousingOutInfo {
  5194. //查询今日是否有出库数据
  5195. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  5196. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5197. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5198. //出库逻辑
  5199. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  5200. //查询剩余库存
  5201. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5202. var sum_count int64
  5203. for _, its := range stockInfo {
  5204. if its.MaxUnit == medical.MaxUnit {
  5205. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5206. }
  5207. sum_count += its.StockMaxNumber + its.StockMinNumber
  5208. }
  5209. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5210. }
  5211. }
  5212. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5213. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5214. //耗材保存处方出库
  5215. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5216. //已收费和已发药限制逻辑
  5217. isCharge := false
  5218. isMedicine := false
  5219. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5220. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5221. if new_prescription.IsMedicine == 1 {
  5222. isMedicine = true
  5223. }
  5224. for _, item := range new_prescriptions {
  5225. if item.OrderStatus == 4 {
  5226. isCharge = true
  5227. }
  5228. }
  5229. if p_err != nil {
  5230. if new_prescription.ID > 0 {
  5231. if new_prescription.OrderStatus == 2 {
  5232. isCharge = true
  5233. }
  5234. }
  5235. }
  5236. for _, item := range advices {
  5237. if item.IsMedicine == 1 {
  5238. isMedicine = true
  5239. }
  5240. }
  5241. if isCharge {
  5242. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5243. return
  5244. }
  5245. if isMedicine {
  5246. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5247. return
  5248. }
  5249. //已收费和已发药限制逻辑
  5250. if len(projects) > 0 {
  5251. for _, item := range projects {
  5252. service.DeletePrintInfo(item.ID) //删除打印信息
  5253. if goodOutConfig.IsOpen != 1 {
  5254. if stockConfig.IsOpen == 1 {
  5255. if item.Type == 3 && item.IsOut == 1 {
  5256. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5257. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5258. good.Total = good.Total + f_count
  5259. service.UpdateGoodInfo(&good)
  5260. operation_time := time.Now().Unix()
  5261. creater := c.GetAdminUserInfo().AdminUser.Id
  5262. //创建退库单
  5263. timeStr := time.Now().Format("2006-01-02")
  5264. timeArr := strings.Split(timeStr, "-")
  5265. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5266. total = total + 1
  5267. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5268. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5269. cancelStock := models.CancelStock{
  5270. OrderNumber: orderNumber,
  5271. OperaTime: operation_time,
  5272. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5273. Creater: creater,
  5274. Ctime: time.Now().Unix(),
  5275. Status: 1,
  5276. ReturnTime: item.RecordDate,
  5277. Type: 1,
  5278. StorehouseId: houseConfig.StorehouseOutInfo,
  5279. IsCheck: 1,
  5280. }
  5281. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5282. if msgerrkonde == gorm.ErrRecordNotFound {
  5283. service.AddSigleCancelStock(&cancelStock)
  5284. }
  5285. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5286. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5287. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5288. //查询该耗材是否出库
  5289. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5290. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5291. deaerler, _ := service.GetDealerById(info.Dealer)
  5292. var total_count int64
  5293. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5294. total_count += count
  5295. if info.ID > 0 {
  5296. if info.Count >= total_count {
  5297. //回退库存
  5298. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5299. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5300. var flush_count int64
  5301. for _, it := range goodList {
  5302. flush_count += it.StockCount
  5303. }
  5304. cancelStockInfo := models.CancelStockInfo{
  5305. GoodId: item.ProjectId,
  5306. CancelStockId: cancel.ID,
  5307. GoodTypeId: good.GoodTypeId,
  5308. Count: prescribingNumber,
  5309. Price: info.Price,
  5310. Total: 0,
  5311. ProductDate: info.ProductDate,
  5312. ExpiryDate: info.ExpiryDate,
  5313. Ctime: time.Now().Unix(),
  5314. Status: 1,
  5315. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5316. OrderNumber: cancel.OrderNumber,
  5317. Type: 0,
  5318. Dealer: deaerler.DealerName,
  5319. Manufacturer: manufacturer.ManufacturerName,
  5320. Number: info.Number,
  5321. RegisterAccount: "",
  5322. Remark: "",
  5323. WarehouseInfoId: info.WarehouseInfotId,
  5324. PatientId: info.PatientId,
  5325. RecordDate: info.SysRecordTime,
  5326. StorehouseId: houseConfig.StorehouseOutInfo,
  5327. IsCheck: 1,
  5328. }
  5329. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5330. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5331. flow := models.VmStockFlow{
  5332. WarehousingId: info.WarehouseInfotId,
  5333. GoodId: item.ProjectId,
  5334. Number: info.Number,
  5335. LicenseNumber: info.LicenseNumber,
  5336. Count: prescribingNumber,
  5337. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5338. PatientId: item.PatientId,
  5339. SystemTime: info.SysRecordTime,
  5340. ConsumableType: 7,
  5341. IsSys: 0,
  5342. WarehousingOrder: "",
  5343. WarehouseOutId: info.WarehouseOutId,
  5344. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5345. IsEdit: 0,
  5346. CancelStockId: cancel.ID,
  5347. CancelOrderNumber: cancel.OrderNumber,
  5348. Manufacturer: manufacturer.ID,
  5349. Dealer: 0,
  5350. Creator: c.GetAdminUserInfo().CurrentOrgId,
  5351. UpdateCreator: 0,
  5352. Status: 1,
  5353. Ctime: time.Now().Unix(),
  5354. Mtime: 0,
  5355. Price: info.Price,
  5356. WarehousingDetailId: info.WarehouseInfotId,
  5357. WarehouseOutDetailId: info.ID,
  5358. CancelOutDetailId: cancelInfo.ID,
  5359. ProductDate: info.ProductDate,
  5360. ExpireDate: info.ExpiryDate,
  5361. StorehouseId: houseConfig.StorehouseOutInfo,
  5362. OverCount: flush_count,
  5363. OperateTime: time.Now().Unix(),
  5364. }
  5365. service.CreateStockFlowOne(flow)
  5366. //退库数量增加
  5367. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  5368. //出库数量减少
  5369. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  5370. }
  5371. if info.Count < total_count {
  5372. //回退库存
  5373. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5374. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5375. var flush_count int64
  5376. for _, it := range goodList {
  5377. flush_count += it.StockCount
  5378. }
  5379. cancelStockInfo := models.CancelStockInfo{
  5380. GoodId: item.ProjectId,
  5381. CancelStockId: cancel.ID,
  5382. GoodTypeId: good.GoodTypeId,
  5383. Count: info.Count,
  5384. Price: info.Price,
  5385. Total: 0,
  5386. ProductDate: info.ProductDate,
  5387. ExpiryDate: info.ExpiryDate,
  5388. Ctime: time.Now().Unix(),
  5389. Status: 1,
  5390. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5391. OrderNumber: cancel.OrderNumber,
  5392. Type: 0,
  5393. Dealer: deaerler.DealerName,
  5394. Manufacturer: manufacturer.ManufacturerName,
  5395. Number: info.Number,
  5396. RegisterAccount: "",
  5397. Remark: "",
  5398. WarehouseInfoId: info.WarehouseInfotId,
  5399. PatientId: info.PatientId,
  5400. RecordDate: info.SysRecordTime,
  5401. StorehouseId: houseConfig.StorehouseOutInfo,
  5402. IsCheck: 1,
  5403. }
  5404. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5405. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5406. flow := models.VmStockFlow{
  5407. WarehousingId: info.WarehouseInfotId,
  5408. GoodId: item.ProjectId,
  5409. Number: info.Number,
  5410. LicenseNumber: info.LicenseNumber,
  5411. Count: info.Count,
  5412. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5413. PatientId: item.PatientId,
  5414. SystemTime: info.SysRecordTime,
  5415. ConsumableType: 7,
  5416. IsSys: 0,
  5417. WarehousingOrder: "",
  5418. WarehouseOutId: info.WarehouseOutId,
  5419. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5420. IsEdit: 0,
  5421. CancelStockId: cancel.ID,
  5422. CancelOrderNumber: cancel.OrderNumber,
  5423. Manufacturer: manufacturer.ID,
  5424. Dealer: 0,
  5425. Creator: c.GetAdminUserInfo().CurrentOrgId,
  5426. UpdateCreator: 0,
  5427. Status: 1,
  5428. Ctime: time.Now().Unix(),
  5429. Mtime: 0,
  5430. Price: info.Price,
  5431. WarehousingDetailId: info.WarehouseInfotId,
  5432. WarehouseOutDetailId: info.ID,
  5433. CancelOutDetailId: cancelInfo.ID,
  5434. ProductDate: info.ProductDate,
  5435. ExpireDate: info.ExpiryDate,
  5436. StorehouseId: houseConfig.StorehouseOutInfo,
  5437. OverCount: flush_count,
  5438. OperateTime: time.Now().Unix(),
  5439. }
  5440. service.CreateStockFlowOne(flow)
  5441. //退库数量增加
  5442. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  5443. //出库数量减少
  5444. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  5445. }
  5446. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5447. var flush_count int64
  5448. for _, it := range goodList {
  5449. flush_count += it.StockCount
  5450. }
  5451. //查询已出库数量
  5452. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  5453. if prescribingNumber < dialysisInfo.Count {
  5454. //改变数量
  5455. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  5456. }
  5457. if prescribingNumber >= dialysisInfo.Count {
  5458. //删除出库表
  5459. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  5460. }
  5461. //更新库存
  5462. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  5463. //更新基础库库存
  5464. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  5465. }
  5466. }
  5467. }
  5468. }
  5469. //保存耗材出库
  5470. if goodOutConfig.IsOpen == 1 {
  5471. if item.Type == 3 {
  5472. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5473. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5474. good.Total = good.Total + f_count
  5475. service.UpdateGoodInfo(&good)
  5476. operation_time := time.Now().Unix()
  5477. creater := c.GetAdminUserInfo().AdminUser.Id
  5478. //创建退库单
  5479. timeStr := time.Now().Format("2006-01-02")
  5480. timeArr := strings.Split(timeStr, "-")
  5481. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5482. total = total + 1
  5483. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5484. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5485. cancelStock := models.CancelStock{
  5486. OrderNumber: orderNumber,
  5487. OperaTime: operation_time,
  5488. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5489. Creater: creater,
  5490. Ctime: time.Now().Unix(),
  5491. Status: 1,
  5492. ReturnTime: item.RecordDate,
  5493. Type: 1,
  5494. StorehouseId: houseConfig.StorehouseOutInfo,
  5495. IsCheck: 1,
  5496. }
  5497. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5498. if msgerrkonde == gorm.ErrRecordNotFound {
  5499. service.AddSigleCancelStock(&cancelStock)
  5500. }
  5501. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5502. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5503. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5504. //查询该耗材是否出库
  5505. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5506. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5507. deaerler, _ := service.GetDealerById(info.Dealer)
  5508. var total_count int64
  5509. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5510. total_count += count
  5511. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5512. var flush_count int64
  5513. for _, it := range goodList {
  5514. flush_count += it.StockCount
  5515. }
  5516. fmt.Println("历史出库数据", info.Count)
  5517. fmt.Println("出库数量", total_count)
  5518. if info.ID > 0 {
  5519. cancelStockInfo := models.CancelStockInfo{
  5520. GoodId: item.ProjectId,
  5521. CancelStockId: cancel.ID,
  5522. GoodTypeId: good.GoodTypeId,
  5523. Count: prescribingNumber,
  5524. Price: info.Price,
  5525. Total: 0,
  5526. ProductDate: info.ProductDate,
  5527. ExpiryDate: info.ExpiryDate,
  5528. Ctime: time.Now().Unix(),
  5529. Status: 1,
  5530. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5531. OrderNumber: cancel.OrderNumber,
  5532. Type: 0,
  5533. Dealer: deaerler.DealerName,
  5534. Manufacturer: manufacturer.ManufacturerName,
  5535. Number: info.Number,
  5536. RegisterAccount: "",
  5537. Remark: "",
  5538. WarehouseInfoId: info.WarehouseInfotId,
  5539. PatientId: info.PatientId,
  5540. RecordDate: info.SysRecordTime,
  5541. StorehouseId: houseConfig.StorehouseOutInfo,
  5542. IsCheck: 1,
  5543. }
  5544. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5545. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5546. //查询出库数量
  5547. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  5548. //出库数据 大于 退库数量
  5549. if len(list) > 0 {
  5550. for _, it := range list {
  5551. //回退库存
  5552. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  5553. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5554. var flush_count_one int64
  5555. for _, it := range goodList {
  5556. flush_count_one += it.StockCount
  5557. }
  5558. //查询该批次是否有退库数据
  5559. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  5560. creater := c.GetAdminUserInfo().AdminUser.Id
  5561. flow := models.VmStockFlow{
  5562. WarehousingId: it.WarehouseInfotId,
  5563. GoodId: it.GoodId,
  5564. Number: it.Number,
  5565. LicenseNumber: it.LicenseNumber,
  5566. Count: it.Count,
  5567. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5568. PatientId: it.PatientId,
  5569. SystemTime: it.SysRecordTime,
  5570. ConsumableType: 7,
  5571. IsSys: 0,
  5572. WarehousingOrder: "",
  5573. WarehouseOutId: it.WarehouseOutId,
  5574. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  5575. IsEdit: 0,
  5576. CancelStockId: cancel.ID,
  5577. CancelOrderNumber: cancel.OrderNumber,
  5578. Manufacturer: manufacturer.ID,
  5579. Dealer: 0,
  5580. Creator: creater,
  5581. UpdateCreator: 0,
  5582. Status: 1,
  5583. Ctime: time.Now().Unix(),
  5584. Mtime: 0,
  5585. Price: it.Price,
  5586. WarehousingDetailId: it.WarehouseInfotId,
  5587. WarehouseOutDetailId: it.ID,
  5588. CancelOutDetailId: cancelInfo.ID,
  5589. ProductDate: it.ProductDate,
  5590. ExpireDate: it.ExpiryDate,
  5591. StorehouseId: houseConfig.StorehouseOutInfo,
  5592. OverCount: flush_count_one,
  5593. }
  5594. service.CreateStockFlowOne(flow)
  5595. //if flow.ID > 0 {
  5596. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  5597. //}
  5598. }
  5599. }
  5600. //flow := models.VmStockFlow{
  5601. // WarehousingId: info.WarehouseInfotId,
  5602. // GoodId: item.ProjectId,
  5603. // Number: info.Number,
  5604. // LicenseNumber: info.LicenseNumber,
  5605. // Count: prescribingNumber,
  5606. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5607. // PatientId: item.PatientId,
  5608. // SystemTime: info.SysRecordTime,
  5609. // ConsumableType: 7,
  5610. // IsSys: 0,
  5611. // WarehousingOrder: "",
  5612. // WarehouseOutId: info.WarehouseOutId,
  5613. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5614. // IsEdit: 0,
  5615. // CancelStockId: cancel.ID,
  5616. // CancelOrderNumber: cancel.OrderNumber,
  5617. // Manufacturer: manufacturer.ID,
  5618. // Dealer: 0,
  5619. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  5620. // UpdateCreator: 0,
  5621. // Status: 1,
  5622. // Ctime: time.Now().Unix(),
  5623. // Mtime: 0,
  5624. // Price: info.Price,
  5625. // WarehousingDetailId: info.WarehouseInfotId,
  5626. // WarehouseOutDetailId: info.ID,
  5627. // CancelOutDetailId: cancelInfo.ID,
  5628. // ProductDate: info.ProductDate,
  5629. // ExpireDate: info.ExpiryDate,
  5630. // StorehouseId: houseConfig.StorehouseOutInfo,
  5631. // OverCount: flush_count,
  5632. //}
  5633. //service.CreateStockFlowOne(flow)
  5634. //退库数量增加
  5635. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  5636. //出库数量减少
  5637. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  5638. //查询已出库数量
  5639. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  5640. if prescribingNumber < dialysisInfo.Count {
  5641. //改变数量
  5642. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  5643. }
  5644. if prescribingNumber >= dialysisInfo.Count {
  5645. //删除出库表
  5646. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  5647. }
  5648. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5649. var flush_count_one int64
  5650. for _, it := range goodList {
  5651. flush_count_one += it.StockCount
  5652. }
  5653. //更新库存
  5654. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  5655. fmt.Println("msgerrkonde23332323", msgerrkonde)
  5656. //更新基础库库存
  5657. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  5658. }
  5659. }
  5660. }
  5661. }
  5662. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5663. fmt.Println(err)
  5664. }
  5665. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5666. fmt.Println(err)
  5667. if len(advices) > 0 {
  5668. for _, item := range advices {
  5669. redis := service.RedisClient()
  5670. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5671. redis.Set(keyFive, "", time.Second)
  5672. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5673. redis.Set(keyOne, "", time.Second)
  5674. redis.Close()
  5675. }
  5676. }
  5677. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5678. if len(advices) > 0 {
  5679. for _, item := range advices {
  5680. creater := c.GetAdminUserInfo().AdminUser.Id
  5681. service.DrugAutoAddCancelInfo(item, creater)
  5682. }
  5683. }
  5684. } else {
  5685. if drugOutConfig.IsOpen == 1 {
  5686. if len(advices) > 0 {
  5687. for _, item := range advices {
  5688. creater := c.GetAdminUserInfo().AdminUser.Id
  5689. service.DrugAutoAddCancelInfo(item, creater)
  5690. }
  5691. }
  5692. } else {
  5693. if len(advices) > 0 {
  5694. for _, item := range advices {
  5695. creater := c.GetAdminUserInfo().AdminUser.Id
  5696. service.DrugAutoAddCancelInfo(item, creater)
  5697. }
  5698. }
  5699. }
  5700. }
  5701. c.ServeSuccessJSON(map[string]interface{}{
  5702. "msg": "删除成功",
  5703. })
  5704. return
  5705. }
  5706. func (c *HisApiController) DeleteDoctorAdvice() {
  5707. id, _ := c.GetInt64("id")
  5708. advice, _ := service.GetHisDoctorAdvicesById(id)
  5709. ////同步到自备药
  5710. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  5711. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  5712. if selfPrescriptionOpen.IsOpen == 1 {
  5713. db := service.XTWriteDB()
  5714. tx := db.Begin()
  5715. defer func() {
  5716. if r := recover(); r != nil {
  5717. tx.Rollback()
  5718. } else {
  5719. tx.Commit()
  5720. }
  5721. }()
  5722. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  5723. var total_count int64
  5724. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  5725. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5726. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5727. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5728. }
  5729. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5730. total_count += prescribingNumberSeven
  5731. }
  5732. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5733. total_count += prescribingNumberSeven
  5734. }
  5735. timeStr := time.Now().Format("2006-01-02")
  5736. timeArr := strings.Split(timeStr, "-")
  5737. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5738. total = total + 1
  5739. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5740. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5741. number = number + total
  5742. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5743. operation_time := time.Now().Unix()
  5744. creater := c.GetAdminUserInfo().AdminUser.Id
  5745. //创建一个出库单
  5746. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5747. WarehouseOutOrderNumber: warehousing_out_order,
  5748. OperationTime: operation_time,
  5749. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5750. Creater: creater,
  5751. Ctime: time.Now().Unix(),
  5752. Status: 1,
  5753. WarehouseOutTime: advice.AdviceDate,
  5754. Type: 0,
  5755. PatientId: advice.PatientId,
  5756. IsCheck: 1,
  5757. }
  5758. //查询今日是否有出库数据
  5759. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  5760. if lastWarehouseOut.ID == 0 {
  5761. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5762. }
  5763. //出库
  5764. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5765. WarehouseOutId: lastWarehouseOut.ID,
  5766. WarehouseOutOrderNumber: warehousing_out_order,
  5767. DrugId: advice.DrugId,
  5768. Count: total_count,
  5769. Price: 0,
  5770. TotalPrice: 0,
  5771. Status: 1,
  5772. Ctime: advice.AdviceDate,
  5773. Mtime: advice.AdviceDate,
  5774. Remark: "",
  5775. OrgId: advice.UserOrgId,
  5776. Type: 0,
  5777. Manufacturer: selfBasedrug.Manufacturer,
  5778. Dealer: selfBasedrug.Dealer,
  5779. RetailPrice: 0,
  5780. RetailTotalPrice: 0,
  5781. CountUnit: advice.PrescribingNumberUnit,
  5782. ExpiryDate: 0,
  5783. ProductDate: 0,
  5784. Number: "",
  5785. BatchNumber: "",
  5786. IsSys: 0,
  5787. WarehouseInfoId: 0,
  5788. AdminUserId: 0,
  5789. StockCount: "",
  5790. IsCheck: 1,
  5791. SysRecordTime: advice.AdviceDate,
  5792. PatientId: advice.PatientId,
  5793. AdviceId: advice.ID,
  5794. ClassType: "",
  5795. }
  5796. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5797. for _, it := range warehousingOutInfo {
  5798. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5799. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5800. //出库逻辑
  5801. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  5802. //查询剩余库存
  5803. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5804. var sum_count int64
  5805. for _, its := range stockInfo {
  5806. if its.MaxUnit == medical.MaxUnit {
  5807. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5808. }
  5809. sum_count += its.StockMaxNumber + its.StockMinNumber
  5810. }
  5811. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5812. }
  5813. }
  5814. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5815. //已收费和已发药的限制逻辑
  5816. isCharge := false
  5817. isMedicine := false
  5818. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5819. //获取今天该患者所有处方,判断是否发药或者收费
  5820. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5821. //for _, item := range new_prescriptions {
  5822. if new_prescription.IsMedicine == 1 {
  5823. isMedicine = true
  5824. }
  5825. //}
  5826. for _, item := range new_prescriptions {
  5827. if item.OrderStatus == 4 {
  5828. isCharge = true
  5829. }
  5830. }
  5831. if isMedicine {
  5832. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5833. return
  5834. }
  5835. if isCharge {
  5836. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5837. return
  5838. }
  5839. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  5840. for _, item := range advices {
  5841. if item.IsMedicine == 1 {
  5842. isMedicine = true
  5843. }
  5844. }
  5845. if isMedicine {
  5846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  5847. return
  5848. }
  5849. if new_prescription.ID > 0 {
  5850. if new_prescription.OrderStatus == 2 {
  5851. isCharge = true
  5852. }
  5853. }
  5854. if isCharge {
  5855. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5856. return
  5857. }
  5858. //已收费和已发药的限制逻辑
  5859. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  5860. redis := service.RedisClient()
  5861. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  5862. redis.Set(keyFive, "", time.Second)
  5863. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  5864. redis.Set(keyOne, "", time.Second)
  5865. defer redis.Close()
  5866. if err == nil {
  5867. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5868. //查询是否在处方中出库
  5869. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5870. if openConfig.IsOpen != 1 {
  5871. //判断该医嘱是否执行了
  5872. if advice.ExecutionState == 1 {
  5873. creater := c.GetAdminUserInfo().AdminUser.Id
  5874. service.DrugAutoAddCancelInfo(&advice, creater)
  5875. }
  5876. }
  5877. //开启保存处方扣减功能
  5878. if openConfig.IsOpen == 1 {
  5879. creater := c.GetAdminUserInfo().AdminUser.Id
  5880. service.DrugAutoAddCancelInfo(&advice, creater)
  5881. }
  5882. } else {
  5883. if drugOutConfig.IsOpen == 1 {
  5884. //查询是否在处方中出库
  5885. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5886. if openConfig.IsOpen != 1 {
  5887. //判断该医嘱是否执行了
  5888. if advice.ExecutionState == 1 {
  5889. creater := c.GetAdminUserInfo().AdminUser.Id
  5890. service.DrugAutoAddCancelInfo(&advice, creater)
  5891. }
  5892. }
  5893. //开启保存处方扣减功能
  5894. if openConfig.IsOpen == 1 {
  5895. creater := c.GetAdminUserInfo().AdminUser.Id
  5896. service.DrugAutoAddCancelInfo(&advice, creater)
  5897. }
  5898. } else {
  5899. //判断该医嘱是否执行了
  5900. if advice.ExecutionState == 1 {
  5901. creater := c.GetAdminUserInfo().AdminUser.Id
  5902. service.DrugAutoAddCancelInfo(&advice, creater)
  5903. }
  5904. }
  5905. }
  5906. c.ServeSuccessJSON(map[string]interface{}{
  5907. "msg": "删除成功",
  5908. })
  5909. return
  5910. } else {
  5911. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5912. return
  5913. }
  5914. }
  5915. func (c *HisApiController) DeleteProject() {
  5916. id, _ := c.GetInt64("id")
  5917. adminInfo := c.GetAdminUserInfo()
  5918. project, _ := service.GetHisProjectByID(id)
  5919. // var consumable models.DialysisBeforePrepare
  5920. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5921. //耗材保存处方出库
  5922. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5923. isCharge := false
  5924. isMedicine := false
  5925. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5926. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5927. for _, item := range new_prescriptions {
  5928. if item.IsMedicine == 1 {
  5929. isMedicine = true
  5930. }
  5931. }
  5932. for _, item := range new_prescriptions {
  5933. if item.OrderStatus == 4 {
  5934. isCharge = true
  5935. }
  5936. }
  5937. if isMedicine {
  5938. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5939. return
  5940. }
  5941. if isCharge {
  5942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5943. return
  5944. }
  5945. if new_prescription.ID > 0 {
  5946. if new_prescription.OrderStatus == 2 {
  5947. isCharge = true
  5948. }
  5949. }
  5950. if isCharge {
  5951. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5952. return
  5953. }
  5954. service.DeletePrintInfo(id)
  5955. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  5956. label.Status = 0
  5957. service.CreateHisLabelRecordTwo(&label)
  5958. fmt.Println(goodOutConfig.IsOpen)
  5959. if goodOutConfig.IsOpen != 1 {
  5960. if stockConfig.IsOpen == 1 {
  5961. if project.Type == 2 {
  5962. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5963. fmt.Println(err)
  5964. }
  5965. if project.Type == 3 && project.IsOut == 1 {
  5966. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5967. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5968. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5969. operation_time := time.Now().Unix()
  5970. creater := adminInfo.AdminUser.Id
  5971. //创建退库单
  5972. timeStr := time.Now().Format("2006-01-02")
  5973. timeArr := strings.Split(timeStr, "-")
  5974. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5975. total = total + 1
  5976. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5977. cancelStock := models.CancelStock{
  5978. OrderNumber: orderNumber,
  5979. OperaTime: operation_time,
  5980. OrgId: adminInfo.CurrentOrgId,
  5981. Creater: creater,
  5982. Ctime: time.Now().Unix(),
  5983. Status: 1,
  5984. ReturnTime: project.RecordDate,
  5985. Type: 1,
  5986. StorehouseId: houseConfig.StorehouseOutInfo,
  5987. IsCheck: 1,
  5988. }
  5989. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5990. if msgerrkonde == gorm.ErrRecordNotFound {
  5991. service.AddSigleCancelStock(&cancelStock)
  5992. }
  5993. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5994. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5995. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5996. //查询是否有出库
  5997. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5998. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5999. deaerler, _ := service.GetDealerById(info.Dealer)
  6000. if info.ID > 0 {
  6001. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6002. if info.Count >= prescribingNumber {
  6003. cancelStockInfo := models.CancelStockInfo{
  6004. GoodId: project.ProjectId,
  6005. CancelStockId: cancel.ID,
  6006. GoodTypeId: good.GoodTypeId,
  6007. Count: prescribingNumber,
  6008. Price: info.Price,
  6009. Total: 0,
  6010. ProductDate: info.ProductDate,
  6011. ExpiryDate: info.ExpiryDate,
  6012. Ctime: time.Now().Unix(),
  6013. Status: 1,
  6014. OrgId: adminInfo.CurrentOrgId,
  6015. OrderNumber: cancel.OrderNumber,
  6016. Type: 0,
  6017. Dealer: deaerler.DealerName,
  6018. Manufacturer: manufacturer.ManufacturerName,
  6019. Number: info.Number,
  6020. RegisterAccount: "",
  6021. Remark: "",
  6022. WarehouseInfoId: info.WarehouseInfotId,
  6023. PatientId: info.PatientId,
  6024. RecordDate: info.SysRecordTime,
  6025. StorehouseId: houseConfig.StorehouseOutInfo,
  6026. IsCheck: 1,
  6027. }
  6028. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6029. //回退库存
  6030. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  6031. //退库数量增加
  6032. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6033. //出库数量减少
  6034. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6035. }
  6036. if info.Count < prescribingNumber {
  6037. cancelStockInfo := models.CancelStockInfo{
  6038. GoodId: project.ProjectId,
  6039. CancelStockId: cancel.ID,
  6040. GoodTypeId: good.GoodTypeId,
  6041. Count: info.Count,
  6042. Price: info.Price,
  6043. Total: 0,
  6044. ProductDate: info.ProductDate,
  6045. ExpiryDate: info.ExpiryDate,
  6046. Ctime: time.Now().Unix(),
  6047. Status: 1,
  6048. OrgId: adminInfo.CurrentOrgId,
  6049. OrderNumber: cancel.OrderNumber,
  6050. Type: 0,
  6051. Dealer: deaerler.DealerName,
  6052. Manufacturer: manufacturer.ManufacturerName,
  6053. Number: info.Number,
  6054. RegisterAccount: "",
  6055. Remark: "",
  6056. WarehouseInfoId: info.WarehouseInfotId,
  6057. PatientId: info.PatientId,
  6058. RecordDate: info.SysRecordTime,
  6059. StorehouseId: houseConfig.StorehouseOutInfo,
  6060. IsCheck: 1,
  6061. }
  6062. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6063. //回退库存
  6064. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6065. //退库数量增加
  6066. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6067. //出库数量减少
  6068. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  6069. }
  6070. //查询剩余库存
  6071. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6072. var over_count int64
  6073. for _, it := range goodList {
  6074. over_count += it.StockCount
  6075. }
  6076. //出库数据 大于 退库数量
  6077. if info.Count >= prescribingNumber {
  6078. flow := models.VmStockFlow{
  6079. WarehousingId: info.WarehouseInfotId,
  6080. GoodId: project.ProjectId,
  6081. Number: info.Number,
  6082. LicenseNumber: info.LicenseNumber,
  6083. Count: prescribingNumber,
  6084. UserOrgId: adminInfo.CurrentOrgId,
  6085. PatientId: project.PatientId,
  6086. SystemTime: info.SysRecordTime,
  6087. ConsumableType: 7,
  6088. IsSys: 0,
  6089. WarehousingOrder: "",
  6090. WarehouseOutId: info.WarehouseOutId,
  6091. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6092. IsEdit: 0,
  6093. CancelStockId: cancel.ID,
  6094. CancelOrderNumber: cancel.OrderNumber,
  6095. Manufacturer: manufacturer.ID,
  6096. Dealer: 0,
  6097. Creator: adminInfo.AdminUser.Id,
  6098. UpdateCreator: 0,
  6099. Status: 1,
  6100. Ctime: time.Now().Unix(),
  6101. Mtime: 0,
  6102. Price: info.Price,
  6103. WarehousingDetailId: info.WarehouseInfotId,
  6104. WarehouseOutDetailId: info.ID,
  6105. CancelOutDetailId: cancelInfo.ID,
  6106. ProductDate: info.ProductDate,
  6107. ExpireDate: info.ExpiryDate,
  6108. StorehouseId: houseConfig.StorehouseOutInfo,
  6109. OverCount: over_count,
  6110. OperateTime: time.Now().Unix(),
  6111. }
  6112. service.CreateStockFlowOne(flow)
  6113. }
  6114. //出库数据小于退库数据
  6115. if info.Count < prescribingNumber {
  6116. flow := models.VmStockFlow{
  6117. WarehousingId: info.WarehouseInfotId,
  6118. GoodId: project.ProjectId,
  6119. Number: info.Number,
  6120. LicenseNumber: info.LicenseNumber,
  6121. Count: info.Count,
  6122. UserOrgId: adminInfo.CurrentOrgId,
  6123. PatientId: project.PatientId,
  6124. SystemTime: info.SysRecordTime,
  6125. ConsumableType: 7,
  6126. IsSys: 0,
  6127. WarehousingOrder: "",
  6128. WarehouseOutId: info.WarehouseOutId,
  6129. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6130. IsEdit: 0,
  6131. CancelStockId: cancel.ID,
  6132. CancelOrderNumber: cancel.OrderNumber,
  6133. Manufacturer: manufacturer.ID,
  6134. Dealer: 0,
  6135. Creator: adminInfo.AdminUser.Id,
  6136. UpdateCreator: 0,
  6137. Status: 1,
  6138. Ctime: time.Now().Unix(),
  6139. Mtime: 0,
  6140. Price: info.Price,
  6141. WarehousingDetailId: info.WarehouseInfotId,
  6142. WarehouseOutDetailId: info.ID,
  6143. CancelOutDetailId: cancelInfo.ID,
  6144. ProductDate: info.ProductDate,
  6145. ExpireDate: info.ExpiryDate,
  6146. StorehouseId: houseConfig.StorehouseOutInfo,
  6147. OverCount: over_count,
  6148. OperateTime: time.Now().Unix(),
  6149. }
  6150. service.CreateStockFlowOne(flow)
  6151. }
  6152. //查询已出库数量
  6153. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6154. //fmt.Println("aiwohonguo --------------------", prescribingNumber)
  6155. //fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  6156. if prescribingNumber < dialysisInfo.Count {
  6157. //改变数量
  6158. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6159. }
  6160. if prescribingNumber >= dialysisInfo.Count {
  6161. //删除出库表
  6162. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6163. }
  6164. //更新剩余库存
  6165. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6166. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6167. var total_count_one int64
  6168. for _, it := range stockList {
  6169. total_count_one += it.StockCount
  6170. }
  6171. //基础库插入数据
  6172. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6173. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6174. var flush_count int64
  6175. for _, it := range goodListOne {
  6176. flush_count += it.StockCount
  6177. }
  6178. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6179. if errs != nil {
  6180. goodErrcode := models.XtGoodErrcode{
  6181. UserOrgId: project.UserOrgId,
  6182. Errcode: "手动出库更新剩余出库失败",
  6183. GoodId: project.ProjectId,
  6184. Status: 1,
  6185. Ctime: time.Now().Unix(),
  6186. Mtime: 0,
  6187. Count: 0,
  6188. StockCount: 0,
  6189. Creater: creater,
  6190. BatchNumberId: 0,
  6191. WarehouseOutId: 0,
  6192. }
  6193. service.CreateGoodErrcode(goodErrcode)
  6194. }
  6195. }
  6196. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6197. fmt.Println(err)
  6198. } else {
  6199. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6200. fmt.Println(err)
  6201. }
  6202. } else {
  6203. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6204. fmt.Println(err)
  6205. }
  6206. }
  6207. //保存处方出库
  6208. if goodOutConfig.IsOpen == 1 {
  6209. if project.Type == 3 {
  6210. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6211. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6212. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6213. operation_time := time.Now().Unix()
  6214. creater := adminInfo.AdminUser.Id
  6215. //创建退库单
  6216. timeStr := time.Now().Format("2006-01-02")
  6217. timeArr := strings.Split(timeStr, "-")
  6218. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6219. total = total + 1
  6220. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6221. cancelStock := models.CancelStock{
  6222. OrderNumber: orderNumber,
  6223. OperaTime: operation_time,
  6224. OrgId: adminInfo.CurrentOrgId,
  6225. Creater: creater,
  6226. Ctime: time.Now().Unix(),
  6227. Status: 1,
  6228. ReturnTime: project.RecordDate,
  6229. Type: 1,
  6230. StorehouseId: houseConfig.StorehouseOutInfo,
  6231. IsCheck: 1,
  6232. }
  6233. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6234. if msgerrkonde == gorm.ErrRecordNotFound {
  6235. service.AddSigleCancelStock(&cancelStock)
  6236. }
  6237. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6238. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6239. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6240. //获取出库数据
  6241. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6242. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6243. deaerler, _ := service.GetDealerById(info.Dealer)
  6244. if info.ID > 0 {
  6245. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6246. if info.Count >= prescribingNumber {
  6247. cancelStockInfo := models.CancelStockInfo{
  6248. GoodId: project.ProjectId,
  6249. CancelStockId: cancel.ID,
  6250. GoodTypeId: good.GoodTypeId,
  6251. Count: prescribingNumber,
  6252. Price: info.Price,
  6253. Total: 0,
  6254. ProductDate: info.ProductDate,
  6255. ExpiryDate: info.ExpiryDate,
  6256. Ctime: time.Now().Unix(),
  6257. Status: 1,
  6258. OrgId: adminInfo.CurrentOrgId,
  6259. OrderNumber: cancel.OrderNumber,
  6260. Type: 0,
  6261. Dealer: deaerler.DealerName,
  6262. Manufacturer: manufacturer.ManufacturerName,
  6263. Number: info.Number,
  6264. RegisterAccount: "",
  6265. Remark: "",
  6266. WarehouseInfoId: info.WarehouseInfotId,
  6267. PatientId: info.PatientId,
  6268. RecordDate: info.SysRecordTime,
  6269. StorehouseId: houseConfig.StorehouseOutInfo,
  6270. IsCheck: 1,
  6271. }
  6272. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6273. //退库数量增加
  6274. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6275. //出库数量减少
  6276. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6277. }
  6278. if info.Count < prescribingNumber {
  6279. cancelStockInfo := models.CancelStockInfo{
  6280. GoodId: project.ProjectId,
  6281. CancelStockId: cancel.ID,
  6282. GoodTypeId: good.GoodTypeId,
  6283. Count: prescribingNumber,
  6284. Price: info.Price,
  6285. Total: 0,
  6286. ProductDate: info.ProductDate,
  6287. ExpiryDate: info.ExpiryDate,
  6288. Ctime: time.Now().Unix(),
  6289. Status: 1,
  6290. OrgId: adminInfo.CurrentOrgId,
  6291. OrderNumber: cancel.OrderNumber,
  6292. Type: 0,
  6293. Dealer: deaerler.DealerName,
  6294. Manufacturer: manufacturer.ManufacturerName,
  6295. Number: info.Number,
  6296. RegisterAccount: "",
  6297. Remark: "",
  6298. WarehouseInfoId: info.WarehouseInfotId,
  6299. PatientId: info.PatientId,
  6300. RecordDate: info.SysRecordTime,
  6301. StorehouseId: houseConfig.StorehouseOutInfo,
  6302. IsCheck: 1,
  6303. }
  6304. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6305. //回退库存
  6306. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6307. }
  6308. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6309. var over_count int64
  6310. for _, it := range goodList {
  6311. over_count += it.StockCount
  6312. }
  6313. //查询出库数量
  6314. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  6315. //出库数据 大于 退库数量
  6316. if len(list) > 0 {
  6317. for _, it := range list {
  6318. //回退库存
  6319. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6320. //退库数量增加
  6321. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  6322. //出库数量减少
  6323. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  6324. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6325. var over_count_one int64
  6326. for _, it := range goodList {
  6327. over_count_one += it.StockCount
  6328. }
  6329. //查询该批次是否有退库数据
  6330. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  6331. flow := models.VmStockFlow{
  6332. WarehousingId: it.WarehouseInfotId,
  6333. GoodId: it.GoodId,
  6334. Number: it.Number,
  6335. LicenseNumber: it.LicenseNumber,
  6336. Count: it.Count,
  6337. UserOrgId: adminInfo.CurrentOrgId,
  6338. PatientId: it.PatientId,
  6339. SystemTime: it.SysRecordTime,
  6340. ConsumableType: 7,
  6341. IsSys: 0,
  6342. WarehousingOrder: "",
  6343. WarehouseOutId: it.WarehouseOutId,
  6344. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6345. IsEdit: 0,
  6346. CancelStockId: cancel.ID,
  6347. CancelOrderNumber: cancel.OrderNumber,
  6348. Manufacturer: manufacturer.ID,
  6349. Dealer: 0,
  6350. Creator: adminInfo.AdminUser.Id,
  6351. UpdateCreator: 0,
  6352. Status: 1,
  6353. Ctime: time.Now().Unix(),
  6354. Mtime: 0,
  6355. Price: it.Price,
  6356. WarehousingDetailId: it.WarehouseInfotId,
  6357. WarehouseOutDetailId: it.ID,
  6358. CancelOutDetailId: cancelInfo.ID,
  6359. ProductDate: it.ProductDate,
  6360. ExpireDate: it.ExpiryDate,
  6361. StorehouseId: houseConfig.StorehouseOutInfo,
  6362. OverCount: over_count_one,
  6363. OperateTime: time.Now().Unix(),
  6364. }
  6365. service.CreateStockFlowOne(flow)
  6366. }
  6367. }
  6368. //查询已出库数量
  6369. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6370. if prescribingNumber < dialysisInfo.Count {
  6371. //改变数量
  6372. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6373. }
  6374. if prescribingNumber >= dialysisInfo.Count {
  6375. //删除出库表
  6376. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6377. }
  6378. //更新剩余库存
  6379. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6380. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6381. var total_count_one int64
  6382. for _, it := range stockList {
  6383. total_count_one += it.StockCount
  6384. }
  6385. //基础库插入数据
  6386. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6387. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6388. var flush_count int64
  6389. for _, it := range goodListOne {
  6390. flush_count += it.StockCount
  6391. }
  6392. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6393. if errs != nil {
  6394. goodErrcode := models.XtGoodErrcode{
  6395. UserOrgId: project.UserOrgId,
  6396. Errcode: "手动出库更新剩余出库失败",
  6397. GoodId: project.ProjectId,
  6398. Status: 1,
  6399. Ctime: time.Now().Unix(),
  6400. Mtime: 0,
  6401. Count: 0,
  6402. StockCount: 0,
  6403. Creater: creater,
  6404. BatchNumberId: 0,
  6405. WarehouseOutId: 0,
  6406. }
  6407. service.CreateGoodErrcode(goodErrcode)
  6408. }
  6409. }
  6410. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6411. fmt.Println(err)
  6412. } else {
  6413. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6414. fmt.Println(err)
  6415. }
  6416. }
  6417. c.ServeSuccessJSON(map[string]interface{}{
  6418. "msg": "删除成功",
  6419. })
  6420. return
  6421. }
  6422. func (c *HisApiController) CreateHisAdditionalCharge() {
  6423. his_patient_id, _ := c.GetInt64("his_patient_id")
  6424. patient_id, _ := c.GetInt64("patient_id")
  6425. record_date := c.GetString("record_date")
  6426. timeLayout := "2006-01-02"
  6427. loc, _ := time.LoadLocation("Local")
  6428. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6429. if err != nil {
  6430. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6431. return
  6432. }
  6433. adminInfo := c.GetAdminUserInfo()
  6434. recordDateTime := theTime.Unix()
  6435. dataBody := make(map[string]interface{}, 0)
  6436. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6437. if err != nil {
  6438. utils.ErrorLog(err.Error())
  6439. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6440. return
  6441. }
  6442. var additions []*models.HisAdditionalCharge
  6443. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  6444. additions, _ := dataBody["addition"].([]interface{})
  6445. if len(additions) > 0 {
  6446. for _, item := range additions {
  6447. items := item.(map[string]interface{})
  6448. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  6449. utils.ErrorLog("item_id")
  6450. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6451. return
  6452. }
  6453. item_id := int64(items["item_id"].(float64))
  6454. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  6455. utils.ErrorLog("item_name")
  6456. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6457. return
  6458. }
  6459. item_name := items["item_name"].(string)
  6460. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  6461. utils.ErrorLog("price")
  6462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6463. return
  6464. }
  6465. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  6466. ctime := time.Now().Unix()
  6467. additional := &models.HisAdditionalCharge{
  6468. PatientId: patient_id,
  6469. HisPatientId: his_patient_id,
  6470. UserOrgId: adminInfo.CurrentOrgId,
  6471. RecordDate: recordDateTime,
  6472. CreatedTime: ctime,
  6473. UpdatedTime: ctime,
  6474. Modifier: adminInfo.AdminUser.Id,
  6475. Creator: adminInfo.AdminUser.Id,
  6476. Price: price,
  6477. ItemName: item_name,
  6478. ItemId: item_id,
  6479. Status: 1,
  6480. }
  6481. additions = append(additions, additional)
  6482. }
  6483. }
  6484. }
  6485. for _, item := range additions {
  6486. service.CreateAddtionalCharge(item)
  6487. }
  6488. c.ServeSuccessJSON(map[string]interface{}{
  6489. "msg": "创建成功",
  6490. })
  6491. }
  6492. func (c *HisApiController) CreateHisPatientCaseHistory() {
  6493. blood_fat := c.GetString("blood_fat")
  6494. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  6495. blood_sugar := c.GetString("blood_sugar")
  6496. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  6497. chief_conplaint := c.GetString("chief_conplaint")
  6498. dbp := c.GetString("dbp")
  6499. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  6500. delivery_way, _ := c.GetInt64("delivery_way")
  6501. diagnostic := c.GetString("diagnostic")
  6502. family_history := c.GetString("family_history")
  6503. height := c.GetString("height")
  6504. history_of_present_illness := c.GetString("history_of_present_illness")
  6505. is_infect, _ := c.GetInt64("is_infect")
  6506. past_history := c.GetString("past_history")
  6507. patient_id, _ := c.GetInt64("patient_id")
  6508. his_patient_id, _ := c.GetInt64("his_patient_id")
  6509. personal_history := c.GetString("personal_history")
  6510. pulse := c.GetString("pulse")
  6511. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  6512. sbp := c.GetString("sbp")
  6513. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  6514. heightfloat, _ := strconv.ParseFloat(height, 64)
  6515. sicktype := c.GetString("sick_type")
  6516. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  6517. symptom := c.GetString("symptom")
  6518. sick_date := c.GetString("sick_date")
  6519. temperatures := c.GetString("temperature")
  6520. temperature, _ := strconv.ParseFloat(temperatures, 64)
  6521. record_date := c.GetString("record_date")
  6522. breathing := c.GetString("breathing")
  6523. doctor_advice := c.GetString("doctor_advice")
  6524. remark := c.GetString("remark")
  6525. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  6526. sick, _ := c.GetInt64("sick")
  6527. diagnose, _ := c.GetInt64("diagnose")
  6528. //id, _ := c.GetInt64("id")
  6529. timeLayout := "2006-01-02"
  6530. loc, _ := time.LoadLocation("Local")
  6531. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6532. allergic_history := c.GetString("allergic_history")
  6533. if err != nil {
  6534. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6535. return
  6536. }
  6537. recordDateTime := theTime.Unix()
  6538. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  6539. if err != nil {
  6540. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6541. return
  6542. }
  6543. sickTimes := sickTime.Unix()
  6544. ctime := time.Now().Unix()
  6545. primary_disease := c.GetString("primary_disease")
  6546. confirm_failure_date := c.GetString("confirm_failure_date")
  6547. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  6548. drug_allergy_history := c.GetString("drug_allergy_history")
  6549. physical_examination := c.GetString("physical_examination")
  6550. special_inspection := c.GetString("special_inspection")
  6551. lab_apparatus := c.GetString("lab_apparatus")
  6552. caseHistory := models.HisPatientCaseHistory{
  6553. HisPatientId: his_patient_id,
  6554. PatientId: patient_id,
  6555. Temperature: temperature,
  6556. BloodSugar: bloodsugarfloat,
  6557. Pulse: pulsefloat,
  6558. Sbp: sbpfloat,
  6559. Dbp: dbpfloat,
  6560. Height: heightfloat,
  6561. BloodFat: bloodfatfloat,
  6562. SickType: sick_type,
  6563. Symptom: symptom,
  6564. SickDate: sickTimes,
  6565. IsInfect: is_infect,
  6566. HistoryOfPresentIllness: history_of_present_illness,
  6567. PastHistory: past_history,
  6568. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  6569. ChiefConplaint: chief_conplaint,
  6570. PersonalHistory: personal_history,
  6571. FamilyHistory: family_history,
  6572. Diagnostic: diagnostic,
  6573. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6574. Status: 1,
  6575. Ctime: ctime,
  6576. Mtime: ctime,
  6577. RecordDate: recordDateTime,
  6578. DeliveryWay: delivery_way,
  6579. Breathing: breathingfloat,
  6580. DoctorAdvice: doctor_advice,
  6581. Remark: remark,
  6582. Sick: sick,
  6583. Diagnose: diagnose,
  6584. AllergicHistory: allergic_history,
  6585. PrimaryDisease: primary_disease,
  6586. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  6587. DrugAllergyHistory: drug_allergy_history,
  6588. PhysicalExamination: physical_examination,
  6589. SpecialInspection: special_inspection,
  6590. LabApparatus: lab_apparatus,
  6591. }
  6592. //查询该患者是否有病历
  6593. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  6594. if errcodes == gorm.ErrRecordNotFound {
  6595. err = service.SaveHisPatientCaseHistory(&caseHistory)
  6596. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  6597. if err != nil {
  6598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6599. return
  6600. }
  6601. c.ServeSuccessJSON(map[string]interface{}{
  6602. "caseHistory": caseHistory,
  6603. "historyInfo": historyInfo,
  6604. })
  6605. return
  6606. } else if errcodes == nil {
  6607. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  6608. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  6609. if err != nil {
  6610. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6611. return
  6612. }
  6613. c.ServeSuccessJSON(map[string]interface{}{
  6614. "caseHistory": caseHistory,
  6615. "historyInfo": historyInfo,
  6616. })
  6617. }
  6618. //查询该患者是否有病历
  6619. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  6620. //if errcode == gorm.ErrRecordNotFound {
  6621. // err = service.SaveHisPatientCaseHistory(caseHistory)
  6622. // if err != nil {
  6623. // c.ServeSuccessJSON(map[string]interface{}{
  6624. // "msg": "保存成功",
  6625. // })
  6626. // }
  6627. //} else if errcode == nil {
  6628. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6629. // return
  6630. //}
  6631. }
  6632. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  6633. patient_id, _ := c.GetInt64("patient_id", 0)
  6634. adminUser := c.GetAdminUserInfo()
  6635. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  6636. c.ServeSuccessJSON(map[string]interface{}{
  6637. "list": caseHistorys,
  6638. })
  6639. }
  6640. func (c *HisApiController) GetHisPatientCaseHistory() {
  6641. record_date, _ := c.GetInt64("record_date", 0)
  6642. patient_id, _ := c.GetInt64("patient_id", 0)
  6643. admin := c.GetAdminUserInfo()
  6644. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  6645. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  6646. c.ServeSuccessJSON(map[string]interface{}{
  6647. "info": info,
  6648. "case_history": case_history,
  6649. })
  6650. }
  6651. func (c *HisApiController) CreateCaseHistoryTemplate() {
  6652. template_name := c.GetString("template_name")
  6653. template_remark := c.GetString("template_remark")
  6654. doctor := c.GetAdminUserInfo().AdminUser.Id
  6655. diagnostic := c.GetString("diagnostic")
  6656. chief_conplaint := c.GetString("chief_conplain")
  6657. history_of_present_illness := c.GetString("history_of_present_illness")
  6658. past_history := c.GetString("past_history")
  6659. personal_history := c.GetString("personal_history")
  6660. family_history := c.GetString("family_history")
  6661. user_name := c.GetString("user_name")
  6662. doctor_advice := c.GetString("doctor_advice")
  6663. remark := c.GetString("remark")
  6664. //record_date := c.GetString("record_date")
  6665. //fmt.Println("record_date--------",record_date)
  6666. //timeLayout := "2006-01-02"
  6667. //loc, _ := time.LoadLocation("Local")
  6668. //
  6669. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6670. //if err != nil {
  6671. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6672. // return
  6673. //}
  6674. //recordDateTime := theTime.Unix()
  6675. ctime := time.Now().Unix()
  6676. template := models.HisCaseHistoryTemplate{
  6677. HistoryOfPresentIllness: history_of_present_illness,
  6678. PastHistory: past_history,
  6679. ChiefConplaint: chief_conplaint,
  6680. PersonalHistory: personal_history,
  6681. FamilyHistory: family_history,
  6682. Diagnostic: diagnostic,
  6683. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6684. Status: 1,
  6685. Ctime: ctime,
  6686. Mtime: ctime,
  6687. RecordDate: time.Now().Unix(),
  6688. TemplateName: template_name,
  6689. TemplateRemark: template_remark,
  6690. Creator: doctor,
  6691. Modifier: doctor,
  6692. UserName: user_name,
  6693. DoctorAdvice: doctor_advice,
  6694. Remark: remark,
  6695. }
  6696. err := service.SaveHisPatientCaseHistoryTemplate(template)
  6697. if err == nil {
  6698. c.ServeSuccessJSON(map[string]interface{}{
  6699. "msg": "保存成功",
  6700. })
  6701. } else {
  6702. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6703. return
  6704. }
  6705. }
  6706. func (c *HisApiController) GetCaseHistoryTemplate() {
  6707. timeLayout := "2006-01-02"
  6708. loc, _ := time.LoadLocation("Local")
  6709. keyword := c.GetString("keyword")
  6710. start_time := c.GetString("start_time")
  6711. end_time := c.GetString("end_time")
  6712. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6713. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6714. admin := c.GetAdminUserInfo()
  6715. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  6716. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  6717. c.ServeSuccessJSON(map[string]interface{}{
  6718. "template": template,
  6719. //"history": history,
  6720. })
  6721. }
  6722. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6723. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6724. utils.ErrorLog("drug_name")
  6725. return enums.ErrorCodeParamWrong
  6726. }
  6727. adviceName, _ := json["drug_name"].(string)
  6728. if len(adviceName) == 0 {
  6729. utils.ErrorLog("len(advice_name) == 0")
  6730. return enums.ErrorCodeParamWrong
  6731. }
  6732. advice.AdviceName = adviceName
  6733. adviceDesc, _ := json["advice_desc"].(string)
  6734. advice.AdviceDesc = adviceDesc
  6735. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6736. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6737. advice.DrugSpec = drugSpec
  6738. }
  6739. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6740. remark, _ := json["remark"].(string)
  6741. advice.Remark = remark
  6742. }
  6743. if json["id"] == nil {
  6744. advice.DrugId = 0
  6745. } else {
  6746. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6747. drug_id := int64(json["id"].(float64))
  6748. advice.DrugId = drug_id
  6749. }
  6750. }
  6751. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6752. advice_id := int64(json["advice_id"].(float64))
  6753. advice.ID = advice_id
  6754. if advice.ID > 0 {
  6755. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6756. if err == nil {
  6757. if hisAdvice.ID > 0 {
  6758. advice.ExecutionTime = hisAdvice.ExecutionTime
  6759. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6760. advice.ExecutionState = hisAdvice.ExecutionState
  6761. advice.CheckTime = hisAdvice.CheckTime
  6762. advice.Checker = hisAdvice.Checker
  6763. advice.CheckState = hisAdvice.CheckState
  6764. advice.StartTime = hisAdvice.StartTime
  6765. advice.FeedetlSn = hisAdvice.FeedetlSn
  6766. }
  6767. }
  6768. }
  6769. }
  6770. //
  6771. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6772. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6773. // advice.ExecutionTime = execution_time
  6774. //}
  6775. //
  6776. //
  6777. //
  6778. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6779. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6780. // advice.ExecutionStaff = execution_staff
  6781. //}
  6782. //
  6783. //
  6784. //
  6785. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6786. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6787. // advice.ExecutionState = execution_state
  6788. //}
  6789. //
  6790. //
  6791. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6792. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6793. // advice.CheckTime = check_time
  6794. //}
  6795. //
  6796. //
  6797. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6798. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6799. // advice.CheckState = check_state
  6800. //}
  6801. //
  6802. //
  6803. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6804. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6805. // advice.Checker = checker
  6806. //}
  6807. //
  6808. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6809. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6810. // advice.StartTime = start_time
  6811. //}
  6812. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6813. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6814. advice.IsSelfDrug = is_self_drug
  6815. }
  6816. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6817. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6818. drug_way_count, _ := json["drug_way_count"].(string)
  6819. advice.DrugWayCount = drug_way_count
  6820. }
  6821. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6822. drugSpecUnit, _ := json["min_unit"].(string)
  6823. advice.DrugSpecUnit = drugSpecUnit
  6824. }
  6825. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6826. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6827. advice.SingleDose = singleDose
  6828. }
  6829. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6830. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6831. advice.SingleDoseUnit = singleDoseUnit
  6832. }
  6833. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6834. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6835. advice.PrescribingNumber = prescribingNumber
  6836. }
  6837. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6838. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6839. advice.PrescribingNumberUnit = prescribingNumberUnit
  6840. }
  6841. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6842. deliveryWay, _ := json["delivery_way"].(string)
  6843. advice.DeliveryWay = deliveryWay
  6844. }
  6845. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6846. executionFrequency, _ := json["execution_frequency"].(string)
  6847. advice.ExecutionFrequency = executionFrequency
  6848. }
  6849. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6850. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6851. advice.Price = price
  6852. }
  6853. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6854. med_list_codg, _ := json["medical_insurance_number"].(string)
  6855. advice.MedListCodg = med_list_codg
  6856. }
  6857. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6858. day := int64(json["day"].(float64))
  6859. advice.Day = day
  6860. }
  6861. return 0
  6862. }
  6863. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6864. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6865. id := int64(json["id"].(float64))
  6866. project.ID = id
  6867. historyProject, _ := service.GetHisProjectByID(id)
  6868. project.FeedetlSn = historyProject.FeedetlSn
  6869. }
  6870. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6871. project_id := int64(json["project_id"].(float64))
  6872. project.ProjectId = project_id
  6873. }
  6874. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6875. // price := int64(json["price"].(float64))
  6876. // formatInt_price := strconv.FormatInt(price, 10)
  6877. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6878. // project.Price = float_price
  6879. // }
  6880. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6881. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6882. project.Price = price
  6883. }
  6884. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6885. total, _ := json["total"].(string)
  6886. project.Count = total
  6887. }
  6888. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6889. medical_code, _ := json["medical_code"].(string)
  6890. project.MedListCodg = medical_code
  6891. }
  6892. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6893. single_dose, _ := json["single_dose"].(string)
  6894. project.SingleDose = single_dose
  6895. }
  6896. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6897. delivery_way, _ := json["delivery_way"].(string)
  6898. project.DeliveryWay = delivery_way
  6899. }
  6900. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6901. execution_frequency, _ := json["execution_frequency"].(string)
  6902. project.ExecutionFrequency = execution_frequency
  6903. }
  6904. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6905. remark, _ := json["remark"].(string)
  6906. project.Remark = remark
  6907. }
  6908. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6909. day, _ := json["number_days"].(string)
  6910. project.Day = day
  6911. }
  6912. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6913. unit, _ := json["unit"].(string)
  6914. project.Unit = unit
  6915. }
  6916. return 0
  6917. }
  6918. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6919. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6920. id := int64(json["id"].(float64))
  6921. historyAddtions, _ := service.GetHisAdditionByID(id)
  6922. additionalCharge.ID = id
  6923. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  6924. }
  6925. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6926. item_id := int64(json["item_id"].(float64))
  6927. additionalCharge.ItemId = item_id
  6928. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6929. if config.ID > 0 {
  6930. if len(config.Code) > 0 {
  6931. additionalCharge.MedListCodg = config.Code
  6932. }
  6933. }
  6934. }
  6935. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6936. // price := int64(json["price"].(float64))
  6937. // formatInt_price := strconv.FormatInt(price, 10)
  6938. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6939. // additionalCharge.Price = float_price
  6940. // }
  6941. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6942. // price := int64(json["price"].(float64))
  6943. // formatInt_price := strconv.FormatInt(price, 10)
  6944. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6945. // additionalCharge.Price = float_price
  6946. //}
  6947. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6948. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6949. additionalCharge.Price = price
  6950. }
  6951. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6952. count, _ := json["count"].(string)
  6953. counts, _ := strconv.ParseInt(count, 10, 64)
  6954. additionalCharge.Count = counts
  6955. }
  6956. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6957. item_name, _ := json["item_name"].(string)
  6958. additionalCharge.ItemName = item_name
  6959. }
  6960. return 0
  6961. }
  6962. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6963. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6964. utils.ErrorLog("drug_name")
  6965. return enums.ErrorCodeParamWrong
  6966. }
  6967. adviceName, _ := json["drug_name"].(string)
  6968. if len(adviceName) == 0 {
  6969. utils.ErrorLog("len(advice_name) == 0")
  6970. return enums.ErrorCodeParamWrong
  6971. }
  6972. advice.AdviceName = adviceName
  6973. adviceDesc, _ := json["advice_desc"].(string)
  6974. advice.AdviceDesc = adviceDesc
  6975. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6976. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6977. advice.DrugSpec = drugSpec
  6978. }
  6979. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6980. remark, _ := json["remark"].(string)
  6981. advice.Remark = remark
  6982. }
  6983. if json["id"] == nil {
  6984. advice.DrugId = 0
  6985. } else {
  6986. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6987. drug_id := int64(json["id"].(float64))
  6988. advice.DrugId = drug_id
  6989. }
  6990. }
  6991. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6992. groupno := int64(json["groupno"].(float64))
  6993. advice.Groupno = groupno
  6994. }
  6995. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6996. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6997. advice.IsSelfDrug = is_self_drug
  6998. }
  6999. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7000. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7001. drug_way_count, _ := json["drug_way_count"].(string)
  7002. advice.DrugWayCount = drug_way_count
  7003. }
  7004. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7005. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7006. advice.HospApprFlag = hosp_appr_flag
  7007. }
  7008. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7009. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7010. advice.PrescribingNumber = prescribingNumber
  7011. }
  7012. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7013. // frequency_type := int64(json["frequency_type"].(float64))
  7014. // advice.FrequencyType = frequency_type
  7015. //}
  7016. //
  7017. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7018. // day_count := int64(json["day_count"].(float64))
  7019. // advice.DayCount = day_count
  7020. //}
  7021. //
  7022. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7023. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7024. // week_day, _ := json["week_day"].(string)
  7025. // advice.WeekDay = week_day
  7026. //}
  7027. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7028. drugSpecUnit, _ := json["min_unit"].(string)
  7029. advice.DrugSpecUnit = drugSpecUnit
  7030. }
  7031. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7032. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7033. advice.SingleDose = singleDose
  7034. }
  7035. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7036. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7037. advice.SingleDoseUnit = singleDoseUnit
  7038. }
  7039. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7040. deliveryWay, _ := json["delivery_way"].(string)
  7041. advice.DeliveryWay = deliveryWay
  7042. }
  7043. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7044. executionFrequency, _ := json["execution_frequency"].(string)
  7045. advice.ExecutionFrequency = executionFrequency
  7046. }
  7047. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7048. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7049. advice.Price = price
  7050. }
  7051. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7052. med_list_codg, _ := json["medical_insurance_number"].(string)
  7053. advice.MedListCodg = med_list_codg
  7054. }
  7055. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7056. day := int64(json["day"].(float64))
  7057. advice.Day = day
  7058. }
  7059. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7060. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7061. advice.PrescribingNumberUnit = prescribingNumberUnit
  7062. }
  7063. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7064. advice_id := int64(json["advice_id"].(float64))
  7065. advice.ID = advice_id
  7066. if advice.ID > 0 {
  7067. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7068. if err == nil {
  7069. if hisAdvice.ID > 0 {
  7070. advice.ExecutionTime = hisAdvice.ExecutionTime
  7071. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7072. advice.ExecutionState = hisAdvice.ExecutionState
  7073. advice.CheckTime = hisAdvice.CheckTime
  7074. advice.Checker = hisAdvice.Checker
  7075. advice.CheckState = hisAdvice.CheckState
  7076. advice.StartTime = hisAdvice.StartTime
  7077. advice.HospApprFlag = hisAdvice.HospApprFlag
  7078. advice.IsMedicine = hisAdvice.IsMedicine
  7079. if hisAdvice.UserOrgId == 10028 {
  7080. 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 {
  7081. advice.ExecutionTime = 0
  7082. advice.ExecutionStaff = 0
  7083. advice.ExecutionState = 2
  7084. advice.CheckTime = 0
  7085. advice.Checker = 0
  7086. advice.CheckState = 2
  7087. }
  7088. } else {
  7089. 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 {
  7090. advice.ExecutionTime = 0
  7091. advice.ExecutionStaff = 0
  7092. advice.ExecutionState = 2
  7093. advice.CheckTime = 0
  7094. advice.Checker = 0
  7095. advice.CheckState = 2
  7096. advice.UpdatedTime = time.Now().Unix()
  7097. }
  7098. }
  7099. //advice.Groupno = hisAdvice.Groupno
  7100. }
  7101. }
  7102. }
  7103. }
  7104. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7105. //
  7106. //if drugStockConfig.IsOpen == 1 {
  7107. //
  7108. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7109. // if advice.ID == 0 { //医嘱不存在
  7110. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7111. // drug.Total = drug.Total - advice.PrescribingNumber
  7112. // service.UpdateBaseDrugLib(&drug)
  7113. //
  7114. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7115. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7116. // drug.Total = drug.Total - num
  7117. // service.UpdateBaseDrugLib(&drug)
  7118. // }
  7119. //
  7120. // } else if advice.ID > 0 { //医嘱存在
  7121. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7122. // var num float64
  7123. //
  7124. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7125. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7126. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7127. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7128. // drug.Total = drug.Total + num
  7129. // service.UpdateBaseDrugLib(&drug)
  7130. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7131. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7132. // drug.Total = drug.Total - num
  7133. // service.UpdateBaseDrugLib(&drug)
  7134. // }
  7135. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7136. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7137. // if num2 > advice.PrescribingNumber {
  7138. // num = num2 - advice.PrescribingNumber
  7139. // drug.Total = drug.Total + num
  7140. // service.UpdateBaseDrugLib(&drug)
  7141. // } else if num2 < advice.PrescribingNumber {
  7142. // num = advice.PrescribingNumber - num2
  7143. // drug.Total = drug.Total - num
  7144. // service.UpdateBaseDrugLib(&drug)
  7145. // }
  7146. //
  7147. // }
  7148. //
  7149. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7150. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7151. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7152. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7153. // if num1 > num2 {
  7154. // num = num1 - num2
  7155. // drug.Total = drug.Total + num
  7156. // service.UpdateBaseDrugLib(&drug)
  7157. // } else if num1 < num2 {
  7158. // num = num2 - num1
  7159. // drug.Total = drug.Total - num
  7160. // service.UpdateBaseDrugLib(&drug)
  7161. // }
  7162. //
  7163. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7164. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7165. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7166. // if hisAdvice.PrescribingNumber > num2 {
  7167. // num = hisAdvice.PrescribingNumber - num2
  7168. // drug.Total = drug.Total + num
  7169. // service.UpdateBaseDrugLib(&drug)
  7170. // } else if num2 < advice.PrescribingNumber {
  7171. // num = num2 - hisAdvice.PrescribingNumber
  7172. // drug.Total = drug.Total - num
  7173. // service.UpdateBaseDrugLib(&drug)
  7174. // }
  7175. //
  7176. // }
  7177. // }
  7178. // }
  7179. //}
  7180. //
  7181. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7182. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7183. // advice.ExecutionTime = execution_time
  7184. //}
  7185. //
  7186. //
  7187. //
  7188. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7189. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7190. // advice.ExecutionStaff = execution_staff
  7191. //}
  7192. //
  7193. //
  7194. //
  7195. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7196. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7197. // advice.ExecutionState = execution_state
  7198. //}
  7199. //
  7200. //
  7201. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7202. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7203. // advice.CheckTime = check_time
  7204. //}
  7205. //
  7206. //
  7207. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7208. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7209. // advice.CheckState = check_state
  7210. //}
  7211. //
  7212. //
  7213. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7214. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7215. // advice.Checker = checker
  7216. //}
  7217. //
  7218. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7219. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7220. // advice.StartTime = start_time
  7221. //}
  7222. return 0
  7223. }
  7224. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7225. project.ExecutionStaff = 0
  7226. project.ExecutionState = 2
  7227. project.ExecutionTime = 0
  7228. project.Checker = 0
  7229. project.CheckState = 2
  7230. project.CheckTime = 0
  7231. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7232. id := int64(json["id"].(float64))
  7233. project.ID = id
  7234. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7235. project.ExecutionStaff = temp_project.ExecutionStaff
  7236. project.ExecutionState = temp_project.ExecutionState
  7237. project.ExecutionTime = temp_project.ExecutionTime
  7238. project.Checker = temp_project.Checker
  7239. project.CheckState = temp_project.CheckState
  7240. project.CheckTime = temp_project.CheckTime
  7241. project.TeamId = temp_project.TeamId
  7242. }
  7243. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7244. types := int64(json["type"].(float64))
  7245. project.Type = types
  7246. }
  7247. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7248. project_id := int64(json["project_id"].(float64))
  7249. project.ProjectId = project_id
  7250. }
  7251. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7252. team_id := int64(json["team_id"].(float64))
  7253. project.TeamId = team_id
  7254. }
  7255. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7256. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7257. project.Price = price
  7258. }
  7259. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7260. total, _ := json["total"].(string)
  7261. //totals, _ := strconv.ParseInt(total, 10, 64)
  7262. project.Count = total
  7263. }
  7264. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7265. medical_code, _ := json["medical_code"].(string)
  7266. project.MedListCodg = medical_code
  7267. }
  7268. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7269. single_dose, _ := json["single_dose"].(string)
  7270. project.SingleDose = single_dose
  7271. }
  7272. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7273. delivery_way, _ := json["delivery_way"].(string)
  7274. project.DeliveryWay = delivery_way
  7275. }
  7276. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7277. execution_frequency, _ := json["execution_frequency"].(string)
  7278. project.ExecutionFrequency = execution_frequency
  7279. }
  7280. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7281. remark, _ := json["remark"].(string)
  7282. project.Remark = remark
  7283. }
  7284. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7285. day, _ := json["number_days"].(string)
  7286. project.Day = day
  7287. }
  7288. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7289. unit, _ := json["unit"].(string)
  7290. project.Unit = unit
  7291. }
  7292. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7293. // frequency_type := int64(json["frequency_type"].(float64))
  7294. // project.FrequencyType = frequency_type
  7295. //}
  7296. //
  7297. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7298. // day_count := int64(json["day_count"].(float64))
  7299. // project.DayCount = day_count
  7300. //}
  7301. //
  7302. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7303. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7304. // week_day, _ := json["week_day"].(string)
  7305. // project.WeekDay = week_day
  7306. //}
  7307. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7308. //
  7309. //if project.ID == 0 {
  7310. // if stockConfig.IsOpen == 1 {
  7311. // if project.Type == 3 {
  7312. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7313. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7314. // good.Total = good.Total - f_count
  7315. // service.UpdateGoodInfo(&good)
  7316. // }
  7317. // }
  7318. //
  7319. //} else {
  7320. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7321. //
  7322. // if stockConfig.IsOpen == 1 {
  7323. // if project.Type == 3 {
  7324. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7325. // if project.Count < temp_project.Count {
  7326. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7327. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7328. //
  7329. // other_count := f_count_two - f_count_one
  7330. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7331. // good.Total = good.Total + other_count_two
  7332. // service.UpdateGoodInfo(&good)
  7333. // } else if project.Count > temp_project.Count {
  7334. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7335. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7336. //
  7337. // other_count := f_count_one - f_count_two
  7338. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7339. // good.Total = good.Total - other_count_two
  7340. // service.UpdateGoodInfo(&good)
  7341. // }
  7342. //
  7343. // }
  7344. // }
  7345. //
  7346. //}
  7347. return 0
  7348. }
  7349. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7350. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7351. utils.ErrorLog("drug_name")
  7352. return enums.ErrorCodeParamWrong
  7353. }
  7354. adviceName, _ := json["drug_name"].(string)
  7355. if len(adviceName) == 0 {
  7356. utils.ErrorLog("len(advice_name) == 0")
  7357. return enums.ErrorCodeParamWrong
  7358. }
  7359. advice.AdviceName = adviceName
  7360. adviceDesc, _ := json["advice_desc"].(string)
  7361. advice.AdviceDesc = adviceDesc
  7362. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7363. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7364. advice.DrugSpec = drugSpec
  7365. }
  7366. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7367. remark, _ := json["remark"].(string)
  7368. advice.Remark = remark
  7369. }
  7370. if json["id"] == nil {
  7371. advice.DrugId = 0
  7372. } else {
  7373. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7374. drug_id := int64(json["id"].(float64))
  7375. advice.DrugId = drug_id
  7376. }
  7377. }
  7378. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7379. groupno := int64(json["groupno"].(float64))
  7380. advice.Groupno = groupno
  7381. }
  7382. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7383. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7384. advice.IsSelfDrug = is_self_drug
  7385. }
  7386. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7387. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7388. drug_way_count, _ := json["drug_way_count"].(string)
  7389. advice.DrugWayCount = drug_way_count
  7390. }
  7391. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7392. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7393. advice.HospApprFlag = hosp_appr_flag
  7394. }
  7395. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7396. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7397. advice.PrescribingNumber = prescribingNumber
  7398. }
  7399. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7400. // frequency_type := int64(json["frequency_type"].(float64))
  7401. // advice.FrequencyType = frequency_type
  7402. //}
  7403. //
  7404. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7405. // day_count := int64(json["day_count"].(float64))
  7406. // advice.DayCount = day_count
  7407. //}
  7408. //
  7409. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7410. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7411. // week_day, _ := json["week_day"].(string)
  7412. // advice.WeekDay = week_day
  7413. //}
  7414. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7415. drugSpecUnit, _ := json["min_unit"].(string)
  7416. advice.DrugSpecUnit = drugSpecUnit
  7417. }
  7418. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7419. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7420. advice.SingleDose = singleDose
  7421. }
  7422. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7423. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7424. advice.SingleDoseUnit = singleDoseUnit
  7425. }
  7426. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7427. deliveryWay, _ := json["delivery_way"].(string)
  7428. advice.DeliveryWay = deliveryWay
  7429. }
  7430. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7431. executionFrequency, _ := json["execution_frequency"].(string)
  7432. advice.ExecutionFrequency = executionFrequency
  7433. }
  7434. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7435. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7436. advice.Price = price
  7437. }
  7438. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7439. med_list_codg, _ := json["medical_insurance_number"].(string)
  7440. advice.MedListCodg = med_list_codg
  7441. }
  7442. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7443. day := int64(json["day"].(float64))
  7444. advice.Day = day
  7445. }
  7446. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7447. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7448. advice.PrescribingNumberUnit = prescribingNumberUnit
  7449. }
  7450. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7451. advice_id := int64(json["advice_id"].(float64))
  7452. advice.ID = advice_id
  7453. if advice.ID > 0 {
  7454. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7455. if err == nil {
  7456. if hisAdvice.ID > 0 {
  7457. advice.ExecutionTime = hisAdvice.ExecutionTime
  7458. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7459. advice.ExecutionState = hisAdvice.ExecutionState
  7460. advice.CheckTime = hisAdvice.CheckTime
  7461. advice.Checker = hisAdvice.Checker
  7462. advice.CheckState = hisAdvice.CheckState
  7463. advice.StartTime = hisAdvice.StartTime
  7464. advice.HospApprFlag = hisAdvice.HospApprFlag
  7465. advice.IsMedicine = hisAdvice.IsMedicine
  7466. if hisAdvice.UserOrgId == 10028 {
  7467. 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 {
  7468. advice.ExecutionTime = 0
  7469. advice.ExecutionStaff = 0
  7470. advice.ExecutionState = 2
  7471. advice.CheckTime = 0
  7472. advice.Checker = 0
  7473. advice.CheckState = 2
  7474. }
  7475. } else {
  7476. 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 {
  7477. advice.ExecutionTime = 0
  7478. advice.ExecutionStaff = 0
  7479. advice.ExecutionState = 2
  7480. advice.CheckTime = 0
  7481. advice.Checker = 0
  7482. advice.CheckState = 2
  7483. //advice.UpdatedTime = time.Now().Unix()
  7484. advice.CreatedTime = hisAdvice.CreatedTime
  7485. advice.UpdatedTime = time.Now().Unix()
  7486. } else {
  7487. advice.CreatedTime = hisAdvice.CreatedTime
  7488. advice.UpdatedTime = hisAdvice.UpdatedTime
  7489. }
  7490. }
  7491. //advice.Groupno = hisAdvice.Groupno
  7492. } else {
  7493. advice.IsMedicine = 0
  7494. ctime := time.Now().Unix()
  7495. advice.CreatedTime = ctime
  7496. advice.UpdatedTime = ctime
  7497. }
  7498. }
  7499. } else {
  7500. advice.IsMedicine = 0
  7501. ctime := time.Now().Unix()
  7502. advice.CreatedTime = ctime
  7503. advice.UpdatedTime = ctime
  7504. }
  7505. }
  7506. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7507. //
  7508. //if drugStockConfig.IsOpen == 1 {
  7509. //
  7510. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7511. // if advice.ID == 0 { //医嘱不存在
  7512. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7513. // drug.Total = drug.Total - advice.PrescribingNumber
  7514. // service.UpdateBaseDrugLib(&drug)
  7515. //
  7516. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7517. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7518. // drug.Total = drug.Total - num
  7519. // service.UpdateBaseDrugLib(&drug)
  7520. // }
  7521. //
  7522. // } else if advice.ID > 0 { //医嘱存在
  7523. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7524. // var num float64
  7525. //
  7526. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7527. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7528. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7529. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7530. // drug.Total = drug.Total + num
  7531. // service.UpdateBaseDrugLib(&drug)
  7532. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7533. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7534. // drug.Total = drug.Total - num
  7535. // service.UpdateBaseDrugLib(&drug)
  7536. // }
  7537. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7538. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7539. // if num2 > advice.PrescribingNumber {
  7540. // num = num2 - advice.PrescribingNumber
  7541. // drug.Total = drug.Total + num
  7542. // service.UpdateBaseDrugLib(&drug)
  7543. // } else if num2 < advice.PrescribingNumber {
  7544. // num = advice.PrescribingNumber - num2
  7545. // drug.Total = drug.Total - num
  7546. // service.UpdateBaseDrugLib(&drug)
  7547. // }
  7548. //
  7549. // }
  7550. //
  7551. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7552. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7553. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7554. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7555. // if num1 > num2 {
  7556. // num = num1 - num2
  7557. // drug.Total = drug.Total + num
  7558. // service.UpdateBaseDrugLib(&drug)
  7559. // } else if num1 < num2 {
  7560. // num = num2 - num1
  7561. // drug.Total = drug.Total - num
  7562. // service.UpdateBaseDrugLib(&drug)
  7563. // }
  7564. //
  7565. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7566. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7567. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7568. // if hisAdvice.PrescribingNumber > num2 {
  7569. // num = hisAdvice.PrescribingNumber - num2
  7570. // drug.Total = drug.Total + num
  7571. // service.UpdateBaseDrugLib(&drug)
  7572. // } else if num2 < advice.PrescribingNumber {
  7573. // num = num2 - hisAdvice.PrescribingNumber
  7574. // drug.Total = drug.Total - num
  7575. // service.UpdateBaseDrugLib(&drug)
  7576. // }
  7577. //
  7578. // }
  7579. // }
  7580. // }
  7581. //}
  7582. //
  7583. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7584. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7585. // advice.ExecutionTime = execution_time
  7586. //}
  7587. //
  7588. //
  7589. //
  7590. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7591. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7592. // advice.ExecutionStaff = execution_staff
  7593. //}
  7594. //
  7595. //
  7596. //
  7597. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7598. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7599. // advice.ExecutionState = execution_state
  7600. //}
  7601. //
  7602. //
  7603. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7604. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7605. // advice.CheckTime = check_time
  7606. //}
  7607. //
  7608. //
  7609. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7610. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7611. // advice.CheckState = check_state
  7612. //}
  7613. //
  7614. //
  7615. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7616. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7617. // advice.Checker = checker
  7618. //}
  7619. //
  7620. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7621. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7622. // advice.StartTime = start_time
  7623. //}
  7624. return 0
  7625. }
  7626. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7627. project.ExecutionStaff = 0
  7628. project.ExecutionState = 2
  7629. project.ExecutionTime = 0
  7630. project.Checker = 0
  7631. project.CheckState = 2
  7632. project.CheckTime = 0
  7633. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7634. id := int64(json["id"].(float64))
  7635. project.ID = id
  7636. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7637. project.ExecutionStaff = temp_project.ExecutionStaff
  7638. project.ExecutionState = temp_project.ExecutionState
  7639. project.ExecutionTime = temp_project.ExecutionTime
  7640. project.Checker = temp_project.Checker
  7641. project.CheckState = temp_project.CheckState
  7642. project.CheckTime = temp_project.CheckTime
  7643. project.TeamId = temp_project.TeamId
  7644. }
  7645. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7646. types := int64(json["type"].(float64))
  7647. project.Type = types
  7648. }
  7649. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7650. project_id := int64(json["project_id"].(float64))
  7651. project.ProjectId = project_id
  7652. }
  7653. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7654. team_id := int64(json["team_id"].(float64))
  7655. project.TeamId = team_id
  7656. }
  7657. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7658. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7659. project.Price = price
  7660. }
  7661. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7662. total, _ := json["total"].(string)
  7663. //totals, _ := strconv.ParseInt(total, 10, 64)
  7664. project.Count = total
  7665. }
  7666. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7667. medical_code, _ := json["medical_code"].(string)
  7668. project.MedListCodg = medical_code
  7669. }
  7670. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7671. single_dose, _ := json["single_dose"].(string)
  7672. project.SingleDose = single_dose
  7673. }
  7674. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7675. delivery_way, _ := json["delivery_way"].(string)
  7676. project.DeliveryWay = delivery_way
  7677. }
  7678. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7679. execution_frequency, _ := json["execution_frequency"].(string)
  7680. project.ExecutionFrequency = execution_frequency
  7681. }
  7682. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7683. remark, _ := json["remark"].(string)
  7684. project.Remark = remark
  7685. }
  7686. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7687. day, _ := json["number_days"].(string)
  7688. project.Day = day
  7689. }
  7690. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7691. unit, _ := json["unit"].(string)
  7692. project.Unit = unit
  7693. }
  7694. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7695. // frequency_type := int64(json["frequency_type"].(float64))
  7696. // project.FrequencyType = frequency_type
  7697. //}
  7698. //
  7699. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7700. // day_count := int64(json["day_count"].(float64))
  7701. // project.DayCount = day_count
  7702. //}
  7703. //
  7704. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7705. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7706. // week_day, _ := json["week_day"].(string)
  7707. // project.WeekDay = week_day
  7708. //}
  7709. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7710. //
  7711. //if project.ID == 0 {
  7712. // if stockConfig.IsOpen == 1 {
  7713. // if project.Type == 3 {
  7714. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7715. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7716. // good.Total = good.Total - f_count
  7717. // service.UpdateGoodInfo(&good)
  7718. // }
  7719. // }
  7720. //
  7721. //} else {
  7722. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7723. //
  7724. // if stockConfig.IsOpen == 1 {
  7725. // if project.Type == 3 {
  7726. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7727. // if project.Count < temp_project.Count {
  7728. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7729. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7730. //
  7731. // other_count := f_count_two - f_count_one
  7732. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7733. // good.Total = good.Total + other_count_two
  7734. // service.UpdateGoodInfo(&good)
  7735. // } else if project.Count > temp_project.Count {
  7736. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7737. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7738. //
  7739. // other_count := f_count_one - f_count_two
  7740. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7741. // good.Total = good.Total - other_count_two
  7742. // service.UpdateGoodInfo(&good)
  7743. // }
  7744. //
  7745. // }
  7746. // }
  7747. //
  7748. //}
  7749. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7750. id := int64(json["id"].(float64))
  7751. if id > 0 {
  7752. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7753. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  7754. fmt.Println("666666")
  7755. project.Mtime = time.Now().Unix()
  7756. project.Ctime = temp_project.Ctime
  7757. } else {
  7758. project.Mtime = temp_project.Mtime
  7759. project.Ctime = temp_project.Ctime
  7760. }
  7761. } else {
  7762. ctime := time.Now().Unix()
  7763. project.Mtime = ctime
  7764. project.Ctime = ctime
  7765. }
  7766. }
  7767. return 0
  7768. }
  7769. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7770. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7771. id := int64(json["id"].(float64))
  7772. additionalCharge.ID = id
  7773. }
  7774. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7775. item_id := int64(json["item_id"].(float64))
  7776. additionalCharge.ItemId = item_id
  7777. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7778. if config.ID > 0 {
  7779. if len(config.Code) > 0 {
  7780. additionalCharge.MedListCodg = config.Code
  7781. }
  7782. }
  7783. }
  7784. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7785. // price := int64(json["price"].(float64))
  7786. // formatInt_price := strconv.FormatInt(price, 10)
  7787. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7788. // additionalCharge.Price = float_price
  7789. // }
  7790. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7791. // price := int64(json["price"].(float64))
  7792. // formatInt_price := strconv.FormatInt(price, 10)
  7793. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7794. // additionalCharge.Price = float_price
  7795. //}
  7796. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7797. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7798. additionalCharge.Price = price
  7799. }
  7800. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  7801. count, _ := json["count"].(string)
  7802. counts, _ := strconv.ParseInt(count, 10, 64)
  7803. additionalCharge.Count = counts
  7804. }
  7805. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  7806. item_name, _ := json["item_name"].(string)
  7807. additionalCharge.ItemName = item_name
  7808. }
  7809. return 0
  7810. }
  7811. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  7812. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7813. utils.ErrorLog("drug_name")
  7814. return enums.ErrorCodeParamWrong
  7815. }
  7816. adviceName, _ := json["drug_name"].(string)
  7817. if len(adviceName) == 0 {
  7818. utils.ErrorLog("len(advice_name) == 0")
  7819. return enums.ErrorCodeParamWrong
  7820. }
  7821. advice.AdviceName = adviceName
  7822. adviceDesc, _ := json["advice_desc"].(string)
  7823. advice.AdviceDesc = adviceDesc
  7824. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7825. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7826. advice.DrugSpec = drugSpec
  7827. }
  7828. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7829. remark, _ := json["remark"].(string)
  7830. advice.Remark = remark
  7831. }
  7832. if json["id"] == nil {
  7833. advice.DrugId = 0
  7834. } else {
  7835. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7836. drug_id := int64(json["id"].(float64))
  7837. advice.DrugId = drug_id
  7838. }
  7839. }
  7840. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7841. groupno := int64(json["groupno"].(float64))
  7842. advice.Groupno = groupno
  7843. }
  7844. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7845. drugSpecUnit, _ := json["min_unit"].(string)
  7846. advice.DrugSpecUnit = drugSpecUnit
  7847. }
  7848. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7849. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7850. advice.SingleDose = singleDose
  7851. }
  7852. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7853. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7854. advice.SingleDoseUnit = singleDoseUnit
  7855. }
  7856. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7857. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7858. advice.PrescribingNumber = prescribingNumber
  7859. }
  7860. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7861. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7862. advice.PrescribingNumberUnit = prescribingNumberUnit
  7863. }
  7864. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7865. deliveryWay, _ := json["delivery_way"].(string)
  7866. advice.DeliveryWay = deliveryWay
  7867. }
  7868. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7869. executionFrequency, _ := json["execution_frequency"].(string)
  7870. advice.ExecutionFrequency = executionFrequency
  7871. }
  7872. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7873. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7874. advice.Price = price
  7875. }
  7876. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7877. med_list_codg, _ := json["medical_insurance_number"].(string)
  7878. advice.MedListCodg = med_list_codg
  7879. }
  7880. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7881. day := int64(json["day"].(float64))
  7882. advice.Day = day
  7883. }
  7884. advice.FrequencyType = 1
  7885. return 0
  7886. }
  7887. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  7888. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7889. types := int64(json["type"].(float64))
  7890. project.Type = types
  7891. }
  7892. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7893. project_id := int64(json["project_id"].(float64))
  7894. project.ProjectId = project_id
  7895. }
  7896. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7897. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7898. project.Price = price
  7899. }
  7900. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7901. total, _ := json["total"].(string)
  7902. //totals, _ := strconv.ParseInt(total, 10, 64)
  7903. project.Count = total
  7904. }
  7905. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7906. medical_code, _ := json["medical_code"].(string)
  7907. project.MedListCodg = medical_code
  7908. }
  7909. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7910. single_dose, _ := json["single_dose"].(string)
  7911. project.SingleDose = single_dose
  7912. }
  7913. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7914. delivery_way, _ := json["delivery_way"].(string)
  7915. project.DeliveryWay = delivery_way
  7916. }
  7917. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7918. execution_frequency, _ := json["execution_frequency"].(string)
  7919. project.ExecutionFrequency = execution_frequency
  7920. }
  7921. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7922. remark, _ := json["remark"].(string)
  7923. project.Remark = remark
  7924. }
  7925. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7926. day, _ := json["number_days"].(string)
  7927. project.Day = day
  7928. }
  7929. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7930. unit, _ := json["unit"].(string)
  7931. project.Unit = unit
  7932. }
  7933. project.FrequencyType = 1
  7934. return 0
  7935. }
  7936. func (c *HisApiController) GetHisOrderListTwo() {
  7937. start_time := c.GetString("start_time")
  7938. end_time := c.GetString("end_time")
  7939. timeLayout := "2006-01-02"
  7940. loc, _ := time.LoadLocation("Local")
  7941. var startTime int64
  7942. if len(start_time) > 0 {
  7943. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7944. if err != nil {
  7945. //fmt.Println(err)
  7946. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7947. return
  7948. }
  7949. startTime = theTime.Unix()
  7950. }
  7951. var endTime int64
  7952. if len(end_time) > 0 {
  7953. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7954. if err != nil {
  7955. utils.ErrorLog(err.Error())
  7956. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7957. return
  7958. }
  7959. endTime = theTime.Unix()
  7960. }
  7961. adminUser := c.GetAdminUserInfo()
  7962. org_id := adminUser.CurrentOrgId
  7963. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  7964. if err == nil {
  7965. c.ServeSuccessJSON(map[string]interface{}{
  7966. "order2": order,
  7967. })
  7968. } else {
  7969. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7970. return
  7971. }
  7972. }
  7973. func (c *HisApiController) GetHisOrderList() {
  7974. page, _ := c.GetInt64("page", -1)
  7975. limit, _ := c.GetInt64("limit", -1)
  7976. start_time := c.GetString("start_time")
  7977. end_time := c.GetString("end_time")
  7978. types, _ := c.GetInt64("type", 0)
  7979. keywords := c.GetString("keywords")
  7980. p_type, _ := c.GetInt64("p_type", 0)
  7981. sort_type, _ := c.GetInt64("sort_type", 0)
  7982. charge_type, _ := c.GetInt64("charge_type", 0)
  7983. sch_type, _ := c.GetInt64("sch_type", 0)
  7984. zone_type, _ := c.GetInt64("zone_type", 0)
  7985. med_type, _ := c.GetInt64("med_type", 0)
  7986. timeLayout := "2006-01-02"
  7987. loc, _ := time.LoadLocation("Local")
  7988. var startTime int64
  7989. if len(start_time) > 0 {
  7990. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7991. if err != nil {
  7992. //fmt.Println(err)
  7993. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7994. return
  7995. }
  7996. startTime = theTime.Unix()
  7997. }
  7998. var endTime int64
  7999. if len(end_time) > 0 {
  8000. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8001. if err != nil {
  8002. utils.ErrorLog(err.Error())
  8003. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8004. return
  8005. }
  8006. endTime = theTime.Unix()
  8007. }
  8008. adminUser := c.GetAdminUserInfo()
  8009. org_id := adminUser.CurrentOrgId
  8010. 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)
  8011. for _, item := range order {
  8012. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  8013. item.DoctorName = info.Doctor
  8014. item.DepartmentName = info.XtHisDepartment.Name
  8015. }
  8016. if err == nil {
  8017. c.ServeSuccessJSON(map[string]interface{}{
  8018. "order": order,
  8019. "total": total,
  8020. })
  8021. } else {
  8022. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8023. return
  8024. }
  8025. }
  8026. func (c *HisApiController) GetHisOrder() {
  8027. patient_id, _ := c.GetInt64("patient_id", 0)
  8028. number := c.GetString("number")
  8029. adminInfo := c.GetAdminUserInfo()
  8030. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  8031. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  8032. if err == nil {
  8033. c.ServeSuccessJSON(map[string]interface{}{
  8034. "order": order,
  8035. "prescription": prescriptions,
  8036. })
  8037. } else {
  8038. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8039. return
  8040. }
  8041. }
  8042. func (c *HisApiController) GetHisPrescriptionList() {
  8043. record_date := c.GetString("record_date")
  8044. keywords := c.GetString("keywords")
  8045. page, _ := c.GetInt64("page")
  8046. limit, _ := c.GetInt64("limit")
  8047. sch_type, _ := c.GetInt64("sch_type")
  8048. timeLayout := "2006-01-02"
  8049. loc, _ := time.LoadLocation("Local")
  8050. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8051. if err != nil {
  8052. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8053. return
  8054. }
  8055. recordDateTime := theTime.Unix()
  8056. adminInfo := c.GetAdminUserInfo()
  8057. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  8058. //adminInfo := c.GetAdminUserInfo()
  8059. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  8060. //fmt.Println(prescriptionOrder)
  8061. if err == nil {
  8062. c.ServeSuccessJSON(map[string]interface{}{
  8063. "order": prescriptionOrder,
  8064. "total": total,
  8065. })
  8066. } else {
  8067. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8068. return
  8069. }
  8070. }
  8071. func (c *HisApiController) GetHisPrescriptionInfo() {
  8072. id, _ := c.GetInt64("id")
  8073. adminInfo := c.GetAdminUserInfo()
  8074. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  8075. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  8076. if err == nil {
  8077. c.ServeSuccessJSON(map[string]interface{}{
  8078. "order": prescriptionOrder,
  8079. "prescription": prescription,
  8080. })
  8081. } else {
  8082. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8083. return
  8084. }
  8085. }
  8086. func (c *HisApiController) GetMedicalInsuranceConfig() {
  8087. adminUser := c.GetAdminUserInfo()
  8088. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  8089. c.ServeSuccessJSON(map[string]interface{}{
  8090. "config": config,
  8091. })
  8092. }
  8093. type ResultTwo struct {
  8094. ErrMsg interface{} `json:"err_msg"`
  8095. InfRefmsgid string `json:"inf_refmsgid"`
  8096. Infcode int64 `json:"infcode"`
  8097. Output struct {
  8098. Baseinfo struct {
  8099. Age float64 `json:"age"`
  8100. Brdy string `json:"brdy"`
  8101. Certno string `json:"certno"`
  8102. Gend string `json:"gend"`
  8103. Naty string `json:"naty"`
  8104. PsnCertType string `json:"psn_cert_type"`
  8105. PsnName string `json:"psn_name"`
  8106. PsnNo string `json:"psn_no"`
  8107. } `json:"baseinfo"`
  8108. Idetinfo []interface{} `json:"idetinfo"`
  8109. Iinfo []struct {
  8110. Balc float64 `json:"balc"`
  8111. CvlservFlag string `json:"cvlserv_flag"`
  8112. EmpName string `json:"emp_name"`
  8113. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  8114. Insutype string `json:"insutype"`
  8115. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  8116. PausInsuDate interface{} `json:"paus_insu_date"`
  8117. PsnInsuDate string `json:"psn_insu_date"`
  8118. PsnInsuStas string `json:"psn_insu_stas"`
  8119. PsnType string `json:"psn_type"`
  8120. } `json:"insuinfo"`
  8121. } `json:"output"`
  8122. RefmsgTime string `json:"refmsg_time"`
  8123. RespondTime string `json:"respond_time"`
  8124. Signtype interface{} `json:"signtype"`
  8125. WarnInfo interface{} `json:"warn_info"`
  8126. }
  8127. type ResultThree struct {
  8128. Cainfo interface{} `json:"cainfo"`
  8129. ErrMsg interface{} `json:"err_msg"`
  8130. InfRefmsgid string `json:"inf_refmsgid"`
  8131. Infcode int64 `json:"infcode"`
  8132. Output struct {
  8133. Data struct {
  8134. IptOtpNo string `json:"ipt_otp_no"`
  8135. MdtrtID string `json:"mdtrt_id"`
  8136. PsnNo string `json:"psn_no"`
  8137. } `json:"data"`
  8138. } `json:"output"`
  8139. RefmsgTime string `json:"refmsg_time"`
  8140. RespondTime string `json:"respond_time"`
  8141. Signtype interface{} `json:"signtype"`
  8142. WarnMsg interface{} `json:"warn_msg"`
  8143. }
  8144. type ResultFour struct {
  8145. Cainfo string `json:"cainfo"`
  8146. ErrMsg string `json:"err_msg"`
  8147. InfRefmsgid string `json:"inf_refmsgid"`
  8148. Infcode int64 `json:"infcode"`
  8149. Output struct {
  8150. Result []struct {
  8151. BasMednFlag string `json:"bas_medn_flag"`
  8152. ChldMedcFlag string `json:"chld_medc_flag"`
  8153. ChrgitmLv string `json:"chrgitm_lv"`
  8154. Cnt float64 `json:"cnt"`
  8155. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  8156. DrtReimFlag string `json:"drt_reim_flag"`
  8157. FeedetlSn string `json:"feedetl_sn"`
  8158. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8159. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  8160. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8161. ListSpItemFlag string `json:"list_sp_item_flag"`
  8162. LmtUsedFlag string `json:"lmt_used_flag"`
  8163. MedChrgitmType string `json:"med_chrgitm_type"`
  8164. Memo string `json:"memo"`
  8165. OverlmtAmt float64 `json:"overlmt_amt"`
  8166. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8167. Pric float64 `json:"pric"`
  8168. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  8169. SelfpayProp float64 `json:"selfpay_prop"`
  8170. } `json:"result"`
  8171. } `json:"output"`
  8172. RefmsgTime string `json:"refmsg_time"`
  8173. RespondTime string `json:"respond_time"`
  8174. Signtype string `json:"signtype"`
  8175. WarnMsg string `json:"warn_msg"`
  8176. }
  8177. type ResultFive struct {
  8178. Insutype string `json:"insutype"`
  8179. }
  8180. type ResultSix struct {
  8181. Cainfo interface{} `json:"cainfo"`
  8182. ErrMsg interface{} `json:"err_msg"`
  8183. InfRefmsgid string `json:"inf_refmsgid"`
  8184. Infcode int64 `json:"infcode"`
  8185. Output struct {
  8186. } `json:"output"`
  8187. RefmsgTime string `json:"refmsg_time"`
  8188. RespondTime string `json:"respond_time"`
  8189. Signtype interface{} `json:"signtype"`
  8190. WarnMsg interface{} `json:"warn_msg"`
  8191. }
  8192. type ResultSeven struct {
  8193. Cainfo string `json:"cainfo"`
  8194. ErrMsg string `json:"err_msg"`
  8195. InfRefmsgid string `json:"inf_refmsgid"`
  8196. Infcode int64 `json:"infcode"`
  8197. Output struct {
  8198. Setldetail []interface{} `json:"setldetail"`
  8199. Setlinfo struct {
  8200. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8201. AcctPay float64 `json:"acct_pay"`
  8202. ActPayDedc float64 `json:"act_pay_dedc"`
  8203. Age float64 `json:"age"`
  8204. Balc float64 `json:"balc"`
  8205. Brdy string `json:"brdy"`
  8206. Certno string `json:"certno"`
  8207. ClrOptins string `json:"clr_optins"`
  8208. ClrType string `json:"clr_type"`
  8209. ClrWay string `json:"clr_way"`
  8210. CvlservFlag string `json:"cvlserv_flag"`
  8211. CvlservPay float64 `json:"cvlserv_pay"`
  8212. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8213. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8214. Gend string `json:"gend"`
  8215. HifesPay float64 `json:"hifes_pay"`
  8216. HifmiPay float64 `json:"hifmi_pay"`
  8217. HifobPay float64 `json:"hifob_pay"`
  8218. HifpPay float64 `json:"hifp_pay"`
  8219. HospPartAmt float64 `json:"hosp_part_amt"`
  8220. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8221. Insutype string `json:"insutype"`
  8222. MafPay float64 `json:"maf_pay"`
  8223. MdtrtCertType string `json:"mdtrt_cert_type"`
  8224. MdtrtID string `json:"mdtrt_id"`
  8225. MedType string `json:"med_type"`
  8226. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8227. MedinsSetlID string `json:"medins_setl_id"`
  8228. Naty string `json:"naty"`
  8229. OthPay float64 `json:"oth_pay"`
  8230. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8231. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8232. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8233. PsnCashPay float64 `json:"psn_cash_pay"`
  8234. PsnCertType string `json:"psn_cert_type"`
  8235. PsnName string `json:"psn_name"`
  8236. PsnNo string `json:"psn_no"`
  8237. PsnPartAmt float64 `json:"psn_part_amt"`
  8238. PsnType string `json:"psn_type"`
  8239. SetlID string `json:"setl_id"`
  8240. SetlTime string `json:"setl_time"`
  8241. } `json:"setlinfo"`
  8242. } `json:"output"`
  8243. RefmsgTime string `json:"refmsg_time"`
  8244. RespondTime string `json:"respond_time"`
  8245. Signtype interface{} `json:"signtype"`
  8246. WarnMsg interface{} `json:"warn_msg"`
  8247. }
  8248. type ResultEight struct {
  8249. Cainfo string `json:"cainfo"`
  8250. ErrMsg string `json:"err_msg"`
  8251. InfRefmsgid string `json:"inf_refmsgid"`
  8252. Infcode int64 `json:"infcode"`
  8253. Output struct {
  8254. Stmtinfo struct {
  8255. SetlOptins string `json:"setl_optins"`
  8256. StmtRslt string `json:"stmt_rslt"`
  8257. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  8258. } `json:"stmtinfo"`
  8259. } `json:"output"`
  8260. RefmsgTime string `json:"refmsg_time"`
  8261. RespondTime string `json:"respond_time"`
  8262. Signtype interface{} `json:"signtype"`
  8263. WarnMsg interface{} `json:"warn_msg"`
  8264. }
  8265. type ResultNine struct {
  8266. Cainfo string `json:"cainfo"`
  8267. ErrMsg string `json:"err_msg"`
  8268. InfRefmsgid string `json:"inf_refmsgid"`
  8269. Infcode int64 `json:"infcode"`
  8270. Output struct {
  8271. FileQuryNo string `json:"file_qury_no"`
  8272. } `json:"output"`
  8273. RefmsgTime string `json:"refmsg_time"`
  8274. RespondTime string `json:"respond_time"`
  8275. Signtype interface{} `json:"signtype"`
  8276. WarnMsg interface{} `json:"warn_msg"`
  8277. }
  8278. type ResultTen struct {
  8279. Cainfo string `json:"cainfo"`
  8280. ErrMsg string `json:"err_msg"`
  8281. InfRefmsgid string `json:"inf_refmsgid"`
  8282. Infcode int64 `json:"infcode"`
  8283. Output struct {
  8284. DldEndtime string `json:"dld_endtime"`
  8285. FileQuryNo string `json:"file_qury_no"`
  8286. Filename string `json:"filename"`
  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 ResultEleven 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. Setlinfo struct {
  8300. FixmedinsName string `json:"fixmedins_name"`
  8301. FixmedinsCode string `json:"fixmedins_code"`
  8302. PsnNo string `json:"psn_no"`
  8303. PsnName string `json:"psn_name"`
  8304. HifobPay float64 `json:"hifob_pay"`
  8305. Gend string `json:"gend"`
  8306. Brdy string `json:"brdy"`
  8307. PsnCertType string `json:"psn_cert_type"`
  8308. PsnType string `json:"psn_type"`
  8309. EmpName string `json:"emp_name"`
  8310. Certno string `json:"certno"`
  8311. Insutype string `json:"insutype"`
  8312. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8313. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8314. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8315. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8316. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8317. ActPayDedc float64 `json:"act_pay_dedc"`
  8318. HifpPay float64 `json:"hifp_pay"`
  8319. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8320. CvlservPay float64 `json:"cvlserv_pay"`
  8321. HifesPay float64 `json:"hifes_pay"`
  8322. HifmiPay float64 `json:"hifmi_pay"`
  8323. MafPay float64 `json:"maf_pay"`
  8324. OthPay float64 `json:"oth_pay"`
  8325. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8326. PsnPay float64 `json:"psn_pay"`
  8327. AcctPay float64 `json:"acct_pay"`
  8328. CashPayamt float64 `json:"cash_payamt"`
  8329. Balc float64 `json:"balc"`
  8330. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8331. MedinsSetlId string `json:"medins_setl_id"`
  8332. RefdSetlFlag string `json:"refd_setl_flag"`
  8333. SetlTime string `json:"setl_time"`
  8334. MedType string `json:"med_type"`
  8335. } `json:"setlinfo"`
  8336. } `json:"output"`
  8337. RefmsgTime string `json:"refmsg_time"`
  8338. RespondTime string `json:"respond_time"`
  8339. Signtype interface{} `json:"signtype"`
  8340. WarnMsg interface{} `json:"warn_msg"`
  8341. }
  8342. type Custom struct {
  8343. DetItemFeeSumamt string
  8344. Cut string
  8345. FeedetlSn string
  8346. Price string
  8347. MedListCodg string
  8348. Type int64
  8349. AdviceId int64
  8350. ProjectId int64
  8351. ItemId int64
  8352. }
  8353. // 获取个人信息----挂号-----上传就诊信息
  8354. func (c *HisApiController) GetRegisterInfo() {
  8355. id, _ := c.GetInt64("id")
  8356. record_time := c.GetString("record_time")
  8357. settlementValue, _ := c.GetInt64("settlement_value")
  8358. medical_insurance_card := c.GetString("medical_insurance_card")
  8359. name := c.GetString("name")
  8360. id_card_type, _ := c.GetInt64("id_card_type")
  8361. certificates, _ := c.GetInt64("certificates")
  8362. medical_care, _ := c.GetInt64("medical_care")
  8363. birthday := c.GetString("birthday")
  8364. age, _ := c.GetInt64("age")
  8365. id_card := c.GetString("id_card")
  8366. register_type, _ := c.GetInt64("register")
  8367. doctor, _ := c.GetInt64("doctor")
  8368. department, _ := c.GetInt64("department")
  8369. gender, _ := c.GetInt64("sex")
  8370. phone := c.GetString("phone")
  8371. registration_fee, _ := c.GetFloat("registration_fee")
  8372. medical_expenses, _ := c.GetFloat("medical_expenses")
  8373. social_type, _ := c.GetInt64("social_type")
  8374. //diagnosis_id, _ := c.GetInt64("diagnosis")
  8375. diagnosis_ids := c.GetString("diagnosis")
  8376. sick_type, _ := c.GetInt64("sick_type")
  8377. reg_type := c.GetString("p_type")
  8378. timeLayout := "2006-01-02"
  8379. loc, _ := time.LoadLocation("Local")
  8380. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  8381. birthUnix := birthdays.Unix()
  8382. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8383. if err != nil {
  8384. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8385. return
  8386. }
  8387. recordDateTime := theTime.Unix()
  8388. adminInfo := c.GetAdminUserInfo()
  8389. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  8390. if tempPatient.ID == 0 {
  8391. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  8392. return
  8393. }
  8394. var patient service.Patients
  8395. if id == 0 {
  8396. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  8397. } else {
  8398. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  8399. }
  8400. if patient.ID == 0 {
  8401. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  8402. return
  8403. }
  8404. if len(patient.IdCardNo) == 0 {
  8405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  8406. return
  8407. }
  8408. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  8409. if len(his) >= 1 {
  8410. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  8411. if len(his) >= 1 && order.ID == 0 {
  8412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  8413. return
  8414. }
  8415. }
  8416. timeStr := time.Now().Format("2006-01-02 15:04:05")
  8417. fmt.Println(timeStr)
  8418. timeArr := strings.Split(timeStr, " ")
  8419. fmt.Println(timeArr)
  8420. timeArrTwo := strings.Split(timeArr[0], "-")
  8421. timeArrThree := strings.Split(timeArr[1], ":")
  8422. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  8423. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  8424. if len(lists) == 0 {
  8425. var hisPatient models.XtHisPatient
  8426. hisPatient = models.XtHisPatient{
  8427. Name: name,
  8428. Age: age,
  8429. Gender: gender,
  8430. Birthday: birthUnix,
  8431. Phone: phone,
  8432. MedicalTreatmentType: medical_care,
  8433. IdType: certificates,
  8434. IdCardNo: id_card,
  8435. BalanceAccountsType: settlementValue,
  8436. SocialType: social_type,
  8437. MedicalInsuranceNumber: medical_insurance_card,
  8438. RegisterType: register_type,
  8439. RegisterCost: registration_fee,
  8440. TreatmentCost: medical_expenses,
  8441. AdminUserId: adminInfo.AdminUser.Id,
  8442. UserOrgId: adminInfo.CurrentOrgId,
  8443. Status: 1,
  8444. RecordDate: recordDateTime,
  8445. IsReturn: 1,
  8446. PatientId: patient.ID,
  8447. Ctime: time.Now().Unix(),
  8448. Mtime: time.Now().Unix(),
  8449. Number: str,
  8450. IdCardType: id_card_type,
  8451. Departments: department,
  8452. Doctor: doctor,
  8453. PType: reg_type,
  8454. Diagnosis: diagnosis_ids,
  8455. SickType: sick_type,
  8456. }
  8457. service.CreateHisPatient(&hisPatient)
  8458. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  8459. c.ServeSuccessJSON(map[string]interface{}{
  8460. "his_info": hisPatient,
  8461. })
  8462. } else {
  8463. //chrgBchno := rand.Intn(1000000) + 10000
  8464. var hisPatient models.XtHisPatient
  8465. hisPatient = models.XtHisPatient{
  8466. Name: name,
  8467. Age: age,
  8468. Gender: gender,
  8469. Birthday: birthUnix,
  8470. Phone: phone,
  8471. MedicalTreatmentType: medical_care,
  8472. IdType: certificates,
  8473. IdCardNo: id_card,
  8474. BalanceAccountsType: settlementValue,
  8475. SocialType: social_type,
  8476. MedicalInsuranceNumber: medical_insurance_card,
  8477. RegisterType: register_type,
  8478. RegisterCost: registration_fee,
  8479. TreatmentCost: medical_expenses,
  8480. AdminUserId: adminInfo.AdminUser.Id,
  8481. UserOrgId: adminInfo.CurrentOrgId,
  8482. Status: 1,
  8483. RecordDate: recordDateTime,
  8484. IsReturn: 1,
  8485. PatientId: patient.ID,
  8486. Ctime: time.Now().Unix(),
  8487. Mtime: time.Now().Unix(),
  8488. Number: str,
  8489. IdCardType: id_card_type,
  8490. Departments: department,
  8491. Doctor: doctor,
  8492. PType: reg_type,
  8493. Diagnosis: diagnosis_ids,
  8494. SickType: sick_type,
  8495. }
  8496. service.CreateHisPatient(&hisPatient)
  8497. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  8498. c.ServeSuccessJSON(map[string]interface{}{
  8499. "his_info": hisPatient,
  8500. })
  8501. }
  8502. }
  8503. // 上传明细----结算
  8504. func (c *HisApiController) GetUploadInfo() {
  8505. id, _ := c.GetInt64("id")
  8506. record_time := c.GetString("record_time")
  8507. his_patient_id, _ := c.GetInt64("his_patient_id")
  8508. oth_desc := c.GetString("oth_desc")
  8509. pay_way, _ := c.GetInt64("pay_way")
  8510. pay_ways := c.GetString("pay_ways")
  8511. pay_price, _ := c.GetFloat("pay_price")
  8512. pay_card_no := c.GetString("pay_card_no")
  8513. discount_price, _ := c.GetFloat("discount_price")
  8514. preferential_price, _ := c.GetFloat("preferential_price")
  8515. reality_price, _ := c.GetFloat("reality_price")
  8516. found_price, _ := c.GetFloat("found_price")
  8517. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  8518. private_price, _ := c.GetFloat("private_price")
  8519. timeLayout := "2006-01-02"
  8520. loc, _ := time.LoadLocation("Local")
  8521. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  8522. fapiao_code := c.GetString("fapiao_code")
  8523. fapiao_number := c.GetString("fapiao_number")
  8524. diagnosis_id := c.GetString("diagnosis")
  8525. sick_type, _ := c.GetInt64("sick_type")
  8526. reg_type, _ := c.GetInt64("p_type")
  8527. order_id, _ := c.GetInt64("order_id")
  8528. cash_pay := c.GetString("cash_pay")
  8529. wechat_pay := c.GetString("wechat_pay")
  8530. ali_pay := c.GetString("ali_pay")
  8531. jifen_pay := c.GetString("jifen_pay")
  8532. band_card_pay := c.GetString("band_card_pay")
  8533. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  8534. tmp_decimal := c.GetString("tmp_decimal")
  8535. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  8536. var decimal float64 //本次使用的押金
  8537. var errmsg error
  8538. tx := service.XTWriteDB().Begin() //开了事务
  8539. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  8540. defer func() {
  8541. if errmsg != nil {
  8542. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  8543. tx.Rollback()
  8544. } else {
  8545. tx.Commit()
  8546. }
  8547. }()
  8548. fmt.Println("dec_way", dec_way)
  8549. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  8550. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  8551. return
  8552. }
  8553. if len(tmp_decimal) > 0 {
  8554. if tmp_decimal[0] == 45 {
  8555. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  8556. return
  8557. }
  8558. }
  8559. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  8560. fmt.Println(errs)
  8561. decimal = tt
  8562. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  8563. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  8564. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8565. if err != nil {
  8566. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8567. return
  8568. }
  8569. recordDateTime := theTime.Unix()
  8570. adminUser := c.GetAdminUserInfo()
  8571. var prescriptions []*models.HisPrescription
  8572. var prescriptionsOne []*models.HisPrescription
  8573. var start_time int64
  8574. var end_time int64
  8575. ids_str := c.GetString("ids")
  8576. ids_arr := strings.Split(ids_str, ",")
  8577. if tempOrder.ID == 0 {
  8578. if settle_accounts_type == 1 { //日结
  8579. fmt.Println(reg_type)
  8580. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  8581. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  8582. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  8583. } else {
  8584. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8585. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8586. }
  8587. } else { //月结
  8588. start_time_str := c.GetString("start_time")
  8589. end_time_str := c.GetString("end_time")
  8590. timeLayout := "2006-01-02"
  8591. loc, _ := time.LoadLocation("Local")
  8592. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  8593. if err != nil {
  8594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8595. return
  8596. }
  8597. recordStartTime := theStartTime.Unix()
  8598. start_time = recordStartTime
  8599. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  8600. if err != nil {
  8601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8602. return
  8603. }
  8604. recordEndTime := theEndTime.Unix()
  8605. end_time = recordEndTime
  8606. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  8607. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8608. }
  8609. var goods []*models.DialysisBeforePrepareGoods
  8610. var newGoods []*models.NewDialysisBeforePrepareGoods
  8611. var oldGoods []*models.OldDialysisBeforePrepareGoods
  8612. var infos []*models.HisDoctorAdviceInfo
  8613. var infoList []*models.HisDoctorAdviceInfo
  8614. var hisAdvice []*models.HisDoctorAdviceInfo
  8615. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  8616. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  8617. //判断库存不足
  8618. //结算出库开关
  8619. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  8620. if settConfig.IsOpen == 1 {
  8621. //判断库存的地方
  8622. for _, info := range prescriptions {
  8623. if info.Type == 1 {
  8624. infos = append(infos, info.HisDoctorAdviceInfo...)
  8625. }
  8626. if info.Type == 2 {
  8627. for _, sumItem := range info.HisPrescriptionProject {
  8628. if sumItem.Type == 3 {
  8629. var good models.DialysisBeforePrepareGoods
  8630. var newGood models.NewDialysisBeforePrepareGoods
  8631. good.GoodId = sumItem.GoodInfo.ID
  8632. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8633. count, _ := strconv.Atoi(sumItem.Count)
  8634. good.Count = int64(count)
  8635. good.StorehouseId = houseConfig.StorehouseOutInfo
  8636. good.ProjectId = sumItem.ID
  8637. goods = append(goods, &good)
  8638. newGood.GoodId = sumItem.GoodInfo.ID
  8639. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8640. count2, _ := strconv.Atoi(sumItem.Count)
  8641. newGood.Count = int64(count2)
  8642. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8643. newGood.ProjectId = sumItem.ID
  8644. newGoods = append(newGoods, &newGood)
  8645. }
  8646. }
  8647. }
  8648. }
  8649. for _, info := range prescriptionsOne {
  8650. if info.Type == 1 {
  8651. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  8652. }
  8653. if info.Type == 2 {
  8654. for _, sumItem := range info.HisPrescriptionProject {
  8655. if sumItem.Type == 3 {
  8656. var newGood models.NewDialysisBeforePrepareGoods
  8657. newGood.GoodId = sumItem.GoodInfo.ID
  8658. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8659. count2, _ := strconv.Atoi(sumItem.Count)
  8660. newGood.Count = int64(count2)
  8661. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8662. newGood.ProjectId = sumItem.ID
  8663. newGoodOne = append(newGoodOne, &newGood)
  8664. }
  8665. }
  8666. }
  8667. }
  8668. //判断
  8669. for _, itemOne := range infos {
  8670. for _, itemTwo := range hisAdvice {
  8671. if itemOne.DrugId == itemTwo.DrugId {
  8672. itemTwo.Child = append(itemTwo.Child, itemOne)
  8673. }
  8674. }
  8675. }
  8676. for _, itemTwo := range hisAdvice {
  8677. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  8678. var sum_out_count int64
  8679. for _, itemThree := range itemTwo.Child {
  8680. var prescribing_number int64
  8681. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8682. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8683. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8684. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8685. }
  8686. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8687. prescribing_number = parseIntPrescribingNumber
  8688. }
  8689. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8690. prescribing_number = parseIntPrescribingNumber
  8691. }
  8692. sum_out_count += prescribing_number
  8693. }
  8694. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  8695. if sum_out_count > drugStockOut.FlushCount {
  8696. c.ServeSuccessJSON(map[string]interface{}{
  8697. "msg": "2",
  8698. "drug": medical,
  8699. })
  8700. return
  8701. }
  8702. }
  8703. for _, itemOne := range newGoods {
  8704. for _, item := range newGoodOne {
  8705. if itemOne.GoodId == item.GoodId {
  8706. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  8707. }
  8708. }
  8709. }
  8710. for _, item := range newGoodOne {
  8711. var sum_out_count_one int64
  8712. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  8713. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  8714. sum_out_count_one += itemOne.Count
  8715. }
  8716. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8717. fmt.Println("sum_out_count_one", sum_out_count_one)
  8718. fmt.Println("list.FlushCount", list.FlushCount)
  8719. if sum_out_count_one > list.FlushCount {
  8720. c.ServeSuccessJSON(map[string]interface{}{
  8721. "msg": "3",
  8722. "good": good,
  8723. })
  8724. return
  8725. }
  8726. }
  8727. }
  8728. timestamp := time.Now().Unix()
  8729. tempTime := time.Unix(timestamp, 0)
  8730. timeFormat := tempTime.Format("20060102150405")
  8731. chrgBchno := rand.Intn(100000) + 10000
  8732. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  8733. strconv.FormatInt(his.PatientId, 10)
  8734. var ids []int64
  8735. for _, item := range prescriptions {
  8736. ids = append(ids, item.ID)
  8737. }
  8738. var total float64
  8739. for _, item := range prescriptions {
  8740. fmt.Println(item)
  8741. if item.Type == 1 { //药品
  8742. for _, subItem := range item.HisDoctorAdviceInfo {
  8743. total = total + (subItem.Price * subItem.PrescribingNumber)
  8744. }
  8745. }
  8746. if item.Type == 2 { //项目
  8747. for _, subItem := range item.HisPrescriptionProject {
  8748. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8749. total = total + (subItem.Price * cnt)
  8750. }
  8751. }
  8752. for _, subItem := range item.HisAdditionalCharge {
  8753. total = total + (subItem.Price * float64(subItem.Count))
  8754. }
  8755. }
  8756. if reg_type == 1111 || reg_type == 1112 {
  8757. reg_type = 11
  8758. }
  8759. tm := time.Unix(time.Now().Unix(), 0)
  8760. allTotal := fmt.Sprintf("%.4f", total)
  8761. totals, _ := strconv.ParseFloat(allTotal, 64)
  8762. order := &models.HisOrder{
  8763. UserOrgId: adminUser.CurrentOrgId,
  8764. HisPatientId: his.ID,
  8765. PatientId: id,
  8766. SettleAccountsDate: recordDateTime,
  8767. Ctime: time.Now().Unix(),
  8768. Mtime: time.Now().Unix(),
  8769. Status: 1,
  8770. OrderStatus: 2,
  8771. MdtrtId: his.Number,
  8772. Number: chrg_bchno,
  8773. MedfeeSumamt: totals,
  8774. PayWay: pay_way,
  8775. PayWays: pay_ways,
  8776. PayPrice: pay_price,
  8777. MedType: strconv.Itoa(int(reg_type)),
  8778. PayCardNo: pay_card_no,
  8779. DiscountPrice: discount_price,
  8780. PreferentialPrice: preferential_price,
  8781. RealityPrice: reality_price,
  8782. FoundPrice: found_price,
  8783. MedicalInsurancePrice: medical_insurance_price,
  8784. PrivatePrice: private_price,
  8785. SettleEndTime: end_time,
  8786. SettleStartTime: start_time,
  8787. PsnPartAmt: totals,
  8788. PsnCashPay: totals,
  8789. SettleType: settle_accounts_type,
  8790. FaPiaoCode: fapiao_code,
  8791. FaPiaoNumber: fapiao_number,
  8792. Diagnosis: diagnosis_id,
  8793. PType: 2,
  8794. SetlTime: tm.Format("2006-01-02 15:04:05"),
  8795. Decimal: decimal,
  8796. OthDesc: oth_desc,
  8797. CashPay: cash_pay,
  8798. WechatPay: wechat_pay,
  8799. AliPay: ali_pay,
  8800. JifenPay: jifen_pay,
  8801. BandCardPay: band_card_pay,
  8802. Creator: adminUser.AdminUser.Id,
  8803. }
  8804. err = service.CreateOrderTX(order, tx)
  8805. if err != nil {
  8806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8807. return
  8808. }
  8809. var customs []*Custom
  8810. for _, item := range prescriptions {
  8811. if item.Type == 1 { //药品a
  8812. for _, subItem := range item.HisDoctorAdviceInfo {
  8813. cus := &Custom{
  8814. AdviceId: subItem.ID,
  8815. ProjectId: 0,
  8816. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  8817. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  8818. FeedetlSn: subItem.FeedetlSn,
  8819. Price: fmt.Sprintf("%.4f", subItem.Price),
  8820. MedListCodg: subItem.MedListCodg,
  8821. Type: 1,
  8822. }
  8823. customs = append(customs, cus)
  8824. }
  8825. }
  8826. if item.Type == 2 { //项目
  8827. for _, subItem := range item.HisPrescriptionProject {
  8828. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8829. cus := &Custom{
  8830. AdviceId: 0,
  8831. ProjectId: subItem.ID,
  8832. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  8833. Cut: fmt.Sprintf("%.4f", cnt),
  8834. FeedetlSn: subItem.FeedetlSn,
  8835. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  8836. MedListCodg: subItem.MedListCodg,
  8837. Type: 2,
  8838. }
  8839. customs = append(customs, cus)
  8840. }
  8841. }
  8842. for _, item := range item.HisAdditionalCharge {
  8843. cus := &Custom{
  8844. ItemId: item.ID,
  8845. AdviceId: 0,
  8846. ProjectId: 0,
  8847. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  8848. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  8849. FeedetlSn: item.FeedetlSn,
  8850. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  8851. MedListCodg: item.XtHisAddtionConfig.Code,
  8852. Type: 3,
  8853. }
  8854. customs = append(customs, cus)
  8855. }
  8856. }
  8857. for _, item := range customs {
  8858. var advice_id int64 = 0
  8859. var project_id int64 = 0
  8860. var item_id int64 = 0
  8861. var types int64 = 0
  8862. if item.Type == 1 {
  8863. advice_id = item.AdviceId
  8864. project_id = 0
  8865. item_id = 0
  8866. } else if item.Type == 2 {
  8867. advice_id = 0
  8868. item_id = 0
  8869. project_id = item.ProjectId
  8870. } else if item.Type == 3 {
  8871. advice_id = 0
  8872. item_id = item.ItemId
  8873. project_id = 0
  8874. }
  8875. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8876. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8877. pric, _ := strconv.ParseFloat(item.Price, 32)
  8878. info := &models.HisOrderInfo{
  8879. OrderNumber: order.Number,
  8880. UploadDate: time.Now().Unix(),
  8881. AdviceId: advice_id,
  8882. DetItemFeeSumamt: detItemFeeSumamt,
  8883. Cnt: cut,
  8884. Pric: pric,
  8885. PatientId: id,
  8886. Status: 1,
  8887. Mtime: time.Now().Unix(),
  8888. Ctime: time.Now().Unix(),
  8889. UserOrgId: adminUser.CurrentOrgId,
  8890. HisPatientId: his.ID,
  8891. OrderId: order.ID,
  8892. ProjectId: project_id,
  8893. Type: types,
  8894. ItemId: item_id,
  8895. }
  8896. service.CreateOrderInfoTX(info, tx)
  8897. }
  8898. his.Diagnosis = diagnosis_id
  8899. his.SickType = sick_type
  8900. his.RegisterType = reg_type
  8901. his.MedicalTreatmentType = reg_type
  8902. service.UpdataHisPateintTX(&his, tx)
  8903. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  8904. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  8905. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  8906. //判断是否使用了押金
  8907. if dec_way == "true" {
  8908. tmpstring := strconv.FormatInt(order.ID, 10)
  8909. //扣押金
  8910. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  8911. order.Decimal = decimal
  8912. service.UpDateOrderTwo(order, tx)
  8913. if errmsg != nil {
  8914. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  8915. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8916. return
  8917. }
  8918. }
  8919. if err == nil {
  8920. for _, info := range prescriptions {
  8921. if info.Type == 1 {
  8922. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  8923. }
  8924. if info.Type == 2 {
  8925. for _, sumItem := range info.HisPrescriptionProject {
  8926. if sumItem.Type == 3 {
  8927. var good models.DialysisBeforePrepareGoods
  8928. var newGood models.NewDialysisBeforePrepareGoods
  8929. var oldGood models.OldDialysisBeforePrepareGoods
  8930. good.GoodId = sumItem.GoodInfo.ID
  8931. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8932. count, _ := strconv.Atoi(sumItem.Count)
  8933. good.Count = int64(count)
  8934. good.StorehouseId = houseConfig.StorehouseOutInfo
  8935. good.ProjectId = sumItem.ID
  8936. good.PatientId = sumItem.PatientId
  8937. goods = append(goods, &good)
  8938. newGood.GoodId = sumItem.GoodInfo.ID
  8939. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8940. count2, _ := strconv.Atoi(sumItem.Count)
  8941. newGood.Count = int64(count2)
  8942. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8943. newGood.ProjectId = sumItem.ID
  8944. newGood.PatientId = sumItem.HisPatientId
  8945. newGoods = append(newGoods, &newGood)
  8946. oldGood.GoodId = sumItem.GoodInfo.ID
  8947. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8948. count3, _ := strconv.Atoi(sumItem.Count)
  8949. oldGood.Count = int64(count3)
  8950. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  8951. oldGood.ProjectId = sumItem.ID
  8952. oldGood.RecordDate = sumItem.RecordDate
  8953. oldGood.PatientId = sumItem.HisPatientId
  8954. oldGoods = append(oldGoods, &oldGood)
  8955. }
  8956. }
  8957. }
  8958. }
  8959. if settConfig.IsOpen == 1 {
  8960. for _, item := range infoList {
  8961. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8962. if medical.IsUse == 2 {
  8963. //药品出库
  8964. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  8965. //查询默认仓库
  8966. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  8967. //查询默认仓库剩余多少库存
  8968. var sum_count int64
  8969. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8970. for _, its := range stockInfo {
  8971. if its.MaxUnit == medical.MaxUnit {
  8972. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8973. }
  8974. sum_count += its.StockMaxNumber + its.StockMinNumber
  8975. }
  8976. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8977. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8978. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  8979. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  8980. }
  8981. }
  8982. orgId := c.GetAdminUserInfo().CurrentOrgId
  8983. if len(oldGoods) > 0 {
  8984. timeStr := time.Now().Format("2006-01-02")
  8985. timeArr := strings.Split(timeStr, "-")
  8986. total, _ := service.FindAllWarehouseOut(orgId)
  8987. total = total + 1
  8988. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8989. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8990. number = number + total
  8991. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8992. operation_time := time.Now().Unix()
  8993. creater := c.GetAdminUserInfo().AdminUser.Id
  8994. //查询默认出库仓库库存
  8995. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8996. recordDateStr := time.Now().Format("2006-01-02")
  8997. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8998. nowtime := recordDate.Unix()
  8999. warehouseOut := models.WarehouseOut{
  9000. WarehouseOutOrderNumber: warehousing_out_order,
  9001. OperationTime: operation_time,
  9002. OrgId: orgId,
  9003. Creater: creater,
  9004. Ctime: time.Now().Unix(),
  9005. Status: 1,
  9006. WarehouseOutTime: nowtime,
  9007. Type: 1,
  9008. StorehouseId: storeConfig.StorehouseOutInfo,
  9009. IsCheck: 1,
  9010. OrderId: order.ID,
  9011. IsSys: 5,
  9012. }
  9013. //查询是否生成出库单
  9014. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9015. if out.ID == 0 {
  9016. service.AddSigleWarehouseOut(&warehouseOut)
  9017. }
  9018. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9019. for _, item := range oldGoods {
  9020. dialyPrepareOne := models.DialysisBeforePrepare{
  9021. GoodTypeId: item.GoodTypeId,
  9022. GoodId: item.GoodId,
  9023. PatientId: his.PatientId,
  9024. RecordDate: item.RecordDate,
  9025. UserOrgId: adminUser.CurrentOrgId,
  9026. Count: item.Count,
  9027. Ctime: time.Now().Unix(),
  9028. Creater: adminUser.AdminUser.Id,
  9029. CommdityCode: item.CommdityCode,
  9030. Status: 1,
  9031. StorehouseId: houseConfig.StorehouseOutInfo,
  9032. }
  9033. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  9034. //非零用
  9035. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  9036. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9037. //查询剩余库存
  9038. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9039. var sum_count int64
  9040. for _, item := range goodList {
  9041. sum_count += item.StockCount
  9042. }
  9043. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9044. //耗材
  9045. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9046. }
  9047. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  9048. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9049. //查询剩余库存
  9050. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9051. var sum_count int64
  9052. for _, item := range goodList {
  9053. sum_count += item.StockCount
  9054. }
  9055. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9056. //耗材
  9057. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9058. }
  9059. }
  9060. }
  9061. }
  9062. c.ServeSuccessJSON(map[string]interface{}{
  9063. "msg": "结算成功",
  9064. })
  9065. }
  9066. }
  9067. }
  9068. // 退款
  9069. func (c *HisApiController) Refund() {
  9070. order_id, _ := c.GetInt64("order_id")
  9071. order, _ := service.GetHisOrderByID(order_id)
  9072. adminUser := c.GetAdminUserInfo()
  9073. orgid := c.GetAdminUserInfo().CurrentOrgId
  9074. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  9075. if err != nil {
  9076. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9077. return
  9078. }
  9079. tmp := strconv.FormatInt(order.ID, 10)
  9080. //当押金不为零时产生退费记录
  9081. if order.Decimal != 0 {
  9082. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  9083. if err != nil {
  9084. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9085. return
  9086. }
  9087. }
  9088. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  9089. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  9090. var goods []*models.DialysisBeforePrepareGoods
  9091. var newGoods []*models.NewDialysisBeforePrepareGoods
  9092. var infos []*models.HisDoctorAdviceInfo
  9093. for _, info := range orders {
  9094. if info.AdviceId > 0 && info.ProjectId == 0 {
  9095. infos = append(infos, &info.HisDoctorAdviceInfo)
  9096. }
  9097. if info.ProjectId > 0 && info.AdviceId == 0 {
  9098. if info.HisPrescriptionProject.Type == 3 {
  9099. var good models.DialysisBeforePrepareGoods
  9100. var newGood models.NewDialysisBeforePrepareGoods
  9101. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9102. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9103. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9104. good.Count = int64(count)
  9105. good.StorehouseId = houseConfig.StorehouseOutInfo
  9106. good.ProjectId = info.HisPrescriptionProject.ID
  9107. good.PatientId = info.PatientId
  9108. good.OrderId = order_id
  9109. goods = append(goods, &good)
  9110. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9111. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9112. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9113. newGood.Count = int64(count2)
  9114. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9115. newGood.ProjectId = info.HisPrescriptionProject.ID
  9116. newGood.RecordDate = order.SettleAccountsDate
  9117. newGood.UserOrgId = order.UserOrgId
  9118. newGood.PatientId = info.PatientId
  9119. newGood.OrderId = order_id
  9120. newGoods = append(newGoods, &newGood)
  9121. }
  9122. }
  9123. }
  9124. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9125. if settConfig.IsOpen == 1 {
  9126. for _, item := range infos {
  9127. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9128. }
  9129. for _, item := range newGoods {
  9130. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9131. }
  9132. }
  9133. c.ServeSuccessJSON(map[string]interface{}{
  9134. "msg": "退费成功",
  9135. })
  9136. }
  9137. func (c *HisApiController) RefundNumber() {
  9138. his_patient_id, _ := c.GetInt64("id")
  9139. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9140. info.Status = 0
  9141. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  9142. if count > 0 {
  9143. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  9144. return
  9145. }
  9146. err := service.SaveHisPatient(info)
  9147. if err == nil {
  9148. c.ServeSuccessJSON(map[string]interface{}{
  9149. "msg": "退号成功",
  9150. })
  9151. } else {
  9152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9153. return
  9154. }
  9155. }
  9156. func (this *HisApiController) AdditionalCharge() {
  9157. dataBody := make(map[string]interface{}, 0)
  9158. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  9159. fmt.Println(err)
  9160. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  9161. patient_id := int64(dataBody["patient_id"].(float64))
  9162. medicineData, _ := dataBody["medicineData"].([]interface{})
  9163. adminUserInfo := this.GetAdminUserInfo()
  9164. orgId := adminUserInfo.CurrentOrgId
  9165. admin_user_id := adminUserInfo.AdminUser.Id
  9166. timeStr := time.Now().Format("2006-01-02")
  9167. timeLayout := "2006-01-02 15:04:05"
  9168. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9169. timenow := timeStringToTime.Unix()
  9170. var additionalCharges []*models.HisAdditionalCharge
  9171. for _, item := range medicineData {
  9172. var randNum int
  9173. randNum = rand.Intn(10000) + 1000
  9174. timestamp := time.Now().Unix()
  9175. tempTime := time.Unix(timestamp, 0)
  9176. timeFormat := tempTime.Format("20060102150405")
  9177. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  9178. items := item.(map[string]interface{})
  9179. money := items["price"].(string)
  9180. item_id_str := items["item_id"].(string)
  9181. name := items["name"].(string)
  9182. id_str := items["id"].(string)
  9183. moneys, _ := strconv.ParseInt(money, 10, 64)
  9184. monStr := strconv.FormatInt(moneys, 10)
  9185. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  9186. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  9187. id, _ := strconv.ParseInt(id_str, 10, 64)
  9188. additionalCharge := &models.HisAdditionalCharge{
  9189. ID: id,
  9190. HisPatientId: his_patient_id,
  9191. UserOrgId: orgId,
  9192. PatientId: patient_id,
  9193. RecordDate: timenow,
  9194. Price: monneyStr,
  9195. Status: 1,
  9196. ItemName: name,
  9197. ItemId: item_id,
  9198. AdminUserId: admin_user_id,
  9199. CreatedTime: time.Now().Unix(),
  9200. OrderStatus: 0,
  9201. PrescriptionNumber: "",
  9202. BatchNumber: "",
  9203. FeedetlSn: p_number,
  9204. }
  9205. service.CreateAdditionalCharge(additionalCharge)
  9206. additionalCharges = append(additionalCharges, additionalCharge)
  9207. }
  9208. this.ServeSuccessJSON(map[string]interface{}{
  9209. "msg": "添加成功",
  9210. "additional_charges": additionalCharges,
  9211. })
  9212. }
  9213. func (this *HisApiController) DeleteAddition() {
  9214. id, _ := this.GetInt64("id")
  9215. //TODO 需要判断是否已经结算
  9216. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  9217. if err == nil {
  9218. this.ServeSuccessJSON(map[string]interface{}{
  9219. "msg": "删除成功",
  9220. })
  9221. return
  9222. } else {
  9223. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9224. return
  9225. }
  9226. }
  9227. func (this *HisApiController) GetAdminUsers() {
  9228. adminUser := this.GetAdminUserInfo()
  9229. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  9230. this.ServeSuccessJSON(map[string]interface{}{
  9231. "doctors": doctors,
  9232. })
  9233. }
  9234. func (this *HisApiController) GetLastOrNextHisPrescription() {
  9235. change_type, _ := this.GetInt64("type", 0)
  9236. record_date := this.GetString("record_time")
  9237. patient_id, _ := this.GetInt64("patient_id", 0)
  9238. p_type, _ := this.GetInt64("p_type", 0)
  9239. timeLayout := "2006-01-02"
  9240. loc, _ := time.LoadLocation("Local")
  9241. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  9242. record_time := theAdviceRecordTime.Unix()
  9243. adminUserInfo := this.GetAdminUserInfo()
  9244. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  9245. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  9246. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9247. if config.ID > 0 && config.IsOpen == 1 {
  9248. for _, subitems := range prescriptions {
  9249. for _, item := range subitems.VMHisPrescription {
  9250. for _, subItem := range item.HisDoctorAdviceInfo {
  9251. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9252. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9253. if info.RetailPrice > 0 {
  9254. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9255. subItem.Drug.RetailPrice = drug.RetailPrice
  9256. }
  9257. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9258. subItem.Drug.MinPrice = info.RetailPrice
  9259. subItem.Drug.RetailPrice = info.RetailPrice
  9260. }
  9261. }
  9262. }
  9263. }
  9264. }
  9265. }
  9266. if config.ID > 0 && config.IsOpen == 1 {
  9267. for _, subitems := range prescriptions {
  9268. for _, item := range subitems.VMHisPrescription {
  9269. for _, subItem := range item.HisPrescriptionProject {
  9270. if subItem.Type == 3 {
  9271. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9272. if info.Price > 0 {
  9273. subItem.GoodInfo.PackingPrice = info.Price
  9274. }
  9275. }
  9276. }
  9277. }
  9278. }
  9279. }
  9280. }
  9281. if err == nil {
  9282. if len(prescriptions) == 0 {
  9283. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  9284. return
  9285. } else {
  9286. this.ServeSuccessJSON(map[string]interface{}{
  9287. "prescriptions": prescriptions,
  9288. })
  9289. return
  9290. }
  9291. } else {
  9292. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9293. return
  9294. }
  9295. }
  9296. func (this *HisApiController) GetCallHisPrescription() {
  9297. patient_id, _ := this.GetInt64("patient_id", 0)
  9298. timeLayout := "2006-01-02"
  9299. loc, _ := time.LoadLocation("Local")
  9300. start_time := this.GetString("start_time")
  9301. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9302. end_time := this.GetString("end_time")
  9303. p_type, _ := this.GetInt64("p_type")
  9304. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9305. adminUserInfo := this.GetAdminUserInfo()
  9306. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  9307. //if
  9308. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  9309. //
  9310. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  9311. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  9312. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9313. if config.ID > 0 && config.IsOpen == 1 {
  9314. for _, subitems := range prescriptions {
  9315. for _, item := range subitems.VMHisPrescription {
  9316. for _, subItem := range item.HisDoctorAdviceInfo {
  9317. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9318. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9319. if info.RetailPrice > 0 {
  9320. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9321. subItem.Drug.RetailPrice = drug.RetailPrice
  9322. }
  9323. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9324. subItem.Drug.MinPrice = info.RetailPrice
  9325. subItem.Drug.RetailPrice = info.RetailPrice
  9326. }
  9327. }
  9328. }
  9329. }
  9330. }
  9331. }
  9332. if config.ID > 0 && config.IsOpen == 1 {
  9333. for _, subitems := range prescriptions {
  9334. for _, item := range subitems.VMHisPrescription {
  9335. for _, subItem := range item.HisPrescriptionProject {
  9336. if subItem.Type == 3 {
  9337. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9338. if info.Price > 0 {
  9339. subItem.GoodInfo.PackingPrice = info.Price
  9340. }
  9341. }
  9342. }
  9343. }
  9344. }
  9345. }
  9346. }
  9347. if err == nil {
  9348. this.ServeSuccessJSON(map[string]interface{}{
  9349. "prescriptions": prescriptions,
  9350. })
  9351. return
  9352. } else {
  9353. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9354. return
  9355. }
  9356. }
  9357. func (this *HisApiController) GetHisDayPrescription() {
  9358. timeLayout := "2006-01-02"
  9359. loc, _ := time.LoadLocation("Local")
  9360. start_time := this.GetString("start_time")
  9361. patient_id, _ := this.GetInt64("patient_id", 0)
  9362. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9363. end_time := this.GetString("end_time")
  9364. p_type, _ := this.GetInt64("p_type")
  9365. order_status, _ := this.GetInt64("type")
  9366. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9367. adminUserInfo := this.GetAdminUserInfo()
  9368. var dayHisPrescription []*models.HisPrescription
  9369. var err error
  9370. if order_status == 1 || order_status == 0 {
  9371. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  9372. } else if order_status == 2 {
  9373. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  9374. }
  9375. var settle_total float64
  9376. for _, item := range dayHisPrescription {
  9377. if len(item.HisPrescriptionProject) > 0 {
  9378. for _, subItem := range item.HisPrescriptionProject {
  9379. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9380. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9381. settle_total = settle_total + total
  9382. }
  9383. }
  9384. if len(item.HisDoctorAdviceInfo) > 0 {
  9385. for _, subItem := range item.HisDoctorAdviceInfo {
  9386. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9387. settle_total = settle_total + total
  9388. }
  9389. }
  9390. }
  9391. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9392. if err == nil {
  9393. this.ServeSuccessJSON(map[string]interface{}{
  9394. "day_prescription": dayHisPrescription,
  9395. "settle_total": settle_total,
  9396. })
  9397. return
  9398. } else {
  9399. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9400. return
  9401. }
  9402. }
  9403. func (c *HisApiController) GetHisChargePatientList() {
  9404. record_date := c.GetString("record_date")
  9405. order_status, _ := c.GetInt64("type")
  9406. sch_type, _ := c.GetInt64("sch_type")
  9407. timeLayout := "2006-01-02"
  9408. loc, _ := time.LoadLocation("Local")
  9409. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9410. if err != nil {
  9411. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9412. return
  9413. }
  9414. recordDateTime := theTime.Unix()
  9415. adminInfo := c.GetAdminUserInfo()
  9416. var tempPatients []*service.NewTempPatients
  9417. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  9418. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  9419. if order_status != 2 {
  9420. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9421. } else {
  9422. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9423. }
  9424. } else {
  9425. if order_status != 2 {
  9426. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9427. } else {
  9428. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9429. }
  9430. }
  9431. var patients []*service.NewTempPatients
  9432. var patients_two []*service.NewTempPatients
  9433. for _, item := range tempPatients {
  9434. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  9435. //过滤掉没挂号的和没开处方的
  9436. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  9437. patients = append(patients, item)
  9438. }
  9439. //过滤掉没挂号的
  9440. if len(item.HisPatient) > 0 {
  9441. patients_two = append(patients_two, item)
  9442. }
  9443. } else {
  9444. if len(item.HisPrescription) > 0 {
  9445. patients = append(patients, item)
  9446. }
  9447. }
  9448. }
  9449. c.ServeSuccessJSON(map[string]interface{}{
  9450. "list": patients,
  9451. "list_two": patients_two,
  9452. })
  9453. }
  9454. func (c *HisApiController) GetHisUnRegisterPatientList() {
  9455. record_date := c.GetString("record_date")
  9456. timeLayout := "2006-01-02"
  9457. loc, _ := time.LoadLocation("Local")
  9458. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9459. if err != nil {
  9460. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9461. return
  9462. }
  9463. recordDateTime := theTime.Unix()
  9464. adminUser := c.GetAdminUserInfo()
  9465. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  9466. var patients []*service.Patients
  9467. for _, item := range tempPatients {
  9468. if item.HisPatient.ID == 0 {
  9469. patients = append(patients, item)
  9470. }
  9471. }
  9472. c.ServeSuccessJSON(map[string]interface{}{
  9473. "list": patients,
  9474. //"list_two": patients_two,
  9475. })
  9476. }
  9477. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  9478. newArr = make([]*service.Patients, 0)
  9479. for i := 0; i < len(patient); i++ {
  9480. repeat := false
  9481. for j := i + 1; j < len(patient); j++ {
  9482. if patient[i].ID == patient[j].ID {
  9483. repeat = true
  9484. break
  9485. }
  9486. }
  9487. if !repeat {
  9488. newArr = append(newArr, patient[i])
  9489. }
  9490. }
  9491. return
  9492. }
  9493. func (c *HisApiController) GetHisChargePatientInfo() {
  9494. patient_id, _ := c.GetInt64("patient_id")
  9495. his_patient_id, _ := c.GetInt64("his_patient_id")
  9496. record_date := c.GetString("record_date")
  9497. //start_time := c.GetString("start_time")
  9498. //end_time := c.GetString("end_time")
  9499. order_status, _ := c.GetInt64("type", 0)
  9500. p_type, _ := c.GetInt64("p_type", 0)
  9501. order_id, _ := c.GetInt64("order_id", 0)
  9502. timeLayout := "2006-01-02"
  9503. loc, _ := time.LoadLocation("Local")
  9504. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9505. if err != nil {
  9506. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9507. return
  9508. }
  9509. recordDateTime := theTime.Unix()
  9510. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9511. //if err != nil {
  9512. //
  9513. //}
  9514. //startRecordDateTime := startTime.Unix()
  9515. //
  9516. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9517. //if err != nil {
  9518. //
  9519. //}
  9520. //endRecordDateTime := endTime.Unix()
  9521. admin := c.GetAdminUserInfo()
  9522. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9523. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9524. var prescriptions []*models.HisPrescription
  9525. //var unChargeMonthPrescriptions []*models.HisPrescription
  9526. order, _ := service.GetHisOrderByID(order_id)
  9527. if order_status == 1 || order_status == 0 {
  9528. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  9529. } else if order_status == 2 {
  9530. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  9531. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9532. }
  9533. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9534. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9535. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9536. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9537. //获取所有科室信息
  9538. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9539. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  9540. c.ServeSuccessJSON(map[string]interface{}{
  9541. "his_info": his_patient_info,
  9542. "xt_info": xt_patient_info,
  9543. "prescription": prescriptions,
  9544. "case_history": case_history,
  9545. "info": patientPrescriptionInfo,
  9546. "last_info": lastPatientPrescriptionInfo,
  9547. "order": order,
  9548. "doctors": doctors,
  9549. "department": department,
  9550. "sch": sch,
  9551. })
  9552. return
  9553. }
  9554. func (c *HisApiController) GetAllOrderDetail() {
  9555. order_id, _ := c.GetInt64("id", 0)
  9556. order, _ := service.GetHisOrderByID(order_id)
  9557. if order.ID == 0 {
  9558. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9559. return
  9560. }
  9561. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9562. org_id := c.GetAdminUserInfo().CurrentOrgId
  9563. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9564. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9565. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9566. c.ServeSuccessJSON(map[string]interface{}{
  9567. "order": order,
  9568. "order_info": order_info,
  9569. "patient": patient,
  9570. "admin_info": adminInfo,
  9571. "hospital_record": record,
  9572. })
  9573. return
  9574. }
  9575. func (c *HisApiController) GetAllOrderDetailCollect() {
  9576. order_id, _ := c.GetInt64("id", 0)
  9577. order, _ := service.GetHisOrderByID(order_id)
  9578. if order.ID == 0 {
  9579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9580. return
  9581. }
  9582. org_id := c.GetAdminUserInfo().CurrentOrgId
  9583. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9584. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9585. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9586. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  9587. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  9588. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9589. var bedCostTotal float64 = 0 //床位总费
  9590. //var bedCostSelfTotal float64 = 0 //床位自费
  9591. var operationCostTotal float64 = 0 //手术费
  9592. //var operationCostSelfTotal float64 = 0 //手术费
  9593. var otherCostTotal float64 = 0 //其他费用
  9594. //var otherCostSelfTotal float64 = 0 //其他费用
  9595. var materialCostTotal float64 = 0 //材料费
  9596. //var materialCostSelfTotal float64 = 0 //材料费
  9597. var westernMedicineCostTotal float64 = 0 //西药费
  9598. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  9599. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9600. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9601. var checkCostTotal float64 = 0 //检查费
  9602. //var checkCostSelfTotal float64 = 0 //检查费
  9603. var laboratoryCostTotal float64 = 0 //化验费
  9604. //var laboratoryCostSelfTotal float64 = 0 //化验费
  9605. var treatCostTotal float64 = 0 //治疗费用
  9606. //var treatCostSelfTotal float64 = 0 //治疗费用
  9607. var zhenChaCostTotal float64 = 0 //其他费用
  9608. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9609. decimal.DivisionPrecision = 2
  9610. var BalanceAccountsType int64
  9611. if his.ID > 0 {
  9612. BalanceAccountsType = his.BalanceAccountsType
  9613. } else {
  9614. BalanceAccountsType = record.BalanceAccountsType
  9615. }
  9616. if BalanceAccountsType != 2 {
  9617. for _, item := range order_info {
  9618. if org_id == 10215 {
  9619. if item.MedChrgitmType == "01" { //床位费
  9620. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9621. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9622. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9623. }
  9624. if item.MedChrgitmType == "02" { //诊察费
  9625. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9626. //zhenChaCostSelfTotal = zhenChaCostTotal
  9627. }
  9628. if item.MedChrgitmType == "03" { //检查费
  9629. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9630. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9631. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9632. }
  9633. //if item.MedChrgitmType == "02" { //检查费
  9634. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9635. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9636. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9637. //}
  9638. if item.MedChrgitmType == "04" { //化验费
  9639. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9640. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9641. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9642. }
  9643. if item.MedChrgitmType == "05" { //治疗费
  9644. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9645. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9646. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9647. }
  9648. if item.MedChrgitmType == "06" { //手术费
  9649. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9650. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9651. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9652. }
  9653. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9654. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9655. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9656. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9657. }
  9658. if item.MedChrgitmType == "09" { //西药费
  9659. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9660. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9661. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9662. }
  9663. if item.MedChrgitmType == "11" { //中成费
  9664. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9665. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9666. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9667. }
  9668. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9669. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9670. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9671. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9672. }
  9673. } else if org_id == 10188 || org_id == 10217 {
  9674. if item.MedChrgitmType == "01" { //床位费
  9675. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9676. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9677. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9678. }
  9679. if item.MedChrgitmType == "02" { //诊察费
  9680. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9681. //zhenChaCostSelfTotal = zhenChaCostTotal
  9682. }
  9683. if item.MedChrgitmType == "03" { //检查费
  9684. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9685. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9686. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9687. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9688. }
  9689. //if item.MedChrgitmType == "02" { //检查费
  9690. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9691. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9692. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9693. //}
  9694. if item.MedChrgitmType == "04" { //化验费
  9695. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9696. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9697. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9698. }
  9699. if item.MedChrgitmType == "05" { //治疗费
  9700. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9701. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9702. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9703. }
  9704. if item.MedChrgitmType == "06" { //手术费
  9705. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9706. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9707. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9708. }
  9709. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9710. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9711. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9712. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9713. }
  9714. if item.MedChrgitmType == "09" { //西药费
  9715. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9716. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9717. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9718. }
  9719. if item.MedChrgitmType == "11" { //中成费
  9720. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9721. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9722. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9723. }
  9724. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9725. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9726. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9727. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9728. }
  9729. } else {
  9730. if item.MedChrgitmType == "01" { //床位费
  9731. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9732. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9733. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9734. }
  9735. //if item.MedChrgitmType == "02" { //诊察费
  9736. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9737. // //zhenChaCostSelfTotal = zhenChaCostTotal
  9738. //}
  9739. if item.MedChrgitmType == "03" { //检查费
  9740. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9741. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9742. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9743. }
  9744. //if item.MedChrgitmType == "02" { //检查费
  9745. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9746. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9747. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9748. //}
  9749. if item.MedChrgitmType == "04" { //化验费
  9750. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9751. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9752. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9753. }
  9754. if item.MedChrgitmType == "05" { //治疗费
  9755. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9756. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9757. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9758. }
  9759. if item.MedChrgitmType == "06" { //手术费
  9760. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9761. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9762. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9763. }
  9764. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9765. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9766. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9767. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9768. }
  9769. if item.MedChrgitmType == "09" { //西药费
  9770. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9771. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9772. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9773. }
  9774. if item.MedChrgitmType == "11" { //中成费
  9775. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9776. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9777. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9778. }
  9779. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9780. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9781. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9782. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9783. }
  9784. }
  9785. }
  9786. c.ServeSuccessJSON(map[string]interface{}{
  9787. "order": order,
  9788. "order_info": order_info,
  9789. "patient": patient,
  9790. "admin_info": adminInfo,
  9791. "his_hospital": record,
  9792. "bedCostTotal": bedCostTotal,
  9793. "operationCostTotal": operationCostTotal,
  9794. "otherCostTotal": otherCostTotal,
  9795. "materialCostTotal": materialCostTotal,
  9796. "westernMedicineCostTotal": westernMedicineCostTotal,
  9797. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9798. "checkCostTotal": checkCostTotal,
  9799. "zhenChaCostTotal": zhenChaCostTotal,
  9800. "laboratoryCostTotal": laboratoryCostTotal,
  9801. "treatCostTotal": treatCostTotal,
  9802. })
  9803. } else {
  9804. for _, item := range order_info {
  9805. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9806. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9807. item.MedChrgitmType = "09"
  9808. }
  9809. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9810. if item.HisPrescriptionProject.Type == 2 {
  9811. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9812. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9813. case 0:
  9814. item.MedChrgitmType = "0"
  9815. break
  9816. case 1:
  9817. item.MedChrgitmType = "14"
  9818. break
  9819. case 2:
  9820. item.MedChrgitmType = "05"
  9821. break
  9822. case 3:
  9823. item.MedChrgitmType = "03"
  9824. break
  9825. case 4:
  9826. item.MedChrgitmType = "03"
  9827. break
  9828. case 5:
  9829. item.MedChrgitmType = "08"
  9830. break
  9831. case 6:
  9832. item.MedChrgitmType = "14"
  9833. break
  9834. case 7:
  9835. item.MedChrgitmType = "14"
  9836. break
  9837. case 8:
  9838. item.MedChrgitmType = "03"
  9839. break
  9840. case 9:
  9841. item.MedChrgitmType = "14"
  9842. break
  9843. case 10:
  9844. item.MedChrgitmType = "14"
  9845. break
  9846. case 11:
  9847. item.MedChrgitmType = "06"
  9848. break
  9849. case 12:
  9850. item.MedChrgitmType = "12"
  9851. break
  9852. case 13:
  9853. item.MedChrgitmType = "01"
  9854. break
  9855. case 14:
  9856. item.MedChrgitmType = "04"
  9857. break
  9858. case 15:
  9859. item.MedChrgitmType = "14"
  9860. break
  9861. }
  9862. } else {
  9863. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9864. case 1:
  9865. item.MedChrgitmType = "14"
  9866. break
  9867. case 2:
  9868. item.MedChrgitmType = "05"
  9869. break
  9870. case 3:
  9871. item.MedChrgitmType = "04"
  9872. break
  9873. case 4:
  9874. item.MedChrgitmType = "14"
  9875. break
  9876. case 5:
  9877. item.MedChrgitmType = "08"
  9878. break
  9879. case 6:
  9880. item.MedChrgitmType = "14"
  9881. break
  9882. case 7:
  9883. item.MedChrgitmType = "14"
  9884. break
  9885. case 8:
  9886. item.MedChrgitmType = "03"
  9887. break
  9888. case 9:
  9889. item.MedChrgitmType = "14"
  9890. break
  9891. }
  9892. }
  9893. } else if item.HisPrescriptionProject.Type == 3 {
  9894. item.MedChrgitmType = "08"
  9895. }
  9896. }
  9897. }
  9898. for _, item := range order_info {
  9899. if org_id == 10215 {
  9900. if item.MedChrgitmType == "01" { //床位费
  9901. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9902. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9903. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9904. }
  9905. if item.MedChrgitmType == "02" { //诊察费
  9906. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9907. //zhenChaCostSelfTotal = zhenChaCostTotal
  9908. }
  9909. if item.MedChrgitmType == "03" { //检查费
  9910. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9911. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9912. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9913. }
  9914. //if item.MedChrgitmType == "02" { //检查费
  9915. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9916. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9917. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9918. //}
  9919. if item.MedChrgitmType == "04" { //化验费
  9920. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9921. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9922. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9923. }
  9924. if item.MedChrgitmType == "05" { //治疗费
  9925. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9926. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9927. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9928. }
  9929. if item.MedChrgitmType == "06" { //手术费
  9930. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9931. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9932. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9933. }
  9934. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9935. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9936. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9937. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9938. }
  9939. if item.MedChrgitmType == "09" { //西药费
  9940. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9941. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9942. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9943. }
  9944. if item.MedChrgitmType == "11" { //中成费
  9945. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9946. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9947. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9948. }
  9949. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9950. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9951. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9952. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9953. }
  9954. } else {
  9955. if item.MedChrgitmType == "01" { //床位费
  9956. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9957. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9958. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9959. }
  9960. //if item.MedChrgitmType == "02" { //诊察费
  9961. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9962. // //zhenChaCostSelfTotal = zhenChaCostTotal
  9963. //}
  9964. if item.MedChrgitmType == "03" { //检查费
  9965. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9966. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9967. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9968. }
  9969. //if item.MedChrgitmType == "02" { //检查费
  9970. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9971. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9972. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9973. //}
  9974. if item.MedChrgitmType == "04" { //化验费
  9975. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9976. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9977. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9978. }
  9979. if item.MedChrgitmType == "05" { //治疗费
  9980. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9981. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9982. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9983. }
  9984. if item.MedChrgitmType == "06" { //手术费
  9985. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9986. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9987. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9988. }
  9989. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9990. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9991. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9992. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9993. }
  9994. if item.MedChrgitmType == "09" { //西药费
  9995. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9996. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9997. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9998. }
  9999. if item.MedChrgitmType == "11" { //中成费
  10000. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10001. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10002. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10003. }
  10004. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10005. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10006. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10007. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10008. }
  10009. }
  10010. }
  10011. c.ServeSuccessJSON(map[string]interface{}{
  10012. "order": order,
  10013. "order_info": order_info,
  10014. "patient": patient,
  10015. "admin_info": adminInfo,
  10016. "his_hospital": record,
  10017. "bedCostTotal": bedCostTotal,
  10018. "operationCostTotal": operationCostTotal,
  10019. "otherCostTotal": otherCostTotal,
  10020. "materialCostTotal": materialCostTotal,
  10021. "westernMedicineCostTotal": westernMedicineCostTotal,
  10022. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10023. "checkCostTotal": checkCostTotal,
  10024. "zhenChaCostTotal": zhenChaCostTotal,
  10025. "laboratoryCostTotal": laboratoryCostTotal,
  10026. "treatCostTotal": treatCostTotal,
  10027. })
  10028. }
  10029. }
  10030. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  10031. page, _ := c.GetInt64("page")
  10032. limit, _ := c.GetInt64("limit")
  10033. keywords := c.GetString("keywords")
  10034. start_time := c.GetString("start_time")
  10035. end_time := c.GetString("end_time")
  10036. //clr_type := c.GetString("clr_type")
  10037. insutype := c.GetString("insutype")
  10038. timeLayout := "2006-01-02"
  10039. loc, _ := time.LoadLocation("Local")
  10040. var theStartTIme int64
  10041. if len(start_time) > 0 {
  10042. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10043. theStartTIme = theTime.Unix()
  10044. }
  10045. var theEndtTIme int64
  10046. if len(end_time) > 0 {
  10047. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10048. theEndtTIme = theTime.Unix()
  10049. }
  10050. if page <= 0 {
  10051. page = 1
  10052. }
  10053. if limit <= 0 {
  10054. limit = 10
  10055. }
  10056. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  10057. c.ServeSuccessJSON(map[string]interface{}{
  10058. "total": total,
  10059. "list": list,
  10060. })
  10061. return
  10062. }
  10063. func (c *HisApiController) GetPutOnRecordList() {
  10064. page, _ := c.GetInt64("page")
  10065. limit, _ := c.GetInt64("limit")
  10066. keywords := c.GetString("keywords")
  10067. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  10068. if page <= 0 {
  10069. page = 1
  10070. }
  10071. if limit <= 0 {
  10072. limit = 10
  10073. }
  10074. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  10075. c.ServeSuccessJSON(map[string]interface{}{
  10076. "total": total,
  10077. "list": list,
  10078. })
  10079. return
  10080. }
  10081. func (c *HisApiController) GetCompareData() {
  10082. start_time := c.GetString("start_time")
  10083. end_time := c.GetString("end_time")
  10084. insutype := c.GetString("insutype")
  10085. clr_type := c.GetString("clr_type")
  10086. timeLayout := "2006-01-02"
  10087. loc, _ := time.LoadLocation("Local")
  10088. var theStartTIme int64
  10089. if len(start_time) > 0 {
  10090. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10091. if err != nil {
  10092. theStartTIme = 0
  10093. }
  10094. theStartTIme = theTime.Unix()
  10095. }
  10096. var theEndtTIme int64
  10097. if len(end_time) > 0 {
  10098. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10099. if err != nil {
  10100. theEndtTIme = 0
  10101. }
  10102. theEndtTIme = theTime.Unix()
  10103. }
  10104. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  10105. fmt.Println(err)
  10106. if err == nil {
  10107. c.ServeSuccessJSON(map[string]interface{}{
  10108. "list": formData,
  10109. })
  10110. } else {
  10111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10112. return
  10113. }
  10114. }
  10115. func (c *HisApiController) GetFaPiaoData() {
  10116. order_id, _ := c.GetInt64("order_id")
  10117. patient_id, _ := c.GetInt64("patient_id")
  10118. //number := c.GetString("number")
  10119. adminUser := c.GetAdminUserInfo()
  10120. order, _ := service.GetHisOrderByID(order_id)
  10121. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10122. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10123. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10124. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10125. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  10126. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  10127. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10128. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10129. var bedCostTotal float64 = 0 //床位总费
  10130. var bedCostSelfTotal float64 = 0 //床位自费
  10131. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10132. var operationCostTotal float64 = 0 //手术费
  10133. var operationCostSelfTotal float64 = 0 //手术费
  10134. var operationCostPartSelfTotal float64 = 0 //手术费
  10135. var otherCostTotal float64 = 0 //其他费用
  10136. var otherCostSelfTotal float64 = 0 //其他费用
  10137. var otherCostPartSelfTotal float64 = 0 //其他费用
  10138. var materialCostTotal float64 = 0 //材料费
  10139. var materialCostSelfTotal float64 = 0 //材料费
  10140. var materialCostPartSelfTotal float64 = 0 //材料费
  10141. var westernMedicineCostTotal float64 = 0 //西药费
  10142. var westernMedicineCostSelfTotal float64 = 0 //西药费
  10143. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10144. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10145. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10146. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10147. var checkCostTotal float64 = 0 //检查费
  10148. var checkCostSelfTotal float64 = 0 //检查费
  10149. var checkCostPartSelfTotal float64 = 0 //检查费
  10150. var hiliCostTotal float64 = 0 //护理费
  10151. var hiliCostSelfTotal float64 = 0 //护理费
  10152. var hiliCostPartSelfTotal float64 = 0 //护理费
  10153. var laboratoryCostTotal float64 = 0 //化验费
  10154. var laboratoryCostSelfTotal float64 = 0 //化验费
  10155. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10156. var treatCostTotal float64 = 0 //治疗费用
  10157. var treatCostSelfTotal float64 = 0 //治疗费用
  10158. var treatCostPartSelfTotal float64 = 0 //治疗费用
  10159. var zhenChaCostTotal float64 = 0 //其他费用
  10160. var zhenChaCostSelfTotal float64 = 0 //其他费用
  10161. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10162. decimal.DivisionPrecision = 2
  10163. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10164. var balanceAccountsType int64
  10165. if his.ID > 0 {
  10166. balanceAccountsType = his.BalanceAccountsType
  10167. } else {
  10168. balanceAccountsType = his_hospital_record.BalanceAccountsType
  10169. }
  10170. if balanceAccountsType == 2 {
  10171. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10172. for _, item := range orderInfos_two {
  10173. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10174. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10175. item.MedChrgitmType = "09"
  10176. }
  10177. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10178. if item.HisPrescriptionProject.Type == 2 {
  10179. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10180. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10181. case 0:
  10182. item.MedChrgitmType = "0"
  10183. break
  10184. case 1:
  10185. item.MedChrgitmType = "14"
  10186. break
  10187. case 2:
  10188. item.MedChrgitmType = "05"
  10189. break
  10190. case 3:
  10191. item.MedChrgitmType = "03"
  10192. break
  10193. case 4:
  10194. item.MedChrgitmType = "03"
  10195. break
  10196. case 5:
  10197. item.MedChrgitmType = "08"
  10198. break
  10199. case 6:
  10200. item.MedChrgitmType = "14"
  10201. break
  10202. case 7:
  10203. item.MedChrgitmType = "14"
  10204. break
  10205. case 8:
  10206. item.MedChrgitmType = "03"
  10207. break
  10208. case 9:
  10209. item.MedChrgitmType = "14"
  10210. break
  10211. case 10:
  10212. item.MedChrgitmType = "14"
  10213. break
  10214. case 11:
  10215. item.MedChrgitmType = "06"
  10216. break
  10217. case 12:
  10218. item.MedChrgitmType = "12"
  10219. break
  10220. case 13:
  10221. item.MedChrgitmType = "01"
  10222. break
  10223. case 14:
  10224. item.MedChrgitmType = "04"
  10225. break
  10226. case 15:
  10227. item.MedChrgitmType = "02"
  10228. break
  10229. }
  10230. } else {
  10231. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10232. case 1:
  10233. item.MedChrgitmType = "14"
  10234. break
  10235. case 2:
  10236. item.MedChrgitmType = "05"
  10237. break
  10238. case 3:
  10239. item.MedChrgitmType = "04"
  10240. break
  10241. case 4:
  10242. item.MedChrgitmType = "03"
  10243. break
  10244. case 5:
  10245. item.MedChrgitmType = "08"
  10246. break
  10247. case 6:
  10248. item.MedChrgitmType = "14"
  10249. break
  10250. case 7:
  10251. item.MedChrgitmType = "14"
  10252. break
  10253. case 8:
  10254. item.MedChrgitmType = "03"
  10255. break
  10256. case 9:
  10257. item.MedChrgitmType = "14"
  10258. break
  10259. }
  10260. }
  10261. } else if item.HisPrescriptionProject.Type == 3 {
  10262. item.MedChrgitmType = "08"
  10263. }
  10264. }
  10265. }
  10266. for _, item := range orderInfos_two {
  10267. fmt.Println(item.MedChrgitmType)
  10268. if item.MedChrgitmType == "07" { //床位费
  10269. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10270. hiliCostSelfTotal = hiliCostTotal
  10271. }
  10272. if item.MedChrgitmType == "01" { //床位费
  10273. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10274. bedCostSelfTotal = bedCostTotal
  10275. }
  10276. if item.MedChrgitmType == "02" { //诊察费
  10277. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10278. zhenChaCostSelfTotal = zhenChaCostTotal
  10279. }
  10280. if item.MedChrgitmType == "03" { //检查费
  10281. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10282. checkCostSelfTotal = checkCostTotal
  10283. }
  10284. if item.MedChrgitmType == "04" { //化验费
  10285. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10286. laboratoryCostSelfTotal = laboratoryCostTotal
  10287. }
  10288. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10289. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10290. treatCostSelfTotal = treatCostTotal
  10291. }
  10292. if item.MedChrgitmType == "06" { //手术费
  10293. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10294. operationCostSelfTotal = treatCostTotal
  10295. }
  10296. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  10297. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10298. materialCostSelfTotal = materialCostTotal
  10299. }
  10300. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10301. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10302. westernMedicineCostSelfTotal = westernMedicineCostTotal
  10303. }
  10304. if item.MedChrgitmType == "11" { //中成费
  10305. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10306. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10307. }
  10308. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10309. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10310. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10311. otherCostSelfTotal = otherCostTotal
  10312. }
  10313. } else {
  10314. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10315. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10316. otherCostSelfTotal = otherCostTotal
  10317. }
  10318. }
  10319. }
  10320. } else {
  10321. for _, item := range orderInfos {
  10322. if item.MedChrgitmType == "01" { //床位费
  10323. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10324. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10325. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10326. }
  10327. if item.MedChrgitmType == "02" { //诊察费
  10328. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10329. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10330. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10331. }
  10332. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  10333. if item.MedChrgitmType == "03" { //检查费
  10334. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10335. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10336. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10337. }
  10338. } else {
  10339. if item.MedChrgitmType == "03" { //检查费
  10340. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10341. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10342. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10343. }
  10344. }
  10345. if item.MedChrgitmType == "04" { //化验费
  10346. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10347. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10348. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10349. }
  10350. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10351. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10352. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10353. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10354. }
  10355. if item.MedChrgitmType == "06" { //手术费
  10356. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10357. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10358. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10359. }
  10360. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  10361. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10362. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10363. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10364. }
  10365. if item.MedChrgitmType == "07" { //护理
  10366. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10367. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10368. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10369. }
  10370. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10371. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10372. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10373. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10374. }
  10375. if item.MedChrgitmType == "11" { //中成费
  10376. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10377. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10378. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10379. }
  10380. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10381. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10382. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10383. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10384. }
  10385. }
  10386. }
  10387. timeLayout := "2006-01-02"
  10388. loc, _ := time.LoadLocation("Local")
  10389. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  10390. if err != nil {
  10391. }
  10392. startRecordDateTime := startTime.Unix()
  10393. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  10394. if err != nil {
  10395. }
  10396. endRecordDateTime := endTime.Unix()
  10397. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  10398. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  10399. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  10400. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  10401. c.ServeSuccessJSON(map[string]interface{}{
  10402. "charge_admin_name": charge_admin.UserName,
  10403. "order_number": order.Number, //业务流水号
  10404. "id_card_no": his.IdCardNo, //社会保障号
  10405. "patient": patient,
  10406. "department_name": department.Name, //科室
  10407. "number": his.Number, //门诊号
  10408. "date": order.SettleAccountsDate, //结算日期
  10409. "name": order.PsnName, //姓名
  10410. "gender": patient.Gender, //性别
  10411. "psn_cash_money": order.PsnCashPay, //个人支付
  10412. "pay_way": "门诊", //结算方式
  10413. "medfee_sumamt": order.MedfeeSumamt, //总费用
  10414. "admin_user_name": admin.UserName, //收款员
  10415. "order": order,
  10416. "order_info": orderInfos_two,
  10417. "his": his,
  10418. "bedCostTotal": bedCostTotal,
  10419. "bedCostSelfTotal": bedCostSelfTotal,
  10420. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  10421. "operationCostTotal": operationCostTotal,
  10422. "operationCostSelfTotal": operationCostSelfTotal,
  10423. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  10424. "otherCostTotal": otherCostTotal,
  10425. "otherCostSelfTotal": otherCostSelfTotal,
  10426. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  10427. "materialCostTotal": materialCostTotal,
  10428. "materialCostSelfTotal": materialCostSelfTotal,
  10429. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  10430. "westernMedicineCostTotal": westernMedicineCostTotal,
  10431. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  10432. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  10433. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10434. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  10435. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  10436. "checkCostTotal": checkCostTotal,
  10437. "checkCostSelfTotal": checkCostSelfTotal,
  10438. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  10439. "laboratoryCostTotal": laboratoryCostTotal,
  10440. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  10441. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  10442. "treatCostTotal": treatCostTotal,
  10443. "treatCostSelfTotal": treatCostSelfTotal,
  10444. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  10445. "zhenChaCostTotal": zhenChaCostTotal,
  10446. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  10447. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  10448. "his_hospital_record": his_hospital_record,
  10449. "pre_pay_money": pre_pay_money,
  10450. "refund_sum": sum,
  10451. "doctor_info": doctor_info,
  10452. "hiliCostTotal": hiliCostTotal,
  10453. "hiliCostSelfTotal": hiliCostSelfTotal,
  10454. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  10455. })
  10456. }
  10457. //func (c *HisApiController) GetFaPiaoDatas() {
  10458. // order_ids := c.GetString("order_ids")
  10459. // patient_id, _ := c.GetInt64("patient_id")
  10460. // adminUser := c.GetAdminUserInfo()
  10461. //
  10462. // orders := strings.Split(order_ids, ",")
  10463. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10464. //
  10465. // for _, item := range orders {
  10466. // order_id, _ := strconv.ParseInt(item, 10, 64)
  10467. // order, _ := service.GetHisOrderByID(order_id)
  10468. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10469. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10470. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10471. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10472. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10473. //
  10474. // }
  10475. //
  10476. // var bedCostTotal float64 = 0 //床位总费
  10477. // var bedCostSelfTotal float64 = 0 //床位自费
  10478. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10479. //
  10480. // var operationCostTotal float64 = 0 //手术费
  10481. // var operationCostSelfTotal float64 = 0 //手术费
  10482. // var operationCostPartSelfTotal float64 = 0 //手术费
  10483. //
  10484. // var otherCostTotal float64 = 0 //其他费用
  10485. // var otherCostSelfTotal float64 = 0 //其他费用
  10486. // var otherCostPartSelfTotal float64 = 0 //其他费用
  10487. //
  10488. // var materialCostTotal float64 = 0 //材料费
  10489. // var materialCostSelfTotal float64 = 0 //材料费
  10490. // var materialCostPartSelfTotal float64 = 0 //材料费
  10491. //
  10492. // var westernMedicineCostTotal float64 = 0 //西药费
  10493. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  10494. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10495. //
  10496. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10497. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10498. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10499. //
  10500. // var checkCostTotal float64 = 0 //检查费
  10501. // var checkCostSelfTotal float64 = 0 //检查费
  10502. // var checkCostPartSelfTotal float64 = 0 //检查费
  10503. //
  10504. // var laboratoryCostTotal float64 = 0 //化验费
  10505. // var laboratoryCostSelfTotal float64 = 0 //化验费
  10506. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10507. //
  10508. // var treatCostTotal float64 = 0 //治疗费用
  10509. // var treatCostSelfTotal float64 = 0 //治疗费用
  10510. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  10511. //
  10512. // var zhenChaCostTotal float64 = 0 //其他费用
  10513. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  10514. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10515. //
  10516. // decimal.DivisionPrecision = 2
  10517. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10518. //
  10519. // var balanceAccountsType int64
  10520. // if his.ID > 0 {
  10521. // balanceAccountsType = his.BalanceAccountsType
  10522. // } else {
  10523. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  10524. // }
  10525. // if balanceAccountsType == 2 {
  10526. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10527. // for _, item := range orderInfos_two {
  10528. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10529. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10530. // item.MedChrgitmType = "09"
  10531. // }
  10532. //
  10533. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10534. // if item.HisPrescriptionProject.Type == 2 {
  10535. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10536. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10537. // case 0:
  10538. // item.MedChrgitmType = "0"
  10539. // break
  10540. // case 1:
  10541. // item.MedChrgitmType = "14"
  10542. // break
  10543. // case 2:
  10544. // item.MedChrgitmType = "05"
  10545. //
  10546. // break
  10547. // case 3:
  10548. // item.MedChrgitmType = "03"
  10549. //
  10550. // break
  10551. // case 4:
  10552. // item.MedChrgitmType = "03"
  10553. //
  10554. // break
  10555. // case 5:
  10556. // item.MedChrgitmType = "08"
  10557. //
  10558. // break
  10559. // case 6:
  10560. // item.MedChrgitmType = "14"
  10561. //
  10562. // break
  10563. // case 7:
  10564. // item.MedChrgitmType = "14"
  10565. //
  10566. // break
  10567. // case 8:
  10568. // item.MedChrgitmType = "03"
  10569. // break
  10570. // case 9:
  10571. // item.MedChrgitmType = "14"
  10572. // break
  10573. // case 10:
  10574. // item.MedChrgitmType = "14"
  10575. // break
  10576. // case 11:
  10577. // item.MedChrgitmType = "06"
  10578. // break
  10579. // case 12:
  10580. // item.MedChrgitmType = "12"
  10581. // break
  10582. // case 13:
  10583. // item.MedChrgitmType = "01"
  10584. // break
  10585. // case 14:
  10586. // item.MedChrgitmType = "04"
  10587. // break
  10588. // case 15:
  10589. // item.MedChrgitmType = "02"
  10590. // break
  10591. //
  10592. // }
  10593. //
  10594. // } else {
  10595. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10596. //
  10597. // case 1:
  10598. // item.MedChrgitmType = "14"
  10599. // break
  10600. // case 2:
  10601. // item.MedChrgitmType = "05"
  10602. //
  10603. // break
  10604. // case 3:
  10605. // item.MedChrgitmType = "03"
  10606. //
  10607. // break
  10608. // case 4:
  10609. // item.MedChrgitmType = "03"
  10610. //
  10611. // break
  10612. // case 5:
  10613. // item.MedChrgitmType = "08"
  10614. //
  10615. // break
  10616. // case 6:
  10617. // item.MedChrgitmType = "14"
  10618. //
  10619. // break
  10620. // case 7:
  10621. // item.MedChrgitmType = "14"
  10622. //
  10623. // break
  10624. // case 8:
  10625. // item.MedChrgitmType = "03"
  10626. // break
  10627. // case 9:
  10628. // item.MedChrgitmType = "14"
  10629. // break
  10630. //
  10631. // }
  10632. //
  10633. // }
  10634. //
  10635. // } else if item.HisPrescriptionProject.Type == 3 {
  10636. // item.MedChrgitmType = "08"
  10637. // }
  10638. // }
  10639. // }
  10640. //
  10641. // for _, item := range orderInfos_two {
  10642. // fmt.Println(item.MedChrgitmType)
  10643. // if item.MedChrgitmType == "01" { //床位费
  10644. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10645. // bedCostSelfTotal = bedCostTotal
  10646. // }
  10647. //
  10648. // if item.MedChrgitmType == "02" { //诊察费
  10649. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10650. // zhenChaCostSelfTotal = zhenChaCostTotal
  10651. // }
  10652. //
  10653. // if item.MedChrgitmType == "03" { //检查费
  10654. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10655. // checkCostSelfTotal = checkCostTotal
  10656. // }
  10657. //
  10658. // if item.MedChrgitmType == "04" { //化验费
  10659. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10660. // laboratoryCostSelfTotal = laboratoryCostTotal
  10661. // }
  10662. //
  10663. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  10664. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10665. // treatCostSelfTotal = treatCostTotal
  10666. // }
  10667. //
  10668. // if item.MedChrgitmType == "06" { //手术费
  10669. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10670. // operationCostSelfTotal = treatCostTotal
  10671. // }
  10672. //
  10673. // if item.MedChrgitmType == "08" { //材料费
  10674. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10675. // materialCostSelfTotal = materialCostTotal
  10676. // }
  10677. //
  10678. // if item.MedChrgitmType == "09" { //西药费
  10679. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10680. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  10681. // }
  10682. //
  10683. // if item.MedChrgitmType == "11" { //中成费
  10684. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10685. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10686. // }
  10687. //
  10688. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10689. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10690. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10691. // otherCostSelfTotal = otherCostTotal
  10692. // }
  10693. // } else {
  10694. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10695. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10696. // otherCostSelfTotal = otherCostTotal
  10697. // }
  10698. //
  10699. // }
  10700. //
  10701. // }
  10702. //
  10703. // } else {
  10704. // for _, item := range orderInfos {
  10705. // if item.MedChrgitmType == "01" { //床位费
  10706. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10707. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10708. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10709. // }
  10710. //
  10711. // if item.MedChrgitmType == "02" { //诊察费
  10712. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10713. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10714. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10715. // }
  10716. //
  10717. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  10718. // if item.MedChrgitmType == "03" { //检查费
  10719. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10720. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10721. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10722. //
  10723. // }
  10724. // } else {
  10725. // if item.MedChrgitmType == "03" { //检查费
  10726. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10727. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10728. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10729. // }
  10730. //
  10731. // }
  10732. //
  10733. // if item.MedChrgitmType == "04" { //化验费
  10734. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10735. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10736. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10737. //
  10738. // }
  10739. //
  10740. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  10741. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10742. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10743. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10744. //
  10745. // }
  10746. //
  10747. // if item.MedChrgitmType == "06" { //手术费
  10748. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10749. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10750. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10751. // }
  10752. //
  10753. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  10754. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10755. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10756. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10757. // }
  10758. //
  10759. // if item.MedChrgitmType == "09" { //西药费
  10760. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10761. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10762. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10763. // }
  10764. //
  10765. // if item.MedChrgitmType == "11" { //中成费
  10766. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10767. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10768. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10769. // }
  10770. //
  10771. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10772. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10773. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10774. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10775. // }
  10776. //
  10777. // }
  10778. // }
  10779. // timeLayout := "2006-01-02"
  10780. // loc, _ := time.LoadLocation("Local")
  10781. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  10782. // if err != nil {
  10783. // }
  10784. // startRecordDateTime := startTime.Unix()
  10785. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  10786. // if err != nil {
  10787. // }
  10788. // endRecordDateTime := endTime.Unix()
  10789. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  10790. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  10791. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  10792. //
  10793. // c.ServeSuccessJSON(map[string]interface{}{
  10794. // "order_number": order.Number, //业务流水号
  10795. // "id_card_no": his.IdCardNo, //社会保障号
  10796. // "department_name": department.Name, //科室
  10797. // "number": his.Number, //门诊号
  10798. // "date": order.SettleAccountsDate, //结算日期
  10799. // "name": order.PsnName, //姓名
  10800. // "gender": patient.Gender, //性别
  10801. // "psn_cash_money": order.PsnCashPay, //个人支付
  10802. // "pay_way": "门诊", //结算方式
  10803. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  10804. // "admin_user_name": admin.UserName, //收款员
  10805. // "order": order,
  10806. // "order_info": orderInfos_two,
  10807. // "his": his,
  10808. // "bedCostTotal": bedCostTotal,
  10809. // "bedCostSelfTotal": bedCostSelfTotal,
  10810. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  10811. // "operationCostTotal": operationCostTotal,
  10812. // "operationCostSelfTotal": operationCostSelfTotal,
  10813. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  10814. // "otherCostTotal": otherCostTotal,
  10815. // "otherCostSelfTotal": otherCostSelfTotal,
  10816. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  10817. // "materialCostTotal": materialCostTotal,
  10818. // "materialCostSelfTotal": materialCostSelfTotal,
  10819. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  10820. // "westernMedicineCostTotal": westernMedicineCostTotal,
  10821. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  10822. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  10823. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10824. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  10825. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  10826. // "checkCostTotal": checkCostTotal,
  10827. // "checkCostSelfTotal": checkCostSelfTotal,
  10828. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  10829. // "laboratoryCostTotal": laboratoryCostTotal,
  10830. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  10831. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  10832. // "treatCostTotal": treatCostTotal,
  10833. // "treatCostSelfTotal": treatCostSelfTotal,
  10834. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  10835. // "zhenChaCostTotal": zhenChaCostTotal,
  10836. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  10837. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  10838. // "his_hospital_record": his_hospital_record,
  10839. // "pre_pay_money": pre_pay_money,
  10840. // "refund_sum": sum,
  10841. // })
  10842. //
  10843. //}
  10844. func (this *HisApiController) GetIncomeStatisticsData() {
  10845. start_time := this.GetString("start_time")
  10846. end_time := this.GetString("end_time")
  10847. key_words := this.GetString("key_words")
  10848. limit, _ := this.GetInt64("limit")
  10849. page, _ := this.GetInt64("page")
  10850. if page <= 0 {
  10851. page = 1
  10852. }
  10853. if limit <= 0 {
  10854. limit = 10
  10855. }
  10856. statistics_type, _ := this.GetInt64("statistics_type")
  10857. admin := this.GetAdminUserInfo()
  10858. timeLayout := "2006-01-02"
  10859. loc, _ := time.LoadLocation("Local")
  10860. var theStartTIme int64
  10861. if len(start_time) > 0 {
  10862. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10863. if err != nil {
  10864. theStartTIme = 0
  10865. }
  10866. theStartTIme = theTime.Unix()
  10867. }
  10868. var theEndtTIme int64
  10869. if len(end_time) > 0 {
  10870. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10871. if err != nil {
  10872. theEndtTIme = 0
  10873. }
  10874. theEndtTIme = theTime.Unix()
  10875. }
  10876. if statistics_type == 1 {
  10877. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10878. this.ServeSuccessJSON(map[string]interface{}{
  10879. "list": list,
  10880. "total": total,
  10881. })
  10882. } else {
  10883. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10884. this.ServeSuccessJSON(map[string]interface{}{
  10885. "list": list,
  10886. "total": total,
  10887. })
  10888. }
  10889. }
  10890. func (c *HisApiController) PostProjectInformation() {
  10891. adminUser := c.GetAdminUserInfo()
  10892. orgId := adminUser.CurrentOrgId
  10893. dataBody := make(map[string]interface{}, 0)
  10894. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10895. if err != nil {
  10896. utils.ErrorLog(err.Error())
  10897. return
  10898. }
  10899. utils.ErrorLog("%v", dataBody)
  10900. var projectList []*models.HisProject
  10901. var total_goods []interface{}
  10902. tempProjects := dataBody["projects"].([]interface{})
  10903. total_goods = tempProjects
  10904. for index, projectMap := range tempProjects {
  10905. projectM := projectMap.(map[string]interface{})
  10906. var project models.HisProject
  10907. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  10908. utils.ErrorLog("project_name")
  10909. return
  10910. }
  10911. project_name, _ := projectM["project_name"].(string)
  10912. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  10913. err_log := models.ExportErrLog{
  10914. LogType: 6,
  10915. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10916. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  10917. Status: 1,
  10918. CreateTime: time.Now().Unix(),
  10919. UpdateTime: time.Now().Unix(),
  10920. ExportTime: time.Now().Unix(),
  10921. }
  10922. service.CreateExportErrLog(&err_log)
  10923. continue
  10924. }
  10925. project.ProjectName = project_name
  10926. prices := projectM["price"].(string)
  10927. price, _ := strconv.ParseFloat(prices, 64)
  10928. if price <= 0 { //名字为空则生成一条导入错误日志
  10929. err_log := models.ExportErrLog{
  10930. LogType: 6,
  10931. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10932. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  10933. Status: 1,
  10934. CreateTime: time.Now().Unix(),
  10935. UpdateTime: time.Now().Unix(),
  10936. ExportTime: time.Now().Unix(),
  10937. }
  10938. service.CreateExportErrLog(&err_log)
  10939. continue
  10940. }
  10941. project.Price = price
  10942. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  10943. utils.ErrorLog("unit_id")
  10944. return
  10945. }
  10946. unit := projectM["unit"].(string)
  10947. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  10948. err_log := models.ExportErrLog{
  10949. LogType: 6,
  10950. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10951. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  10952. Status: 1,
  10953. CreateTime: time.Now().Unix(),
  10954. UpdateTime: time.Now().Unix(),
  10955. ExportTime: time.Now().Unix(),
  10956. }
  10957. service.CreateExportErrLog(&err_log)
  10958. continue
  10959. }
  10960. project.Unit = unit
  10961. cost_classify := projectM["cost_classify"].(string)
  10962. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  10963. err_log := models.ExportErrLog{
  10964. LogType: 6,
  10965. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10966. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10967. Status: 1,
  10968. CreateTime: time.Now().Unix(),
  10969. UpdateTime: time.Now().Unix(),
  10970. ExportTime: time.Now().Unix(),
  10971. }
  10972. service.CreateExportErrLog(&err_log)
  10973. continue
  10974. }
  10975. var costClassify = "费用类别"
  10976. var cost_classify_id int64
  10977. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  10978. if len(cost_classify) != 0 {
  10979. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  10980. if errcode == gorm.ErrRecordNotFound {
  10981. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  10982. dataconfig := models.DictDataconfig{
  10983. ParentId: costClassifyConfig.ID,
  10984. Module: "system",
  10985. OrgId: orgId,
  10986. Name: cost_classify,
  10987. FieldName: "",
  10988. Value: costConfig.Value + 1,
  10989. CreatedTime: "",
  10990. UpdatedTime: "",
  10991. CreateUserId: adminUser.AdminUser.Id,
  10992. Status: 1,
  10993. Remark: "",
  10994. DeleteIdSystem: 0,
  10995. Title: "",
  10996. Content: "",
  10997. Order: 0,
  10998. Code: "",
  10999. }
  11000. service.CreatedDicConfig(&dataconfig)
  11001. }
  11002. }
  11003. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  11004. for _, it := range costClassList {
  11005. if cost_classify == it.Name {
  11006. cost_classify_id = int64(it.Value)
  11007. }
  11008. }
  11009. project.CostClassify = cost_classify_id
  11010. executive_section := projectM["executive_section"].(string)
  11011. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  11012. err_log := models.ExportErrLog{
  11013. LogType: 6,
  11014. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11015. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  11016. Status: 1,
  11017. CreateTime: time.Now().Unix(),
  11018. UpdateTime: time.Now().Unix(),
  11019. ExportTime: time.Now().Unix(),
  11020. }
  11021. service.CreateExportErrLog(&err_log)
  11022. continue
  11023. }
  11024. if len(executive_section) != 0 {
  11025. //查找科室是否有内容
  11026. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  11027. if errcodedepart == gorm.ErrRecordNotFound {
  11028. department := models.XtHisDepartment{
  11029. Name: executive_section,
  11030. Status: 1,
  11031. UserOrgId: adminUser.CurrentOrgId,
  11032. CreatedTime: time.Now().Unix(),
  11033. }
  11034. service.CreateDePartment(&department)
  11035. }
  11036. }
  11037. var executive_section_id int64
  11038. departMentList, _ := service.GetAllDepartMent(orgId)
  11039. for _, it := range departMentList {
  11040. if executive_section == it.Name {
  11041. executive_section_id = it.ID
  11042. }
  11043. }
  11044. project.ExecutiveSection = executive_section_id
  11045. medical_coverage := projectM["medical_coverage"].(string)
  11046. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  11047. err_log := models.ExportErrLog{
  11048. LogType: 6,
  11049. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11050. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11051. Status: 1,
  11052. CreateTime: time.Now().Unix(),
  11053. UpdateTime: time.Now().Unix(),
  11054. ExportTime: time.Now().Unix(),
  11055. }
  11056. service.CreateExportErrLog(&err_log)
  11057. continue
  11058. }
  11059. var medicalCoverage = "医保等级"
  11060. var medical_coverage_id int64
  11061. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  11062. if len(medical_coverage) != 0 {
  11063. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  11064. if errormedicalcoverage == gorm.ErrRecordNotFound {
  11065. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  11066. dataconfig := models.DictDataconfig{
  11067. ParentId: medicalCoverageConfig.ID,
  11068. Module: "system",
  11069. OrgId: orgId,
  11070. Name: medical_coverage,
  11071. FieldName: "",
  11072. Value: medicalCoverageConfig.Value + 1,
  11073. CreatedTime: "",
  11074. UpdatedTime: "",
  11075. CreateUserId: adminUser.AdminUser.Id,
  11076. Status: 1,
  11077. Remark: "",
  11078. DeleteIdSystem: 0,
  11079. Title: "",
  11080. Content: "",
  11081. Order: 0,
  11082. Code: "",
  11083. }
  11084. service.CreatedDicConfig(&dataconfig)
  11085. }
  11086. }
  11087. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  11088. for _, it := range medicalCoverageList {
  11089. if medical_coverage == it.Name {
  11090. medical_coverage_id = int64(it.Value)
  11091. }
  11092. }
  11093. project.MedicalCoverage = medical_coverage_id
  11094. pinyin := projectM["pinyin"].(string)
  11095. project.Pinyin = pinyin
  11096. wubi := projectM["wubi"].(string)
  11097. project.Wubi = wubi
  11098. statistical_classification := projectM["statistical_classification"].(string)
  11099. var statisticalClassification = "统计分类"
  11100. var statistical_classification_id int64
  11101. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  11102. if len(statistical_classification) != 0 {
  11103. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  11104. if classificationerrcodes == gorm.ErrRecordNotFound {
  11105. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  11106. dataconfig := models.DictDataconfig{
  11107. ParentId: classiFication.ID,
  11108. Module: "system",
  11109. OrgId: orgId,
  11110. Name: statistical_classification,
  11111. FieldName: "",
  11112. Value: classiFicationConfig.Value + 1,
  11113. CreatedTime: "",
  11114. UpdatedTime: "",
  11115. CreateUserId: adminUser.AdminUser.Id,
  11116. Status: 1,
  11117. Remark: "",
  11118. DeleteIdSystem: 0,
  11119. Title: "",
  11120. Content: "",
  11121. Order: 0,
  11122. Code: "",
  11123. }
  11124. service.CreatedDicConfig(&dataconfig)
  11125. }
  11126. }
  11127. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  11128. for _, it := range classiFicationList {
  11129. if statistical_classification == it.Name {
  11130. statistical_classification_id = int64(it.Value)
  11131. }
  11132. }
  11133. project.StatisticalClassification = statistical_classification_id
  11134. disease_directory := int64(projectM["disease_directory"].(float64))
  11135. project.DiseaseDirectory = disease_directory
  11136. is_record := int64(projectM["is_record"].(float64))
  11137. project.IsRecord = is_record
  11138. medical_code := projectM["medical_code"].(string)
  11139. project.MedicalCode = medical_code
  11140. tube_color := projectM["tube_color"].(string)
  11141. var tubeColor = "试管颜色"
  11142. var tube_color_id int64
  11143. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  11144. if len(tube_color) != 0 {
  11145. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  11146. if errcodetube == gorm.ErrRecordNotFound {
  11147. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  11148. dataconfig := models.DictDataconfig{
  11149. ParentId: tubeColorConfig.ID,
  11150. Module: "system",
  11151. OrgId: orgId,
  11152. Name: tube_color,
  11153. FieldName: "",
  11154. Value: tubeConfig.Value + 1,
  11155. CreatedTime: "",
  11156. UpdatedTime: "",
  11157. CreateUserId: adminUser.AdminUser.Id,
  11158. Status: 1,
  11159. Remark: "",
  11160. DeleteIdSystem: 0,
  11161. Title: "",
  11162. Content: "",
  11163. Order: 0,
  11164. Code: "",
  11165. }
  11166. service.CreatedDicConfig(&dataconfig)
  11167. }
  11168. }
  11169. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  11170. for _, it := range tubeColorList {
  11171. if tube_color == it.Name {
  11172. tube_color_id = int64(it.Value)
  11173. }
  11174. }
  11175. project.TubeColor = tube_color_id
  11176. single_dose := projectM["single_dose"].(string)
  11177. project.SingleDose = single_dose
  11178. execution_frequency := projectM["execution_frequency"].(string)
  11179. project.ExecutionFrequency = execution_frequency
  11180. delivery_way := projectM["delivery_way"].(string)
  11181. project.DeliveryWay = delivery_way
  11182. number_days := projectM["number_days"].(string)
  11183. project.NumberDays = number_days
  11184. total := projectM["total"].(string)
  11185. project.Total = total
  11186. medical_status := int64(projectM["medical_status"].(float64))
  11187. project.MedicalStatus = medical_status
  11188. category := int64(projectM["category"].(float64))
  11189. project.Category = category
  11190. specail_project := int64(projectM["specail_project"].(float64))
  11191. project.SpecailProject = specail_project
  11192. social_security_directory_code := projectM["social_security_directory_code"].(string)
  11193. project.SocialSecurityDirectoryCode = social_security_directory_code
  11194. remark := projectM["remark"].(string)
  11195. project.Remark = remark
  11196. record_date := projectM["record_date"].(string)
  11197. timeLayout := "2006-01-02"
  11198. loc, _ := time.LoadLocation("Local")
  11199. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11200. project.RecordDate = theTime.Unix()
  11201. projectList = append(projectList, &project)
  11202. }
  11203. export_time := time.Now().Unix()
  11204. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  11205. if len(projectList) > 0 {
  11206. for _, item := range projectList {
  11207. hans := item.ProjectName // 要转换的汉字字符串
  11208. // 创建一个拼音转换器
  11209. p := pinyin.NewArgs()
  11210. // 将汉字转为拼音
  11211. pinyinSlice := pinyin.Pinyin(hans, p)
  11212. // 输出拼音
  11213. fmt.Println("Pinyin:", pinyinSlice)
  11214. // 获取首字母
  11215. firstLetter := ""
  11216. for _, py := range pinyinSlice {
  11217. if len(py) > 0 {
  11218. firstLetter += string(py[0][0])
  11219. }
  11220. }
  11221. item.FirstLetter = firstLetter
  11222. project := models.HisProject{
  11223. ProjectName: item.ProjectName,
  11224. Price: item.Price,
  11225. Unit: item.Unit,
  11226. CostClassify: item.CostClassify,
  11227. ExecutiveSection: item.ExecutiveSection,
  11228. MedicalCoverage: item.MedicalCoverage,
  11229. UserOrgId: orgId,
  11230. Status: 1,
  11231. CreatedTime: time.Now().Unix(),
  11232. Pinyin: item.Pinyin,
  11233. Wubi: item.Wubi,
  11234. StatisticalClassification: item.StatisticalClassification,
  11235. DiseaseDirectory: item.DiseaseDirectory,
  11236. IsRecord: item.IsRecord,
  11237. MedicalCode: item.MedicalCode,
  11238. TubeColor: item.TubeColor,
  11239. SingleDose: item.SingleDose,
  11240. DeliveryWay: item.DeliveryWay,
  11241. NumberDays: item.NumberDays,
  11242. Total: item.Total,
  11243. Category: item.Category,
  11244. MedicalStatus: item.MedicalStatus,
  11245. SpecailProject: item.SpecailProject,
  11246. RecordDate: item.RecordDate,
  11247. Remark: item.Remark,
  11248. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  11249. ExecutionFrequency: item.ExecutionFrequency,
  11250. FirstLetter: item.FirstLetter,
  11251. }
  11252. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  11253. if errcodeproject == gorm.ErrRecordNotFound {
  11254. service.CreateProjectInfomation(&project)
  11255. } else if errcodeproject == nil {
  11256. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  11257. }
  11258. log := models.ExportLog{
  11259. LogType: 6,
  11260. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11261. TotalNum: int64(len(total_goods)),
  11262. FailNum: int64(len(errLogs)),
  11263. SuccessNum: int64(len(projectList)),
  11264. CreateTime: time.Now().Unix(),
  11265. UpdateTime: time.Now().Unix(),
  11266. ExportTime: export_time,
  11267. Status: 1,
  11268. }
  11269. service.CreateExportLog(&log)
  11270. c.ServeSuccessJSON(map[string]interface{}{
  11271. "msg": "导入成功",
  11272. "total_num": len(total_goods),
  11273. "success_num": len(projectList),
  11274. "fail_num": int64(len(errLogs)),
  11275. })
  11276. }
  11277. } else {
  11278. log := models.ExportLog{
  11279. LogType: 6,
  11280. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11281. TotalNum: int64(len(total_goods)),
  11282. FailNum: int64(len(errLogs)),
  11283. SuccessNum: int64(len(projectList)),
  11284. CreateTime: time.Now().Unix(),
  11285. UpdateTime: time.Now().Unix(),
  11286. ExportTime: export_time,
  11287. Status: 1,
  11288. }
  11289. service.CreateExportLog(&log)
  11290. c.ServeSuccessJSON(map[string]interface{}{
  11291. "msg": "导入成功",
  11292. "total_num": len(total_goods),
  11293. "success_num": len(projectList),
  11294. "fail_num": int64(len(errLogs)),
  11295. })
  11296. }
  11297. }
  11298. //func (this *HisApiController) EditProjectInformation(){
  11299. //
  11300. // id, _ := this.GetInt64("id")
  11301. // project_team := this.GetString("project_team")
  11302. // price := this.GetString("price")
  11303. // price_float, _ := strconv.ParseFloat(price, 64)
  11304. // pinyin := this.GetString("pinyin")
  11305. // wubi := this.GetString("wubi")
  11306. // tube_color, _ := this.GetInt64("tube_color")
  11307. // team_type, _ := this.GetInt64("team_type")
  11308. // remark := this.GetString("remark")
  11309. // ids := this.GetString("ids")
  11310. // item_id := this.GetString("item_id")
  11311. // projectTeam := models.XtHisProjectTeam{
  11312. // ProjectTeam: project_team,
  11313. // Price: price_float,
  11314. // Pinyin: pinyin,
  11315. // Wubi: wubi,
  11316. // TubeColor: tube_color,
  11317. // TeamType: team_type,
  11318. // Remark: remark,
  11319. // ProjectId: ids,
  11320. // ItemId: item_id,
  11321. // }
  11322. //
  11323. //
  11324. // dataBody := make(map[string]interface{}, 0)
  11325. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  11326. // if err != nil {
  11327. // utils.ErrorLog(err.Error())
  11328. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11329. // return
  11330. // }
  11331. //
  11332. // err = service.UpdatedProjectTeam(id, &projectTeam)
  11333. //
  11334. //
  11335. // if err != nil {
  11336. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  11337. // return
  11338. // }
  11339. //
  11340. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  11341. // infos, _ := dataBody["info"].([]interface{})
  11342. // if len(infos) > 0 {
  11343. // var ids []string
  11344. //
  11345. // for _, item := range infos {
  11346. // items := item.(map[string]interface{})
  11347. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  11348. // utils.ErrorLog("id")
  11349. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11350. // return
  11351. // }
  11352. // id := int64(items["id"].(float64))
  11353. //
  11354. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11355. // utils.ErrorLog("type")
  11356. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11357. // return
  11358. // }
  11359. // types := int64(items["type"].(float64))
  11360. //
  11361. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  11362. // utils.ErrorLog("number")
  11363. // }
  11364. //
  11365. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  11366. //
  11367. // projectList := models.XtHisProjectList{
  11368. // Number: number,
  11369. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  11370. // ProjectId: id,
  11371. // Status: 1,
  11372. // CreatedTime: time.Now().Unix(),
  11373. // UpdatedTime: time.Now().Unix(),
  11374. // TeamId: projectTeam.ID,
  11375. // Type: types,
  11376. // }
  11377. // list := projectList
  11378. //
  11379. // service.CreateProjectList(&list)
  11380. //
  11381. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  11382. //
  11383. // }
  11384. // ids_str := strings.Join(ids, ",")
  11385. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  11386. // service.SaveProjectTeam(&projectTeam)
  11387. // this.ServeSuccessJSON(map[string]interface{}{
  11388. // "projectTeam": projectTeam,
  11389. // })
  11390. // }
  11391. // }
  11392. //}
  11393. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  11394. name := c.GetString("name")
  11395. mode_id, _ := c.GetInt64("mode", 0)
  11396. types, _ := c.GetInt64("type", 0)
  11397. patient_id, _ := c.GetInt64("patient_id", 0)
  11398. types = 1
  11399. adminInfo := c.GetAdminUserInfo()
  11400. template := &models.HisPrescriptionTemplate{
  11401. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11402. PatientId: patient_id,
  11403. Type: types,
  11404. Status: 1,
  11405. Ctime: time.Now().Unix(),
  11406. Mtime: time.Now().Unix(),
  11407. Name: name,
  11408. Mode: mode_id,
  11409. }
  11410. dataBody := make(map[string]interface{}, 0)
  11411. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11412. if err != nil {
  11413. utils.ErrorLog(err.Error())
  11414. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11415. return
  11416. }
  11417. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  11418. //如果已经存在记录则删除处方
  11419. if template_one.ID > 0 {
  11420. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  11421. var ids []int64
  11422. var org_id int64
  11423. for _, item := range ps {
  11424. org_id = c.GetAdminUserInfo().CurrentOrgId
  11425. ids = append(ids, item.ID)
  11426. }
  11427. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  11428. if err2 == nil {
  11429. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11430. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11431. if len(prescriptions) > 0 {
  11432. for _, item := range prescriptions {
  11433. items := item.(map[string]interface{})
  11434. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11435. utils.ErrorLog("type")
  11436. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11437. return
  11438. }
  11439. types := int64(items["type"].(float64))
  11440. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  11441. utils.ErrorLog("med_type")
  11442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11443. return
  11444. }
  11445. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  11446. ctime := time.Now().Unix()
  11447. prescription := &models.HisPrescriptionInfoTemplate{
  11448. PatientId: patient_id,
  11449. UserOrgId: adminInfo.CurrentOrgId,
  11450. Ctime: ctime,
  11451. Mtime: ctime,
  11452. Type: types,
  11453. Modifier: adminInfo.AdminUser.Id,
  11454. Creator: adminInfo.AdminUser.Id,
  11455. Status: 1,
  11456. PTemplateId: template_one.ID,
  11457. MedType: med_type,
  11458. }
  11459. service.CreateHisPrescriptionInfoTemplate(prescription)
  11460. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11461. advices := items["advices"].([]interface{})
  11462. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11463. ctime := time.Now().Unix()
  11464. mtime := ctime
  11465. if len(advices) > 0 {
  11466. for _, advice := range advices {
  11467. var s models.HisPrescriptionAdviceTemplate
  11468. s.PrescriptionId = prescription.ID
  11469. s.AdviceType = 2
  11470. s.StopState = 2
  11471. s.ExecutionState = 2
  11472. s.Status = 1
  11473. s.UserOrgId = adminInfo.CurrentOrgId
  11474. s.CreatedTime = ctime
  11475. s.UpdatedTime = mtime
  11476. s.PatientId = patient_id
  11477. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  11478. if errcode > 0 {
  11479. c.ServeFailJSONWithSGJErrorCode(errcode)
  11480. return
  11481. }
  11482. service.CreateHisPrescriptionAdviceTemplate(&s)
  11483. }
  11484. }
  11485. }
  11486. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11487. projects := items["project"].([]interface{})
  11488. if len(projects) > 0 {
  11489. for _, project := range projects {
  11490. var p models.HisPrescriptionProjectTemplate
  11491. p.PrescriptionId = prescription.ID
  11492. p.Ctime = time.Now().Unix()
  11493. p.Mtime = time.Now().Unix()
  11494. p.PatientId = patient_id
  11495. p.UserOrgId = adminInfo.CurrentOrgId
  11496. p.Status = 1
  11497. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  11498. if errcode > 0 {
  11499. c.ServeFailJSONWithSGJErrorCode(errcode)
  11500. return
  11501. }
  11502. service.CreateHisPrescriptionProjectTemplate(&p)
  11503. }
  11504. }
  11505. }
  11506. }
  11507. c.ServeSuccessJSON(map[string]interface{}{
  11508. "msg": "创建成功",
  11509. })
  11510. }
  11511. }
  11512. } else {
  11513. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11514. return
  11515. }
  11516. } else {
  11517. err3 := service.CreateHisPrescriptionTemplate(template)
  11518. if err3 == nil {
  11519. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11520. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11521. if len(prescriptions) > 0 {
  11522. for _, item := range prescriptions {
  11523. items := item.(map[string]interface{})
  11524. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11525. utils.ErrorLog("type")
  11526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11527. return
  11528. }
  11529. types := int64(items["type"].(float64))
  11530. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  11531. utils.ErrorLog("med_type")
  11532. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11533. return
  11534. }
  11535. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  11536. ctime := time.Now().Unix()
  11537. prescription := &models.HisPrescriptionInfoTemplate{
  11538. PatientId: patient_id,
  11539. UserOrgId: adminInfo.CurrentOrgId,
  11540. Ctime: ctime,
  11541. Mtime: ctime,
  11542. Type: types,
  11543. Modifier: adminInfo.AdminUser.Id,
  11544. Creator: adminInfo.AdminUser.Id,
  11545. Status: 1,
  11546. PTemplateId: template.ID,
  11547. MedType: med_type,
  11548. }
  11549. service.CreateHisPrescriptionInfoTemplate(prescription)
  11550. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11551. advices := items["advices"].([]interface{})
  11552. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11553. ctime := time.Now().Unix()
  11554. mtime := ctime
  11555. if len(advices) > 0 {
  11556. for _, advice := range advices {
  11557. var s models.HisPrescriptionAdviceTemplate
  11558. s.PrescriptionId = prescription.ID
  11559. s.AdviceType = 2
  11560. s.StopState = 2
  11561. s.ExecutionState = 2
  11562. s.Status = 1
  11563. s.UserOrgId = adminInfo.CurrentOrgId
  11564. s.CreatedTime = ctime
  11565. s.UpdatedTime = mtime
  11566. s.PatientId = patient_id
  11567. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  11568. if errcode > 0 {
  11569. c.ServeFailJSONWithSGJErrorCode(errcode)
  11570. return
  11571. }
  11572. service.CreateHisPrescriptionAdviceTemplate(&s)
  11573. }
  11574. }
  11575. }
  11576. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11577. projects := items["project"].([]interface{})
  11578. if len(projects) > 0 {
  11579. for _, project := range projects {
  11580. var p models.HisPrescriptionProjectTemplate
  11581. p.PrescriptionId = prescription.ID
  11582. p.Ctime = time.Now().Unix()
  11583. p.Mtime = time.Now().Unix()
  11584. p.PatientId = patient_id
  11585. p.UserOrgId = adminInfo.CurrentOrgId
  11586. p.Status = 1
  11587. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  11588. if errcode > 0 {
  11589. c.ServeFailJSONWithSGJErrorCode(errcode)
  11590. return
  11591. }
  11592. service.CreateHisPrescriptionProjectTemplate(&p)
  11593. }
  11594. }
  11595. }
  11596. }
  11597. c.ServeSuccessJSON(map[string]interface{}{
  11598. "msg": "创建成功",
  11599. })
  11600. }
  11601. }
  11602. } else {
  11603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11604. return
  11605. }
  11606. }
  11607. }
  11608. func (c *HisApiController) PreSettle() {
  11609. id, _ := c.GetInt64("id")
  11610. record_time := c.GetString("record_time")
  11611. his_patient_id, _ := c.GetInt64("his_patient_id")
  11612. timeLayout := "2006-01-02"
  11613. loc, _ := time.LoadLocation("Local")
  11614. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  11615. diagnosis_id := c.GetString("diagnosis")
  11616. sick_type, _ := c.GetInt64("sick_type")
  11617. reg_type, _ := c.GetInt64("p_type")
  11618. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  11619. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  11620. if err != nil {
  11621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11622. return
  11623. }
  11624. recordDateTime := theTime.Unix()
  11625. adminUser := c.GetAdminUserInfo()
  11626. var prescriptions []*models.HisPrescription
  11627. var start_time int64
  11628. var end_time int64
  11629. ids_str := c.GetString("ids")
  11630. ids_arr := strings.Split(ids_str, ",")
  11631. fmt.Println(reg_type)
  11632. if settle_accounts_type == 1 { //日结
  11633. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  11634. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  11635. } else {
  11636. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  11637. }
  11638. fmt.Println(prescriptions)
  11639. } else { //月结
  11640. start_time_str := c.GetString("start_time")
  11641. end_time_str := c.GetString("end_time")
  11642. timeLayout := "2006-01-02"
  11643. loc, _ := time.LoadLocation("Local")
  11644. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  11645. if err != nil {
  11646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11647. return
  11648. }
  11649. recordStartTime := theStartTime.Unix()
  11650. start_time = recordStartTime
  11651. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  11652. if err != nil {
  11653. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11654. return
  11655. }
  11656. recordEndTime := theEndTime.Unix()
  11657. end_time = recordEndTime
  11658. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  11659. }
  11660. if reg_type == 1111 || reg_type == 1112 {
  11661. reg_type = 11
  11662. }
  11663. timestamp := time.Now().Unix()
  11664. tempTime := time.Unix(timestamp, 0)
  11665. timeFormat := tempTime.Format("20060102150405")
  11666. chrgBchno := rand.Intn(100000) + 10000
  11667. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  11668. strconv.FormatInt(his.PatientId, 10)
  11669. var ids []int64
  11670. for _, item := range prescriptions {
  11671. ids = append(ids, item.ID)
  11672. }
  11673. fmt.Println(ids)
  11674. var total float64
  11675. for _, item := range prescriptions {
  11676. fmt.Println(item)
  11677. if item.Type == 1 { //药品
  11678. for _, subItem := range item.HisDoctorAdviceInfo {
  11679. total = total + (subItem.Price * subItem.PrescribingNumber)
  11680. }
  11681. }
  11682. if item.Type == 2 { //项目
  11683. for _, subItem := range item.HisPrescriptionProject {
  11684. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  11685. total = total + (subItem.Price * cnt)
  11686. }
  11687. }
  11688. for _, subItem := range item.HisAdditionalCharge {
  11689. total = total + (subItem.Price * float64(subItem.Count))
  11690. }
  11691. }
  11692. allTotal := fmt.Sprintf("%.2f", total)
  11693. totals, _ := strconv.ParseFloat(allTotal, 64)
  11694. order := &models.HisOrder{
  11695. UserOrgId: adminUser.CurrentOrgId,
  11696. HisPatientId: his.ID,
  11697. PatientId: id,
  11698. SettleAccountsDate: recordDateTime,
  11699. Ctime: time.Now().Unix(),
  11700. Mtime: time.Now().Unix(),
  11701. Status: 1,
  11702. OrderStatus: 1,
  11703. MdtrtId: his.Number,
  11704. Number: chrg_bchno,
  11705. MedfeeSumamt: totals,
  11706. SettleEndTime: end_time,
  11707. SettleStartTime: start_time,
  11708. SettleType: settle_accounts_type,
  11709. PsnPartAmt: totals,
  11710. PsnCashPay: totals,
  11711. PType: 2,
  11712. IsPre: 1,
  11713. MedType: strconv.Itoa(int(reg_type)),
  11714. Diagnosis: diagnosis_id,
  11715. }
  11716. err = service.CreateOrder(order)
  11717. if err != nil {
  11718. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  11719. return
  11720. }
  11721. var customs []*Custom
  11722. for _, item := range prescriptions {
  11723. fmt.Println(item.Type)
  11724. if item.Type == 1 { //药品
  11725. for _, subItem := range item.HisDoctorAdviceInfo {
  11726. cus := &Custom{
  11727. AdviceId: subItem.ID,
  11728. ProjectId: 0,
  11729. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  11730. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  11731. FeedetlSn: subItem.FeedetlSn,
  11732. Price: fmt.Sprintf("%.2f", subItem.Price),
  11733. MedListCodg: subItem.MedListCodg,
  11734. Type: 1,
  11735. }
  11736. customs = append(customs, cus)
  11737. }
  11738. }
  11739. if item.Type == 2 { //项目
  11740. for _, subItem := range item.HisPrescriptionProject {
  11741. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  11742. cus := &Custom{
  11743. AdviceId: 0,
  11744. ProjectId: subItem.ID,
  11745. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  11746. Cut: fmt.Sprintf("%.2f", cnt),
  11747. FeedetlSn: subItem.FeedetlSn,
  11748. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  11749. MedListCodg: subItem.MedListCodg,
  11750. Type: 2,
  11751. }
  11752. customs = append(customs, cus)
  11753. }
  11754. }
  11755. for _, item := range item.HisAdditionalCharge {
  11756. cus := &Custom{
  11757. ItemId: item.ID,
  11758. AdviceId: 0,
  11759. ProjectId: 0,
  11760. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  11761. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  11762. FeedetlSn: item.FeedetlSn,
  11763. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  11764. MedListCodg: item.XtHisAddtionConfig.Code,
  11765. Type: 3,
  11766. }
  11767. customs = append(customs, cus)
  11768. }
  11769. }
  11770. fmt.Println(customs)
  11771. for _, item := range customs {
  11772. var advice_id int64 = 0
  11773. var project_id int64 = 0
  11774. var item_id int64 = 0
  11775. var types int64 = 0
  11776. if item.Type == 1 {
  11777. advice_id = item.AdviceId
  11778. project_id = 0
  11779. item_id = 0
  11780. } else if item.Type == 2 {
  11781. advice_id = 0
  11782. item_id = 0
  11783. project_id = item.ProjectId
  11784. } else if item.Type == 3 {
  11785. advice_id = 0
  11786. item_id = item.ItemId
  11787. project_id = 0
  11788. }
  11789. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  11790. cut, _ := strconv.ParseFloat(item.Cut, 32)
  11791. pric, _ := strconv.ParseFloat(item.Price, 32)
  11792. info := &models.HisOrderInfo{
  11793. OrderNumber: order.Number,
  11794. UploadDate: time.Now().Unix(),
  11795. AdviceId: advice_id,
  11796. DetItemFeeSumamt: detItemFeeSumamt,
  11797. Cnt: cut,
  11798. Pric: pric,
  11799. PatientId: id,
  11800. Status: 1,
  11801. Mtime: time.Now().Unix(),
  11802. Ctime: time.Now().Unix(),
  11803. UserOrgId: adminUser.CurrentOrgId,
  11804. HisPatientId: his.ID,
  11805. OrderId: order.ID,
  11806. ProjectId: project_id,
  11807. Type: types,
  11808. ItemId: item_id,
  11809. }
  11810. service.CreateOrderInfo(info)
  11811. }
  11812. his.SickType = sick_type
  11813. service.UpdataHisPateint(&his)
  11814. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  11815. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  11816. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  11817. if err == nil {
  11818. c.ServeSuccessJSON(map[string]interface{}{
  11819. "msg": "结算成功",
  11820. })
  11821. }
  11822. }
  11823. type CustomOrderInfo struct {
  11824. Name string
  11825. Spec string
  11826. Unit string
  11827. Count float64
  11828. Price float64
  11829. Total float64
  11830. }
  11831. func (c *HisApiController) GetPrivateExpensesInfo() {
  11832. order_id, _ := c.GetInt64("id", 0)
  11833. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  11834. order, _ := service.GetHisOrderByID(order_id)
  11835. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  11836. if order.ID == 0 {
  11837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  11838. return
  11839. }
  11840. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  11841. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  11842. org_id := c.GetAdminUserInfo().CurrentOrgId
  11843. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  11844. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  11845. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  11846. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  11847. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  11848. //var orderInfos_four []*models.HisOrderInfoTwo
  11849. //for _, item := range orderInfos_three {
  11850. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  11851. // item.HisPrescriptionProject.IsCheckTeam = 1
  11852. // orderInfos_four = append(orderInfos_four, item)
  11853. //
  11854. // }
  11855. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  11856. // item.HisPrescriptionProject.IsCheckTeam = 2
  11857. // orderInfos_two = append(orderInfos_two, item)
  11858. // }
  11859. //}
  11860. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  11861. //var cus_slice []CustomOrderInfo
  11862. //for _, item := range new_order_info {
  11863. // var cus CustomOrderInfo
  11864. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  11865. // cus.Unit = ""
  11866. // cus.Spec = ""
  11867. // var total float64
  11868. // for _, subItem := range orderInfos_four {
  11869. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  11870. // total = total + subItem.DetItemFeeSumamt
  11871. // fmt.Println(subItem.DetItemFeeSumamt)
  11872. // }
  11873. // }
  11874. // cus.Count = 1
  11875. // cus.Total = total
  11876. // cus_slice = append(cus_slice, cus)
  11877. //}
  11878. orderInfos = append(orderInfos, orderInfos_two...)
  11879. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  11880. //orderInfos = append(orderInfos, orderInfos_three...)
  11881. //}/**/
  11882. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  11883. c.ServeSuccessJSON(map[string]interface{}{
  11884. "order": order,
  11885. "order_info": orderInfos,
  11886. "patient": patient,
  11887. "admin_info": adminInfo,
  11888. "his": his,
  11889. "current_admin": role,
  11890. "org_config": miConfig,
  11891. //"new_order_info": cus_slice,
  11892. })
  11893. }
  11894. func (this *HisApiController) ChangeMedType() {
  11895. med_type := this.GetString("med_type")
  11896. old_med_type := this.GetString("old_med_type")
  11897. ids := this.GetString("ids")
  11898. settle_type, _ := this.GetInt64("settle_type")
  11899. start_time := this.GetString("start_time")
  11900. end_time := this.GetString("end_time")
  11901. ids_arr := strings.Split(ids, ",")
  11902. if settle_type == 1 { //日结
  11903. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  11904. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  11905. prescription.MedType = med_type
  11906. err := service.SaveHisPrescriptionTwo(&prescription)
  11907. if err == nil {
  11908. this.ServeSuccessJSON(map[string]interface{}{
  11909. "msg": "修改成功",
  11910. })
  11911. } else {
  11912. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11913. return
  11914. }
  11915. } else if settle_type == 2 {
  11916. timeLayout := "2006-01-02"
  11917. loc, _ := time.LoadLocation("Local")
  11918. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11919. if err != nil {
  11920. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11921. return
  11922. }
  11923. recordStartTime := theStartTime.Unix()
  11924. start_time_timestamp := recordStartTime
  11925. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  11926. if err != nil {
  11927. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11928. return
  11929. }
  11930. recordEndTime := theEndTime.Unix()
  11931. end_time_timestamp := recordEndTime
  11932. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  11933. if updateErr == nil {
  11934. this.ServeSuccessJSON(map[string]interface{}{
  11935. "msg": "修改成功",
  11936. })
  11937. } else {
  11938. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11939. return
  11940. }
  11941. }
  11942. }
  11943. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  11944. patient_id, _ := c.GetInt64("patient_id")
  11945. his_patient_id, _ := c.GetInt64("his_patient_id")
  11946. record_date := c.GetString("record_date")
  11947. start_time := c.GetString("start_time")
  11948. end_time := c.GetString("end_time")
  11949. order_status, _ := c.GetInt64("type", 0)
  11950. p_type, _ := c.GetInt64("p_type", 0)
  11951. order_id, _ := c.GetInt64("order_id", 0)
  11952. timeLayout := "2006-01-02"
  11953. loc, _ := time.LoadLocation("Local")
  11954. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11955. if err != nil {
  11956. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11957. return
  11958. }
  11959. recordDateTime := theTime.Unix()
  11960. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11961. if err != nil {
  11962. }
  11963. startRecordDateTime := startTime.Unix()
  11964. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11965. if err != nil {
  11966. }
  11967. endRecordDateTime := endTime.Unix()
  11968. admin := c.GetAdminUserInfo()
  11969. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  11970. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11971. order, _ := service.GetHisOrderByID(order_id)
  11972. var monthPrescriptions []*models.HisPrescription
  11973. if order_status == 1 || order_status == 0 {
  11974. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11975. } else if order_status == 2 {
  11976. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  11977. }
  11978. var settle_total float64
  11979. for _, item := range monthPrescriptions {
  11980. if len(item.HisPrescriptionProject) > 0 {
  11981. for _, subItem := range item.HisPrescriptionProject {
  11982. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11983. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11984. settle_total = settle_total + total
  11985. }
  11986. }
  11987. if len(item.HisDoctorAdviceInfo) > 0 {
  11988. for _, subItem := range item.HisDoctorAdviceInfo {
  11989. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11990. settle_total = settle_total + total
  11991. }
  11992. }
  11993. }
  11994. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11995. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11996. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11997. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11998. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11999. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12000. //获取所有科室信息
  12001. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12002. var dia string
  12003. for _, item := range month_p_info {
  12004. if len(dia) == 0 {
  12005. dia = item.Diagnosis
  12006. } else {
  12007. dia = dia + "," + item.Diagnosis
  12008. }
  12009. }
  12010. dia_arr := removeDuplicates(strings.Split(dia, ","))
  12011. dia_arr = removeEmptyStrings(dia_arr)
  12012. c.ServeSuccessJSON(map[string]interface{}{
  12013. "his_info": his_patient_info,
  12014. "xt_info": xt_patient_info,
  12015. "case_history": case_history,
  12016. "info": patientPrescriptionInfo,
  12017. "last_info": lastPatientPrescriptionInfo,
  12018. "month_prescriptions": monthPrescriptions,
  12019. "order": order,
  12020. "doctors": doctors,
  12021. "department": department,
  12022. "settle_total": settle_total,
  12023. "dia_arr": dia_arr,
  12024. })
  12025. return
  12026. }
  12027. func removeEmptyStrings(input []string) []string {
  12028. var output []string
  12029. for _, s := range input {
  12030. if s != "" {
  12031. output = append(output, s)
  12032. }
  12033. }
  12034. return output
  12035. }
  12036. func removeDuplicates(input []string) []string {
  12037. seen := make(map[string]bool)
  12038. output := []string{}
  12039. for _, s := range input {
  12040. if _, exists := seen[s]; !exists {
  12041. seen[s] = true
  12042. output = append(output, s)
  12043. }
  12044. }
  12045. return output
  12046. }
  12047. func (c *HisApiController) GetHisMonthPatientInfo() {
  12048. patient_id, _ := c.GetInt64("patient_id")
  12049. his_patient_id, _ := c.GetInt64("his_patient_id")
  12050. record_date := c.GetString("record_date")
  12051. number := c.GetString("number")
  12052. start_time := c.GetString("start_time")
  12053. end_time := c.GetString("end_time")
  12054. p_type, _ := c.GetInt64("p_type")
  12055. timeLayout := "2006-01-02"
  12056. loc, _ := time.LoadLocation("Local")
  12057. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12058. if err != nil {
  12059. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12060. return
  12061. }
  12062. recordDateTime := theTime.Unix()
  12063. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12064. if err != nil {
  12065. }
  12066. startRecordDateTime := startTime.Unix()
  12067. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12068. if err != nil {
  12069. }
  12070. endRecordDateTime := endTime.Unix()
  12071. admin := c.GetAdminUserInfo()
  12072. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  12073. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12074. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  12075. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12076. var settle_total float64
  12077. for _, item := range monthPrescriptions {
  12078. if len(item.HisPrescriptionProject) > 0 {
  12079. for _, subItem := range item.HisPrescriptionProject {
  12080. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12081. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12082. settle_total = settle_total + total
  12083. }
  12084. }
  12085. if len(item.HisDoctorAdviceInfo) > 0 {
  12086. for _, subItem := range item.HisDoctorAdviceInfo {
  12087. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12088. settle_total = settle_total + total
  12089. }
  12090. }
  12091. }
  12092. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12093. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12094. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12095. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12096. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  12097. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12098. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  12099. //获取所有科室信息
  12100. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12101. c.ServeSuccessJSON(map[string]interface{}{
  12102. "his_info": his_patient_info,
  12103. "xt_info": xt_patient_info,
  12104. "case_history": case_history,
  12105. "info": patientPrescriptionInfo,
  12106. "month_prescriptions": monthPrescriptions,
  12107. "order": order,
  12108. "doctors": doctors,
  12109. "department": department,
  12110. "count": count,
  12111. "drugStockConfig": drugStockConfig,
  12112. "last_info": lastPatientPrescriptionInfo,
  12113. "settle_total": settle_total,
  12114. })
  12115. return
  12116. }
  12117. func (c *HisApiController) GetAllOrder() {
  12118. org_id := c.GetAdminUserInfo().CurrentOrgId
  12119. orders, _ := service.GetNewHisOrderList(org_id)
  12120. c.ServeSuccessJSON(map[string]interface{}{
  12121. "order": orders,
  12122. })
  12123. return
  12124. }
  12125. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  12126. newArr = make([]*models.HisOrderInfoTwo, 0)
  12127. for i := 0; i < len(arr); i++ {
  12128. repeat := false
  12129. for j := i + 1; j < len(arr); j++ {
  12130. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  12131. repeat = true
  12132. break
  12133. }
  12134. }
  12135. if !repeat {
  12136. newArr = append(newArr, arr[i])
  12137. }
  12138. }
  12139. return
  12140. }
  12141. // 修改处方退库操作 参数传修改之前的处方数据
  12142. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  12143. if advice.ExecutionState == 1 {
  12144. //查询该病人该药品是否有库存记录
  12145. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  12146. if errcode == gorm.ErrRecordNotFound {
  12147. } else {
  12148. //退库
  12149. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  12150. if advice.PrescribingNumberUnit == drug.MinUnit {
  12151. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12152. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12153. //退库
  12154. warehouseInfo := models.DrugWarehouseInfo{
  12155. StockMinNumber: prescribingNumber,
  12156. }
  12157. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  12158. operation_time := time.Now().Unix()
  12159. creater := advice.AdviceDoctor
  12160. ctime := time.Now().Unix()
  12161. timeStr := time.Now().Format("2006-01-02")
  12162. timeArr := strings.Split(timeStr, "-")
  12163. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12164. total = total + 1
  12165. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12166. cancelStock := models.DrugCancelStock{
  12167. OrderNumber: orderNumber,
  12168. OperaTime: operation_time,
  12169. OrgId: advice.UserOrgId,
  12170. Creater: creater,
  12171. Ctime: ctime,
  12172. Status: 1,
  12173. ReturnTime: advice.AdviceDate,
  12174. Dealer: info.Dealer,
  12175. Manufacturer: info.Manufacturer,
  12176. Type: 1,
  12177. }
  12178. service.AddSigleDrugCancelStock(&cancelStock)
  12179. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12180. dealer, _ := service.GetDealerById(info.Dealer)
  12181. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12182. cancelStockInfo := models.DrugCancelStockInfo{
  12183. OrderNumber: cancelInfo.OrderNumber,
  12184. CancelStockId: cancelInfo.ID,
  12185. DrugId: info.DrugId,
  12186. Count: info.Count,
  12187. Status: 1,
  12188. Ctime: ctime,
  12189. OrgId: advice.UserOrgId,
  12190. Type: 1,
  12191. Manufacturer: manufactureName.ManufacturerName,
  12192. Dealer: dealer.DealerName,
  12193. Total: 0,
  12194. RetailPrice: info.RetailPrice,
  12195. RetailTotalPrice: info.RetailTotalPrice,
  12196. Price: info.Price,
  12197. RegisterAccount: "",
  12198. Remark: info.Remark,
  12199. BatchNumber: info.BatchNumber,
  12200. MaxUnit: info.CountUnit,
  12201. ProductDate: info.ProductDate,
  12202. ExpiryDate: info.ExpiryDate,
  12203. BatchNumberId: info.WarehouseInfoId,
  12204. }
  12205. flow := models.DrugFlow{
  12206. WarehousingId: 0,
  12207. DrugId: info.DrugId,
  12208. Number: "",
  12209. BatchNumber: info.BatchNumber,
  12210. Count: info.Count,
  12211. UserOrgId: advice.UserOrgId,
  12212. PatientId: 0,
  12213. SystemTime: ctime,
  12214. ConsumableType: 4,
  12215. IsSys: 0,
  12216. WarehousingOrder: "",
  12217. WarehouseOutId: 0,
  12218. WarehouseOutOrderNumber: "",
  12219. IsEdit: 0,
  12220. CancelStockId: cancelStock.ID,
  12221. CancelOrderNumber: cancelStock.OrderNumber,
  12222. Manufacturer: info.Manufacturer,
  12223. Dealer: info.Dealer,
  12224. Creator: advice.UserOrgId,
  12225. UpdateCreator: 0,
  12226. Status: 1,
  12227. Ctime: time.Now().Unix(),
  12228. Mtime: 0,
  12229. Price: info.Price,
  12230. WarehousingDetailId: 0,
  12231. WarehouseOutDetailId: 0,
  12232. CancelOutDetailId: 0,
  12233. ExpireDate: info.ExpiryDate,
  12234. ProductDate: info.ProductDate,
  12235. MaxUnit: info.CountUnit,
  12236. MinUnit: "",
  12237. }
  12238. service.CreatedCancelStock(cancelStockInfo)
  12239. service.CreateDrugFlowOne(flow)
  12240. } else {
  12241. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12242. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12243. if advice.PrescribingNumberUnit == drug.MaxUnit {
  12244. warehouseInfo := models.DrugWarehouseInfo{
  12245. StockMinNumber: prescribingNumber,
  12246. }
  12247. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  12248. }
  12249. operation_time := time.Now().Unix()
  12250. creater := advice.AdviceDoctor
  12251. ctime := time.Now().Unix()
  12252. timeStr := time.Now().Format("2006-01-02")
  12253. timeArr := strings.Split(timeStr, "-")
  12254. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12255. total = total + 1
  12256. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12257. cancelStock := models.DrugCancelStock{
  12258. OrderNumber: orderNumber,
  12259. OperaTime: operation_time,
  12260. OrgId: advice.UserOrgId,
  12261. Creater: creater,
  12262. Ctime: ctime,
  12263. Status: 1,
  12264. ReturnTime: advice.AdviceDate,
  12265. Dealer: info.Dealer,
  12266. Manufacturer: info.Manufacturer,
  12267. Type: 1,
  12268. }
  12269. service.AddSigleDrugCancelStock(&cancelStock)
  12270. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12271. dealer, _ := service.GetDealerById(info.Dealer)
  12272. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12273. cancelStockInfo := models.DrugCancelStockInfo{
  12274. OrderNumber: cancelInfo.OrderNumber,
  12275. CancelStockId: cancelInfo.ID,
  12276. DrugId: info.DrugId,
  12277. Count: info.Count,
  12278. Status: 1,
  12279. Ctime: ctime,
  12280. OrgId: advice.UserOrgId,
  12281. Type: 1,
  12282. Manufacturer: manufactureName.ManufacturerName,
  12283. Dealer: dealer.DealerName,
  12284. Total: 0,
  12285. RetailPrice: info.RetailPrice,
  12286. RetailTotalPrice: info.RetailTotalPrice,
  12287. Price: info.Price,
  12288. RegisterAccount: "",
  12289. Remark: info.Remark,
  12290. BatchNumber: info.BatchNumber,
  12291. MaxUnit: info.CountUnit,
  12292. ProductDate: info.ProductDate,
  12293. ExpiryDate: info.ExpiryDate,
  12294. BatchNumberId: info.WarehouseInfoId,
  12295. }
  12296. flow := models.DrugFlow{
  12297. WarehousingId: 0,
  12298. DrugId: info.DrugId,
  12299. Number: "",
  12300. BatchNumber: info.BatchNumber,
  12301. Count: info.Count,
  12302. UserOrgId: advice.UserOrgId,
  12303. PatientId: 0,
  12304. SystemTime: ctime,
  12305. ConsumableType: 4,
  12306. IsSys: 0,
  12307. WarehousingOrder: "",
  12308. WarehouseOutId: 0,
  12309. WarehouseOutOrderNumber: "",
  12310. IsEdit: 0,
  12311. CancelStockId: cancelStock.ID,
  12312. CancelOrderNumber: cancelStock.OrderNumber,
  12313. Manufacturer: info.Manufacturer,
  12314. Dealer: info.Dealer,
  12315. Creator: advice.AdviceDoctor,
  12316. UpdateCreator: 0,
  12317. Status: 1,
  12318. Ctime: time.Now().Unix(),
  12319. Mtime: 0,
  12320. Price: info.Price,
  12321. WarehousingDetailId: 0,
  12322. WarehouseOutDetailId: 0,
  12323. CancelOutDetailId: 0,
  12324. ExpireDate: info.ExpiryDate,
  12325. ProductDate: info.ProductDate,
  12326. MaxUnit: info.CountUnit,
  12327. MinUnit: "",
  12328. }
  12329. service.CreatedCancelStock(cancelStockInfo)
  12330. service.CreateDrugFlowOne(flow)
  12331. }
  12332. }
  12333. }
  12334. return err
  12335. }
  12336. func (this *HisApiController) DeleteNCDS() {
  12337. id, _ := this.GetInt64("id", 0)
  12338. if id > 0 {
  12339. service.DeletePsnNCDSRecordById(id)
  12340. this.ServeSuccessJSON(map[string]interface{}{
  12341. "msg": "删除成功",
  12342. })
  12343. } else {
  12344. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  12345. return
  12346. }
  12347. }
  12348. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  12349. id, _ := c.GetInt64("id")
  12350. advice, _ := service.GetHisDoctorAdviceInfo(id)
  12351. c.ServeSuccessJSON(map[string]interface{}{
  12352. "advice": advice,
  12353. })
  12354. return
  12355. }
  12356. func (c *HisApiController) GetHisMonthChargePatientList() {
  12357. record_date := c.GetString("record_date")
  12358. start_time := c.GetString("start_time")
  12359. end_time := c.GetString("end_time")
  12360. timeLayout := "2006-01-02"
  12361. loc, _ := time.LoadLocation("Local")
  12362. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12363. if err != nil {
  12364. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12365. return
  12366. }
  12367. if err != nil {
  12368. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12369. return
  12370. }
  12371. recordDateTime := theTime.Unix()
  12372. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12373. if err != nil {
  12374. }
  12375. startRecordDateTime := startTime.Unix()
  12376. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12377. if err != nil {
  12378. }
  12379. endRecordDateTime := endTime.Unix()
  12380. adminInfo := c.GetAdminUserInfo()
  12381. var tempMonthChargePatients []*service.MonthChargePatients
  12382. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  12383. for _, item := range tempPatients {
  12384. //过滤没有处方的
  12385. if len(item.HisPrescription) == 0 {
  12386. tempMonthChargePatients = append(tempMonthChargePatients, item)
  12387. }
  12388. }
  12389. c.ServeSuccessJSON(map[string]interface{}{
  12390. "list": tempMonthChargePatients,
  12391. })
  12392. }
  12393. // PrescriptionDifference 医嘱数量差值结构体
  12394. type PrescriptionDrugDifference struct {
  12395. DrugID int64 //基础库药品id
  12396. ID int64 //医嘱id
  12397. Difference float64 //差值
  12398. Unit string //单位
  12399. }
  12400. type PrescriptionGoodDifference struct {
  12401. GoodID int64 //基础库项目耗材id
  12402. ID int64 //医嘱id
  12403. Difference int64 //差值
  12404. Unit string //单位
  12405. Type int64 //类型
  12406. }
  12407. type EditCustomData struct {
  12408. adviceList []*models.HisDoctorAdviceInfo
  12409. projectList []*models.HisPrescriptionProject
  12410. }
  12411. type SrcCustomData struct {
  12412. adviceList []*models.HisDoctorAdviceInfo
  12413. projectList []*models.HisPrescriptionProject
  12414. }
  12415. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  12416. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  12417. differences := make([]*PrescriptionDrugDifference, 0)
  12418. // 创建一个 map 来存储第一个切片中的药品信息
  12419. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  12420. for _, advice := range firstPrescription {
  12421. firstMap[advice.DrugId] = advice
  12422. }
  12423. // 遍历第二个切片中的药品信息,并比较数量差值
  12424. for _, advice := range secondPrescription {
  12425. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  12426. diff := &PrescriptionDrugDifference{
  12427. DrugID: advice.DrugId,
  12428. ID: firstAdvice.ID,
  12429. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  12430. Unit: firstAdvice.PrescribingNumberUnit,
  12431. }
  12432. differences = append(differences, diff)
  12433. }
  12434. }
  12435. return differences
  12436. }
  12437. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  12438. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  12439. differences := make([]*PrescriptionGoodDifference, 0)
  12440. // 创建一个 map 来存储第一个切片中的耗材信息
  12441. firstMap := make(map[int64]*models.HisPrescriptionProject)
  12442. for _, good := range firstPrescription {
  12443. firstMap[good.ProjectId] = good
  12444. }
  12445. // 遍历第二个切片中的耗材信息,并比较数量差值
  12446. for _, good := range secondPrescription {
  12447. if firstGood, ok := firstMap[good.ProjectId]; ok {
  12448. count, _ := strconv.ParseInt(good.Count, 10, 64)
  12449. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  12450. diff := &PrescriptionGoodDifference{
  12451. GoodID: good.ProjectId,
  12452. ID: firstGood.ID,
  12453. Difference: count - firstCount,
  12454. Unit: firstGood.Unit,
  12455. Type: firstGood.Type,
  12456. }
  12457. differences = append(differences, diff)
  12458. }
  12459. }
  12460. return differences
  12461. }
  12462. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  12463. var adviceList []*models.HisDoctorAdviceInfo
  12464. var projectList []*models.HisPrescriptionProject
  12465. var advice_ids []int64
  12466. var project_ids []int64
  12467. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12468. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12469. //var tempPrescription *models.HisPrescriptionProjectscription
  12470. if len(prescriptions) > 0 {
  12471. for _, item := range prescriptions {
  12472. items := item.(map[string]interface{})
  12473. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12474. advices := items["advices"].([]interface{})
  12475. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12476. groupNo := int64(0)
  12477. ctime := time.Now().Unix()
  12478. mtime := ctime
  12479. if len(advices) > 0 {
  12480. for _, advice := range advices {
  12481. var s models.HisDoctorAdviceInfo
  12482. s.AdviceType = 2
  12483. s.StopState = 2
  12484. s.ExecutionState = 2
  12485. s.Status = 1
  12486. s.Groupno = groupNo
  12487. s.CreatedTime = ctime
  12488. s.UpdatedTime = mtime
  12489. s.IsSettle = 2
  12490. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  12491. //存储切片中
  12492. if s.ID > 0 {
  12493. advice_ids = append(advice_ids, s.ID)
  12494. adviceList = append(adviceList, &s)
  12495. }
  12496. }
  12497. }
  12498. }
  12499. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12500. projects := items["project"].([]interface{})
  12501. if len(projects) > 0 {
  12502. for _, project := range projects {
  12503. var p models.HisPrescriptionProject
  12504. p.Ctime = time.Now().Unix()
  12505. p.Mtime = time.Now().Unix()
  12506. p.Status = 1
  12507. SetProjectWithJSON(&p, project.(map[string]interface{}))
  12508. if p.ID > 0 {
  12509. project_ids = append(project_ids, p.ID)
  12510. projectList = append(projectList, &p)
  12511. }
  12512. }
  12513. }
  12514. }
  12515. }
  12516. }
  12517. }
  12518. editCustomData.projectList = projectList
  12519. editCustomData.adviceList = adviceList
  12520. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  12521. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  12522. srcCustomData.adviceList = list
  12523. srcCustomData.projectList = list2
  12524. return
  12525. }